-
Notifications
You must be signed in to change notification settings - Fork 30
Nodes created/touched by Ignition lack the proper selinux labels #2417
Comments
I find the term "node" to mean "file" to be rather confusing 😄 Policy should have already been loaded by the time ignition runs - systemd does it very early in the initramfs. I think this is probably just a matter of telling libselinux to look in I may be missing something. |
I definitely vote for Ignition generates this unit in the files stage, but do think the possible race condition there is not ideal. Is there any possibility of an intermediate "query what the policy would be for this given file given this policy" without fully loading the selinux policy into the initramfs systemd? |
@cgwalters it's the phrasing the code base uses to refer to a generic file/directory/link, if you're got better terminology I'd be happy to use it. So Ignition could call I hadn't seen that function before. |
@cgwalters Ignition internally uses "node" for file-like things (e.g. dirs, regular files, links, etc) and "file" for regular files. In practice we're pretty bad at using precise langauge when discussing things. Another issue with the systemd unit is the contents of that unit are tied to the OS and it's units. I don't particularly want an entire unit sitting in |
@ajeddeloh I intend for just the |
A unit can't really be distro independent. What if |
@ajeddeloh ah yeah, that's fair. I'm leaning towards the second option here anyway. If |
I just made a patch that has Ignition call The function returns successfully but files created by Ignition are still unlabeled, so unless I'm missing something there I don't believe that will work for this use case. |
yeah. this is probably because we exec to run other binaries in their own process. It's possible if we stay in our own process using a go selinux library and then call the equivalent of restorecon it might work. |
So, to summarize my findings here (though note my perspective is from getting this working on an OSTree-based system, not CL):
So the obvious thing to do is to teach ignition to load the policy. This is what this PR does: It feels a bit awkward to do this in Ignition, given that this affects the whole initramfs environment. At the same time, this is right before we pivot, and systemd prompty reloads it again right after, so we're talking about a pretty thin time window. Though I'm open to doing this somewhere else (a new flag to With the PR above, I was able to boot RHCOS in enforcing mode without issues. |
Moved to coreos/ignition#591. |
Issue Report
Bug
Environment
All distros with selinux enabled
Expected Behavior
Filesystem nodes created by Ignition receive the correct default selinux labels for their location
Actual Behavior
Nodes created by Ignition lack a selinux label (
ls -Z
showssystem_u:object_r:unlabeled_t:s0
)Other Information
When a node (i.e. files, dirs, and links) is created on a distro with selinux a default label is applied to the node based on the selinux policies. These selinux policies are stored on disk, and on a typical distro with selinux enabled (Fedora 27 is what I'm testing on) these policies are loaded in after the switch-root occurs. This means that any node created by Ignition lacks the proper default selinux label. One side effect of this is that when Ignition creates a user
/etc/{passwd,shadow,group}
become unlabeled,sssd.service
fails to start as a result, and then the machine doesn't fully boot.I asked Dan Walsh the following:
His answer was:
So loading in the selinux policies in the initramfs would be a fairly involved solution to this.
Luckily Ignition knows which nodes it creates, so a far easier solution would be to call
restorecon
on the touched nodes once the policies have been loaded. Having Ignition create a unit like this resulted in a Fedora machine successfully booting in my testing.This leaves the question of what creates this unit. I see two options:
restorecon
could be set in theinternal/distro
package, and if the file exists in the root fs then Ignition will add/enable this generated unit. This approach somewhat breaks the Ignition model by being dependent on work post switch-root, but this work would happen as early as possible after that point. It should be safe to always generate this unit whenrestorecon
exists, since having things labeled properly on systems with selinux disabled won't affect things.ct
equivalent that doesn't exist yet) is responsible for generating this unit and including it in the config. This approach makes hand writing Ignition configs that don't break machines much trickier, since the config author would need to manually generate this unit.Which option should I take?
And as a side note, I'm going to add the ability to manually set extended attributes on nodes eventually. Any node that has
security.selinux
set for it in the config wouldn't be included in the list of nodes to be relabeled.The text was updated successfully, but these errors were encountered: