-
Notifications
You must be signed in to change notification settings - Fork 27
Ensure SELinux label policy is applied when merging image layers #626
Conversation
The merge shouldn't introduce any new files or directories though; we should always be taking the underlying object. So I think this will just unnecessarily force us to recompute the labels without fixing the core bug from #388 right? |
So the relationship to #388 may not be there but there is a noticeable difference in result nonetheless. tl;dr: The merge commit seems to relabel files based on the context in which the merge commit happens rather than the policy of the base commit. Working shown in (possibly overenthusiastic) detail below. The scenario I'm working with here is that I've got an ostree commit created using When I run this process without this patch, I see an oddly large number of changes between the base commit and the commit based off the new container image:
Examining this more closely we see some additions we expect:
But we also see a bunch of file modifications that seem unnecessary, to pick one example out of this case a whole bunch of zoneinfo files have changed:
Digging in to these we see that the only change is in the metadata, and the only change there is to the label:
So the next question is when did the label change happen? Luckily we can examine the individual layer commits. I see four of those and examining each we see:
So the only place that directory shows up is in that last layer and with the correct label and, confirming a suspicion:
Yep, it's the same as the base commit. So the only operation that touched that label was the merge commit. Doing the process again but with the patch to add the SELinux policy during the merge commit:
That seems more like what I expected, as does this:
|
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.
OK so you're seeing this skew when running in a container; makes sense. But wait ugh...that implies that the labels we've been using for layers actually use whatever we see from the raw xattrs, but...
OK in your case when you were pulling into a repo in a container image, were you using an archive
mode or bare-user
? You must have been.
I think this bug will only occur when operating on one of those repo modes, because when operating on bare repos the checkout will always see the right xattrs.
Hmm it's a bit unfortunate here because I think this may actually force the normal "bare" repo case to do another trip through all the 4000 regexps in the policy to handle labeling for each file.
Utimately composefs is going to make this 1000% saner, but doing a hard switch to that gets tricky.
This has some bearing on #388.
When importing a container image via
ostree container image pull ...
, care is taken to maintain SELinux label policy when importing the layers, vis:ostree-rs-ext/lib/src/container/store.rs
Lines 869 to 876 in 9a4743a
and then in
write_tar
itself:ostree-rs-ext/lib/src/tar/write.rs
Lines 335 to 343 in 9a4743a
However when it comes time to merge these layers with the base commit, we fail to apply the SELinux policy of the base commit:
ostree-rs-ext/lib/src/container/store.rs
Lines 973 to 985 in 9a4743a
This change adds a call to
ostree::RepoCommitModifier::set_sepolicy_from_commit()
to ensure that the SELinux labelling is consistent with the base commit.