Repository navigation
fix(workspace): look up provider tokens as GITHUB_TOKEN - #5730
Conversation
clone_repos requested github_token, gitlab_token and bitbucket_token, so a token stored under its conventional env var name was never used and private repos were cloned without credentials. It now requests GITHUB_TOKEN etc. and falls back to the lowercase name served by older app servers. Fixes #5729 Co-authored-by: openhands <openhands@all-hands.dev>
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Co-authored-by: openhands <openhands@all-hands.dev>
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||
Co-authored-by: openhands <openhands@all-hands.dev>
|
Manual test:
|
| Provider | Secret stored as | Before: requested -> result | After: requested -> result |
|---|---|---|---|
| github | GITHUB_TOKEN only (documented name) |
github_token -> 0/1 cloned |
GITHUB_TOKEN -> 1/1 (github:upper) |
| gitlab | GITLAB_TOKEN only |
gitlab_token -> 0/1 |
GITLAB_TOKEN -> 1/1 (gitlab:upper) |
| bitbucket | BITBUCKET_TOKEN only |
bitbucket_token -> 0/1 |
BITBUCKET_TOKEN -> 1/1 (bitbucket:upper) |
| github / gitlab / bitbucket | lowercase only (github_token etc.) |
*_token -> 1/1 (*:lower) |
*_TOKEN, then *_token -> 1/1 (*:lower), so the fallback works |
| github / gitlab / bitbucket | both names | *_token -> 1/1, lowercase value used (*:lower) |
*_TOKEN only -> 1/1, uppercase value used (*:upper), so uppercase wins and no second request is made |
| github / gitlab / bitbucket | nothing stored | 0/1 | 0/1 (asks *_TOKEN, then *_token, then clones anonymously and fails) |
Failure on main for the documented-name case (GitHub), from the [clone] warning log:
[clone] Failed: Cloning into '.../qa-repo'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
(0, None, ['github_token']) # cloned=0, requested=['github_token']
Commands (same for both checkouts, only the venv and QA_ROOT differ):
for w in main pr; do
QA_ROOT=/tmp/qa5730/root-$w /tmp/wt-$w/.venv-t/bin/python harness.py
doneSupplement (not the manual test): pytest tests/workspace/test_cloud_workspace_repos.py on the PR head -> 86 passed.
Full output for both checkouts
=== main @ 1592baf
github | documented name only | stored=['GITHUB_TOKEN'] | requested=['github_token'] | cloned=0 | repo_marker=None
github | lowercase name only | stored=['github_token'] | requested=['github_token'] | cloned=1 | repo_marker=github:lower
github | both names | stored=['GITHUB_TOKEN', 'github_token'] | requested=['github_token'] | cloned=1 | repo_marker=github:lower
github | no token stored | stored=[] | requested=['github_token'] | cloned=0 | repo_marker=None
gitlab | documented name only | stored=['GITLAB_TOKEN'] | requested=['gitlab_token'] | cloned=0 | repo_marker=None
gitlab | lowercase name only | stored=['gitlab_token'] | requested=['gitlab_token'] | cloned=1 | repo_marker=gitlab:lower
gitlab | both names | stored=['GITLAB_TOKEN', 'gitlab_token'] | requested=['gitlab_token'] | cloned=1 | repo_marker=gitlab:lower
gitlab | no token stored | stored=[] | requested=['gitlab_token'] | cloned=0 | repo_marker=None
bitbucket | documented name only | stored=['BITBUCKET_TOKEN'] | requested=['bitbucket_token'] | cloned=0 | repo_marker=None
bitbucket | lowercase name only | stored=['bitbucket_token'] | requested=['bitbucket_token'] | cloned=1 | repo_marker=bitbucket:lower
bitbucket | both names | stored=['BITBUCKET_TOKEN', 'bitbucket_token'] | requested=['bitbucket_token'] | cloned=1 | repo_marker=bitbucket:lower
bitbucket | no token stored | stored=[] | requested=['bitbucket_token'] | cloned=0 | repo_marker=None
=== PR @ 1190075
github | documented name only | stored=['GITHUB_TOKEN'] | requested=['GITHUB_TOKEN'] | cloned=1 | repo_marker=github:upper
github | lowercase name only | stored=['github_token'] | requested=['GITHUB_TOKEN', 'github_token'] | cloned=1 | repo_marker=github:lower
github | both names | stored=['GITHUB_TOKEN', 'github_token'] | requested=['GITHUB_TOKEN'] | cloned=1 | repo_marker=github:upper
github | no token stored | stored=[] | requested=['GITHUB_TOKEN', 'github_token'] | cloned=0 | repo_marker=None
gitlab | documented name only | stored=['GITLAB_TOKEN'] | requested=['GITLAB_TOKEN'] | cloned=1 | repo_marker=gitlab:upper
gitlab | lowercase name only | stored=['gitlab_token'] | requested=['GITLAB_TOKEN', 'gitlab_token'] | cloned=1 | repo_marker=gitlab:lower
gitlab | both names | stored=['GITLAB_TOKEN', 'gitlab_token'] | requested=['GITLAB_TOKEN'] | cloned=1 | repo_marker=gitlab:upper
gitlab | no token stored | stored=[] | requested=['GITLAB_TOKEN', 'gitlab_token'] | cloned=0 | repo_marker=None
bitbucket | documented name only | stored=['BITBUCKET_TOKEN'] | requested=['BITBUCKET_TOKEN'] | cloned=1 | repo_marker=bitbucket:upper
bitbucket | lowercase name only | stored=['bitbucket_token'] | requested=['BITBUCKET_TOKEN', 'bitbucket_token'] | cloned=1 | repo_marker=bitbucket:lower
bitbucket | both names | stored=['BITBUCKET_TOKEN', 'bitbucket_token'] | requested=['BITBUCKET_TOKEN'] | cloned=1 | repo_marker=bitbucket:upper
bitbucket | no token stored | stored=[] | requested=['BITBUCKET_TOKEN', 'bitbucket_token'] | cloned=0 | repo_marker=None
Harness (harness.py)
"""Real RemoteWorkspace.clone_repos -> real HTTP secrets endpoint -> real `git clone`."""
import os, subprocess, tempfile, threading
from http.server import BaseHTTPRequestHandler, HTTPServer
from pathlib import Path
os.environ["OPENHANDS_SUPPRESS_BANNER"] = "1"
ROOT = Path(os.environ["QA_ROOT"])
SECRETS, REQUESTED = {}, []
class H(BaseHTTPRequestHandler):
def log_message(self, *a): pass
def do_GET(self):
name = self.path.rsplit("/", 1)[-1]
REQUESTED.append(name)
if name in SECRETS: # case-sensitive, like the server
body = SECRETS[name].encode(); self.send_response(200)
else:
body = b'{"detail":"not found"}'; self.send_response(404)
self.send_header("Content-Length", str(len(body))); self.end_headers(); self.wfile.write(body)
srv = HTTPServer(("127.0.0.1", 0), H)
threading.Thread(target=srv.serve_forever, daemon=True).start()
from openhands.sdk.workspace.remote.base import RemoteWorkspace
PROV = {"github": ("{t}@", "github.com"), "gitlab": ("oauth2:{t}@", "gitlab.com"),
"bitbucket": ("x-token-auth:{t}@", "bitbucket.org")}
UP = {"github": "GITHUB_TOKEN", "gitlab": "GITLAB_TOKEN", "bitbucket": "BITBUCKET_TOKEN"}
TOK = {"upper": "fake-upper-tok", "lower": "fake-lower-tok"}
# build_fixtures(): one bare repo per (provider, label) with WHO="<provider>:<label>",
# plus gitconfig: [url "file://<root>/bare/<prov>/<label>/"] insteadOf = https://<auth-prefix><tok>@<host>/
# run(prov, secrets): RemoteWorkspace(host=stub).clone_repos([{"url": "https://<host>/qa-owner/qa-repo", "provider": prov}], tmp)
# -> returns (success_count, WHO marker of the clone, secret names requested)
# env for git: GIT_CONFIG_GLOBAL=<gitconfig> GIT_CONFIG_NOSYSTEM=1 GIT_TERMINAL_PROMPT=0(Fixture and run() bodies abbreviated into comments; the full script is in the sandbox at /tmp/qa5730/harness.py.)
Limits
- Not exercised: a real
app.all-hands.dev/ enterprise app server, real GitHub/GitLab/Bitbucket hosts, or a full agent-server process. The secrets endpoint is a local stub that mimicsGET /api/settings/secrets/{name}(200 with the value, or 404). TheRemoteWorkspaceHTTP client andclone_reposare the real code. git clonewas redirected withinsteadOf, so the token-bearing URL is what the SDK built, but no real authentication happened.CloudWorkspacewiring (openhands-workspace) and the agent-servergit_provider_servicetoken candidates were not run. I only read the diff for them.- Azure DevOps and the
bitbucket_data_centerentry onmainwere not tested. The PR branch predatesBITBUCKET_DATA_CENTERinPROVIDER_TOKEN_NAMES, which is stillbitbucket_data_center_tokenonmain. After rebasing, that provider would keep the lowercase-only name unless it is handled too. - "Before" is current
main(1592baf), not the PR's recorded baseacca181; I did not runacca181itself.
Verdict: Reproduced and fixed. On main, a token stored under GITHUB_TOKEN / GITLAB_TOKEN / BITBUCKET_TOKEN is never requested, so the clone runs unauthenticated (could not read Username). On the PR head it clones. The lowercase-only fallback and "uppercase wins when both exist" also behave as the PR describes.
This manual test was run by an AI agent (OpenHands) on behalf of @jpshackelford.
Resolve conflict in tests/workspace/test_cloud_workspace_repos.py: keep main's parametrized test_provider_token_name and expect the uppercase token names. Co-authored-by: openhands <openhands@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: In-repository change matching issue #5729 (bug, ready-for-dev): PROVIDER_TOKEN_NAMES now uses the documented uppercase env-var names, with a lowercase fallback in _TokenCache.get_provider_token() for app servers predating the rename. The agent-server's _GITHUB_TOKEN_CANDIDATES keeps the same name set (order swap only), and the verify-agent-server F15/F18 feature maps were updated consistently with the code including the fallback order. Grep confirms no other consumers of PROVIDER_TOKEN_NAMES/get_token_name(); the TypeScript client is unaffected.
Verification in workspace (head 346ba608): tests/workspace/test_cloud_workspace_repos.py 103 passed (including the three new regression tests covering uppercase lookup, lowercase fallback order, and uppercase preference); tests/workspace/ 250 passed; agent-server git-provider/secrets tests 73 passed. The live-evidence requirement is met: the PR includes a real git clone reproduction against a local bare repo reachable only via a token-bearing URL (insteadOf rewrite), showing main fails with could not read Username and this branch clones 1/1 with the token stored only as GITHUB_TOKEN.
Compatibility/security: backward compatible via the lowercase fallback; no new secret exposure (token-in-clone-URL behavior and redaction paths unchanged); _TokenCache caches None results so the fallback adds at most one extra lookup; no dependency or lockfile changes. Current-head CI: 36 checks pass (sdk-tests, agent-server-tests, cross-tests, integration-test, pre-commit, windows-tests); only image Build & Push jobs remain pending, with no failures. Not a release PR.
✅ APPROVED
HUMAN:
This PR is part of agentic self-healing work for the SDK.
AGENT:
Why
clone_reposrequested the provider token asgithub_token,gitlab_tokenorbitbucket_token. Everywhere else, including OpenHands conversations, the GitHub skill and the plugin-source docs, the same token isGITHUB_TOKEN. Secret names are case-sensitive. When a user stored their token under the documented name,clone_reposrangit clonewithout credentials, so their private repos failed to clone.Summary
PROVIDER_TOKEN_NAMESmaps providers toGITHUB_TOKEN,GITLAB_TOKENandBITBUCKET_TOKEN.clone_reposfalls back to the lowercase name when the uppercase one has no value, because app servers before fix: name provider tokens GITHUB_TOKEN in sandbox secrets endpoints enterprise#752 serve only the lowercase name.github_token, so its lookup is unchanged. Theverify-agent-serverfeature maps (F15, F18) now use the new names.Issue Number
Fixes #5729
How to Test
Run
uv run pytest tests/workspace/test_cloud_workspace_repos.py.test_clone_authenticates_with_token_stored_under_env_var_namestores the token asGITHUB_TOKEN,GITLAB_TOKENorBITBUCKET_TOKENand checks that it reaches the clone command.test_clone_falls_back_to_lowercase_token_namechecks the lookup order (uppercase, then lowercase) and that a token served only asgithub_tokenis still used.test_clone_prefers_uppercase_token_namechecks that the uppercase token wins when both names exist.I also ran the real
clone_reposwith a realgit cloneagainst a local bare repo that git could reach only through a token-bearinggithub.comURL (aninsteadOfrewrite, as in recipe F18.sdk-clone-repos). The token was stored only asGITHUB_TOKEN.main(acca181)['github_token']fatal: could not read Username for 'https://github.com', 0/1 cloned['GITHUB_TOKEN']Video/Screenshots
None.
Design Doc
None.
Type
Notes
RepoSource.get_token_name()now returns the uppercase name, which callers outsideclone_reposwill see. Once the enterprise change is deployed everywhere, the lowercase fallback can be removed.This PR was drafted by an AI agent (OpenHands) on behalf of @jpshackelford.
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:346ba60-pythonRun
All tags pushed for this build
About Multi-Architecture Support
346ba60-python) is a multi-arch manifest supporting both amd64 and arm64346ba60-python-amd64) are also available if needed