Skip to content
This repository was archived by the owner on Jul 27, 2026. It is now read-only.
This repository was archived by the owner on Jul 27, 2026. It is now read-only.

[ACP on Cloud] SDK: materialise reserved file-content auth secrets (Codex auth.json, Gemini Vertex SA) #2115

Closed

Description

@simonrosenberg

Priority: P0. Part of OpenHands/OpenHands#15746. Depends on #2113 (consolidated secret channel); pairs with #2114 / #2116 (where the file lands).

Goal

Some ACP providers authenticate from a file on disk, not an env var: Codex reads $CODEX_HOME/auth.json, Gemini (Vertex AI) reads a service-account JSON. The user supplies the credential as a pasted blob (a reserved "file-content" secret); the SDK must materialise it to the file path the CLI expects, with the right env var pointing at it.

Mechanism — declarative, registry-driven

Add an ACPFileSecretSpec (frozen, serialisable) plus a per-provider file_secrets list on the ACP_PROVIDERS registry, mapping a reserved secret name → target filename + the env var that points at it. Materialisation is generic and command-independent (keyed off the configured secret_name, so custom/aliased acp_commands still work):

  • Codex: CODEX_AUTH_JSON → auth.json, env CODEX_HOME=<dir>.
  • Gemini (Vertex): GOOGLE_APPLICATION_CREDENTIALS_JSON → gcloud-credentials.json, env GOOGLE_APPLICATION_CREDENTIALS=<file>; prefer the vertex-ai auth method; warn if GOOGLE_CLOUD_PROJECT / GOOGLE_CLOUD_LOCATION are unset.

Tasks

  • Read the secret value from state.secret_registry (the canonical channel — credentials arrive there via create_agent() → agent_context.secrets → create_request lift; see [ACP on Cloud] Refactor: consolidate ACP secret/env channels onto state.secret_registry #2113). Do not rely on agent_context.secrets alone.
  • Materialise into the persisted, per-conversation root (#1019 / [ACP on Cloud] Persistence: durable config + native session storage across pod recycles #2116), e.g. <conversations>/{id.hex}/acp/{provider}/ — seed-if-absent, no TemporaryDirectory, no delete-on-cleanup; write 0600 files in 0700 dirs. So a token the CLI refreshes on disk survives a recycle, and a stale paste never overwrites it.
  • Point the provider's data-dir env (CODEX_HOME / GOOGLE_APPLICATION_CREDENTIALS) at the materialised path.
  • Make Codex auth detection CODEX_HOME-aware — today it hardcodes ~/.codex/auth.json (acp_agent.py:234), so a relocated CODEX_HOME is never detected.
  • Tests: Codex auth.json + Gemini Vertex SA materialise to the right path; the env vars point at them; detection selects the subscription/Vertex auth method; the file survives across runs (seed-if-absent, not clobbered).

Depends on

#2113 (provides the secret_registry source + the per-provider data-dir env via create_agent). Materialisation target defined in #2114 / #2116.

Activity

  1. changed the title [-]ACP file-secret materialisation: pick ONE mechanism (#3269 vs #3292) + read from state.secret_registry[/-] [+][ACP on Cloud] SDK: pick ONE file-secret materialisation mechanism (+ read from secret_registry)[/+] on Jun 2, 2026
  2. changed the title [-][ACP on Cloud] SDK: pick ONE file-secret materialisation mechanism (+ read from secret_registry)[/-] [+][ACP on Cloud] SDK: materialise reserved file-content auth secrets (Codex auth.json, Gemini Vertex SA)[/+] on Jun 2, 2026
  3. simonrosenberg commented on Jun 3, 2026

    @simonrosenberg
    MemberAuthor

    Should file-materialisation live in the SDK (this PR) or in the downstream app?

    Re-raising the May-15 thread question (@xingyao's advice: let the downstream app own the credential files, keep the SDK out of it). Now that the cloud architecture is formalised, here's where I land.

    The thread conflated two deployment targets

    • Local unsandboxed (the desktop/npm run dev case, canvas#348): the local CLI is already logged in (~/.codex/auth.json, ~/.gemini/…). Xingyao is right here — the SDK shouldn't materialise anything.
    • Cloud / Docker (the whole point of [ACP on Cloud] Epic: ACP agents (Claude Code / Codex / Gemini) in Docker + cloud OpenHands#15746): the pod starts blank, HOME is ephemeral, and the downstream app (canvas browser / OpenHands backend pod) has no filesystem access to the runtime pod. The only channel into the pod is the conversation transport → state.secret_registry.

    The decisive constraint

    In cloud, "downstream writes the file" is physically impossible without building a separate credential-file-upload channel parallel to the secret channel. Whatever materialises the credential must run in-pod, at subprocess-spawn time. And the wiring is irreducibly SDK-side regardless of where the bytes are written:

    • setting CODEX_HOME / GOOGLE_APPLICATION_CREDENTIALS on the subprocess,
    • knowing the durable per-conversation root (state.persistence_dir),
    • CODEX_HOME-aware detection in _select_auth_method,
    • seed-if-absent so a token Codex rewrites on refresh survives a pod recycle and a stale paste can't clobber the live one.

    Splitting the file-write (downstream) from this wiring (SDK) would fracture one tightly-coupled concern across two repos.

    "Two auth paths" is intrinsic, not introduced by this PR

    Codex/Gemini subscription auth is file-based — there is no env var that authenticates a Codex subscription. The file path has to exist somewhere no matter what; the only choice is where it lives, not whether. Moving it downstream doesn't remove the second path, it relocates it to a place that can't reach the pod — and bypasses the secret channel's masking/redaction (#1023).

    This PR is already the hybrid the advice was asking for

    The design separates mechanism (write file, set env, seed-if-absent, 0600/0700, detection — SDK-owned, in-pod, cloud-capable) from policy (which secret → which file/env/dir for which CLI — expressed as data via ACPFileSecretSpec + an overridable acp_file_secrets field). So a downstream app can support a new file-auth CLI by supplying a spec, with no SDK change — exactly the "the app decides which CLIs it supports" flexibility from the thread.

    And it's a no-op in the local case: _materialise_file_secrets only acts when a reserved secret is actually present; otherwise detection falls back to the local login files unchanged. So Xingyao's "bare unsandboxed agent-server in a VM" case keeps working untouched (the only detection change — CODEX_HOME-awareness — is strictly additive).

    Recommendation

    Keep the mechanism in the SDK; keep policy as overridable data (i.e. what this PR ships). Reverting to "canvas owns the files" optimises the local case (already a no-op here) at the cost of the cloud case — the actual goal of OpenHands/OpenHands#15746 — and re-creates an ACP-special-case parallel channel, the opposite of the epic's guiding principle ("collapse onto state.secret_registry").

    One genuinely open sub-decision worth a call: openhands-sdk core vs openhands-agent-server as the home. Both run in-pod and both solve cloud. It's in core today because ACPAgent itself lives there and policy-as-data keeps core from hardcoding CLI quirks — but if we'd rather core stay strictly CLI-agnostic, the agent-server layer is a defensible alternative. Not canvas, though — that can't reach the pod FS.

    @xingyaoww — does the policy/mechanism split address the original concern, or do you want this in openhands-agent-server rather than sdk-core?

  4. simonrosenberg commented on Jun 3, 2026

    @simonrosenberg
    MemberAuthor

    Strategy read after reviewing OpenHands/software-agent-sdk#3474, this issue, and the surrounding epic/issues:

    I think we should follow the architectural advice in spirit, but not pivot to moving file materialisation out of the SDK entirely.

    The right split seems to be:

    • SDK owns mechanism: write the credential file inside the runtime pod before spawning the ACP subprocess, set the path env var, enforce 0600/0700, preserve refreshed files seed-if-absent, and honor final env precedence. This needs to happen where the CLI actually runs and where state.secret_registry, agent_context.secrets, persistence_dir, and acp_env precedence are all visible.
    • Downstream/product owns policy: which reserved secret maps to which filename/env/subdir for a provider. The PR head already mostly supports this via public ACPFileSecretSpec plus ACPAgent.acp_file_secrets / settings pass-through, with built-in defaults and downstream override/opt-out.

    Pros of this direction:

    • Avoids hard-coding product/provider policy too deeply in SDK internals.
    • Lets Canvas/OpenHands or another downstream support custom ACP servers without an SDK release.
    • Keeps the security-sensitive and pod-local operation in the only layer that can reliably do it.
    • Preserves direct SDK ergonomics through built-in Codex/Gemini defaults.
    • Matches the broader epic direction: collapse ACP credentials onto the normal secret/state path, but keep ACP subprocess setup as an SDK responsibility.

    Risks/tradeoffs:

    • If downstream must explicitly pass specs, missing wiring can regress auth, so product-level tests are needed.
    • The SDK still has some provider-specific auth-method detection (chatgpt, vertex-ai, API-key fallback), so the abstraction is not perfectly policy-free.
    • Removing built-in defaults entirely would make direct SDK usage worse and increase rollout risk for a P0 cloud path.

    Recommended tactical path for OpenHands/OpenHands#3474:

    1. Keep the SDK materialisation engine in this PR.
    2. Keep built-in Codex/Gemini defaults, but frame them as convenience defaults, not the only policy source.
    3. Have OpenHands/Canvas cloud construction pass explicit acp_file_secrets for the selected provider once that wiring is ready, so product policy is deliberate.
    4. Add/track product-level coverage that Canvas passes the expected Codex/Gemini specs.
    5. Update the PR body to remove stale references to the old ACP_FILE_SECRETS_BY_NAME registry and describe the current acp_file_secrets mechanism/policy split.

    Net: I would not do a broad rewrite. The PR already made the important strategic correction. Merge direction should be “SDK mechanism + downstream-overridable policy,” not “all provider file-auth logic lives outside the SDK.”

  5. simonrosenberg commented on Jun 3, 2026

    @simonrosenberg
    MemberAuthor

    Done — implemented in software-agent-sdk#3474 (merged 557f4664). Ships the mechanism/policy split: ACPFileSecretSpec + overridable acp_file_secrets (with built-in Codex/Gemini convenience defaults), materialises reserved file-content secrets seed-if-absent into <persistence_dir>/acp/{provider}/ (0600/0700), reads state.secret_registry then the agent_context.secrets drain, sets CODEX_HOME/GOOGLE_APPLICATION_CREDENTIALS, and adds CODEX_HOME-aware + vertex-ai detection. Validated e2e in a Docker container for all three providers (Codex via materialised auth.json→chatgpt, Claude via env token, Gemini via materialised SA→vertex-ai), which also confirmed the vertex-ai method id and yolo mode are real on the pinned CLIs. Follow-ups (downstream wiring: Canvas/OpenHands pass explicit specs + product tests) tracked toward #2117/#1016/#1013.

  6. transferred this issue fromOpenHands/OpenHandson Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions