Skip to content

ROX-34164: Validation checks in exclusion scope#20049

Draft
clickboo wants to merge 1 commit intomasterfrom
boo-fix-exclusion-validation
Draft

ROX-34164: Validation checks in exclusion scope#20049
clickboo wants to merge 1 commit intomasterfrom
boo-fix-exclusion-validation

Conversation

@clickboo
Copy link
Copy Markdown
Contributor

@clickboo clickboo commented Apr 16, 2026

Description

Problem (before)

Policy exclusions accept a Scope which includes cluster_label and namespace_label fields, however label matchers are not supported in exclusions and do not resolve at runtime.

If a user sets cluster_label or namespace_label on an exclusion scope:

  • Validation passes without error
  • At match time, MatchesClusterLabels/MatchesNamespaceLabels detects the nil provider and returns false
  • The policy applies more broadly than intended - deployments the user expected to be excluded still trigger violations, but there is no user visible error.

Behavior (after)

  • validateDeploymentExclusion rejects cluster_label and namespace_label on exclusion scopes with a clear user visible error message
  • The nil-provider guard in MatchesClusterLabels/MatchesNamespaceLabels is upgraded from log.Error to utils.Should so that it panics in dev/test builds, logs in release. It is noted that this path is unreachable in production code.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

CI + Manual

ksanchet@ksanchet-mac:~/go/src/github.com/stackrox/stackrox$ curl -k -X POST 'https://localhost:8000/v1/policies' \
>   -u 'admin:<password>' \
>   -H 'Content-Type: application/json' \
>   -d '{
>     "name": "My Test Policy",
>     "description": "Policy with cluster label exclusion",
>     "severity": "LOW_SEVERITY",
>     "categories": ["DevOps Best Practices"],
>     "lifecycleStages": ["DEPLOY"],
>     "eventSource": "NOT_APPLICABLE",
>     "policyVersion": "1.1",
>     "policySections": [
>       {
>         "policyGroups": [
>           {
>             "fieldName": "Image Registry",
>             "values": [
>               { "value": "docker.io" }
>             ]
>           }
>         ]
>       }
>     ],
>     "exclusions": [
>       {
>         "name": "Exclude by cluster label",
>         "deployment": {
>           "scope": {
>             "clusterLabel": {
>               "key": "env",
>               "value": "staging"
>             }
>           }
>         }
>       }
>     ]
>   }'
{"code":3,"message":"policy invalid error: exclusion scopes do not support cluster labels: invalid arguments","details":[],"error":"policy invalid error: exclusion scopes do not support cluster labels: invalid arguments"

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 16, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.64%. Comparing base (13998bd) to head (769f460).
⚠️ Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
pkg/scopecomp/scope.go 0.00% 2 Missing ⚠️
central/policy/service/validator.go 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20049      +/-   ##
==========================================
+ Coverage   49.62%   49.64%   +0.02%     
==========================================
  Files        2765     2765              
  Lines      208599   208826     +227     
==========================================
+ Hits       103511   103669     +158     
- Misses      97435    97493      +58     
- Partials     7653     7664      +11     
Flag Coverage Δ
go-unit-tests 49.64% <75.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 16, 2026

🚀 Build Images Ready

Images are ready for commit 769f460. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.11.x-653-g769f460081

@clickboo clickboo force-pushed the boo-fix-exclusion-validation branch from 769f460 to 511878e Compare April 17, 2026 07:18
@clickboo
Copy link
Copy Markdown
Contributor Author

/test all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant