Hi,
I tried a lot of things but failed so far to add additional rootfs mount options when starting a lxc container.
I am developing a SELinux module for incus/incusd.
I can set for example
raw.lxc: |
lxc.selinux.context = system_u:system_r:spc_t:s0:c100
which works so far, so the container process runs in this domain.
But the rootfs and all files below it are labeled unlabeled_t
which is bad. What other container systems do today is to add a mount option for the rootfs like context=system_u:system_r:container_file_t:s0:c100
.
Is there any way to do that in current version (6.1)?
I am using the ZFS storage driver.
What I tried already:
- lxc.rootfs.options
raw.lxc: |
lxc.rootfs.options = idmap=container,context=system_u:system_r:container_file_t:s0:c100
but this ends up as a second line for lxc.rootfs.options
and seems to be ignored
- lxc.hook.pre-start
raw.lxc: |
lxc.hook.pre-start = /usr/local/bin/lxc_rootfs_label.sh
#!/usr/bin/env bash
sed -i '/^lxc.rootfs.options/ s/$/,context=system_u:system_r:container_file_t:s0:c100/' "$LXC_CONFIG_FILE"
This hook is being executed, the resulting lxc.conf
has context= added as I want it.
But in any case, the result is the same:
+ incus exec first -- ls -lZ /
total 96
lrwxrwxrwx. 1 root root system_u:object_r:unlabeled_t:s0 7 Jul 3 07:43 bin -> usr/bin
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 Apr 18 2022 boot
drwxr-xr-x. 8 root root system_u:object_r:initrc_state_t:s0 480 Jul 3 20:12 dev
drwxr-xr-x. 62 root root system_u:object_r:unlabeled_t:s0 126 Jul 3 07:44 etc
drwxr-xr-x. 3 root root system_u:object_r:unlabeled_t:s0 3 Jul 3 07:44 home
lrwxrwxrwx. 1 root root system_u:object_r:unlabeled_t:s0 7 Jul 3 07:43 lib -> usr/lib
lrwxrwxrwx. 1 root root system_u:object_r:unlabeled_t:s0 9 Jul 3 07:43 lib64 -> usr/lib64
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 Jul 3 07:43 media
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 Jul 3 07:43 mnt
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 Jul 3 07:43 opt
dr-xr-xr-x. 575 nobody nogroup system_u:object_r:proc_t:s0 0 Jul 3 20:12 proc
drwx------. 2 root root system_u:object_r:unlabeled_t:s0 4 Jul 3 07:43 root
drwxr-xr-x. 5 root root system_u:object_r:container_tmpfs_t:s0:c100 100 Jul 3 20:12 run
lrwxrwxrwx. 1 root root system_u:object_r:unlabeled_t:s0 8 Jul 3 07:43 sbin -> usr/sbin
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 Jul 3 07:43 srv
dr-xr-xr-x. 13 nobody nogroup system_u:object_r:sysfs_t:s0 0 May 10 13:29 sys
drwxrwxrwt. 2 root root system_u:object_r:unlabeled_t:s0 2 Jul 3 07:43 tmp
drwxr-xr-x. 12 root root system_u:object_r:unlabeled_t:s0 12 Jul 3 07:43 usr
drwxr-xr-x. 12 root root system_u:object_r:unlabeled_t:s0 13 Jul 3 07:43 var
+ ls -lZ /var/lib/incus/containers/first/rootfs/
total 130
lrwxrwxrwx. 1 root root system_u:object_r:unlabeled_t:s0 7 3. Jul 09:43 bin -> usr/bin
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 18. Apr 2022 boot
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 3. Jul 09:48 dev
drwxr-xr-x. 62 root root system_u:object_r:unlabeled_t:s0 126 3. Jul 09:44 etc
drwxr-xr-x. 3 root root system_u:object_r:unlabeled_t:s0 3 3. Jul 09:44 home
lrwxrwxrwx. 1 root root system_u:object_r:unlabeled_t:s0 7 3. Jul 09:43 lib -> usr/lib
lrwxrwxrwx. 1 root root system_u:object_r:unlabeled_t:s0 9 3. Jul 09:43 lib64 -> usr/lib64
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 3. Jul 09:43 media
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 3. Jul 09:43 mnt
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 3. Jul 09:43 opt
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 18. Apr 2022 proc
drwx------. 2 root root system_u:object_r:unlabeled_t:s0 4 3. Jul 09:43 root
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 3. Jul 09:44 run
lrwxrwxrwx. 1 root root system_u:object_r:unlabeled_t:s0 8 3. Jul 09:43 sbin -> usr/sbin
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 3. Jul 09:43 srv
drwxr-xr-x. 2 root root system_u:object_r:unlabeled_t:s0 2 18. Apr 2022 sys
drwxrwxrwt. 2 root root system_u:object_r:unlabeled_t:s0 2 3. Jul 09:43 tmp
drwxr-xr-x. 12 root root system_u:object_r:unlabeled_t:s0 12 3. Jul 09:43 usr
drwxr-xr-x. 12 root root system_u:object_r:unlabeled_t:s0 13 3. Jul 09:43 var
Am I missing something?
I am quite new to incus or lxc so there might be something I misunderstood or that I am assuming which is not the case…