Skip to content

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

TypeScript

fix: close remaining D13 CEL and Grok Host grant-switch holes

Jose Gabriel Ramirez Encinas9f5d34e1ef44
diff --git a/charts/clerum-crds/crds/workflowrecipe.yaml b/charts/clerum-crds/crds/workflowrecipe.yaml
index af80735a9..211f7598e 100644
--- a/charts/clerum-crds/crds/workflowrecipe.yaml
+++ b/charts/clerum-crds/crds/workflowrecipe.yaml
@@ -88,6 +88,10 @@ spec:
# R10: run steps cannot also declare a step agent
- rule: "!has(self.steps) || self.steps.all(s, !(has(s.run) && has(s.agent)))"
message: "step cannot define both run and agent"
+ # D13: at most one oauth-broker id across agent and steps[].agent.
+ # kubectl apply bypasses control-api; this is the cluster gate.
+ - rule: "!(((has(self.agent) && has(self.agent.provider) && self.agent.provider == 'codex-subscription') || (has(self.steps) && self.steps.exists(s, has(s.agent) && has(s.agent.provider) && s.agent.provider == 'codex-subscription'))) && ((has(self.agent) && has(self.agent.provider) && self.agent.provider == 'grok-subscription') || (has(self.steps) && self.steps.exists(s, has(s.agent) && has(s.agent.provider) && s.agent.provider == 'grok-subscription'))))"
+ message: "a WorkflowRecipe may declare at most one oauth-broker provider"
# R11: snippet MCP tool allowlists must be explicit; no wildcard in v1
- rule: "!has(self.steps) || self.steps.all(s, !has(s.run) || !has(s.run.capabilities) || !has(s.run.capabilities.mcp) || !has(s.run.capabilities.mcp.allowedTools) || !has(s.run.capabilities.mcp.allowedTools.include) || s.run.capabilities.mcp.allowedTools.include.all(t, !t.contains('*')))"
message: "snippet mcp allowedTools.include must not contain wildcards"
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 655d61be9..653cbc6e7 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.561",
+ "version": "0.1.562",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.561",
+ "version": "0.1.562",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index c295d8b72..d5fc5fa18 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.561",
+ "version": "0.1.562",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/hostSpecValidation.ts b/control-api/src/routes/admin/hostSpecValidation.ts
index 5a1de39f6..a164d6243 100644
--- a/control-api/src/routes/admin/hostSpecValidation.ts
+++ b/control-api/src/routes/admin/hostSpecValidation.ts
@@ -428,9 +428,9 @@ export async function validateHostSpec(
// already lived on the Host. A revoked/unknown grant must not ride the
// identity/channels full-replace tolerance. An unchanged revoked ref stays
// tolerable so operators can still save unrelated fields.
- const storedConnectionRef = storedCodexConnectionRef(context.stored)
+ const storedConnectionRef = storedBrokerConnectionRef(context.stored)
const connectionAssignmentChanged =
- provider === 'codex-subscription' &&
+ (provider === 'codex-subscription' || provider === 'grok-subscription') &&
storedConnectionRef !== undefined &&
storedConnectionRef !== connectionRef
if (
@@ -632,13 +632,22 @@ function resolvedCodexConnectionRef(model: unknown): string {
)
}
-function storedCodexConnectionRef(stored: Record<string, unknown> | undefined): string | undefined {
+function storedBrokerConnectionRef(
+ stored: Record<string, unknown> | undefined
+): string | undefined {
if (!isPlainObject(stored) || !isPlainObject(stored.model)) return undefined
const provider = typeof stored.model.provider === 'string' ? stored.model.provider.trim() : ''
- if (provider !== 'codex-subscription') return undefined
- return readHostCodexConnectionRef(
- typeof stored.model.connectionRef === 'string' ? stored.model.connectionRef : null
- )
+ if (provider === 'codex-subscription') {
+ return readHostCodexConnectionRef(
+ typeof stored.model.connectionRef === 'string' ? stored.model.connectionRef : null
+ )
+ }
+ if (provider === 'grok-subscription') {
+ return readHostGrokConnectionRef(
+ typeof stored.model.connectionRef === 'string' ? stored.model.connectionRef : null
+ )
+ }
+ return undefined
}
function toleratePair(
diff --git a/control-api/test/crd.llmProviderEnums.test.ts b/control-api/test/crd.llmProviderEnums.test.ts
index e3031026f..fc712e75d 100644
--- a/control-api/test/crd.llmProviderEnums.test.ts
+++ b/control-api/test/crd.llmProviderEnums.test.ts
@@ -95,4 +95,15 @@ describe('LLM provider CRD enums', () => {
expect(recipe).toMatch(new RegExp(`provider (==|!=) '${id}'`))
}
})
+
+ it('WorkflowRecipe CEL rejects mixed oauth-broker agent and step providers', () => {
+ const recipe = readFileSync(resolve(crdsDir, 'workflowrecipe.yaml'), 'utf8')
+ expect(recipe).toContain('a WorkflowRecipe may declare at most one oauth-broker provider')
+ expect(recipe).toMatch(
+ /self\.steps\.exists\(s, has\(s\.agent\) && has\(s\.agent\.provider\) && s\.agent\.provider == 'codex-subscription'\)/
+ )
+ expect(recipe).toMatch(
+ /self\.steps\.exists\(s, has\(s\.agent\) && has\(s\.agent\.provider\) && s\.agent\.provider == 'grok-subscription'\)/
+ )
+ })
})
diff --git a/control-api/test/hostSpecValidation.codexSubscription.test.ts b/control-api/test/hostSpecValidation.codexSubscription.test.ts
index 725ef9e8b..01ffbbb5b 100644
--- a/control-api/test/hostSpecValidation.codexSubscription.test.ts
+++ b/control-api/test/hostSpecValidation.codexSubscription.test.ts
@@ -153,6 +153,39 @@ describe('codex-subscription Host admission', () => {
expect(isModelAllowed).toHaveBeenCalledWith('codex-subscription', 'gpt-5.3-codex', 'team-plus')
})
+ it('does not tolerate switching a Grok Host onto a revoked connectionRef with the same model', async () => {
+ process.env.CONTROL_API_GROK_SUBSCRIPTION_ENABLED = 'true'
+ const isModelAllowed = vi.fn(async (_provider, _model, connectionRef) => {
+ return connectionRef === 'team-grok'
+ })
+ const tolerations: Array<Record<string, unknown>> = []
+ const res = await validateHostSpec(
+ {
+ model: {
+ provider: 'grok-subscription',
+ name: 'grok-4.6',
+ connectionRef: 'revoked-grok',
+ },
+ },
+ { isModelAllowed },
+ {
+ stored: {
+ model: {
+ provider: 'grok-subscription',
+ name: 'grok-4.6',
+ connectionRef: 'team-grok',
+ },
+ },
+ hostRef: { namespace: 'mcp-host', name: 'agent-g' },
+ tolerations,
+ }
+ )
+ expect(res).not.toBeNull()
+ expect(res!.errors[0].message).toContain('model_not_allowed')
+ expect(tolerations).toEqual([])
+ expect(isModelAllowed).toHaveBeenCalledWith('grok-subscription', 'grok-4.6', 'revoked-grok')
+ })
+
it('does not tolerate switching to a revoked connectionRef with the same model', async () => {
process.env.CONTROL_API_CODEX_SUBSCRIPTION_ENABLED = 'true'
const isModelAllowed = vi.fn(async (_provider, _model, connectionRef) => {
diff --git a/scripts/tests/test-grok-subscription-t0.sh b/scripts/tests/test-grok-subscription-t0.sh
index 2031a7d32..3e042300d 100755
--- a/scripts/tests/test-grok-subscription-t0.sh
+++ b/scripts/tests/test-grok-subscription-t0.sh
@@ -92,6 +92,7 @@ require_file control-api/test/subscriptionGrantIdentity.test.ts
require_file control-api/test/routes.adminPluginWorkloadSdk.test.ts
require_file control-api/test/services.recipeCodexGrantIdentity.test.ts
require_file control-api/test/hostSpecValidation.codexSubscription.test.ts
+require_file control-api/test/crd.llmProviderEnums.test.ts
require_file scripts/tests/test-grok-llm-proxy-deploy-contract.sh
require_file tests/e2e/fixtures/grok-subscription/sanitized-upstream-contract.json
require_file workflow-recipes/src/workflow/codexRecipeVerdict.test.ts
@@ -135,7 +136,7 @@ run_group "grok-llm-proxy freeze+origin" \
bash -lc "cd '${ROOT}/grok-llm-proxy' && npx vitest run test/contractFreeze.test.ts test/originPolicy.test.ts --no-file-parallelism"
run_group "control-api grok grant/oauth/redeem/authorize" \
- bash -lc "cd '${ROOT}/control-api' && npx vitest run test/db.grokSubscriptionMigration.test.ts test/services.grokSubscriptionConnection.test.ts test/services.grokSubscriptionOAuth.test.ts test/services.grokSubscriptionCatalog.test.ts test/services.grokProviderAttemptRedemption.test.ts test/services.llmProviderAttemptAuthorizer.grok.test.ts test/subscriptionGrantIdentity.test.ts test/routes.adminPluginWorkloadSdk.test.ts test/services.recipeCodexGrantIdentity.test.ts test/hostSpecValidation.codexSubscription.test.ts --no-file-parallelism"
+ bash -lc "cd '${ROOT}/control-api' && npx vitest run test/db.grokSubscriptionMigration.test.ts test/services.grokSubscriptionConnection.test.ts test/services.grokSubscriptionOAuth.test.ts test/services.grokSubscriptionCatalog.test.ts test/services.grokProviderAttemptRedemption.test.ts test/services.llmProviderAttemptAuthorizer.grok.test.ts test/subscriptionGrantIdentity.test.ts test/routes.adminPluginWorkloadSdk.test.ts test/services.recipeCodexGrantIdentity.test.ts test/hostSpecValidation.codexSubscription.test.ts test/crd.llmProviderEnums.test.ts --no-file-parallelism"
run_group "workflow-recipes grok SDK" \
bash -lc "cd '${ROOT}/workflow-recipes' && npx vitest run src/workflow/codexRecipeVerdict.test.ts src/workflow/sdkOnlyGrokBinding.test.ts src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts src/reconciler/pluginWorkloadSdkValidator.test.ts tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.ts --no-file-parallelism"
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index a1580c706..42b6079bd 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.354",
+ "version": "0.1.355",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.354",
+ "version": "0.1.355",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@aws-sdk/client-s3": "^3.1009.0",
diff --git a/workflow-recipes/package.json b/workflow-recipes/package.json
index a8543d2ce..70bb0f59b 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.354",
+ "version": "0.1.355",
"description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface",
"main": "dist/main.js",
"engines": {
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
index 4d95b7625..096d446fe 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
@@ -491,8 +491,13 @@ describe('eager Grok policy gate', () => {
})
it('rejects a Grok bootstrap whose hash is a Codex digest', async () => {
+ // Minted and echoed hashes MUST be the same Codex digest. If parse used
+ // computeCodexPolicyHash, the echo would match and this would report ready.
const forged = {
- ...GROK_MINTED,
+ connectionKey: 'team-grok',
+ catalogRevision: 5,
+ credentialRevision: 2,
+ model: GROK_MODEL,
bindingHash: computeCodexPolicyHash({
model: GROK_MODEL,
catalogRevision: 5,
@@ -501,8 +506,9 @@ describe('eager Grok policy gate', () => {
}),
}
const harness = makeHarness(readyGrokBootstrapBody(forged), GROK_SPEC)
- expect(await harness.reconcile({ grokBinding: GROK_MINTED })).toBe('deploying')
+ expect(await harness.reconcile({ grokBinding: forged })).toBe('deploying')
expect(harness.provisioner.getBootstrapProof(GROK_RECIPE)).toBeUndefined()
+ expect(harness.configure).toHaveBeenCalled()
})
it('accepts execution_binding_missing as awaiting_policy when Grok has no grant', async () => {