[gentoo-user] Update to /etc/sudoers disables wheel users!!!

3 views
Skip to first unread message

Walter Dnes

unread,
Oct 25, 2022, 10:40:03 PM10/25/22
to
I had the following in my /etc/sudoers before tonight's update...

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL:ALL) ALL

## Same thing without a password
%wheel ALL=(ALL:ALL) NOPASSWD: ALL

...and my regular user was able to run commands and scripts via
/usr/bin/sudo which had been authorized in files in the /etc/sudoers.d
directory. Tonight's update changed /etc/sudoers to...

## Uncomment to allow members of group wheel to execute any command
# %wheel ALL=(ALL:ALL) ALL

## Same thing without a password
# %wheel ALL=(ALL:ALL) NOPASSWD: ALL

I was "like WTF?!?" but I let it through. sudo stopped working for my
regular user. As root, I went in and manually reverted the update with
visudo. Is this a bug?

--
I've seen things, you people wouldn't believe; Gopher, Netscape with
frames, the first Browser Wars. Searching for pages with AltaVista,
pop-up windows self-replicating, trying to uninstall RealPlayer. All
those moments, will be lost in time like tears in rain... time to die.

Matt Connell

unread,
Oct 25, 2022, 11:20:03 PM10/25/22
to
On Tue, 2022-10-25 at 22:34 -0400, Walter Dnes wrote:
>  Is this a bug?

Nope, this is the way it is supposed to work.

Ramon is correct, user changes should go into sudoers.d which has been
the case for... some years now, I think? I don't recall.

I still make changes in sudoers directly, and just make sure dispatch-
conf doesn't squish them. I like to live dangerously I guess.

Grant Taylor

unread,
Oct 25, 2022, 11:20:03 PM10/25/22
to
On 10/25/22 9:04 PM, Ramon Fischer wrote:
> I do not think, that this is a bug, since it is the default file, which
> should not be edited by the user.

I *STRONGLY* /OBJECT/ to the notion that users should not edit
configuration files.

By design, that's the very purpose of the configuration file, for users
to edit them to be what they want them to be.

The concept of "don't edit configuration files" seems diametrically
opposed to the idea of Gentoo as I understand it. Namely, /you/ build
/your/ system to behave the way that /you/ want it to.

> All changes should be done in "/etc/sudoers.d/" to avoid such cases.

Then why in the world does the /default/ file, as installed by Gentoo,
include directions to edit the the file?!?!?!

Aside: Someone recently posted a comment to the sudo users mailing list
(exact name escapes me) wherein their security policy prohibited
@includedir explicitly because of the capability that adding a file to
such included directories inherently enabled sudo access -or- caused
sudo to fail secure and perform a Denial of Service. They were required
to use individual @include directives.

IMHO telling a Gentoo user not to modify a file in /etc takes hutzpah.



--
Grant. . . .
unix || die

Matt Connell

unread,
Oct 25, 2022, 11:50:03 PM10/25/22
to
On Tue, 2022-10-25 at 21:15 -0600, Grant Taylor wrote:
> I *STRONGLY* /OBJECT/ to the notion that users should not edit
> configuration files.

Calm down. Nobody said you can't. I do. Just know what you're doing
and pay attention to what portage does with package-managed
configuration files.

dispatch-conf even gives you the opportunity to edit it before
applying.

Anna “CyberTailor”

unread,
Oct 26, 2022, 12:10:03 AM10/26/22
to
# emerge app-admin/doas
# emerge -c app-admin/sudo
# ln -s ./doas /usr/bin/sudo

:P

Walter Dnes

unread,
Oct 26, 2022, 2:40:04 AM10/26/22
to
On Wed, Oct 26, 2022 at 05:04:35AM +0200, Ramon Fischer wrote
> Hello Walter,
>
> I do not think, that this is a bug, since it is the default file, which
> should not be edited by the user.

Firstly "grep -i uncomment /etc/sudoers" results in...

## Uncomment to enable special input methods. Care should be taken as
## Uncomment to use a hard-coded PATH instead of the user's to find commands
## Uncomment to send mail if the user does not enter the correct password.
## Uncomment to enable logging of a command's output, except for
## Uncomment to allow members of group wheel to execute any command
## Uncomment to allow members of group sudo to execute any command
## Uncomment to allow any user to run sudo if they know the password

...I.e. the file is explicitly telling you to edit it if required!!!

> All changes should be done in "/etc/sudoers.d/" to avoid such cases.

My regular user has script "settime" in ${HOME}/bin

#!/bin/bash
date
/usr/bin/sudo /usr/bin/rdate -nsv ca.pool.ntp.org
/usr/bin/sudo /sbin/hwclock --systohc
date

/etc/sudoers.d/001 has, amongst other things, two lines...

waltdnes x8940 = (root) NOPASSWD: /sbin/hwclock --systohc
waltdnes x8940 = (root) NOPASSWD: /usr/bin/rdate -nsv ca.pool.ntp.org

User "waltdnes" is a member of "wheel". If the "wheel" line is
uncommented in /etc/sudoers, sudo works for me. If the "wheel" line is
commented, then sudo breaks for my regular user.

> I kept mine unchanged from 2nd October and only have two uncommented lines:
>
>     [...]
>     root ALL=(ALL:AlL) ALL
>     [...]
>     @includedir /etc/sudoers.d
>
> I am using version "1.9.11_p3-r1".

Me too.

There seem to be two different approaches here. The loose approach is
to allow a user to run "sudo <whatever I damn well want>". A more locked
down approach allows regular users to run "sudo <very specific command>".
This guards against "fat-finger-syndrome". I go with the more locked
down approach

Rich Freeman

unread,
Oct 26, 2022, 7:40:04 AM10/26/22
to
On Wed, Oct 26, 2022 at 3:42 AM Ramon Fischer <Ramon_...@hotmail.de> wrote:
>
> I do not know, what the developers were thinking to encourage the user
> to edit a default file, which gets potentially overwritten after each
> package update...
>
> "etc-update" helps to have an eye on, but muscle memory and fast fingers
> are sometimes faster.

The Gentoo preference tends to be to follow upstream. So if sudo
upstream distributes a file like this that has comments encouraging
users to edit it, then that is likely how Gentoo will ship it. If
sudo switched to moving everything into an include-based system
UPSTREAM then Gentoo would probably start shipping that. If you look
at the sudo ebuild you'll see that the config files are 100% upstream.

If you look at things like systemd units or udev rules they're much
more include-oriented, as this is the upstream preference.

Gentoo has emphasized using config file protection early on, and
doesn't have any official preference for using included config
directories distro-wide. Portage has been moving in this direction
for a while though (for the stuff in /etc/portage).

--
Rich

Grant Taylor

unread,
Oct 26, 2022, 12:30:03 PM10/26/22
to
On 10/25/22 9:44 PM, Matt Connell wrote:
> Calm down.

I am calm.

The suggestion to not edit the (/etc/sudoeres) configuration file is one
of those types of things that if nobody objects to then eventually not
doing so will become defacto policy. So I objected, calmly, but with
emphasis.

> Nobody said you can't.

Yet. (See above.)

> I do.

I do too.

> Just know what you're doing and pay attention to what portage does
> with package-managed configuration files.

Yep.

This is a common pitfall across multiple distributions / operating
systems / platforms.

> dispatch-conf even gives you the opportunity to edit it before
> applying.

Yep.

I almost always reject the changes suggested on config files that I've
modified and accept them on files that I've not modified.

I really do wish that there was a better way to manage this, likely
involving diffs / deltas. E.g. what changed between the N distribution
file and the N+1 distribution file. Can that same change be safely
applied to the N' distribution file to create the N'+1 file?

Grant Taylor

