Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(clerum-crds): pin spec.contextRef immutable for oauth mcp-servers (#317 M1)

Diego Zacarias527ec08bcbeb
diff --git a/charts/clerum-crds/crds/mcpserver.yaml b/charts/clerum-crds/crds/mcpserver.yaml
index 30d2835e2..217cc2d02 100644
--- a/charts/clerum-crds/crds/mcpserver.yaml
+++ b/charts/clerum-crds/crds/mcpserver.yaml
@@ -517,6 +517,26 @@ spec:
# requires delete+recreate — consistent with the `managed` rule.
- rule: "!has(oldSelf.oauth) || has(self.oauth)"
message: "spec.oauth cannot be removed once set; delete and recreate the McpServer to change or remove the OAuth identity"
+ # M1 (@alfredolopez80, PR #317): spec.contextRef is the
+ # AUTHORITATIVE shared-identity coordinate for a
+ # grantScope:'context' oauth server — control-api keys the
+ # shared grant by server.spec.contextRef (mcpOauth.ts), NEVER
+ # the request body. Without this rule an actor with `update`
+ # RBAC on the McpServer CR could repoint contextRef ctxA→ctxB
+ # in place and redirect the shared token, defeating the
+ # grantScope/id/provider immutability above. oauth-GUARDED
+ # (!has(oldSelf.oauth) short-circuit) on purpose: contextRef is
+ # required on ALL servers (visibility/allowlisting too), and a
+ # WRC delegation reconcile legitimately re-writes it when an
+ # operator edits the owning WorkflowRecipe.spec.contextRef —
+ # global immutability would wedge that non-oauth flow. The
+ # shared-token threat is oauth-only, so we pin contextRef only
+ # once oauth exists. No two-step drop-oauth bypass: the rule
+ # above forbids removing oauth once set. contextRef is required
+ # → on UPDATE oldSelf/self.contextRef always exist. Transition
+ # rule (oldSelf) → skipped on CREATE.
+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || self.contextRef == oldSelf.contextRef"
+ message: "spec.contextRef is immutable; delete and recreate the McpServer to re-parent it to a different Context"
status:
type: object
properties:
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 45c93ac23..17b2019f2 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.471",
+ "version": "0.1.472",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.471",
+ "version": "0.1.472",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/control-api/package.json b/control-api/package.json
index d4f9cf5ff..4a5a57da1 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.471",
+ "version": "0.1.472",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/crd.mcpServerOauth.test.ts b/control-api/test/crd.mcpServerOauth.test.ts
index 3b311d877..51d23b5af 100644
--- a/control-api/test/crd.mcpServerOauth.test.ts
+++ b/control-api/test/crd.mcpServerOauth.test.ts
@@ -93,4 +93,20 @@ describe('McpServer CRD — OAuth surface (U1)', () => {
expect(rule, `immutability rule for oauth.${field} present and oldSelf-guarded`).toBeDefined()
}
})
+
+ it('makes spec.contextRef immutable for oauth servers via oldSelf-guarded transition rule (M1)', () => {
+ // M1 (@alfredolopez80, PR #317): contextRef is the authoritative
+ // shared-identity coordinate for a grantScope:'context' oauth server, so
+ // it must be pinned once oauth exists. oauth-guarded (!has(oldSelf.oauth)
+ // short-circuit) so non-oauth servers can still be re-parented by WRC.
+ // Presence-only assertion — CEL semantics are enforced by the apiserver
+ // at admission (verify with `kubectl --dry-run=server`), not here.
+ const rule = specRules.find(
+ r =>
+ r.rule.includes('self.contextRef == oldSelf.contextRef') &&
+ r.rule.includes('!has(oldSelf.oauth)')
+ )
+ expect(rule, 'contextRef immutability rule present and oauth/oldSelf-guarded').toBeDefined()
+ expect(rule?.message).toMatch(/contextRef is immutable/)
+ })
})