From 45e4d4fc3bb52f73eb6e687a144cd48587fad2d4 Mon Sep 17 00:00:00 2001 From: John Kinsella Date: Wed, 23 Oct 2013 13:42:16 -0700 Subject: [PATCH] Summary: Updated sudoers approved commands for cloud user Detail: Previously the cloud user has full password-less sudo access. This commit changes that to only allow access to a specific list of commands. Been tested in production on ACS 4.0 and 4.2 mangement servers. BUG-ID: CLOUDSTACK-967 Bugfix-for: Reviewed-by: Reported-by: Signed-off-by: John Kinsella 1382560936 -0700 --- python/lib/cloudutils/serviceConfig.py | 2 +- server/conf/cloudstack-sudoers.in | 2 +- tools/appliance/definitions/devcloud/base.sh | 2 +- tools/appliance/definitions/systemvm64template/base.sh | 2 +- tools/appliance/definitions/systemvm64template/postinstall.sh | 2 +- tools/appliance/definitions/systemvmtemplate/base.sh | 2 +- tools/appliance/definitions/systemvmtemplate/postinstall.sh | 2 +- tools/devcloud/src/deps/boxes/basebox-build/postinstall.sh | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/python/lib/cloudutils/serviceConfig.py b/python/lib/cloudutils/serviceConfig.py index 5c552c0b756..4ed9a57079c 100755 --- a/python/lib/cloudutils/serviceConfig.py +++ b/python/lib/cloudutils/serviceConfig.py @@ -727,7 +727,7 @@ class sudoersConfig(serviceCfgBase): def config(self): try: cfo = configFileOps("/etc/sudoers", self) - cfo.addEntry("cloud ALL ", "NOPASSWD : ALL") + cfo.addEntry("cloud ALL ", "NOPASSWD : /bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount") cfo.rmEntry("Defaults", "requiretty", " ") cfo.save() return True diff --git a/server/conf/cloudstack-sudoers.in b/server/conf/cloudstack-sudoers.in index dcfb17b3ddf..069016434c7 100644 --- a/server/conf/cloudstack-sudoers.in +++ b/server/conf/cloudstack-sudoers.in @@ -18,5 +18,5 @@ # The CloudStack management server needs sudo permissions # without a password. -@MSUSER@ ALL =NOPASSWD : ALL +@MSUSER@ ALL =NOPASSWD : /bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount diff --git a/tools/appliance/definitions/devcloud/base.sh b/tools/appliance/definitions/devcloud/base.sh index 122b3893c92..7fec0fc342d 100644 --- a/tools/appliance/definitions/devcloud/base.sh +++ b/tools/appliance/definitions/devcloud/base.sh @@ -6,7 +6,7 @@ apt-get -y update apt-get -y install curl unzip apt-get clean -echo 'cloud ALL=NOPASSWD:ALL' > /etc/sudoers.d/cloud +echo 'cloud ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount' > /etc/sudoers.d/cloud # Tweak sshd to prevent DNS resolution (speed up logins) echo 'UseDNS no' >> /etc/ssh/sshd_config diff --git a/tools/appliance/definitions/systemvm64template/base.sh b/tools/appliance/definitions/systemvm64template/base.sh index d6faea04b41..46c5db6dcd1 100644 --- a/tools/appliance/definitions/systemvm64template/base.sh +++ b/tools/appliance/definitions/systemvm64template/base.sh @@ -5,7 +5,7 @@ apt-get -y update apt-get -y install curl unzip # Set up sudo -echo 'vagrant ALL=NOPASSWD:ALL' > /etc/sudoers.d/vagrant +echo 'vagrant ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount' > /etc/sudoers.d/vagrant # Tweak sshd to prevent DNS resolution (speed up logins) echo 'UseDNS no' >> /etc/ssh/sshd_config diff --git a/tools/appliance/definitions/systemvm64template/postinstall.sh b/tools/appliance/definitions/systemvm64template/postinstall.sh index 929773101c2..d33b943b47a 100644 --- a/tools/appliance/definitions/systemvm64template/postinstall.sh +++ b/tools/appliance/definitions/systemvm64template/postinstall.sh @@ -105,7 +105,7 @@ setup_accounts() { echo "root:$ROOTPW" | chpasswd echo "cloud:`openssl rand -base64 32`" | chpasswd sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=admin' /etc/sudoers - sed -i -e 's/%admin ALL=(ALL) ALL/%admin ALL=NOPASSWD:ALL/g' /etc/sudoers + sed -i -e 's/%admin ALL=(ALL) ALL/%admin ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount/g' /etc/sudoers # Disable password based authentication via ssh, this will take effect on next reboot sed -i -e 's/^.*PasswordAuthentication .*$/PasswordAuthentication no/g' /etc/ssh/sshd_config # Secure ~/.ssh diff --git a/tools/appliance/definitions/systemvmtemplate/base.sh b/tools/appliance/definitions/systemvmtemplate/base.sh index 4d6092a5995..5aaa0eddbb6 100644 --- a/tools/appliance/definitions/systemvmtemplate/base.sh +++ b/tools/appliance/definitions/systemvmtemplate/base.sh @@ -7,7 +7,7 @@ apt-get -y install curl unzip apt-get clean # Set up sudo, TODO: Check security concerns -echo 'cloud ALL=NOPASSWD:ALL' > /etc/sudoers.d/cloud +echo 'cloud ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount' > /etc/sudoers.d/cloud # Tweak sshd to prevent DNS resolution (speed up logins) echo 'UseDNS no' >> /etc/ssh/sshd_config diff --git a/tools/appliance/definitions/systemvmtemplate/postinstall.sh b/tools/appliance/definitions/systemvmtemplate/postinstall.sh index caee7b36a5e..1309d47a9f5 100644 --- a/tools/appliance/definitions/systemvmtemplate/postinstall.sh +++ b/tools/appliance/definitions/systemvmtemplate/postinstall.sh @@ -104,7 +104,7 @@ setup_accounts() { echo "root:$ROOTPW" | chpasswd echo "cloud:`openssl rand -base64 32`" | chpasswd sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=admin' /etc/sudoers - sed -i -e 's/%admin ALL=(ALL) ALL/%admin ALL=NOPASSWD:ALL/g' /etc/sudoers + sed -i -e 's/%admin ALL=(ALL) ALL/%admin ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount/g' /etc/sudoers # Disable password based authentication via ssh, this will take effect on next reboot sed -i -e 's/^.*PasswordAuthentication .*$/PasswordAuthentication no/g' /etc/ssh/sshd_config # Secure ~/.ssh diff --git a/tools/devcloud/src/deps/boxes/basebox-build/postinstall.sh b/tools/devcloud/src/deps/boxes/basebox-build/postinstall.sh index 217d23024aa..f2b15602e8c 100644 --- a/tools/devcloud/src/deps/boxes/basebox-build/postinstall.sh +++ b/tools/devcloud/src/deps/boxes/basebox-build/postinstall.sh @@ -28,7 +28,7 @@ groupadd -r admin usermod -a -G admin devcloud echo "root:password" | chpasswd sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=admin' /etc/sudoers -sed -i -e 's/%admin ALL=(ALL) ALL/%admin ALL=NOPASSWD:ALL/g' /etc/sudoers +sed -i -e 's/%admin ALL=(ALL) ALL/%admin ALL=NOPASSWD:/bin/chmod, /bin/cp, /bin/mkdir, /bin/mount, /bin/umount/g' /etc/sudoers mkdir /home/devcloud/.ssh chmod 700 /home/devcloud/.ssh