Skip to content

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

TypeScript

fix(control-api): enforce the registry URL allowlist for self-hosted regardless of auth

Jose Ramireze3aa0716562b
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 66f083368..f84aba000 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.381",
+ "version": "0.1.382",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.381",
+ "version": "0.1.382",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-api/package.json b/control-api/package.json
index 8333eddc2..3b3990254 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.381",
+ "version": "0.1.382",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/config.ts b/control-api/src/config.ts
index 2dca4a6f6..a159e179d 100644
--- a/control-api/src/config.ts
+++ b/control-api/src/config.ts
@@ -807,25 +807,39 @@ for (const key of NAMESPACE_KEYS) {
}
// Registry consumer auth guard: when auth is on, refuse to boot without OAuth2
-// credentials and refuse a registry URL outside the allowlist (defense against
+// credentials; separately, refuse a registry URL outside the allowlist for any
+// deployment that will really talk to a registry (defense against
// cross-environment misconfiguration sending writes to the wrong registry).
-if (config.registryAuthEnabled) {
- // Mode must be set EXPLICITLY when the registry is enabled — never inferred
- // from which credentials happen to be present (S10: no silent split-brain).
- if (!process.env.REGISTRY_CONNECTION_MODE) {
- throw new Error(
- 'REGISTRY_CONNECTION_MODE is required (managed|self-hosted) when CLERUM_REGISTRY_AUTH_ENABLED=true'
- )
- }
- console.log(`[ControlAPI] Registry connection mode: ${config.registryConnectionMode}`)
- // URL allowlist applies in BOTH modes. The shared registry
- // `registry.evenfire.ai` is the default a self-hoster connects to (see
- // docs/how-to/connect-to-registry.md); the in-cluster URL covers a
- // self-hosted registry-api. A deployment that runs its own registry adds its
- // URL via CLERUM_REGISTRY_URL_ALLOWLIST (comma-separated) rather than editing
- // this list. `example.com` is the reserved-domain fixture used across the
- // test suite — inert (no real registry) and kept so tests need no churn.
+// A configured URL is MANDATORY whenever auth is on. Today this is enforced
+// implicitly — allowed.includes('') is never true, so an empty URL falls
+// through to the allowlist throw. The allowlist block below is preconditioned
+// on registryUrl !== '', which would SKIP that throw and let a managed
+// deployment with auth on and no URL boot, then fail later with a bare fetch
+// URL-parse TypeError. Kept as its own check so the OR cannot swallow it.
+if (config.registryAuthEnabled && config.registryUrl === '') {
+ throw new Error('CLERUM_REGISTRY_URL is required when CLERUM_REGISTRY_AUTH_ENABLED=true')
+}
+
+// URL allowlist — defense against cross-environment misconfiguration sending
+// writes to the wrong registry. Enforced whenever the deployment will really
+// talk to a registry: an EXPLICITLY self-hosted deployment (which POSTs its
+// registration before any credentials exist, so gating this on auth was always
+// backwards), or any auth-enabled deployment. The shared registry
+// `registry.evenfire.ai` is the default a self-hoster connects to (see
+// docs/how-to/connect-to-registry.md); the in-cluster URL covers a
+// self-hosted registry-api. A deployment that runs its own registry adds its
+// URL via CLERUM_REGISTRY_URL_ALLOWLIST (comma-separated) rather than editing
+// this list. `example.com` is the reserved-domain fixture used across the
+// test suite — inert (no real registry) and kept so tests need no churn.
+//
+// Reads process.env directly, NOT config.registryConnectionMode: the mode
+// PARSER defaults to 'managed' when unset, so gating on the parsed value would
+// newly break managed deployments that rely on that default.
+if (
+ config.registryUrl !== '' &&
+ (process.env.REGISTRY_CONNECTION_MODE === 'self-hosted' || config.registryAuthEnabled)
+) {
const allowed = [
'https://registry.evenfire.ai',
'http://registry-api.registry.svc.cluster.local:8085',
@@ -845,6 +859,19 @@ if (config.registryAuthEnabled) {
`CLERUM_REGISTRY_URL=${config.registryUrl} is not in the registry URL allowlist: ${allowed.join(', ')}`
)
}
+}
+
+// Mode requirement (S10: never infer mode from which credentials exist) and the
+// managed credential/voucher checks stay gated on auth, UNCHANGED.
+if (config.registryAuthEnabled) {
+ // Mode must be set EXPLICITLY when the registry is enabled — never inferred
+ // from which credentials happen to be present (S10: no silent split-brain).
+ if (!process.env.REGISTRY_CONNECTION_MODE) {
+ throw new Error(
+ 'REGISTRY_CONNECTION_MODE is required (managed|self-hosted) when CLERUM_REGISTRY_AUTH_ENABLED=true'
+ )
+ }
+ console.log(`[ControlAPI] Registry connection mode: ${config.registryConnectionMode}`)
if (config.registryConnectionMode === 'managed') {
// Managed machine creds live in env (unchanged).
diff --git a/control-api/test/config.registryConnectionMode.test.ts b/control-api/test/config.registryConnectionMode.test.ts
index 41eb11b5d..92bb0847e 100644
--- a/control-api/test/config.registryConnectionMode.test.ts
+++ b/control-api/test/config.registryConnectionMode.test.ts
@@ -100,3 +100,52 @@ describe('config: registry URL allowlist', () => {
expect(config.registryUrl).toBe('https://registry.MyCorp.example')
})
})
+
+describe('boot validation — URL allowlist re-gating', () => {
+ // The hole this task closes: today the allowlist only runs when auth is on,
+ // and auth ships false, so a self-hosted deployment registers and claims
+ // credentials against a totally unvalidated URL.
+ it('self-hosted + unlisted URL throws even with NO auth env var', { retry: 0 }, async () => {
+ vi.resetModules()
+ delete process.env.CLERUM_REGISTRY_AUTH_ENABLED
+ process.env.REGISTRY_CONNECTION_MODE = 'self-hosted'
+ process.env.CLERUM_REGISTRY_URL = 'https://evil.example.net'
+ await expect(import('../src/config.js')).rejects.toThrow(/allowlist/)
+ })
+
+ it('self-hosted + allowlisted URL boots with no auth env var', { retry: 0 }, async () => {
+ vi.resetModules()
+ delete process.env.CLERUM_REGISTRY_AUTH_ENABLED
+ process.env.REGISTRY_CONNECTION_MODE = 'self-hosted'
+ process.env.CLERUM_REGISTRY_URL = 'https://registry.evenfire.ai'
+ await expect(import('../src/config.js')).resolves.toBeDefined()
+ })
+
+ // Regression guard for the managed hard constraint: mode UNSET (defaults to
+ // managed) + a URL + auth off must still boot. This mirrors
+ // startupGuards.registryConsumer.test.ts:85-91, restated here because two
+ // spec revisions broke exactly this case.
+ it('managed-by-default + URL + auth off still boots', { retry: 0 }, async () => {
+ vi.resetModules()
+ delete process.env.REGISTRY_CONNECTION_MODE
+ process.env.CLERUM_REGISTRY_AUTH_ENABLED = 'false'
+ process.env.CLERUM_REGISTRY_URL = 'https://registry.evenfire.ai'
+ await expect(import('../src/config.js')).resolves.toBeDefined()
+ })
+
+ // The new explicit check. Today an empty URL with auth on throws via the
+ // allowlist (allowed.includes('') is never true). The new allowlist block is
+ // preconditioned on registryUrl !== '', which would skip it — so this needs
+ // its own guard, and nothing covered it before.
+ it('auth on with an EMPTY url throws', { retry: 0 }, async () => {
+ vi.resetModules()
+ process.env.CLERUM_REGISTRY_AUTH_ENABLED = 'true'
+ process.env.REGISTRY_CONNECTION_MODE = 'managed'
+ process.env.CLERUM_REGISTRY_CLIENT_ID = 'id'
+ process.env.CLERUM_REGISTRY_CLIENT_SECRET = 's'
+ process.env.CONTROL_API_REGISTRY_VOUCHER_PRIVATE_KEY = voucherPem()
+ process.env.CONTROL_API_REGISTRY_VOUCHER_KID = 'key-uuid'
+ delete process.env.CLERUM_REGISTRY_URL
+ await expect(import('../src/config.js')).rejects.toThrow(/CLERUM_REGISTRY_URL is required/)
+ })
+})