Skip to content

fix(security): ACP namespace authz, error sanitization, CI stability - #1689

Merged
pdettori merged 44 commits into
rossoctl:mainfrom
Ladas:feat/openshell-security-fixes
Jun 10, 2026
Merged

pdettori merged 44 commits into
rossoctl:mainfrom
Ladas:feat/openshell-security-fixes

Conversation

@Ladas

@Ladas Ladas commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Security hardening and CI stability fixes following PR #1498 merge.

  • ACP namespace authorization: Verify JWT audience includes the requested namespace before accepting WebSocket connections. Prevents cross-tenant session access.
  • Session ownership checks: session/prompt, session/close, and session/resume verify the session belongs to the caller's namespace.
  • Error sanitization: Return generic error messages to clients, log full details server-side only.
  • gRPC credential eviction: Evict cached TLS credentials on UNAUTHENTICATED errors so key rotation takes effect immediately.
  • K8s name validation: Add length check (63 char max) and logging for rejected inputs.
  • Settings filtering: Broader pattern matching for sensitive keys in teleport script.
  • CI stability: Deploy team2 without agents (saves ~5 min, avoids helm timeout). RCA skill assertion accepts tool-call output from Claude Code.

Test plan

  • Backend unit tests pass (330/330)
  • T7 teleport tests pass (12/12) on local Kind
  • CI lint, CodeQL, Scorecard pass
  • OpenShell PoC Kind passes

Assisted-By: Claude Code

Comment thread kagenti/backend/app/routers/acp.py Fixed
# ADK agent with OpenShell supervisor as entrypoint
# Supervisor applies Landlock + seccomp + netns + OPA before exec'ing the agent
FROM ghcr.io/nvidia/openshell/supervisor:latest@sha256:70ad41288b905ae7b20d90da3a7709974ab9bc5fa9c699cdc32ea31facc552ed AS supervisor
FROM ghcr.io/kagenti/openshell/supervisor:v0.0.36-kagenti.8 AS supervisor
FROM ghcr.io/kagenti/openshell/supervisor:v0.0.36-kagenti.8 AS supervisor

FROM python:3.12-slim@sha256:4386a385d81dba9f72ed72a6fe4237755d7f5440c84b417650f38336bbc43117
FROM python:3.13-slim
@@ -1,4 +1,4 @@
FROM python:3.12-slim@sha256:4386a385d81dba9f72ed72a6fe4237755d7f5440c84b417650f38336bbc43117
FROM python:3.13-slim
# Weather agent running inside OpenShell supervisor
# Supervisor applies Landlock + seccomp, then execs the weather agent
FROM ghcr.io/nvidia/openshell/supervisor:latest@sha256:70ad41288b905ae7b20d90da3a7709974ab9bc5fa9c699cdc32ea31facc552ed AS supervisor
FROM ghcr.io/kagenti/openshell/supervisor:v0.0.36-kagenti.8 AS supervisor
@Ladas

Ladas commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

# Based on: NousResearch/hermes-agent v2026.5.29

FROM python:3.12-slim@sha256:4386a385d81dba9f72ed72a6fe4237755d7f5440c84b417650f38336bbc43117
FROM python:3.13-slim
@Ladas

Ladas commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

1 similar comment
@Ladas

Ladas commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

@github-actions

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: 518dbc45197ba4f9dfbf3ba8f8bc2e1e88469a36
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@github-actions

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: ed0e07108e05ec7177b2d10e12b671e17cd6bbc7
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

Ladas added a commit to Ladas/kagenti that referenced this pull request May 29, 2026
Add 3 T6 tests for sandbox agents via ACP WebSocket:
- test_T6_sandbox__initialize: ACP handshake works for sandbox agent name
- test_T6_sandbox__session_lifecycle: create/close session
- test_T6_sandbox__prompt_response: send prompt, get response via ExecSandbox

Initialize and session tests pass. Prompt test requires backend with
ExecSandbox gRPC client (PR rossoctl#1689 — currently uses kubectl exec fallback
on deployed backend from merged PR rossoctl#1498).

Signed-off-by: Ladislav Smola <[email protected]>
@Ladas

Ladas commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

@github-actions

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: af0af773a6130632b790e88adcfbec5f441de160
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@Ladas

Ladas commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

2 similar comments
@Ladas

Ladas commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

@Ladas

Ladas commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

@github-actions

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: cb5eba05f3f92f5d1c4aa2635ed473c0f5e828a7
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@github-actions

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: cb83cd9029ba734b12d6e551e9bdd810a275e6bb
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@github-actions

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: 88f9a4b1c80a8f3e3eaa11185c045efd5aebe623
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@Ladas

Ladas commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

1 similar comment
@Ladas

Ladas commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: aa359a6c281f9b93332774c3f09e2b37fe69c397
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: 8ef4bce1e6ecc2ece469cd07241b7de699929967
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@Ladas

Ladas commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: 6c7fb7b7df2221bd25039420a78625b554fd83c8
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

APPROVE — Solid security hardening across namespace authorization, error sanitization, and credential lifecycle. All 27 commits signed-off, lint/security/unit CI green.

The OpenShell PoC (Kind) failure appears to be a timeout issue being addressed by the latest commits (team2 skip when no LLM creds). Not blocking.

3 inline suggestions below for future hardening — none are blockers.

Comment thread kagenti/backend/app/routers/acp.py Outdated
allowed = {*aud, azp} if azp else set(aud)
# Deny if: no audience claims at all, or namespace not in allowed set
# "account" is Keycloak's default audience for all tokens
if not allowed or (namespace not in allowed and "account" not in allowed):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: The "account" audience is Keycloak's default for all tokens. If Keycloak mints every token with aud: ["account"], this check becomes a no-op — any authenticated user passes regardless of namespace.

The security guarantee depends on Keycloak client config: each tenant client must set azp to the namespace name, or use namespace-specific audiences. Consider:

  1. A comment documenting the Keycloak configuration requirement (which client mappers produce the correct audience)
  2. An optional strict mode where "account" alone is NOT sufficient (requires explicit namespace in aud or azp)

Not blocking since the fix for empty aud=[] is correct and the denial path is sound.

cmd = ["timeout", "90", cli]
if cli == "claude":
cmd += ["--print", "--bare", "--model", "claude-sonnet-4-20250514", text]
if "hermes" in session.agent_name:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Agent-to-CLI dispatch uses substring matching ("hermes" in session.agent_name). If a future agent name contains "claude" or "hermes" as a substring (e.g., my-claude-wrapper), it would route incorrectly.

Consider an explicit mapping dict keyed on the SANDBOX_AGENTS set values:

_SANDBOX_CLI = {
    "nemoclaw-hermes": ["hermes", "chat", "-q"],
    "openshell-claude": ["claude", "--print", "--bare", "--model", ...],
    "openshell-opencode": ["opencode", "run"],
}

)
if e.code() == grpc.StatusCode.UNAUTHENTICATED:
self._tls_cache.pop(namespace, None)
self._channels.pop(namespace, None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: The evicted channel isn't closed before removal. self._channels.pop(namespace, None) leaves the old gRPC channel potentially holding open connections.

Consider:

old_channel = self._channels.pop(namespace, None)
if old_channel:
    await old_channel.close()

Not critical since gRPC channels are reference-counted and eventually GC'd, but explicit close is cleaner for long-running processes.

Ladas added 14 commits June 6, 2026 22:47
…lose

Address 3 review comments from pdettori:

1. acp.py: Remove "account" audience bypass — Keycloak's default aud
   alone is NOT sufficient for namespace authorization. Add comment
   documenting the Keycloak client config requirement.

2. acp_bridge.py: Replace substring matching ("hermes" in agent_name)
   with explicit _SANDBOX_CLI dispatch dict keyed on exact agent names.
   Prevents misrouting if future agent names contain substrings.

3. gateway.py: Close evicted gRPC channel explicitly before removal
   instead of relying on GC. Prevents connection leaks on long-running
   backend processes.

Signed-off-by: Ladislav Smola <[email protected]>
BACKEND_NS is defined in Step 7 (backend deploy) but the Keycloak
client secret creation was added to Step 4 (realm setup). Use explicit
namespace loop for team1/team2 instead of the undefined variable.

Fixes: "BACKEND_NS: unbound variable" crash in CI deploy.

Signed-off-by: Ladislav Smola <[email protected]>
The gateway validates aud claim in JWT. The kagenti-backend client was
created without the tenant audience scopes (team1-audience, etc.), so
tokens had no audience and the gateway rejected them.

Assign the same default client scopes to kagenti-backend that the
openshell-cli client gets, so ExecSandbox gRPC tokens include the
correct aud: team1 claim.

Signed-off-by: Ladislav Smola <[email protected]>
T6 sandbox prompt test failed because:
1. ExecSandbox sends agent_name as sandbox_id but 'openshell-claude'
   isn't a Sandbox CR name — real sandboxes are 'teleport-<session>'
2. Gateway requires openshell-user role on the service account JWT

Fix:
- Test creates a sandbox via teleport --spawn before sending prompt
- ACP bridge routes teleport-* prefixed agent names to sandbox path
- Default CLI fallback uses claude --print (for teleport sandboxes)
- Deploy script assigns openshell-user role to backend service account

Signed-off-by: Ladislav Smola <[email protected]>
Address 3 findings from high-effort code review:

1. Session memory leak: cleanup_sessions only removed closed sessions.
   Open sessions leaked on WebSocket disconnect. Fixed by removing
   all sessions for the disconnected namespace/agent pair.

2. OIDC token TTL: cache check used TLS_CACHE_TTL (300s) instead of
   the token's actual expiry time. Fixed to compare against the stored
   expiry timestamp (monotonic + expires_in - margin).

3. Blocking subprocess in async test: subprocess.run(timeout=120)
   blocked the event loop. Wrapped in asyncio.to_thread() for both
   spawn and cleanup calls.

Signed-off-by: Ladislav Smola <[email protected]>
ExecSandbox gRPC requires gateway-managed sandboxes (CreateSandbox RPC).
Teleport creates K8s-managed sandboxes (Sandbox CRD via agent-sandbox-
controller). These are different systems — the gateway's ExecSandbox
returns NOT_FOUND for CRD-created sandboxes.

Mark as xfail with detailed explanation instead of removing. The test
still runs and will flag XPASS when CreateSandbox proto is vendored
and the backend creates sandboxes via the gateway.

Architecture gap tracked in docs/research/openshell-fork-analysis.md.

Signed-off-by: Ladislav Smola <[email protected]>
Update gateway and supervisor images from v0.0.36-kagenti.8 (mvp branch)
to mvp-v2-3a1bbea7 (mvp-v2 branch, based on upstream v0.0.49+).

The mvp-v2 branch was created by pdettori with:
- Synced main with NVIDIA/OpenShell upstream
- Rebased kagenti patches (credentials driver, External driver, OIDC)
- Fixed Rust compilation issues (clippy, Debug impl, telemetry)
- CI publish workflows updated for mvp-v2 branch

This upgrades the OpenShell gateway and supervisor to the latest
upstream, which may include fixes for rossoctl#1647 (wildcard matching)
and rossoctl#1669 (port/ports normalization).

Old mvp branch (v0.0.36-kagenti.8) preserved for rollback.

Signed-off-by: Ladislav Smola <[email protected]>
Rewrite openshell-fork-analysis.md to reflect mvp-v2 as the active
build branch (was mvp/v0.0.36-kagenti.8):

- Branch strategy updated: mvp-v2 is active, mvp archived
- CLI args change documented (--drivers=external replaces --sandbox-namespace)
- Patches section rewritten with actual mvp-v2 commits
- Known issues updated: rossoctl#1815 (scratch image), ExecSandbox vs CRD mismatch
- Upgrade plan replaced with "completed" status and rollback instructions
- Status table: what's done vs what needs verification

Signed-off-by: Ladislav Smola <[email protected]>
The pull_request CI trigger has no secrets, so litellm-virtual-keys
secret doesn't exist. Sandbox pods using hard secretKeyRef would be
stuck in ContainerCreating. Making the ref optional lets pods start
without LLM credentials — prompt tests already skip when LLM is
unavailable. Also adds diagnostic output on spawn failures and fixes
test timeout (60s was less than script's 90s wait).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
The upstream certgen pre-install hook (gatewayJwt.enabled=true) creates
TLS secrets directly, but our deploy-shared.sh sets up cert-manager to
manage the same secrets via Certificate CRs. Both target the same secret
names (openshell-server-tls, openshell-client-tls), causing cert-manager
Certificates to never become Ready — the secrets already exist without
cert-manager ownership annotations.

Disable the certgen hook for now so cert-manager handles TLS as before.
The gateway JWT auth feature can be re-enabled when cert-manager
Certificate resources are conditioned on gatewayJwt.enabled.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
Code review findings:
1. gateway.py: _get_oidc_token used sync httpx.post inside async
   exec_sandbox, blocking the event loop for up to 10s on cache miss.
   Converted to async with httpx.AsyncClient.
2. weather-agent policy-data.yaml: openweathermap.org:443 was removed
   from network_policies, breaking the agent's core function.
   Restored the endpoint.
3. weather-agent policy-data.yaml: /.cache was missing from Landlock
   read_write list but the deployment mounts an emptyDir there.
   Added /.cache to read_write.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
…secrets

- Keycloak backend client secret: generated via /dev/urandom (was
  hardcoded 'kagenti-backend-secret')
- PostgreSQL sessions password: generated via /dev/urandom (was
  hardcoded 'kagenti-sessions-dev')
- Test user passwords (alice/bob/admin): generated via /dev/urandom
  (were hardcoded 'alice123'/'bob123'/'admin123'), stored in K8s
  secret openshell-test-users for test scripts to read
- openshell-full-test.sh: exports OPENSHELL_ALICE_PASSWORD and
  OPENSHELL_BOB_PASSWORD from K8s secret for tenant isolation tests

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
Upstream PR rossoctl#1833 removed cert-manager Certificate resources, so the
certgen hook is now the sole TLS mechanism. The gatewayJwt.enabled=false
workaround (added to avoid cert-manager conflict) is no longer needed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
@Ladas
Ladas force-pushed the feat/openshell-security-fixes branch from efa6a3e to c34789b Compare June 6, 2026 20:48
@Ladas

Ladas commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

@github-actions github-actions Bot removed the safe-to-test Maintainer reviewed - safe to run E2E tests label Jun 6, 2026
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

New Commits Detected

The safe-to-test label has been automatically removed because new commits were pushed.

New HEAD: c34789b

For maintainers: Please review the new changes and comment /run-e2e to trigger E2E tests.

Security checklist

Before running E2E tests, verify the PR does NOT contain:

  • Changes to .github/workflows/ that bypass security
  • Changes to .github/scripts/ that could exfiltrate secrets
  • curl, wget, or nc commands to external URLs in scripts
  • Base64 encoding of environment variables
  • Printing secrets to logs (echo $SECRET)
  • Suspicious package installations

This is an automated security measure to prevent TOCTOU attacks

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: c34789b23383f67d80e24ab9054d211e922ed648
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

AWS refuses to delete a route table that has non-local routes pointing
to active targets (e.g., 0.0.0.0/0 -> NAT gateway). The cleanup code
called delete-route-table directly and swallowed the error with || true,
leaving orphaned route tables that caused RouteAlreadyExists on the
next cluster creation.

Fix: enumerate and delete all non-local routes from the route table
before attempting deletion. Also improved association query to exclude
main route table associations (which can't be disassociated).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
@Ladas

Ladas commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e-openshell

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

❌ [Experimental] OpenShell E2E Tests Failed

Commit: 303341a8acbd20c1086b7f2700400f07b80be84f
Workflow: View logs


Non-voting. Re-run: /run-e2e-openshell

@Ladas
Ladas marked this pull request as ready for review June 9, 2026 12:21
@pdettori

Copy link
Copy Markdown
Member

All three review suggestions addressed in latest commits:

  1. acp.py audience check — strict mode implemented ("account" discarded from allowed audiences) + docstring documenting Keycloak config requirement
  2. acp_bridge.py dispatch — substring matching replaced with explicit _SANDBOX_CLI mapping dict
  3. gateway.py channel eviction — await old_channel.close() added before cache removal

CI all green. LGTM to merge.

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.

3 participants