Zero Trust Workload Identity Manager OIDC federation¶
Ensure that your workloads can receive verifiable JSON Web Tokens (JWT-SVIDs) and allow external systems, such as cloud providers, to retrieve public keys from the discovery endpoint. Configure Zero Trust Workload Identity Manager to act as an OpenID Connect (OIDC) provider through the SPIRE server.
The following providers are verified to work with SPIRE OIDC federation:
- Azure Entra ID
- Vault
About the Entra ID OpenID Connect¶
Integrate Entra ID OpenID Connect (OIDC) with SPIRE to provide workloads with automatic, short-lived cryptographic identities. This configuration allows you to securely authenticate services without maintaining static secrets.
Configure the external certificate for the managed OIDC discovery provider route¶
Configure the managed OIDC discovery provider route to use an externally managed TLS certificate. By referencing a TLS secret, you can secure the OIDC endpoint with your own certificate credentials.
Prerequisites
- You have installed Zero Trust Workload Identity Manager 0.2.0 or later.
- You have deployed the SPIRE Server, SPIRE Agent, SPIFFEE CSI Driver, and the SPIRE OIDC Discovery Provider operands in the cluster.
- You have installed the cert-manager Operator for Red Hat OpenShift. For more information, Installing the cert-manager Operator for Red Hat OpenShift.
- You have created a
ClusterIssuerorIssuerconfigured with a publicly trusted CA service. For example, an Automated Certificate Management Environment (ACME) typeIssuerwith the "Let’s Encrypt ACME" service. For more information, see Configuring an ACME issuer
Procedure
-
Create a
Roleto provide the router service account permissions to read the referenced secret by running the following command: -
Create a
RoleBindingresource to bind the router service account with the newly created Role resource by running the following command: -
Configure the
SpireOIDCDIscoveryProviderCustom Resource (CR) object to reference the Secret generated in the earlier step by running the following command:
Verification
-
In the
SpireOIDCDiscoveryProviderCR, check if theManageRouteReadycondition is set toTrueby running the following command: -
Verify that the OIDC endpoint can be accessed securely through HTTPS by running the following command:
$ curl https://$JWT_ISSUER_ENDPOINT/.well-known/openid-configuration { "issuer": "https://$JWT_ISSUER_ENDPOINT", "jwks_uri": "https://$JWT_ISSUER_ENDPOINT/keys", "authorization_endpoint": "", "response_types_supported": [ "id_token" ], "subject_types_supported": [], "id_token_signing_alg_values_supported": [ "RS256", "ES256", "ES384" ] }%
Disable a managed route¶
If you want to fully control the behavior of exposing the OIDC Discovery Provider service, you can disable the managed route based on your requirements.
Procedure
-
To manually configure the OIDC Discovery Provider, set
managedRoutetofalseby running the following command:
Use Entra ID with Microsoft Azure¶
Configure your Microsoft Azure environment to enable Entra ID integration with Azure. By defining variables and creating a resource group, you establish the infrastructure needed to securely manage workload identities.
Prerequisites
- You have configured the SPIRE OIDC Discovery Provider Route to serve the TLS certificates from a publicly trusted CA.
Procedure
-
Log in to Azure by running the following command:
-
Configure variables for your Azure subscription and tenant by running the following commands:
where:
SUBSCRIPTION_ID- Specifies your unique subscription identifier.
TENANT_ID- Specifies the ID for your Azure Active Directory instance.
LOCATION- The Azure region where your resource is created.
-
Define resource variable names by running the following commands:
where:
NAME- Specifies A base name for all resources.
RESOURCE_GROUP- Specifies the name of the resource group.
STORAGE_ACCOUNT- Specifies the name for the storage account.
STORAGE_CONTAINER- Specifies the name for the storage container.
USER_ASSIGNED_IDENTITY_NAME- Specifies the name for a managed identity.
-
Create the resource group by running the following command:
Configure Azure blob storage¶
Create a new Microsoft Azure storage account and container to provide a dedicated location for your content. Configuring this storage ensures that the Zero Trust Workload Identity Manager can successfully store and retrieve blobs for your environment.
Procedure
-
Create a new storage account that is used to store content by running the following command:
-
Obtain the storage ID for the newly created storage account by running the following command:
-
Create a storage container inside the newly created storage account to provide a location to support the storage of blobs by running the following command:
Configure an Azure user managed identity¶
Create a user-assigned managed identity in Azure to manage access control for your resources. You must also obtain the Client ID to associate roles with the service principal.
Procedure
-
Create a new User Managed Identity and then obtain the Client ID of the related Service Principal associated with the User Managed Identity by running the following command:
-
Retrieve the
CLIENT_IDof an Azure user-assigned managed identity and save it as an environment variable by running the following command: -
Associate a role with the Service Principal associated with the User Managed Identity by running the following command:
Create the demonstration application¶
Create the demonstration application to verify that the entire system functions correctly. This process validates the configuration of your application secrets and namespaces.
Procedure
-
Set the application name and namespace by running the following commands:
-
Create the namespace by running the following command:
-
Create the application Secret by running the following command:
$ oc apply -f - << EOF apiVersion: v1 kind: Secret metadata: name: $APP_NAME namespace: $APP_NAMESPACE stringData: AAD_AUTHORITY: https://login.microsoftonline.com/ AZURE_AUDIENCE: "api://AzureADTokenExchange" AZURE_TENANT_ID: "${TENANT_ID}" AZURE_CLIENT_ID: "${IDENTITY_CLIENT_ID}" BLOB_STORE_ACCOUNT: "${STORAGE_ACCOUNT}" BLOB_STORE_CONTAINER: "${STORAGE_CONTAINER}" EOF
Deploy the workload application¶
Deploy the workload application to your cluster to validate the Zero Trust Workload Identity Manager environment. This application confirms that the SPIFFE Workload API is functioning and can successfully retrieve JWT tokens.
Prerequisites
- The demonstration application has been created and deployed.
Procedure
-
To deploy the application, copy the entire command block provided and paste it directly into your terminal. Press Enter.
$ oc apply -f - << EOF apiVersion: v1 kind: ServiceAccount metadata: name: $APP_NAME namespace: $APP_NAMESPACE --- kind: Deployment apiVersion: apps/v1 metadata: name: $APP_NAME namespace: $APP_NAMESPACE spec: selector: matchLabels: app: $APP_NAME template: metadata: labels: app: $APP_NAME deployment: $APP_NAME spec: serviceAccountName: $APP_NAME containers: - name: $APP_NAME image: "registry.redhat.io/ubi9/python-311:latest" command: - /bin/bash - "-c" - | #!/bin/bash pip install spiffe azure-cli cat << EOF > /opt/app-root/src/get-spiffe-token.py #!/opt/app-root/bin/python from spiffe import JwtSource import argparse parser = argparse.ArgumentParser(description='Retrieve SPIFFE Token.') parser.add_argument("-a", "--audience", help="The audience to include in the token", required=True) args = parser.parse_args() with JwtSource() as source: jwt_svid = source.fetch_svid(audience={args.audience}) print(jwt_svid.token) EOF chmod +x /opt/app-root/src/get-spiffe-token.py while true; do sleep 10; done envFrom: - secretRef: name: $APP_NAME env: - name: SPIFFE_ENDPOINT_SOCKET value: unix:///run/spire/sockets/spire-agent.sock securityContext: allowPrivilegeEscalation: false capabilities: drop: - ALL readOnlyRootFilesystem: false runAsNonRoot: true seccompProfile: type: RuntimeDefault ports: - containerPort: 8080 protocol: TCP volumeMounts: - name: spiffe-workload-api mountPath: /run/spire/sockets readOnly: true volumes: - name: spiffe-workload-api csi: driver: csi.spiffe.io readOnly: true EOF
Verification
-
Ensure that the
workload-apppod is running successfully by running the following command: -
Retrieve the SPIFFE JWT Token (SVID-JWT):
-
Get the pod name dynamically by running the following command:
-
Run the script inside the pod by running the following command:
-
Configure Azure with the SPIFFE identity federation¶
Configure Microsoft Azure with SPIFFE identity federation to enable password-free, automated authentication for the demonstration application. This federates the User Managed Identity with the SPIFFE identity associated with your workload application.
Procedure
-
Federate the identities between the User Managed Identity and the SPIFFE identity associated with the workload application by running the following command:
Verify that the application workload can access the content in the Azure Blob Storage¶
Verify that your application workload can connect to the Azure Blob Storage. By uploading a test file, you validate the authentication token and ensure that the workload has the correct permissions.
Prerequisites
- An Azure Blob Storage has been created.
Procedure
-
Retrieve a JWT token from the SPIFFE Workload API by running the following command:
-
Create and export an environment variable named
TOKENby running the following command: -
Log in to Azure CLI included within the pod by running the following command:
-
Create a new file with the application workload pod and upload the file to the Blob Storage by running the following command:
-
Upload a file to the Azure Blog Storage by running the following command:
Verification
-
Confirm the file uploaded successfully by listing the files contained by running the following command:
About Vault OpenID Connect¶
Use Vault OpenID Connect (OIDC) with SPIRE to securely authenticate workloads. Vault uses SPIRE as a trusted OIDC provider to validate workload identities. This configuration enables workloads to receive short-lived tokens to access secrets and perform actions within Vault.
Install Vault¶
Install HashiCorp Vault to serve as an OpenID Connect (OIDC) provider. This establishes the necessary infrastructure to manage workload identities securely in your Zero Trust Workload Identity Manager environment.
Prerequisites
- Configure a route. For more information, see Configuring routes
- Helm is installed.
- A command-line JSON processor for easily reading the output from the Vault API.
- A HashiCorp Helm repository is added.
Procedure
-
Create the
vault-helm-value.yamlfile.global: enabled: true openshift: true tlsDisable: true injector: enabled: false server: ui: enabled: true image: repository: docker.io/hashicorp/vault tag: "1.19.0" dataStorage: enabled: true size: 1Gi standalone: enabled: true config: | listener "tcp" { tls_disable = 1 address = "[::]:8200" cluster_address = "[::]:8201" } storage "file" { path = "/vault/data" } extraEnvironmentVars: {}- The
openshiftfield optimizes the deployment for OpenShift-specific security contexts. - The
tlsDisablefield disables TLS for Kubernetes objects created by the chart. - The
datastorage.enabledfield creates a 1Gi persistent volume to store Vault data. - The
standalone.enabledfield deploys a single Vault pod. - The
tls_disabledfield tells the Vault server to not use TLS.
- The
-
Run the
helm installcommand: -
Expose the Vault service by running the following command:
-
Set the
VAULT_ADDRenvironment variable to retrieve the hostname from the new route and then export it by running the following command:Note
http://is prepended because TLS is disabled.
Verification
-
To ensure your Vault instance is running, run the following command:
Example output{ "initialized": true, "sealed": true, "standby": true, "performance_standby": false, "replication_performance_mode": "disabled", "replication_dr_mode": "disabled", "server_time_utc": 1663786574, "version": "1.19.0", "cluster_name": "vault-cluster-a1b2c3d4", "cluster_id": "5e6f7a8b-9c0d-1e2f-3a4b-5c6d7e8f9a0b" }
Initialize and unseal Vault¶
To prepare a newly installed Vault server for operation, initialize and unseal it. This process loads the primary encryption key into memory so that Vault can decrypt data and protect other encryption keys.
The steps to initialize a Vault server are:
- Initialize and unseal Vault
- Enable the key-value (KV) secrets engine and store a test secret
- Configure JSON Web Token (JWT) authentication with SPIRE
- Deploy a demonstration application
- Authenticate and retrieve the secret
Prerequisites
- Ensure that Vault is running.
- Ensure that Vault is not initialized. You can only initialize a Vault server once.
Procedure
-
Open a remote shell into the
vaultpod by running the following command: -
Initialize Vault to get your unseal key and root token by running the following command:
-
Export the unseal key and root token you received from the earlier command by running the following commands:
-
Unseal Vault using your unseal key by running the following command:
-
Exit the pod by entering
exit.
Verification
-
To verify that the Vault pod is ready, run the following command:
Enable the key-value secrets engine and store a test secret¶
Enable the key-value secrets engine to create a secure, centralized location for managing credentials. You can also store a test secret to verify that the engine is working.
Prerequisites
- Make sure that Vault is initialized and unsealed.
Procedure
-
Open another shell session in the
Vaultpod by running the following command: -
Export your root token again within this new session and log in by running the following command:
-
Enable the KV secrets engine at the
secret/path and create a test secret by running the following commands:
Verification
-
To verify that the secret is stored correctly, run the following command:
Configure JSON Web Token authentication with SPIRE¶
To help your applications securely log in to Vault using SPIFFE identities, configure JSON Web Token (JWT) authentication.
Prerequisites
- Make sure that Vault is initialized and unsealed.
- Ensure that a test secret is stored in the key-value secrets engine.
Procedure
-
On your local machine, retrieve the SPIRE Certificate Authority (CA) bundle and save it to a file by running the following command:
-
Back in the Vault pod shell, create a temporary file and paste the contents of
oidc_provider_ca.peminto it by running the following command: -
Set up the necessary environment variables for the JWT configuration by running the following commands:
-
Crate a new environment variable by running the following command:
-
Enable the JWT authentication method by running the following command:
-
Configure you ODIC authentication method by running the following command:
-
Create a policy named
ztwim-policyby running the following command: -
Grant read access to the secret you created earlier by running the following command:
-
Create the following environment variables by running the following commands:
-
Create a JWT role that binds the policy to workload with a specific SPIFFE ID by running the following command:
Deploy a demonstration application¶
Deploy a demonstration application to create a simple client that uses its SPIFFE identity to authenticate with Vault. By doing this you can verify that the client can successfully authenticate using the configured identity.
Procedure
-
On your local machine, set the environment variables for your application by running the following commands:
-
Apply the Kubernetes manifest to create the namespace, service account, and deployment for the demo app by running the following command. This deployment mounts the SPIFFE CSI driver socket.
Verification
-
Verify that the client deployment is ready by running the following command:
Authenticate and retrieve the secret¶
Use the demonstration application to fetch a JWT token from the SPIFFE Workload API. Use the token to authenticate with Vault so that you can securely retrieve the secret and verify the workflow.
Procedure
-
Fetch a JWT-SVID by running the following command inside the running client pod:
-
Copy the token from the output and export it as an environment variable on your local machine by running the following command:
-
Crate a new environment variable by running the following command:
-
Use
curlto send the JWT token to the Vault login endpoint to get a Vault client token by running the following command:
Verification
-
Use the newly acquired Vault token to read the secret from the KV store by running the following command:
You should see the contents of the secret (
"version": "v0.1.0") in the output, confirming the entire workflow is successful