Skip to content

Groups for root user not applied during podman exec when no explicit user specified #25610

Closed
@bodobrand

Description

@bodobrand

Issue Description

Under certain conditions - specifically when the container relies on an implicit root user for each step - the Linux groups added to the root user in the Dockerfile do not apply to an interactive shell session started with podman exec -it ... /bin/sh. This issue also impacts any groups defined in the base image.

I am only able to reproduce this issue when the following conditions are met:

  • Building from a Dockerfile WITHOUT any USER directive
  • Podman run the image WITHOUT the --user parameter
  • Podman exec into the running container WITHOUT the --user parameter

Note: As soon as I add --user or the USER directive at any step I cannot reproduce this issue anymore.

Steps to reproduce the issue

Steps to reproduce the issue

  1. Create a Dockerfile with the following content:
FROM alpine

# for capsh --print
RUN apk add libcap

RUN addgroup -S appgroup && \
    adduser -S appuser -G appgroup && \
    addgroup root appgroup
  1. Build the image
podman build .
  1. Run the container (without the --user parameter).
podman run -itd $IMAGE /bin/sh
  1. Exec into the container (without the --user parameter).
podman exec -it $CONTAINER /bin/sh
  1. Verify that the root user does not have any group memberships in the current shell session:
# In the container
capsh --print | grep groups

Describe the results you received

/ # capsh --print | grep groups
groups=

Describe the results you expected

/ # capsh --print | grep groups
groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video),101(appgroup)

podman info output

Client:        Podman Engine
Version:       5.5.0-dev
API Version:   5.5.0-dev
Go Version:    go1.22.9 (Red Hat 1.22.9-2.el9_5)
Git Commit:    5eeaa437286c84ee29339911e68ec7957161b231
Built:         Tue Mar 11 01:00:00 2025
Build Origin:  Copr: rhcontainerbot/podman-next
OS/Arch:       linux/s390x

Podman in a container

No

Privileged Or Rootless

None

Upstream Latest Release

Yes

Additional environment details

No response

Additional information

No response

Metadata

Metadata

Assignees

Labels

jirakind/bugCategorizes issue or PR as related to a bug.locked - please file new issue/PRAssist humans wanting to comment on an old issue or PR with locked comments.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions