Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): reject Secret keys with a ".." prefix (complete IsConfigMapKey parity)
Alfredo Lopezb1b7451d973e
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex b131756a6..b75bd6f77 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.396",+ "version": "0.1.397","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.396",+ "version": "0.1.397","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.jsonindex 99b8d631e..2ca346d93 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.396",+ "version": "0.1.397","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/services/secretKeys.ts b/control-api/src/services/secretKeys.tsindex 029f594ed..7f14f8d38 100644--- a/control-api/src/services/secretKeys.ts+++ b/control-api/src/services/secretKeys.ts@@ -1,10 +1,12 @@// Kubernetes Secret data-key validation, centralized so every write path shares// ONE definition of "valid key". A Secret data key must satisfy the apiserver's-// IsConfigMapKey check: it matches [-._a-zA-Z0-9]+, is neither "." nor "..", and-// is at most 253 characters. A key that fails any of these is rejected by the-// apiserver with an opaque 500; validating here turns that into an actionable-// 400 at the single chokepoint (SecretService) every Secret write passes-// through, so no route — present or future — can leak an invalid key to k8s.+// IsConfigMapKey check: it matches [-._a-zA-Z0-9]+, is not "." and does NOT start+// with ".." (k8s rejects ".", "..", and any "..*" prefix such as "..data" — the+// reserved symlink convention of mounted Secret/ConfigMap volumes), and is at+// most 253 characters. A key that fails any of these is rejected by the apiserver+// with an opaque 500; validating here turns that into an actionable 400 at the+// single chokepoint (SecretService) every Secret write passes through, so no+// route — present or future — can leak an invalid key to k8s.export const SECRET_DATA_KEY_RE = /^[-._a-zA-Z0-9]+$/export const SECRET_DATA_KEY_MAX_LENGTH = 253@@ -12,7 +14,7 @@ export const SECRET_DATA_KEY_MAX_LENGTH = 253// The one message used by both the route-level reason string and the thrown// error, so an operator sees identical wording no matter which layer rejects.function secretKeyErrorMessage(key: string): string {- return `data key "${key}" is not a valid Secret key (only [-._a-zA-Z0-9], not "." or "..", max ${SECRET_DATA_KEY_MAX_LENGTH} chars)`+ return `data key "${key}" is not a valid Secret key (only [-._a-zA-Z0-9], not "." and not starting with "..", max ${SECRET_DATA_KEY_MAX_LENGTH} chars)`}// Thrown when a Secret data key cannot be a valid Kubernetes key. Carries@@ -37,7 +39,7 @@ export function invalidSecretDataKeyReason(key: string): string | null {if (!SECRET_DATA_KEY_RE.test(key) ||key === '.' ||- key === '..' ||+ key.startsWith('..') ||key.length > SECRET_DATA_KEY_MAX_LENGTH) {return secretKeyErrorMessage(key)diff --git a/control-api/test/services.secretService.test.ts b/control-api/test/services.secretService.test.tsindex df4d13726..117181a14 100644--- a/control-api/test/services.secretService.test.ts+++ b/control-api/test/services.secretService.test.ts@@ -19,6 +19,9 @@ const INVALID_KEYS: readonly string[] = ['café', // non-ASCII outside charset'', // empty'x'.repeat(SECRET_DATA_KEY_MAX_LENGTH + 1), // 254 chars, over the limit+ '..foo', // "..*" prefix — apiserver rejects (reserved mounted-volume symlink)+ '..data', // "..*" prefix+ '...x', // "..*" prefix (three dots still starts with "..")]// Keys that are legitimate Secret data keys and MUST keep flowing through to the@@ -29,6 +32,8 @@ const VALID_KEYS: readonly string[] = ['tls.crt','api-key','foo.bar',+ '.foo', // a single leading dot is valid — only the "..*" PREFIX is reserved+ 'foo..', // trailing dots are valid — only the prefix matters, not the suffix'a'.repeat(SECRET_DATA_KEY_MAX_LENGTH), // exactly 253 chars]