Skip to content

fix: name provider tokens GITHUB_TOKEN in sandbox secrets endpoints - #752

Merged
jpshackelford merged 1 commit into
mainfrom
fix/provider-token-env-var-names
Nov 5, 2026
Merged

jpshackelford merged 1 commit into
mainfrom
fix/provider-token-env-var-names

Conversation

@jpshackelford

@jpshackelford jpshackelford commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

  • A human has tested these changes.

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 token github_token. Automations load their secrets from those endpoints, so an automation's agent had no $GITHUB_TOKEN, and a private plugin source written as https://x-access-token:${GITHUB_TOKEN}@github.com/... failed to clone.

Summary

  • ProviderHandler.get_provider_env_key() returns GITHUB_TOKEN, GITLAB_TOKEN, AZURE_DEVOPS_TOKEN, etc. Both places that build conversation secrets now call it, so the name is defined once.
  • The value endpoint still resolves the old lowercase name, because released SDKs request github_token when cloning repos.
  • A custom secret that overrides a provider token now has the same name, so the list endpoint returns that name once rather than twice.

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. TestProviderTokenNames drives the real endpoints through AuthUserContext, 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

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

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_TOKEN rather than $github_token.


This PR was drafted by an AI agent (OpenHands) on behalf of @jpshackelford.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-05bbcf2

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/app_conversation
  live_status_app_conversation_service.py
  openhands/app_server/integrations
  provider.py
  openhands/app_server/sandbox
  sandbox_router.py
Project Total  

This report was generated by python-coverage-comment-action

@jpshackelford

Copy link
Copy Markdown
Member Author

Manual test: sandbox secrets endpoints name provider tokens GITHUB_TOKEN

Tested PR head: 0e902e4733 (branch fix/provider-token-env-var-names, head unchanged since the request). Baseline: main @ 36b22be7da.
Both ran in a fresh uv sync --all-groups venv per checkout.

How it was run

The real sandbox_router FastAPI routes (/api/v1/sandboxes/{id}/settings/secrets[/{name}]), the real AuthUserContext, and the real ProviderHandler.get_provider_env_key were served with uvicorn on localhost and called with curl and an X-Session-API-Key header. Only two things were stubbed: the session-key-to-sandbox lookup and the user_auth object, which returns fake tokens (FAKE-...). Nothing touched beta, staging or prod, and no real tokens were used. The same harness file (see below) ran against both checkouts. It has three scenarios: GitHub provider token only (plain), a custom secret named GITHUB_TOKEN on top of the provider token (override), and GitHub + GitLab + Azure DevOps provider tokens (multi).

Before vs After (key results)

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 to get_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). The ghcr.io/openhands/enterprise-server:sha-0e902e4 image 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 main and GitHub reports it as CONFLICTING/DIRTY. main has since changed sandbox_router._get_user_context (it now calls get_user_auth_for_sandbox). The main baseline above still has the bug in the same endpoint code, but this test did not check that the PR's change applies cleanly on current main; 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>
@jpshackelford
jpshackelford force-pushed the fix/provider-token-env-var-names branch from 0e902e4 to 05bbcf2 Compare November 5, 2026 14:38
@jpshackelford
jpshackelford marked this pull request as ready for review November 5, 2026 14:38
@all-hands-bot

all-hands-bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Review posted for 05bbcf24b9a6

Verdict: ✅ APPROVED. See the review.

This is an automated status.

@jpshackelford
jpshackelford requested review from all-hands-bot and removed request for all-hands-bot November 5, 2026 15:19

@all-hands-bot all-hands-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 returns f'{provider.name}_TOKEN'. For every ProviderType this is the same string the conversation builder already built inline, so the change in live_status_app_conversation_service.py does not change behavior. The only other caller is AuthUserContext.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 enum name.lower() equals its value, so all of the old names still resolve. That covers the PROVIDER_TOKEN_NAMES that clone_repos requests in the pinned openhands-sdk==1.59.0. Custom secrets are still checked first, so a user's own github_token or GITHUB_TOKEN secret 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

@jpshackelford
jpshackelford merged commit f83b2dd into main Nov 5, 2026
23 checks passed
@jpshackelford
jpshackelford deleted the fix/provider-token-env-var-names branch November 5, 2026 15:31
@openhands-release-bot openhands-release-bot Bot added the released: 1.87.0 Shipped in 1.87.0 label Nov 5, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.87.0.

jpshackelford added a commit that referenced this pull request Nov 23, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working released: 1.87.0 Shipped in 1.87.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sandbox secrets endpoint names provider tokens github_token instead of GITHUB_TOKEN

3 participants