Skip to content

Commit

Permalink
Merge pull request #5544 from jonahbull/fix-up-env-var-secret-mounts-…
Browse files Browse the repository at this point in the history
…for-chroot-isolation

fix secret mounts for env vars when using chroot isolation
  • Loading branch information
openshift-merge-bot[bot] authored May 27, 2024
2 parents bb4c8b0 + 939a58b commit 6ad7efb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion chroot/run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,12 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func(
if effectiveImportantFlags != expectedImportantFlags {
// Do a remount to try to get the desired flags to stick.
effectiveUnimportantFlags := uintptr(fs.Flags) & ^possibleImportantFlags
if err = unix.Mount(target, target, m.Type, unix.MS_REMOUNT|bindFlags|requestFlags|mountFlagsForFSFlags(effectiveUnimportantFlags), ""); err != nil {
remountFlags := unix.MS_REMOUNT | bindFlags | requestFlags | mountFlagsForFSFlags(effectiveUnimportantFlags)
// If we are requesting a read-only mount, add any possibleImportantFlags present in fs.Flags to remountFlags.
if requestFlags&unix.ST_RDONLY == unix.ST_RDONLY {
remountFlags |= uintptr(fs.Flags) & possibleImportantFlags
}
if err = unix.Mount(target, target, m.Type, remountFlags, ""); err != nil {
return undoBinds, fmt.Errorf("remounting %q in mount namespace with flags %#x instead of %#x: %w", target, requestFlags, effectiveImportantFlags, err)
}
// Check if the desired flags stuck.
Expand Down
9 changes: 9 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6825,3 +6825,12 @@ _EOF
# both of these should have just been the base image's ID, which shouldn't have changed the second time around
cmp ${TEST_SCRATCH_DIR}/image1.txt ${TEST_SCRATCH_DIR}/image2.txt
}

# Verify: https://github.com/containers/buildah/issues/5185
@test "build-test --mount=type=secret test from env with chroot isolation" {
skip_if_root_environment "Need to not be root for this test to work"
local contextdir=$BUDFILES/secret-env
export MYSECRET=SOMESECRETDATA
run_buildah build $WITH_POLICY_JSON --no-cache --isolation chroot --secret id=MYSECRET -t test -f $contextdir/Dockerfile
expect_output --substring "SOMESECRETDATA"
}
3 changes: 3 additions & 0 deletions tests/bud/secret-env/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine
RUN --mount=type=secret,id=MYSECRET \
printf "%s\n" $(cat /run/secrets/MYSECRET)

1 comment on commit 6ad7efb

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.