Skip to content

Support federated workload identity files in the Python SDK - #15

Open
muvaf wants to merge 9 commits into
mainfrom
codex/workload-federation
Open

muvaf wants to merge 9 commits into
mainfrom
codex/workload-federation

Conversation

@muvaf

@muvaf muvaf commented Nov 16, 2026 •

Copy link
Copy Markdown

CI jobs and external services can receive JWTs from their identity provider but previously needed a separate Limrun API key for SDK requests. The Python client accepts a workload identity file and binding_id selecting an administrator-defined permission binding. Default clients discover LIMRUN_WORKLOAD_IDENTITY_BINDING_ID and LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE. The client caches the exchanged access token, rereads the file on renewal, and shares refresh work across concurrent calls. Explicit API keys keep precedence.

Federation uses form-encoded requests at /v1/access_tokens; existing JSON issuance remains unchanged. The SDK guidance now distinguishes default instance control tokens from credentials used for lifecycle management. Control permits runtime operations and reading an instance, while create, update, and delete require corresponding grants on the configured client. Existing all permissions retain full access. See the permissions reference. Release after the federation endpoint and control-token verifiers are available.


Note

High Risk
Introduces a second authentication path on every SDK request and STS token exchange; misconfiguration or exchange bugs could break auth broadly, though API keys still take precedence when set.

Overview
Adds workload identity federation as an alternative to API keys: Limrun and AsyncLimrun accept JWT sources (workload_token, workload_token_file, or proxy injected mode via workload_token_injected) plus binding_id and optional LIMRUN_STS_BASE_URL, with matching environment variables. When no API key is configured, requests get a cached Bearer token from OAuth token exchange against STS /v1/access_tokens.

New _workload_identity module handles exchange, refresh, concurrency-safe caching, and sync/async callables. Client copy/with_options can switch identity sources while reusing the same exchange object when federation settings are unchanged. README documents setup (including K8s projected tokens and egress-proxy JWT injection) and clarifies instance control tokens vs lifecycle credentials.

Extensive tests cover rotation, concurrent refresh, precedence, validation, and failure behavior before any API call runs.

Reviewed by Cursor Bugbot for commit 06d1956. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread src/limrun_api/_client.py Resolved
Comment thread src/limrun_api/_client.py Resolved
@muvaf muvaf changed the title Support federated workload identity files in Python clients Support federated workload identity files in the Python SDK Nov 16, 2026
muvaf and others added 2 commits November 24, 2026 20:01
workload_token takes a JWT or a callable that returns the current one; the
async client also accepts an async callable. The callable runs for every
exchange, so long-lived clients renew with a fresh JWT.
LIMRUN_WORKLOAD_IDENTITY_TOKEN does the same from the environment. Explicit
options win over environment variables, and a token over a file. Matches the
TypeScript and Go SDKs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
workload_token_injected and LIMRUN_WORKLOAD_IDENTITY_TOKEN_INJECTED send the
federation exchange without subject_token, so a proxy can supply the JWT in the
X-Limrun-Subject-Token header for workloads that never see it. Matches the
TypeScript and Go SDKs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread src/limrun_api/_client.py Resolved
copy() and with_options() forwarded the current injected flag alongside any new
token or file, so switching sources raised the combination error, and enabling
injection could not drop a token or file. A source passed to copy() now
replaces the current one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 06d1956. Configure here.

) -> Tuple[Optional[_Token], Optional[str], bool]:
"""A source passed to copy() replaces the client's current one rather than combining with it."""
if token or token_file or injected:
return token, token_file, bool(injected)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy to injected restores env sources

Medium Severity

When with_options() switches a client to workload_token_injected, replace_identity clears the token and file by returning None. The copied client constructor treats those as unset and reloads LIMRUN_WORKLOAD_IDENTITY_TOKEN or LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE, so the switch raises a combined-source error whenever those environment variables are set.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 06d1956. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant