Include profile kind in node status naming and validate SELinux profile names #3376
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/3376#" title="Author self-approved">saschagrunert</a>
The full list of commands accepted by this bot can be found here.
The pull request process is described here
<details >
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":[]} -->
Codecov Report
:x: Patch coverage is
42.25352% with 41 lines in your changes missing coverage. Please review.:white_check_mark: Project coverage is 25.98%. Comparing base (
11d77f4) to head (d35a992).:warning: Report is 1417 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## main #3376 +/- ##
===========================================
- Coverage 45.50% 25.98% -19.52%
===========================================
Files 79 132 +53
Lines 7782 18561 +10779
===========================================
+ Hits 3541 4824 +1283
- Misses 4099 13418 +9319
- Partials 142 319 +177
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
@kubernetes-sigs/security-profiles-operator-maintainers PTAL
is there a way to autodiscover instead of hardcode? this seems brittle and wouldn't work for other distros
Good point, replaced the hardcoded list with node-side autodiscovery. The daemon container now mounts /var/lib/selinux read-only and walks the host's module store (<policy_type>/active/modules/<priority>/<name>/) to detect conflicts before writing policy files. This works for any distro and requires no maintenance.
The tradeoff is that the check happens at install time (surfaced via SecurityProfileNodeStatus error state and events) rather than at admission time, but that's consistent with how other node-side validation failures are already reported.
return false missing?
Yes, added the missing return. 👍
haircommander
saschagrunert
What type of PR is this?
/kind feature
What this PR does / why we need it:
Two enhancements to improve profile management reliability:
1. Include profile kind in SecurityProfileNodeStatus naming: Changes status object names from
<profileName>-<nodeName>to<kind>-<profileName>-<nodeName>(e.g.,seccompprofile-myprofile-worker-1). This prevents collisions when a SelinuxProfile and SeccompProfile share the same name, which previously caused status objects to overwrite each other. Includes migration logic to clean up old-format objects on upgrade, with a label ownership check to prevent cross-profile deletion in edge cases.2. Validate SELinux profile names against system modules: At reconcile time on each node, the daemon checks whether a SELinux profile name conflicts with an existing module in the host's module store (
/var/lib/selinux). If a conflict is detected on first installation, the profile enters an error state with a descriptive event. The check is skipped on pod restarts and upgrades to avoid false positives.Which issue(s) this PR fixes:
None
Does this PR have test?
Yes. Unit tests for kind-based naming (
TestPerNodeStatusNameIncludesKind), legacy status migration (TestRemoveLegacyNodeStatus), and module conflict detection (TestIsSystemSELinuxModule).Special notes for your reviewer:
The system module check only runs on first install (
firstInstall = !wasMigrated). On upgrade, the legacy node status migration setswasMigrated = true, suppressing the check. On pod restart, the node status CRD persists in etcd, soExists()returns true and the check is skipped entirely.Does this PR introduce a user-facing change?
``
release-note
``SecurityProfileNodeStatus objects now include the profile kind in their name to prevent collisions between different profile types. SELinux profile names that conflict with system SELinux policy modules are rejected at reconcile time with a descriptive error event.