Skip to content

Test proxy-runner RBAC under owner reference admission - #7336

Closed
ChrisJBurns wants to merge 2 commits into
mainfrom
ChrisJBurns/ownerref-admission-canary
Closed

ChrisJBurns wants to merge 2 commits into
mainfrom
ChrisJBurns/ownerref-admission-canary

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

#6835 broke OpenShift: its OwnerReferencesPermissionEnforcement admission plugin rejected the proxy-runner creating its Services, because they are owned by the StatefulSet with blockOwnerDeletion: true and the proxy-runner Role lacked update on apps/statefulsets/finalizers. #6756 fixed the Role and #7334 turned the plugin on in the kind e2e clusters. As rdimitrov noted in the #7334 review, nothing checks that guard. This PR adds an operator integration test that checks the RBAC directly instead of depending on how CI's kind cluster is configured.

  • New envtest suite, cmd/thv-operator/test-integration/mcp-server-ownerref-admission/, whose API server runs with OwnerReferencesPermissionEnforcement enabled. envtest already authorizes with RBAC, which the plugin consults.
    • Positive case: the real MCPServerReconciler reconciles an SSE MCPServer, so the test uses the proxy-runner Role the operator actually generates from defaultRBACRules. Acting as that Role's ServiceAccount, the test creates a Service owned by a StatefulSet with blockOwnerDeletion: true, as the runner does, and the create must succeed.
    • Negative control: a copy of that Role without statefulsets/finalizers must be rejected with cannot set blockOwnerDeletion. This proves the plugin is active, so the positive case can't pass vacuously.
  • testutil.SuiteOptions gains EnableAdmissionPlugins, so only this suite's API server changes.
  • The suite runs in the existing task operator-test-integration / operator-tests-integration job.

An earlier revision of this PR added a Chainsaw canary instead; it's replaced, because an envtest Go test is the better fit.

Type of change

  • Other (describe): Test coverage

Test plan

  • Manual testing (describe below)

  • Ran the new suite with envtest 1.31.0 (ginkgo ./cmd/thv-operator/test-integration/mcp-server-ownerref-admission/): 2/2 specs pass, across several runs with and without -p.

  • Temporarily removed the statefulsets/finalizers rule from defaultRBACRules: the positive case fails with services "mcp-ownerref-admission-headless" is forbidden: cannot set blockOwnerDeletion if an ownerReference refers to a resource you can't set finalizers on. I then restored the rule.

  • task lint-fix doesn't run locally: staticcheck panics under Go 1.27 (unexpected expr: *ast.KeyValueExpr). golangci-lint with staticcheck disabled reports 0 issues on the changed packages, and go vet and gofmt are clean. CI lint covers staticcheck.

Special notes for reviewers

  • The test doesn't check that the kind config keeps the plugin on, which was the review's literal ask. It checks the property that guard exists for: that the operator's proxy-runner RBAC works under the plugin. The plugin in kind stays as a second layer.
  • Drop blockOwnerDeletion on proxy-runner owned Services #6836 (dropping blockOwnerDeletion) will need to update this test. That's intended: the test then records whether the grant is still needed.

🤖 Generated with Claude Code

#7334 enabled OwnerReferencesPermissionEnforcement in the kind e2e
clusters, but nothing checks it stays on. Dropping the workflow's
config or editing the kubeadm patch would silently remove the guard
while every scenario still passed. Add a Chainsaw scenario that
expects a blockOwnerDeletion owner reference to be rejected without
finalizers RBAC and accepted once it is granted.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the size/S Small PR: 100-299 lines changed label Nov 26, 2026
A Chainsaw canary only checked that the kind cluster ran the
OwnerReferencesPermissionEnforcement plugin. Replace it with an envtest
suite that enables the plugin and has the operator-generated
proxy-runner Role create a Service owned with blockOwnerDeletion, so the
RBAC behind #6835 is tested directly. A control Role without
statefulsets/finalizers must be rejected, proving the plugin is on.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@ChrisJBurns ChrisJBurns changed the title Add canary for the owner reference admission check Test proxy-runner RBAC under owner reference admission Nov 26, 2026
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.40%. Comparing base (9300f3f) to head (16d5a18).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7336      +/-   ##
==========================================
- Coverage   82.40%   82.40%   -0.01%     
==========================================
  Files         937      937              
  Lines       95821    95821              
==========================================
- Hits        78962    78960       -2     
- Misses      16854    16856       +2     
  Partials        5        5              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisJBurns

Copy link
Copy Markdown
Collaborator Author

Folded into #7337. The envtest suite now runs the proxy-runner's real DeployWorkload under OwnerReferencesPermissionEnforcement, alongside the change that drops blockOwnerDeletion and the finalizers grant, so the code and its proof land together.

@ChrisJBurns
ChrisJBurns deleted the ChrisJBurns/ownerref-admission-canary branch November 26, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant