Commit Graph

15 Commits

Author SHA1 Message Date
Jonah Bull 939a58b967
fix secret mounts for env vars when using chroot isolation
Before #5083, when running with chroot isolation ro mounts like secrets
from env vars would explicitly have the unix.MS_NOEXEC, unix.MS_NOSUID
and unix.MS_NODEV flags set when they were remounted. Now when running
with chroot isolation ro mounts like secrets from env vars are not
getting those same flags set and so the remount operation fails.
Specifically it looks like we are missing the unix.MS_NOSUID and
unix.MS_NODEV flags.

This change adds special handling for read-only mounts when we need to do
a remount to try to get the desired flags to stick. If we've requested
a read-only mount (unix.ST_RDONLY is set in requestFlags), then we add any
possibleImportantFlags that are set in fs.Flags to remountFlags so the remount
operation doesn't fail because they are missing. I've also added a test to
bud.bats that covers this case.

Signed-off-by: Jonah Bull <jonah.bull@elastic.co>
2024-05-25 15:49:51 -05:00
Nalin Dahyabhai 2a3a956cbb chroot.setupChrootBindMounts: pay more attention to flags
Pay better attention to dev/nodev/exec/noexec/suid/nosuid/ro/rw flags on
bind, overlay, and tmpfs mounts when any of them are specified.  Stop
quietly adding "nodev" when it isn't asked for.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-10-20 09:46:58 -04:00
Giuseppe Scrivano ffb00243f1
chroot: fix mounting of ro bind mounts
a bind mount cannot be made RDONLY in the same mount operation as it
is created.  For that we need a second operation.

Closes: https://github.com/containers/buildah/issues/4203

[NO NEW TESTS NEEDED] it fails in Buildah in a container

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-11-01 21:20:15 +01:00
Daniel J Walsh 8d5d763213
Fix stutters
Podman adds an Error: to every error message. So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-19 07:11:44 -04:00
Doug Rabson 309f714b5f chroot: Move isDevNull to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:48 +01:00
Doug Rabson 363bf9c5bc chroot: Fix setRlimit build on FreeBSD
On FreeBSD, members of the rlimit structure are signed, not unsigned.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:48 +01:00
Doug Rabson dc49c3cb4d chroot: Move parseRLimits and setRlimits to run_common.go
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:47 +01:00
Doug Rabson b64d814325 chroot: Fix runUsingChrootExecMain on FreeBSD
This adds no-op stubs for various things and adds an optional override
for creating the container chroot - on FreeBSD we use a jail to allow
setting the container hostname.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:47 +01:00
Doug Rabson 4d963eb5e1 chroot: Move runUsingChrootExecMain to run_common.go
Again, this breaks the FreeBSD build and this will be addressed by
refactoring in the next commit.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:47 +01:00
Doug Rabson 0a61e4b280 chroot: Factor out Linux-specific unshare options from runUsingChroot
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:47 +01:00
Doug Rabson 3b42b51524 chroot: Move runUsingChroot to run_common.go
This intentionally breaks the FreeBSD so that I can move the code
unmodified which will help with future merge conflicts. A subsequent
commit will resolve this by factoring out Linux-specific code.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:47 +01:00
Doug Rabson 350c509ecf chroot: Move RunUsingChroot and runUsingChrootMain to run_common.go
This leaves runUsingChrootSubprocOptions in the platform-specific file
since syscall.SysProcIDMap isn't available on FreeBSD.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:47 +01:00
Doug Rabson 188dcc3608 chroot: Factor out /dev/ptmx pty implementation
The ptmx device is fairly common and this code could be used on
platforms other than Linux.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-09-01 13:50:47 +01:00
Nalin Dahyabhai bb149ea686 Use errors.Is() instead of os.Is{Not,}Exist
If errors for which os.IsExist() or os.IsNotExist() would have returned
true have been wrapped using fmt.Errorf()'s "%w" verb, os.IsExist() and
os.IsNotExist(), not having been retrofitted to use errors.Is(), will
return false.

Use errors.Is() to check if an error is an os.ErrExist or os.ErrNotExist
error instead of calling os.IsExist() or os.IsNotExist().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-07-26 15:36:58 -04:00
Doug Rabson ac4b39a220 Rename chroot/run.go to chroot/run_linux.go
This is a precursor to adding isolation=chroot support for
FreeBSD.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-07-25 11:28:51 +01:00