docker / docker/cli

docker exec can not get the correct permission with non-root user launch container

Open
#4,732 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug status/0-triage version/24.0
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Description

I use "docker run -itd -u 50294:50294 almalinux:8 /bin/bash" launch a container, then use root user permission enter the container do some operation "docker exec -it --user=root <container> /bin/bash".

  1. create then same UID user("jenkins") and UID group("jenkins")
  2. Create another group "docker"(GID:50000)
  3. Join the "jenkins" into the "docker" group

After that I use non-root user enter the container "docker exec -it <container> /bin/bash", then execute "id" and "id jenkins" command, it'll show different output

$ docker exec -it cranky_ardinghelli /bin/bash
[jenkins@6dd2b805c3d6 /]$ id 
uid=50294(jenkins) gid=50294(jenkins) groups=50294(jenkins)
[jenkins@6dd2b805c3d6 /]$ id jenkins
uid=50294(jenkins) gid=50294(jenkins) groups=50294(jenkins),50000(docker)
[jenkins@6dd2b805c3d6 /]$ 
Reproduce
$ docker run -itd -u 50294:50294 almalinux:8 /bin/bash
$ docker ps
CONTAINER ID   IMAGE                                        COMMAND                  CREATED          STATUS          PORTS     NAMES
6dd2b805c3d6   almalinux:8                                  "/bin/bash"              11 seconds ago   Up 10 seconds             cranky_ardinghelli
$ docker exec -it cranky_ardinghelli /bin/bash
bash-4.4$ id
uid=50294 gid=50294 groups=50294
bash-4.4$ exit
exit
$ docker exec -it --user=root cranky_ardinghelli /bin/bash
[root@6dd2b805c3d6 /]# groupadd -g 50294 jenkins && useradd -d /home/jenkins -m -u 50294 -g 50294 -s /bin/bash jenkins
[root@6dd2b805c3d6 /]# groupadd -g 50000 docker
[root@6dd2b805c3d6 /]# usermod -aG docker jenkins
[root@6dd2b805c3d6 /]# id jenkins
uid=50294(jenkins) gid=50294(jenkins) groups=50294(jenkins),50000(docker)
[root@6dd2b805c3d6 /]# exit
exit
$ docker exec -it cranky_ardinghelli /bin/bash
[jenkins@6dd2b805c3d6 /]$ id 
uid=50294(jenkins) gid=50294(jenkins) groups=50294(jenkins)
[jenkins@6dd2b805c3d6 /]$ id jenkins
uid=50294(jenkins) gid=50294(jenkins) groups=50294(jenkins),50000(docker)
[jenkins@6dd2b805c3d6 /]$ 
Expected behavior

Fix this, make "docker exec" have the correct permission

docker version
Client: Docker Engine - Community
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:36:32 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.5
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.6
  Git commit:       a61e2b4
  Built:            Fri Jul 21 20:35:32 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
docker info
Client: Docker Engine - Community
 Version:    24.0.5
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.20.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  scan: Docker Scan (Docker Inc.)
    Version:  v0.21.0
    Path:     /usr/libexec/docker/cli-plugins/docker-scan

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 22
 Server Version: 24.0.5
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
 runc version: v1.1.7-0-g860f061
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 4.18.0-477.21.1.el8_8.x86_64
 Operating System: AlmaLinux 8.8 (Sapphire Caracal)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.58GiB
 Name: jenkins-node-alma8
 ID: 1c007b45-4f34-41e8-ac74-12822b2fa8df
 Docker Root Dir: /data/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
Additional Info

This issue will block some jenkins job, example:
Use non-root jenkins run docker in docker(DinD or Docker socket mounting),
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the documented docker run and docker exec commands with the AlmaLinux 8 container, then trace the docker exec entry point and how its --user setting handles supplementary groups. Compare the id and id jenkins outputs before and after the in-container account changes. Done means the non-root exec process has the expected group permissions, with a regression test covering this sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, linux
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.