Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 691786 - net-dns/bind-9.14.4 USE=urandom: postinst fails if no /etc/bind/rndc.key file present
Summary: net-dns/bind-9.14.4 USE=urandom: postinst fails if no /etc/bind/rndc.key file...
Status: RESOLVED DUPLICATE of bug 701032
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Mikle Kolyada (RETIRED)
URL:
Whiteboard:
Keywords: PullRequest
: 745909 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-08-08 21:38 UTC by Phil Stracchino (Unix Ronin)
Modified: 2021-01-22 12:04 UTC (History)
9 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Stracchino (Unix Ronin) 2019-08-08 21:38:07 UTC
Keys for rndc can be defined either in /etc/bind/rndc.conf or /etc/bind/rndc.key.  If both files exist, rndc will use the key in rndc.conf, but warn that rndc.key exists as well.

However, if rndc.key does NOT exist, then postinst fails:

 * FAILED postinst: 1
 * ERROR: net-dns/bind-9.14.4::gentoo failed (postinst phase):
 *   (no error message)
 *
 * Call stack:
 *     ebuild.sh, line 125:  Called pkg_postinst
 *   environment, line 3114:  Called die
 * The specific snippet of code:
 *           chown root:named /etc/bind/rndc.key || die;
 *


So postinst dies if a file that bind does not actually require to exist does not exist.
Comment 1 Stéphane Veyret 2019-08-09 17:19:48 UTC
Actually, the file should exist because if not, it is created a few lines above. The problem (which I faced too) is that if USE="urandom" is defined, the file is created using `-r /dev/urandom`, but rndc-confgen is failing because the `-r` flag is deprecated.
Comment 2 Phil Stracchino (Unix Ronin) 2019-08-09 17:31:30 UTC
(In reply to Stéphane Veyret from comment #1)
> Actually, the file should exist because if not, it is created a few lines
> above. The problem (which I faced too) is that if USE="urandom" is defined,
> the file is created using `-r /dev/urandom`, but rndc-confgen is failing
> because the `-r` flag is deprecated.

I would suggest that postinst shouldn't be trying to create rndc.key at all if a valid rndc.conf file already exists.  I have to keep manually deleting rndc.key files that I don't need and don't want.
Comment 3 Tomáš Mózes 2019-08-29 13:47:05 UTC
New installation, USE="caps urandom zlib" emerge =net-dns/bind-9.14.4 fails because /etc/bind/rndc.key does not exist.
Comment 4 Tomáš Mózes 2019-08-29 13:51:06 UTC
(In reply to Tomáš Mózes from comment #3)
> New installation, USE="caps urandom zlib" emerge =net-dns/bind-9.14.4 fails
> because /etc/bind/rndc.key does not exist.

It does not exist because rndc-confgen failed as Stéphane pointed out. 

Workaround:
emerge net-dns/bind
rndc-confgen -a
emerge net-dns/bind
Comment 5 Phil Stracchino (Unix Ronin) 2019-08-29 16:02:43 UTC
(In reply to Tomáš Mózes from comment #4)
> (In reply to Tomáš Mózes from comment #3)
> > New installation, USE="caps urandom zlib" emerge =net-dns/bind-9.14.4 fails
> > because /etc/bind/rndc.key does not exist.
> 
> It does not exist because rndc-confgen failed as Stéphane pointed out. 
> 
> Workaround:
> emerge net-dns/bind
> rndc-confgen -a
> emerge net-dns/bind


So there's two issues here.

1.  rndc-confgen is failing to create rndc.key.

2.  postinst is trying to create an rndc.key file even when a perfectly valid and correct rndc.conf file already exists.  If rndc.conf already exists, rndc.key is not only unnecessary, it actively confuses the issue and results in a warning message from rndc.  We should not be doing this.

The gripping hand is, the underlying problem is that bind has two different possible files for the same purpose in the first place, but will complain if both exist.
Comment 6 Phil Stracchino (Unix Ronin) 2019-08-29 16:11:55 UTC
To further clarify:

— The ebuild does not as far as I can see make any attempt to auto create rndc.conf, only rndc.key;
— Therefore if rndc.conf exists, we should assume it was created by the user and is correctly configured for the installation;
— If both rndc.conf and rndc.key exists, bind will prefer rndc.conf anyway, making the rndc.key file of no practical use in this case;
— Ergo, we should not attempt to create rndc.key if rndc.conf already exists.
Comment 7 Phil Stracchino (Unix Ronin) 2019-10-09 17:30:47 UTC
I propose the following one-line fix to the unferlying logic:

--- bind-9.14.4.ebuild.orig     2019-09-21 11:09:50.000000000 -0400
+++ bind-9.14.4.ebuild  2019-10-09 13:14:06.612424140 -0400
@@ -268,11 +268,11 @@
        exeinto /usr/libexec
        doexe "${FILESDIR}/generate-rndc-key.sh"
 }

 pkg_postinst() {
-       if [ ! -f '/etc/bind/rndc.key' ]; then
+       if [ ! -f '/etc/bind/rndc.key' -a ! -f '/etc/bind/rndc.conf']; then
                if use urandom; then
                        einfo "Using /dev/urandom for generating rndc.key"
                        /usr/sbin/rndc-confgen -r /dev/urandom -a
                        echo
                else


The reasoning behind this change:

— The ebuild does not create /etc/bind/rndc.conf, therefore if rndc.conf exists, already exists, we should assume that the user created it AND IT IS CORRECT, and NOT create a conflicting /etc/bind/rdnc.key which bind will ignore anyway (but issue a warning every time) because rndc.conf already exists.
— If rndc.conf does not exist but rndc.key already does, obviously we should use the existing rndc.key file and not overwrite it.
— ONLY IF NEITHER rndc.conf NOR rndc.key already exists should we create a new rndc.key file.


The rndc-confgen usage issue (-r deprecated) is a separate problem.
Comment 8 David Klaftenegger 2020-07-08 12:35:17 UTC
> The rndc-confgen usage issue (-r deprecated) is a separate problem.

Is there, or should there be, a separate bug for that issue?
Comment 9 Stéphane Veyret 2020-07-08 12:44:58 UTC
Well, this issue should be corrected in a way or another: either within this same issue (it is just 3 characters to remove), or creating a new one. But to my knowledge, there is no other open issue for it.
Comment 10 Phil Stracchino (Unix Ronin) 2020-07-08 14:20:11 UTC
I see no reason not to fix it at the same time.
Comment 11 Toralf Förster gentoo-dev 2020-12-15 22:04:44 UTC
*** Bug 745909 has been marked as a duplicate of this bug. ***
Comment 12 Phil Stracchino (Unix Ronin) 2021-01-21 17:27:33 UTC
Fixed in #701032 in 9.16.10
Comment 13 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2021-01-22 12:04:55 UTC

*** This bug has been marked as a duplicate of bug 701032 ***