Skip to content

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

TypeScript

feat(hcc,wrc): mint llm:grok:execute and grok-proxy egress

Jose Gabriel Ramirez Encinas97feed279d82
diff --git a/deploy/base/control-plane/workflow-recipes.yaml b/deploy/base/control-plane/workflow-recipes.yaml
index 227b04912..f2b2e02c0 100644
--- a/deploy/base/control-plane/workflow-recipes.yaml
+++ b/deploy/base/control-plane/workflow-recipes.yaml
@@ -72,6 +72,8 @@ spec:
value: "false"
- name: WRC_ENABLE_SNIPPET_RUNTIME
value: "false"
+ - name: WRC_GROK_SUBSCRIPTION_ENABLED
+ value: "false"
- name: WRC_MAX_WORKFLOW_STEPS
value: "100"
- name: CLERUM_WORKFLOW_MAX_WORKLOADS_PER_RECIPE
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 5e911645c..c62df61cc 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.322",
+ "version": "0.1.323",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.322",
+ "version": "0.1.323",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 3d9e0bf25..91da13907 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.322",
+ "version": "0.1.323",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/src/codexExecutionProjection.ts b/host-context-controller/src/codexExecutionProjection.ts
index a151c6462..35779d07d 100644
--- a/host-context-controller/src/codexExecutionProjection.ts
+++ b/host-context-controller/src/codexExecutionProjection.ts
@@ -2,10 +2,13 @@ export {
CODEX_EXECUTE_SCOPE,
CODEX_PROVIDER,
CODEX_UNASSIGNED_CONNECTION_KEY,
+ GROK_EXECUTE_SCOPE,
+ GROK_PROVIDER,
assignedCodexConnectionKey as assignedHostCodexConnectionRef,
collectCodexTargets,
isCodexUnassignedConnectionKey as isCodexUnassignedConnectionRef,
projectCodexExecution,
+ projectGrokExecution,
} from '@clerum/codex-catalog-projection'
export type {
CodexCatalogSnapshot,
diff --git a/host-context-controller/src/hostReconciler.ts b/host-context-controller/src/hostReconciler.ts
index d903d7d4a..48545e8bf 100644
--- a/host-context-controller/src/hostReconciler.ts
+++ b/host-context-controller/src/hostReconciler.ts
@@ -9,6 +9,7 @@ import {
type CodexExecutionProjection,
assignedHostCodexConnectionRef,
projectCodexExecution,
+ projectGrokExecution,
} from './codexExecutionProjection'
import { config } from './config'
import { HOST_LABEL, MANAGED_BY_LABEL, MANAGED_BY_VALUE } from './constants'
@@ -33,6 +34,7 @@ import {
import {
ALLOWED_MODELS_CONFIGMAP_NAME,
parseAllowedModelsSnapshot,
+ parseGrokAllowedModelsSnapshot,
snapshotForAssignedCodexGrant,
snapshotFromConfigMapError,
} from './llmAllowedModelsSnapshot'
@@ -1246,7 +1248,8 @@ export class HostReconciler {
host: HostCRD,
hasChannelIngress = false,
frontsOAuthServer = false,
- projection?: CodexExecutionProjection
+ projection?: CodexExecutionProjection,
+ grokProjection?: CodexExecutionProjection
): string {
// Hash the EFFECTIVE (resolved) scopes — what actually gets minted into the
// control token — so change-detection matches the default-fallback applied
@@ -1254,21 +1257,24 @@ export class HostReconciler {
// carries the first-party defaults, and the two drift). Uses the SAME
// `resolveRuntimeControlScopes` as the mint path (see
// `resolveEffectiveControlScopesForHost`) so the hashed set and the minted
- // set — including the derive-only `oauth:user-token` and the codex
- // projection's derived scopes — can never diverge.
+ // set — including the derive-only `oauth:user-token` and broker
+ // projections' derived scopes — can never diverge.
const runtimeScopes = [
...resolveRuntimeControlScopes(host.spec.workflowControl, {
hasChannelIngress,
frontsOAuthServer,
}),
].sort()
- const derived = projection?.derivedScopes ?? []
+ const derived = [...(projection?.derivedScopes ?? []), ...(grokProjection?.derivedScopes ?? [])]
if (derived.length === 0) {
return HostReconciler.shortHash(runtimeScopes)
}
return HostReconciler.shortHash({
scopes: [...runtimeScopes, ...derived].sort(),
- drift: projection?.driftHashInput,
+ drift: {
+ codex: projection?.driftHashInput,
+ grok: grokProjection?.driftHashInput,
+ },
})
}
@@ -1297,7 +1303,8 @@ export class HostReconciler {
hasChannelIngress = false,
frontsOAuthServer = false,
preservedHostUid?: string,
- projection?: CodexExecutionProjection
+ projection?: CodexExecutionProjection,
+ grokProjection?: CodexExecutionProjection
): Record<string, string> {
const refreshTtlSec = Number.isFinite(tokens.refreshExpiresInSeconds)
? Math.max(0, tokens.refreshExpiresInSeconds)
@@ -1316,7 +1323,8 @@ export class HostReconciler {
host,
hasChannelIngress,
frontsOAuthServer,
- projection
+ projection,
+ grokProjection
),
[RUNTIME_TOKEN_ISSUER_ANNOTATION]: RUNTIME_TOKEN_ISSUER,
[RUNTIME_TOKEN_AUDIENCE_ANNOTATION]: RUNTIME_TOKEN_AUDIENCE,
@@ -1348,7 +1356,8 @@ export class HostReconciler {
nowMs: number,
hasChannelIngress = false,
frontsOAuthServer = false,
- projection?: CodexExecutionProjection
+ projection?: CodexExecutionProjection,
+ grokProjection?: CodexExecutionProjection
): { refresh: boolean; rolloutRequired: boolean; reason: string; refreshTokenExpMs?: number } {
const labels = secret.metadata?.labels ?? {}
if (labels[MANAGED_BY_LABEL] !== MANAGED_BY_VALUE || labels[HOST_LABEL] !== host.name) {
@@ -1367,7 +1376,8 @@ export class HostReconciler {
host,
hasChannelIngress,
frontsOAuthServer,
- projection
+ projection,
+ grokProjection
)
const hasContractMetadata =
RUNTIME_TOKEN_HOST_BINDING_HASH_ANNOTATION in annotations ||
@@ -1588,6 +1598,14 @@ export class HostReconciler {
return projectCodexExecution(host.spec, snapshot)
}
+ private projectGrokForHost(host: HostCRD): CodexExecutionProjection & {
+ requiresGrokProxyEgress: boolean
+ } {
+ const connectionKey = assignedHostCodexConnectionRef(host.spec.model?.connectionRef)
+ const snapshot = parseGrokAllowedModelsSnapshot(this.lastCodexConfigMap, connectionKey)
+ return projectGrokExecution(host.spec, snapshot)
+ }
+
private resolveEffectiveControlScopesForHost(
host: HostCRD,
frontsOAuthServer: boolean,
@@ -1598,9 +1616,10 @@ export class HostReconciler {
hasChannelIngress,
frontsOAuthServer
)
- const derived = this.projectCodexForHost(host).derivedScopes.filter(
- scope => !workflow.includes(scope as HostWorkflowControlScope)
- )
+ const derived = [
+ ...this.projectCodexForHost(host).derivedScopes,
+ ...this.projectGrokForHost(host).derivedScopes,
+ ].filter(scope => !workflow.includes(scope as HostWorkflowControlScope))
return [...workflow, ...derived] as EffectiveMcpHostControlScope[]
}
@@ -1613,7 +1632,8 @@ export class HostReconciler {
host,
hasChannelIngress,
frontsOAuthServer,
- this.projectCodexForHost(host)
+ this.projectCodexForHost(host),
+ this.projectGrokForHost(host)
)
}
@@ -1694,11 +1714,13 @@ export class HostReconciler {
// hash never diverge.
const frontsOAuthServer = await this.frontsOAuthServer(host)
const projection = this.projectCodexForHost(host)
+ const grokProjection = this.projectGrokForHost(host)
const scopeHash = HostReconciler.runtimeTokenScopeHash(
host,
hasChannelIngress,
frontsOAuthServer,
- projection
+ projection,
+ grokProjection
)
let decision: {
refresh: boolean
@@ -1712,7 +1734,8 @@ export class HostReconciler {
nowMs,
hasChannelIngress,
frontsOAuthServer,
- projection
+ projection,
+ grokProjection
)
: { refresh: true, rolloutRequired: false, reason: 'missing_secret' }
if (
@@ -1884,7 +1907,8 @@ export class HostReconciler {
hasChannelIngress,
frontsOAuthServer,
existing?.metadata?.annotations?.[GFS_TOKEN_HOST_UID_ANNOTATION],
- projection
+ projection,
+ grokProjection
),
[RUNTIME_TOKEN_BOOTSTRAP_STATE_ANNOTATION]: RUNTIME_TOKEN_BOOTSTRAP_STATE_FRESH,
[RUNTIME_TOKEN_ROLLOUT_REQUIRED_ANNOTATION]: rolloutRequired ? 'true' : 'false',
@@ -4215,6 +4239,84 @@ export class HostReconciler {
await this.deleteMcpHostCodexProxyEgressNetworkPolicy(host)
}
+ private async ensureMcpHostGrokProxyEgressNetworkPolicy(host: HostCRD): Promise<void> {
+ const policyName = `mcp-host-${host.name}-egress-grok-proxy`
+ const policy: k8s.V1NetworkPolicy = {
+ apiVersion: 'networking.k8s.io/v1',
+ kind: 'NetworkPolicy',
+ metadata: {
+ name: policyName,
+ namespace: host.namespace,
+ labels: {
+ [MANAGED_BY_LABEL]: MANAGED_BY_VALUE,
+ [HOST_LABEL]: host.name,
+ 'clerum.io/policy-type': 'grok-proxy-egress',
+ },
+ },
+ spec: {
+ podSelector: {
+ matchLabels: {
+ [HOST_LABEL]: host.name,
+ [MANAGED_BY_LABEL]: MANAGED_BY_VALUE,
+ },
+ },
+ policyTypes: ['Egress'],
+ egress: [
+ {
+ to: [
+ {
+ namespaceSelector: {
+ matchLabels: { 'kubernetes.io/metadata.name': config.controlPlaneNamespace },
+ },
+ podSelector: {
+ matchLabels: { app: 'grok-llm-proxy' },
+ },
+ },
+ ],
+ ports: [{ port: 8080, protocol: 'TCP' }],
+ },
+ ],
+ },
+ }
+ await applyNetworkPolicy(
+ this.networkingApi,
+ policyName,
+ host.namespace,
+ policy,
+ '[HostReconciler]'
+ )
+ }
+
+ private async deleteMcpHostGrokProxyEgressNetworkPolicy(host: HostCRD): Promise<void> {
+ const policyName = `mcp-host-${host.name}-egress-grok-proxy`
+ await this.deleteIfHccOwned(
+ 'NetworkPolicy',
+ policyName,
+ host.namespace,
+ host.name,
+ () =>
+ this.networkingApi.readNamespacedNetworkPolicy({
+ name: policyName,
+ namespace: host.namespace,
+ }),
+ () =>
+ this.networkingApi.deleteNamespacedNetworkPolicy({
+ name: policyName,
+ namespace: host.namespace,
+ })
+ )
+ }
+
+ private async reconcileMcpHostGrokProxyEgressNetworkPolicy(host: HostCRD): Promise<void> {
+ const projection = this.projectGrokForHost(host)
+ if (projection.eligibility === 'uncertain') return
+ if (projection.requiresGrokProxyEgress) {
+ await this.ensureMcpHostGrokProxyEgressNetworkPolicy(host)
+ return
+ }
+ await this.deleteMcpHostGrokProxyEgressNetworkPolicy(host)
+ }
+
/**
* Delete per-Host NetworkPolicies created by this reconciler.
* 404-tolerant — safe to call even if NPs were never created or already gone.
@@ -4227,6 +4329,7 @@ export class HostReconciler {
{ name: `mcp-host-${name}-ingress-rpc-proxy`, namespace },
{ name: `mcp-host-${name}-egress-gfs`, namespace },
{ name: `mcp-host-${name}-egress-codex-proxy`, namespace },
+ { name: `mcp-host-${name}-egress-grok-proxy`, namespace },
{ name: `mcp-host-${name}-egress-llm-hooks`, namespace },
{ name: `channel-reader-${name}-egress`, namespace: config.channelsNamespace },
{
@@ -4482,6 +4585,7 @@ export class HostReconciler {
await this.ensureMcpHostGfsEgressNetworkPolicy(host)
revalidateHostMutationBoundary()
await this.reconcileMcpHostCodexProxyEgressNetworkPolicy(host)
+ await this.reconcileMcpHostGrokProxyEgressNetworkPolicy(host)
// The mcp-host→llm-hooks egress policy is now owned by LlmHookReconciler
// (per-host, scoped to referenced hook pods — N1/N7); host-delete cleanup
// of `mcp-host-<host>-egress-llm-hooks` stays in deleteHostNetworkPolicies.
diff --git a/host-context-controller/src/llmAllowedModelsSnapshot.ts b/host-context-controller/src/llmAllowedModelsSnapshot.ts
index 3dcfd4f33..32f4a8fe8 100644
--- a/host-context-controller/src/llmAllowedModelsSnapshot.ts
+++ b/host-context-controller/src/llmAllowedModelsSnapshot.ts
@@ -7,6 +7,7 @@ export {
CONNECTION_REVISION_ANNOTATION,
CONTENT_HASH_ANNOTATION,
parseAllowedModelsSnapshot,
+ parseGrokAllowedModelsSnapshot,
snapshotForAssignedCodexGrant,
snapshotFromConfigMapError,
} from '@clerum/codex-catalog-projection'
diff --git a/host-context-controller/src/types.ts b/host-context-controller/src/types.ts
index e01d50d7d..3a177dce1 100644
--- a/host-context-controller/src/types.ts
+++ b/host-context-controller/src/types.ts
@@ -440,7 +440,7 @@ export type HostWorkflowControlScope =
| 'workflow:approval:resolve'
| 'workflow:approval:decide'
-export type DerivedPlatformScope = 'llm:codex:execute'
+export type DerivedPlatformScope = 'llm:codex:execute' | 'llm:grok:execute'
// The full effective runtime control scope set minted into an mcp-host control
// JWT: the user-declarable workflow-control scopes PLUS every HCC-derived scope
// — `oauth:user-token` (see {@link HostRuntimeControlScope}) and the codex
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index 658e6bf84..a412b033a 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.352",
+ "version": "0.1.353",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.352",
+ "version": "0.1.353",
"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 a1304124e..871917bad 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.352",
+ "version": "0.1.353",
"description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface",
"main": "dist/main.js",
"engines": {
diff --git a/workflow-recipes/src/config.ts b/workflow-recipes/src/config.ts
index d927029ee..88ccb701b 100644
--- a/workflow-recipes/src/config.ts
+++ b/workflow-recipes/src/config.ts
@@ -57,6 +57,7 @@ export interface OperatorConfig {
* runtime capability is activated.
*/
pluginWorkloadSdkEnabled: boolean
+ grokSubscriptionEnabled: boolean
maxWorkflowSteps: number
workflowMaxWorkloadsPerRecipe: number
workflowUiEgressInternalMaxItems: number
@@ -366,6 +367,7 @@ export function loadConfig(): OperatorConfig {
enableCustomCoordinatorImage: getEnvBool('WRC_ENABLE_CUSTOM_COORDINATOR_IMAGE', false),
enableSnippetRuntime: getEnvBool('WRC_ENABLE_SNIPPET_RUNTIME', false),
pluginWorkloadSdkEnabled: getEnvBool('PLUGIN_WORKLOAD_SDK_ENABLED', false),
+ grokSubscriptionEnabled: getEnvBool('WRC_GROK_SUBSCRIPTION_ENABLED', false),
maxWorkflowSteps: workflowMaxSteps,
workflowMaxWorkloadsPerRecipe,
workflowUiEgressInternalMaxItems,
diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.ts
index a47ff5874..282666034 100644
--- a/workflow-recipes/src/reconciler/reconciler.test.ts
+++ b/workflow-recipes/src/reconciler/reconciler.test.ts
@@ -10146,6 +10146,7 @@ describe('WorkflowRecipeReconciler', () => {
claimedParent: true,
parentSpec: null,
connectionKey: 'unassigned',
+ grokConnectionKey: 'unassigned',
})
})
@@ -10204,6 +10205,7 @@ describe('WorkflowRecipeReconciler', () => {
claimedParent: true,
parentSpec,
connectionKey: 'unassigned',
+ grokConnectionKey: 'unassigned',
})
})
@@ -10265,6 +10267,7 @@ describe('WorkflowRecipeReconciler', () => {
claimedParent: true,
parentSpec,
connectionKey: 'team-plus',
+ grokConnectionKey: 'unassigned',
})
})
diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
index 28e36557a..a670eaf75 100644
--- a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
@@ -49,7 +49,10 @@ import {
import { HttpMcpHostClient } from '../workflow/httpMcpHostClient'
import { JwtTokenFactory } from '../workflow/jwtTokenFactory'
import { K8sSecretReaderImpl } from '../workflow/k8sSecretReaderImpl'
-import { readRecipeCodexConnectionRef } from '../workflow/llmAllowedModelsSnapshot'
+import {
+ readRecipeCodexConnectionRef,
+ readRecipeGrokConnectionRef,
+} from '../workflow/llmAllowedModelsSnapshot'
import { ModelConfigHandler } from '../workflow/modelConfigHandler'
import { buildCoordinatorGfsNetworkPolicy } from '../workflow/networkPolicyFactory'
import type { EagerSdkBootstrapProof } from '../workflow/pluginWorkloadSdkProvisioner'
@@ -1283,6 +1286,7 @@ export class WorkflowRecipeReconciler {
claimedParent: this.claimedCodexParent(recipe),
parentSpec: parent.spec,
connectionKey: readRecipeCodexConnectionRef(grantAnnotations),
+ grokConnectionKey: readRecipeGrokConnectionRef(grantAnnotations),
})
}
diff --git a/workflow-recipes/src/workflow/codexRecipeVerdict.ts b/workflow-recipes/src/workflow/codexRecipeVerdict.ts
index d6690ec9e..5cfd9b9b5 100644
--- a/workflow-recipes/src/workflow/codexRecipeVerdict.ts
+++ b/workflow-recipes/src/workflow/codexRecipeVerdict.ts
@@ -1,8 +1,11 @@
import {
CODEX_PROVIDER,
+ CODEX_UNASSIGNED_CONNECTION_KEY,
type CodexCatalogSnapshot,
type CodexConfigMapView,
type CodexExecutionProjection,
+ parseGrokAllowedModelsSnapshot,
+ projectGrokExecution,
snapshotForAssignedCodexGrant,
toEligiblePolicyBinding,
} from '@clerum/codex-catalog-projection'
@@ -10,6 +13,7 @@ import type { WorkflowRecipeSpec } from '../types'
import {
type CodexProvenance,
projectRecipeCodexExecution,
+ recipeToCodexHostSpec,
resolveCodexAuthoritativeSpec,
} from './codexExecutionProjection'
import {
@@ -54,6 +58,12 @@ export type CodexReconcileContext = {
* only producer (`bindCodexReconcileContext`) always fills it.
*/
connectionKey: string
+ /**
+ * Canonical Grok grant key. Codex alias leftovers fail closed to
+ * `unassigned` at the reader. Optional so existing Codex-only callers
+ * keep compiling; missing is `unassigned` and cannot spend Grok.
+ */
+ grokConnectionKey?: string
}
/**
@@ -83,6 +93,7 @@ export type CodexRecipeVerdict = {
*/
readonly hostBinding: PluginWorkloadSdkCodexBindingProof | null
readonly hostBindingReason: string
+ readonly grokProjection: CodexExecutionProjection & { requiresGrokProxyEgress: boolean }
}
export function projectCodexRecipeVerdict(input: {
@@ -109,12 +120,16 @@ export function projectCodexRecipeVerdict(input: {
view.snapshot
)
const projection = projectRecipeCodexExecution(resolved.spec, snapshot, resolved.provenance)
+ const grokKey = context.grokConnectionKey ?? CODEX_UNASSIGNED_CONNECTION_KEY
+ const grokSnapshot = parseGrokAllowedModelsSnapshot(view.configMap, grokKey)
+ const grokProjection = projectGrokExecution(recipeToCodexHostSpec(resolved.spec), grokSnapshot)
const base = {
provenance: resolved.provenance,
provenanceReason: resolved.reason,
connectionKey: context.connectionKey,
projection,
+ grokProjection,
} as const
if (projection.eligibility !== 'eligible') {
diff --git a/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts b/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts
index d0dabd7f0..5e74f2bcf 100644
--- a/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts
+++ b/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts
@@ -34,3 +34,10 @@ export function readRecipeCodexConnectionRef(
if (!result.ok) return CODEX_UNASSIGNED_CONNECTION_KEY
return result.connectionKey
}
+
+/** Canonical Grok grant. Leftover Codex alias fails closed to `unassigned`. */
+export function readRecipeGrokConnectionRef(
+ annotations: Record<string, string> | undefined
+): string {
+ return readRecipeCodexConnectionRef(annotations, 'grok-subscription')
+}
diff --git a/workflow-recipes/src/workflow/mcpHostRuntimeTokenIssuerClient.ts b/workflow-recipes/src/workflow/mcpHostRuntimeTokenIssuerClient.ts
index a332a4cf5..cbc6805d5 100644
--- a/workflow-recipes/src/workflow/mcpHostRuntimeTokenIssuerClient.ts
+++ b/workflow-recipes/src/workflow/mcpHostRuntimeTokenIssuerClient.ts
@@ -36,7 +36,7 @@ export type WorkflowControlScope =
| 'workflow:approval:decide'
| 'plugin-workload-sdk'
-export type DerivedPlatformScope = 'llm:codex:execute'
+export type DerivedPlatformScope = 'llm:codex:execute' | 'llm:grok:execute'
export type EffectiveWorkflowControlScope = WorkflowControlScope | DerivedPlatformScope
async function postMcpHostTokenIssue(
diff --git a/workflow-recipes/src/workflow/networkPolicyFactory.ts b/workflow-recipes/src/workflow/networkPolicyFactory.ts
index f35c2dfaa..8e3895eda 100644
--- a/workflow-recipes/src/workflow/networkPolicyFactory.ts
+++ b/workflow-recipes/src/workflow/networkPolicyFactory.ts
@@ -72,6 +72,7 @@ export interface NetworkPolicyConfig {
* same eligibility projection that mints `llm:codex:execute`.
*/
includeCodexProxyEgress?: boolean
+ includeGrokProxyEgress?: boolean
includeCoordinatorGfs?: boolean
includeArtifactReader?: boolean
includeSnippetRunner?: boolean
@@ -1019,6 +1020,48 @@ export function buildWorkflowNetworkPolicies(
} as k8s.V1NetworkPolicy,
]
: []),
+ ...(config.includeGrokProxyEgress
+ ? [
+ {
+ apiVersion: 'networking.k8s.io/v1',
+ kind: 'NetworkPolicy',
+ metadata: {
+ name: `${config.recipeName}-mcp-host-to-grok-proxy`,
+ namespace: config.sandboxNamespace,
+ labels: {
+ ...commonLabels,
+ 'clerum.io/policy-type': 'grok-proxy-egress',
+ },
+ },
+ spec: {
+ podSelector: {
+ matchLabels: {
+ 'clerum.io/recipe': config.recipeName,
+ 'clerum.io/component': 'workflow-mcp-host',
+ },
+ },
+ policyTypes: ['Egress'],
+ egress: [
+ {
+ to: [
+ {
+ namespaceSelector: {
+ matchLabels: {
+ 'kubernetes.io/metadata.name': config.controlPlaneNamespace,
+ },
+ },
+ podSelector: {
+ matchLabels: { app: 'grok-llm-proxy' },
+ },
+ },
+ ],
+ ports: [{ port: 8080, protocol: 'TCP' as const }],
+ },
+ ],
+ },
+ } as k8s.V1NetworkPolicy,
+ ]
+ : []),
// 8. Plugin Workload SDK: same-recipe workloads <-> mcp-host on the SDK
// port plus mcp-host -> WRC for per-attempt credential ticket redemption.
// Empty unless the capability and feature flag are both enabled.
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
index 7a68aaa91..143243d62 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
@@ -74,6 +74,19 @@ function verdictFor(opts: {
},
hostBinding: binding,
hostBindingReason: binding ? 'eligible' : 'unassigned',
+ grokProjection: {
+ targets: [],
+ eligibleTargets: [],
+ derivedScopes: [],
+ requiresCodexProxyEgress: false,
+ requiresGrokProxyEgress: false,
+ catalogContentHash: null,
+ catalogRevision: null,
+ connectionRevision: null,
+ eligibility: 'ineligible',
+ reason: 'static_only',
+ driftHashInput: '{}',
+ },
}
}
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts
index 8996708bb..2224f6795 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts
@@ -159,6 +159,19 @@ const decidedVerdict: CodexRecipeVerdict = {
},
hostBinding: null,
hostBindingReason: 'unassigned',
+ grokProjection: {
+ targets: [],
+ eligibleTargets: [],
+ derivedScopes: [],
+ requiresCodexProxyEgress: false,
+ requiresGrokProxyEgress: false,
+ catalogContentHash: null,
+ catalogRevision: null,
+ connectionRevision: null,
+ eligibility: 'ineligible',
+ reason: 'static_only',
+ driftHashInput: '{}',
+ },
}
describe('ensureEagerSdkMcpHost image-drift roll', () => {
@@ -730,6 +743,19 @@ describe('ensureEagerSdkMcpHost ConfigMap snapshot skip', () => {
},
hostBinding: null,
hostBindingReason: 'provenance_uncertain',
+ grokProjection: {
+ targets: [],
+ eligibleTargets: [],
+ derivedScopes: [],
+ requiresCodexProxyEgress: false,
+ requiresGrokProxyEgress: false,
+ catalogContentHash: null,
+ catalogRevision: null,
+ connectionRevision: null,
+ eligibility: 'ineligible',
+ reason: 'static_only',
+ driftHashInput: '{}',
+ },
} satisfies CodexRecipeVerdict,
}
)
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
index adef2d844..50daa5290 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
@@ -134,7 +134,8 @@ export type PluginWorkloadSdkProvisionerDeps = {
runtime: WorkflowRuntimePlan,
awaitsTriggeredRun: boolean,
codexProjection: CodexRecipeVerdict['projection'],
- eagerSdkMcpHost: boolean
+ eagerSdkMcpHost: boolean,
+ grokProjection?: CodexRecipeVerdict['grokProjection']
) => Promise<void>
ensureMcpHostHeadlessService: (recipeName: string) => Promise<void>
createIfNotExists: (createFn: () => Promise<unknown>, label: string) => Promise<boolean>
@@ -253,7 +254,8 @@ export class PluginWorkloadSdkProvisioner {
runtime,
/* awaitsTriggeredRun */ true,
opts.codexVerdict.projection,
- /* eagerSdkMcpHost */ true
+ /* eagerSdkMcpHost */ true,
+ opts.codexVerdict.grokProjection
)
await this.deps.ensureMcpHostHeadlessService(recipeName)
diff --git a/workflow-recipes/src/workflow/podFactory.ts b/workflow-recipes/src/workflow/podFactory.ts
index 06afbdf40..1a0bcab86 100644
--- a/workflow-recipes/src/workflow/podFactory.ts
+++ b/workflow-recipes/src/workflow/podFactory.ts
@@ -603,6 +603,8 @@ export interface McpHostPodOptions {
pluginWorkloadSdkRuntimeMode?: 'workflow' | 'sdk-only'
/** Secret residue copied onto the eager pod after a scope/binding remint. */
runtimeTokenGeneration?: string
+ grokSubscriptionEnabled?: boolean
+ recipeAgentProvider?: string
}
export function buildMcpHostPod(
@@ -756,6 +758,16 @@ export function buildMcpHostPod(
name: 'CODEX_LLM_PROXY_RUNTIME_URL',
value: 'http://codex-llm-proxy.control-plane.svc.cluster.local:8080',
},
+ ...(options.grokSubscriptionEnabled &&
+ options.recipeAgentProvider === 'grok-subscription'
+ ? [
+ { name: 'MCP_HOST_GROK_SUBSCRIPTION_ENABLED', value: 'true' },
+ {
+ name: 'GROK_LLM_PROXY_RUNTIME_URL',
+ value: 'http://grok-llm-proxy.control-plane.svc.cluster.local:8080',
+ },
+ ]
+ : []),
// PromptBridge resolves exactly one signed target credential per
// attempt through WRC. Notification-only hosts are provider-free
// and deliberately receive no broker URL.
diff --git a/workflow-recipes/src/workflow/workflowReconciler.ts b/workflow-recipes/src/workflow/workflowReconciler.ts
index 1cb15fba2..dabca33c8 100644
--- a/workflow-recipes/src/workflow/workflowReconciler.ts
+++ b/workflow-recipes/src/workflow/workflowReconciler.ts
@@ -14,6 +14,7 @@ import { decodeJwt } from 'jose'
import { randomBytes } from 'node:crypto'
import { isIP } from 'node:net'
import type { Pool } from 'pg'
+import { GROK_EXECUTE_SCOPE } from '@clerum/codex-catalog-projection'
import {
hasInvalidDigest,
hasLatestTag,
@@ -365,6 +366,7 @@ const WORKFLOW_CONTROL_SCOPE_ORDER: WorkflowControlScope[] = [
const EFFECTIVE_WORKFLOW_CONTROL_SCOPE_ORDER: EffectiveWorkflowControlScope[] = [
...WORKFLOW_CONTROL_SCOPE_ORDER,
'llm:codex:execute',
+ 'llm:grok:execute',
]
export type { CodexReconcileContext } from './codexRecipeVerdict'
@@ -946,7 +948,8 @@ export class WorkflowReconciler {
runtime,
awaitsTriggeredRun,
codexProjection,
- eagerSdkMcpHost
+ eagerSdkMcpHost,
+ grokProjection
) =>
this.applyWorkflowNetworkPolicies(
recipeName,
@@ -955,7 +958,8 @@ export class WorkflowReconciler {
runtime,
awaitsTriggeredRun,
codexProjection,
- eagerSdkMcpHost
+ eagerSdkMcpHost,
+ grokProjection
),
ensureMcpHostHeadlessService: recipeName => this.ensureMcpHostHeadlessService(recipeName),
createIfNotExists: (createFn, label) => this.createIfNotExists(createFn, label),
@@ -1030,16 +1034,22 @@ export class WorkflowReconciler {
private resolveEffectiveControlScopes(
spec: WorkflowRecipeSpec,
verdict: CodexRecipeVerdict
- ): { scopes: EffectiveWorkflowControlScope[]; codexScopeUncertain: boolean } {
+ ): {
+ scopes: EffectiveWorkflowControlScope[]
+ codexScopeUncertain: boolean
+ grokScopeUncertain: boolean
+ } {
const workflow = deriveWorkflowControlScopes(spec, {
pluginWorkloadSdkEnabled: this.deps.config.pluginWorkloadSdkEnabled,
})
- const derived = verdict.projection.derivedScopes.filter(
- scope => !workflow.includes(scope as WorkflowControlScope)
- )
+ const derived = [
+ ...verdict.projection.derivedScopes,
+ ...(verdict.grokProjection?.derivedScopes ?? []),
+ ].filter(scope => !workflow.includes(scope as WorkflowControlScope))
return {
scopes: [...workflow, ...derived] as EffectiveWorkflowControlScope[],
codexScopeUncertain: verdict.projection.eligibility === 'uncertain',
+ grokScopeUncertain: verdict.grokProjection?.eligibility === 'uncertain',
}
}
@@ -1227,6 +1237,7 @@ export class WorkflowReconciler {
`${recipeName}-mcp-host-to-gfs`,
`${recipeName}-mcp-host-to-approval-gateway`,
`${recipeName}-mcp-host-to-codex-proxy`,
+ `${recipeName}-mcp-host-to-grok-proxy`,
]
const networkPolicyNames = preserveWorkflowRuntime
? sdkNetworkPolicyNames
@@ -2132,7 +2143,9 @@ export class WorkflowReconciler {
spec,
runtime,
awaitsTriggeredRun,
- codexVerdict.projection
+ codexVerdict.projection,
+ false,
+ codexVerdict.grokProjection
)
// 6. Create Pods — mcp-host FIRST, then coordinator. If the coordinator
@@ -2208,6 +2221,8 @@ export class WorkflowReconciler {
pluginWorkloadSdkCapabilities: this.deps.config.pluginWorkloadSdkEnabled
? declaredPluginWorkloadSdkCapabilities(spec.pluginWorkloadSdk)
: [],
+ grokSubscriptionEnabled: this.deps.config.grokSubscriptionEnabled === true,
+ recipeAgentProvider: spec.agent?.provider,
}
)
await this.createIfNotExists(
@@ -2910,7 +2925,15 @@ export class WorkflowReconciler {
* decision could rest on a different snapshot than the binding did.
*/
codexProjection: CodexExecutionProjection,
- eagerSdkMcpHost = false
+ eagerSdkMcpHost = false,
+ grokProjection: CodexExecutionProjection & { requiresGrokProxyEgress?: boolean } = {
+ ...codexProjection,
+ derivedScopes: [],
+ requiresCodexProxyEgress: false,
+ requiresGrokProxyEgress: false,
+ eligibility: 'ineligible',
+ reason: 'static_only',
+ }
): Promise<k8s.V1NetworkPolicy[]> {
const runtimeHttpEgressPolicyNames = this.runtimeHttpEgressPolicyNames(recipeName, spec)
const runtimeHttpEgressState =
@@ -2942,6 +2965,7 @@ export class WorkflowReconciler {
snippetRunnerPort: 8095,
includeMcpHost,
includeCodexProxyEgress: codexProjection.requiresCodexProxyEgress && includeMcpHost,
+ includeGrokProxyEgress: grokProjection.requiresGrokProxyEgress === true && includeMcpHost,
// A stepless eager SDK host has no coordinator pod. Keep the mcp-host
// control/egress lanes, but do not manufacture coordinator policies
// whose selectors can never match a real workload.
@@ -3034,7 +3058,8 @@ export class WorkflowReconciler {
runtime: WorkflowRuntimePlan,
awaitsTriggeredRun: boolean,
codexProjection: CodexExecutionProjection,
- eagerSdkMcpHost = false
+ eagerSdkMcpHost = false,
+ grokProjection?: CodexExecutionProjection & { requiresGrokProxyEgress?: boolean }
): Promise<void> {
const policies = await this.buildWorkflowNetworkPoliciesForSpec(
recipeName,
@@ -3043,13 +3068,15 @@ export class WorkflowReconciler {
runtime,
awaitsTriggeredRun,
codexProjection,
- eagerSdkMcpHost
+ eagerSdkMcpHost,
+ grokProjection
)
for (const policy of policies) {
await this.applyNetworkPolicy(policy)
}
const policyNames = new Set(policies.map(policy => policy.metadata?.name))
const codexProxyPolicyName = `${recipeName}-mcp-host-to-codex-proxy`
+ const grokProxyPolicyName = `${recipeName}-mcp-host-to-grok-proxy`
if (!policyNames.has(codexProxyPolicyName) && codexProjection.eligibility !== 'uncertain') {
await this.safeDelete(() =>
@@ -3059,6 +3086,14 @@ export class WorkflowReconciler {
})
)
}
+ if (!policyNames.has(grokProxyPolicyName) && grokProjection?.eligibility !== 'uncertain') {
+ await this.safeDelete(() =>
+ this.deps.networkingApi.deleteNamespacedNetworkPolicy({
+ name: grokProxyPolicyName,
+ namespace: this.deps.config.sandboxNamespace,
+ })
+ )
+ }
await this.pruneLegacyMcpServersInternetEgressPolicy(recipeName)
}
@@ -3390,6 +3425,7 @@ export class WorkflowReconciler {
`${recipeName}-mcp-host-to-llm-api`,
`${recipeName}-mcp-host-to-approval-gateway`,
`${recipeName}-mcp-host-to-codex-proxy`,
+ `${recipeName}-mcp-host-to-grok-proxy`,
`${recipeName}-coord-to-snippet-runner`,
`${recipeName}-coord-to-snippet-runner-ingress`,
`${recipeName}-snippet-runner-egress`,
@@ -3773,7 +3809,8 @@ export class WorkflowReconciler {
runtimeScopeRecipeName,
effectiveScopes.scopes,
deriveRecipeHostGfsScopes(spec),
- effectiveScopes.codexScopeUncertain
+ effectiveScopes.codexScopeUncertain,
+ effectiveScopes.grokScopeUncertain
)
if (this.deps.config.pluginWorkloadSdkEnabled && spec.pluginWorkloadSdk) {
await this.pluginWorkloadSdkProvisioner.ensurePluginWorkloadSdkTokenSecret(recipeName, spec)
@@ -4709,7 +4746,8 @@ export class WorkflowReconciler {
runtimeScopeRecipeName = recipeName,
workflowControlScopes: EffectiveWorkflowControlScope[] = [],
gfsScopes: WorkflowRecipeGfsScope[] = ['gfs.read'],
- codexScopeUncertain = false
+ codexScopeUncertain = false,
+ grokScopeUncertain = false
): Promise<McpHostRuntimeTokenRefreshResult> {
const secretName = `wf-${recipeName}-mcp-host-runtime-tokens`
const sandboxNamespace = this.deps.config.sandboxNamespace
@@ -4726,7 +4764,8 @@ export class WorkflowReconciler {
workflowControlScopes,
gfsScopes,
existing,
- codexScopeUncertain
+ codexScopeUncertain,
+ grokScopeUncertain
)
} catch (err) {
if (getErrorCode(err) !== 404) throw err
@@ -4773,7 +4812,8 @@ export class WorkflowReconciler {
workflowControlScopes,
gfsScopes,
existing,
- codexScopeUncertain
+ codexScopeUncertain,
+ grokScopeUncertain
)
this.log.info(`Secret "${secretName}" already exists (skip)`)
return tokenRefresh
@@ -4801,7 +4841,8 @@ export class WorkflowReconciler {
requestedWorkflowControlScopes: EffectiveWorkflowControlScope[],
expectedGfsScopes: WorkflowRecipeGfsScope[],
existing: k8s.V1Secret,
- codexScopeUncertain = false
+ codexScopeUncertain = false,
+ grokScopeUncertain = false
): Promise<McpHostRuntimeTokenRefreshResult> {
const rawAccess = existing.data?.['mcp-host-runtime-access-token']
const rawRefresh = existing.data?.['mcp-host-runtime-refresh-token']
@@ -4835,9 +4876,22 @@ export class WorkflowReconciler {
scope: CODEX_EXECUTE_SCOPE,
})
}
- const workflowControlScopes: EffectiveWorkflowControlScope[] = preservedCodexScope
- ? [...requestedWorkflowControlScopes, CODEX_EXECUTE_SCOPE]
- : requestedWorkflowControlScopes
+ const preservedGrokScope =
+ grokScopeUncertain &&
+ accessScopes.includes(GROK_EXECUTE_SCOPE) &&
+ !requestedWorkflowControlScopes.includes(GROK_EXECUTE_SCOPE)
+ if (preservedGrokScope) {
+ this.log.warn('Grok catalog is undecidable; preserving the live Grok scope', {
+ recipeName,
+ runtimeScopeRecipeName,
+ scope: GROK_EXECUTE_SCOPE,
+ })
+ }
+ const workflowControlScopes: EffectiveWorkflowControlScope[] = [
+ ...requestedWorkflowControlScopes,
+ ...(preservedCodexScope ? [CODEX_EXECUTE_SCOPE] : []),
+ ...(preservedGrokScope ? [GROK_EXECUTE_SCOPE] : []),
+ ]
const rawMcpHostControl = existing.data?.['mcp-host-workflow-control-token']
const mcpHostControlJwt = rawMcpHostControl
? Buffer.from(rawMcpHostControl, 'base64').toString('utf-8')