|
|
528637 |
From 9934b17365083ce966b44c5ce3c7e052f516e255 Mon Sep 17 00:00:00 2001
|
|
|
528637 |
From: Aditya R <arajan@redhat.com>
|
|
|
528637 |
Date: Wed, 24 Aug 2022 08:42:23 +0530
|
|
|
528637 |
Subject: [PATCH] run: add container gid to additional groups
|
|
|
528637 |
|
|
|
528637 |
When container is created with specific uid and gid also add container
|
|
|
528637 |
gid to supplementary/additional group.
|
|
|
528637 |
|
|
|
528637 |
Signed-off-by: Aditya R <arajan@redhat.com>
|
|
|
528637 |
---
|
|
|
528637 |
run_common.go | 1 +
|
|
|
528637 |
tests/bud.bats | 16 ++++++++++++++++
|
|
|
528637 |
tests/bud/supplemental-groups/Dockerfile | 3 +++
|
|
|
528637 |
tests/run.bats | 14 ++++++++++++++
|
|
|
528637 |
4 files changed, 34 insertions(+)
|
|
|
528637 |
create mode 100644 tests/bud/supplemental-groups/Dockerfile
|
|
|
528637 |
|
|
|
528637 |
diff --git a/run_common.go b/run_common.go
|
|
|
528637 |
index 2054c56527..f5a5ec8505 100644
|
|
|
528637 |
--- a/run_common.go
|
|
|
528637 |
+++ b/run_common.go
|
|
|
528637 |
@@ -262,6 +262,7 @@ func (b *Builder) configureUIDGID(g *generate.Generator, mountPoint string, opti
|
|
|
528637 |
}
|
|
|
528637 |
g.SetProcessUID(user.UID)
|
|
|
528637 |
g.SetProcessGID(user.GID)
|
|
|
528637 |
+ g.AddProcessAdditionalGid(user.GID)
|
|
|
528637 |
for _, gid := range user.AdditionalGids {
|
|
|
528637 |
g.AddProcessAdditionalGid(gid)
|
|
|
528637 |
}
|
|
|
528637 |
diff --git a/tests/bud.bats b/tests/bud.bats
|
|
|
528637 |
index a37e418b41..07bdf45cac 100644
|
|
|
528637 |
--- a/tests/bud.bats
|
|
|
528637 |
+++ b/tests/bud.bats
|
|
|
528637 |
@@ -366,6 +366,22 @@ _EOF
|
|
|
528637 |
expect_output --substring "invalid response status"
|
|
|
528637 |
}
|
|
|
528637 |
|
|
|
528637 |
+@test "build test has gid in supplemental groups" {
|
|
|
528637 |
+ _prefetch alpine
|
|
|
528637 |
+ run_buildah build $WITH_POLICY_JSON -t source -f $BUDFILES/supplemental-groups/Dockerfile
|
|
|
528637 |
+ # gid 1000 must be in supplemental groups
|
|
|
528637 |
+ expect_output --substring "Groups: 1000"
|
|
|
528637 |
+}
|
|
|
528637 |
+
|
|
|
528637 |
+@test "build test if supplemental groups has gid with --isolation chroot" {
|
|
|
528637 |
+ test -z "${BUILDAH_ISOLATION}" || skip "BUILDAH_ISOLATION=${BUILDAH_ISOLATION} overrides --isolation"
|
|
|
528637 |
+
|
|
|
528637 |
+ _prefetch alpine
|
|
|
528637 |
+ run_buildah build --isolation chroot $WITH_POLICY_JSON -t source -f $BUDFILES/supplemental-groups/Dockerfile
|
|
|
528637 |
+ # gid 1000 must be in supplemental groups
|
|
|
528637 |
+ expect_output --substring "Groups: 1000"
|
|
|
528637 |
+}
|
|
|
528637 |
+
|
|
|
528637 |
# Test skipping images with FROM
|
|
|
528637 |
@test "build-test skipping unwanted stages with FROM" {
|
|
|
528637 |
mkdir -p ${TEST_SCRATCH_DIR}/bud/platform
|
|
|
528637 |
diff --git a/tests/bud/supplemental-groups/Dockerfile b/tests/bud/supplemental-groups/Dockerfile
|
|
|
528637 |
new file mode 100644
|
|
|
528637 |
index 0000000000..462d9ea7a4
|
|
|
528637 |
--- /dev/null
|
|
|
528637 |
+++ b/tests/bud/supplemental-groups/Dockerfile
|
|
|
528637 |
@@ -0,0 +1,3 @@
|
|
|
528637 |
+FROM alpine
|
|
|
528637 |
+USER 1000:1000
|
|
|
528637 |
+RUN cat /proc/$$/status
|
|
|
528637 |
diff --git a/tests/run.bats b/tests/run.bats
|
|
|
528637 |
index 2e8836c470..e34091fcbe 100644
|
|
|
528637 |
--- a/tests/run.bats
|
|
|
528637 |
+++ b/tests/run.bats
|
|
|
528637 |
@@ -349,6 +349,20 @@ function configure_and_check_user() {
|
|
|
528637 |
expect_output "888:888"
|
|
|
528637 |
}
|
|
|
528637 |
|
|
|
528637 |
+@test "run --user and verify gid in supplemental groups" {
|
|
|
528637 |
+ skip_if_no_runtime
|
|
|
528637 |
+
|
|
|
528637 |
+ # Create the container.
|
|
|
528637 |
+ _prefetch alpine
|
|
|
528637 |
+ run_buildah from $WITH_POLICY_JSON alpine
|
|
|
528637 |
+ ctr="$output"
|
|
|
528637 |
+
|
|
|
528637 |
+ # Run with uid:gid 1000:1000 and verify if gid is present in additional groups
|
|
|
528637 |
+ run_buildah run --user 1000:1000 "$ctr" cat /proc/self/status
|
|
|
528637 |
+ # gid 1000 must be in additional/supplemental groups
|
|
|
528637 |
+ expect_output --substring "Groups: 1000 "
|
|
|
528637 |
+}
|
|
|
528637 |
+
|
|
|
528637 |
@test "run --workingdir" {
|
|
|
528637 |
skip_if_no_runtime
|
|
|
528637 |
|