Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

sec-policy/*: sync with gentoo #1993

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

sec-policy/*: sync with gentoo #1993

wants to merge 17 commits into from

Conversation

tormath1
Copy link
Contributor

@tormath1 tormath1 commented Jun 28, 2022

In this PR, we upgrade selinux-{base,base-policy} to a more recent version (2022-01-06) and we drop selinux-virt. Two new policy modules have been added: selinux-docker and selinux-container.

We tried to align on the upstream but we still have some divergences:

  • torcx does run as unconfined (don't want to bother to write a custom module for it... as it might be soon deprecated)
  • added missing file contexts to the torcx image files
  • since Flatcar overuses systemd-tmpfiles, we're still missing some interfaces (see PRs)

Result from moving from selinux-virt to selinux-container:

  • docker process are running fine without patches
  • processes are labelled with spc_t for --privileged containers (TODO: add a test for it)

Closes: flatcar/Flatcar#479, flatcar/Flatcar#695

The system is now fully labeled:

Process contexts:
Current context:                system_u:system_r:unconfined_t:s0
Init context:                   system_u:system_r:init_t:s0

File contexts:
Controlling terminal:           system_u:object_r:user_devpts_t:s0
/etc/passwd                     system_u:object_r:etc_t:s0
/etc/shadow                     system_u:object_r:shadow_t:s0
/bin/bash                       system_u:object_r:shell_exec_t:s0
/bin/login                      system_u:object_r:login_exec_t:s0
/bin/sh                         system_u:object_r:bin_t:s0 -> system_u:object_r:shell_exec_t:s0
/sbin/agetty                    system_u:object_r:getty_exec_t:s0
/sbin/init                      system_u:object_r:bin_t:s0 -> system_u:object_r:init_exec_t:s0
/usr/sbin/sshd                  system_u:object_r:unconfined_exec_t:s0

in contrast with current stable:

Process contexts:
Current context:                system_u:system_r:kernel_t:s0
Init context:                   system_u:system_r:kernel_t:s0

File contexts:
Controlling terminal:           system_u:object_r:devpts_t:s0
/etc/passwd                     system_u:object_r:unlabeled_t:s0
/etc/shadow                     system_u:object_r:unlabeled_t:s0
/bin/bash                       system_u:object_r:unlabeled_t:s0
/bin/login                      system_u:object_r:unlabeled_t:s0
/bin/sh                         system_u:object_r:unlabeled_t:s0 -> system_u:object_r:unlabeled_t:s0
/sbin/agetty                    system_u:object_r:unlabeled_t:s0
/sbin/init                      system_u:object_r:unlabeled_t:s0 -> system_u:object_r:unlabeled_t:s0
/usr/sbin/sshd                  system_u:object_r:unlabeled_t:s0

Containerd and Docker are running with the correct labels:

core@localhost ~ $ ps auxZ | grep container
system_u:system_r:dockerd_t:s0  root         828  0.7  4.5 1421368 44856 ?       Ssl  08:45   0:00 /run/torcx/bin/containerd --config /run/torcx/unpack/docker/usr/share/containerd/config.toml
system_u:system_r:dockerd_t:s0  root         924  3.6  8.6 1456640 85892 ?       Ssl  08:45   0:00 /run/torcx/bin/dockerd --host=fd:// --containerd=/var/run/docker/libcontainerd/docker-containerd.sock --selinux-enabled=true

Correct processes labelling from inside a container:

core@localhost ~ $ docker run --privileged --rm -ti -d alpine sleep infinity
core@localhost ~ $ docker run --rm -ti -d alpine sleep infinity
core@localhost ~ $ ps auxZ | grep infinity
system_u:system_r:container_t:s0:c115,c639 root 1159 0.2  0.0 1596    4 pts/0    Ss+  08:46   0:00 sleep infinity
system_u:system_r:spc_t:s0      root        1234  0.4  0.0   1596     4 pts/0    Ss+  08:46   0:00 sleep infinity

TODO:

  • regen the manifest files for the cleanup of ebuilds

@tormath1 tormath1 self-assigned this Jun 28, 2022
@tormath1 tormath1 added the main label Jun 28, 2022
@tormath1 tormath1 force-pushed the tormath1/selinux branch 2 times, most recently from 7ed8c0f to 09877a3 Compare June 29, 2022 13:03
@tormath1 tormath1 changed the title wip: sec-policy/*: sync with gentoo sec-policy/*: sync with gentoo Jun 29, 2022
@tormath1 tormath1 force-pushed the tormath1/selinux branch 3 times, most recently from fab7151 to 5a65e94 Compare July 6, 2022 09:10
@krnowak
Copy link
Contributor

krnowak commented Jul 7, 2022

I would only want to ask you to keep only one ebuild per package, so it will be clear which ebuild is actually patched up by us. Thanks!

@tormath1
Copy link
Contributor Author

tormath1 commented Jul 7, 2022

I would only want to ask you to keep only one ebuild per package, so it will be clear which ebuild is actually patched up by us. Thanks!

I did or I missed one? If you just checked the Manifest that's normal, it's added in the TODO to regen the manifest otherwise it's in each "flatcar patches" commit (removed non-used ebuilds)

@krnowak
Copy link
Contributor

krnowak commented Jul 7, 2022

I would only want to ask you to keep only one ebuild per package, so it will be clear which ebuild is actually patched up by us. Thanks!

I did or I missed one? If you just checked the Manifest that's normal, it's added in the TODO to regen the manifest otherwise it's in each "flatcar patches" commit (removed non-used ebuilds)

Ah, sorry. I just remembered that we used to have more ebuilds in those packages and Manifest files confused me, apparently. :) Thanks for taking care of it.

@@ -1,3 +1,4 @@
#Type Path Mode UID GID Age Argument
d /etc/selinux/ - - - - -
L /etc/selinux/semanage.conf - - - - ../../usr/lib/selinux/semanage.conf
z /etc/selinux/semanage.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we instead do:

Z	/etc/selinux/

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we could try that.

Commit-Ref: c9baed78f05f99338abd378e4338ff6d2a9a509d

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
- removed non-used ebuilds
- added patch for ping
- run sshd (and child) as unconfined_t
- add init.patch to allow execute_no_trans,map and exec from init to unconfined
- add AVC patch for local login and journald

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Commit-Ref: c9baed78f05f99338abd378e4338ff6d2a9a509d

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
- remove non-used ebuilds
- added a patch for ping
- run sshd (and child) as unconfined_t
- add init.patch to allow execute_no_trans,map and
exec from init to unconfined
- add AVC patch for local login and journald
- enabled tunable_policy systemd_tmpfiles_manage_all

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
- removed non-used ebuilds
- add file context for torcx image

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
it pulls relabelling of some files

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
```
Jul 07 08:37:09 localhost audit[1363]: AVC avc:  denied  { getattr } for  pid=1363 comm="systemd-tmpfile" path="/etc/selinux/semanage.conf" dev="vda9" ino=27 scontext=system_u:system_r:systemd_tmpfiles_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=lnk_file permissive=1
```

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
otherwise it's keep the initrc_runtime_t label from the systemd unit
and it leads to denials.

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
- drop useless ebuilds
- add torcx docker patch

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants