Repository navigation
fix: name provider tokens GITHUB_TOKEN in sandbox secrets endpoints - #752
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||
Manual test: sandbox secrets endpoints name provider tokens
|
| Request | Before: main @ 36b22be7da |
After: PR @ 0e902e4733 |
|---|---|---|
GET .../secrets (plain) |
[github_token] |
[GITHUB_TOKEN] |
GET .../secrets/GITHUB_TOKEN (plain) |
404 Secret not found |
200 FAKE-gh-provider-token |
GET .../secrets/github_token (plain, legacy SDK name) |
200 | 200 (still works) |
GET .../secrets (custom secret GITHUB_TOKEN overrides provider token) |
[GITHUB_TOKEN, github_token] (token listed twice under two names) |
[GITHUB_TOKEN] (once) |
GET .../secrets/GITHUB_TOKEN (override) |
200 FAKE-custom-override-pat |
200 FAKE-custom-override-pat (custom wins) |
GET .../secrets (multi) |
[github_token, gitlab_token, azure_devops_token] |
[GITHUB_TOKEN, GITLAB_TOKEN, AZURE_DEVOPS_TOKEN] |
GET .../secrets/{GITLAB_TOKEN,AZURE_DEVOPS_TOKEN} (multi) |
404, 404 | 200, 200 (FAKE-gl-token, FAKE-ado-token) |
So an automation that asks the endpoints for GITHUB_TOKEN gets a 404 on main and the value on the PR.
Raw output, Before (main @ 36b22be)
# git: 36b22be7da scenario=plain
$ curl http://127.0.0.1:18111/api/v1/sandboxes/sbx1/settings/secrets
{"secrets":[{"name":"github_token","description":"github_token provider token"}]}
$ curl http://127.0.0.1:18111/api/v1/sandboxes/sbx1/settings/secrets/GITHUB_TOKEN
{"detail":"Secret not found"} [HTTP 404]
$ curl http://127.0.0.1:18111/api/v1/sandboxes/sbx1/settings/secrets/github_token
FAKE-gh-provider-token [HTTP 200]
# git: 36b22be7da scenario=override
$ curl http://127.0.0.1:18112/api/v1/sandboxes/sbx1/settings/secrets
{"secrets":[{"name":"GITHUB_TOKEN","description":null},{"name":"github_token","description":"github_token provider token"}]}
$ curl http://127.0.0.1:18112/api/v1/sandboxes/sbx1/settings/secrets/GITHUB_TOKEN
FAKE-custom-override-pat [HTTP 200]
$ curl http://127.0.0.1:18112/api/v1/sandboxes/sbx1/settings/secrets/github_token
FAKE-gh-provider-token [HTTP 200]
# git: 36b22be7da scenario=multi
$ curl http://127.0.0.1:18113/api/v1/sandboxes/sbx1/settings/secrets
{"secrets":[{"name":"github_token","description":"github_token provider token"},{"name":"gitlab_token","description":"gitlab_token provider token"},{"name":"azure_devops_token","description":"azure_devops_token provider token"}]}
$ curl http://127.0.0.1:18113/api/v1/sandboxes/sbx1/settings/secrets/GITHUB_TOKEN
{"detail":"Secret not found"} [HTTP 404]
$ curl http://127.0.0.1:18113/api/v1/sandboxes/sbx1/settings/secrets/github_token
FAKE-gh-provider-token [HTTP 200]
$ curl http://127.0.0.1:18113/api/v1/sandboxes/sbx1/settings/secrets/GITLAB_TOKEN
{"detail":"Secret not found"} [HTTP 404]
$ curl http://127.0.0.1:18113/api/v1/sandboxes/sbx1/settings/secrets/AZURE_DEVOPS_TOKEN
{"detail":"Secret not found"} [HTTP 404]
Raw output, After (PR @ 0e902e4)
# git: 0e902e4733 scenario=plain
$ curl http://127.0.0.1:18121/api/v1/sandboxes/sbx1/settings/secrets
{"secrets":[{"name":"GITHUB_TOKEN","description":"GITHUB_TOKEN provider token"}]}
$ curl http://127.0.0.1:18121/api/v1/sandboxes/sbx1/settings/secrets/GITHUB_TOKEN
FAKE-gh-provider-token [HTTP 200]
$ curl http://127.0.0.1:18121/api/v1/sandboxes/sbx1/settings/secrets/github_token
FAKE-gh-provider-token [HTTP 200]
# git: 0e902e4733 scenario=override
$ curl http://127.0.0.1:18122/api/v1/sandboxes/sbx1/settings/secrets
{"secrets":[{"name":"GITHUB_TOKEN","description":null}]}
$ curl http://127.0.0.1:18122/api/v1/sandboxes/sbx1/settings/secrets/GITHUB_TOKEN
FAKE-custom-override-pat [HTTP 200]
$ curl http://127.0.0.1:18122/api/v1/sandboxes/sbx1/settings/secrets/github_token
FAKE-gh-provider-token [HTTP 200]
# git: 0e902e4733 scenario=multi
$ curl http://127.0.0.1:18123/api/v1/sandboxes/sbx1/settings/secrets
{"secrets":[{"name":"GITHUB_TOKEN","description":"GITHUB_TOKEN provider token"},{"name":"GITLAB_TOKEN","description":"GITLAB_TOKEN provider token"},{"name":"AZURE_DEVOPS_TOKEN","description":"AZURE_DEVOPS_TOKEN provider token"}]}
$ curl http://127.0.0.1:18123/api/v1/sandboxes/sbx1/settings/secrets/GITHUB_TOKEN
FAKE-gh-provider-token [HTTP 200]
$ curl http://127.0.0.1:18123/api/v1/sandboxes/sbx1/settings/secrets/github_token
FAKE-gh-provider-token [HTTP 200]
$ curl http://127.0.0.1:18123/api/v1/sandboxes/sbx1/settings/secrets/GITLAB_TOKEN
FAKE-gl-token [HTTP 200]
$ curl http://127.0.0.1:18123/api/v1/sandboxes/sbx1/settings/secrets/AZURE_DEVOPS_TOKEN
FAKE-ado-token [HTTP 200]
Harness: /tmp/harness/serve.py (same file used for both runs)
"""Serve the real sandbox_router routes over HTTP with only auth stubbed.
Stubbed: session-key -> sandbox lookup, and the user_auth object (fake tokens).
Real: router, AuthUserContext, ProviderHandler.get_provider_env_key, FastAPI/uvicorn.
SCENARIO=plain -> user has a fake GitHub provider token only
SCENARIO=override -> user also has a custom secret named GITHUB_TOKEN
SCENARIO=multi -> GitHub + GitLab + Azure DevOps fake provider tokens
"""
import os
from unittest.mock import AsyncMock
import uvicorn
from fastapi import FastAPI, HTTPException
from pydantic import SecretStr
from openhands.app_server.integrations.provider import CustomSecret, ProviderToken
from openhands.app_server.integrations.service_types import ProviderType
from openhands.app_server.sandbox import sandbox_router
from openhands.app_server.sandbox.sandbox_models import SandboxInfo, SandboxStatus
from openhands.app_server.secrets.secrets_models import Secrets
scenario = os.environ['SCENARIO']
custom = {}
tokens = {ProviderType.GITHUB: ProviderToken(token=SecretStr('FAKE-gh-provider-token'))}
if scenario == 'override':
custom = {'GITHUB_TOKEN': CustomSecret(secret=SecretStr('FAKE-custom-override-pat'))}
if scenario == 'multi':
tokens[ProviderType.GITLAB] = ProviderToken(token=SecretStr('FAKE-gl-token'))
tokens[ProviderType.AZURE_DEVOPS] = ProviderToken(token=SecretStr('FAKE-ado-token'))
user_auth = AsyncMock()
user_auth.get_secrets = AsyncMock(return_value=Secrets(custom_secrets=custom))
user_auth.get_provider_tokens = AsyncMock(return_value=tokens)
SANDBOX = SandboxInfo(
id='sbx1',
created_by_user_id='user-1',
sandbox_spec_id='spec',
status=SandboxStatus.RUNNING,
session_api_key='FAKE-session-key',
)
async def fake_validate_session_key(key):
if key != 'FAKE-session-key':
raise HTTPException(401, 'bad session key')
return SANDBOX
async def fake_user_auth(_arg):
return user_auth
sandbox_router.validate_session_key = fake_validate_session_key
for attr in ('get_user_auth_for_user', 'get_user_auth_for_sandbox'):
if hasattr(sandbox_router, attr):
setattr(sandbox_router, attr, fake_user_auth)
app = FastAPI()
app.include_router(sandbox_router.router, prefix='/api/v1')
if __name__ == '__main__':
uvicorn.run(app, host='127.0.0.1', port=int(os.environ['PORT']), log_level='warning')Run as SCENARIO=<plain|override|multi> PORT=<n> PYTHONPATH=<checkout>:/tmp/harness <checkout>/.venv/bin/python serve.py, then curl -H 'X-Session-API-Key: FAKE-session-key' http://127.0.0.1:<n>/api/v1/sandboxes/sbx1/settings/secrets[/<name>].
Limits
- Verified: the two sandbox secrets endpoints (names, values, legacy lowercase lookup, override listed once) over real HTTP, for GitHub, GitLab and Azure DevOps.
- Not exercised: the conversation-start path (
live_status_app_conversation_service, which also switched toget_provider_env_key); a real sandbox/automation run reading$GITHUB_TOKEN; the SDK change in software-agent-sdk#5730; a real user store, Keycloak or refreshed Azure DevOps/Bitbucket DC tokens (the user auth is stubbed). Theghcr.io/openhands/enterprise-server:sha-0e902e4image was not pulled. - Not run: the PR's own unit tests (they need the Docker-backed Postgres fixtures). This test is separate from them.
- Heads-up (not part of the test): the PR branch is 291 commits behind
mainand GitHub reports it asCONFLICTING/DIRTY.mainhas since changedsandbox_router._get_user_context(it now callsget_user_auth_for_sandbox). Themainbaseline above still has the bug in the same endpoint code, but this test did not check that the PR's change applies cleanly on currentmain; it needs a rebase.
Verdict: Reproduced and fixed (for the sandbox secrets endpoints; conversation-start path and the end-to-end automation flow not tested)
This manual test was run by an AI agent (OpenHands) on behalf of @jpshackelford.
The sandbox secrets endpoints named provider tokens github_token while conversations receive GITHUB_TOKEN. The value endpoint still resolves the lowercase name for SDK releases that request it. Fixes #750 Co-authored-by: openhands <openhands@all-hands.dev>
0e902e4 to
05bbcf2
Compare
Review posted for
|
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
I found no material issues. The change does what #750 asks for:
get_provider_env_key()now returnsf'{provider.name}_TOKEN'. For everyProviderTypethis is the same string the conversation builder already built inline, so the change inlive_status_app_conversation_service.pydoes not change behavior. The only other caller isAuthUserContext.get_provider_tokens(as_env_vars=True), and only the two sandbox secrets endpoints use that. No other enterprise code depends on the lowercase names.- The value endpoint maps the old name back with
key.lower(). Each enumname.lower()equals itsvalue, so all of the old names still resolve. That covers thePROVIDER_TOKEN_NAMESthatclone_reposrequests in the pinnedopenhands-sdk==1.59.0. Custom secrets are still checked first, so a user's owngithub_tokenorGITHUB_TOKENsecret still wins. - The list endpoint now skips a provider token when a custom secret has the same name. This matches the precedence in the value endpoint and stops the token from being listed twice.
Verification: all checks on this head pass. Locally, tests/unit/app_server/test_sandbox_secrets_router.py, tests/unit/integrations/test_provider_immutability.py and tests/unit/app_server/test_live_status_app_conversation_service.py gave 424 passed and 1 skipped, using the Docker-backed Postgres fixtures. The author's manual HTTP test was run on an earlier head (0e902e4), which can no longer be fetched, so it was not re-checked against this head. The unit tests above cover the same endpoint behavior.
As the PR notes say, the list endpoint no longer returns the lowercase name. Any automation that started using ${github_token} as a workaround (as in the #750 reproduction) will need to switch to ${GITHUB_TOKEN} once this ships.
✅ APPROVED
|
🚀 Released in 1.87.0. |
…actory (#1392) Adds worklogs: named, append-only logs scoped to a factory, so orchestration state that lived in a committed WORKLOG.md has a proper home in Enterprise, which owns organizations, roles and licensing. Factories live in the automation service, so `worklogs.factory_id` is a plain UUID with no foreign key. - Data: migration 221 adds `worklogs` and `worklog_entries`. Slug and name are unique per factory, one default worklog per factory, and entries have no update or delete route. - People API (`/api/organizations/{org_id}/factories/{factory_id}/...`): worklog CRUD, entry append and list with cursor paging, and org-wide summaries. Read needs VIEW_AUTOMATIONS, writes need MANAGE_AUTOMATIONS. - Run API (`/api/service/worklog/...`): the same entry routes, authorized only by a factory run token (HS256, key derived from AUTOMATIONS_SERVICE_KEY via HKDF), so a session or API key is rejected. - Entries: markdown or JSON bodies, validated and size-limited (64 KiB). Author and provenance (ui, api_key, service_account, automation) are set by the server and cannot be supplied by the caller. - Default worklog is created on first access after confirming the factory exists in the automation service. - Gated by the new `worklogs` license feature and rate limited per org and factory. - Cleanup: a factory-deleted service route and `WorklogOrphanPurgeProcessor` (run from maintenance tasks) remove worklogs of deleted factories, and user deletion nulls `author_id` on their entries. Rollout: ship the automation service changes (OpenHands/automation#751, #752) first, since they mint the run token and serve the factory lookup this relies on. Fixes #1297 Co-authored-by: openhands <openhands@all-hands.dev>
HUMAN:
AGENT:
Why
Conversations started by the app server receive the connected git provider's token as
GITHUB_TOKEN. The sandbox secrets endpoints (/api/v1/sandboxes/{id}/settings/secrets) named the same tokengithub_token. Automations load their secrets from those endpoints, so an automation's agent had no$GITHUB_TOKEN, and a private plugin source written ashttps://x-access-token:${GITHUB_TOKEN}@github.com/...failed to clone.Summary
ProviderHandler.get_provider_env_key()returnsGITHUB_TOKEN,GITLAB_TOKEN,AZURE_DEVOPS_TOKEN, etc. Both places that build conversation secrets now call it, so the name is defined once.github_tokenwhen cloning repos.Issue Number
Fixes #750
How to Test
Run
uv run pytest tests/unit/app_server/test_sandbox_secrets_router.py tests/unit/integrations/test_provider_immutability.py.TestProviderTokenNamesdrives the real endpoints throughAuthUserContext, stubbing only user auth. It covers the uppercase name in both endpoints, the lowercase name in the value endpoint, and a single listing when a custom secret overrides the provider token. #750 describes the reproduction on a staging deployment.Video/Screenshots
None.
Type
Notes
The matching SDK change is OpenHands/software-agent-sdk#5730. The lowercase lookup can be removed once SDK releases without it are no longer in use. After this ships, an automation's agent sees
$GITHUB_TOKENrather than$github_token.This PR was drafted by an AI agent (OpenHands) on behalf of @jpshackelford.
Enterprise server image for this PR: