Skip to content

Drop blockOwnerDeletion on proxy-runner owned Services #6836

Done

Description

@jhrozek

Proposal

Stop setting blockOwnerDeletion: true on the owner reference the proxy runner puts on the headless and ClusterIP Services pointing at their StatefulSet. Once that's done, drop the apps/statefulsets/finalizers grant that #6756 adds.

Background

On OpenShift, OwnerReferencesPermissionEnforcement rejects a blockOwnerDeletion: true owner reference unless the caller has update on the owner's /finalizers (#6835). #6756 fixes that by granting statefulsets/finalizers to the proxy-runner Role and to the operator ClusterRole. The operator needs it too because Kubernetes won't let it grant a permission it doesn't hold.

That's the standard fix, but it's RBAC we may not need. The flag only does something when the owner is deleted with foreground propagation: the StatefulSet would wait until its Services are gone. We never delete that way:

  • RemoveWorkload deletes the StatefulSet with empty DeleteOptions (background) in pkg/container/kubernetes/client.go.
  • finalizeMCPServer deletes the StatefulSet and both Services by name.
  • Nothing in production code sets PropagationPolicy or DeletePropagationForeground.

GC still removes the Services once the StatefulSet is gone, with or without the flag.

Change

  • pkg/container/kubernetes/client.go, ensureBackendServices: drop BlockOwnerDeletion: ptr.To(true) from the StatefulSet owner reference.
  • pkg/container/kubernetes/client.go, the service apply helper: drop the hardcoded WithBlockOwnerDeletion(true). It ignores whatever the owner passed in says anyway.
  • pkg/container/kubernetes/client_test.go: update the two assertions that expect true.
  • Revert the apps/statefulsets/finalizers entry in defaultRBACRules and its +kubebuilder:rbac marker, then regenerate role.yaml.

Why it's safe

  • Admission rules: the plugin only asks for the finalizers permission when an owner reference is newly blocking or flipped to blocking (source). Removing the flag, or leaving it out, never triggers that check. Any change to owner refs also needs delete on the object itself, and the proxy-runner Role already has delete on services.
  • Existing Services on vanilla clusters: the next Force apply drops the field. That passes even with the plugin on.
  • OpenShift: nothing to migrate, because Service creation has failed there since Add ClusterIP service with SessionAffinity for MCP server backend #3992.
  • Recreated StatefulSet (new UID): under B this needs no extra permission. Under the current grant approach it needs the finalizers permission every time.
  • Coverage: this is the only owner reference the proxy runner sets. The runner creates the StatefulSet with no owner, and the operator later adopts it under the MCPServer.

What B buys over the RBAC grant alone

  • Least privilege: with the grant, every MCPServer's runner service account can set blocking owner references on any StatefulSet in its namespace.
  • Mixed versions: a newer runner works against an older operator chart that lacks statefulsets/finalizers.

Related

  • Enable OwnerReferencesPermissionEnforcement in test/e2e/thv-operator/kind-config.yaml (apiServer.extraArgs). The chainsaw job in operator-ci.yml creates its kind cluster without a config and would need one too. This would have caught Add ClusterIP service with SessionAffinity for MCP server backend #3992, and it would prove B in CI. Ideally it lands with or before B.

Open question

@ChrisJBurns, what do you think? Is it worth dropping the flag and shrinking the RBAC footprint, or should we stick with the conventional /finalizers grant from #6756?

Refs #6756, #6835

Activity

  1. added
    kubernetes
    on Oct 15, 2026
  2. added
    needs-triage
    on Oct 15, 2026
  3. Sanskarzz commented on Oct 28, 2026

    @Sanskarzz
    Collaborator

    @jhrozek From the operator side, I support dropping blockOwnerDeletion while retaining the StatefulSet owner references. That preserves GC cleanup, including the orphaned-Service case raised in #3992, and our deletion paths do not rely on foreground ordering.

    I’d include admission-enabled coverage for both Kind setups, existing-Service updates, StatefulSet UID changes, and eventual cleanup. We should also coordinate with #6756: it is still open, and older runner images still need the grant when creating or rebinding Services. If that grant lands first, let’s agree on the rollout/rollback policy before removing it.

  4. removed
    needs-triage
    on Nov 24, 2026
  5. rdimitrov commented on Nov 26, 2026

    @rdimitrov
    Member

    I'm folding #7322 into this issue, since both propose the same change. #7322 settles the rollout question raised above, so here is its plan:

    • Keep the apps/statefulsets/finalizers grant for one release. Drop blockOwnerDeletion first, but leave the grant in defaultRBACRules and in the operator's +kubebuilder:rbac marker. A new operator paired with an older runner pinned through operator.toolhiveRunnerImage still sets the flag, and that would break OpenShift again. Remove the grant in a later release, then run task operator-manifests and update the Chainsaw ClusterRole and proxy-runner Role fixtures. upsertRole replaces a Role's rules wholesale, so existing Roles shrink without a migration.
    • Keep the per-CRD toolhive /finalizers markers. The toolhive.stacklok.dev * rule already covers them, but they document the dependency in case * is ever narrowed.

    Sequencing: land this after #6756 (approved, not merged yet) and after #7321, so CI enforces OwnerReferencesPermissionEnforcement when this goes in.

  6. added a commit that references this issue on Nov 26, 2026
    420f1b5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kubernetesoperator

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions