Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): validate LLM secret names as Kubernetes DNS subdomains
Ma623a088cfa9
diff --git a/control-ui/app/secrets/new/page.tsx b/control-ui/app/secrets/new/page.tsxindex bf851b8e5..05403685a 100644--- a/control-ui/app/secrets/new/page.tsx+++ b/control-ui/app/secrets/new/page.tsx@@ -24,6 +24,7 @@ import {getRecipes,getRegistryCredentialSchema,} from '@lib/api'+import { isValidDNSSubdomain } from '@lib/k8sValidation'import { createEmptyLlmKeyDraft, validateLlmSecretData } from '@lib/llm'import {areRequiredCredentialRowsComplete,@@ -34,6 +35,10 @@ import type { CredentialDraftRow } from '@lib/registryCredentialDraft.types'const HOST_SECRET_LABEL_KEY = 'clerum.io/host-secret'const HOST_SECRET_LABEL_VALUE = 'true'const MCP_SECRET_NAME_PATTERN = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/+const LLM_SECRET_NAME_FIELD_ID = 'llm-secret-name'+const LLM_SECRET_NAME_ERROR_ID = `${LLM_SECRET_NAME_FIELD_ID}-error`+const LLM_SECRET_NAME_ERROR =+ 'Secret name must be a Kubernetes DNS subdomain: dot-separated labels of lowercase letters, numbers, and hyphens — max 63 characters per label, 253 in total.'type SecretScope = 'llm' | 'mcp' | 'recipe'@@ -220,14 +225,22 @@ function CreateSecretPageContent() {: recipeRows.filter(row => row.secretKey.trim().length > 0 && row.value.trim().length > 0)const currentCanSubmit =scope === 'llm' ? llmCanSubmit : scope === 'mcp' ? mcpCanSubmit : recipeCanSubmit- const activeNameInvalid =- activeSecretName.length > 0 &&- (!MCP_SECRET_NAME_PATTERN.test(activeSecretName) || activeSecretName.length > 253)+ // One name-validity predicate per scope, shared by the step-0 wizard gate,+ // the inline field error, and the final save guard. LLM secrets POST to+ // /admin/secrets, which defers to the Kubernetes API server's DNS-subdomain+ // rules (dot-separated labels, ≤63 per label, ≤253 total) — the same+ // semantics as lib/k8sValidation's isValidDNSSubdomain. The MCP and recipe+ // routes validate server-side against the stricter label charset, so their+ // gates stay aligned with what their own API accepts.+ const activeNameValid =+ scope === 'llm'+ ? isValidDNSSubdomain(activeSecretName)+ : MCP_SECRET_NAME_PATTERN.test(activeSecretName) && activeSecretName.length <= 253+ const activeNameInvalid = activeSecretName.length > 0 && !activeNameValidconst canContinue =step === 0? activeSecretName.length > 0 &&- MCP_SECRET_NAME_PATTERN.test(activeSecretName) &&- activeSecretName.length <= 253 &&+ activeNameValid &&(scope !== 'recipe' ||recipeOwnershipKind === 'shared' ||recipeOwnerName.trim().length > 0)@@ -261,10 +274,8 @@ function CreateSecretPageContent() {setError('Secret name is required.')return}- if (!MCP_SECRET_NAME_PATTERN.test(secretName) || secretName.length > 253) {- setError(- 'Secret name must be lowercase alphanumeric and hyphens, and must start/end with an alphanumeric character.'- )+ if (!isValidDNSSubdomain(secretName)) {+ setError(LLM_SECRET_NAME_ERROR)return}const stringData = Object.fromEntries(@@ -456,19 +467,18 @@ function CreateSecretPageContent() {{step === 0 && scope === 'llm' ? (<div className="cu-form-stack cu-agent-form-stack"><Field- description="Kubernetes resource name: lowercase alphanumeric and hyphens, max 253 chars."- error={- activeNameInvalid- ? 'Name must match the Kubernetes DNS name format.'- : undefined- }- htmlFor="llm-secret-name"+ description="Kubernetes resource name: dot-separated labels of lowercase alphanumeric and hyphens — max 63 chars per label, 253 in total."+ error={activeNameInvalid ? LLM_SECRET_NAME_ERROR : undefined}+ errorId={LLM_SECRET_NAME_ERROR_ID}+ htmlFor={LLM_SECRET_NAME_FIELD_ID}label="Secret name"required><TextInput- id="llm-secret-name"+ id={LLM_SECRET_NAME_FIELD_ID}invalid={activeNameInvalid}+ aria-invalid={activeNameInvalid || undefined}+ aria-describedby={activeNameInvalid ? LLM_SECRET_NAME_ERROR_ID : undefined}value={llmName}onChange={event => setLlmName(event.target.value)}placeholder="secret-name"@@ -503,6 +513,7 @@ function CreateSecretPageContent() {? 'Name must match the Kubernetes DNS name format.': undefined}+ errorId="mcp-secret-name-error"htmlFor="mcp-secret-name"label="Secret name"required@@ -510,6 +521,8 @@ function CreateSecretPageContent() {<TextInputid="mcp-secret-name"invalid={activeNameInvalid}+ aria-invalid={activeNameInvalid || undefined}+ aria-describedby={activeNameInvalid ? 'mcp-secret-name-error' : undefined}monospacevalue={mcpName}onChange={event => setMcpName(event.target.value)}@@ -605,6 +618,7 @@ function CreateSecretPageContent() {? 'Name must match the Kubernetes DNS name format.': undefined}+ errorId="recipe-secret-name-error"htmlFor="recipe-secret-name"label="Secret name"required@@ -612,6 +626,8 @@ function CreateSecretPageContent() {<TextInputid="recipe-secret-name"invalid={activeNameInvalid}+ aria-invalid={activeNameInvalid || undefined}+ aria-describedby={activeNameInvalid ? 'recipe-secret-name-error' : undefined}monospacevalue={recipeName}onChange={event => setRecipeName(event.target.value)}diff --git a/control-ui/components/__tests__/CreateSecretPage.llm.test.tsx b/control-ui/components/__tests__/CreateSecretPage.llm.test.tsxindex 89ba282d2..c03c81968 100644--- a/control-ui/components/__tests__/CreateSecretPage.llm.test.tsx+++ b/control-ui/components/__tests__/CreateSecretPage.llm.test.tsx@@ -83,28 +83,78 @@ describe('Create LLM secret flow', () => {})})- it('blocks Continue on a name outside the Kubernetes DNS format', () => {+ it('accepts a valid dotted DNS-subdomain name and submits it', async () => {+ render(<CreateSecretPage />)+ await walkToValuesStep('team.primary')+ addProvider('OpenAI')+ fireEvent.change(screen.getByLabelText(/^OpenAI API key/i), {+ target: { value: 'sk-live-123' },+ })+ fireEvent.click(screen.getByRole('button', { name: 'Create secret' }))+ await waitFor(() => {+ expect(apiSend).toHaveBeenCalledWith(+ 'POST',+ '/api/v1/admin/secrets',+ expect.objectContaining({ name: 'team.primary' })+ )+ })+ })++ it('accepts a 63-character label and a 253-character dotted name at the boundary', () => {+ render(<CreateSecretPage />)+ fireEvent.change(secretNameInput(), { target: { value: 'a'.repeat(63) } })+ expect(screen.getByRole('button', { name: 'Continue' })).toBeEnabled()+ const atLimit = `${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(61)}`+ expect(atLimit.length).toBe(253)+ fireEvent.change(secretNameInput(), { target: { value: atLimit } })+ expect(screen.getByRole('button', { name: 'Continue' })).toBeEnabled()+ })++ it('blocks Continue on a name outside the DNS-subdomain rules without submitting', () => {render(<CreateSecretPage />)fireEvent.change(secretNameInput(), { target: { value: 'My Secret!' } })- const field = secretNameInput().closest('.cu-field')- expect(field).not.toBeNull()- expect(screen.getByText('Name must match the Kubernetes DNS name format.')).toBeInTheDocument()+ expect(screen.getByText(/must be a Kubernetes DNS subdomain/i)).toBeInTheDocument()expect(screen.getByRole('button', { name: 'Continue' })).toBeDisabled()+ expect(apiSend).not.toHaveBeenCalled()})- it('blocks Continue on a name longer than 253 characters', () => {+ it('rejects a 64-character label and a 254-character dotted name', () => {render(<CreateSecretPage />)- fireEvent.change(secretNameInput(), { target: { value: `${'a'.repeat(250)}-extra` } })- expect(screen.getByText('Name must match the Kubernetes DNS name format.')).toBeInTheDocument()+ fireEvent.change(secretNameInput(), { target: { value: 'a'.repeat(64) } })+ expect(screen.getByText(/must be a Kubernetes DNS subdomain/i)).toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Continue' })).toBeDisabled()+ const overLimit = `${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(62)}`+ expect(overLimit.length).toBe(254)+ fireEvent.change(secretNameInput(), { target: { value: overLimit } })+ expect(screen.getByText(/must be a Kubernetes DNS subdomain/i)).toBeInTheDocument()expect(screen.getByRole('button', { name: 'Continue' })).toBeDisabled()})+ it('exposes the invalid name to screen readers via aria-invalid and aria-describedby', () => {+ render(<CreateSecretPage />)+ const input = secretNameInput()+ // Valid (or empty): no invalid state announced.+ expect(input).not.toHaveAttribute('aria-invalid')+ fireEvent.change(input, { target: { value: 'Not A Name' } })+ const invalidInput = secretNameInput()+ expect(invalidInput).toHaveAttribute('aria-invalid', 'true')+ const describedBy = invalidInput.getAttribute('aria-describedby')+ expect(describedBy).toBeTruthy()+ const errorElement = document.getElementById(describedBy ?? '')+ expect(errorElement).not.toBeNull()+ expect(errorElement?.textContent).toMatch(/must be a Kubernetes DNS subdomain/i)+ // Recovery clears the announcement.+ fireEvent.change(invalidInput, { target: { value: 'team.primary' } })+ expect(secretNameInput()).not.toHaveAttribute('aria-invalid')+ expect(secretNameInput()).not.toHaveAttribute('aria-describedby')+ })+it('re-gates the flow when the name is invalidated after Back from step 2', async () => {render(<CreateSecretPage />)await walkToValuesStep('chatllm-api-keys')fireEvent.click(screen.getByRole('button', { name: 'Back' }))fireEvent.change(secretNameInput(), { target: { value: 'Not A Name' } })- expect(screen.getByText('Name must match the Kubernetes DNS name format.')).toBeInTheDocument()+ expect(screen.getByText(/must be a Kubernetes DNS subdomain/i)).toBeInTheDocument()expect(screen.getByRole('button', { name: 'Continue' })).toBeDisabled()expect(apiSend).not.toHaveBeenCalled()})diff --git a/control-ui/components/ui/index.tsx b/control-ui/components/ui/index.tsxindex bd21540ad..c40aae93c 100644--- a/control-ui/components/ui/index.tsx+++ b/control-ui/components/ui/index.tsx@@ -62,7 +62,15 @@ export function Button({)}-export function Field({ children, description, error, htmlFor, label, required }: FieldProps) {+export function Field({+ children,+ description,+ error,+ errorId,+ htmlFor,+ label,+ required,+}: FieldProps) {return (<div className="cu-field">{label ? (@@ -73,7 +81,11 @@ export function Field({ children, description, error, htmlFor, label, required }) : null}{children}{description ? <span className="cu-field__hint">{description}</span> : null}- {error ? <span className="cu-field__error">{error}</span> : null}+ {error ? (+ <span className="cu-field__error" id={errorId}>+ {error}+ </span>+ ) : null}</div>)}diff --git a/control-ui/components/ui/types.ts b/control-ui/components/ui/types.tsindex aa263b896..9ff828d51 100644--- a/control-ui/components/ui/types.ts+++ b/control-ui/components/ui/types.ts@@ -25,6 +25,8 @@ export type FieldProps = {children: ReactNodedescription?: ReactNodeerror?: ReactNode+ /** Stable id for the rendered error span, so inputs can aria-describedby it. */+ errorId?: stringhtmlFor?: stringlabel?: ReactNoderequired?: booleandiff --git a/control-ui/lib/__tests__/k8sValidation.test.ts b/control-ui/lib/__tests__/k8sValidation.test.tsindex 9ce1177a0..bdc93d9a1 100644--- a/control-ui/lib/__tests__/k8sValidation.test.ts+++ b/control-ui/lib/__tests__/k8sValidation.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { getAgentNameError, isValidK8sName, toK8sName } from '../k8sValidation'+import { getAgentNameError, isValidDNSSubdomain, isValidK8sName, toK8sName } from '../k8sValidation'describe('isValidK8sName', () => {it('accepts RFC 1123 DNS labels', () => {@@ -16,6 +16,44 @@ describe('isValidK8sName', () => {})})+describe('isValidDNSSubdomain', () => {+ it('accepts plain labels and dot-separated subdomains', () => {+ expect(isValidDNSSubdomain('chatllm-api-keys')).toBe(true)+ expect(isValidDNSSubdomain('team.primary')).toBe(true)+ expect(isValidDNSSubdomain('a.b.c')).toBe(true)+ expect(isValidDNSSubdomain('team-1.primary-2.keys')).toBe(true)+ })++ it('enforces DNS-label rules inside every dot-separated label', () => {+ expect(isValidDNSSubdomain('Team.Primary')).toBe(false)+ expect(isValidDNSSubdomain('team._primary')).toBe(false)+ expect(isValidDNSSubdomain('team.-primary')).toBe(false)+ expect(isValidDNSSubdomain('team.primary-')).toBe(false)+ expect(isValidDNSSubdomain('team..primary')).toBe(false)+ expect(isValidDNSSubdomain('.team')).toBe(false)+ expect(isValidDNSSubdomain('team.')).toBe(false)+ expect(isValidDNSSubdomain('')).toBe(false)+ })++ it('caps each label at 63 characters', () => {+ expect(isValidDNSSubdomain('a'.repeat(63))).toBe(true)+ expect(isValidDNSSubdomain('a'.repeat(64))).toBe(false)+ expect(isValidDNSSubdomain(`${'a'.repeat(63)}.b`)).toBe(true)+ expect(isValidDNSSubdomain(`${'a'.repeat(64)}.b`)).toBe(false)+ })++ it('caps the complete name at 253 characters', () => {+ // 4 labels of 63/63/63/61 chars + 3 dots = 253 exactly.+ const atLimit = `${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(61)}`+ expect(atLimit.length).toBe(253)+ expect(isValidDNSSubdomain(atLimit)).toBe(true)+ // Same shape with one more character (254 total) is over the limit.+ const overLimit = `${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(62)}`+ expect(overLimit.length).toBe(254)+ expect(isValidDNSSubdomain(overLimit)).toBe(false)+ })+})+describe('getAgentNameError', () => {it('accepts a valid agent name', () => {expect(getAgentNameError('my-agent')).toBe('')diff --git a/control-ui/lib/k8sValidation.ts b/control-ui/lib/k8sValidation.tsindex 93f53b585..22bac0957 100644--- a/control-ui/lib/k8sValidation.ts+++ b/control-ui/lib/k8sValidation.ts@@ -15,23 +15,25 @@ export function isValidK8sName(name: string): boolean {// RFC1123 DNS-SUBDOMAIN max length. K8s Secret names are validated as DNS// subdomains (≤253), NOT the stricter ≤63 DNS label used for hosts/contexts/-// channels. Mirrors the server's `isValidDNSSubdomain`-// (control-api/src/http/rfc1123.ts).+// channels.export const DNS_SUBDOMAIN_MAX_LENGTH = 253-// Same charset as a DNS label but up to 253 chars. Regex mirrors the server's-// DNS_SUBDOMAIN_RE (control-api/src/http/rfc1123.ts) exactly.-const DNS_SUBDOMAIN_RE = /^[a-z0-9]([a-z0-9-]{0,251}[a-z0-9])?$/+// One RFC1123 DNS label: lowercase alphanumeric + interior hyphens, 1-63+// chars, no leading/trailing hyphen.+const DNS_LABEL_RE = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$//**- * Validate a name as an RFC1123 DNS subdomain (lowercase alphanumeric + interior- * hyphens, ≤253 chars, no leading/trailing hyphen). Client-side mirror of the- * control-api `isValidDNSSubdomain` used to validate K8s Secret names. Returns- * false for the empty string. Use this — not `isValidK8sName` — for Secret- * names, which the server accepts up to 253 chars.+ * Validate a name as an RFC1123 DNS subdomain the way the Kubernetes API+ * server accepts Secret names (kubernetes.io names rules): dot-separated DNS+ * labels — lowercase alphanumeric + interior hyphens — with each label at+ * most 63 chars and the complete name at most 253 chars. `team.primary` is+ * valid; a 64-char label, an empty label (`a..b`, leading/trailing dot), and+ * an over-253 name are not. Returns false for the empty string. Use this —+ * not `isValidK8sName` — for Secret names.*/export function isValidDNSSubdomain(name: string): boolean {- return DNS_SUBDOMAIN_RE.test(name)+ if (name.length === 0 || name.length > DNS_SUBDOMAIN_MAX_LENGTH) return false+ return name.split('.').every(label => DNS_LABEL_RE.test(label))}/**diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex f991f6729..3af339469 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.708",+ "version": "0.1.709","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.708",+ "version": "0.1.709","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 94179ab19..1eaf4ecc2 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.708",+ "version": "0.1.709","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",