Skip to content

Service route: short-lived lookup references for a member's Git tokens and custom secrets (automation private plugin sources) #1202

Closed

Description

@jpshackelford

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:

  1. On create and on PATCH. The service clones the plugin to read its manifest, validate config against config_schema, and render the trigger. No sandbox exists.
  2. Before each run. The service checks the plugin again before it creates the sandbox.
  3. In the sandbox. The service asks the agent server to fetch the plugin (POST /api/plugins/fetch). That request accepts secrets: 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)

Gaps

  1. No lookup reference without a sandbox. Only the app server signs SECRET_LOOKUP tokens, and only while it builds a conversation. The sandbox endpoint needs a sandbox.
  2. The lookup handler uses the wrong org. /api/v1/webhooks/secrets builds the user context with get_for_user(user_id). The secrets store then falls back to user.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.
  3. The lookup handler cannot return a custom secret. It resolves only provider_type and oauth_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.
  • purpose and automation_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 membership route. 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. Return 404 when the user is not a member, and 401 or 503 for service-key problems, as the membership route 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}:
    1. The named_secret of a linked OAuth v2 provider resolves to oauth_provider_id.
    2. <PROVIDER_TYPE>_TOKEN resolves to provider_type for a connected provider type with no named OAuth secret. Also accept the lowercase alias <provider>_token until Sandbox secrets endpoint names provider tokens github_token instead of GITHUB_TOKEN #750 is closed.
    3. Any other name resolves to a custom secret: personal or org-shared in {org_id}, as SaasSecretsStore.load merges them for that org.
    4. On a collision, use the conversation-launch precedence: the provider or OAuth secret wins.
    5. Do not resolve the system-managed OPENHANDS_API_KEY.
  • missing. List the names that resolve to nothing in missing and do not sign a token for them. The automations service then reports missing_secret at create time and never reads a value.
  • Lookup URL. Build lookup_url from web_url, as _secret_lookup_url does. Sandboxes use this URL. When _secret_lookup_url would return None, return 503 with a clear detail. Do not fall back to static values. Also return lookup_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_id
  • org_id
  • exactly one of provider_type, oauth_provider_id or secret_name
  • exp set from ttl_seconds

Change GET /api/v1/webhooks/secrets as follows:

  • org_id present: call set_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 gets 403.
  • secret_name present: return that custom secret from the org's merged view, or 404.
  • Tokens without org_id or secret_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 in missing.
  • The route works for a human member and for a service account. It returns 404 for 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_id is org B.
  • A secret_name token returns 404 after the secret is deleted. It returns 403 after the principal leaves the org. It returns 401 after exp.
  • Existing conversation tokens resolve exactly as before. tests/unit/app_server/test_webhook_router_secrets.py passes 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 LookupSecret to preflight_plugin against 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:token values
    • Bitbucket Data Center, where the username depends on the token and the server version (get_git_credentials)
  • Azure DevOps Entra tokens. They need an Authorization header. SDK strict fetch cannot send one.

Open questions

  1. 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?
  2. Org-scoped agent profiles (OHE-3088). A conversation that uses an org-scoped agent profile with explicit secret_refs sees 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.
  3. TTL. The default is 900 seconds. Is that correct for slow clones of large plugin repositories?

References

This issue was created by an AI agent (OpenHands) on behalf of @jpshackelford.

Activity

  1. added
    enhancement
    on Nov 5, 2026
  2. self-assigned this
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions