Skip to content

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

TypeScript

feat(control-api): member-registration mode switch (remote|hosted) with scoped fail-fast

Jose Ramirez7995c8180678
diff --git a/control-api/src/config.ts b/control-api/src/config.ts
index 9f1841592..b75019ac9 100644
--- a/control-api/src/config.ts
+++ b/control-api/src/config.ts
@@ -18,6 +18,8 @@ type Config = {
internalControlJwtWrcHmacSecret: string
internalControlJwtHccHmacSecret: string
allowedIssuanceNamespaces: string[]
+ memberRegistrationMode: 'remote' | 'hosted'
+ memberRegistrationExternalHubBaseUrl: string
memberRegistrationServiceBaseUrl: string
memberRegistrationServiceHmacSecret: string
memberRegistrationServiceHmacKid: string
@@ -396,6 +398,43 @@ const RPC_JWT_PUBLIC_KEY = normalizePem(
process.env.CONTROL_API_RPC_JWT_PUBLIC_KEY || publicKeyFromPrivateKey(RPC_JWT_PRIVATE_KEY)
)
+const memberRegistrationMode: 'remote' | 'hosted' = (() => {
+ const raw = (process.env.CONTROL_API_MEMBER_REGISTRATION_MODE || 'remote').trim()
+ if (raw !== 'remote' && raw !== 'hosted') {
+ throw new Error(
+ `CONTROL_API_MEMBER_REGISTRATION_MODE must be 'remote' or 'hosted' (got '${raw}')`
+ )
+ }
+ return raw
+})()
+
+// "Present" = non-empty after trim: blanking a value in the deploy Secret must
+// count as absent (spec §8.1 — apply-inter-service-tokens.sh re-adds the key).
+function memberRegistrationEnvPresent(name: string): boolean {
+ const value = process.env[name]
+ return typeof value === 'string' && value.trim() !== ''
+}
+
+if (memberRegistrationMode === 'hosted') {
+ // Fail fast on ambiguity — scoped to the DELIBERATELY-set identity vars only.
+ // HMAC_SECRET is excluded: the shipped deploy unconditionally injects it via
+ // the control-api-internal-tokens Secret (spec §8.1), so it is ignorable legacy.
+ const injectedIdentity = [
+ 'CONTROL_API_MEMBER_REGISTRATION_HMAC_KID',
+ 'CONTROL_API_MEMBER_REGISTRATION_TENANT_ID',
+ ].filter(memberRegistrationEnvPresent)
+ if (injectedIdentity.length > 0) {
+ throw new Error(
+ `[SECURITY] CONTROL_API_MEMBER_REGISTRATION_MODE=hosted is mutually exclusive with an injected remote member-registration identity. Unset: ${injectedIdentity.join(', ')}`
+ )
+ }
+ if (memberRegistrationEnvPresent('CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET')) {
+ console.warn(
+ '[ControlAPI] CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET is set but IGNORED in hosted member-registration mode (deploy-injected legacy value; credentials are self-enrolled and stored in Postgres)'
+ )
+ }
+}
+
export const config: Config = {
port: Number(process.env.CONTROL_API_PORT || 8090),
jsonBodyLimit: process.env.CONTROL_API_JSON_BODY_LIMIT || '150mb',
@@ -429,11 +468,22 @@ export const config: Config = {
allowedIssuanceNamespaces: parseCsvList(
process.env.CONTROL_API_ALLOWED_ISSUANCE_NAMESPACES || `${HOSTS_NAMESPACE},${SANDBOX_NAMESPACE}`
),
- memberRegistrationServiceBaseUrl: requiredOrDevDefault(
- 'CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL',
- 'http://member-registration-service.profiles.svc.cluster.local:8092/api/v1'
- ),
+ memberRegistrationMode,
+ memberRegistrationExternalHubBaseUrl:
+ process.env.CONTROL_API_MEMBER_REGISTRATION_EXTERNAL_HUB_BASE_URL ||
+ 'https://registration.evenfire.ai/api/v1',
+ memberRegistrationServiceBaseUrl:
+ memberRegistrationMode === 'hosted'
+ ? process.env.CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL || ''
+ : requiredOrDevDefault(
+ 'CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL',
+ 'http://member-registration-service.profiles.svc.cluster.local:8092/api/v1'
+ ),
memberRegistrationServiceHmacSecret: (() => {
+ if (memberRegistrationMode === 'hosted') {
+ // Hosted mode never signs with the env secret; see the module-scope warning.
+ return ''
+ }
const value = requiredOrDevDefault(
'CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET',
'dev-member-registration-hmac-secret'
diff --git a/control-api/test/config.memberRegistrationMode.test.ts b/control-api/test/config.memberRegistrationMode.test.ts
new file mode 100644
index 000000000..0bbd90efc
--- /dev/null
+++ b/control-api/test/config.memberRegistrationMode.test.ts
@@ -0,0 +1,179 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { generateKeyPairSync, randomBytes } from 'node:crypto'
+
+function generateNonDevPem(): string {
+ // 3072-bit RSA — 2048 collides with the dev-key fingerprint check in src/config.ts.
+ return generateKeyPairSync('rsa', {
+ modulusLength: 3072,
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
+ }).privateKey
+}
+
+/** Mirror of test/config.prod.test.ts applyProdEnv — every env the prod path requires. */
+function applyProdEnv(env: Record<string, string | undefined>): void {
+ env.NODE_ENV = 'production'
+ env.CONTROL_API_RPC_JWT_PRIVATE_KEY = generateNonDevPem()
+ env.CONTROL_API_SESSION_JWT_PRIVATE_KEY = generateNonDevPem()
+ env.CONTROL_API_ADMIN_JWT_PRIVATE_KEY = generateNonDevPem()
+ env.INTERNAL_CONTROL_JWT_WRC_HMAC_SECRET = randomBytes(32).toString('hex')
+ env.INTERNAL_CONTROL_JWT_HCC_HMAC_SECRET = randomBytes(32).toString('hex')
+ env.CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL = 'https://example.com/api/v1'
+ env.CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET = randomBytes(32).toString('hex')
+ env.CONTROL_API_MEMBER_REGISTRATION_HMAC_KID = 'clerum'
+ env.CONTROL_API_MEMBER_REGISTRATION_TENANT_ID = 'clerum'
+ env.CONTROL_API_JWT_ISSUER = 'control-api'
+ env.CONTROL_API_JWT_AUDIENCE = 'profile-ui'
+ env.CONTROL_API_RPC_JWT_ISSUER = 'control-api'
+ env.CONTROL_API_RPC_JWT_AUDIENCE = 'rpc-proxy'
+ env.CONTROL_API_GOOGLE_CLIENT_ID = 'prod-google-client-id'
+ env.CONTROL_API_ADMIN_JWT_ISSUER = 'control-api'
+ env.CONTROL_API_ADMIN_JWT_AUDIENCE = 'control-ui'
+ env.CONTROL_API_ADMIN_BOOTSTRAP_USERNAME = 'admin'
+ env.CONTROL_API_ADMIN_BOOTSTRAP_PASSWORD_HASH =
+ '$2b$12$4dm17x2DESCxETGi0MpNruC0KpCev5lbKwqgmUkVLxKsNUxoXXXXXX'
+ env.CONTROL_API_OAUTH_STATE_HMAC_SECRET = randomBytes(32).toString('hex')
+ env.CONTROL_API_OAUTH_ENCRYPTION_KEY = randomBytes(32).toString('hex')
+ env.CONTROL_API_INTERNAL_SERVICE_TOKENS =
+ 'external-rest-api=prod-external-rest-api-token,rpc-proxy=prod-rpc-proxy-token,webhook-proxy=prod-webhook-proxy-token'
+}
+
+const MEMBER_REG_VARS = [
+ 'CONTROL_API_MEMBER_REGISTRATION_MODE',
+ 'CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL',
+ 'CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET',
+ 'CONTROL_API_MEMBER_REGISTRATION_HMAC_KID',
+ 'CONTROL_API_MEMBER_REGISTRATION_TENANT_ID',
+ 'CONTROL_API_MEMBER_REGISTRATION_EXTERNAL_HUB_BASE_URL',
+] as const
+
+describe('config: member-registration mode', () => {
+ const origEnv = { ...process.env }
+
+ beforeEach(() => {
+ vi.resetModules()
+ process.env = { ...origEnv }
+ for (const name of MEMBER_REG_VARS) delete process.env[name]
+ delete process.env.NODE_ENV
+ })
+
+ afterEach(() => {
+ process.env = { ...origEnv }
+ vi.restoreAllMocks()
+ vi.resetModules()
+ })
+
+ it('defaults to remote', async () => {
+ const { config } = await import('../src/config.js')
+ expect(config.memberRegistrationMode).toBe('remote')
+ })
+
+ it('parses hosted and defaults the external hub base URL', async () => {
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'hosted'
+ const { config } = await import('../src/config.js')
+ expect(config.memberRegistrationMode).toBe('hosted')
+ expect(config.memberRegistrationExternalHubBaseUrl).toBe(
+ 'https://registration.evenfire.ai/api/v1'
+ )
+ })
+
+ it('honors an explicit external hub override (staging hub)', async () => {
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'hosted'
+ process.env.CONTROL_API_MEMBER_REGISTRATION_EXTERNAL_HUB_BASE_URL =
+ 'https://registration.staging.example.com/api/v1'
+ const { config } = await import('../src/config.js')
+ expect(config.memberRegistrationExternalHubBaseUrl).toBe(
+ 'https://registration.staging.example.com/api/v1'
+ )
+ })
+
+ it('hard-errors on unknown mode values (e.g. the abandoned "offline")', async () => {
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'offline'
+ await expect(() => import('../src/config.js')).rejects.toThrow(
+ /CONTROL_API_MEMBER_REGISTRATION_MODE/
+ )
+ })
+
+ it('fail-fasts hosted + injected HMAC_KID', async () => {
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'hosted'
+ process.env.CONTROL_API_MEMBER_REGISTRATION_HMAC_KID = 'clerum-dev-e6f79032'
+ await expect(() => import('../src/config.js')).rejects.toThrow(
+ /CONTROL_API_MEMBER_REGISTRATION_HMAC_KID/
+ )
+ })
+
+ it('fail-fasts hosted + injected TENANT_ID', async () => {
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'hosted'
+ process.env.CONTROL_API_MEMBER_REGISTRATION_TENANT_ID = 'clerum-dev'
+ await expect(() => import('../src/config.js')).rejects.toThrow(
+ /CONTROL_API_MEMBER_REGISTRATION_TENANT_ID/
+ )
+ })
+
+ it('treats empty/whitespace identity vars as absent (deploy blanking escape hatch)', async () => {
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'hosted'
+ process.env.CONTROL_API_MEMBER_REGISTRATION_HMAC_KID = ' '
+ process.env.CONTROL_API_MEMBER_REGISTRATION_TENANT_ID = ''
+ await expect(import('../src/config.js')).resolves.toBeDefined()
+ })
+
+ it('ignores a lone deploy-injected HMAC_SECRET in hosted mode, with a warning', async () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'hosted'
+ process.env.CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET = 'legacy-injected-secret'
+ await expect(import('../src/config.js')).resolves.toBeDefined()
+ expect(warn).toHaveBeenCalledWith(
+ expect.stringContaining('CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET')
+ )
+ })
+
+ it('hosted relaxes the prod requirement for base URL + secret (non-vacuous direction)', async () => {
+ applyProdEnv(process.env)
+ // A real self-hosted operator flipping hosted: the four legacy vars are gone
+ // except the deploy-injected secret; base URL removed to prove the relaxation.
+ delete process.env.CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL
+ delete process.env.CONTROL_API_MEMBER_REGISTRATION_HMAC_KID
+ delete process.env.CONTROL_API_MEMBER_REGISTRATION_TENANT_ID
+ delete process.env.CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'hosted'
+ const { config } = await import('../src/config.js')
+ expect(config.memberRegistrationMode).toBe('hosted')
+ })
+
+ // All four mode × var combinations (spec §8.8): a relaxation gated on env-var
+ // PRESENCE rather than the parsed mode passes a 2-combo suite while booting a
+ // prod remote deploy with no secret.
+ it('NEGATIVE: prod remote (mode unset) still REQUIRES the HMAC secret', async () => {
+ applyProdEnv(process.env)
+ delete process.env.CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET
+ await expect(() => import('../src/config.js')).rejects.toThrow(
+ /CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET/
+ )
+ })
+
+ it('NEGATIVE: prod remote (explicit) still REQUIRES the HMAC secret', async () => {
+ applyProdEnv(process.env)
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'remote'
+ delete process.env.CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET
+ await expect(() => import('../src/config.js')).rejects.toThrow(
+ /CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET/
+ )
+ })
+
+ it('NEGATIVE: prod remote (mode unset) still REQUIRES the service base URL', async () => {
+ applyProdEnv(process.env)
+ delete process.env.CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL
+ await expect(() => import('../src/config.js')).rejects.toThrow(
+ /CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL/
+ )
+ })
+
+ it('NEGATIVE: prod remote (explicit) still REQUIRES the service base URL', async () => {
+ applyProdEnv(process.env)
+ process.env.CONTROL_API_MEMBER_REGISTRATION_MODE = 'remote'
+ delete process.env.CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL
+ await expect(() => import('../src/config.js')).rejects.toThrow(
+ /CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL/
+ )
+ })
+})