Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b4245ae
feat(workload-identity): Add workload identity federation credentials
gjtorikian Nov 12, 2026
8840a7b
feat(workload-identity): Add GitHub Actions, GCP and AWS identity tok…
gjtorikian Nov 12, 2026
860b2eb
ci(workload-identity): Release each identity token provider on its own
gjtorikian Nov 12, 2026
ecee1e9
docs(workload-identity): Document workload identity in the README
gjtorikian Nov 12, 2026
ca29dee
ci(workload-identity): Start provider releases at 0.1.0
gjtorikian Nov 12, 2026
a5db152
ci(workload-identity): Keep provider-only commits out of the SDK release
gjtorikian Nov 12, 2026
4a1bc71
ci(workload-identity): Bound the first provider release scan
gjtorikian Nov 12, 2026
450a9b0
test(workload-identity): Name the GCP proxy test for WIF-GCP-03
gjtorikian Nov 12, 2026
672620f
fix(workload-identity): Make environment ID optional and align error …
gjtorikian Nov 13, 2026
f0084ee
fix(workload-identity): Stop reading WORKOS_ENVIRONMENT_ID and correc…
gjtorikian Nov 14, 2026
e0e14c7
fix(workload-identity): Stop reading WORKOS_WIF_TOKEN_URL and WORKOS_…
gjtorikian Nov 14, 2026
ba6f1c4
fix(workload-identity): Require an https token URL
gjtorikian Nov 16, 2026
86910ff
fix(workload-identity): Say why the GCP metadata server could not be …
gjtorikian Nov 20, 2026
6ae85b7
fix(workload-identity): Say why an endpoint could not be reached
gjtorikian Nov 23, 2026
f3eca16
fix(workload-identity): Keep the GitHub Actions request token out of …
gjtorikian Nov 23, 2026
14383b2
fix(workload-identity): Use the shared text for a refused request token
gjtorikian Nov 23, 2026
51594ce
Merge remote-tracking branch 'origin/main' into feat/workload-identity
gjtorikian Nov 23, 2026
0e7b70a
fix(workload-identity): Refuse a call that needs an API key as its cl…
gjtorikian Nov 23, 2026
7efacdc
fix(workload-identity): Keep the GCP identity token out of errors for…
gjtorikian Nov 23, 2026
37db2a9
fix(workload-identity): Share one exchange between synchronous and as…
gjtorikian Nov 23, 2026
8de5545
fix(workload-identity): Run every token exchange on a thread of its own
gjtorikian Nov 23, 2026
1d5282d
fix(workload-identity): Keep the assertion out of the frames an error…
gjtorikian Nov 23, 2026
c2125ef
fix(workload-identity): Make one bounded STS request per AWS provider…
gjtorikian Nov 23, 2026
d383085
fix(workload-identity): Run the exchange in the context of the caller…
gjtorikian Nov 23, 2026
3f19c0c
test(workload-identity): Keep the test of a caller canceled right aft…
gjtorikian Nov 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,44 @@ jobs:
- name: Test
run: uv run pytest

# Each provider distribution is released on its own, so it is linted,
# type-checked and tested on its own: only its dependencies are installed.
packages:
name: ${{ matrix.package }} (Python ${{ matrix.python }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package:
- workos-workload-identity-github-actions
- workos-workload-identity-gcp
- workos-workload-identity-aws
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
defaults:
run:
working-directory: packages/${{ matrix.package }}
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
python-version: ${{ matrix.python }}
enable-cache: true

- name: Install dependencies
run: uv sync --locked

- name: Lint
run: uv run ruff check .

- name: Type check
run: uv run pyright

- name: Test
run: uv run pytest

- name: Build
run: uv build --out-dir dist

smoke-test:
name: Smoke test (Python ${{ matrix.python }})
if: "${{ github.event_name == 'pull_request' && contains(toJSON(github.event.pull_request.labels.*.name), 'autorelease: pending') }}"
Expand Down
108 changes: 102 additions & 6 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ jobs:
pull-requests: write
outputs:
pr: ${{ steps.release.outputs.pr }}
# Every release PR this run created or updated. The SDK and each provider
# distribution get their own (separate-pull-requests).
prs: ${{ steps.release.outputs.prs }}
# The unprefixed outputs are the root package's, i.e. the SDK's.
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
github_actions_release_created: ${{ steps.release.outputs['packages/workos-workload-identity-github-actions--release_created'] }}
gcp_release_created: ${{ steps.release.outputs['packages/workos-workload-identity-gcp--release_created'] }}
aws_release_created: ${{ steps.release.outputs['packages/workos-workload-identity-aws--release_created'] }}
steps:
- name: Generate token
id: generate-token
Expand All @@ -45,15 +52,20 @@ jobs:
with:
token: ${{ steps.generate-token.outputs.token }}

# While the release PR is open, enrich it before it merges. Runs as its
# own job (gated on the PR existing) so a failure here can never block the
# release or the PyPI publish that depends on release-please.
# While a release PR is open, enrich it before it merges. Runs as its
# own job (gated on a PR existing) so a failure here can never block the
# release or the PyPI publish that depends on release-please. One run per
# release PR: the SDK's and each provider distribution's.
enrich-release-pr:
needs: release-please
if: needs.release-please.outputs.pr
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
fail-fast: false
matrix:
pr: ${{ fromJSON(needs.release-please.outputs.prs) }}
steps:
- name: Generate token
id: generate-token
Expand All @@ -67,12 +79,14 @@ jobs:
- name: Checkout release PR branch
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
ref: ${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}
ref: ${{ matrix.pr.headBranchName }}
token: ${{ steps.generate-token.outputs.token }}

- name: Install uv
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2

# Every release PR needs this: the one uv.lock at the root records the
# version of the SDK and of each provider distribution.
- name: Update lockfile
run: |
uv lock
Expand All @@ -89,9 +103,13 @@ jobs:
# without a fragment (typical for human-authored PRs), keep what
# release-please wrote. Fragments are deleted in the same commit.
# Idempotent: if no fragments exist, skip silently.
# SDK release PR only. Fragments describe SDK changes and go into the
# root CHANGELOG.md; a provider's release PR is on a branch named
# ...--components--<distribution>.
- name: Inline rich changelog fragments
if: ${{ !contains(matrix.pr.headBranchName, '--components--') }}
env:
PR_JSON: ${{ needs.release-please.outputs.pr }}
PR_TITLE: ${{ matrix.pr.title }}
run: |
set -euo pipefail
shopt -s nullglob
Expand All @@ -101,7 +119,7 @@ jobs:
exit 0
fi

VERSION=$(echo "$PR_JSON" | jq -r '.title' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
VERSION=$(echo "$PR_TITLE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
export VERSION

python3 - <<'PY'
Expand Down Expand Up @@ -212,6 +230,9 @@ jobs:
echo "No CHANGELOG.md body for $TAG; keeping release-please default notes."
fi

# The SDK. In a uv workspace, `uv build` at the root builds only the root
# package; each provider distribution has its own job below, gated on its
# own release.
publish:
needs: release-please
if: needs.release-please.outputs.release_created == 'true'
Expand All @@ -231,3 +252,78 @@ jobs:

- name: Publish to PyPI
run: uv publish

publish-workload-identity-github-actions:
needs: release-please
if: needs.release-please.outputs.github_actions_release_created == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
defaults:
run:
working-directory: packages/workos-workload-identity-github-actions
steps:
- name: Checkout
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

- name: Install uv
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2

# A workspace member builds into the workspace root's dist/ by default;
# keep the artifacts next to the package so uv publish finds only them.
- name: Build
run: uv build --out-dir dist

- name: Publish to PyPI
run: uv publish

publish-workload-identity-gcp:
needs: release-please
if: needs.release-please.outputs.gcp_release_created == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
defaults:
run:
working-directory: packages/workos-workload-identity-gcp
steps:
- name: Checkout
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

- name: Install uv
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2

# A workspace member builds into the workspace root's dist/ by default;
# keep the artifacts next to the package so uv publish finds only them.
- name: Build
run: uv build --out-dir dist

- name: Publish to PyPI
run: uv publish

publish-workload-identity-aws:
needs: release-please
if: needs.release-please.outputs.aws_release_created == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
defaults:
run:
working-directory: packages/workos-workload-identity-aws
steps:
- name: Checkout
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

- name: Install uv
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2

# A workspace member builds into the workspace root's dist/ by default;
# keep the artifacts next to the package so uv publish finds only them.
- name: Build
run: uv build --out-dir dist

- name: Publish to PyPI
run: uv publish
5 changes: 4 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
".": "10.9.0"
".": "10.9.0",
"packages/workos-workload-identity-github-actions": "0.0.0",
"packages/workos-workload-identity-gcp": "0.0.0",
"packages/workos-workload-identity-aws": "0.0.0"
}
121 changes: 121 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,127 @@ The client reads credentials from the environment when not passed explicitly:
| `WORKOS_REQUEST_TIMEOUT` | HTTP timeout in seconds (defaults to `60`) |
| `WORKOS_ISSUER` | Expected `iss` claim of session access tokens, comma-separated to accept several (not validated when unset; also settable via `jwt_issuer=`) |

## Workload Identity

A workload running in GitHub Actions, GCP or AWS can call the WorkOS API without a stored API key. The SDK exchanges a JWT issued by the platform for a short-lived WorkOS access token, caches it in memory, and refreshes it before it expires.

Build a `WorkloadIdentityCredentials` and pass it as `credentials` instead of `api_key`:

```python
from workos import WorkOSClient, WorkloadIdentityCredentials
from workos_workload_identity_github_actions import github_actions

client = WorkOSClient(
credentials=WorkloadIdentityCredentials(
client_id="client_1234", # the M2M application's client ID
token_url="https://.../oauth2/token", # the token exchange endpoint
environment_id="environment_1234", # optional, see below
identity_token_provider=github_actions("https://api.workos.com"),
)
)

page = client.organizations.list_organizations()
```

`AsyncWorkOSClient` takes the same `credentials` argument. Workload identity is used only when you pass `credentials`: no environment variable switches it on, `WORKOS_API_KEY` is ignored when credentials are passed, and a failed exchange is an error, never a fallback to an API key. Passing both `api_key` and `credentials` raises `ValueError`.

The calls that send the API key as the client secret still need a client built with `api_key`: the `user_management` sign-in methods such as `authenticate_with_password` and `authenticate_with_code`, `sso.get_profile_and_token`, and `refresh()` on a session.

| Argument | Environment variable | Description |
|----------|----------------------|-------------|
| `identity_token_provider` | | A callable that returns the workload's JWT (required) |
| `client_id` | `WORKOS_CLIENT_ID` | The M2M application's client ID (required) |
| `token_url` | | The token exchange endpoint (required; set in code only, and there is no default). It must be an `https` URL |
| `environment_id` | | The environment ID (optional; set in code only). When set, it is sent as the `x-url-environment-id` header on every API request |
| `resource` | | The resource to request a token for (defaults to `https://api.workos.com`) |
| `scope` | | The scope to request (optional; set in code only, and omitted when unset) |

`WORKOS_CLIENT_ID` is the only environment variable the credentials read, and an explicit `client_id` wins over it. Every other argument is set in code.

`token_url` must be an absolute `https` URL, because the exchange request carries the workload's identity token and the response carries the access token. Any other URL, `http://localhost` included, raises `WorkloadIdentityError` with the code `invalid_configuration` when the credentials are built.

`environment_id` is optional. WorkOS binds a workload identity client to exactly one environment, so the header selects nothing, and when no environment ID is set the header is not sent. Setting it is a safety check: if the value names a different environment from the one the client is bound to, the API refuses the request with `403 environment_mismatch`.

### Platform Providers

Each platform's provider is a separate distribution, so the SDK itself gains no dependencies. Install the one you need; installing a provider does not select it.

```bash
pip install "workos[github-actions]" # workos-workload-identity-github-actions
pip install "workos[gcp]" # workos-workload-identity-gcp
pip install "workos[aws]" # workos-workload-identity-aws (depends on boto3)
```

Every provider takes the audience the identity token is requested for. It must match the audience of the trust rule on your WorkOS application; the conventional value is `https://api.workos.com`.

**GitHub Actions.** The job needs `permissions: id-token: write`.

```python
from workos_workload_identity_github_actions import github_actions

provider = github_actions("https://api.workos.com")
```

**GCP.** Uses the default service account's identity token from the metadata server (Compute Engine, GKE, Cloud Run, Cloud Functions).

```python
from workos_workload_identity_gcp import gcp_metadata

provider = gcp_metadata("https://api.workos.com")
```

**AWS.** Calls STS `GetWebIdentityToken` with the default AWS credential chain. The calling identity needs the `sts:GetWebIdentityToken` permission. `region` is optional when boto3 can resolve one.

```python
from workos_workload_identity_aws import aws_sts

provider = aws_sts("https://api.workos.com", region="us-east-1")
```

### Custom Providers

A provider is any callable that returns the JWT as a string. The SDK ships two, and you can pass your own function:

```python
from workos import WorkloadIdentityCredentials, token_env, token_file

# A file that another process writes, such as a sidecar or an earlier CI step
# that fetches a new token. The file is read again on every exchange
provider = token_file("/run/workos/identity-token")

# An environment variable, read on every exchange
provider = token_env("MY_IDENTITY_TOKEN")

# Your own callable
def provider() -> str:
return fetch_identity_token_somehow()

# client_id comes from WORKOS_CLIENT_ID here
credentials = WorkloadIdentityCredentials(
token_url="https://.../oauth2/token",
identity_token_provider=provider,
)
```

WorkOS accepts an identity token for one exchange only. The SDK exchanges again about every four minutes. If the file or the variable still holds the same token then, that exchange fails with `invalid_grant`. So use `token_file` and `token_env` for a source that something rewrites before each exchange, or for a job shorter than four minutes. The platform providers (GitHub Actions, GCP and AWS) fetch a new token every time.

With `AsyncWorkOSClient`, a plain function runs in a worker thread so it cannot block the event loop, and an `async def` provider is awaited.

### Workload Identity Errors

A failed exchange raises `WorkloadIdentityError`. Its `code` is the OAuth error code from the token endpoint (such as `invalid_grant`) or one of `exchange_failed`, `invalid_response`, `provider_failed` and `invalid_configuration`; `hint` says what to check; `description` carries the server's detail when there is any. Neither token ever appears in an error.

```python
from workos import WorkloadIdentityError

try:
client.organizations.list_organizations()
except WorkloadIdentityError as e:
print(e.code, e.hint)
```

The exchange is retried on connection failures, 429 and 5xx responses. If the API answers a request with a 401, the SDK discards that token, exchanges again, and retries the request once.

## Available Resources

The client exposes the WorkOS API through typed namespace properties:
Expand Down
Loading
Loading