containerd: kubectl exec does not have a -user option

Description

Access bash of the container and switch to root user (sudo su -), user get the privilege access and become root without any password.

Steps to reproduce the issue

  1. Use the dockerfile as attached and make the docker image (docker build …) Dockerfile_centos.txt

  2. Use the deployment as attached deployment_centos_yaml.txt

  3. login to the container

Describe the results you received and expected

In the deployment file please notice the command “sudo gpasswd -d mmsuper wheel” <-- removing the “mmsuper” user from the group “wheel”.

Rest execution steps are:


==
etester@master-0:~/test_dir> kubectl apply -f deployment_centos.yaml
deployment.apps/centos1 created
etester@master-0:~/test_dir> kubectl get pods
NAME                       READY   STATUS    RESTARTS   AGE
centos1-74c9778d9f-4ts58   1/1     Running   0          37s

Login to the container
==
etester@master-0:~/test_dir> kubectl exec -i -t centos1-74c9778d9f-4ts58 -- /bin/bash
[mmsuper@centos1-74c9778d9f-4ts58 ~]$ id
uid=10021(mmsuper) gid=1000(user1) groups=1000(user1),10(wheel)
[mmsuper@centos1-74c9778d9f-4ts58 ~]$ sudo gpasswd -d mmsuper wheel
Removing user mmsuper from group wheel
gpasswd: user 'mmsuper' is not a member of 'wheel'
[mmsuper@centos1-74c9778d9f-4ts58 ~]$ id
uid=10021(mmsuper) gid=1000(user1) groups=1000(user1),10(wheel)
[mmsuper@centos1-74c9778d9f-4ts58 ~]$
==

As you can see even after removing the user “mmsuper” from the group “wheel” in deployment file, user is not removed from that group.


The sudoers file:
==
[mmsuper@centos1-74c9778d9f-4ts58 ~]$ sudo cat /etc/sudoers
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command.

## Host Aliases
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
# Host_Alias     FILESERVERS = fs1, fs2
# Host_Alias     MAILSERVERS = smtp, smtp2

## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = jsmith, mikem


## Command Aliases
## These are groups of related commands...

## Networking
# Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool

## Installation and management of software
# Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum

## Services
# Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig, /usr/bin/systemctl start, /usr/bin/systemctl stop, /usr/bin/systemctl reload, /usr/bin/systemctl restart, /usr/bin/systemctl status, /usr/bin/systemctl enable, /usr/bin/systemctl disable

## Updating the locate database
# Cmnd_Alias LOCATE = /usr/bin/updatedb

## Storage
# Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount

## Delegating permissions
# Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp

## Processes
# Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall

## Drivers
# Cmnd_Alias DRIVERS = /sbin/modprobe

# Defaults specification

#
# Refuse to run if unable to disable echo on the tty.
#
Defaults   !visiblepw

#
# Preserving HOME has security implications since many programs
# use it when searching for configuration files. Note that HOME
# is already set when the the env_reset option is enabled, so
# this option is only effective for configurations where either
# env_reset is disabled or HOME is present in the env_keep list.
#
Defaults    always_set_home
Defaults    match_group_by_gid

# Prior to version 1.8.15, groups listed in sudoers that were not
# found in the system group database were passed to the group
# plugin, if any. Starting with 1.8.15, only groups of the form
# %:group are resolved via the group plugin by default.
# We enable always_query_group_plugin to restore old behavior.
# Disable this option for new behavior.
Defaults    always_query_group_plugin

Defaults    env_reset
Defaults    env_keep =  "COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS"
Defaults    env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults    env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults    env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults    env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"

#
# Adding HOME to env_keep may enable a user to run unrestricted
# commands via sudo.
#
# Defaults   env_keep += "HOME"

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL

## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL

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

## Allows members of the users group to mount and unmount the
## cdrom as root
# %users  ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

## Allows members of the users group to shutdown this system
# %users  localhost=/sbin/shutdown -h now

## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
mmsuper ALL=(ALL) NOPASSWD: ALL
==

The group file:
==
[mmsuper@centos1-74c9778d9f-4ts58 ~]$
[mmsuper@centos1-74c9778d9f-4ts58 ~]$ cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:33:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
users:x:100:
nobody:x:65534:
dbus:x:81:
utmp:x:22:
utempter:x:35:
input:x:999:
kvm:x:36:
render:x:998:
systemd-journal:x:190:
systemd-coredump:x:997:
systemd-resolve:x:193:
user1:x:1000:
==

[mmsuper@centos1-74c9778d9f-4ts58 ~]$ exit
exit

Re-login:
==
etester@master-0:~/test_dir> kubectl exec -i -t centos1-74c9778d9f-4ts58 -- /bin/bash
[mmsuper@centos1-74c9778d9f-4ts58 ~]$ id
uid=10021(mmsuper) gid=1000(user1) groups=1000(user1),10(wheel)
[mmsuper@centos1-74c9778d9f-4ts58 ~]$ sudo gpasswd -d mmsuper wheel
Removing user mmsuper from group wheel
gpasswd: user 'mmsuper' is not a member of 'wheel'
[mmsuper@centos1-74c9778d9f-4ts58 ~]$ id
uid=10021(mmsuper) gid=1000(user1) groups=1000(user1),10(wheel)
[mmsuper@centos1-74c9778d9f-4ts58 ~]$
==

What version of containerd are you using?

containerd github.com/containerd/containerd v1.5.7 8686ededfc90076914c5238eb96c883ea093a8ba

Any other relevant information

Versions:
==
etester@master-0:~/ttt> containerd --version
containerd github.com/containerd/containerd v1.5.7 8686ededfc90076914c5238eb96c883ea093a8ba
etester@master-0:~/ttt> runc --version
runc version 1.0.2
commit: v1.0.2-0-g52b36a2d
spec: 1.0.2-dev
go: go1.15.3
libseccomp: 2.4.1
etester@master-0:~/ttt> kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.3", GitCommit:"60a539cdd7ac8ea7a62b7c3bd1d3c374529788cb", GitTreeState:"clean", BuildDate:"2022-01-26T06:28:20Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.3", GitCommit:"60a539cdd7ac8ea7a62b7c3bd1d3c374529788cb", GitTreeState:"clean", BuildDate:"2022-01-26T06:18:30Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"linux/amd64"}
etester@master-0:~/ttt> sudo crictl --version
crictl version 1.21.0
etester@master-0:~/ttt> uname -a
Linux master-0 5.3.18-24.99-default #1 SMP Sun Jan 23 19:03:51 UTC 2022 (712a8e6) x86_64 x86_64 x86_64 GNU/Linux
== 

Show configuration if it is related to CRI plugin.

cat /etc/containerd/config.toml

version = 2
root = "/var/lib/docker/containerd/root"
state = "/run/containerd"
plugin_dir = ""
disabled_plugins = []
required_plugins = []
oom_score = -999

[grpc]
  address = "/run/containerd/containerd.sock"
  tcp_address = ""
  tcp_tls_cert = ""
  tcp_tls_key = ""
  uid = 0
  gid = 0
  max_recv_message_size = 16777216
  max_send_message_size = 16777216

[ttrpc]
  address = ""
  uid = 0
  gid = 0

[debug]
  address = ""
  uid = 0
  gid = 0
  level = ""

[metrics]
  address = ""
  grpc_histogram = false

[cgroup]
  path = ""

[timeouts]
  "io.containerd.timeout.shim.cleanup" = "5s"
  "io.containerd.timeout.shim.load" = "5s"
  "io.containerd.timeout.shim.shutdown" = "3s"
  "io.containerd.timeout.task.state" = "2s"

