SPIFFE/SPIRE
Learn how to authenticate SPIRE workloads with Hanzo KMS using OpenID Connect (OIDC).
OIDC Auth is a platform-agnostic JWT-based authentication method that can be used to authenticate from any platform or environment using an identity provider with OpenID Connect.
Diagram
The following sequence diagram illustrates the OIDC Auth workflow for authenticating SPIRE workloads with Hanzo KMS.
sequenceDiagram
participant Client as SPIRE Workload
participant Agent as SPIRE Agent
participant Server as SPIRE Server
participant Infis as Hanzo KMS
Client->>Agent: Step 1: Request JWT-SVID
Agent->>Server: Validate workload and fetch signing key
Server-->>Agent: Return signing material
Agent-->>Client: Return JWT-SVID with verifiable claims
Note over Client,Infis: Step 2: Login Operation
Client->>Infis: Send JWT-SVID to /api/v1/auth/oidc-auth/login
Note over Infis,Server: Step 3: Query verification
Infis->>Server: Request JWT public key using OIDC Discovery
Server-->>Infis: Return public key
Note over Infis: Step 4: JWT validation
Infis->>Client: Return short-lived access token
Note over Client,Infis: Step 5: Access Hanzo KMS API with Token
Client->>Infis: Make authenticated requests using the short-lived access tokenConcept
At a high-level, Hanzo KMS authenticates a SPIRE workload by verifying the JWT-SVID and checking that it meets specific requirements (e.g. it is issued by a trusted SPIRE server) at the /api/v1/auth/oidc-auth/login endpoint. If successful,
then Hanzo KMS returns a short-lived access token that can be used to make authenticated requests to the Hanzo KMS API.
To be more specific:
- The SPIRE workload requests a JWT-SVID from the local SPIRE Agent.
- The SPIRE Agent validates the workload's identity and requests signing material from the SPIRE Server.
- The SPIRE Agent returns a JWT-SVID containing the workload's SPIFFE ID and other claims.
- The JWT-SVID is sent to Hanzo KMS at the
/api/v1/auth/oidc-auth/loginendpoint. - Hanzo KMS fetches the public key that was used to sign the JWT-SVID from the SPIRE Server using OIDC Discovery.
- Hanzo KMS validates the JWT-SVID using the public key provided by the SPIRE Server and checks that the subject, audience, and claims of the token matches with the set criteria.
- If all is well, Hanzo KMS returns a short-lived access token that the workload can use to make authenticated requests to the Hanzo KMS API.
Prerequisites
Before following this guide, ensure you have:
- A running SPIRE deployment with both SPIRE Server and SPIRE Agent configured
- OIDC Discovery Provider deployed alongside your SPIRE Server
- Workload registration entries created in SPIRE for the workloads that need to access Hanzo KMS
- Network connectivity between Hanzo KMS and your OIDC Discovery Provider endpoint
For detailed SPIRE setup instructions, refer to the SPIRE documentation.
OIDC Discovery Provider Setup
To enable JWT-SVID verification with Hanzo KMS, you need to deploy the OIDC Discovery Provider alongside your SPIRE Server. The OIDC Discovery Provider runs as a separate service that exposes the necessary OIDC endpoints.
In Kubernetes deployments, this is typically done by adding an oidc-discovery-provider container to your SPIRE Server StatefulSet:
- name: spire-oidc
image: ghcr.io/spiffe/oidc-discovery-provider:1.12.2
args:
- -config
- /run/spire/oidc/config/oidc-discovery-provider.conf
ports:
- containerPort: 443
name: spire-oidc-portThe OIDC Discovery Provider will expose the OIDC Discovery endpoint at https://<spire-oidc-host>/.well-known/openid_configuration, which Hanzo KMS will use to fetch the public keys for JWT-SVID verification.
Guide
In the following steps, we explore how to create and use identities to access the Hanzo KMS API using the OIDC Auth authentication method with SPIFFE/SPIRE.
To create an identity, head to your Organization Settings > Access Control > Identities and press Create identity.

When creating an identity, you specify an organization level role for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles.

Now input a few details for your new identity. Here's some guidance for each field:
- Name (required): A friendly name for the identity.
- Role (required): A role from the Organization Roles tab for the identity to assume. The organization role assigned will determine what organization level resources this identity can have access to.
Once you've created an identity, you'll be redirected to a page where you can manage the identity.