unread,
Oct 26, 2022, 12:50:04 PM10/26/22
to
On 10/26/22 12:31 AM, Walter Dnes wrote:
> My regular user has script "settime" in ${HOME}/bin
>
> #!/bin/bash
> date
> /usr/bin/sudo /usr/bin/rdate -nsv ca.pool.ntp.org
> /usr/bin/sudo /sbin/hwclock --systohc
> date
>
> /etc/sudoers.d/001 has, amongst other things, two lines...
>
> waltdnes x8940 = (root) NOPASSWD: /sbin/hwclock --systohc
> waltdnes x8940 = (root) NOPASSWD: /usr/bin/rdate -nsv ca.pool.ntp.org
>
> User "waltdnes" is a member of "wheel". If the "wheel" line is
> uncommented in /etc/sudoers, sudo works for me. If the "wheel"
> line is commented, then sudo breaks for my regular user.

Please try running the two sudo lines from the script as is on the
command line as the waltdnes user. I'm wondering if the problem is
potentially related to something else, namely sudo wanting to read from
a terminal (PTY) in some configurations.

I believe there is a non-zero chance that the commands allowed via the
/etc/sudoers.d/001 file will work as entered. But that running sudo
from within a script, as opposed to on the command line, /may/ be the
source of problems. -- Divide and conquer the problem.

> There seem to be two different approaches here. The loose approach
> is to allow a user to run "sudo <whatever I damn well want>".

This seems to be -- what I refer to as -- the distribution default.
E.g. get people to run things through sudo vs running things through su
or running directly as root.

> A more locked down approach allows regular users to run "sudo <very
> specific command>".

This is -- what I refer to as -- the (more) enterprise approach. It
also seems to be the next evolution of the distribution default wherein
people want to start restricting what can and can't be run via sudo.

The enterprise approach also tends to come more into play as you use
sudo to run things as users other than root; e.g. run RDBMS commands as
the Oracle user or backup commands as the Tivoli user.

> This guards against "fat-finger-syndrome".

I think it's more than protection against fat-finger-syndrome. After
all, unless the sudoers file(s) is (are) *EXTREMELY* specific down to
and including command parameters / options, you can still fat-finger
command parameters / options.

When you start separating duties and who is allowed to do what is when
you start to see the more locked down enterprise methodology.

> I go with the more locked down approach

I use the distribution default on my personal systems where I'm 95% of
the use case.

I use the enterprise method on work systems where we have multiple
people with different skill levels doing different tasks.

Aside: One advantage of the enterprise method is that you can allow a
command as one target user (Oracle) but not the (default) root user.
Thus helping protect against people omitting a critical option. --
Many things, e.g. Oracle RDBMS, get rather upset when commands
(accidentally) change the ownership of files when run as the wrong user.

Grant Taylor

unread,
Oct 26, 2022, 1:00:04 PM10/26/22
to
On 10/26/22 1:42 AM, Ramon Fischer wrote:
> and your user is able to synchronise your clock again.

I'm not sure that will work as hoped. See my other reply about PTY and
testing the commands at the command line for more explanation of what I
suspect is happening.

> I do not know, what the developers were thinking to encourage the user
> to edit a default file, which gets potentially overwritten after each
> package update...

To the sudo developers, the /etc/sudoers file is *SUPPOSED* *TO* /be/
/edited/.

The sudo developers provide the sudo (et al.) program(s) for your use
and /you/ provide the configuration file(s) that it (they) use.

It is natural for the /etc/sudoers file to be edited.

To me the disconnect is when people other than the sudo developers
distribute the /etc/sudoers file and expect that it will not be edited.

What are end users / systems administrators to do if the default file
has something like the following enabled in the default /etc/sudoers
file and the EUs / SAs want it to not be there?

%wheel ALL=(ALL:ALL) ALL

They have no choice but to change (edit / replace) the /etc/sudoers file.

Especially if other parts of the system rely on the wheel group and not
putting users in it is not an option. -- The above line *MUST* be
taken out, thus the /etc/sudoers file *MUST* be edited.

Unix has 50 years of editing files to make the system behave as desired.
Modularization and including other files is nice /when/ /it/ /works/.
But there are times that modularization doesn't work and files *MUST* be
edited.

> "etc-update" helps to have an eye on, but muscle memory and fast fingers
> are sometimes faster.

How many levels of safety do you suggest that we put in place?

What if someone were to put the following into /etc/sudoers.d/zzzzzzzzzz

ALL ALL=(ALL) !ALL

}:-)

> This is the best way. Try to be as precise as possible, but be aware of
> wildcards![1]

The /etc/sudoers syntax can be tricky to master. But it can also be
very powerful when done correctly.

Grant Edwards

unread,
Oct 26, 2022, 1:20:03 PM10/26/22
to
On 2022-10-26, Grant Taylor <gta...@gentoo.tnetconsulting.net> wrote:

> To the sudo developers, the /etc/sudoers file is *SUPPOSED* *TO* /be/
> /edited/.

And editing that file is how I configure sudo. And when an emerge
update changes /etc/sudoers, the edited file is left as-is and there
is a message that you need to run etc-update to merge the changes.

--
Grant

Neil Bothwick

unread,
Oct 26, 2022, 1:21:32 PM10/26/22
to
On Wed, 26 Oct 2022 10:21:06 -0600, Grant Taylor wrote:

> > dispatch-conf even gives you the opportunity to edit it before
> > applying.
>
> Yep.
>
> I almost always reject the changes suggested on config files that I've
> modified and accept them on files that I've not modified.
>
> I really do wish that there was a better way to manage this, likely
> involving diffs / deltas. E.g. what changed between the N distribution
> file and the N+1 distribution file. Can that same change be safely
> applied to the N' distribution file to create the N'+1 file?

conf-update allows you to merge the new and old files, prompting you to
pick which to use on each differing section, with a further option to
edit the lines. That way you can keep your changed lines but still add
lines relating to new config options.


--
Neil Bothwick

Top Oxymorons Number 36: Alone together

Rich Freeman

unread,
Oct 26, 2022, 1:40:04 PM10/26/22
to
It could really use an overhaul but cfg-update does 3-way diffs and
auto-merges based on them. Ie, if in a block of text you make a
change, and in a new update that particular block of text hasn't
changed, then your previous change will get auto-merged. If the
upstream file changed in that block of text then you can do a 3-way
diff.

The tool is really old and barely maintained (I'm caretaking it but
don't really want to deal with that - patches welcome). It also uses
RCS to store the change history for 3-way merging and that could
probably be switched to git or something more modern. If you use an
x11-based merge tool then it will also refuse to attempt an automatic
merge if X11 isn't available. (Obviously you can't actually run the
manual merge if the tool uses X11 and that isn't available.)

Using it I find that maybe 95% of my config file changes involve no prompts.

Another useful tool is etckeeper which is basically just some
integrations for portage around maintaining /etc in git. You can of
course just do that manually but it will auto-commit changes if you
forget to do so before an update.

--
Rich

Neil Bothwick

unread,
Oct 26, 2022, 2:31:12 PM10/26/22
to
On Wed, 26 Oct 2022 20:04:10 +0200, Ramon Fischer wrote:

> Also a very interesting question!
>
> I just tested this with "visudo" and it does not intercept this.
>
> If "su" is disabled, you are locked out and you are forced to enter
> your system via a live USB stick and a "chroot" in order to edit
> "/etc/shadow" to set a root password via "mkpasswd" and enable "su".
> Nice. :D

You need to be root to write to /etc/sudoers.d. If someone has that
access, you are already doomed!

>
> -Ramon
>
> On 26/10/2022 18:52, Grant Taylor wrote:
> > What if someone were to put the following into
> > /etc/sudoers.d/zzzzzzzzzz
> >
> >    ALL ALL=(ALL) !ALL
> >
> > }:-)




--
Neil Bothwick

I thought I saw the light at the end of the tunnel...
but it was just some sod with a torch bringing me more work!

Jack

unread,
Oct 26, 2022, 2:40:03 PM10/26/22
to
On 2022.10.26 14:04, Ramon Fischer wrote:
> Also a very interesting question!
>
> I just tested this with "visudo" and it does not intercept this.
>
> If "su" is disabled, you are locked out and you are forced to enter
> your system via a live USB stick and a "chroot" in order to edit
> "/etc/shadow" to set a root password via "mkpasswd" and enable "su".
> Nice. :D
Could you not interrupt grup and append "single" or "init=/bin/bash"
to the kernel command line?
>
> -Ramon
>
> On 26/10/2022 18:52, Grant Taylor wrote:
>> What if someone were to put the following into
>> /etc/sudoers.d/zzzzzzzzzz
>>
>>    ALL ALL=(ALL) !ALL
>>
>> }:-)
>
>--
> GPG public key: 5983 98DA 5F4D A464 38FD CF87 155B E264 13E6 99BF
>

