Repository navigation
Description
Summary
Add a service route that lets the automations service get short-lived lookup references for a member's Git provider tokens and custom secrets. The route never returns secret values. The service passes the references as SDK LookupSecrets. The value is resolved only when a plugin is fetched, through the existing GET /api/v1/webhooks/secrets.
This is the cloud prerequisite for OpenHands/automation#694 (plugin-spec automations from a private repository). The local Agent Canvas side of #694 needs no enterprise change.
Why
A plugin-spec automation can point at a private repository, for example https://x-access-token:${GITHUB_TOKEN}@github.com/acme/plugins.git. To fetch it, the automations service must resolve ${GITHUB_TOKEN} for the automation's run-as principal at three points:
- On create and on PATCH. The service clones the plugin to read its manifest, validate
configagainstconfig_schema, and render the trigger. No sandbox exists. - Before each run. The service checks the plugin again before it creates the sandbox.
- In the sandbox. The service asks the agent server to fetch the plugin (
POST /api/plugins/fetch). That request acceptssecrets: dict[str, SecretSource].
At points 1 and 2 the service holds only an API key or the shared service key. It cannot get the token today.
How secrets reach code today (enterprise 91b5f70)
- Conversations get Git tokens as
LookupSecrets. The app server signs a JWS with audienceSECRET_LOOKUPthat namesuser_idand eitherprovider_typeoroauth_provider_id(_get_provider_token_secrets,_lookup_secret). The sandbox trades the JWS atGET /api/v1/webhooks/secretsfor the current token. That trade refreshes the token when necessary. Tokens are valid foraccess_token_hard_timeout, which is 14 days by default.- Secret names:
<PROVIDER_TYPE>_TOKEN(GITHUB_TOKEN,GITLAB_TOKEN,BITBUCKET_TOKEN,BITBUCKET_DATA_CENTER_TOKEN,FORGEJO_TOKEN,AZURE_DEVOPS_TOKEN). With OAuth v2, a linked provider uses itsnamed_secretinstead. - Custom secrets are sent as
StaticSecretvalues. - On a name collision, the provider or OAuth secret wins (L2125-L2128).
- Secret names:
- Sandbox secrets endpoints (
/api/v1/sandboxes/{id}/settings/secrets/{name}) need the sandbox's session key. They check custom secrets first, then provider tokens under lowercase names (Sandbox secrets endpoint names provider tokens github_token instead of GITHUB_TOKEN #750, PR fix: name provider tokens GITHUB_TOKEN in sandbox secrets endpoints #752). - Service routes for the automations service authenticate with
X-Service-API-Keyand takeuser_idandorg_idin the path (api-keys,membership).
Gaps
- No lookup reference without a sandbox. Only the app server signs
SECRET_LOOKUPtokens, and only while it builds a conversation. The sandbox endpoint needs a sandbox. - The lookup handler uses the wrong org.
/api/v1/webhooks/secretsbuilds the user context withget_for_user(user_id). The secrets store then falls back touser.current_org_id(saas_secrets_store.py#L47). Provider tokens are stored per user, so this is correct for them. It is not correct for custom secrets: an automation runs in its own org, and a member of several orgs can have a different current org. - The lookup handler cannot return a custom secret. It resolves only
provider_typeandoauth_provider_id. Service accounts have no Git provider connection, so for them a custom secret (for example a PAT) is the only credential.
Proposed design
1. New service route
POST /api/service/users/{user_id}/orgs/{org_id}/secret-lookups
X-Service-API-Key: <AUTOMATIONS_SERVICE_KEY>
Request:
{
"names": ["GITHUB_TOKEN", "PLUGINS_PAT"],
"ttl_seconds": 900,
"purpose": "plugin_source",
"automation_id": "6f1c…"
}names: required. 1 to 20 entries. Each entry uses the existing secret-name format.ttl_seconds: optional. Default 900. Maximum 3600.purposeandautomation_id: optional. They are for the audit log only.
Response 200:
{
"lookup_url": "https://app.example.com/api/v1/webhooks/secrets",
"lookup_path": "/api/v1/webhooks/secrets",
"expires_at": "2026-11-05T06:15:00Z",
"secrets": {
"GITHUB_TOKEN": {"kind": "provider", "provider": "github", "headers": {"X-Access-Token": "<jws>"}},
"PLUGINS_PAT": {"kind": "custom", "headers": {"X-Access-Token": "<jws>"}}
},
"missing": []
}Rules:
- Access check. Do the same user and membership check as the
membershiproute. The user must exist and be active, the user must be a member of{org_id}, and the membership must be active. Human members and service accounts are both allowed. Return404when the user is not a member, and401or503for service-key problems, as themembershiproute does. - No values. The response never contains a secret value.
- One token per name. Each name gets its own JWS. A token resolves exactly one secret.
- Resolve names the way a conversation launch would. A name must mean what it means in a conversation of this principal in
{org_id}:- The
named_secretof a linked OAuth v2 provider resolves tooauth_provider_id. <PROVIDER_TYPE>_TOKENresolves toprovider_typefor a connected provider type with no named OAuth secret. Also accept the lowercase alias<provider>_tokenuntil Sandbox secrets endpoint names provider tokens github_token instead of GITHUB_TOKEN #750 is closed.- Any other name resolves to a custom secret: personal or org-shared in
{org_id}, asSaasSecretsStore.loadmerges them for that org. - On a collision, use the conversation-launch precedence: the provider or OAuth secret wins.
- Do not resolve the system-managed
OPENHANDS_API_KEY.
- The
missing. List the names that resolve to nothing inmissingand do not sign a token for them. The automations service then reportsmissing_secretat create time and never reads a value.- Lookup URL. Build
lookup_urlfromweb_url, as_secret_lookup_urldoes. Sandboxes use this URL. When_secret_lookup_urlwould returnNone, return503with a clear detail. Do not fall back to static values. Also returnlookup_path, so the automations service can resolve inside the cluster through its configured API base URL.
2. Token claims and the lookup handler
Sign each JWS with audience SECRET_LOOKUP and these claims:
user_idorg_id- exactly one of
provider_type,oauth_provider_idorsecret_name expset fromttl_seconds
Change GET /api/v1/webhooks/secrets as follows:
org_idpresent: callset_effective_org_id_override(org_id)on the resolved user auth before it reads any secret. The override checks membership, so a principal who has since left the org gets403.secret_namepresent: return that custom secret from the org's merged view, or404.- Tokens without
org_idorsecret_name(all tokens that conversations sign today) work exactly as now. - Audit log: log each resolution with
user_id,org_id, kind and name. Never log the value.
Security considerations
- No new privilege. Only the shared service key can call the route. That key can already mint an API key for any member (
/api/service/users/{user_id}/orgs/{org_id}/api-keys). Do not expose the route to user API keys. A user API key that could get a lookup token could read raw Git tokens directly. - Narrow tokens. A token names one secret and one org and lasts 15 minutes by default. Conversation tokens last 14 days.
- Values stay out of the service's storage. The automations service stores only plugin sources without credentials. It sends the references in
secrets, and the SDK masks resolved values in its errors.
Acceptance criteria
- The route returns lookup references for
<PROVIDER_TYPE>_TOKEN, named OAuth secrets, and personal and org-shared custom secrets of{org_id}. Any other name is listed inmissing. - The route works for a human member and for a service account. It returns
404for a non-member and for an inactive membership. - A token signed for org A returns org A's custom secret, even when the user's
current_org_idis org B. - A
secret_nametoken returns404after the secret is deleted. It returns403after the principal leaves the org. It returns401afterexp. - Existing conversation tokens resolve exactly as before.
tests/unit/app_server/test_webhook_router_secrets.pypasses without change. - No response body or log line from the route or the handler contains a secret value.
- A test signs a reference, passes it as an SDK
LookupSecrettopreflight_pluginagainst a private repository, and the clone succeeds.
Out of scope (follow-ups)
- Credential selection from the source host. Match a plugin URL's host to a connected provider without a
${NAME}placeholder, using the marketplace logic (authenticate_marketplace_sources). This also covers providers whose git username a placeholder cannot express:- Bitbucket Cloud
email:tokenvalues - Bitbucket Data Center, where the username depends on the token and the server version (
get_git_credentials)
- Bitbucket Cloud
- Azure DevOps Entra tokens. They need an
Authorizationheader. SDK strict fetch cannot send one.
Open questions
- Precedence. The conversation launch lets a provider secret win over a custom secret of the same name. The sandbox endpoint does the opposite. This route follows the conversation launch. Should the sandbox endpoint change to match, as part of fix: name provider tokens GITHUB_TOKEN in sandbox secrets endpoints #752?
- Org-scoped agent profiles (OHE-3088). A conversation that uses an org-scoped agent profile with explicit
secret_refssees only org-shared secrets. Should a plugin fetch for an automation that uses such a profile get the same restriction? The proposal does not apply it, because the value goes to the plugin fetch, not to the agent. - TTL. The default is 900 seconds. Is that correct for slow clones of large plugin repositories?
References
- [Feature]: Plugin-spec automations from a private repository automation#694 (Linear OSS-15139): the automation side; it depends on this issue.
- Sandbox secrets endpoint names provider tokens github_token instead of GITHUB_TOKEN #750 and PR fix: name provider tokens GITHUB_TOKEN in sandbox secrets endpoints #752: the lowercase provider-token names in the sandbox endpoints.
- feat(plugin): add strict plugin fetch preflight software-agent-sdk#5987: strict
preflight_pluginand thesecretsfield ofPOST /api/plugins/fetch. - feat: let automation run as a service account automation#655: automations that run as a service account.
This issue was created by an AI agent (OpenHands) on behalf of @jpshackelford.
Activity