Since the identity has been configured with Universal Auth by default, you should re-configure it to use OIDC Auth instead. To do this, press to edit the Authentication section, remove the existing Universal Auth configuration, and add a new OIDC Auth configuration onto the identity.


Here's some more guidance on each field:
- OIDC Discovery URL: The URL used to retrieve the OpenID Connect configuration from the SPIRE Server. This will be used to fetch the public key needed for verifying the provided JWT-SVID. This should be set to your SPIRE Server's OIDC Discovery endpoint, typically
https://<spire-server-host>:<port>/.well-known/openid_configuration - Issuer: The unique identifier of the SPIRE Server issuing the JWT-SVID. This value is used to verify the iss (issuer) claim in the JWT-SVID to ensure the token is issued by a trusted SPIRE Server. This should match your SPIRE Server's configured issuer, typically
https://<spire-server-host>:<port> - CA Certificate: The PEM-encoded CA certificate for establishing secure communication with the SPIRE Server endpoints. This should contain the CA certificate that signed your SPIRE Server's TLS certificate.
- Subject: The expected SPIFFE ID that is the subject of the JWT-SVID. The format of the sub field for SPIRE JWT-SVIDs follows the SPIFFE ID format:
spiffe://<trust-domain>/<workload-path>. For example:spiffe://example.org/workload/api-server - Audiences: A list of intended recipients for the JWT-SVID. This value is checked against the aud (audience) claim in the token. When workloads request JWT-SVIDs from SPIRE, they specify an audience (e.g.,
kmsor your service name). Configure this to match what your workloads use. - Claims: Additional information or attributes that should be present in the JWT-SVID for it to be valid. Standard SPIRE JWT-SVID claims include
sub(SPIFFE ID),aud(audience),exp(expiration), andiat(issued at). You can also configure custom claims if your SPIRE Server includes additional metadata. - Access Token TTL (default is
2592000equivalent to 30 days): The lifetime for an access token in seconds. This value will be referenced at renewal time. - Access Token Max TTL (default is
2592000equivalent to 30 days): The maximum lifetime for an access token in seconds. This value will be referenced at renewal time. - Access Token Max Number of Uses (default is
0): The maximum number of times that an access token can be used; a value of0implies infinite number of uses. - Access Token Trusted IPs: The IPs or CIDR ranges that access tokens can be used from. By default, each token is given the
0.0.0.0/0, allowing usage from any network address. SPIRE JWT-SVIDs contain standard claims likesub(SPIFFE ID),aud(audience),exp, andiat. The audience is typically specified when requesting the JWT-SVID (e.g.,spire-agent api fetch jwt -audience kms). Thesubject,audiences, andclaimsfields support glob pattern matching; however, we highly recommend using hardcoded SPIFFE IDs whenever possible for better security.
To enable the identity to access project-level resources such as secrets within a specific project, you should add it to that project.
To do this, head over to the project you want to add the identity to and go to Project Settings > Access Control > Machine Identities and press Add identity.
Next, select the identity you want to add to the project and the project level role you want to allow it to assume. The project role assigned will determine what project level resources this identity can have access to.


Here's an example of how a workload can use its JWT-SVID to authenticate with Hanzo KMS and retrieve secrets:
#!/bin/bash
# Obtain JWT-SVID from SPIRE Agent
JWT_SVID=$(spire-agent api fetch jwt -audience kms -socketPath /run/spire/sockets/agent.sock | grep -A1 "token(" | tail -1)
# Authenticate with Hanzo KMS using the JWT-SVID
ACCESS_TOKEN=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d "{\"identityId\":\"<your-identity-id>\",\"jwt\":\"$JWT_SVID\"}" \
https://app.kms.hanzo.ai/api/v1/auth/oidc-auth/login | jq -r '.accessToken')
# Use the access token to retrieve secrets
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://app.kms.hanzo.ai/api/v3/secrets/raw?workspaceSlug=<project-slug>&environment=<env-slug>&secretPath=/"Each identity access token has a time-to-live (TTL) which you can infer from the response of the login operation;
the default TTL is 7200 seconds which can be adjusted.
If an identity access token expires, it can no longer authenticate with the Hanzo KMS API. In this case, a new access token should be obtained by performing another login operation.
JWT-SVIDs from SPIRE have their own expiration time (typically short-lived). Ensure your application handles both JWT-SVID renewal from SPIRE and access token renewal from Hanzo KMS appropriately.
How is this guide?
Last updated on