[plugins]
  [plugins."io.containerd.gc.v1.scheduler"]
    pause_threshold = 0.02
    deletion_threshold = 0
    mutation_threshold = 100
    schedule_delay = "0s"
    startup_delay = "100ms"
  [plugins."io.containerd.grpc.v1.cri"]
    disable_tcp_service = true
    stream_server_address = "127.0.0.1"
    stream_server_port = "0"
    stream_idle_timeout = "4h0m0s"
    enable_selinux = false
    sandbox_image = "registry.local:5000/pause:3.6-1-8e9e8d09"
    stats_collect_period = 10
    systemd_cgroup = false
    enable_tls_streaming = false
    max_container_log_line_size = 16384
    disable_cgroup = false
    disable_apparmor = false
    restrict_oom_score_adj = false
    max_concurrent_downloads = 3
    disable_proc_mount = false
    [plugins."io.containerd.grpc.v1.cri".containerd]
      snapshotter = "overlayfs"
      default_runtime_name = "runc"
      no_pivot = false
      [plugins."io.containerd.grpc.v1.cri".containerd.default_runtime]
        runtime_type = ""
        runtime_engine = ""
        runtime_root = ""
        privileged_without_host_devices = false
      [plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime]
        runtime_type = ""
        runtime_engine = ""
        runtime_root = ""
        privileged_without_host_devices = false
      [plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
        [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
          runtime_type = "io.containerd.runc.v2"
          runtime_engine = ""
          runtime_root = ""
          privileged_without_host_devices = false
          [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
                      SystemdCgroup = true
              [plugins."io.containerd.grpc.v1.cri".cni]
      bin_dir = "/opt/cni/bin"
      conf_dir = "/etc/cni/net.d"
      max_conf_num = 1
      conf_template = ""
    [plugins."io.containerd.grpc.v1.cri".registry]
      config_path = "/etc/containerd/certs.d"
      [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
    [plugins."io.containerd.grpc.v1.cri".x509_key_pair_streaming]
      tls_cert_file = ""
      tls_key_file = ""
  [plugins."io.containerd.internal.v1.opt"]
    path = "/opt/containerd"
  [plugins."io.containerd.internal.v1.restart"]
    interval = "10s"
  [plugins."io.containerd.metadata.v1.bolt"]
    content_sharing_policy = "shared"
  [plugins."io.containerd.monitor.v1.cgroups"]
    no_prometheus = false
  [plugins."io.containerd.runtime.v1.linux"]
    shim = "containerd-shim"
    runtime = "runc"
    runtime_root = ""
    no_shim = false
    shim_debug = false
  [plugins."io.containerd.runtime.v2.task"]
    platforms = ["linux/amd64"]
  [plugins."io.containerd.service.v1.diff-service"]
    default = ["walking"]
  [plugins."io.containerd.snapshotter.v1.devmapper"]
    root_path = ""
    pool_name = ""
    base_image_size = ""

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

| @mikebrow Splitted the issue and created another one – https://github.com/containerd/containerd/issues/6852

I closed that one as it was written up as a duplicate pointing to this issue.

| @mikebrow Any update about this ticket ?

no update…

| Is there any estimate, when this might get fixed ?

no estimate…

… Did you want to change the description of this issue? Or split it out into two issues? It seems like you have two issues here, one for 1) default user gains root access via sudo su - without password, the other 2) kubectl exec (a different product than where you opened your issue) does not have a -user option and instead uses the current user (the one I’ve been discussing)

I’ve marked the second issue for feature discussions, however I point out that containerd/containerd is a container runtime that implements the CRI apis. We don’t change the kubernetes APIs here. A kubernetes enhancement request will have to be opened up in kubernetes/enhancements.

Is there any estimate, when this might get fixed ?

no estimate…

Did you want to change the title and description of this issue? Or split it out into two issues? It seems like you had two issues here, one for 1) default user gains root access via sudo su - without password, the other 2) kubectl exec does not have a -user option and instead uses the current user (the one I’ve been discussing)

After split I’ll mark the second one for feature discussions