Grant Taylor

unread,
Oct 26, 2022, 3:30:04 PM10/26/22
to
On 10/26/22 12:04 PM, Ramon Fischer wrote:
> Also a very interesting question!

}:-)

> I just tested this with "visudo" and it does not intercept this.

Nor should it.

It's perfect legitimate sudoers syntax.

The location; /etc/sudoers.d/zzzzzzzzzz vs the end of /etc/sudoers
(proper), doesn't matter.

> If "su" is disabled, you are locked out and you are forced to enter your
> system via a live USB stick and a "chroot" in order to edit
> "/etc/shadow" to set a root password via "mkpasswd" and enable "su".

Which is one of the reasons that it's important to have (set) a known
root password.

Grant Taylor

unread,
Oct 26, 2022, 3:30:04 PM10/26/22
to
On 10/26/22 12:22 PM, Neil Bothwick wrote:
> You need to be root to write to /etc/sudoers.d. If someone has that
> access, you are already doomed!

And what happens if someone uses the existing root-via-sudo access to
break sudo?

You loose root-via-sudo access.

Someone could become root, via sudo, edit the sudoers file without using
visudo, introduce a syntax problem, thereby breaking sudo (fail secure).

You could easily do this to yourself if you don't follow best practices.

Grant Taylor

unread,
Oct 26, 2022, 3:40:03 PM10/26/22
to
On 10/26/22 12:35 PM, Jack wrote:
> Could you not interrupt  grup and append "single" or "init=/bin/bash" to
> the kernel command line?

Maybe.

It will depend on how complex your configuration is.

I don't remember if Gentoo requires root's password when entering single
user mode or not. (I've not tested it in a long time.)

Invoking Bash (or any shell) as init may not work as desired if your
system configuration is complex and needs fancier things (modules /
network resources / etc) during normal init.

My 20 years worth of experience is to have a root password set so that
you can fix this more directly and more reliably.

Ideally, as soon as you learn that sudo is not working as desired, use
su -- using root's password -- and revert the recent sudo change.

Neil Bothwick

unread,
Oct 26, 2022, 4:10:04 PM10/26/22
to
On Wed, 26 Oct 2022 13:28:49 -0600, Grant Taylor wrote:

> > You need to be root to write to /etc/sudoers.d. If someone has that
> > access, you are already doomed!
>
> And what happens if someone uses the existing root-via-sudo access to
> break sudo?

So they have root access, nothing has changed. How they get root access
is irrelevant, just that they have it.


--
Neil Bothwick

A positive attitude may not solve all your problems, but it will annoy
enough people to make it worth the effort.

Neil Bothwick

unread,
Oct 26, 2022, 4:10:04 PM10/26/22
to
On Wed, 26 Oct 2022 20:38:35 +0200, Ramon Fischer wrote:

> I thought in a too complicated way.
>
> Why not just remove the entry from "/etc/sudoers.d/zzzzzzz", while
> being in a "chroot"?

Still too complicated. Just mount the root partition from a live USB and
delete the file. no need for a chroot.


--
Neil Bothwick

Facts are stubborn, but statistics are more pliable

Grant Taylor

unread,
Oct 26, 2022, 4:20:04 PM10/26/22
to
On 10/26/22 2:08 PM, Neil Bothwick wrote:
> So they have root access, nothing has changed. How they get root
> access is irrelevant, just that they have it.

No, how they get root access is not irrelevant.

If your only access to root is via sudo and you break sudo you no longer
have root access.

If you don't have root access through something other than sudo, you
can't fix your sudo (from your existing system).

Neil Bothwick

unread,
Oct 26, 2022, 5:20:04 PM10/26/22
to
They and you are different people. You are looking at it from the
perspective of a user accidentally locking themself out of the system, so
su is the best way to be able to fix it. I agree with you there. I was
looking at it from the perspective of a third party changing sudo right
without your consent. We were at cross purposes.


--
Neil Bothwick

"We can't solve problems by using the same kind of thinking we used when
we created them." (Albert Einstein)

Grant Edwards

unread,
Oct 26, 2022, 5:30:04 PM10/26/22
to
On 2022-10-26, Dale <rdale...@gmail.com> wrote:
> Rich Freeman wrote:
>> If you use an x11-based merge tool then it will also refuse to attempt
>> an automatic
>> merge if X11 isn't available. (Obviously you can't actually run the
>> manual merge if the tool uses X11 and that isn't available.)
>>
>>
>
> I'd like to try a GUI based tool.  Is that what you talking about?  If
> so, name or what package has it?

At one point, I had one of my systems configured to use "meld" when I
picked "interactive merge" in the etc-update menu, but I've since gone
back to just picking "show differences" in the etc-update menu, then
manually running merge on the two filenames shown. With the
interactive merge option, I was always a bit confused about which file
was the destination and what happened after I exited meld.

--
Grant

Grant Taylor

unread,
Oct 26, 2022, 5:40:03 PM10/26/22
to
On 10/26/22 3:13 PM, Neil Bothwick wrote:
> They and you are different people. You are looking at it from the
> perspective of a user accidentally locking themself out of the system,
> so su is the best way to be able to fix it. I agree with you there. I
> was looking at it from the perspective of a third party changing sudo
> right without your consent. We were at cross purposes.

ACK

Thank you for clarifying.

Grant Taylor

unread,
Oct 26, 2022, 5:40:04 PM10/26/22
to
On 10/26/22 3:27 PM, Ramon Fischer wrote:
> Why was I thinking of a chroot?
>
> Maybe because of reading "grup/grub" a few e-mails before and thinking
> of "grub-mkconfig"...

Or maybe because entering a chroot is such a prominent thing to do when
booting off of Gentoo media to do an installation that it's largely
habitual for some of us. ;-)

Grant Taylor

unread,
Oct 26, 2022, 7:10:03 PM10/26/22
to
On 10/26/22 3:48 PM, Ramon Fischer wrote:
> I have created an issue at their Git repository. Maybe there will be
> solution for this:
>
>    https://github.com/sudo-project/sudo/issues/190

I ... don't know where to begin.

There are so many ways that you can hurt yourself with syntactically
valid sudoers that it's not even funny.

You could allow list almost all commands, without using the special ALL
place holder and then remark critical commands and end up in a very
similar situation.

At some point we have to trust that Systems Administrators / Sudoers
editors know what they are doing and let them do so.

Rich Freeman

unread,
Oct 26, 2022, 8:00:04 PM10/26/22
to
I use cfg-update+meld. It can use any 3-way diff/edit tool, but there
aren't many of those.

I believe the three panels show:
Left: the current config file
Right: new new packaged config file
Center: what the packaged config file was the last time you did an update

So Left vs Center shows you what changes you've made vs upstream, and
center vs right show you what changes upstream made to their file. So
you would look for differences on the right side to see what needs
attention in the file, and then work those changes if appropriate into
the left file.

You just edit the left file to get it the way you want it and save
that, and then cfg-update captures the changes in RCS.

--
Rich

Grant Taylor

unread,
Oct 26, 2022, 9:50:03 PM10/26/22
to
On 10/26/22 7:27 PM, Ramon Fischer wrote:
> Sure, you cannot cover everything, but mitigating at least a little bit
> would be OK or not? :)

I don't know. :-/

It's the proverbial problem of spam / virus filtering and a spam / virus
gets through the filters and someone saying "But it's your fault because
you are supposed to protect me!!!".

Sometimes there's advantages to saying "here's a gun, it's loaded, and
the safety is off. we suggest not pointing it at your foot. If you do
point it at your foot, don't pull the trigger." type thing.
Reply all
Reply to author
Forward
0 new messages