OIDC federation
Reach AWS, Google Cloud and Azure from your deployments and your local development, and AWS and Google Cloud from your builds, with short-lived OIDC tokens instead of stored keys.
OIDC federation lets your project prove who it is to a cloud provider without a stored key. Arkor issues an OpenID Connect token to the project's builds, to its deployments while they run, and to your local development. You tell AWS, Google Cloud or Azure to trust Arkor's issuer, and the cloud exchanges the token for short-lived credentials of a role you choose.
It is on by default, with the Team issuer. Owners and admins can change it under Settings › OIDC federation. It is part of every plan.
A change applies to the project's next deployment. Every deployment keeps the settings it was made with, so redeploy for a change to reach production.
The token
| Claim | Value |
|---|---|
iss | https://oidc.arkor.dev/team_… with the Team issuer, https://oidc.arkor.dev with Global |
aud | https://arkor.dev/team_… unless you ask for another audience |
sub | owner:team_…:project:<address label>:environment:<environment> |
owner_id | Your Team ID |
project | The project's original address label |
project_id | The project's ID |
environment | production, preview or development |
deployment_id | The deployment the token was issued to; absent from a development token |
iat nbf exp | When it was issued, from when and until when it is valid |
jti | A unique ID for the token |
Changing the project's display name leaves its original address label and the project and sub
claims unchanged.
The signing keys are published at https://oidc.arkor.dev/.well-known/jwks. Tokens for builds and
deployments are valid for 1 hour; development tokens for 12 hours.
Settings › OIDC federation lists the exact values for your project: its Team ID, project ID, issuer, audience and the subject for each environment. Your Team ID is also under Team settings › Members.
Team or Global issuer
- Team (recommended): the issuer URL names your team, so a cloud that trusts it trusts only your team's tokens.
- Global: one issuer URL for every team on Arkor. A trust policy on it must check
suborowner_id, or it trusts every team.
Where your code gets a token
- Builds get a token in the
ARKOR_OIDC_TOKENenvironment variable. - Deployments ask for one while they run, through the
ARKOR_OIDCbinding. - Local development uses a development token: choose Issue development token under
Settings › OIDC federation, and put it in
.env.localasARKOR_OIDC_TOKEN. The public API issues one too:POST /v1/projects/{projectId}/oidc/token, with a token that can write to the project. See Public API.
This helper covers all three. A future Arkor SDK will ship it; until then, copy it into your app:
interface TokenOptions {
/** Leave out for the default audience, `https://arkor.dev/team_…`. */
readonly audience?: string;
}
type TokenAnswer =
| {
readonly ok: true;
readonly token: string;
/** When the token expires, in milliseconds since the epoch. */
readonly expiresAt: number;
}
| { readonly ok: false; readonly reason: string };
interface ArkorOidc {
token(options?: TokenOptions): Promise<TokenAnswer>;
}
/** An OIDC token for this project: fresh at runtime, from the environment in a build or locally. */
export async function getArkorOidcToken(options: TokenOptions = {}): Promise<string> {
const env = (globalThis as Record<symbol, { ARKOR_OIDC?: ArkorOidc } | undefined>)[
Symbol.for('arkor.function-env')
];
const binding = env?.ARKOR_OIDC;
if (binding !== undefined) {
const answer = await binding.token(options);
if (!answer.ok) {
throw new Error(`Arkor did not issue an OIDC token: ${answer.reason}`);
}
return answer.token;
}
const token = process.env.ARKOR_OIDC_TOKEN;
if (token === undefined || token === '') {
throw new Error('ARKOR_OIDC_TOKEN is not set');
}
return token;
}In a build or locally, the token in ARKOR_OIDC_TOKEN carries the default audience, whatever
audience asks for. For another audience locally, enter it when you issue the development token.
AWS
- In IAM, add an OpenID Connect identity provider. Provider URL is your issuer, such as
https://oidc.arkor.dev/team_…; Audience is your audience,https://arkor.dev/team_…. - Create a role with Web identity as the trusted entity, and give it a trust policy that pins the audience and the subject:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/oidc.arkor.dev/team_…"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.arkor.dev/team_…:aud": "https://arkor.dev/team_…",
"oidc.arkor.dev/team_…:sub": "owner:team_…:project:shop-web:environment:production"
}
}
}
]
}- Use the role from your app. Hand the SDK a function, so every refresh gets a fresh token:
import { S3Client } from '@aws-sdk/client-s3';
import { fromWebToken } from '@aws-sdk/credential-providers';
import { getArkorOidcToken } from './arkor-oidc';
export const s3 = new S3Client({
region: 'us-east-1',
credentials: async () =>
fromWebToken({
roleArn: 'arn:aws:iam::123456789012:role/shop-web-production',
webIdentityToken: await getArkorOidcToken(),
clientConfig: { region: 'us-east-1' },
})(),
});Google Cloud
- Create a workload identity pool, and in it an OpenID Connect provider. Issuer URL is
your issuer; under Allowed audiences, add your audience,
https://arkor.dev/team_…. - Map the attributes.
google.subjectholds at most 127 bytes, which a long address label can pass, so map it from the project ID and environment rather than fromsub:
| Google attribute | Assertion |
|---|---|
google.subject | assertion.project_id + ':' + assertion.environment |
attribute.project_id | assertion.project_id |
attribute.environment | assertion.environment |
attribute.owner_id | assertion.owner_id |
- Add an attribute condition such as
assertion.owner_id == 'team_…' && assertion.environment == 'production', and grant a service account to the principal set forattribute.project_id/<project ID>. - Use it from your app through
google-auth-library's external account client, with a subject token supplier that asks for a fresh token each time:
import { IdentityPoolClient } from 'google-auth-library';
import { getArkorOidcToken } from './arkor-oidc';
const POOL =
'//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/arkor/providers/arkor';
export const googleAuth = new IdentityPoolClient({
audience: POOL,
subject_token_type: 'urn:ietf:params:oauth:token-type:jwt',
token_url: 'https://sts.googleapis.com/v1/token',
service_account_impersonation_url:
'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/shop-web@my-project.iam.gserviceaccount.com:generateAccessToken',
subject_token_supplier: { getSubjectToken: async () => getArkorOidcToken() },
});Azure
- On an app registration or a user-assigned managed identity, add a federated identity
credential for Other issuer. Issuer is your issuer, Subject identifier is the exact
subject, such as
owner:team_…:project:shop-web:environment:production, and Audience isapi://AzureADTokenExchange. - Ask for that audience when you get a token, and hand it to the Azure SDK as a client assertion:
import { ClientAssertionCredential } from '@azure/identity';
import { getArkorOidcToken } from './arkor-oidc';
export const credential = new ClientAssertionCredential(
'00000000-0000-0000-0000-000000000000', // tenant ID
'11111111-1111-1111-1111-111111111111', // client ID
async () => getArkorOidcToken({ audience: 'api://AzureADTokenExchange' }),
);For local development, enter api://AzureADTokenExchange as the audience when you issue the
development token.
Azure is for your deployments and local development, not your builds. A build's ARKOR_OIDC_TOKEN
always carries the default audience, https://arkor.dev/team_…, which a federated identity
credential set to api://AzureADTokenExchange refuses. Setting the credential's audience to the
default one instead makes it take build tokens too, at the cost of Microsoft's recommended value.
Good to know
- With the Global issuer, always check
suborowner_id. Anything else trusts every team on Arkor. - Pin
environment:productionfor production roles. Any owner or admin of the team, and any API token that can write to the project, can issue a development token. - A token cannot be revoked. It stays valid until it expires. To cut off access at once, remove the trust at the cloud provider, or tighten its conditions.
- Changes apply to the next deployment. Turning OIDC federation off stops new deployments from getting tokens; the ones already made keep theirs.
- Arkor never logs a token. Do not log it yourself.
- In middleware, a token costs a subrequest. Asking for one from middleware spends one of its subrequests; ask once and reuse the token until it expires.
- A project that belongs to no team cannot get tokens: there is no team for a token to name.