Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.22] run: add container gid to additional groups #4263

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2018,6 +2018,7 @@ func (b *Builder) configureUIDGID(g *generate.Generator, mountPoint string, opti
}
g.SetProcessUID(user.UID)
g.SetProcessGID(user.GID)
g.AddProcessAdditionalGid(user.GID)
for _, gid := range user.AdditionalGids {
g.AddProcessAdditionalGid(gid)
}
Expand Down
16 changes: 16 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ symlink(subdir)"
check_options_flag_err "--userns=cnt1"
}

@test "build test has gid in supplemental groups" {
_prefetch alpine
run_buildah build $WITH_POLICY_JSON -t source -f ${TESTSDIR}/bud/supplemental-groups/Dockerfile
# gid 1000 must be in supplemental groups
expect_output --substring "Groups: 1000"
}

@test "build test if supplemental groups has gid with --isolation chroot" {
test -z "${BUILDAH_ISOLATION}" || skip "BUILDAH_ISOLATION=${BUILDAH_ISOLATION} overrides --isolation"

_prefetch alpine
run_buildah build --isolation chroot $WITH_POLICY_JSON -t source -f ${TESTSDIR}/bud/supplemental-groups/Dockerfile
# gid 1000 must be in supplemental groups
expect_output --substring "Groups: 1000"
}

@test "bud with --layers and --no-cache flags" {
cp -a ${TESTSDIR}/bud/use-layers ${TESTDIR}/use-layers

Expand Down
3 changes: 3 additions & 0 deletions tests/bud/supplemental-groups/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine
USER 1000:1000
RUN cat /proc/$$/status
14 changes: 14 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,20 @@ function configure_and_check_user() {
expect_output "888:888"
}

@test "run --user and verify gid in supplemental groups" {
skip_if_no_runtime

# Create the container.
_prefetch alpine
run_buildah from $WITH_POLICY_JSON alpine
ctr="$output"

# Run with uid:gid 1000:1000 and verify if gid is present in additional groups
run_buildah run --user 1000:1000 "$ctr" cat /proc/self/status
# gid 1000 must be in additional/supplemental groups
expect_output --substring "Groups: 1000 "
}

@test "run --workingdir" {
skip_if_no_runtime

Expand Down