Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): require real credential material in a dockerconfig entry
Jose Ramirez84ab30aed0d6
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 01e116cbc..672ea8a81 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.412",+ "version": "0.1.413","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.412",+ "version": "0.1.413","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 49ce6b05a..4c59c3a27 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.412",+ "version": "0.1.413","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/registryPullSecretService.ts b/control-api/src/services/registryPullSecretService.tsindex 8a9b35e35..aaa827e6e 100644--- a/control-api/src/services/registryPullSecretService.ts+++ b/control-api/src/services/registryPullSecretService.ts@@ -166,12 +166,45 @@ function dockerconfigMatchesHost(blob: string | undefined, host: string): booleaconst parsed = JSON.parse(Buffer.from(blob, 'base64').toString('utf8')) as {auths?: Record<string, unknown>}- return !!parsed?.auths && Object.prototype.hasOwnProperty.call(parsed.auths, host)+ if (!parsed?.auths || !Object.prototype.hasOwnProperty.call(parsed.auths, host)) return false+ return dockerconfigEntryCarriesCredential(parsed.auths[host])} catch {return false}}+/**+ * Does an `auths[<host>]` entry carry something the kubelet can actually present?+ *+ * Host presence alone is not enough. `{"auths":{"registry.example":{}}}` parses cleanly,+ * matches the host, and is entirely unusable — the kubelet finds no credential to send and+ * the pull goes out anonymous. Accepting it is wrong in BOTH directions:+ *+ * - for a Secret we own, it classifies an empty copy as healthy instead of repairing it;+ * - for a FOREIGN copy it is worse, because the all-or-nothing gate reads "usable foreign"+ * as "somebody's live credential is sealed in here" and refuses to mint at all. Nothing+ * was ever served through an empty entry, so that is a self-inflicted outage: every+ * private install fails closed on account of a Secret that could never pull.+ *+ * Accepted forms, all of which the kubelet understands: `auth` (base64 `user:password`, what+ * Docker writes), the split `username`/`password` form some tools emit, and the+ * `identitytoken` / `registrytoken` fields credential helpers use. Any ONE non-empty string+ * suffices — this is a usability check, not a validity check. Whether the credential still+ * WORKS is the registry's answer to give, costs a round trip per install, and belongs to+ * the out-of-band-revocation problem, which is tracked separately.+ */+function dockerconfigEntryCarriesCredential(entry: unknown): boolean {+ if (!entry || typeof entry !== 'object') return false+ const e = entry as Record<string, unknown>+ const nonEmpty = (v: unknown): boolean => typeof v === 'string' && v.trim() !== ''+ return (+ nonEmpty(e.auth) ||+ nonEmpty(e.password) ||+ nonEmpty(e.identitytoken) ||+ nonEmpty(e.registrytoken)+ )+}+/*** Which OBJECT a read saw, as opposed to what was in it.*@@ -464,7 +497,9 @@ function foreignUsabilityProblem(current: SecretView, host: string): string | nureturn `its type is "${current.type ?? 'unset'}", not ${DOCKERCONFIG_TYPE} — the kubelet ignores it for image pulls`}if (!dockerconfigMatchesHost(current.dockerconfig, host)) {- return `its ${DOCKERCONFIG_KEY} carries no entry for "${host}", so the kubelet will never select it`+ // Two different repairs, so name which one it is: a missing entry is usually the wrong+ // registry host, an empty one is usually a half-written or template-generated Secret.+ return `its ${DOCKERCONFIG_KEY} carries no usable credential for "${host}" (the entry is absent, or present but carries no auth/password/token), so the kubelet will never select it`}return null}diff --git a/control-api/test/registryPullSecretService.test.ts b/control-api/test/registryPullSecretService.test.tsindex 1f234af8b..90ea0a2ed 100644--- a/control-api/test/registryPullSecretService.test.ts+++ b/control-api/test/registryPullSecretService.test.ts@@ -532,6 +532,67 @@ describe('ensureRegistryPullSecret — never touches a Secret we do not own', ()expect(mintOrgPullCredential).not.toHaveBeenCalled()})+ // The sharp edge of that boundary: `auths[host]` PRESENT but carrying nothing. It parses,+ // it names our host, and it is completely unusable — the kubelet finds no credential to+ // send and pulls anonymously. Reading host-presence alone as "usable" put this on the+ // BLOCKING side, so an empty or template-generated Secret in any platform namespace+ // fail-closed every private install in the org, permanently, over a copy that could never+ // have served a pull. It is unusable, so it must not block.+ it('does not block the mint for a foreign entry that names our host but carries no credential', async () => {+ const { gateway, mock } = gw()+ const emptyEntry = Buffer.from(JSON.stringify({ auths: { [HOST]: {} } })).toString('base64')+ mock.seedSecret(EVENFIRE_REGISTRY_PULL_SECRET_NAME, UI, {+ type: 'kubernetes.io/dockerconfigjson',+ data: { [DOCKERCONFIG_KEY]: emptyEntry },+ })++ await expect(ensureRegistryPullSecret(gateway, NS)).resolves.toBe('created')+ expect(mintOrgPullCredential).toHaveBeenCalledTimes(1)+ // Unusable does not mean ours: invariant 1 still forbids touching it.+ const squatter = await readStored(mock, UI)+ expect(squatter.blob).toBe(emptyEntry)+ expect(squatter.labels['clerum.io/managed-by']).toBeUndefined()+ })++ // A caller that actually needs that namespace must still fail — unusable is not "fine",+ // it is "fatal to whoever references it". Otherwise we would persist a CRD pointing at a+ // Secret the kubelet cannot use, which is the silent ImagePullBackOff this exists to stop.+ it('still fails a caller that requires the namespace holding the empty foreign entry', async () => {+ const { gateway, mock } = gw()+ mock.seedSecret(EVENFIRE_REGISTRY_PULL_SECRET_NAME, UI, {+ type: 'kubernetes.io/dockerconfigjson',+ data: {+ [DOCKERCONFIG_KEY]: Buffer.from(JSON.stringify({ auths: { [HOST]: {} } })).toString(+ 'base64'+ ),+ },+ })++ await expect(ensureRegistryPullSecrets(gateway, ALL)).rejects.toMatchObject({+ reason: 'foreign_secret_unusable',+ status: 409,+ })+ })++ // Same tightening, our side of the fence: an empty entry in a Secret WE own is broken, not+ // healthy. Left as "valid" it would survive every pass while pulling anonymously.+ it('repairs a Secret we own whose entry names our host but carries no credential', async () => {+ const { gateway, mock } = gw()+ mock.seedSecret(EVENFIRE_REGISTRY_PULL_SECRET_NAME, NS, {+ type: 'kubernetes.io/dockerconfigjson',+ labels: OURS,+ annotations: { [FINGERPRINT_ANNOTATION]: fingerprintOf('efrk_live') },+ data: {+ [DOCKERCONFIG_KEY]: Buffer.from(JSON.stringify({ auths: { [HOST]: {} } })).toString(+ 'base64'+ ),+ },+ })++ await expect(ensureRegistryPullSecret(gateway, NS)).resolves.toBe('repaired')+ expect(decodeHosts((await readStored(mock, NS)).blob)).toEqual([HOST])+ })+// The remedy is not obvious from a bare 409 — the namespace that fails is not the one// holding the external Secret — so the message has to name both and say what to do.it('names the external namespace, the unfillable one, and both remedies', async () => {