-
Notifications
You must be signed in to change notification settings - Fork 789
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
fix secret mounts for env vars when using chroot isolation #5544
fix secret mounts for env vars when using chroot isolation #5544
Conversation
Looks like my initial naive attempt doesn't quite work. I'll poke at getting the unit tests passing (they are failing on |
Before containers#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>
1ec9bc8
to
939a58b
Compare
Thanks @jonahbull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: giuseppe, jonahbull, rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
What this PR does / why we need it:
As discussed in #5185, attempting to build an image that uses environmental variables as build secrets fails with the message:
In my particular use case, this is using the VFS storage driver and chroot isolation. I haven't been able to reproduce using other isolation types, not sure if other folks have.
As far as I can tell, the cause is that before #5083, when running with
chroot
isolationro
mounts like secrets from env vars would explicitly have theunix.MS_NOEXEC
,unix.MS_NOSUID
,unix.MS_NODEV
flags set when they were remounted: https://github.com/containers/buildah/pull/5083/files#diff-c287fcc22d32f0775a98f65ec2db880f887c6c392f8e5ed6d7320a24560c1949L468.Now when running with
chroot
isolationro
mounts like secrets from env vars are not getting those same flags set and so the remount operation fails. Specifically it looks like in this case we are missing theunix.MS_NOSUID
andunix.MS_NODEV
flags.I think the flags aren't being set because when we calculate
effectiveUnimportantFlags
here, we end up with0b100000
. Forgive the possibly overly-verbose notes here, but I'm not well-versed in these kinds of bitwise operations so it was helpful for me to add as much detail as possible when debugging.When we pass effectiveUnimportantFlags to
mountFlagsForFSFlags
, none of the possible fsFlags match0b100000
, so it returns0b0
.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 inrequestFlags
), then we add anypossibleImportantFlags
that are set infs.Flags
toremountFlags
so the remount operation doesn't fail because they are missingHow to verify it
I've added a test to
bud.bats
that reproduces the issue when run locally with a version of buildah that doesn't have the fix applied.I could definitely have missed something, but this change appears to fix the issue in #5185 without breaking other use cases, at least from my limited local testing (running the
bud.bats
andchroot.bats
suites).Which issue(s) this PR fixes:
Fixes #5185
Special notes for your reviewer:
Does this PR introduce a user-facing change?