Skip to content

feat(ui): Add mtlsMode select to AgentRuntime create form - #1627

Merged
huang195 merged 3 commits into
rossoctl:mainfrom
huang195:feat/ui-mtls-mode
May 21, 2026
Merged

huang195 merged 3 commits into
rossoctl:mainfrom
huang195:feat/ui-mtls-mode

Conversation

@huang195

Copy link
Copy Markdown
Member

Summary

Surfaces the new AgentRuntime.Spec.MTLSMode field (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"]] on CreateAgentRequest AND FinalizeShipwrightBuildRequest.
  • @model_validator on both that mirrors the operator's validating webhook check: rejects mtlsMode != disabled when authBridgeMode == envoy-sidecar. Returns 422 from FastAPI rather than letting the operator webhook deny later.
  • _build_agentruntime_manifest emits spec.mtlsMode when set, omits the key when None.
  • Both _ensure_agentruntime call sites updated (direct-create and Shipwright finalize).
  • Shipwright finalize: the field 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 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.
  • Greys out and force-resets to disabled when useEnvoyMode is checked.
  • Helper text covers two operator-relevant caveats:
    • Requires SPIRE in the cluster (the operator auto-enables SPIRE for workloads with mtlsMode != disabled).
    • Permissive falls back silently to plaintext on TLS handshake failure; use strict for production posture once rollout completes.

Types

  • MtlsMode type alias in types/index.ts.
  • mtlsMode field on agentService.create and shipwrightService.finalizeBuild body types in services/api.ts.

TUI (kagenti/tui/internal/api/types.go)

  • MTLSMode string field on CreateAgentRequest. No form/CLI work — TUI's deploy form doesn't yet expose authBridgeMode either; bundling form work would widen parity gaps. Tracked as a follow-up.

Tests

  • New 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-sidecar is rejected at four layers:

Layer Mechanism
UI FormSelect greyed out + force-reset to disabled when useEnvoyMode is checked
Backend Pydantic model_validator on both CreateAgentRequest and FinalizeShipwrightBuildRequest
Operator AgentRuntimeValidator.checkMTLSCompatibleWithMode (kagenti-operator PR #369)
Authbridge (Implicit) envoy-sidecar mode doesn't read the mtls: block; the field has no effect there

Trade-off worth flagging

The form always sends an explicit mtlsMode value (default disabled). Combined with the operator's CR-pin semantic, this means UI-created agents opt out of any namespace-level mtls.mode setting. A cluster admin who sets mtls.mode: strict in authbridge-runtime-config expecting 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 clear Spec.MTLSMode.

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. Clarifying comment added near tools' authBridgeMode field.
  • 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 GET-only display is a separate concern.
  • Edit-after-creation: kagenti has no edit-agent flow. Changing mtlsMode on an existing agent requires kubectl edit agentruntime <name>. Same constraint applies to authBridgeMode.
  • envoy-sidecar mTLS: requires extending the kagenti meta-chart's envoy-config template to configure SDS. Comparable in size to the original PR ✨ Add support for Agent, AgentBuild, MCPServer CRs and new operator integration #424.
  • TUI form parity: the TUI doesn't expose authBridgeMode either; widening that form is a separate piece of work.

Test plan

  • Backend: pytest tests/test_agentruntime_manifest.py — 11/11 pass
  • Backend: smoke-test via python -c 'from app.routers.agents import ...' — model validates, manifest emits, validator rejects the bad combo
  • UI: npx tsc --noEmit clean
  • UI: npm run lint adds no new errors (the two pre-existing 'id' unused-var warnings on the outboundRoutes destructure shifted line numbers due to state additions; count unchanged at 2)
  • TUI: go build ./... clean
  • CI passes
  • End-to-end demo verification:
    1. Deploy operator from main (PR 📖 Maintainers list #369 merged)
    2. Deploy kagenti with this branch
    3. Open the UI, navigate to Import Agent, expand AuthBridge Advanced Configuration
    4. Pick mtlsMode = strict, submit
    5. Verify kubectl get agentruntime <name> -o yaml shows spec.mtlsMode: strict
    6. Verify the per-agent ConfigMap has mtls: {mode: strict} block
    7. Verify two agent pods perform TLS handshakes on the wire (tcpdump from a debug pod)
    8. Toggle the form to useEnvoyMode = true, observe mtlsMode greys out and resets to disabled
    9. Negative path: bypass the form (curl POST), confirm backend returns 422 with the forward-pointing error

Files

  • kagenti/backend/app/routers/agents.py — Pydantic field + validator + manifest plumbing + Shipwright finalize plumbing
  • kagenti/backend/app/routers/tools.py — clarifying comment (no field added)
  • kagenti/backend/tests/test_agentruntime_manifest.py — 11 new tests
  • kagenti/ui-v2/src/types/index.ts — MtlsMode type alias
  • kagenti/ui-v2/src/services/api.ts — request body types
  • kagenti/ui-v2/src/pages/ImportAgentPage.tsx — state + FormSelect + submit-mapping
  • kagenti/tui/internal/api/types.go — Go struct field

Net: ~+308 / -4 LOC across 7 files.

Assisted-By: Claude (Anthropic AI) [email protected]

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]>
huang195 added 2 commits May 21, 2026 15:53
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 cwiklik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@huang195
huang195 merged commit 27787ae into rossoctl:main May 21, 2026
22 checks passed
@github-project-automation github-project-automation Bot moved this from New /:ToDo to Done in Rossoctl Issue Prioritization May 21, 2026
@huang195
huang195 deleted the feat/ui-mtls-mode branch May 21, 2026 20:44
eranra pushed a commit to eranra/kagenti that referenced this pull request May 24, 2026
feat(ui): Add mtlsMode select to AgentRuntime create form
Signed-off-by: Eran Raichstein <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants