Skip to content

Add /finalizers subresource for OKD/OpenShift installs - #6756

Merged
ChrisJBurns merged 6 commits into
stacklok:mainfrom
Gentoli:okd-finalizers
Nov 26, 2026
Merged

ChrisJBurns merged 6 commits into
stacklok:mainfrom
Gentoli:okd-finalizers

Conversation

@Gentoli

@Gentoli Gentoli commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • added /finalizers update role for SAs

OCP requires explicit /finalizers update permission on the parent when creating a resource with owner ref. See https://bugzilla.redhat.com/show_bug.cgi?id=1886142#c6

proxyrunner crashes without statefulsets/finalizers:

{"time":"2026-10-06T04:06:34Z","level":"ERROR","msg":"error executing command","error":"failed to set up workload: failed to create container: failed to create headless service: failed to apply service mcp-fetch-headless: services \"mcp-fetch-headless\" is forbidden: cannot set blockOwnerDeletion if an ownerReference refers to a resource you can't set finalizers on: , <nil>"}

I also added these for some toolhive CRD as missing flagged by LLM. This is not strictly necessary given there is an update * permission ({"apiGroups":["toolhive.stacklok.dev"],"resources":["*"],"verbs":["get","list","update"]}) that was covering all the /finalizers. Without the * the operator logs:

2026/10/06 04:17:22 ERROR Failed to ensure RBAC resources controller=virtualmcpserver controllerGroup=toolhive.stacklok.dev controllerKind=VirtualMCPServer VirtualMCPServer.name=demo-vmcp VirtualMCPServer.namespace=infra-toolhive namespace=infra-toolhive name=demo-vmcp reconcileID=84d87ebd-327d-4bbb-94dd-c05a7bfd7e3c err="failed to ensure service account: failed to upsert service account demo-vmcp-vmcp in namespace infra-toolhive: serviceaccounts \"demo-vmcp-vmcp\" is forbidden: cannot set blockOwnerDeletion if an ownerReference refers to a resource you can't set finalizers on: , <nil>"
2026/10/06 04:17:22 ERROR Reconciler error controller=virtualmcpserver controllerGroup=toolhive.stacklok.dev controllerKind=VirtualMCPServer VirtualMCPServer.name=demo-vmcp VirtualMCPServer.namespace=infra-toolhive namespace=infra-toolhive name=demo-vmcp reconcileID=84d87ebd-327d-4bbb-94dd-c05a7bfd7e3c err="failed to ensure service account: failed to upsert service account demo-vmcp-vmcp in namespace infra-toolhive: serviceaccounts \"demo-vmcp-vmcp\" is forbidden: cannot set blockOwnerDeletion if an ownerReference refers to a resource you can't set finalizers on: , <nil>"

Fixes #6835

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Does this introduce a user-facing change?

Superseded by #7337 before release. #7337 stopped the proxy runner setting blockOwnerDeletion and removed the apps/statefulsets/finalizers grant this PR added, so no release ships it. The net effect for users is that SSE and streamable-http MCPServers work on OpenShift/OKD, and no operator ClusterRole change is needed. Ignore the upgrade note below.

Yes. The operator ClusterRole now needs update on apps/statefulsets/finalizers, because the operator grants that permission to each proxy-runner Role and Kubernetes only lets it grant permissions it holds.

  • Before: on OpenShift/OKD (or any cluster with OwnerReferencesPermissionEnforcement), SSE and streamable-http MCPServers crash-loop because the proxy runner can't create its Services.
  • After: those MCPServers come up. Existing proxy-runner Roles get the new rule on the next reconcile.

Upgrade note: upgrade the operator image and the chart's ClusterRole together. If you bump only operator.image, or manage the operator's RBAC outside the chart, add this rule to the operator ClusterRole yourself:

- apiGroups: ["apps"]
  resources: ["statefulsets/finalizers"]
  verbs: ["update"]

Without it, on any cluster, new MCPServers fail with attempting to grant RBAC permissions not currently held, and existing MCPServers go Ready=False and stop reconciling.

Special notes for reviewers

Follow-ups: #7321 enables OwnerReferencesPermissionEnforcement in the kind e2e clusters so CI catches this class of bug. #6836 stops setting blockOwnerDeletion on the proxy-runner Services; keep the grant from this PR for at least one release after that, since older pinned runner images still set the flag.

@Sanskarzz

Copy link
Copy Markdown
Collaborator

Hi @Gentoli, thank you for raising the PR regarding the bug. If possible, could you please submit a GitHub Issue (Bug Report) so that we can track it more easily?

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.22%. Comparing base (a9e9e48) to head (4bbfbfb).
⚠️ Report is 112 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6756      +/-   ##
==========================================
+ Coverage   81.25%   82.22%   +0.96%     
==========================================
  Files         880      932      +52     
  Lines       89960    94564    +4604     
==========================================
+ Hits        73099    77754    +4655     
+ Misses      16856    16805      -51     
  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.

The operator cannot grant statefulsets/finalizers to proxy-runner
Roles without holding it, so RBAC escalation prevention rejected the
Role. Declare it, plus the virtualmcpservers and mcpremoteproxies
finalizers, as kubebuilder markers so role.yaml is generated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jhrozek

jhrozek commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Thanks for tracking this down @Gentoli. I opened #6835 for it, as @Sanskarzz asked, and linked it from the description.

I also pushed a commit to your branch (ae8d7c4) because the e2e failures came from this change.

Kubernetes won't let anyone grant an RBAC permission they don't hold themselves. The operator builds the proxy-runner Role from defaultRBACRules, so once statefulsets/finalizers was added there, the operator's own ClusterRole needed it too. Without it, every MCPServer failed when its Role was created:

... is attempting to grant RBAC permissions not currently held:
{APIGroups:["apps"], Resources:["statefulsets/finalizers"], Verbs:["update"]}

Note that this broke vanilla clusters, not just OpenShift.

role.yaml is generated by controller-gen from the +kubebuilder:rbac markers (task operator-manifests), so editing it by hand gets undone on the next regen. The commit adds markers for all three permissions (statefulsets/finalizers, virtualmcpservers/finalizers, mcpremoteproxies/finalizers) and regenerates the file. The two toolhive lines you added come out the same as before, but now they're backed by markers. The only new rule is apps/statefulsets/finalizers.

As you mentioned, the toolhive /finalizers entries are already covered by the toolhive.stacklok.dev * rule. They're harmless, and having them as markers documents the dependency.

Separately, we'll probably follow up by dropping blockOwnerDeletion on those Services. Nothing in toolhive deletes StatefulSets with foreground propagation, so the flag doesn't buy us anything. Without it the runner doesn't need the extra permission at all. We'll also turn on OwnerReferencesPermissionEnforcement in the kind e2e config so CI catches this kind of bug. Neither has to block this PR.

@ChrisJBurns

Copy link
Copy Markdown
Collaborator

/retest

The operator e2e setup asserts the exact operator ClusterRole, so the
new statefulsets, mcpremoteproxies and virtualmcpservers finalizer
rules made the assertion fail. Mirror them in both tenancy fixtures.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The MCPServer scenarios assert the proxy-runner Role positionally
against defaultRBACRules, which now includes statefulsets/finalizers.
Add the rule to the stdio and HTTP fixtures for both tenancy modes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@rdimitrov

rdimitrov commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

The fix looks right to me, and I confirmed it on a cluster that enforces the same check as OpenShift. One upgrade requirement should be called out.

What I checked

The proxy runner sets owner references in only two places, ensureBackendServices and the service apply helper in pkg/container/kubernetes/client.go. Both point at the StatefulSet, so apps/statefulsets/finalizers is the only rule it needs. Everything the operator creates is owned by a toolhive.stacklok.dev resource, which the existing * rule already covers. task operator-manifests regenerates role.yaml with no diff, and both Chainsaw ClusterRole fixtures match it exactly. task operator-test passes.

I ran it on kind with --enable-admission-plugins=NodeRestriction,OwnerReferencesPermissionEnforcement:

Scenario Result
v0.69.1 with streamable-http, SSE and stdio MCPServers HTTP and SSE proxy runners crash-loop with the error from #6835. stdio is fine.
helm upgrade to this PR, same servers Existing proxy-runner Roles get the rule in place. All servers go Ready and the headless and ClusterIP Services are created.
MCP initialize + tools/call through the proxy Works
Delete an MCPServer All child resources are garbage-collected
VirtualMCPServer (group, discovered auth) and MCPRemoteProxy Both Ready
operator.rbac.scope=namespace Works

