Configure JWT authentication
Boundary can authenticate automated workloads using signed JSON Web Tokens (JWTs) with the JWT auth method. Instead of a username and password, a workload presents a signed JWT, and Boundary exchanges it for a Boundary auth token. The JWT auth method is useful for machine-to-machine authentication, such as agents or pipelines that need to access infrastructure targets.
The JWT auth method validates tokens against a JSON Web Key Set (JWKS). Boundary retrieves the JWKS using OIDC discovery or a JWKS URL, or you provide it directly. Boundary checks the token's issuer, audience, signing algorithm, and key ID against the auth method's configuration before issuing a Boundary auth token.
The JWT auth method does not support managed groups.
Prerequisites
- Administrator access to Boundary.
- A signing key pair. The private key signs JWTs presented during authentication. The public key is included in the JWKS you provide to Boundary.
- The following values must match in both the JWT auth method configuration and any JWT presented for authentication:
- Issuer (
issclaim): The expected issuer URL, for examplehttps://my-identity-service.example.com. - Audience (
audclaim): The expected audience, for exampleboundary. Setting an audience is optional, but if you set one, it must match. - Signing algorithm: The algorithm used to sign the JWT, for example
RS256.
- Issuer (
Create a JWT auth method
You must specify exactly one signing-key source when you create a JWT auth method. Choose the approach that matches how your issuer exposes its public keys:
- OIDC discovery — Boundary fetches the JWKS endpoint from the issuer's OIDC discovery document.
- Direct JWKS URL — Boundary retrieves the JWKS from one or more HTTPS endpoints you specify.
- JWKS JSON file or environment variable — You provide the JWKS directly as a local file or environment variable.
The -scope-id flag determines which scope contains the auth method. Set it to global or to an org scope ID. When you omit -scope-id, Boundary uses the BOUNDARY_SCOPE_ID environment variable, or defaults to global.
The command returns an auth method ID beginning with amjwt_. Save this value. You need it for subsequent commands.
Refer to the auth-methods create jwt command documentation for the full list of options.
OIDC discovery
Boundary uses the issuer's OIDC discovery document to locate the JWKS endpoint and fetch signing keys automatically.
$ boundary auth-methods create jwt \
-scope-id global \
-name "my-jwt-auth-method" \
-issuer "https://my-identity-service.example.com" \
-allowed-audience "boundary" \
-signing-algorithm RS256 \
-oidc-discovery
For issuers that use a private CA, add -issuer-ca-cert with the PEM CA certificate as raw text. Specifying -issuer-ca-cert also selects OIDC discovery, even if you omit -oidc-discovery. The flag does not accept env:// or file:// references, so use command substitution such as "$(cat issuer-ca.pem)" to pass the contents of a certificate file:
$ boundary auth-methods create jwt \
-scope-id global \
-name "my-jwt-auth-method" \
-issuer "https://my-identity-service.example.com" \
-allowed-audience "boundary" \
-signing-algorithm RS256 \
-oidc-discovery \
-issuer-ca-cert "$(cat /path/to/issuer-ca.pem)"
Direct JWKS URL
Boundary retrieves the JWKS from an HTTPS endpoint you specify.
$ boundary auth-methods create jwt \
-scope-id global \
-name "my-jwt-auth-method" \
-issuer "https://my-identity-service.example.com" \
-allowed-audience "boundary" \
-signing-algorithm RS256 \
-jwks-url "https://my-identity-service.example.com/keys"
Repeat -jwks-url to supply multiple endpoints. Boundary tries them in the order you specify. If your endpoints use a private CA, supply one -jwks-ca-cert flag per URL, in the same order. You must also supply -jwks-url. Like -issuer-ca-cert, -jwks-ca-cert accepts only raw PEM text, not env:// or file:// references:
$ boundary auth-methods create jwt \
-scope-id global \
-name "my-jwt-auth-method" \
-issuer "https://my-identity-service.example.com" \
-allowed-audience "boundary" \
-signing-algorithm RS256 \
-jwks-url "https://keys-a.example.com/jwks.json" \
-jwks-url "https://keys-b.example.com/jwks.json" \
-jwks-ca-cert "$(cat /path/to/ca-a.pem)" \
-jwks-ca-cert "$(cat /path/to/ca-b.pem)"
JWKS JSON file or environment variable
You provide the JWKS directly. Boundary reads the JSON and sends it as the configured key set. The -jwks-json flag requires file:// or env:// syntax; it does not accept literal JSON.
$ boundary auth-methods create jwt \
-scope-id global \
-name "my-jwt-auth-method" \
-issuer "https://my-identity-service.example.com" \
-allowed-audience "boundary" \
-signing-algorithm RS256 \
-jwks-json "file:///path/to/jwks.json"
To read the JWKS from an environment variable instead:
$ boundary auth-methods create jwt \
-scope-id global \
-name "my-jwt-auth-method" \
-issuer "https://my-identity-service.example.com" \
-allowed-audience "boundary" \
-signing-algorithm RS256 \
-jwks-json "env://BOUNDARY_JWT_JWKS"
The JWKS must contain the public key or keys that correspond to the private keys used to sign JWTs.
Map JWT claims to Boundary account fields
Use -account-claim-map to map a claim from the presented JWT to one of Boundary's account fields (sub, name, or email). Specify the mapping as source=target and repeat the flag for additional mappings:
$ boundary auth-methods create jwt \
-scope-id global \
-name "my-jwt-auth-method" \
-issuer "https://my-identity-service.example.com" \
-jwks-json "file:///path/to/jwks.json" \
-account-claim-map "preferred_username=name" \
-account-claim-map "user_email=email"
Activate the JWT auth method
Boundary creates JWT auth methods in an inactive state. You must activate the auth method before workloads can authenticate with it.
$ boundary auth-methods change-state jwt \
-id $JWT_AUTH_METHOD_ID \
-state active-public
Use active-public to make the auth method visible to unauthenticated users, or active-private to let workloads authenticate without listing the method on the login page.
Refer to Auth method states for more information about each state.
Set the auth method as primary
Each scope has one primary auth method. When a workload authenticates with a JWT auth method for the first time, Boundary's behavior depends on whether the auth method is the scope's primary:
- Primary auth method: Boundary automatically creates a user (
u_...) in the scope and links the JWT account (acctjwt_...) to that user. You do not need to configure anything manually. - Not the primary auth method: Boundary creates the JWT account on first login, but does not create or link a user. The login fails until an administrator manually links the account to a user. Refer to Manage users and groups for instructions.
To set the JWT auth method as the primary auth method for a scope:
$ boundary scopes update \
-id $SCOPE_ID \
-primary-auth-method-id $JWT_AUTH_METHOD_ID
Authenticate with the JWT auth method
After the auth method is active, a workload can exchange a signed JWT for a Boundary auth token. Choose one of the following methods to authenticate:
Authenticate with the CLI
Use the -jwt-token flag to pass the JWT using an environment variable or file reference. Do not pass the raw JWT as a flag value on the command line.
Run the following command to authenticate using a JWT stored in an environment variable:
$ boundary authenticate jwt \
-auth-method-id $JWT_AUTH_METHOD_ID \
-jwt-token env://WORKLOAD_JWT
When the JWT auth method is the scope's primary auth method, you can omit the -auth-method-id flag and use the BOUNDARY_AUTHENTICATE_JWT_TOKEN environment variable instead:
$ BOUNDARY_AUTHENTICATE_JWT_TOKEN=$WORKLOAD_JWT \
boundary authenticate -scope-id global
To print the auth token, add -format json to the command. The token appears in the response under .item.attributes.token. When you use -format json, Boundary does not save the token to the system password store. Pass the token to subsequent commands using the BOUNDARY_TOKEN environment variable or the -token flag. The resulting account ID begins with acctjwt_.
Authenticate with the HTTP API
Send the signed JWT in the request body. This request does not require an Authorization header.
$ curl -sS -X POST \
"${BOUNDARY_ADDR}/v1/auth-methods/${JWT_AUTH_METHOD_ID}:authenticate" \
-H 'Content-Type: application/json' \
-d '{"command":"login","attributes":{"jwt":"'"$WORKLOAD_JWT"'"}}'
The request body has the following form:
{
"command": "login",
"attributes": {
"jwt": "<signed JWT>"
}
}
A successful response returns the Boundary auth token under .attributes.token. Use this token, not the original signed JWT, as the Authorization: Bearer token for subsequent Boundary API requests.
Assign roles to JWT users
After a workload authenticates, use its Boundary user ID to assign roles and grants. The user ID begins with u_ and appears in the JSON login response under .item.attributes.user_id (CLI) or .attributes.user_id (API).
$ boundary roles add-principals \
-id $ROLE_ID \
-principal $JWT_USER_ID
Refer to Manage access with roles for instructions on creating roles and assigning grants.