Skip to content

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

TypeScript

Merge remote-tracking branch 'origin/dev' into feat/mcp-server-oauth

Diego Zacariasebee526685c3
diff --cc control-api/src/db.ts
index ae0e7ea50,0c8a8c34f..b172e91c5
--- a/control-api/src/db.ts
+++ b/control-api/src/db.ts
@@@ -5933,20 -5967,25 +5967,43 @@@ export const CONTROL_API_MIGRATIONS: Db
},
},
{
- version: '0101_oauth_grants_owner_generalization',
- // Renamed twice while rebasing onto dev: 0091 -> 0100 -> 0101 (each dev sync
- // collided with a migration dev landed at the same number). Environments where
- // the feature branch already deployed recorded it under an earlier name (the
- // dev cluster most likely as 0100_...). legacyVersions lets the runner mark
- // 0101 applied from that prior row instead of re-running the DDL and leaving an
- // orphan schema_migrations entry. Both names are unique to this migration
- // (dev's 0100 is 0100_seed_minimax_allowed_model), so there is no false-skip.
+ version: '0101_codex_multi_connection',
+ apply: applyCodexMultiConnectionSchema,
+ },
+ {
+ version: '0102_codex_catalog_models',
+ apply: applyCodexCatalogModelsSchema,
+ },
+ {
+ version: '0103_llm_provider_attempts_connection_id',
+ apply: applyLlmProviderAttemptConnectionIdSchema,
+ },
+ {
+ version: '0104_codex_grant_default_model',
+ apply: applyCodexGrantDefaultModelSchema,
+ },
+ {
+ version: '0105_codex_reusable_connection_key',
+ apply: applyCodexReusableConnectionKeySchema,
+ },
++ {
++ version: '0106_oauth_grants_owner_generalization',
++ // Renamed repeatedly while rebasing onto dev: 0091 -> 0100 -> 0101 -> 0106
++ // (each dev sync collided with a migration dev landed at the same number; the
++ // latest sync brought dev's 0101–0105 codex migrations, so 0101 is now taken
++ // by 0101_codex_multi_connection). Environments where the feature branch
++ // already deployed recorded it under an earlier name (the dev cluster most
++ // likely as 0100_...). legacyVersions lets the runner mark 0106 applied from
++ // that prior row instead of re-running the DDL and leaving an orphan
++ // schema_migrations entry. Every prior name is unique to this migration, so
++ // there is no false-skip.
+ legacyVersions: [
++ '0101_oauth_grants_owner_generalization',
+ '0100_oauth_grants_owner_generalization',
+ '0091_oauth_grants_owner_generalization',
+ ],
+ apply: applyOAuthGrantsOwnerGeneralization,
+ },
]
async function consolidateWorkflowAllowedUsersToTriggers(db: DbClient): Promise<void> {
diff --cc control-api/src/utils/auth/mcpHostJwtToken.ts
index fe3d6a568,12bfb61b3..c461b401c
--- a/control-api/src/utils/auth/mcpHostJwtToken.ts
+++ b/control-api/src/utils/auth/mcpHostJwtToken.ts
@@@ -173,11 -173,9 +173,14 @@@ export const ALL_MCP_HOST_CONTROL_SCOPE
// (status.pluginWorkloadSdk) declares the SDK; SDK routes reject access
// tokens without it via scope_denied.
'plugin-workload-sdk',
+ // OAuth mcp-server broker (U1). Lets mcp-host exchange its control JWT for a
+ // per-connection provider access token at POST /api/v1/mcp-oauth/user-token.
+ // Provisioners request it only for hosts that front OAuth mcp-servers; the
+ // route rejects control tokens lacking it with 403 insufficient_scope.
+ 'oauth:user-token',
+ // Derive-only Codex execution. HCC/WRC may request this after projecting an
+ // eligible broker target. Never add it to user-declarable Host/Recipe CRD fields.
+ 'llm:codex:execute',
] as const
export type McpHostControlScope = (typeof ALL_MCP_HOST_CONTROL_SCOPES)[number]
diff --cc control-api/src/utils/log/redact.ts
index a72746bed,d1d5db37e..c00e374ce
--- a/control-api/src/utils/log/redact.ts
+++ b/control-api/src/utils/log/redact.ts
@@@ -17,8 -19,12 +19,14 @@@ export const TOKEN_LEAK_REDACT_PATHS: r
'claimToken',
'client_secret',
'clientSecret',
+ 'code_verifier',
+ 'codeVerifier',
+ 'executionTicket',
+ 'attemptReceipt',
+ 'id_token',
+ 'idToken',
+ 'pkceVerifier',
+ 'refresh_token',
]
/** Asserted by unit tests so redactions can grow but never shrink. */
@@@ -32,6 -40,10 +42,12 @@@ export const REQUIRED_REDACT_PATHS: rea
'claimToken',
'client_secret',
'clientSecret',
+ 'code_verifier',
+ 'codeVerifier',
+ 'executionTicket',
+ 'attemptReceipt',
+ 'id_token',
+ 'idToken',
+ 'pkceVerifier',
+ 'refresh_token',
]
diff --cc control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
index 6639885ee,000000000..936985932
mode 100644,000000..100644
--- a/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
+++ b/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
@@@ -1,80 -1,0 +1,83 @@@
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+const clientQuery = vi.fn()
+const clientRelease = vi.fn()
+const mockConnect = vi.fn()
+const mockPoolCtor = vi.fn(function MockPool() {
+ return { connect: mockConnect, query: vi.fn() }
+})
+
+vi.mock('pg', () => ({ Pool: mockPoolCtor }))
+
+describe('0101 oauth_grants owner generalization migration', () => {
+ beforeEach(() => {
+ vi.resetModules()
+ vi.clearAllMocks()
+ mockConnect.mockResolvedValue({ query: clientQuery, release: clientRelease })
+ clientQuery.mockResolvedValue({ rows: [], rowCount: 0 })
+ })
+
+ it('is registered last in the migration array, after 0100_seed_minimax', async () => {
+ const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')
+ const versions = CONTROL_API_MIGRATIONS.map(m => m.version)
- expect(versions.at(-1)).toBe('0101_oauth_grants_owner_generalization')
++ expect(versions.at(-1)).toBe('0106_oauth_grants_owner_generalization')
+ expect(versions).toContain('0099_gfs_upload_finalizing_recovery')
+ expect(versions).toContain('0100_seed_minimax_allowed_model')
+ })
+
+ it('carries its prior names as legacyVersions so a deploy that already ran it is not re-executed', async () => {
- // Renamed 0091 -> 0100 -> 0101 across dev syncs. Environments that recorded an
- // earlier name (the dev cluster) must mark 0101 applied from that row instead
- // of re-running the DDL. See applyPendingMigrations' legacyVersions branch.
++ // Renamed 0091 -> 0100 -> 0101 -> 0106 across dev syncs (the last sync brought
++ // dev's 0101-0105 codex migrations, taking the 0101 slot). Environments that
++ // recorded an earlier name (the dev cluster) must mark 0106 applied from that
++ // row instead of re-running the DDL. See applyPendingMigrations' legacyVersions
++ // branch.
+ const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')
+ const migration = CONTROL_API_MIGRATIONS.find(
- m => m.version === '0101_oauth_grants_owner_generalization'
++ m => m.version === '0106_oauth_grants_owner_generalization'
+ )
+ expect(migration?.legacyVersions).toEqual([
++ '0101_oauth_grants_owner_generalization',
+ '0100_oauth_grants_owner_generalization',
+ '0091_oauth_grants_owner_generalization',
+ ])
+ })
+
+ it('adds owner_kind/context_id/bootstrapped_by, replaces the kind CHECK to admit shared, and rebuilds uniqueness', async () => {
+ const { initDb } = await import('../src/db.js')
+ await initDb()
+ const sqls = clientQuery.mock.calls.map(([sql]) => String(sql))
+ const migration = sqls.find(
+ sql => sql.includes('ADD COLUMN IF NOT EXISTS owner_kind') && sql.includes('oauth_grants')
+ )
+ expect(migration, 'the oauth_grants generalization DDL was applied').toBeDefined()
+ const ddl = migration as string
+
+ // New columns (idempotent).
+ expect(ddl).toContain("ADD COLUMN IF NOT EXISTS owner_kind TEXT NOT NULL DEFAULT 'recipe'")
+ expect(ddl).toContain('ADD COLUMN IF NOT EXISTS context_id TEXT')
+ expect(ddl).toContain('ADD COLUMN IF NOT EXISTS bootstrapped_by_user_id TEXT')
+
+ // The kind/user_id CHECK is DROP+re-ADD to admit 'shared' — without this a
+ // shared INSERT would violate the old user/service-only CHECK.
+ expect(ddl).toContain('DROP CONSTRAINT IF EXISTS oauth_grants_kind_userid_check')
+ expect(ddl).toContain("grant_kind = 'shared' AND user_id IS NULL")
+ expect(ddl).toContain('context_id IS NOT NULL')
+ expect(ddl).toContain('bootstrapped_by_user_id IS NOT NULL')
+
+ // oauth_grants_unique recreated as a superset with owner_kind.
+ expect(ddl).toContain('DROP CONSTRAINT IF EXISTS oauth_grants_unique')
+ expect(ddl).toContain(
+ 'UNIQUE (owner_kind, recipe_namespace, recipe_name, user_id, oauth_client_id)'
+ )
+
+ // Shared partial unique index keyed by context_id.
+ expect(ddl).toContain('CREATE UNIQUE INDEX IF NOT EXISTS oauth_grants_shared_unique')
+ expect(ddl).toContain(
+ 'ON oauth_grants (owner_kind, recipe_namespace, recipe_name, context_id, oauth_client_id)'
+ )
+ expect(ddl).toContain("WHERE grant_kind = 'shared'")
+
+ // Non-destructive: recipe_namespace/recipe_name are NOT renamed.
+ expect(ddl).not.toContain('RENAME COLUMN')
+ })
+})
diff --cc deploy/base/control-plane/configmaps.yaml
index a99a0b531,2c35e4d6f..5b9b634d3
--- a/deploy/base/control-plane/configmaps.yaml
+++ b/deploy/base/control-plane/configmaps.yaml
@@@ -249,34 -237,28 +252,56 @@@ data
proxy_set_header X-Forwarded-Proto $scheme;
}
+ # U5: mint a fresh authorize-URL for an OAuth mcp-server (reactive
+ # consent). rpc-proxy is the sole caller; requireInternalService('rpc-proxy')
+ # gates it at control-api.
+ location = /api/v1/internal/mcp-oauth/authorize-url {
+ limit_except POST {
+ deny all;
+ }
+ proxy_pass http://control_api_upstream;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ }
+
+ location = /api/v1/internal/llm/provider-attempts/redeem {
+ limit_except POST {
+ deny all;
+ }
+ proxy_pass http://control_api_upstream;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ }
+
+ # spec 11 U4: revoke an OAuth mcp-server grant (desktop "Disconnect").
+ # rpc-proxy is the sole caller; requireInternalService('rpc-proxy') gates
+ # it at control-api.
+ location = /api/v1/internal/mcp-oauth/grant {
+ limit_except DELETE {
+ deny all;
+ }
+ proxy_pass http://control_api_upstream;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ }
+
+ location = /api/v1/internal/llm/provider-attempts/finalize {
+ limit_except POST {
+ deny all;
+ }
+ proxy_pass http://control_api_upstream;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ }
+
location / {
return 403;
}
diff --cc host-context-controller/src/hostReconciler.ts
index 3729828f6,f49cf4ad0..7bc6ce9d0
--- a/host-context-controller/src/hostReconciler.ts
+++ b/host-context-controller/src/hostReconciler.ts
@@@ -47,9 -63,9 +63,10 @@@ import { EffectiveHostLifecycle, Suspen
import { ReflectHostOutcomeFn, StatelessLifecycleExecutor } from './statelessLifecycleExecutor'
import {
CommunicationChannelCRD,
+ EffectiveMcpHostControlScope,
HostCRD,
HostChannelReaderStatus,
+ HostRuntimeControlScope,
HostRuntimeStatus,
HostWorkflowControlScope,
HostWorkflowControlSpec,
@@@ -1167,23 -1068,23 +1186,31 @@@ export class HostReconciler
private static runtimeTokenScopeHash(
host: HostCRD,
hasChannelIngress = false,
- frontsOAuthServer = false
++ frontsOAuthServer = false,
+ projection?: CodexExecutionProjection
): string {
// Hash the EFFECTIVE (resolved) scopes — what actually gets minted into the
// control token — so change-detection matches the default-fallback applied
// at issuance (otherwise a null workflowControl hashes as [] while the token
- // carries the first-party defaults, and the two drift).
- const workflowScopes = [
- ...resolveWorkflowControlScopes(host.spec.workflowControl, { hasChannelIngress }),
+ // carries the first-party defaults, and the two drift). Uses the SAME
+ // `resolveRuntimeControlScopes` as the mint path (see
- // `resolveWorkflowControlScopesForHost`) so the hashed set and the minted
- // set — including the derive-only `oauth:user-token` — can never diverge.
- return HostReconciler.shortHash(
- [
- ...resolveRuntimeControlScopes(host.spec.workflowControl, {
- hasChannelIngress,
- frontsOAuthServer,
- }),
- ].sort()
- )
++ // `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.
++ const runtimeScopes = [
++ ...resolveRuntimeControlScopes(host.spec.workflowControl, {
++ hasChannelIngress,
++ frontsOAuthServer,
++ }),
+ ].sort()
+ const derived = projection?.derivedScopes ?? []
+ if (derived.length === 0) {
- return HostReconciler.shortHash(workflowScopes)
++ return HostReconciler.shortHash(runtimeScopes)
+ }
+ return HostReconciler.shortHash({
- scopes: [...workflowScopes, ...derived].sort(),
++ scopes: [...runtimeScopes, ...derived].sort(),
+ drift: projection?.driftHashInput,
+ })
}
private static gfsCapabilitySetHash(): string {
@@@ -1209,8 -1110,8 +1236,9 @@@
nowMs: number,
gfsTokenTtlSec: number,
hasChannelIngress = false,
+ frontsOAuthServer = false,
- preservedHostUid?: string
+ preservedHostUid?: string,
+ projection?: CodexExecutionProjection
): Record<string, string> {
const refreshTtlSec = Number.isFinite(tokens.refreshExpiresInSeconds)
? Math.max(0, tokens.refreshExpiresInSeconds)
@@@ -1228,7 -1129,7 +1256,8 @@@
[RUNTIME_TOKEN_SCOPE_HASH_ANNOTATION]: HostReconciler.runtimeTokenScopeHash(
host,
hasChannelIngress,
- frontsOAuthServer
++ frontsOAuthServer,
+ projection
),
[RUNTIME_TOKEN_ISSUER_ANNOTATION]: RUNTIME_TOKEN_ISSUER,
[RUNTIME_TOKEN_AUDIENCE_ANNOTATION]: RUNTIME_TOKEN_AUDIENCE,
@@@ -1259,7 -1160,7 +1288,8 @@@
secret: k8s.V1Secret,
nowMs: number,
hasChannelIngress = false,
- frontsOAuthServer = false
++ frontsOAuthServer = false,
+ projection?: 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) {
@@@ -1277,7 -1178,7 +1307,8 @@@
const expectedScopeHash = HostReconciler.runtimeTokenScopeHash(
host,
hasChannelIngress,
- frontsOAuthServer
++ frontsOAuthServer,
+ projection
)
const hasContractMetadata =
RUNTIME_TOKEN_HOST_BINDING_HASH_ANNOTATION in annotations ||
@@@ -1488,6 -1381,80 +1519,87 @@@
return scopes
}
+ private projectCodexForHost(host: HostCRD): CodexExecutionProjection {
+ const connectionKey = assignedHostCodexConnectionRef(host.spec.model?.connectionRef)
+ const snapshot = snapshotForAssignedCodexGrant(
+ connectionKey,
+ this.lastCodexConfigMap,
+ this.codexSnapshot
+ )
+ return projectCodexExecution(host.spec, snapshot)
+ }
+
+ private resolveEffectiveControlScopesForHost(
+ host: HostCRD,
++ frontsOAuthServer: boolean,
+ hasChannelIngress = this.hasChannelIngress(host)
+ ): EffectiveMcpHostControlScope[] {
- const workflow = this.resolveWorkflowControlScopesForHost(host, hasChannelIngress)
++ const workflow = this.resolveWorkflowControlScopesForHost(
++ host,
++ hasChannelIngress,
++ frontsOAuthServer
++ )
+ const derived = this.projectCodexForHost(host).derivedScopes.filter(
+ scope => !workflow.includes(scope as HostWorkflowControlScope)
+ )
+ return [...workflow, ...derived] as EffectiveMcpHostControlScope[]
+ }
+
+ private runtimeScopeHashFor(
+ host: HostCRD,
++ frontsOAuthServer: boolean,
+ hasChannelIngress = this.hasChannelIngress(host)
+ ): string {
+ return HostReconciler.runtimeTokenScopeHash(
+ host,
+ hasChannelIngress,
++ frontsOAuthServer,
+ this.projectCodexForHost(host)
+ )
+ }
+
+ private async refreshCodexSnapshot(): Promise<void> {
+ try {
+ const cm = await this.coreApi.readNamespacedConfigMap({
+ name: ALLOWED_MODELS_CONFIGMAP_NAME,
+ namespace: config.hccTargetNamespace,
+ })
+ this.lastCodexConfigMap = cm
+ this.codexSnapshot = parseAllowedModelsSnapshot(cm)
+ } catch (err) {
+ const timeout =
+ err instanceof HostK8sRequestTimeoutError ||
+ (err as { code?: string }).code === HOST_K8S_REQUEST_TIMEOUT_CODE
+ if (timeout) {
+ this.lastCodexConfigMap = undefined
+ this.codexSnapshot = snapshotFromConfigMapError('timeout')
+ log.warn('Codex allowlist ConfigMap read timed out; failing closed', {
+ configMap: ALLOWED_MODELS_CONFIGMAP_NAME,
+ namespace: config.hccTargetNamespace,
+ })
+ return
+ }
+ const code = getErrorCode(err)
+ if (code === 401 || code === 403) {
+ this.lastCodexConfigMap = undefined
+ this.codexSnapshot = snapshotFromConfigMapError('forbidden')
+ log.warn('Codex allowlist ConfigMap read forbidden; failing closed', {
+ configMap: ALLOWED_MODELS_CONFIGMAP_NAME,
+ namespace: config.hccTargetNamespace,
+ statusCode: code,
+ })
+ return
+ }
+ this.lastCodexConfigMap = undefined
+ this.codexSnapshot = snapshotFromConfigMapError('missing')
+ log.warn('Codex allowlist ConfigMap unavailable; failing closed', {
+ configMap: ALLOWED_MODELS_CONFIGMAP_NAME,
+ namespace: config.hccTargetNamespace,
+ statusCode: code,
+ })
+ }
+ }
+
private async ensureMcpHostRuntimeTokenSecret(
host: HostCRD,
options: BootstrapOptions = {}
@@@ -1515,15 -1482,8 +1627,18 @@@
RUNTIME_TOKEN_BOOTSTRAP_STATE_FRESH
const nowMs = Date.now()
const hasChannelIngress = this.hasChannelIngress(host)
- // Resolve ONCE per issuance and thread the SAME bool into the mint-scope
- // derive, the refresh decision, the scope hash and the stored
- // annotation, so the minted token and the drift hash never diverge.
++ // Resolve ONCE per issuance and thread the SAME frontsOAuthServer bool and
++ // codex projection into the mint-scope derive, the refresh decision, the
++ // scope hash and the stored annotation, so the minted token and the drift
++ // hash never diverge.
+ const frontsOAuthServer = await this.frontsOAuthServer(host)
+ const projection = this.projectCodexForHost(host)
- const scopeHash = this.runtimeScopeHashFor(host, hasChannelIngress)
+ const scopeHash = HostReconciler.runtimeTokenScopeHash(
+ host,
+ hasChannelIngress,
- frontsOAuthServer
++ frontsOAuthServer,
++ projection
+ )
let decision: {
refresh: boolean
rolloutRequired: boolean
@@@ -1535,7 -1495,7 +1650,8 @@@
existing,
nowMs,
hasChannelIngress,
- frontsOAuthServer
++ frontsOAuthServer,
+ projection
)
: { refresh: true, rolloutRequired: false, reason: 'missing_secret' }
if (
@@@ -1677,7 -1637,7 +1793,7 @@@
const tokens = await issueMcpHostRuntimeTokens(
host.name,
host.uid ?? '',
- this.resolveWorkflowControlScopesForHost(host, hasChannelIngress, frontsOAuthServer)
- this.resolveEffectiveControlScopesForHost(host, hasChannelIngress)
++ this.resolveEffectiveControlScopesForHost(host, frontsOAuthServer, hasChannelIngress)
)
const gfs = await mintHostGfsToken({ name: host.name, namespace: host.namespace })
const body = buildMcpHostRuntimeTokenSecret(
@@@ -1705,8 -1665,8 +1821,9 @@@
nowMs,
gfs.expiresInSeconds,
hasChannelIngress,
+ frontsOAuthServer,
- existing?.metadata?.annotations?.[GFS_TOKEN_HOST_UID_ANNOTATION]
+ existing?.metadata?.annotations?.[GFS_TOKEN_HOST_UID_ANNOTATION],
+ projection
),
[RUNTIME_TOKEN_BOOTSTRAP_STATE_ANNOTATION]: RUNTIME_TOKEN_BOOTSTRAP_STATE_FRESH,
[RUNTIME_TOKEN_ROLLOUT_REQUIRED_ANNOTATION]: rolloutRequired ? 'true' : 'false',
@@@ -4263,11 -4314,7 +4471,7 @@@
const ensureCurrentRuntimeTokenScope = async (): Promise<void> => {
for (let attempt = 1; attempt <= 3; attempt++) {
revalidateHostMutationBoundary()
- const currentScopeHash = HostReconciler.runtimeTokenScopeHash(
- host,
- this.hasChannelIngress(host),
- await this.frontsOAuthServer(host)
- )
- const currentScopeHash = this.runtimeScopeHashFor(host)
++ const currentScopeHash = this.runtimeScopeHashFor(host, await this.frontsOAuthServer(host))
if (runtimeTokenProvision.scopeHash === currentScopeHash) return
runtimeTokenProvision = await this.provisionRuntimeTokenRevision(host, {
@@@ -4276,11 -4323,7 +4480,10 @@@
lifecycle.effective.stateless && lifecycle.effective.state === 'suspended',
})
revalidateHostMutationBoundary()
- const postProvisionScopeHash = HostReconciler.runtimeTokenScopeHash(
- const postProvisionScopeHash = this.runtimeScopeHashFor(host)
++ const postProvisionScopeHash = this.runtimeScopeHashFor(
+ host,
- this.hasChannelIngress(host),
+ await this.frontsOAuthServer(host)
+ )
if (runtimeTokenProvision.scopeHash === postProvisionScopeHash) return
log.warn('CommunicationChannel scope contract changed during token provisioning', {
@@@ -4300,11 -4343,7 +4503,7 @@@
await resolveDeploymentLifecycle()
await ensureCurrentRuntimeTokenScope()
const effective = await resolveDeploymentLifecycle()
- const currentScopeHash = HostReconciler.runtimeTokenScopeHash(
- host,
- this.hasChannelIngress(host),
- await this.frontsOAuthServer(host)
- )
- const currentScopeHash = this.runtimeScopeHashFor(host)
++ const currentScopeHash = this.runtimeScopeHashFor(host, await this.frontsOAuthServer(host))
if (runtimeTokenProvision.scopeHash === currentScopeHash) {
revalidateHostMutationBoundary()
return {
diff --cc host-context-controller/src/types.ts
index c14322ba8,be518db34..e01d50d7d
--- a/host-context-controller/src/types.ts
+++ b/host-context-controller/src/types.ts
@@@ -424,6 -400,9 +440,14 @@@ export type HostWorkflowControlScope
| 'workflow:approval:resolve'
| 'workflow:approval:decide'
+ export type DerivedPlatformScope = 'llm:codex:execute'
-export type EffectiveMcpHostControlScope = HostWorkflowControlScope | DerivedPlatformScope
++// 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
++// `llm:codex:execute` derive. Both derives can co-occur on one Host, so this
++// must be their union, not either alone.
++export type EffectiveMcpHostControlScope = HostRuntimeControlScope | DerivedPlatformScope
+
export interface HostWorkflowControlSpec {
scopes?: HostWorkflowControlScope[]
}
diff --cc host-context-controller/test/mcpHostRuntimeTokenIssuerClient.test.ts
index ba498c7e0,b5aebd3b3..d50d2daff
--- a/host-context-controller/test/mcpHostRuntimeTokenIssuerClient.test.ts
+++ b/host-context-controller/test/mcpHostRuntimeTokenIssuerClient.test.ts
@@@ -166,24 -166,22 +166,40 @@@ describe('mcpHostRuntimeTokenIssuerClie
expect(claims.jti).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
})
+ it('serializes the derive-only oauth:user-token scope into the request body', async () => {
+ const fetchMock = vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => canonicalIssueResponse(),
+ } as Response)
+ globalThis.fetch = fetchMock as unknown as typeof globalThis.fetch
+
+ const issueMcpHostRuntimeTokens = await loadIssuer()
+ await issueMcpHostRuntimeTokens('chatllm', 'host-uid', ['workflow:read', 'oauth:user-token'])
+
+ const [, init] = fetchMock.mock.calls[0]
+ // The scope must survive verbatim into the wire body control-api reads —
+ // proving the broker actually receives `oauth:user-token`.
+ expect((init as RequestInit).body).toBe(
+ '{"includeMcpHostControlToken":true,"host":"chatllm","hostUid":"host-uid","workflowControlScopes":["workflow:read","oauth:user-token"]}'
+ )
+ })
+
+ it('forwards derived llm:codex:execute in the issuance body', async () => {
+ const fetchMock = vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => canonicalIssueResponse(),
+ } as Response)
+ globalThis.fetch = fetchMock as unknown as typeof globalThis.fetch
+
+ const issueMcpHostRuntimeTokens = await loadIssuer()
+ await issueMcpHostRuntimeTokens('chatllm', 'host-uid', ['workflow:list', 'llm:codex:execute'])
+
+ const [, init] = fetchMock.mock.calls[0]
+ expect((init as RequestInit).body).toBe(
+ '{"includeMcpHostControlToken":true,"host":"chatllm","hostUid":"host-uid","workflowControlScopes":["workflow:list","llm:codex:execute"]}'
+ )
+ })
+
it('rejects a target namespace that differs from the live Host namespace', async () => {
vi.resetModules()
process.env.HCC_TARGET_NAMESPACE = 'first-party-hosts'
diff --cc mcp-host/package-lock.json
index e73fa5691,2b5e0d13e..f2fa74fc4
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@@ -1,12 -1,12 +1,12 @@@
{
"name": "clerum-mcp-host",
- "version": "0.1.301",
- "version": "0.1.298",
++ "version": "0.1.302",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.301",
- "version": "0.1.298",
++ "version": "0.1.302",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --cc mcp-host/package.json
index d994b340c,aae3c98fc..986372386
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "clerum-mcp-host",
- "version": "0.1.301",
- "version": "0.1.298",
++ "version": "0.1.302",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --cc tests/e2e/package-lock.json
index 2d8c350d2,2d8c350d2..ab0892116
--- a/tests/e2e/package-lock.json
+++ b/tests/e2e/package-lock.json
@@@ -1,12 -1,12 +1,12 @@@
{
"name": "clerum-e2e-tests",
-- "version": "0.1.78",
++ "version": "0.1.79",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-e2e-tests",
-- "version": "0.1.78",
++ "version": "0.1.79",
"devDependencies": {
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^22.0.0",
diff --cc tests/e2e/package.json
index 0a723dd34,0a723dd34..c59047da2
--- a/tests/e2e/package.json
+++ b/tests/e2e/package.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "clerum-e2e-tests",
-- "version": "0.1.78",
++ "version": "0.1.79",
"private": true,
"type": "module",
"scripts": {