Upgrade requirement

The new operator binary needs the new ClusterRole rule. Otherwise it can't grant the rule to proxy-runner Roles. If the image is upgraded without the chart (only operator.image bumped, or the ClusterRole managed outside the chart), MCPServers fail on any cluster, not just OpenShift:

  • New MCPServers fail with attempting to grant RBAC permissions not currently held: {APIGroups:["apps"], Resources:["statefulsets/finalizers"], Verbs:["update"]}.
  • Existing MCPServers keep serving, but they get Ready=False and stop reconciling, so spec changes aren't applied.
  • kubectl get mcpserver still shows Ready in the STATUS column in this state. That's existing behavior, but it makes the failure easy to miss.

Could the description get a "user-facing change" section saying the operator ClusterRole now needs apps/statefulsets/finalizers: update? That would also give the release notes something to pick up.

Follow-ups

#7321 (enable the plugin in kind e2e) and #6836 (drop blockOwnerDeletion) are tracked. #7322 was closed as a duplicate of #6836. When #6836 lands, keep this rule for at least a release, since a proxy runner pinned to an older version via operator.toolhiveRunnerImage still sets the flag.

🤖 Generated with Claude Code

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I confirmed the fix on a kind cluster with OwnerReferencesPermissionEnforcement turned on (details in the comment above). Please add the operator ClusterRole requirement to the user-facing section or the release notes before the next release.

@ChrisJBurns
ChrisJBurns merged commit eb40663 into stacklok:main Nov 26, 2026
43 checks passed
ChrisJBurns added a commit that referenced this pull request Nov 26, 2026
OpenShift runs the OwnerReferencesPermissionEnforcement admission
plugin, which rejects blockOwnerDeletion owner references unless the
caller can update the owner's finalizers. Kind doesn't, so the missing
statefulsets/finalizers grant fixed in #6756 only showed up on
OpenShift. Enable the plugin in the operator e2e kind config and point
the Chainsaw job at it so CI catches this class of RBAC gap.

Closes #7321

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ChrisJBurns added a commit that referenced this pull request Nov 26, 2026
OpenShift runs the OwnerReferencesPermissionEnforcement admission
plugin, which rejects blockOwnerDeletion owner references unless the
caller can update the owner's finalizers. Kind doesn't, so the missing
statefulsets/finalizers grant fixed in #6756 only showed up on
OpenShift. Enable the plugin in the operator e2e kind config and point
the Chainsaw job at it so CI catches this class of RBAC gap.

Closes #7321

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
ChrisJBurns added a commit that referenced this pull request Nov 26, 2026
The runner no longer sets blockOwnerDeletion, so neither the
proxy-runner Role nor the operator ClusterRole needs update on
apps/statefulsets/finalizers. The grant from #6756 has not shipped in
a release, so there is no mixed-version runner to keep working.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ChrisJBurns added a commit that referenced this pull request Nov 26, 2026
* Drop blockOwnerDeletion on runner-owned Services

The proxy runner set blockOwnerDeletion on the StatefulSet owner
reference of its headless and ClusterIP Services. Under
OwnerReferencesPermissionEnforcement (OpenShift) that requires update
on apps/statefulsets/finalizers. The flag only affects foreground
cascading deletion, which toolhive never uses, so it bought nothing
but an extra RBAC requirement. GC still removes the Services when the
StatefulSet is deleted.

The statefulsets/finalizers grant stays for one release so a new
operator paired with an older pinned runner image keeps working.

Closes #6836

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Remove the statefulsets/finalizers grant

The runner no longer sets blockOwnerDeletion, so neither the
proxy-runner Role nor the operator ClusterRole needs update on
apps/statefulsets/finalizers. The grant from #6756 has not shipped in
a release, so there is no mixed-version runner to keep working.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Test the runner under ownerref admission

Run the proxy-runner's real DeployWorkload, as its ServiceAccount with
the operator-generated Role, against an envtest API server with
OwnerReferencesPermissionEnforcement enabled. Both Services must be
created without the finalizers grant, and a blockOwnerDeletion owner
reference must be rejected, which proves the plugin is on and pins
that the grant is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proxy runner fails on OpenShift creating owned Services

5 participants