Cargo / git GitHub auth fails inside the devcontainer
Cargo / git GitHub auth fails inside the devcontainer
You’ll see one of these on Anything that breaks a link produces the errors above.2. Check whether the token reached the containerThe classic failure: the helper points at a host path that doesn’t exist
in the Linux container, e.g.:This happens because VS Code’s “Dev Containers” extension copies your host
Verify:6. Make the fix durableThe container’s
cargo fetch / cargo build / gen genie build:Why it happens
The workshop repos pull framework dependencies from the privategen-bc/gen-framework-preview GitHub repo over HTTPS. Cargo delegates the
fetch to the git CLI (because .cargo/config.toml sets
net.git-fetch-with-cli = true), so git has to be able to authenticate
non-interactively. The token flows host → container like this:Step-by-step diagnosis
1. Confirmgit-fetch-with-cli is enabled[net] only works in .cargo/config.toml, NOT in Cargo.toml. If you
see warning: unused manifest key: net during a build, you have a stray
[net] block in Cargo.toml — remove it; it does nothing there.-
GH_TOKEN EMPTY→ the token never made it in. Fix on the host:ghstores its token in the OS keyring, not as an env var, so you must export it. Then relaunch VS Code from that terminal (code .) or set it machine-wide and rebuild the container: -
GH_TOKENset → continue.
- Returns a commit SHA → auth works; your problem is elsewhere (network,
wrong tag/ref,
Cargo.lock). Stop here. gh: not foundorcould not read Username→ the credential helper is broken. Continue to step 4.
~/.gitconfig into the container, including the credential helper line that
gh auth setup-git wrote on your Mac (which hard-codes
/opt/homebrew/bin/gh).5. Fix the credential helper (immediate, in the running container)Replace the broken helper with a token-backed one that doesn’t depend on
where gh lives:~/.gitconfig isn’t on a persistent volume, and VS Code
re-injects the host gitconfig on every connect, so step 5 alone is temporary.
Pick one permanent fix:-
Preferred — stop VS Code copying the host gitconfig. Add to VS Code
user
settings.json: -
Or fix the host gitconfig so the copied path is valid in both OSes —
use a bare
ghinstead of an absolute Homebrew path:ghresolves to/opt/homebrew/bin/ghon the host and/usr/bin/ghin the container, so the same line works in both.
One-liner triage
Inside the container:Host vs container quick reference
| Concern | Host (macOS) | Container (Ubuntu) |
|---|---|---|
gh binary location | /opt/homebrew/bin/gh | /usr/bin/gh |
| gh credential storage | OS keyring | GH_TOKEN env / gh-auth volume |
| Token as env var? | No (keyring) — export GH_TOKEN=$(gh auth token) to expose | Yes, via ${localEnv:GH_TOKEN} |
| git credential storage | osxkeychain | helper backed by GH_TOKEN |
| Why helpers break | — | host path /opt/homebrew/bin/gh doesn’t exist here |
`docker exec` into the container loses PATH and CARGO_TARGET_DIR
`docker exec` into the container loses PATH and CARGO_TARGET_DIR
remoteEnv from devcontainer.json is only applied to the VS Code terminal,
not to docker exec sessions. If you’re shelling in directly, export them
yourself before running cargo / gen:rust-analyzer / flycheck errors don't surface in the IDE
rust-analyzer / flycheck errors don't surface in the IDE
VS Code’s cargo wrapper inside the devcontainer can strip PATH, leaving
rust-analyzer unable to invoke the right toolchain. Symptom: code compiles
fine on the command line, but the IDE shows no errors or shows stale ones.Workarounds:
- Reload the VS Code window after the container finishes setting up
(
Developer: Reload Window). - Confirm
which cargoresolves inside the integrated terminal (the one VS Code reuses for rust-analyzer) to/home/vscode/.cargo/bin/cargo, not/usr/bin/cargo. - If still wrong, add
~/.cargo/binexplicitly to the front ofPATHin the VS Code terminal profile.
Hit something not on this page? Send the failing command and the full error
output to your Gen Labs contact — the page grows from real reports.

