Re: Setting context in early boot

Ondrej Mosnacek <[email protected]> Thu, 8 Sep 2022 11:23:22 +0200
Newsgroups gmane.linux.redhat.fedora.selinux
Message-ID <CAFqZXNvD5brs=CwBy5zYSQAai29eeGsHNcFAqA35GHOKN4zi2g@mail.gmail.com>
On Mon, Sep 5, 2022 at 8:52 PM Frederick Grose <[email protected]> wrote:
> I have a general scoping question on setting SELinux context on files/directories during early boot.
> I'm working on a feature in dracut to implement general stacking of filesystem hierarchies via OverlayFS for the root filesystem within the dmsquash-live-root module.
> How should I address the setting of context for new files, directories, or links needed to assemble the components for the OverlayFS mount?
>
> For example, when I
>   mkdir -m 0755 -p --context=system_u:object_r:root_t:s0 /run/somemountpoint
> I get this warning in the journal:
>   mkdir: warning: ignoring --context; it requires an SELinux/SMACK-enabled kernel
>
> If the SELinux code is not active at this early stage, what is to be done?

Tools that use libselinux to set labels will probably refuse to work
with SELinux policy not yet loaded, but if you have a recent enough
kernel (5.5+), it should be possible to set the extended attribute
manually - for example using setfattr:

mkdir -m 0755 -p /run/somemountpoint
setfattr -n security.selinux -v system_u:object_r:root_t:s0 /run/somemountpoint

-- 
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
_______________________________________________
selinux mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/[email protected]
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue