Skip to content

fix(sandbox): port submodule credentials to the Go daemon - #5907

Merged
aka-sacci-ccr merged 2 commits into
mainfrom
submodule-deps-not-installed
Aug 11, 2026
Merged

aka-sacci-ccr merged 2 commits into
mainfrom
submodule-deps-not-installed

Conversation

@aka-sacci-ccr

@aka-sacci-ccr aka-sacci-ccr commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This is a regression fix, not a new feature. #4885 shipped per-host submodule PATs in July, with the daemon half in packages/sandbox/daemon/setup/clone.ts. The Go port (#5484) omitted that half, and #5575 deleted the TypeScript daemon on Aug 2 — so since then Studio resolves the secret, redacts it, and ships it in the config payload, while the Go daemon drops it on unmarshal and never runs git submodule update.

git log -S"submodule" -- daemon-go/internal/setup/clone.go returns zero commits: it never existed there. A repo with private submodules clones with empty submodule directories and the dev server dies on unresolved imports — exactly the ZeeDog/zee case #4885 was written for.

What this does

Ports the deleted implementation to Go. Mechanical migration — same call sites, same semantics, no behavior added:

  • git.repository.submoduleCredentials on the Go config, carried through mergeRepository. Absent keeps current (so a clone-URL-only credential refresh doesn't drop the PATs); an explicit [] clears. That reproduces the TS deepMerge's documented "field absent → leave existing / arrays replace wholesale" in Go's field-by-field merge.
  • Host validation (mirrors SUBMODULE_HOST_RE), dedupe by host (last token wins), percent-encoded credentials-file lines, per-host SSH→HTTPS insteadOf rewrites, submodule update --init --recursive --depth 1 — funnelled through finalize so both acquisition paths and both branch cases get it. Same single call site as the TS (spawnClone's finalize); nothing added on checkout/rebase.
  • Opt-in and best-effort throughout: no-op without credentials or a .gitmodules; a fetch failure warns and leaves the checkout intact.
  • The token stays on the git-only channel: a 0600 temp file outside the repo, deleted after the fetch, never in argv, env, or the repo's .git/config, and redacted from both /_sandbox/config responses. Redaction copies rather than mutates — the input aliases the live store, and clearing it in place would disarm the clone step itself.

Deliberate deviations from the TS original

All platform-driven; none changes observable behavior. Listed for review:

  1. Cred file path — TS used a fixed path next to the askpass script; the Go daemon has no askpass file (it sets GIT_ASKPASS=true as env), so there is no such directory. Uses os.CreateTemp. Side benefit: two concurrent clones can't collide on one filename.
  2. Explicit Chmod(0600) on top of CreateTemp's mode — one defensive line against a umask surprise, since the file holds a long-lived PAT.
  3. Token encoding via url.URL{User: url.UserPassword(...)} instead of encodeURIComponent. Not byte-identical (Go leaves $&+,;= literal) but both are valid RFC 3986 userinfo and git decodes to the same token. The obvious alternative, url.QueryEscape, renders a space as +, which git would read literally — that would be a bug.
  4. One log string differs: a credentials-file write failure says submodule credentials file errored (…) where the TS said submodule update errored (…). Same place, same degradation.
  5. runSubmoduleUpdate takes an injected run func([]string) int so the argv/best-effort contract is testable — Go's SpawnStepArgv isn't mockable the way the TS spawn was.

Testing

  • Go unit (go test -race ./..., all packages green): pure argv/credentials-line functions (percent-encoding, dedupe, host rejection, exact argv, no token in argv), the best-effort paths (no creds, no .gitmodules, invalid host, non-zero exit), the 0600 credentials file written outside the repo and deleted after; config merge + Classify; route redaction on read and write echo, asserting the live store keeps the token.
  • New black-box e2e packages/sandbox/daemon-e2e/daemon.submodules.e2e.test.ts (4 tests): the fetch is attempted with the SSH→HTTPS rewrite actually applied, the clone survives an unreachable submodule, an invalid host is skipped, and neither /config response echoes the token. Uses an RFC 2606 .invalid submodule host, so it stays hermetic.
  • Verified the e2e catches the regression: against the pre-fix wiring (SubmoduleCredentials: nil), 2 of the 4 fail.
  • Full daemon e2e suite: 217 pass, 0 fail. go vet + gofmt clean. bun run fmt, bun run lint (14 pre-existing warnings in an unrelated Playwright file), tsc --noEmit on packages/sandbox, knip clean. Studio-side build-config-payload.test.ts + helpers.test.ts: 21 pass.

Evidence from a real clone log during the e2e — rewrites applied, no token in argv:

$ git … -C /…/repo -c url.https://bff.invalid/[email protected]: \
  -c url.https://bff.invalid/.insteadOf=ssh://[email protected]/ \
  -c "credential.helper=store --file=/…/submodule-git-credentials1640896206" \
  submodule update --init --recursive --depth 1
Submodule 'vendor/bff' ([email protected]:acme/bff.git) registered for path 'vendor/bff'

Not covered

  • The real success path (a private submodule materialized with a valid PAT) still has no e2e — it needs an authenticating HTTPS git server in CI. feat(sandbox): user-provided git submodule credentials per virtual MCP #4885 didn't cover it either ("Not exercised end-to-end here"). What's proven: the command runs, with the auth configured.
  • One TS test not ported: "swallows a credentials-file write error and still succeeds". The TS forced it by pointing askpassPath at a nonexistent directory; with CreateTemp in TMPDIR there's no way to force it without injecting the temp dir. The code path exists and degrades correctly, but is untested. Happy to inject the dir and port the case if reviewers want the coverage parity.

How to verify manually

Add a secret holding a PAT with read access to the submodule's repo, map github.com → that secret in the virtual MCP's Sandbox card, then start the sandbox. The clone log should show the submodule update step with the insteadOf rewrites and no token.

🤖 Generated with Claude Code


Summary by cubic

Restores submodule credential support in the Go sandbox daemon so private submodules fetch during clone without leaking tokens. Also fixes config persistence and revocation so an empty submoduleCredentials clears stored PATs and no-op patches still persist.

  • Bug Fixes
    • Ported per-host submodule PATs to packages/sandbox/daemon-go: host validation/dedupe, SSH→HTTPS insteadOf, shallow recursive git submodule update; opt-in and best-effort.
    • Persisted “no‑op” config patches in the store so credential updates aren’t dropped; redacted tokens from all /_sandbox/config responses by copying, not mutating.
    • Studio/API always sends submoduleCredentials (empty included) and the daemon merge treats absent as “keep current” while [] clears; orchestrator now passes creds to the clone step.
    • Tightened token handling: credentials file at a deterministic path under the daemon tmp dir (0600), swept at boot; never in argv/env or .git/config; submodule step runs via runStep to avoid retry inflation.
    • Added Go unit tests and a black‑box e2e suite, including revocation and leftover‑sweep coverage.

Written for commit 840da26. Summary will update on new commits.

Review in cubic

#4885 shipped per-host submodule PATs, with the daemon half in
`packages/sandbox/daemon/setup/clone.ts`. The Go port (#5484) omitted that
half, and #5575 deleted the TypeScript daemon — so since then the Studio
side has resolved the secret, redacted it, and shipped it in the config
payload, while the daemon dropped it on unmarshal and never ran
`git submodule update`. A repo with private submodules clones with empty
submodule directories and the dev server dies on unresolved imports.

Ports the deleted implementation:

- `git.repository.submoduleCredentials` on the Go config, carried through
  `mergeRepository` (absent keeps current, so a clone-URL-only credential
  refresh doesn't drop the PATs).
- Host validation (mirrors `SUBMODULE_HOST_RE`), dedupe by host,
  percent-encoded credentials-file lines, per-host SSH→HTTPS `insteadOf`
  rewrites, and `submodule update --init --recursive --depth 1` — funnelled
  through `finalize` so both acquisition paths and both branch cases get it.
- Opt-in and best-effort throughout: no-op without credentials or a
  `.gitmodules`; a fetch failure warns and leaves the checkout intact.
- The token stays on the git-only channel: a 0600 temp file outside the repo,
  deleted after the fetch, never in argv, env, or the repo's `.git/config`,
  and redacted from both `/_sandbox/config` responses (the copy is what the
  browser sees; the live store keeps the token for the clone step).

Tests: Go unit tests for the pure argv/credentials-line functions and the
best-effort paths, config merge + classify, and route redaction; a
`daemon.submodules.e2e.test.ts` black-box suite asserting the fetch is
attempted with the rewrite applied, the clone survives an unreachable
submodule, an invalid host is skipped, and no response echoes the token.
Verified the e2e fails against the pre-fix wiring.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions github-actions Bot added the claude PR authored by a coding agent label Aug 11, 2026
…ial revoke

Review of the submodule-credentials port surfaced two defects on the config
plane, both of which made the feature partially unusable, plus three smaller
ones. Each had a test pinning the broken behavior as correct; those are
inverted here.

- `Store.apply` returned on a `KindNoOp` transition WITHOUT writing the merged
  config. "No-op" classifies the side effect (no re-clone, no restart), not the
  write — so a patch carrying a field `Classify` has no arm for, which is
  exactly submodule credentials, was answered 200 with a receipt echoing the
  new value while the store kept the old one. Guarded on non-nil so an inert
  patch still can't claim an unclaimed daemon.

- `submoduleCredentials` is now always sent, empty array included. The daemon
  reads an absent field as "keep current", and both `buildConfigPayload` and
  `readValidatedSubmoduleCredentials` collapsed "the user deleted their last
  row" into "never configured" — so a revoked PAT stayed live in the pod for
  its lifetime, and a re-bootstrapped pod kept the previous config's tokens.
  The `[]`-clears path the merge documents was unreachable from its only
  producer.

- The credentials file moves from a random `os.CreateTemp` name in the shared
  /tmp to a deterministic path in the daemon's own tmp dir, swept at boot. A
  SIGKILL between the write and the `defer os.Remove` strands a live PAT on
  disk, and only a name the next boot can predict is sweepable.

- The submodule fetch runs through `runStep`, not `runNetworkStep`. `--recursive`
  emits aggregate output, so one dead submodule host matches the transient-error
  list and bought 4 full recursive passes plus 9s of sleeps ahead of install and
  the dev server, for a step whose failure is already tolerated.

- Two comments claimed protection the runtime doesn't provide: 0600 does not
  hide the file from tenant code (every process in the pod shares one uid — the
  control is lifetime), and `/config` redaction is defense in depth against a
  remote reader, not a boundary against in-pod code.

Tests: the two that pinned the bugs are inverted; the redaction tests now
assert 200 + a cloneUrl round-trip so they can't pass on an empty response;
`cloneLog` throws instead of returning "" so the e2e's absence assertions
can't pass vacuously; the e2e proves the SSH→HTTPS rewrite positively (the
URL git actually dialed) rather than by the absence of an ssh error. New:
credentials-file write failure, deletion after a failed fetch, per-host token
pairing, the boot sweep, and an e2e for revocation.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@aka-sacci-ccr
aka-sacci-ccr merged commit d4511f2 into main Aug 11, 2026
23 checks passed
@aka-sacci-ccr
aka-sacci-ccr deleted the submodule-deps-not-installed branch August 11, 2026 23:22
decocms Bot pushed a commit that referenced this pull request Aug 11, 2026
PR: #5907 fix(sandbox): port submodule credentials to the Go daemon
Bump type: patch

- decocms (apps/api/package.json): 4.204.10 -> 4.204.11
- @decocms/native (apps/native/package.json): 4.204.10 -> 4.204.11
- @decocms/sandbox (packages/sandbox/package.json): 1.53.4 -> 1.53.5
- deploy/helm/sandbox-env (chart 0.15.6) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.53.5

Deploy-Scope: server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude PR authored by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants