4

I have found out that I give get a non-sudo user access to certain commands with the sudo privileges. However, my plan to allow them to run apt-get dist-upgrade the system is not safe because they might be able to access the shell as root. I then found out that I can manually invoke unattended upgrades by running sudo unattended-upgrade -d.

Question

Would giving a non-root user access to call unattended-upgrade be safe (e.g. not possible to get into a root shell)? Would there be any consequences other than the fact that this only installs security updates (e.g. half-installed packages etc).

  • Can you not use the sudoers file to list the commands you want these users to run? In conjunction with the NOPASSWD option. – eyoung100 Jul 28 '15 at 17:09
  • @eyoung100 well no. I'm trying to allow a non-admin to update a system as much as they can safely, but cannot allow them to run upgrade because they could get root shell access. I'm thinking this is the best workaround but want to check if it is also unsafe in the same manner. – Programster Jul 29 '15 at 13:38
  • You need to use a COMMAND ALIAS. See now finished Answer. Sorry for the delay. apt-get update/upgrade are always used in tandem to upgrade packages. The Danger here is dist-upgrade which you correctly pointed out has been removed via the Command Alias. – eyoung100 Jul 29 '15 at 17:50
  • Re: Root Shell Access, see Update Section in Answer. – eyoung100 Jul 29 '15 at 18:40
3

Solution

  1. Create a new Group: groupadd -r updaters The -r option reserves a system group, i.e. 0 - 100.
  2. Add Users to Above Group: useradd -G updaters john, useradd -G updaters sally. You can also use the user alias section to acheive this. See Sudoer File Examples for a fully functioning User Alias Section. In my opinion, doing it the way I've done adds security, as the group actually exists in the system.
  3. Create your command list for updaters: Note: Apt-get uses argument passing. See Problem Section Cmnd_Alias UPDATE_CMDS = /usr/bin/aptitude, /usr/bin/dpkg, /usr/bin/apt-get up*, /usr/bin/apt-get install
    • Note that dpkg is needed for apt-get. See AskUbuntu: Adding apt-get to sudoers file.
    • Note that apt-get update and apt-get upgrade are both needed. Using a glob pattern achieves both.
    • Note that aptitude may be used to replace apt-get if the dpkg behavior noted above is undesired. If you don't want users in the updaters group to install off the internet with a mouse click...

Now we must add our updates into our sudoers file. Issue: visudo,and:

The default sudoers file from Ubuntu (with adds from above):

# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults    env_reset

# Uncomment to allow members of group sudo to not need a password
# %sudo ALL=NOPASSWD: ALL

# Host alias specification

# User alias specification

# Cmnd alias specification
Cmnd_Alias UPDATE_CMDS = /usr/bin/aptitude, /usr/bin/dpkg, /usr/bin/apt-get up*, /usr/bin/apt-get install

# User privilege specification
root    ALL=(ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Members of the upgraders group may perform certain upgrade commands.
# If No Password is desired, comment the line below, and see the next option.
%upgraders ALL=UPDATE_CMDS

# Members of the upgraders group may perform certain upgrade commands, 
# WITHOUT A PASSWORD DANGEROUS (uncomment if desired):
#%upgraders ALL=NOPASSWD:UPDATE_CMDS

If you decide to add unattended-upgrade, read the Debian Documentation on it. and use which unattended-upgrade to determine the path to add it to UPDATE_CMDS. See Problem Section.


Update

After even more research, I ran across a Blogpost: Everything you need to know about conffiles: configuration files managed by dpkg. The problem is not in apt variants, the problem is in the underlying dpkg implementation. Quoting:

Avoiding the conffile prompt

Every time that dpkg must install a new conffile that you have modified (and a removed file is only a particular case of a modified file in dpkg’s eyes), it will stop the upgrade and wait your answer. This can be particularly annoying for major upgrades. That’s why you can give predefined answers to dpkg with the help of multiple --force-conf* options:

  • --force-confold: do not modify the current configuration file, the new version is installed with a .dpkg-dist suffix. With this option alone, even configuration files that you have not modified are left untouched. You need to combine it with --force-confdef to let dpkg overwrite configuration files that you have not modified.
  • --force-confnew: always install the new version of the configuration file, the current version is kept in a file with the .dpkg-old suffix.
  • --force-confdef: ask dpkg to decide alone when it can and prompt otherwise. This is the default behavior of dpkg and this option is mainly useful in combination with --force-confold.
  • --force-confmiss: ask dpkg to install the configuration file if it’s currently missing (for example because you have removed the file by mistake).

Knowing this, as the blog points out, we can create /etc/apt/apt.conf.d/local, and add (example):

Dpkg::Options {
   "--force-confdef";
   "--force-confold";
}

This should then bypass the Z option all together.


Problem

Unattended Upgrades are usually a bad idea, because the OS may install items that were unexpected, for example new kernels, or updated drivers that will break a functioning driver, added to the idea that you're giving the option to a user. The other issue here is that since apt-get uses argument passing to decide which option to perform, one must pass each desired option in the Command Alias created. By adding each argument separately, we remove the ability to use the dist-upgrade argument. Like you, I assumed one could not pass an argument in the sudoers file, and while researching I too, learned something new.


References

nixCraft - Howto: Linux Add User To Group
Aptitude - Ubuntu Documentation
Ubuntu Forums - Thread: HowTO: Sudoers Configuration
Ubuntu Documentation - Installing Software
AskUbuntu - What is the difference between apt-get update and upgrade?

  • Wow! That's a well researched answer. – Programster Jul 30 '15 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.