Repository navigation
feat(automations): short-lived secret lookup references for the automations service - #1205
Conversation
Review posted for
|
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
I found no material issues on 0828f1d1b135.
I checked the areas the PR Notes ask about, plus name precedence:
- Service key only.
create_secret_lookupsusesvalidate_service_api_key, the same check as the other/api/serviceroutes. No user-auth dependency can reach the route. Its entry in the service-account guard allowlist matches the existingapi-keysroutes. - Membership at signing. The route requires an existing user who is not disabled and not pending deletion, and an
activemembership (_membership_status). It does not provision a missing user. After that,user_auth_for_orgsets the org override and resolves it before it reads anything. A suspended org therefore also fails at signing. - Membership at resolution.
_resolve_org_user_contextresolves the override before it reads a secret._resolve_and_verify_override_orgreturns 403 when the membership row is gone.assert_org_usable_for_productreturns 403 for an inactive membership or a suspended org, andget_for_usergives 403 for a disabled user. Inactive memberships are only set through the Super Admin directory, and that same flag gates the check, so the lookup handler applies the same gates as sandbox credential binding. - Org scoping. Custom secrets come from
SaasSecretsStorewitheffective_org_idtaken from the override, never fromcurrent_org_id. Provider and OAuth tokens are stored per user, and the org claim only adds the membership check. - Claims and TTL. Each reference is HS256 with
aud=SECRET_LOOKUPand exactly one target claim; the handler rejects 0 or 2+ targets with 401. TTL is limited to 1 to 3600 s.accept_unscopedstill requiresprovider_typeoroauth_provider_id, so asecret_namereference without an audience is rejected. Asecret_namereference withoutorg_idis also rejected.OPENHANDS_API_KEYis excluded both at signing and at resolution. - Precedence. OAuth named secret, then
<TYPE>_TOKEN(skipped for OAuth-linked types), then custom. This matches_get_provider_token_secretsand_setup_secrets_for_git_providers. Legacy tokens withoutorg_idtake the old path unchanged.
Verification on this head (local PostgreSQL via testcontainers):
uv run pytest tests/unit/server/routes/test_secret_lookups.py tests/unit/server/routes/test_service_account_guard.py: 76 passed. This includes the SDKpreflight_pluginclone against the private git server.uv run pytest tests/unit/app_server/test_webhook_router_secrets.py tests/unit/routes/test_service.py tests/unit/app_server/test_sandbox_org_secret_binding.py tests/unit/app_server/test_live_status_app_conversation_service.py tests/unit/app_server/test_webhook_router_auth.py: 496 passed, 1 skipped.- Every GitHub Actions check on this head passed or was skipped.
The PR Notes ask for a human security review because this route issues credentials. This approval covers the code review only and does not replace that review. The live check on a test install is still listed as pending in the PR body.
✅ APPROVED
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
My earlier review of 0828f1d1b135 had no findings and opened no threads, so nothing carries over. This review covers only what changed in 7a7a7b2fa03b. I found no new material issues.
- Redemption check (
is_active_org_member)._resolve_org_user_contextnow checks the signing-time rule before it builds the user auth: the user exists, is not disabled or being deleted, and hasstatus in (None, 'active'). This no longer depends onENABLE_SUPER_ADMINand has no super-admin bypass. An invited or unknown status is denied, the same as the route's_membership_status. The route now calls the same helper, so signing and redemption cannot drift apart. The override check still runs afterwards and keeps the suspended-org gate. - Org-bound references need an audience and
exp._is_unscoped_secret_lookup_tokennow excludesorg_idandsecret_name, so the legacy no-audpath cannot reach_get_org_secret._is_scoped_org_referencerequiresaudto be exactly theSECRET_LOOKUPstring, which rejects audience lists. It also requires a numericexp, because PyJWT does not requireexpby default. Tokens withoutorg_idtake the unchanged path. - Lowercase alias. A custom secret named exactly
<provider>_tokennow wins over the provider token. This matches a conversation launch, which exposes the provider token only as<PROVIDER_TYPE>_TOKENand keeps custom secrets under their own names.<PROVIDER_TYPE>_TOKENand OAuth named secrets still win collisions as before.
Verification on this head (local PostgreSQL via testcontainers):
uv run pytest tests/unit/server/routes/test_secret_lookups.py tests/unit/server/routes/test_service_account_guard.py: 98 passed.- The five related suites from the PR body (
test_webhook_router_secrets.py,test_service.py,test_sandbox_org_secret_binding.py,test_live_status_app_conversation_service.py,test_webhook_router_auth.py): 496 passed, 1 skipped. - The GitHub Actions lint, test shards, image builds and budget checks on this head have passed. Only the coverage-comment and label jobs were still queued.
As the PR Notes ask, a human still needs to do the security review of this credential-issuing route. This approval does not replace it. The live OHE check in the PR body ran on 0828f1d1, before these redemption and naming changes.
✅ APPROVED
LLM profile: all-hands-bot-reviewer_claude-opus-5-5 · Model: openhands/claude-opus-5-5
|
🚀 Released in 1.87.0. |
Why
The automations service needs to fetch a plugin from a private repository as the user or service account an automation runs as (OpenHands/automation#694). It has to do this when an automation is created or edited and before each run, when no sandbox exists yet. Until now only a conversation launch could hand out a reference to a member's git token, and no reference could name a custom secret or an organization.
Summary
POST /api/service/users/{user_id}/orgs/{org_id}/secret-lookups(service key only). It takes 1 to 20 secret names and returns one short-lived reference per name that resolves: a JWS with audienceSECRET_LOOKUPthat namesuser_id,org_idand exactly one ofprovider_type,oauth_provider_idorsecret_name. TTL is 900 s by default and 3600 s at most. The response never contains a value.<PROVIDER_TYPE>_TOKENfor a connected provider, then the org's personal and org-shared custom secrets. A provider or OAuth secret wins a name collision, as at conversation launch. The lowercase<provider>_tokenthat the sandbox secrets endpoint uses also names the provider token, unless a custom secret has exactly that name: a conversation keeps such a secret under its own name, so it wins here too.OPENHANDS_API_KEYis never handed out. Names that resolve to nothing are listed inmissing.membershiproute reports them. A missing user is not provisioned. Service-key errors are 401 and 503, as on the other service routes.lookup_urlis the URL conversations give sandboxes. When there is none (no web URL, or localhost with remote sandboxes) the route returns 503.GET /api/v1/webhooks/secretsresolves the new references.org_idmust carry theSECRET_LOOKUPaudience and an expiry; tokens minted before audiences are not accepted for it.ENABLE_SUPER_ADMIN. Anyone else gets 403 before anything is read.secret_name, it returns that custom secret from the org's merged view, or 404.org_id(all tokens conversations sign today) work exactly as before.secret_lookup_url()is shared with the conversation service, so both build the sandbox lookup URL the same way.Issue Number
Fixes #1202. Related: OpenHands/automation#694, Linear OSS-15139.
How to Test
uv run pytest tests/unit/server/routes/test_secret_lookups.py(62 passed). These are new tests on real PostgreSQL rows. They cover every acceptance bullet:missinglist;exp;ENABLE_SUPER_ADMINoff and on, and for an instance super admin;github_tokenwith GitHub connected resolves to the custom secret, whileGITHUB_TOKENstill resolves to the provider token;An end-to-end test signs a reference, passes it as an SDK
LookupSecrettopreflight_pluginagainst a private git server served over HTTP, and the clone succeeds. With a rotated secret it fails asauth_failed, with no value in the error.uv run pytest tests/unit/app_server/test_webhook_router_secrets.py tests/unit/routes/test_service.py tests/unit/app_server/test_sandbox_org_secret_binding.py tests/unit/app_server/test_live_status_app_conversation_service.py tests/unit/app_server/test_webhook_router_auth.py(496 passed, 1 skipped).test_webhook_router_secrets.pyis unchanged.The new route is in the service-account guard's allowlist, like the other service-key routes (
tests/unit/server/routes/test_service_account_guard.pypasses).Live check on an OHE test install (enterprise 1.85.0, DB 212, agent server 1.59.0), with this PR's image at
0828f1d1(before the redemption and naming checks above) on every enterprise-server container and feat: plugin-spec automations from private repositories automation#696's image:purposeplugin_source,missingempty) for a Bitbucket Data Center provider token, a GitLab provider token and two custom secrets.lookup_url.service:secret_lookups_signed,webhooks:secret_lookup) carry names, kinds andfoundonly. No token value, raw or percent-encoded, appears in the app-server or automation logs.Live re-check on the same install with this PR's image at
7a7a7b2fand automation main85343cbc(agent server 1.59.0). Service accounts were turned on for this check only, then turned off again.gitlab_tokenresolved to the custom value, whileGITLAB_TOKENresolved to the provider token.Screenshots from the test install (hosts and identities masked):
Run 1 of the conversation-runner automation: the private plugin's command ran in a conversation the app server started.
The same automation after its secret was deleted: the next run failed with "Missing secret: RS226P_PLUGIN_TOKEN".
The service account's automation after its membership was set to inactive: the run failed and the automation is paused.
The script runner with the user's GitLab OAuth token: the run succeeded.
Type
Notes
This adds a credential-issuing route, so it needs a human security review before it merges. Authorization is checked at the start of each redemption, and revocation takes effect for the next request. Please check:
No migration and no configuration change.
Enterprise server image for this PR: