Skip to content

test(C-0055): cover Pod AppArmor profile without annotations - #207

Merged
matthyx merged 1 commit into
kubescape:mainfrom
ANAMASGARD:test/c0055-apparmor-field-172
Nov 30, 2026
Merged

matthyx merged 1 commit into
kubescape:mainfrom
ANAMASGARD:test/c0055-apparmor-field-172

Conversation

@ANAMASGARD

@ANAMASGARD ANAMASGARD commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #172.

Summary

  • Load the actual C-0055 policy in the existing cel-go module and evaluate its variables and validations against a Pod without annotations or other hardening settings. The Pod passes with RuntimeDefault and is denied when the profile is absent or Unconfined.
  • Run the direct test in a dedicated GitHub Actions job. Disable Go test result caching because the policy manifest lives outside the Go module. The existing API-server suite continues to cover admission behavior.

Verification

  • go test -count=1 -v ./... and go vet ./... passed with the module's Go 1.23.4 toolchain.
  • Disabling only the Pod-level AppArmor clause in a temporary policy copy made the field-only test fail for the expected reason. The two denial cases still passed.
  • Kubernetes v1.31.0 admitted the same field-only Pod in a server-side dry run against that temporary policy. The API server added the legacy AppArmor annotation before validation, reproducing the gap.
  • All 60 existing C-0055 admission cases passed on kind with Kubernetes v1.36.1. All 8 helper unit tests and git diff --check passed.

Summary by CodeRabbit

  • Tests
    • Added automated checks for the C-0055 Pod AppArmor policy, covering accepted and rejected profile configurations.
    • The continuous integration workflow now runs the CEL policy tests, helping catch test failures during validation.

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds a focused test for C-0055 Pod AppArmor profile validation and a workflow job that runs the CEL CLI Go tests.

Changes: C-0055 Pod AppArmor field test

Layer / File(s) Summary
Evaluate Pod AppArmor policy
tools/celcli/c0055_test.go
The test evaluates the policy against Pod objects with RuntimeDefault, a missing profile, and Unconfined. It checks that only RuntimeDefault is allowed.
Run CEL CLI tests in CI
.github/workflows/main.yaml
A new workflow job configures Go for the CEL CLI module and runs its tests without using cached test results.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: matthyx

Merge Risk: Minimal · up to 195d1

This change adds test coverage for the C-0055 Pod AppArmor field check and a CI job to run it. It does not change runtime policy behavior, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a test for C-0055 Pod AppArmor profile handling without annotations. The PR adds TestC0055PodAppArmorField, which evaluates the Pod-level appArmorProfile field, and a …
Linked Issues check Passed [#172] The only coding objective is a focused policy-evaluation test for a Pod that sets spec.securityContext.appArmorProfile and has no synthesized legacy annotation. At head, tools/celcli/c0055_test…
Out of Scope Changes check Passed The PR adds two items: the test file tools/celcli/c0055_test.go and a test-policy-expressions job in .github/workflows/main.yaml that runs go test -count=1 -v ./... from tools/celcli. The test file is…
Full details: Title check

Explanation

The title names the main change: a test for C-0055 Pod AppArmor profile handling without annotations. The PR adds TestC0055PodAppArmorField, which evaluates the Pod-level appArmorProfile field, and a CI job that runs it. The title is specific and matches the objectives of issue #172.

Full details: Linked Issues check

Explanation

[#172] The only coding objective is a focused policy-evaluation test for a Pod that sets spec.securityContext.appArmorProfile and has no synthesized legacy annotation. At head, tools/celcli/c0055_test.go defines TestC0055PodAppArmorField. It reads controls/C-0055/policy.yaml, compiles and evaluates the policy variables and validations, and builds a Pod object with only apiVersion, kind, metadata, and spec (containers plus, when set, securityContext.appArmorProfile.type). It sets no annotations. The cases are RuntimeDefault (expected allowed), missing profile (expected denied), and Unconfined (expected denied). This directly exercises the Pod-field branch, as the issue requests. The issue keeps the existing API-server tests for admission behavior, and the PR does not change them. The PR reports that the test fails when the Pod-level clause is disabled in a temporary policy copy. I did not run the tests, so that result is author-reported. The workflow job described in the raw summary is CI support for this test and is not a separate requirement.

Full details: Out of Scope Changes check

Explanation

The PR adds two items: the test file tools/celcli/c0055_test.go and a test-policy-expressions job in .github/workflows/main.yaml that runs go test -count=1 -v ./... from tools/celcli. The test file is the requested objective. The CI job runs that test, and disabling result caching matches the PR rationale that the policy manifest lies outside the Go module. I did not read the workflow file directly, so this verdict relies on the raw summary for the workflow change. No unrelated change was identified.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 666024f9-f7e0-458d-a717-c2b9508713e9
Commits

Reviewing files that changed from the base of the PR and between f29cc53 and 195d14f.

Files selected for processing: 2

  • .github/workflows/main.yaml
  • tools/celcli/c0055_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@matthyx matthyx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review of head 195d14f (base main @ f29cc53)

  • Need: Implements #172: a direct CEL evaluation of C-0055 with a Pod that sets only spec.securityContext.appArmorProfile (no annotation), so the Pod-field branch is tested without API-server annotation synthesis. Related merged PRs: #159, #182, #143, #80 (none supersede this; no duplicates found).
  • Soundness: Test loads the real controls/C-0055/policy.yaml, evaluates variables and validations; RuntimeDefault allowed, missing/Unconfined denied. Failing on any non-boolean result is good. CI job is small and sensible (-count=1 justified since the manifest is outside the module).
  • Validation: I ran go test -count=1 ./... in tools/celcli at the PR head: pass. CI: test-policy-expressions green, DCO/CodeRabbit/GitGuardian/FOSSA green. test-all-policies is red (C-0050/C-0055 integration cases), but the same failures appear on the PR's base commit f29cc53 on main (run 46161363337), and main later went green; the PR doesn't touch policies or that job. Treated as unrelated. I did not re-run the kind/minikube suite and did not verify the author's mutation check myself.
  • Policy: Author has 3 open PRs (#205–207), at the limit, not excessive. Before/After proof: test-only PR; PR body documents the mutation (test fails with the Pod clause disabled) and passing results — acceptable.
  • Nonblocking: The branch is behind main; a rebase would refresh the integration job.

Verdict: approve. No blockers.

@matthyx matthyx moved this to Waiting on Author in KS PRs tracking Nov 30, 2026
@matthyx
matthyx merged commit 230721e into kubescape:main Nov 30, 2026
6 of 7 checks passed
@matthyx matthyx moved this from Waiting on Author to To Archive in KS PRs tracking Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Archive

Development

Successfully merging this pull request may close these issues.

Test C-0055 Pod AppArmor field without annotation synthesis

2 participants