7 Commits

Author SHA1 Message Date
Jan Safranek
eeabc3ac6c selinux: Ignore pods with Recursive policy
Pod that explicitly opted into "seLinuxChangePolicy: Recursive" should not
report conflicts with another SELinux labels. They will only report a
conflict with other Pods using the same volume with "seLinuxChangePolicy:
Mount" (or nil).
2025-02-25 16:34:02 +01:00
Jan Safranek
2050d6fc69 selinux: add a new SELinux translator to the controller
A real SELinuxOptionsToFileLabel function needs access to host's
/etc/selinux to read the defaults. This is not possible in
kube-controller-manager that often runs in a container and does not have
access to /etc on the host. Even if it had, it could run on a different
Linux distro than worker nodes.

Therefore implement a custom SELinuxOptionsToFileLabel that does not
default fields in SELinuxOptions and uses just fields provided by the Pod.

Since the controller cannot default empty SELinux label components,
treat them as incomparable.
Example: "system_u:system_r:container_t:s0:c1,c2" *does not* conflict with ":::s0:c1,c2",
because the node that will run such a Pod may expand "":::s0:c1,c2" to "system_u:system_r:container_t:s0:c1,c2".
However, "system_u:system_r:container_t:s0:c1,c2" *does* conflict with ":::s0:c98,c99".
2025-02-17 13:32:10 +01:00
Jan Safranek
cf7a2c7d35 Add a comment why PVC indexer is used 2024-11-06 11:16:06 +01:00
Jan Safranek
e6807a8e4f Use _ for unused parameters
Sometimes the logger is not used. This fixes some linter warnings.
2024-11-06 11:16:06 +01:00
Jan Safranek
dfb88095b0 Rename label to seLinuxLabel
In various parameters, variables and fields. To make the name more
obvious.
2024-11-06 11:16:06 +01:00
Jan Safranek
e438bc0561 Rework event recorder startup
* Remove Controller.recorder field, there already is eventRecorder.
* Start the event broadcaster in Run(), to save a bit of CPU and memory
  when something initializes the controller, but does not Run() it.
* Log events with log level 3, as the other contollers usually do.
* Use StartStructuredLogging(), which looks fancier than StartLogging
2024-11-06 11:16:06 +01:00
Jan Safranek
aa8872d7a3 Add SELinux warning controller 2024-11-06 11:16:02 +01:00