Authorization: Bearer <jwt> on every subsequent API call.
WIF is opt-in. When wif is None (the default), the SDK uses the static api_key flow.
Enabling
api_key becomes optional when WIF is enabled. If you provide both, the SDK uses WIF and treats api_key as a fallback if session refresh fails after the initial connect.
Security note (v0.9.0-beta.1):
endpoint must use https:// - NexusClient::create rejects plain-http endpoints (loopback/localhost excepted for development), since credentials travel on every request.Supported providers
Whenprovider is "auto" the SDK probes the environment in this order and picks the first provider whose credential material is actually present (v0.9.0-beta.1 - the token files are stat-ed and the metadata servers live-probed, ~1 s timeout):
You can also pin a specific provider:
AWS IAM (non-EKS AWS compute) (v0.9.0-beta.1)
ECS/Fargate tasks, Lambda functions, and plain EC2 instances have IAM credentials but no OIDC token. Theaws_iam provider SigV4-signs an STS GetCallerIdentity request with the standard AWS credential chain - never sending it to AWS - and posts the signed headers + body to /v1/auth/token-exchange. Nexus replays it against a pinned STS endpoint and matches the caller’s IAM role against an aws_iam trust policy (subject = arn:aws:iam::<account>:role/<name>).
It is gated behind the aws-iam cargo feature (off by default; pulls in aws-config + aws-sigv4):
aws_iam without the feature returns an actionable NexusError. The signed X-Nexus-Server-ID is your service’s own endpoint host, verified by the backend against the host the request arrived on - so a captured signed request is valid for that ONE service only.
Custom token_source
Provide a closure to bypass auto-detection entirely. This is the right hook for tests, custom CI flows, or topologies the SDK does not natively recognise.
token_source is Some, it takes precedence over provider.
Token exchange flow
Internally, the SDK runs this protocol:- OIDC token fetch -
WifConfig.token_source(or the auto-detected built-in) returns a workload-identity JWT. - Token exchange - the SDK POSTs
{"oidc_token": "<jwt>"}to/v1/auth/token-exchange. NoX-Nexus-API-KeyorAuthorizationheader is sent on this request. The backend validates the OIDC issuer and signature, then returns: - Bearer auth on subsequent calls - every
/v1/*request carriesAuthorization: Bearer <session_token>. - Pre-emptive refresh - when a request finds the session expires within 60 s, the SDK refreshes (re-running steps 1-2) before issuing the call.
SSE auth_expiring event
About 5 minutes before the session JWT expires, the backend emits an auth_expiring SSE control event. The background SSE thread reacts by triggering a non-blocking session refresh - it does not call /sync, and the event is not surfaced to user code. When the server force-closes the stream at expiry, the thread reconnects with the freshly-issued bearer.
Errors
Service kind awareness
The token-exchange response includesservice_kind ("frontend" or "backend"). The SDK stores this and exposes it via client.kind(). If the resolved kind is "frontend", get_secret(...) returns NexusError::ServiceKindMismatch regardless of key type - frontend services are public by design and must not hold secrets.
Project-level vs service-level trust policies
The Nexus backend supports WIF trust policies at two scopes:
At token exchange time the backend applies this resolution order:
- Does a service-level trust policy match this workload’s OIDC token claims? - if yes, authorise.
- Does a project-level trust policy match? - if yes, authorise.
- Neither matches - return 401.
endpoint, so each gets its own service’s data.
