Skip to content

Add SecurityException CRDs, RBAC, and riskAcceptance capability#817

Merged
matthyx merged 4 commits intomainfrom
feature/security-exception-crds
Apr 15, 2026
Merged

Add SecurityException CRDs, RBAC, and riskAcceptance capability#817
matthyx merged 4 commits intomainfrom
feature/security-exception-crds

Conversation

@slashben
Copy link
Copy Markdown
Contributor

@slashben slashben commented Apr 12, 2026

Summary

  • Adds SecurityException (namespaced) and ClusterSecurityException (cluster-scoped) CRD YAMLs under kubescape.io/v1
  • Adds riskAcceptance: enable capability (default enabled)
  • Grants get/list/watch RBAC to kubevuln and operator clusterroles (gated on capability)

Part of NAUT-1258: GitOps-native risk acceptance via SecurityException CRDs.

Test plan

  • helm template renders CRD rules in kubevuln/operator ClusterRoles
  • helm template --set capabilities.riskAcceptance=disable omits CRD rules
  • CRD YAMLs pass kubectl apply --dry-run=server on a test cluster

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added cluster-scoped and namespace-scoped SecurityException resources to record exceptions with structured metadata (author, reason, expiry, match criteria, vulnerabilities, posture, and status) and improved status/printer display.
    • Introduced a configurable "risk acceptance" capability (defaults to disabled) that enables read access to these exception resources when turned on.
  • Tests

    • Updated snapshot tests to include the risk acceptance capability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

Warning

Rate limit exceeded

@matthyx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 34 minutes and 26 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 34 minutes and 26 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 38dd977e-43b4-4ee8-b979-7c0859b56cf4

📥 Commits

Reviewing files that changed from the base of the PR and between 3d0a045 and f79e87c.

⛔ Files ignored due to path filters (1)
  • charts/kubescape-operator/tests/__snapshot__/snapshot_test.yaml.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • charts/kubescape-operator/crds/cluster-security-exception.crd.yaml
  • charts/kubescape-operator/crds/security-exception.crd.yaml
  • charts/kubescape-operator/templates/kubevuln/clusterrole.yaml
  • charts/kubescape-operator/templates/operator/clusterrole.yaml
  • charts/kubescape-operator/tests/snapshot_test.yaml
  • charts/kubescape-operator/values.yaml
📝 Walkthrough

Walkthrough

Adds two new Kubernetes CRDs (SecurityException, ClusterSecurityException), conditional RBAC rules to allow reading them, a Helm values flag to toggle the feature, and updates snapshot tests to enable the flag in selected scenarios.

Changes

Cohort / File(s) Summary
CRD Definitions
charts/kubescape-operator/crds/security-exception.crd.yaml, charts/kubescape-operator/crds/cluster-security-exception.crd.yaml
Add namespaced SecurityException and cluster-scoped ClusterSecurityException CRDs (group kubescape.io, version v1beta1) with required spec, typed schema for author, reason, expiresAt, match (selectors, resources, images), vulnerabilities (ids, aliases, constrained status and justification), posture (controlID, action enum), enable status subresource and add printer columns.
RBAC Authorization
charts/kubescape-operator/templates/kubevuln/clusterrole.yaml, charts/kubescape-operator/templates/operator/clusterrole.yaml
Conditionally add RBAC rules (verbs: get, list, watch) for securityexceptions and clustersecurityexceptions in API group kubescape.io, toggled by the Helm value capabilities.riskAcceptance.
Helm Configuration & Tests
charts/kubescape-operator/values.yaml, charts/kubescape-operator/tests/snapshot_test.yaml
Introduce capabilities.riskAcceptance (default disable) to values and enable riskAcceptance: enable in specific snapshot test cases to exercise the feature.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through YAML fields today,
CRDs sprouted in the fray,
RBAC peeks when toggles sing,
Tests wake up to try the thing,
A tiny hop — exceptions made, hooray! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main changes: adding two new SecurityException CRDs, associated RBAC rules, and a new riskAcceptance capability flag.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/security-exception-crds

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
charts/kubescape-operator/values.yaml (1)

123-124: Clarify accepted values for riskAcceptance.

Consider adding a short inline note on Line 124 (e.g., # enable|disable) to make the expected value contract explicit for chart users.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/values.yaml` around lines 123 - 124, The chart
values file sets riskAcceptance: enable but doesn't document allowed values;
update the values.yaml next to the riskAcceptance key to include a short inline
note (e.g., "# enable|disable") so users know the accepted options; reference
the riskAcceptance key in values.yaml and ensure the comment is concise and
placed on the same line or immediately above the entry.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@charts/kubescape-operator/crds/cluster-security-exception.crd.yaml`:
- Around line 20-24: The CRD is missing a root-level required for the spec
object, allowing manifests to omit spec and bypass nested validation; update the
cluster-security-exception CRD schema by adding a required: ["spec"] entry
alongside the top-level properties so the spec object (which contains fields
like expiresAt, status, justification, and action) must be present and its
nested validations are enforced.

In `@charts/kubescape-operator/crds/security-exception.crd.yaml`:
- Around line 20-24: The CRD root schema allows objects without a spec; add a
required: [spec] entry at the root schema level (alongside the existing type:
object and properties:) so that the root object must include spec and therefore
triggers validation of the spec properties; update the top-level schema block in
security-exception.crd.yaml to include required: [spec].

In `@charts/kubescape-operator/templates/operator/clusterrole.yaml`:
- Around line 44-48: The snapshot test expectations are out of date because a
conditional RBAC block was added around .Values.capabilities.riskAcceptance ==
"enable" that grants apiGroups ["kubescape.io"] resources
["securityexceptions","clustersecurityexceptions"] with verbs
["get","list","watch"]; update the test fixtures/snapshots to include the new
rendered output when riskAcceptance is "enable" and also add or update the
disabled-case snapshot (when riskAcceptance is not "enable") so the CI snapshot
matcher reflects both states of the conditional rendering.

---

Nitpick comments:
In `@charts/kubescape-operator/values.yaml`:
- Around line 123-124: The chart values file sets riskAcceptance: enable but
doesn't document allowed values; update the values.yaml next to the
riskAcceptance key to include a short inline note (e.g., "# enable|disable") so
users know the accepted options; reference the riskAcceptance key in values.yaml
and ensure the comment is concise and placed on the same line or immediately
above the entry.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44dc7216-3739-40bb-a279-776a43ea44bc

📥 Commits

Reviewing files that changed from the base of the PR and between 5a92010 and 830ba66.

📒 Files selected for processing (5)
  • charts/kubescape-operator/crds/cluster-security-exception.crd.yaml
  • charts/kubescape-operator/crds/security-exception.crd.yaml
  • charts/kubescape-operator/templates/kubevuln/clusterrole.yaml
  • charts/kubescape-operator/templates/operator/clusterrole.yaml
  • charts/kubescape-operator/values.yaml

Comment thread charts/kubescape-operator/crds/cluster-security-exception.crd.yaml
Comment thread charts/kubescape-operator/crds/security-exception.crd.yaml
Comment on lines +44 to +48
{{- if eq .Values.capabilities.riskAcceptance "enable" }}
- apiGroups: ["kubescape.io"]
resources: ["securityexceptions", "clustersecurityexceptions"]
verbs: ["get", "list", "watch"]
{{- end }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Update snapshot fixtures for the new conditional RBAC rule.

CI is currently failing with a snapshot mismatch tied to this block. Please update the expected rendered output (including the disabled path) to unblock merge.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/templates/operator/clusterrole.yaml` around lines
44 - 48, The snapshot test expectations are out of date because a conditional
RBAC block was added around .Values.capabilities.riskAcceptance == "enable" that
grants apiGroups ["kubescape.io"] resources
["securityexceptions","clustersecurityexceptions"] with verbs
["get","list","watch"]; update the test fixtures/snapshots to include the new
rendered output when riskAcceptance is "enable" and also add or update the
disabled-case snapshot (when riskAcceptance is not "enable") so the CI snapshot
matcher reflects both states of the conditional rendering.

Copy link
Copy Markdown
Contributor

@matthyx matthyx left a comment

Choose a reason for hiding this comment

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

can you add a test case in charts/kubescape-operator/tests/snapshot_test.yaml where you enable this, probably in the "all capabilities" one?

Comment thread charts/kubescape-operator/values.yaml Outdated
syncSBOM: disable

# ====== Risk acceptance ======
riskAcceptance: enable
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does it make sense to enable it now (without the new kubevuln)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point — changed to disable by default. Will flip to enable when kubevuln ships.

Comment thread charts/kubescape-operator/crds/cluster-security-exception.crd.yaml
Comment thread charts/kubescape-operator/crds/cluster-security-exception.crd.yaml
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
charts/kubescape-operator/tests/snapshot_test.yaml (1)

61-61: Consider one explicit disabled-path snapshot for resilience.

You already validate the enabled path well; adding a dedicated case with capabilities.riskAcceptance: disable would make the negative-path assertion robust against future default-value changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kubescape-operator/tests/snapshot_test.yaml` at line 61, Add an
explicit negative-path snapshot that sets capabilities.riskAcceptance: disable
to ensure future default changes don't break tests; create a separate test case
in the snapshot suite mirroring the existing enabled case but with
riskAcceptance: disable, give it a clear name (e.g., "riskAcceptance disabled
snapshot"), and include the expected negative-output assertions so the test
harness verifies the disabled path independently of the current defaults.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@charts/kubescape-operator/tests/snapshot_test.yaml`:
- Line 61: Add an explicit negative-path snapshot that sets
capabilities.riskAcceptance: disable to ensure future default changes don't
break tests; create a separate test case in the snapshot suite mirroring the
existing enabled case but with riskAcceptance: disable, give it a clear name
(e.g., "riskAcceptance disabled snapshot"), and include the expected
negative-output assertions so the test harness verifies the disabled path
independently of the current defaults.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e62c2ca-a1ae-49e8-ac6f-902b34fd5a01

📥 Commits

Reviewing files that changed from the base of the PR and between 7456e5a and 3d0a045.

⛔ Files ignored due to path filters (1)
  • charts/kubescape-operator/tests/__snapshot__/snapshot_test.yaml.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • charts/kubescape-operator/tests/snapshot_test.yaml

matthyx
matthyx previously approved these changes Apr 15, 2026
slashben and others added 4 commits April 15, 2026 17:47
Namespaced SecurityException and cluster-scoped ClusterSecurityException
under kubescape.io/v1 with OpenAPI validation and enum constraints.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ben <ben@armosec.io>
Default enabled. Grants kubevuln and operator get/list/watch on
securityexceptions and clustersecurityexceptions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ben <ben@armosec.io>
- Change API version from v1 to v1beta1 (new API, may evolve)
- Add status subresource to both CRDs (consistent with other CRDs)
- Add required: [spec] at root schema level
- Default riskAcceptance to disable (enable when kubevuln ships)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ben <ben@armosec.io>
Add riskAcceptance: enable to all-capabilities test cases and update
snapshots to include SecurityException RBAC rules.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ben <ben@armosec.io>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx matthyx force-pushed the feature/security-exception-crds branch from 3d0a045 to f79e87c Compare April 15, 2026 15:48
@matthyx matthyx merged commit 90db96c into main Apr 15, 2026
4 of 8 checks passed
@matthyx matthyx deleted the feature/security-exception-crds branch April 15, 2026 15:49
@matthyx matthyx moved this from Needs Reviewer to To Archive in KS PRs tracking Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants