Skip to content

computer: Hold Git credentials on the host with an auth resolver - #245

Draft
mattzcarey wants to merge 1 commit into
mainfrom
git-host-auth
Draft

mattzcarey wants to merge 1 commit into
mainfrom
git-host-auth

Conversation

@mattzcarey

Copy link
Copy Markdown
Member

The Git commands the model runs, the worker-shell git command and ws:git, have no way to authenticate (#218). Host code can pass headers or onAuth on each typed call, but a model running git push against a private repository has to put a token on the command line, where it ends up in the transcript.

createGitClient() now takes an auth resolver. The client calls it for every HTTPS request a clone, fetch, pull, or push makes. It passes the repository URL and whether the request reads (fetch) or writes (push), then adds whatever credentials come back as an Authorization header:

const ws = new Workspace({
  storage: ctx.storage,
  git: createGitClient({
    auth: ({ url, operation }) =>
      url.startsWith("https://github.com/acme/")
        ? { username: "x-access-token", password: env.GITHUB_TOKEN }
        : undefined,
  }),
});

The resolver wraps the HTTP transport rather than each command. That way the typed API, cli(), the shell's git command and ws:git all get it, because the last two already run through the host's Git client. The token never reaches argv, the remote URL, .git/config or the output. Knowing the operation lets a host hand out a read-only token for fetches and a write token for pushes, for example short-lived Artifacts tokens.

An Authorization header passed on a call wins, and the resolver isn't asked. Plain http:// requests never get credentials.

The new auth.test.ts covers the header shapes and the operation detection. It also checks that call headers win, that plain HTTP gets nothing, and UTF-8 encoding. It drives a real Workspace through a typed clone, a CLI clone (checking the token isn't in the output) and a CLI push, using a transport that records requests and answers 401. Run it with:

npm test --workspace @cloudflare/computer -- src/git/auth.test.ts

The auth section of docs/13_git_interface.md and the README's Git section describe the resolver. A minor changeset is included.

Not covered here, and possible follow-ups from the issue:

  • ls-remote isn't a CLI command yet.
  • A redirect to another host relies on fetch dropping the Authorization header across origins.
  • The resolver doesn't store secrets. Where tokens live is up to the host.

The Git commands the model runs, the worker-shell `git` command and
`ws:git`, had no way to authenticate. Host code could pass `headers`
or `onAuth` on each typed call, but a model running `git clone` or
`git push` against a private repository had to put a token on the
command line, where it ends up in the transcript.

createGitClient() now takes an `auth` resolver. The client calls it
for every HTTPS request a clone, fetch, pull, or push makes, with the
repository URL and whether the request reads or writes, and adds the
credentials it returns as an Authorization header. The resolver wraps
the HTTP transport rather than each command, so the typed API, cli(),
the shell command, and ws:git all get it without their own plumbing.
The token never reaches argv, the remote URL, .git/config, or output.

An Authorization header passed on a call wins, and the resolver is not
asked. Plain http:// requests never get credentials.

Fixes #218.
@changeset-bot

changeset-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

馃 Changeset detected

Latest commit: 5b92ccd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@cloudflare/computer Minor
@cloudflare/dofs Minor
@cloudflare/computer-rpc Minor
@cloudflare/computerd Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@245

commit: 5b92ccd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant