Skip to content

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

TypeScript

feat(oauth): legalize remote-oauth mcpservers + HCC auth precedence (C3)

Diego Zacariasbaf12e1fac26
diff --git a/charts/clerum-crds/crds/mcpserver.yaml b/charts/clerum-crds/crds/mcpserver.yaml
index 217cc2d02..12a39b164 100644
--- a/charts/clerum-crds/crds/mcpserver.yaml
+++ b/charts/clerum-crds/crds/mcpserver.yaml
@@ -120,20 +120,16 @@ spec:
connection just-in-time and NEVER mounted into the pod. Shape
mirrors WorkflowRecipe spec.oauthClients[] (a single client per
server).
- required:
- - id
- - provider
- - clientIdRef
- - clientSecretRef
properties:
id:
type: string
- maxLength: 63
- pattern: "^[a-z0-9-]{1,63}$"
+ maxLength: 512
description: >-
Stable OAuth client identifier for this server. Surfaced as
the `clientId` on clerum:oauth URLs and the callback path
- segment. Immutable once set.
+ segment. Immutable once set. Baked carril (source absent) is
+ re-narrowed to ^[a-z0-9-]{1,63}$ by CEL; remote carril carries
+ an AS-assigned client_id (arbitrary charset).
provider:
type: string
# Known-shape adapters baked into control-api
@@ -180,10 +176,10 @@ spec:
maxLength: 253
scopes:
type: array
- maxItems: 32
+ maxItems: 128
items:
type: string
- maxLength: 128
+ maxLength: 512
description: >-
OAuth scopes to request. Provider-specific syntax. Include
the provider's offline/refresh scope when backgroundAccess
@@ -208,6 +204,59 @@ spec:
bootstraps it and the rest inherit it, keyed by
(server, context). Immutable once set: flipping it would
change in place which identity is exercised.
+ source:
+ type: string
+ enum: [remote]
+ description: >-
+ Carril discriminator. ABSENT = baked (a known-shape adapter
+ via spec.oauth.provider). 'remote' = a discovery-configured
+ client (control-api remote-MCP install) whose pinned endpoints
+ below replace the baked provider. Immutable; the carril cannot flip.
+ clientMode:
+ type: string
+ enum: [public, confidential]
+ description: >-
+ REMOTE only. 'public' (CIMD/PKCE, no client secret) or
+ 'confidential' (secret via clientIdRef/clientSecretRef, or the
+ encrypted dynamic_clients store for DCR). Immutable.
+ authorizationEndpoint:
+ type: string
+ maxLength: 2048
+ description: REMOTE only. Pinned discovery authorize URL. Immutable.
+ tokenEndpoint:
+ type: string
+ maxLength: 2048
+ description: REMOTE only. Pinned discovery token URL. Immutable.
+ registrationEndpoint:
+ type: string
+ maxLength: 2048
+ description: REMOTE only, optional. Pinned DCR registration URL. Immutable.
+ issuer:
+ type: string
+ maxLength: 2048
+ description: REMOTE only. Pinned AS issuer. Immutable.
+ resource:
+ type: string
+ maxLength: 2048
+ description: REMOTE only. RFC 8707 resource sent on authorize+token. Immutable.
+ issForCallback:
+ type: string
+ maxLength: 2048
+ description: >-
+ REMOTE only, optional. RFC 9207 iss to validate the callback
+ against (present only when advertised). Immutable.
+ bearerInBody:
+ type: boolean
+ description: >-
+ REMOTE only (D-8). Token goes in the request body, not the
+ Authorization header. No default (required-by-CEL for remote).
+ Immutable (pinned at install; runtime never re-derives).
+ supportsRefresh:
+ type: boolean
+ description: >-
+ REMOTE only (D-8), fail-closed. false ⇒ never attempt refresh.
+ No default (required-by-CEL for remote). Immutable (pinned at
+ install; runtime never re-derives).
serverConfig:
type: object
description: Operational configuration for the MCP server runtime.
@@ -504,9 +553,14 @@ spec:
# id / provider that ALREADY existed is rejected.
- rule: "!has(oldSelf.oauth) || !has(self.oauth) || oldSelf.oauth.grantScope == self.oauth.grantScope"
message: "spec.oauth.grantScope is immutable; delete and recreate the McpServer to change which identity is exercised"
- - rule: "!has(oldSelf.oauth) || !has(self.oauth) || oldSelf.oauth.id == self.oauth.id"
+ # id/provider value immutability (IMM-2/IMM-4) is has()-guarded on
+ # BOTH the coordinate presence and the oauth presence: a remote-carril
+ # UPDATE has no id/provider, so an unguarded dereference would
+ # CEL-ERROR. The presence of id (IMM-3) and of the carril (IMM-5) are
+ # pinned separately below, so guarding the value comparison is safe.
+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || !has(oldSelf.oauth.id) || !has(self.oauth.id) || oldSelf.oauth.id == self.oauth.id"
message: "spec.oauth.id is immutable"
- - rule: "!has(oldSelf.oauth) || !has(self.oauth) || oldSelf.oauth.provider == self.oauth.provider"
+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || !has(oldSelf.oauth.provider) || !has(self.oauth.provider) || oldSelf.oauth.provider == self.oauth.provider"
message: "spec.oauth.provider is immutable"
# R1-L1: close the two-step immutability bypass. The rules above
# short-circuit on !has(self.oauth), so an UPDATE could (1) drop
@@ -537,6 +591,53 @@ spec:
# 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"
+ # C3 remote×oauth carril. spec.oauth.source discriminates the carril:
+ # ABSENT = baked (a known-shape provider adapter), 'remote' = a
+ # discovery-configured client with pinned endpoints. The block-level
+ # `required` is gone; requiredness is carril-specific and enforced
+ # here so each carril rejects the other's shape.
+ #
+ # Baked-only slug re-narrow: the structural `pattern` moved to CEL so
+ # the remote carril can carry an AS-assigned client_id (arbitrary
+ # charset). Gated on baked (has(self.oauth.source) short-circuits for
+ # remote) so remote ids are not re-narrowed.
+ - rule: "!has(self.oauth) || has(self.oauth.source) || !has(self.oauth.id) || self.oauth.id.matches('^[a-z0-9-]{1,63}$')"
+ message: "baked spec.oauth.id must match ^[a-z0-9-]{1,63}$"
+ # BAKED-REQ: baked (no source) requires the classic adapter quartet.
+ - rule: "!has(self.oauth) || has(self.oauth.source) || (has(self.oauth.id) && has(self.oauth.provider) && has(self.oauth.clientIdRef) && has(self.oauth.clientSecretRef))"
+ message: "baked spec.oauth (no source) requires id, provider, clientIdRef and clientSecretRef"
+ # REMOTE-REQ: remote requires the pinned discovery client shape.
+ - rule: "!has(self.oauth) || !has(self.oauth.source) || (has(self.oauth.clientMode) && has(self.oauth.authorizationEndpoint) && has(self.oauth.tokenEndpoint) && has(self.oauth.issuer) && has(self.oauth.resource) && has(self.oauth.bearerInBody) && has(self.oauth.supportsRefresh))"
+ message: "remote spec.oauth requires clientMode, authorizationEndpoint, tokenEndpoint, issuer, resource, bearerInBody and supportsRefresh"
+ # REMOTE-FORBID-PROVIDER: source 'remote' replaces the baked adapter.
+ - rule: "!has(self.oauth) || !has(self.oauth.source) || !has(self.oauth.provider)"
+ message: "remote spec.oauth must not set provider; source 'remote' replaces the baked adapter"
+ # BAKED-FORBID-REMOTE-FIELDS: baked must not carry remote-only fields.
+ - rule: "!has(self.oauth) || has(self.oauth.source) || (!has(self.oauth.clientMode) && !has(self.oauth.authorizationEndpoint) && !has(self.oauth.tokenEndpoint) && !has(self.oauth.registrationEndpoint) && !has(self.oauth.issuer) && !has(self.oauth.resource) && !has(self.oauth.issForCallback) && !has(self.oauth.bearerInBody) && !has(self.oauth.supportsRefresh))"
+ message: "baked spec.oauth (no source) must not set remote-only fields"
+ # IMM-3: id presence is immutable — closes the drop/re-add two-step
+ # that would otherwise let an UPDATE add or remove id under a
+ # value-only immutability guard.
+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || has(oldSelf.oauth.id) == has(self.oauth.id)"
+ message: "spec.oauth.id presence is immutable; delete and recreate to add or remove it"
+ # IMM-5: the carril (source presence) is immutable — baked cannot flip
+ # to remote or vice versa in place.
+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || has(oldSelf.oauth.source) == has(self.oauth.source)"
+ message: "spec.oauth carril (source) is immutable; delete and recreate to change it"
+ # IMM-6: remote pinned endpoints + clientMode + registration +
+ # issForCallback + the discovery-derived quirks (bearerInBody,
+ # supportsRefresh) are immutable. These are all pinned at install from
+ # AS metadata and the runtime never re-derives them (D-4/D-8), so an
+ # update-RBAC actor must not flip them in place — e.g. supportsRefresh
+ # false→true would re-enable refresh against the pinned token endpoint,
+ # defeating the D-8 fail-closed decision. Double-source-guarded so it
+ # only dereferences remote-only fields when BOTH revisions are remote;
+ # REMOTE-REQ then guarantees clientMode/endpoints/issuer/resource/
+ # bearerInBody/supportsRefresh are present, so those accesses cannot
+ # CEL-error. registrationEndpoint/issForCallback are optional even on
+ # remote → presence-pinned + guarded value-equality.
+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || !has(oldSelf.oauth.source) || !has(self.oauth.source) || (oldSelf.oauth.clientMode == self.oauth.clientMode && oldSelf.oauth.authorizationEndpoint == self.oauth.authorizationEndpoint && oldSelf.oauth.tokenEndpoint == self.oauth.tokenEndpoint && oldSelf.oauth.issuer == self.oauth.issuer && oldSelf.oauth.resource == self.oauth.resource && oldSelf.oauth.bearerInBody == self.oauth.bearerInBody && oldSelf.oauth.supportsRefresh == self.oauth.supportsRefresh && (has(oldSelf.oauth.registrationEndpoint) == has(self.oauth.registrationEndpoint)) && (!has(oldSelf.oauth.registrationEndpoint) || oldSelf.oauth.registrationEndpoint == self.oauth.registrationEndpoint) && (has(oldSelf.oauth.issForCallback) == has(self.oauth.issForCallback)) && (!has(oldSelf.oauth.issForCallback) || oldSelf.oauth.issForCallback == self.oauth.issForCallback))"
+ message: "remote spec.oauth pinned endpoints/clientMode/quirks are immutable; delete and recreate to change them"
status:
type: object
properties:
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 2498af64c..900dc4ee9 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.591",
+ "version": "0.1.592",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.591",
+ "version": "0.1.592",
"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 798e366f8..5a7c785da 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.591",
+ "version": "0.1.592",
"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 51d23b5af..4888586fb 100644
--- a/control-api/test/crd.mcpServerOauth.test.ts
+++ b/control-api/test/crd.mcpServerOauth.test.ts
@@ -27,12 +27,12 @@ describe('McpServer CRD — OAuth surface (U1)', () => {
expect(specSchema.properties.auth.properties.type.enum).toContain('oauth')
})
- it('defines spec.oauth with the required client fields', () => {
+ it('drops the block-level required and enforces the baked quartet via CEL (BAKED-REQ)', () => {
const oauth = specSchema.properties.oauth
expect(oauth.type).toBe('object')
- expect(oauth.required).toEqual(
- expect.arrayContaining(['id', 'provider', 'clientIdRef', 'clientSecretRef'])
- )
+ // The static block-level required is gone — requiredness is now carril-specific
+ // (baked vs remote) and enforced by CEL, not by a single required list.
+ expect(oauth.required).toBeUndefined()
for (const p of [
'id',
'provider',
@@ -44,6 +44,149 @@ describe('McpServer CRD — OAuth surface (U1)', () => {
]) {
expect(oauth.properties).toHaveProperty(p)
}
+ const bakedReq = specRules.find(
+ r =>
+ r.rule.includes('has(self.oauth.source)') &&
+ r.rule.includes('has(self.oauth.id)') &&
+ r.rule.includes('has(self.oauth.provider)') &&
+ r.rule.includes('has(self.oauth.clientIdRef)') &&
+ r.rule.includes('has(self.oauth.clientSecretRef)')
+ )
+ expect(bakedReq, 'BAKED-REQ rule present').toBeDefined()
+ })
+
+ it('exposes source as an optional enum[remote] carril discriminator (no default, not required)', () => {
+ const oauth = specSchema.properties.oauth
+ const source = oauth.properties.source
+ expect(source.type).toBe('string')
+ expect(source.enum).toEqual(['remote'])
+ expect(source).not.toHaveProperty('default')
+ // Never in a (now-absent) block-level required list.
+ expect(oauth.required).toBeUndefined()
+ })
+
+ it('declares the remote-carril properties (clientMode enum [public, confidential])', () => {
+ const props = specSchema.properties.oauth.properties
+ for (const p of [
+ 'source',
+ 'clientMode',
+ 'authorizationEndpoint',
+ 'tokenEndpoint',
+ 'registrationEndpoint',
+ 'issuer',
+ 'resource',
+ 'issForCallback',
+ 'bearerInBody',
+ 'supportsRefresh',
+ ]) {
+ expect(props).toHaveProperty(p)
+ }
+ expect(props.clientMode.enum).toEqual(['public', 'confidential'])
+ // bearerInBody/supportsRefresh must carry NO default (a default makes has()
+ // always true and voids the REMOTE-REQ presence check).
+ expect(props.bearerInBody).not.toHaveProperty('default')
+ expect(props.supportsRefresh).not.toHaveProperty('default')
+ })
+
+ it('loosens oauth.id to maxLength 512 with no structural pattern, re-narrowed for baked by CEL', () => {
+ const id = specSchema.properties.oauth.properties.id
+ expect(id.maxLength).toBe(512)
+ expect(id).not.toHaveProperty('pattern')
+ const slugRule = specRules.find(
+ r =>
+ r.rule.includes("self.oauth.id.matches('^[a-z0-9-]{1,63}$')") &&
+ r.rule.includes('has(self.oauth.source)')
+ )
+ expect(slugRule, 'baked-slug CEL rule present and gated on source').toBeDefined()
+ })
+
+ it('loosens oauth.scopes caps to maxItems 128 / items.maxLength 512 (large-AS installs)', () => {
+ const scopes = specSchema.properties.oauth.properties.scopes
+ expect(scopes.maxItems).toBe(128)
+ expect(scopes.items.maxLength).toBe(512)
+ })
+
+ it('requires the remote client shape via CEL (REMOTE-REQ)', () => {
+ const rule = specRules.find(
+ r =>
+ r.rule.includes('!has(self.oauth.source)') &&
+ r.rule.includes('has(self.oauth.clientMode)') &&
+ r.rule.includes('has(self.oauth.authorizationEndpoint)') &&
+ r.rule.includes('has(self.oauth.tokenEndpoint)') &&
+ r.rule.includes('has(self.oauth.issuer)') &&
+ r.rule.includes('has(self.oauth.resource)') &&
+ r.rule.includes('has(self.oauth.bearerInBody)') &&
+ r.rule.includes('has(self.oauth.supportsRefresh)')
+ )
+ expect(rule, 'REMOTE-REQ rule present').toBeDefined()
+ })
+
+ it('forbids provider on the remote carril (REMOTE-FORBID-PROVIDER)', () => {
+ const rule = specRules.find(
+ r =>
+ r.rule.includes('!has(self.oauth.source)') &&
+ r.rule.includes('!has(self.oauth.provider)') &&
+ !r.rule.includes('has(self.oauth.clientMode)')
+ )
+ expect(rule, 'REMOTE-FORBID-PROVIDER rule present').toBeDefined()
+ expect(rule?.message).toMatch(/must not set provider/)
+ })
+
+ it('forbids remote-only fields on the baked carril (BAKED-FORBID-REMOTE-FIELDS)', () => {
+ const rule = specRules.find(
+ r =>
+ r.rule.includes('has(self.oauth.source)') &&
+ r.rule.includes('!has(self.oauth.clientMode)') &&
+ r.rule.includes('!has(self.oauth.authorizationEndpoint)') &&
+ r.rule.includes('!has(self.oauth.tokenEndpoint)') &&
+ r.rule.includes('!has(self.oauth.registrationEndpoint)') &&
+ r.rule.includes('!has(self.oauth.issuer)') &&
+ r.rule.includes('!has(self.oauth.resource)') &&
+ r.rule.includes('!has(self.oauth.issForCallback)') &&
+ r.rule.includes('!has(self.oauth.bearerInBody)') &&
+ r.rule.includes('!has(self.oauth.supportsRefresh)')
+ )
+ expect(rule, 'BAKED-FORBID-REMOTE-FIELDS rule present').toBeDefined()
+ })
+
+ it('has()-guards the id and provider value immutability rules against a remote UPDATE (IMM-2/IMM-4)', () => {
+ const idRule = specRules.find(
+ r =>
+ r.rule.includes('oldSelf.oauth.id == self.oauth.id') &&
+ r.rule.includes('!has(oldSelf.oauth.id)') &&
+ r.rule.includes('!has(self.oauth.id)')
+ )
+ expect(idRule, 'id value immutability rule is coordinate-presence guarded').toBeDefined()
+ const providerRule = specRules.find(
+ r =>
+ r.rule.includes('oldSelf.oauth.provider == self.oauth.provider') &&
+ r.rule.includes('!has(oldSelf.oauth.provider)') &&
+ r.rule.includes('!has(self.oauth.provider)')
+ )
+ expect(
+ providerRule,
+ 'provider value immutability rule is coordinate-presence guarded'
+ ).toBeDefined()
+ })
+
+ it('pins id presence (IMM-3), the carril (IMM-5) and remote endpoints (IMM-6) as immutable', () => {
+ const imm3 = specRules.find(r => r.rule.includes('has(oldSelf.oauth.id) == has(self.oauth.id)'))
+ expect(imm3, 'IMM-3 id-presence immutability present').toBeDefined()
+ const imm5 = specRules.find(r =>
+ r.rule.includes('has(oldSelf.oauth.source) == has(self.oauth.source)')
+ )
+ expect(imm5, 'IMM-5 carril immutability present').toBeDefined()
+ const imm6 = specRules.find(
+ r =>
+ r.rule.includes(
+ 'oldSelf.oauth.authorizationEndpoint == self.oauth.authorizationEndpoint'
+ ) && r.rule.includes('oldSelf.oauth.clientMode == self.oauth.clientMode')
+ )
+ expect(imm6, 'IMM-6 remote pinned-endpoint immutability present').toBeDefined()
+ // IMM-6 also pins the discovery-derived quirks (bearerInBody, supportsRefresh)
+ // so an update-RBAC actor cannot flip the fail-closed refresh decision (D-8).
+ expect(imm6?.rule).toContain('oldSelf.oauth.bearerInBody == self.oauth.bearerInBody')
+ expect(imm6?.rule).toContain('oldSelf.oauth.supportsRefresh == self.oauth.supportsRefresh')
})
it('grantScope is enum [user, context], default user, nested under spec.oauth', () => {
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index b2905694f..8e2309e28 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.340",
+ "version": "0.1.341",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.340",
+ "version": "0.1.341",
"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 81dfb1b9c..543c8b462 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.340",
+ "version": "0.1.341",
"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/__tests__/reconciler.remote.test.ts b/host-context-controller/src/__tests__/reconciler.remote.test.ts
index 1e1e74d93..524e1e09c 100644
--- a/host-context-controller/src/__tests__/reconciler.remote.test.ts
+++ b/host-context-controller/src/__tests__/reconciler.remote.test.ts
@@ -411,12 +411,95 @@ describe('McpServerReconciler remote egress proxy', () => {
expect(conf).toContain('${API_KEY}')
})
- it('should omit auth header section when authHeaders is not set', () => {
+ it('omits the credential auth-header section but clears Authorization for a static remote with no authHeaders (D-2)', () => {
const cm = (reconciler as any).buildNginxConfigMap(REMOTE_SERVER)
const conf = cm.data['default.conf.template']
expect(conf).not.toContain('Credential auth headers')
- expect(conf).not.toContain('proxy_set_header Authorization')
+ // A static remote (no oauth, no declared Authorization) clears the header so
+ // it never forwards an incoming Authorization by accident.
+ expect(conf).toContain('proxy_set_header Authorization "";')
+ })
+
+ // ── D-2 Authorization precedence/clearing ──
+ describe('Authorization precedence (D-2)', () => {
+ const oauthRemote = (authHeaders?: Array<{ header: string; valueTemplate: string }>) =>
+ cloneServer(REMOTE_SERVER, {
+ auth: { type: 'oauth' },
+ remote: {
+ baseUrl: 'https://mcp.sentry.io/sse',
+ ...(authHeaders ? { authHeaders } : {}),
+ },
+ })
+
+ it('passes the per-user Bearer through for a remote oauth server (no authHeaders)', () => {
+ const cm = (reconciler as any).buildNginxConfigMap(oauthRemote())
+ const conf = cm.data['default.conf.template']
+
+ expect(conf).toContain('proxy_set_header Authorization $http_authorization;')
+ expect(conf).not.toContain('proxy_set_header Authorization "";')
+ })
+
+ it('clears Authorization for a static remote (no oauth, no authHeaders)', () => {
+ const cm = (reconciler as any).buildNginxConfigMap(REMOTE_SERVER)
+ const conf = cm.data['default.conf.template']
+
+ expect(conf).toContain('proxy_set_header Authorization "";')
+ expect(conf).not.toContain('proxy_set_header Authorization $http_authorization;')
+ })
+
+ it('lets the operator static credential win for a static remote declaring Authorization', () => {
+ const server = cloneServer(REMOTE_SERVER, {
+ remote: {
+ baseUrl: 'https://api.example.com/v1',
+ authHeaders: [{ header: 'Authorization', valueTemplate: 'Bearer ${API_KEY}' }],
+ },
+ })
+ const cm = (reconciler as any).buildNginxConfigMap(server)
+ const conf = cm.data['default.conf.template']
+
+ expect(conf).toContain('proxy_set_header Authorization "Bearer ${API_KEY}";')
+ // Neither the clearing form nor the passthrough form is emitted.
+ expect(conf).not.toContain('proxy_set_header Authorization "";')
+ expect(conf).not.toContain('proxy_set_header Authorization $http_authorization;')
+ })
+
+ it('clears Authorization for a static remote whose Authorization authHeader is dropped by sanitization', () => {
+ // The clear-vs-operator-wins decision keys on the SANITIZED set, not the raw
+ // list: a CR/LF value is dropped by sanitizeAuthHeader, so no static line is
+ // rendered and we must still CLEAR — otherwise the incoming Authorization
+ // would be forwarded to the upstream (the D-2 invariant hole).
+ const server = cloneServer(REMOTE_SERVER, {
+ remote: {
+ baseUrl: 'https://api.example.com/v1',
+ authHeaders: [{ header: 'Authorization', valueTemplate: 'Bearer x\nInjected: y' }],
+ },
+ })
+ const cm = (reconciler as any).buildNginxConfigMap(server)
+ const conf = cm.data['default.conf.template']
+
+ expect(conf).toContain('proxy_set_header Authorization "";')
+ // The malformed value is never rendered.
+ expect(conf).not.toContain('Injected: y')
+ })
+
+ it('throws when a remote oauth server also declares a static Authorization header (conflict)', () => {
+ const server = oauthRemote([
+ { header: 'Authorization', valueTemplate: 'Bearer ${API_KEY}' },
+ ])
+ expect(() => (reconciler as any).buildNginxConfigMap(server)).toThrow(
+ /Authorization header/
+ )
+ })
+
+ it('detects the Authorization conflict case-insensitively', () => {
+ const server = oauthRemote([
+ { header: 'authorization', valueTemplate: 'Bearer ${API_KEY}' },
+ ])
+ expect(() => (reconciler as any).buildNginxConfigMap(server)).toThrow(
+ /Authorization header/
+ )
+ })
})
// ── Codex P0 fix (PR #101) — authHeaders sanitization (nginx + HTTP injection) ──
@@ -520,7 +603,9 @@ describe('McpServerReconciler remote egress proxy', () => {
const conf = cm.data['default.conf.template']
expect(conf).not.toContain('xxxxxxxx')
- expect(conf).not.toContain('proxy_set_header Authorization')
+ // Dropped by sanitization → the static remote clears Authorization (D-2):
+ // the rejected value is never rendered and the incoming header is not forwarded.
+ expect(conf).toContain('proxy_set_header Authorization "";')
expect(warn).toHaveBeenCalledWith(expect.stringContaining('too long'))
warn.mockRestore()
})
@@ -532,7 +617,9 @@ describe('McpServerReconciler remote egress proxy', () => {
)
const conf = cm.data['default.conf.template']
- expect(conf).not.toContain('proxy_set_header Authorization')
+ // Dropped by sanitization → the static remote clears Authorization (D-2).
+ expect(conf).toContain('proxy_set_header Authorization "";')
+ expect(conf).not.toContain('evil')
expect(warn).toHaveBeenCalledWith(expect.stringContaining('CR/LF/NUL'))
warn.mockRestore()
})
diff --git a/host-context-controller/src/k8sClient.test.ts b/host-context-controller/src/k8sClient.test.ts
index 0419fbb3e..4f621bcac 100644
--- a/host-context-controller/src/k8sClient.test.ts
+++ b/host-context-controller/src/k8sClient.test.ts
@@ -627,10 +627,43 @@ describe('MCP authorization store Kubernetes 404 normalization', () => {
description: 'Server A',
transport: { type: 'streamableHttp', url: 'http://server-a/mcp', port: 8080 },
auth: { type: 'bearer', secretRef: 'server-a-auth', secretKey: 'token' },
+ // Non-remote fixture → remote-ness projects as false (mirrors reconciler isRemote).
+ remote: false,
enabled: true,
status: { deployed: true, ready: true, authoritative: true },
})
})
+
+ it('projects remote:true against the real producer when spec.remote.baseUrl is set', async () => {
+ const objects: Record<string, unknown> = {
+ 'mcpservers/server-remote': {
+ metadata: {
+ name: 'server-remote',
+ namespace: 'mcp-server',
+ uid: 'server-uid-remote',
+ resourceVersion: '20',
+ },
+ spec: {
+ description: 'Remote Server',
+ transport: {
+ type: 'streamableHttp',
+ url: 'http://server-remote.mcp-server.svc.cluster.local:8080/mcp',
+ port: 8080,
+ },
+ auth: { type: 'oauth' },
+ remote: { baseUrl: 'https://mcp.example.com/mcp' },
+ enabled: true,
+ },
+ },
+ }
+ mocks.getNamespacedCustomObject.mockImplementation(
+ async ({ plural, name }: { plural: string; name: string }) => objects[`${plural}/${name}`]
+ )
+
+ const store = createMcpAuthorizationStore(provider)
+ const server = await store.readMcpServer('server-remote')
+ expect(server.remote).toBe(true)
+ })
})
describe('McpServerWatcher startup', () => {
diff --git a/host-context-controller/src/k8sClient.ts b/host-context-controller/src/k8sClient.ts
index c96c3d04d..b14fd448e 100644
--- a/host-context-controller/src/k8sClient.ts
+++ b/host-context-controller/src/k8sClient.ts
@@ -5344,6 +5344,8 @@ export function createMcpAuthorizationStore(provider: McpServerProvider): McpAut
auth: object.spec.auth ? { ...object.spec.auth } : undefined,
// grantScope drives the inventory authKind derivation (mini-spec 10 §3.1).
oauth: object.spec.oauth ? { ...object.spec.oauth } : undefined,
+ // Single source of truth for remote-ness, mirrors the reconciler's isRemote.
+ remote: !!object.spec.remote?.baseUrl,
enabled: object.spec.enabled !== false,
status,
}
diff --git a/host-context-controller/src/mcpAuthorization.test.ts b/host-context-controller/src/mcpAuthorization.test.ts
index 98471acba..efb1189bd 100644
--- a/host-context-controller/src/mcpAuthorization.test.ts
+++ b/host-context-controller/src/mcpAuthorization.test.ts
@@ -649,3 +649,49 @@ describe('listServers authKind emission (mini-spec 10 §3.2, T1)', () => {
expect(inventory[0]).not.toHaveProperty('authKind')
})
})
+
+describe('listServers remote projection (C3, orthogonal transport axis)', () => {
+ it('emits remote:true for a remote oauth server while authKind stays oauth-user (no remote rama)', async () => {
+ const store = new FakeStore()
+ store.serverObject = {
+ ...server,
+ auth: { type: 'oauth' },
+ oauth: fullOAuth('user'),
+ remote: true,
+ }
+ const service = new McpAuthorizationService(store)
+ const inventory = await service.listServers(principal)
+ expect(inventory[0].remote).toBe(true)
+ expect(inventory[0].authKind).toBe('oauth-user')
+ // No authority leaks onto the wire item regardless of the transport axis.
+ expect(inventory[0]).not.toHaveProperty('contextRef')
+ expect(inventory[0]).not.toHaveProperty('auth')
+ expect(inventory[0]).not.toHaveProperty('oauth')
+ })
+
+ it('omits remote for a local oauth server (absent → local, fail-safe)', async () => {
+ const store = new FakeStore()
+ store.serverObject = {
+ ...server,
+ auth: { type: 'oauth' },
+ oauth: fullOAuth('context'),
+ }
+ const service = new McpAuthorizationService(store)
+ const inventory = await service.listServers(principal)
+ expect(inventory[0]).not.toHaveProperty('remote')
+ expect(inventory[0].authKind).toBe('oauth-context')
+ })
+
+ it('emits remote:true with authKind static for a static remote server', async () => {
+ const store = new FakeStore()
+ store.serverObject = {
+ ...server,
+ auth: { type: 'bearer', secretRef: 'server-a-auth', secretKey: 'token' },
+ remote: true,
+ }
+ const service = new McpAuthorizationService(store)
+ const inventory = await service.listServers(principal)
+ expect(inventory[0].remote).toBe(true)
+ expect(inventory[0].authKind).toBe('static')
+ })
+})
diff --git a/host-context-controller/src/mcpAuthorization.ts b/host-context-controller/src/mcpAuthorization.ts
index c314a90da..863cc209c 100644
--- a/host-context-controller/src/mcpAuthorization.ts
+++ b/host-context-controller/src/mcpAuthorization.ts
@@ -32,6 +32,8 @@ export interface AuthorityMcpServer {
// OAuth broker config (grantScope) from the CRD. Non-secret; used only to
// derive the inventory `authKind`. HCC never forwards it to mcp-host raw.
oauth?: McpServerOAuth
+ /** True iff spec.remote.baseUrl is set (nginx egress-proxy server). Non-secret topology bit, orthogonal to authKind; C4 lifts the SHARED-without-token precondition on it. */
+ remote?: boolean
enabled: boolean
status: McpServerStatus
}
@@ -70,6 +72,8 @@ export interface AuthorizedMcpServerInfo {
* omitted field. Absent → mcp-host degrades to `static` (fail-closed).
*/
authKind?: AuthorizedMcpAuthKind
+ /** True iff a remote (egress-proxy) server. Absent → local (fail-safe). Orthogonal to authKind; carries no authority. */
+ remote?: boolean
}
export type AuthorizedMcpAuthKind = 'static' | 'oauth-user' | 'oauth-context'
@@ -338,6 +342,7 @@ export class McpAuthorizationService {
authRequired,
...(authRequired ? { credentialRevision: grant.credentialRevision } : {}),
...(authKind ? { authKind } : {}),
+ ...(grant.server.remote ? { remote: true } : {}),
})
}
const revalidated = await this.resolveHostContext(principal)
diff --git a/host-context-controller/src/reconciler.ts b/host-context-controller/src/reconciler.ts
index 5ce469df1..612acbd4a 100644
--- a/host-context-controller/src/reconciler.ts
+++ b/host-context-controller/src/reconciler.ts
@@ -999,12 +999,69 @@ export class McpServerReconciler {
// sanitizeAuthHeader() before emission so an operator-authored CRD cannot
// break out of the quoted string to inject arbitrary nginx config, and
// cannot smuggle HTTP headers via CR/LF.
- const authHeaderLines = (server.spec.remote!.authHeaders ?? [])
+ const sanitizedAuthHeaders = (server.spec.remote!.authHeaders ?? [])
.map(h => this.sanitizeAuthHeader(h))
.filter((h): h is { header: string; valueTemplate: string } => h !== null)
+ const authHeaderLines = sanitizedAuthHeaders
.map(h => ` proxy_set_header ${h.header} "${h.valueTemplate}";`)
.join('\n')
+ // ── D-2 Authorization precedence/clearing ──
+ // Exactly one Authorization directive is emitted, by precedence, because the
+ // security decision here is non-obvious:
+ // oauth (and no static Authorization) → passthrough the per-user Bearer that
+ // mcp-host injects ($http_authorization);
+ // authHeaders declares Authorization → emit nothing here — the operator's
+ // static credential (already rendered by
+ // authHeaderLines) wins;
+ // otherwise (static remote) → clear it ("") so a static remote never
+ // forwards an incoming Authorization by accident.
+ // An oauth server that also statically pins Authorization is a contradiction:
+ // the static value would shadow the per-user Bearer. Reject the reconcile.
+ //
+ // Two different detections on purpose:
+ // - CONFLICT (oauth) is keyed on the RAW authHeaders: an oauth server must not
+ // declare Authorization at all, even a malformed value that sanitization would
+ // drop — otherwise the reject could be bypassed by injecting a bad value.
+ // - The clear-vs-operator-wins decision is keyed on the SANITIZED/EMITTED set:
+ // if the operator's Authorization entry was dropped by sanitizeAuthHeader (bad
+ // name/length/CR-LF-NUL), no static line is rendered, so we must still CLEAR —
+ // keying this on the raw list would leave the incoming Authorization forwarded.
+ const isOAuth = server.spec.auth?.type === 'oauth'
+ const rawDeclaresAuthorizationHeader = (server.spec.remote!.authHeaders ?? []).some(
+ h => h.header.toLowerCase() === 'authorization'
+ )
+ const emitsAuthorizationHeader = sanitizedAuthHeaders.some(
+ h => h.header.toLowerCase() === 'authorization'
+ )
+ if (isOAuth && rawDeclaresAuthorizationHeader) {
+ hccLogger.error(
+ 'Rejecting remote reconcile: oauth server pins a static Authorization header',
+ {
+ scope: '[Reconciler]',
+ mcpServer: server.name,
+ namespace: server.namespace,
+ }
+ )
+ throw new Error(
+ `remote MCP server "${server.name}" uses auth.type 'oauth' but also declares a static ` +
+ 'Authorization header in spec.remote.authHeaders; the per-user Bearer must pass through — ' +
+ 'remove the Authorization entry'
+ )
+ }
+ const authorizationDirective = isOAuth
+ ? ' proxy_set_header Authorization $http_authorization;'
+ : emitsAuthorizationHeader
+ ? ''
+ : ' proxy_set_header Authorization "";'
+ const authorizationBlock = authorizationDirective
+ ? `\n # ── Authorization precedence (D-2): ${
+ isOAuth
+ ? 'passthrough the per-user Bearer'
+ : 'clear — a static remote never forwards Authorization'
+ } ──\n${authorizationDirective}\n`
+ : ''
+
const nginxConf = `# Auto-generated by Clerum HCC for remote MCP server: ${server.name}
# Stored as .conf.template; Clerum's nginx egress proxy runs envsubst at startup.
server {
@@ -1018,7 +1075,7 @@ server {
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;
-${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolved) ──\n' + authHeaderLines + '\n' : ''}
+${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolved) ──\n' + authHeaderLines + '\n' : ''}${authorizationBlock}
# SSE/streaming support
proxy_buffering off;
proxy_cache off;