← Back to Pull requests

Include profile kind in node status naming and validate SELinux profile names #3376

Merged
saschagrunert merged 9 files (414 lines) on Aug 26, 2026 08:10 UTC
View on GitHub
saschagrunert saschagrunert commented on Aug 21, 2026 06:35 UTC
Author

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 sets wasMigrated = true, suppressing the check. On pod restart, the node status CRD persists in etcd, so Exists() 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.
``

Diff: 414 lines (+402 / -12) across 9 files Reviewer: haircommander Review duration: 7295m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.51) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.51 · 414 lines diff across 9 files
0.51
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 5 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
91%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.361
Real PR Conversation Timeline
8 items
kubernetes-prow[bot] kubernetes-prow[bot] commented on Aug 21, 2026 06:35 UTC
Bot

[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:

  • ~~OWNERS~~ [saschagrunert]
  • 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-commenter codecov-commenter commented on Aug 21, 2026 07:14 UTC
    Contributor

    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>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    saschagrunert saschagrunert commented on Aug 21, 2026 09:08 UTC
    Author

    @kubernetes-sigs/security-profiles-operator-maintainers PTAL

    haircommander haircommander commented on code on Aug 21, 2026 13:06 UTC
    Code Review
    internal/pkg/webhooks/validation/validation.go:1
    @@ -30,12 +31,131 @@ import (
     )
     
     // +kubebuilder:rbac:groups=security-profiles-operator.x-k8s.io,resources=rawselinuxprofiles,verbs=get;list;watch
    +// +kubebuilder:rbac:groups=security-profiles-operator.x-k8s.io,resources=selinuxprofiles,verbs=get;list;watch
    +
    +// systemSELinuxModules contains module names shipped in the base SELinux policy
    +// on RHEL, CentOS Stream, and Fedora. SPO installs modules at priority 350,
    +// overriding system modules at priority 100. If a user-created profile
    +// collides with one of these names, the system module is replaced, breaking
    +// types that other modules depend on (e.g., krb5_keytab_t from the kerberos
    +// module).
    +var systemSELinuxModules = map[string]bool{
    +	"abrt":           true,

    is there a way to autodiscover instead of hardcode? this seems brittle and wouldn't work for other distros

    saschagrunert saschagrunert commented on code on Aug 21, 2026 13:42 UTC
    Code Review
    internal/pkg/webhooks/validation/validation.go:1
    @@ -30,12 +31,131 @@ import (
     )
     
     // +kubebuilder:rbac:groups=security-profiles-operator.x-k8s.io,resources=rawselinuxprofiles,verbs=get;list;watch
    +// +kubebuilder:rbac:groups=security-profiles-operator.x-k8s.io,resources=selinuxprofiles,verbs=get;list;watch
    +
    +// systemSELinuxModules contains module names shipped in the base SELinux policy
    +// on RHEL, CentOS Stream, and Fedora. SPO installs modules at priority 350,
    +// overriding system modules at priority 100. If a user-created profile
    +// collides with one of these names, the system module is replaced, breaking
    +// types that other modules depend on (e.g., krb5_keytab_t from the kerberos
    +// module).
    +var systemSELinuxModules = map[string]bool{
    +	"abrt":           true,

    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.

    rphillips rphillips commented on code on Aug 22, 2026 01:21 UTC
    Code Review
    internal/pkg/nodestatus/nodestatus.go:1
    @@ -61,28 +65,66 @@ func NewForProfile(pol profilebase.SecurityProfileBase, c client.Client) (*Statu
     }
     
     func (nsf *StatusClient) perNodeStatusName() string {
    -	return nsf.pol.GetName() + "-" + nsf.nodeName
    +	kind := strings.ToLower(nsf.pol.GetObjectKind().GroupVersionKind().Kind)
    +
    +	return util.DNSLengthName(kind, "%s-%s-%s", kind, nsf.pol.GetName(), nsf.nodeName)
     }
     
     func (nsf *StatusClient) perNodeStatusNamespacedName() types.NamespacedName {
     	return util.NamespacedName(nsf.perNodeStatusName(), nsf.pol.GetNamespace())
     }
     
    -func (nsf *StatusClient) Create(ctx context.Context) error {
    +func (nsf *StatusClient) Create(ctx context.Context) (bool, error) {
     	if err := nsf.createFinalizer(ctx); err != nil {
    -		return fmt.Errorf("cannot create finalizer for %s: %w", nsf.pol.GetName(), err)
    +		return false, fmt.Errorf("cannot create finalizer for %s: %w", nsf.pol.GetName(), err)
     	}
     
     	if err := nsf.createPolLabel(ctx); err != nil {
    -		return fmt.Errorf("cannot create policy name label for %s: %w", nsf.pol.GetName(), err)
    +		return false, fmt.Errorf("cannot create policy name label for %s: %w", nsf.pol.GetName(), err)
     	}
     
    +	wasMigrated := nsf.removeLegacyNodeStatus(ctx)
    +
     	// if object does not exist, add it
     	if err := nsf.createNodeStatus(ctx); err != nil {
    -		return fmt.Errorf("cannot create node status for %s: %w", nsf.pol.GetName(), err)
    +		return false, fmt.Errorf("cannot create node status for %s: %w", nsf.pol.GetName(), err)
     	}
     
    -	return nil
    +	return wasMigrated, nil
    +}
    +
    +// removeLegacyNodeStatus removes old-format status objects that used
    +// <profileName>-<nodeName> instead of <kind>-<profileName>-<nodeName>.
    +// Returns true if a legacy status was found and removed (upgrade migration).
    +func (nsf *StatusClient) removeLegacyNodeStatus(ctx context.Context) bool {
    +	legacyName := nsf.pol.GetName() + "-" + nsf.nodeName
    +	if legacyName == nsf.perNodeStatusName() {
    +		return false
    +	}
    +
    +	old := &secprofnodestatusapi.SecurityProfileNodeStatus{}
    +	key := util.NamespacedName(legacyName, nsf.pol.GetNamespace())
    +
    +	if err := nsf.client.Get(ctx, key, old); err != nil {
    +		if !kerrors.IsNotFound(err) {
    +			log.Error(err, "failed to look up legacy node status", "name", legacyName)
    +		}
    +
    +		return false
    +	}
    +
    +	// Verify the object belongs to this profile. A profile named
    +	// "<kind>-<other>" has a legacy name that collides with the
    +	// new-format name of profile "<other>".
    +	if old.Labels[secprofnodestatusapi.StatusToProfLabel] != util.KindBasedDNSLengthName(nsf.pol) {
    +		return false
    +	}
    +
    +	if err := nsf.client.Delete(ctx, old); err != nil && !kerrors.IsNotFound(err) {
    +		log.Error(err, "failed to remove legacy node status", "name", legacyName)

    return false missing?

    saschagrunert saschagrunert commented on code on Aug 24, 2026 06:36 UTC
    Code Review
    internal/pkg/nodestatus/nodestatus.go:1
    @@ -61,28 +65,66 @@ func NewForProfile(pol profilebase.SecurityProfileBase, c client.Client) (*Statu
     }
     
     func (nsf *StatusClient) perNodeStatusName() string {
    -	return nsf.pol.GetName() + "-" + nsf.nodeName
    +	kind := strings.ToLower(nsf.pol.GetObjectKind().GroupVersionKind().Kind)
    +
    +	return util.DNSLengthName(kind, "%s-%s-%s", kind, nsf.pol.GetName(), nsf.nodeName)
     }
     
     func (nsf *StatusClient) perNodeStatusNamespacedName() types.NamespacedName {
     	return util.NamespacedName(nsf.perNodeStatusName(), nsf.pol.GetNamespace())
     }
     
    -func (nsf *StatusClient) Create(ctx context.Context) error {
    +func (nsf *StatusClient) Create(ctx context.Context) (bool, error) {
     	if err := nsf.createFinalizer(ctx); err != nil {
    -		return fmt.Errorf("cannot create finalizer for %s: %w", nsf.pol.GetName(), err)
    +		return false, fmt.Errorf("cannot create finalizer for %s: %w", nsf.pol.GetName(), err)
     	}
     
     	if err := nsf.createPolLabel(ctx); err != nil {
    -		return fmt.Errorf("cannot create policy name label for %s: %w", nsf.pol.GetName(), err)
    +		return false, fmt.Errorf("cannot create policy name label for %s: %w", nsf.pol.GetName(), err)
     	}
     
    +	wasMigrated := nsf.removeLegacyNodeStatus(ctx)
    +
     	// if object does not exist, add it
     	if err := nsf.createNodeStatus(ctx); err != nil {
    -		return fmt.Errorf("cannot create node status for %s: %w", nsf.pol.GetName(), err)
    +		return false, fmt.Errorf("cannot create node status for %s: %w", nsf.pol.GetName(), err)
     	}
     
    -	return nil
    +	return wasMigrated, nil
    +}
    +
    +// removeLegacyNodeStatus removes old-format status objects that used
    +// <profileName>-<nodeName> instead of <kind>-<profileName>-<nodeName>.
    +// Returns true if a legacy status was found and removed (upgrade migration).
    +func (nsf *StatusClient) removeLegacyNodeStatus(ctx context.Context) bool {
    +	legacyName := nsf.pol.GetName() + "-" + nsf.nodeName
    +	if legacyName == nsf.perNodeStatusName() {
    +		return false
    +	}
    +
    +	old := &secprofnodestatusapi.SecurityProfileNodeStatus{}
    +	key := util.NamespacedName(legacyName, nsf.pol.GetNamespace())
    +
    +	if err := nsf.client.Get(ctx, key, old); err != nil {
    +		if !kerrors.IsNotFound(err) {
    +			log.Error(err, "failed to look up legacy node status", "name", legacyName)
    +		}
    +
    +		return false
    +	}
    +
    +	// Verify the object belongs to this profile. A profile named
    +	// "<kind>-<other>" has a legacy name that collides with the
    +	// new-format name of profile "<other>".
    +	if old.Labels[secprofnodestatusapi.StatusToProfLabel] != util.KindBasedDNSLengthName(nsf.pol) {
    +		return false
    +	}
    +
    +	if err := nsf.client.Delete(ctx, old); err != nil && !kerrors.IsNotFound(err) {
    +		log.Error(err, "failed to remove legacy node status", "name", legacyName)

    Yes, added the missing return. 👍

    Reviewers
    Assignees
    saschagrunert saschagrunert
    Labels
    risk: low confidence: 91.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.8% (MEDIUM) · Higher = larger blast radius
    50.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.3% · Lower = rushed or shallow review
    91.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.4% · Safe to merge
    4.4%