Repository navigation
feat(ui): Add mtlsMode select to AgentRuntime create form - #1627
Conversation
Surfaces the new AgentRuntime.Spec.MTLSMode field (kagenti-operator PR rossoctl#369) through the kagenti stack so users can pick a per-workload mTLS posture from the Import Agent form instead of hand-editing the CR or namespace ConfigMap. # What ships Backend (kagenti/backend/app/routers/agents.py): * mtlsMode: Optional[Literal["disabled", "permissive", "strict"]] on CreateAgentRequest and FinalizeShipwrightBuildRequest. * @model_validator on both that mirrors the operator's validating webhook check: rejects mtlsMode != disabled when authBridgeMode is envoy-sidecar (Envoy SDS not currently configured by the kagenti chart). Returns 422 from FastAPI rather than letting the operator webhook deny later. * _build_agentruntime_manifest gains a mtls_mode kwarg that emits spec.mtlsMode when set, omits the key when None. * _ensure_agentruntime threads the value through; both call sites (direct-create and shipwright-finalize) updated. * Shipwright finalize: mtlsMode is stashed on the BuildRun via kagenti.io/agent-config annotation at submit time and read back at finalize, so build-from-source agents inherit the form's setting (parity with direct-image agents). UI (kagenti/ui-v2/src/pages/ImportAgentPage.tsx): * New FormSelect "Sidecar mTLS" inside the existing AuthBridge Advanced Configuration ExpandableSection (sits next to defaultOutboundPolicy). Three options: disabled (default) / permissive / strict. Each option has a one-line label explaining the runtime behavior. * Greys out and force-resets to "disabled" when useEnvoyMode is checked (pre-empts the backend/operator rejection of the envoy-sidecar + non-disabled combo). * Helper text covers two operator-relevant caveats: - Requires SPIRE in the cluster (mtls != disabled auto-enables SPIRE for the workload via the operator). - Permissive falls back silently to plaintext on TLS handshake failure; use strict for production posture once rollout completes. * Wire payload: always sends an explicit value when AuthBridge is on AND we're not in envoy-sidecar mode; sends undefined otherwise. The explicit-default approach means UI-created agents pin mtlsMode at the CR layer, opting out of any namespace-level mtls.mode setting (deliberate trade-off — the form should reflect what the user picks; cluster admins should use admission policy, not namespace defaults, to enforce posture). Types (kagenti/ui-v2/src/types/index.ts and services/api.ts): * MtlsMode type alias. * mtlsMode field on agentService.create and shipwrightService.finalizeBuild body types. TUI (kagenti/tui/internal/api/types.go): * MTLSMode string field on CreateAgentRequest. No form / CLI work in this PR — the TUI form doesn't yet expose authBridgeMode either; bundling form work would widen parity gaps. Tracked separately. Tests (kagenti/backend/tests/test_agentruntime_manifest.py, new): * 11 tests covering the manifest builder, the cross-field validator on both request models, the default behavior, and Pydantic Literal enforcement. # Out of scope (intentional) * Tools (kagenti/backend/app/routers/tools.py): tools don't create AgentRuntime CRs (they use the deprecated kagenti.io/authbridge-mode pod annotation), so mtlsMode has no place to live. A clarifying comment was added near tools' authBridgeMode field. Once tools start producing AgentRuntime CRs (operator-side follow-up), mtlsMode can be added here too. * AgentDetailPage display: showing the resolved mtlsMode for an existing agent would require a backend GET endpoint for the AgentRuntime CR. Deferred — agents are read-only post-creation today, and adding a GET-only display is a separate concern. * Per-mode metrics on the dashboard. * envoy-sidecar mTLS (Envoy SDS in the kagenti envoy-config template) — separate piece of work in the kagenti meta-chart. # Defense in depth The incompatible combo "mtlsMode != disabled with envoy-sidecar" is rejected at four layers: 1. UI: form greys out the mtlsMode select when useEnvoyMode is checked, force-resets to disabled. 2. Backend Pydantic model_validator on both CreateAgentRequest and FinalizeShipwrightBuildRequest. 3. Operator validating webhook (kagenti-operator PR rossoctl#369). 4. (Implicit) Authbridge runtime never sees the combination because envoy-sidecar mode doesn't read the mtls block. # Verification * Backend: pytest tests/test_agentruntime_manifest.py — 11/11 pass. Smoke-tested CreateAgentRequest instantiation, validator rejection, manifest emission via interactive Python. * UI: tsc --noEmit clean. eslint adds no new errors (the two pre-existing 'id' unused-var warnings on the outboundRoutes destructure pattern shifted line numbers due to my state additions; count unchanged). * TUI: go build ./... clean. * E2E demo path documented in PR description (deploy operator with PR rossoctl#369, deploy kagenti with this PR, walk through form, verify TLS handshake on the wire). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
CI lint job (ruff format --check) flagged two of the new files for formatting. Apply the formatter; no behavior change. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Three review-driven adjustments: 1. Rename the form field from "Sidecar mTLS" to just "mTLS". 2. Lock the select to disabled when spireEnabled is off (mirrors the existing useEnvoyMode lockdown). mTLS requires SPIRE-issued X.509 SVIDs, so the field is meaningless without SPIRE — making it explicit in the UI rather than letting users pick a value that the operator silently ignores. 3. Trim the helper text. Multi-paragraph explanations of byte-peek, SPIRE requirements, and permissive-fallback semantics belonged in docs, not in a form helper. The per-option labels carry the essentials. A single-line warning appears only when the field is disabled, explaining why. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
cwiklik
left a comment
There was a problem hiding this comment.
Well-structured PR surfacing AgentRuntime.Spec.MTLSMode through the full stack. Defense-in-depth validation at 4 layers (UI, backend, operator webhook, implicit envoy). Good test coverage (11 tests). The CR-pin trade-off (always sending explicit disabled) is documented and deliberate.
Areas reviewed: Python, Frontend, TUI (Go), Security
Commits: 2 commits, all signed-off
CI status: passing (Deploy & Test pending)
Assisted-By: Claude Code
| @@ -1207,6 +1221,30 @@ export const ImportAgentPage: React.FC = () => { | |||
| <FormSelectOption key="exchange" value="exchange" label="exchange — require token exchange for all outbound traffic" /> | |||
| </FormSelect> | |||
There was a problem hiding this comment.
suggestion: The MtlsMode type is defined in types/index.ts but the state here is typed inline as a string union literal. Consider using the type alias for consistency:
const [mtlsMode, setMtlsMode] = useState<MtlsMode>('disabled');| @@ -2308,6 +2343,8 @@ def _build_agent_shipwright_build_manifest( | |||
| resource_config["inboundPortsExclude"] = request.inboundPortsExclude | |||
| if request.defaultOutboundPolicy: | |||
There was a problem hiding this comment.
nit: if request.mtlsMode: works here because "disabled" is truthy and you want to stash it. But it reads oddly compared to the is not None pattern used in the finalize path (line ~3614). Consider if request.mtlsMode is not None: for consistency with the rest of the file's None-check pattern.
| // MTLSMode maps to AgentRuntime.Spec.MTLSMode. Backend rejects | ||
| // non-disabled values when AuthBridgeMode is "envoy-sidecar" | ||
| // (Envoy SDS not currently configured by the kagenti chart). | ||
| // Empty string sends nothing (operator default applies); the TUI |
There was a problem hiding this comment.
nit: minor formatting — MTLSMode has extra padding to align with PersistentStorage below, but AuthBridgeMode on the line above doesn't follow the same alignment. Not blocking, just inconsistent.
feat(ui): Add mtlsMode select to AgentRuntime create form Signed-off-by: Eran Raichstein <[email protected]>
Summary
Surfaces the new
AgentRuntime.Spec.MTLSModefield (added in kagenti-operator PR #369) through the kagenti backend + UI + TUI struct so users can pick a per-workload mTLS posture from the Import Agent form rather than hand-editing the CR or namespace ConfigMap.The mTLS feature is fully implemented on the operator + authbridge side (kagenti-extensions PR #424 merged authbridge mTLS, kagenti-operator PR #369 merged the CR field + auto-SPIRE + validation). This PR is the user-facing wiring.
What ships
Backend (
kagenti/backend/app/routers/agents.py)mtlsMode: Optional[Literal["disabled", "permissive", "strict"]]onCreateAgentRequestANDFinalizeShipwrightBuildRequest.@model_validatoron both that mirrors the operator's validating webhook check: rejectsmtlsMode != disabledwhenauthBridgeMode == envoy-sidecar. Returns 422 from FastAPI rather than letting the operator webhook deny later._build_agentruntime_manifestemitsspec.mtlsModewhen set, omits the key whenNone._ensure_agentruntimecall sites updated (direct-create and Shipwright finalize).kagenti.io/agent-configannotation at submit time and read back at finalize, so build-from-source agents inherit the form setting (parity with direct-image agents).UI (
kagenti/ui-v2/src/pages/ImportAgentPage.tsx)FormSelect"Sidecar mTLS" inside the existing AuthBridge Advanced Configuration ExpandableSection (sits next todefaultOutboundPolicy).disabled(default) /permissive/strict.disabledwhenuseEnvoyModeis checked.mtlsMode != disabled).Types
MtlsModetype alias intypes/index.ts.mtlsModefield onagentService.createandshipwrightService.finalizeBuildbody types inservices/api.ts.TUI (
kagenti/tui/internal/api/types.go)MTLSMode stringfield onCreateAgentRequest. No form/CLI work — TUI's deploy form doesn't yet exposeauthBridgeModeeither; bundling form work would widen parity gaps. Tracked as a follow-up.Tests
kagenti/backend/tests/test_agentruntime_manifest.py— 11 tests covering manifest builder, cross-field validator on both request models, default behavior, Pydantic enum enforcement.Defense in depth
The incompatible combo
mtlsMode != disabled+authBridgeMode = envoy-sidecaris rejected at four layers:FormSelectgreyed out + force-reset todisabledwhenuseEnvoyModeis checkedmodel_validatoron bothCreateAgentRequestandFinalizeShipwrightBuildRequestAgentRuntimeValidator.checkMTLSCompatibleWithMode(kagenti-operator PR #369)mtls:block; the field has no effect thereTrade-off worth flagging
The form always sends an explicit
mtlsModevalue (defaultdisabled). Combined with the operator's CR-pin semantic, this means UI-created agents opt out of any namespace-levelmtls.modesetting. A cluster admin who setsmtls.mode: strictinauthbridge-runtime-configexpecting it to apply to all new agents in the namespace will be surprised when UI-created agents come up plaintext.Reasoning: the form should reflect what the user picks; cluster admins should use admission policy (Kyverno / OPA) rather than ConfigMap defaults to enforce posture. Power users can still get namespace-default inheritance by
kubectl edit agentruntime <name>to clearSpec.MTLSMode.Out of scope (intentional)
kagenti/backend/app/routers/tools.py): tools don't create AgentRuntime CRs (they use the deprecatedkagenti.io/authbridge-modepod annotation), somtlsModehas no place to live. Clarifying comment added near tools'authBridgeModefield.mtlsModefor an existing agent would require a backend GET endpoint for the AgentRuntime CR. Deferred — agents are read-only post-creation today, and adding GET-only display is a separate concern.kubectl edit agentruntime <name>. Same constraint applies toauthBridgeMode.authBridgeModeeither; widening that form is a separate piece of work.Test plan
pytest tests/test_agentruntime_manifest.py— 11/11 passpython -c 'from app.routers.agents import ...'— model validates, manifest emits, validator rejects the bad combonpx tsc --noEmitcleannpm run lintadds no new errors (the two pre-existing'id' unused-varwarnings on theoutboundRoutesdestructure shifted line numbers due to state additions; count unchanged at 2)go build ./...cleanmain(PR 📖 Maintainers list #369 merged)mtlsMode = strict, submitkubectl get agentruntime <name> -o yamlshowsspec.mtlsMode: strictmtls: {mode: strict}blockuseEnvoyMode = true, observemtlsModegreys out and resets todisabledFiles
kagenti/backend/app/routers/agents.py— Pydantic field + validator + manifest plumbing + Shipwright finalize plumbingkagenti/backend/app/routers/tools.py— clarifying comment (no field added)kagenti/backend/tests/test_agentruntime_manifest.py— 11 new testskagenti/ui-v2/src/types/index.ts—MtlsModetype aliaskagenti/ui-v2/src/services/api.ts— request body typeskagenti/ui-v2/src/pages/ImportAgentPage.tsx— state + FormSelect + submit-mappingkagenti/tui/internal/api/types.go— Go struct fieldNet: ~+308 / -4 LOC across 7 files.
Assisted-By: Claude (Anthropic AI) [email protected]