Authenticate workloads to other workloads over mTLS

Preview

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

For information about access to this release, see theaccess request page.

This document describes how to set up automatic provisioning and lifecyclemanagement of managed workload identities for Compute Engine. Youconfigure CA pools to issue certificates usingCertificate Authority Service (CA),which is a highly-available, scalable Google Cloud service that simplifies andautomates the deployment, management, and security of CA services. Each VMis provisioned with X.509 credentials from the configured CA pool. Thesecredentials can then be used to establish mTLS connections.

With managed workload identities for Compute Engine, you can implement mutuallyauthenticated and encrypted communications between any two Compute Engine VMs.Workload applications running on the configured VMs can use the X.509credentials for per-VMmTLS.These mTLS certificates are automatically rotated and managed for you byCertificate Authority Service.

Before you begin

Required roles

To get the permissions that you need to create VMs that use managed workload identity certificatesfor authentication to other workloads, ask your administrator to grant you the following IAM roles on the project:

For more information about granting roles, seeManage access to projects, folders, and organizations.

You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

Overview

To use managed workload identities for your applications, you must perform thefollowing tasks:

  1. Security Administrator:

  2. Compute Administrator:

Configure managed workload identities in Identity and Access Management

  • Follow the instructions inConfigure managed workload identities authentication.

    These instructions detail how to complete the following:

    • Create a workload identity pool.
    • Create namespaces in the workload identity pool. You use the namespaces tocreate administrative boundaries for your managed workload identities, forexample, a namespace for each of the applications owned by yourorganization.
    • Create a managed workload identity in a namespace in the workload identitypool. For example, you might create a namespace for an application andcreate managed identities within that namespace for the microservices thatsupport that application.
    • Create a service account. Compute Engine VMs can be authorized toreceive a managed workload identity based on the Google Cloud serviceaccount attached to the VM.
    • Create a workload attestation policy that allows your workload to be issuedcredentials for the managed workload identity. To be issues credentialsfor the managed workload identity, the workload must be within a specifiedproject and have the service account attached.
    • Configure Certificate Authority Service to issue certificates for managed workloadidentities:
      • Configure the root CA pool
      • Configure the subordinate CAs
      • Authorize managed workload identities to request certificatesfrom the CA pool

Get the configuration file to upload the partner metadata

Your security administrator creates a JSON file that contains the following:

This file should be namedCONFIGS.json. You use this file when creating aninstance template for MIGs or when creating an individual VM.

Note: The format of the JSON and the values provided must be valid. TheVM creation will fail if the file provides invalid input.

TheCONFIGS.json file should be similar to the following:

{"wc.compute.googleapis.com":{"entries":{"certificate-issuance-config":{"primary_certificate_authority_config":{"certificate_authority_config":{"ca_pool":"projects/PROJECT_ID/locations/SUBORDINATE_CA_POOL_REGION/caPools/SUBORDINATE_CA_POOL_ID"}},"key_algorithm":"rsa-2048"},"trust-config":{"POOL_ID.global.PROJECT_NUMBER.workload.id.goog":{"trust_anchors":[{"ca_pool":"projects/PROJECT_ID/locations/SUBORDINATE_CA_POOL_REGION/caPools/SUBORDINATE_CA_POOL_ID"}]}}}},"iam.googleapis.com":{"entries":{"workload-identity":"spiffe://POOL_ID.global.PROJECT_NUMBER.workload.id.goog/ns/NAMESPACE_ID/sa/MANAGED_IDENTITY_ID"}}}

Enable managed workload identities for a Managed Instance Group (MIG)

Amanaged instance group (MIG)is a group of virtual machine (VM) instancesthat you treat as a single entity. Each VM in a MIG is created using aninstance template. To enable the VMs in the MIG to use managed workload identities,you specify the configuration in the instance template.

Create an instance template

Create aninstance template with themanaged workload identities feature enabled. Then use this template to create amanaged instance group (MIG).

gcloud

Use thegcloud beta compute instance-templates create command tocreate a new instance template that enables managed workload identities.

gcloud beta compute instance-templates createINSTANCE_TEMPLATE_NAME \    --service-accountSERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com \    --metadata enable-workload-certificate=true \    --partner-metadata-from-fileCONFIGS.json

You can add additional flags when creating the instance template tocustomize the VMs it creates, such as specifying the machine type and image,instead of using the default values.

Replace the following:

  • INSTANCE_TEMPLATE_NAME: the name for the new template.
  • SERVICE_ACCOUNT_NAME: the name of the serviceaccount that is allowed to receive the managed identity.
  • PROJECT_ID: the ID of the project where the service accountwas created.
  • CONFIGS.json: The configuration file containing thecertificate issuance config, the trust config, andthe managed workload identity.

For more information, seeCreate instance templates.

Create a managed instance group from the template

Create amanaged instance groupthat uses an instance template that enables the managed workload identities.For details on how to create the instance template, seeCreate an instance template.

gcloud

Create a MIG using the instance template and thegcloud compute instance-groups managed create command.

gcloud compute instance-groups managed createINSTANCE_GROUP_NAME \    --size=SIZE \    --template=INSTANCE_TEMPLATE_NAME \    --zone=ZONE

Replace the following:

  • INSTANCE_GROUP_NAME: a unique ID for the managed instance group. Fordetails on valid names, seeName resources.
  • SIZE: the size of the managed instance group
  • INSTANCE_TEMPLATE_NAME: the name of the instance template to use whencreating VMs in the MIG.
  • ZONE: the zone to create the VMs in

For detailed information about creating MIGs, seeBasic scenarios for creating managed instance groups (MIGs)

Enable managed workload identities for individual VMs

You can enable managed workload identities for a VM either when creating the VMor by updating the partner metadata for an existing VM.

Create VMs with managed workload identities enabled

When creating a VM, to enable the managed workload identities feature for theVM, you must do the following:

  • Specify a service account for the VM to use
  • Set theenable-workload-certificate metadata attribute totrue
  • Specify the certificate issuance config and trust configinformation aspartner metadata.

gcloud

Use thegcloud beta compute instances create commandto create a new VM. Use theCONFIGS.json file supplied by your securityadministrator, or created by following the instructions inCreate a configuration file to upload the partner metadata.

  1. Create a VM with the managed workload identities feature enabled.

    gcloud beta compute instances createINSTANCE_NAME \   --zone=INSTANCE_ZONE \   --service-accountSERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com \   --metadata enable-workload-certificate=true \   --partner-metadata-from-fileCONFIGS.json

    You can add additional lines to the command to configure the VM,such as the machine type and image, instead of using the default values.For more information, seeCreate and start a VM instance.

    Replace the following:

    • INSTANCE_NAME: a unique name for the VM. For details onvalid instance names, seeName resources.
    • INSTANCE_ZONE: the zone to create the VM in.
    • SERVICE_ACCOUNT_NAME: the name of the service accountthat is allowed to receive the managed identity.
    • PROJECT_ID: the ID of the project where the service accountwas created.
    • CONFIGS.json: The name of the configuration file thatcontains the certificate issuance config, the trustconfig, and the managed workload identity configuration.

Enable managed workload identities on existing VMs

To enable managed workload identities for an existing VM, update the VM toconfigure the following:

  • If the VM doesn't already have an attached service account, then create and attach a service account to the VM.
  • Set theenable-workload-certificate metadata attribute totrue.
  • Specify the certificate issuance config and trust config information aspartner metadata.
  • Restart the VM.

gcloud

This task uses theCONFIGS.json file supplied by your securityadministrator, or created by following the instructions inCreate a configuration file to upload the partner metadata.

  1. If the VM doesn't already have an attached service account,attach the service account to the VM.

  2. Update the metadata for an existing VM to enablemanaged workload identities.

    gcloud beta compute instances add-metadataVM_NAME \   --zone=ZONE \   --metadata enable-workload-certificate=true

    Replace the following:

    • VM_NAME: the name of the VM
    • ZONE: the zone where the VM is located
  3. Update the configuration for an existing VM to add the config file.

    gcloud beta compute instances updateVM_NAME \   --zone=ZONE \   --partner-metadata-from-fileCONFIGS.json

    Replace the following:

    • VM_NAME: the name of the VM
    • ZONE: the zone where the VM is located
    • CONFIGS.json: The configuration file containing thecertificate issuance config, the trust config, andthe managed workload identity.
  4. Stop the VM.

    gcloud beta compute instances stopVM_NAME \   --zone=ZONE

    Replace the following:

    • VM_NAME: the name of the VM
    • ZONE: the zone where the VM is located.
  5. Start the VM.

    gcloud beta compute instances startVM_NAME \   --zone=ZONE

    Replace the following:

    • VM_NAME: the name of the VM
    • ZONE: the zone where the VM is located.

Access workload credentials on a Linux VM

After successfully configuring workload to workload authentication using mTLS,you can access the issued credentials on your VM.

There are two ways to access the Compute Engine managed workload identitycredentials and the associated trust bundle:

  • The file system on the VM
  • The Compute Engine metadata server

Access the workload credentials and trust bundle using the file system on the VM

This method puts the X.509 credentials and the trust bundle at a specific pathinside the VM's file system. Applications can directly read the credentialsand the trust bundle from the file system. For examples of how to retrieve thecredentials, see the following examples on GitHub:

The VM must run the Compute Engine guest agent version 20231103.01 or later.Use the following command to check the version of the Compute Engine guestagent on your VM:

gcloud beta compute instances get-serial-port-outputINSTANCE_NAME \   --zone=ZONE | grep "GCE Agent Started"

If the version of the guest agent is less than 20231103.01, you can updateit by following the instructions inUpdating the guest environment.

To make the workload credentials and trust bundle available in the file systemof a VM, complete the following steps:

  1. Install or update theCompute Engine guest agentto version 20231103.01 or later. The guest agent does the following:

    • Automatically retrieves the credentials and the trust bundle from theCompute Engine metadata server.
    • Ensures atomic writes to the file system while updating the X.509certificate and the corresponding private key.
    • Automatically refreshes the credentials and the trust bundle, for example,when the mTLS certificates are rotated.
  2. After you install or update the Compute Engine guest agent on the guest OS,the workload refresh job creates the directory/var/run/secrets/workload-spiffe-credentials and sets the directorypermissions to0755 (rwxr-xr-x).

    The directory contains the following files created with0644 (rw-r--r--)permissions:

  3. Applications can read the certificates, private key and the trust bundle fromthe file system directly to establish mTLS connections.

    Note: Your application code must verify that the private key and certificatefile are consistent before using them to establish mTLS connection. Amismatch between the private key and certificate may happen if theCompute Engine guest agent refreshes the credentials from MDS in the timebetween the application reading theprivate_key.pem file and thecertificates.pem file or the other way around. For example, applicationswritten in Golang can use thetls.LoadX509KeyPair methodto check for consistency between the public and private key pair.

Access the workload credentials and trust bundle using the metadata server

An application running on a Compute Engine VM can directlyquery the metadata server endpointsand retrieve the credentials and the trust bundle. Theapplication is responsible for periodically checking the metadata serverendpoints for new credentials and updates to the trust bundle.

The Compute Engine metadata server exposes three HTTP endpoints to enablethe use of the managed workload identities feature by applications runninginside the VM.

  • gce-workload-certificates/config-status: An endpoint containing any errorsin the configuration values provided through the VM metadata.
  • gce-workload-certificates/workload-identities: An endpoint of identitiesmanaged by the Compute Engine control plane. This endpoint contains theX.509 certificate and the private key for the VM's trust domain.
  • gce-workload-certificates/trust-anchors: An endpoint containing a set oftrusted certificates for peer X.509 certificate chain validation.

To learn more about querying the metadata for a VM instance, seeAbout VM metadata.

To access the workload credentials and trust bundle using the metadata server,your application should do the following:

  1. Query thegce-workload-certificates/config-status endpoint. Ensure thatthe HTTP response code is200 and that the response doesn't contain anypartnerMetadataConfigsErrors errors. If such errors exist, update theappropriate configuration with valid values by following the steps discussedinUpdate certificate issuance and trust config.

    To check the value, you can run the following command on the VM:

    curl"http://metadata.google.internal/computeMetadata/v1/instance/gce-workload-certificates/config-status"-H"Metadata-Flavor: Google"

    Theconfig-status endpoint returns a JSON response with followingstructure:

    {    "partnerMetadataConfigsErrors": {        "errors": {  // A map of errors keyed by attribute name.            "ATTRIBUTE_NAME" : "ERROR_DETAILS",            ...        }    }}
  2. Query thegce-workload-certificates/workload-identities endpoint. Ensurethat the HTTP response code is200. The endpoint returns a JSON responsewith following structure:

    { "workloadCredentials": {  // Credentials for the VM's trust domains   "spiffe://POOL_ID.global.PROJECT_NUMBER.workload.id.goog/ns/NAMESPACE_ID/sa/MANAGED_IDENTITY_ID": {      "certificatePem" : "X.509 certificate or certificate chain",      "privateKeyPem" : "Private for X.509 leaf certificate"   } }}

    Extract thecertificatePem and theprivateKeyPem. It is critical thatboth values are read from the same response to avoid mismatch between theprivate and public key in case the managed workload identities were refreshed bythe Compute Engine infrastructure.

  3. Query thegce-workload-certificates/trust-anchors endpoint. Ensure thatthe HTTP response code is200. The response will only contain the trustanchors for the SPIFFE trust domain, if specified. Otherwise, the queryreturns an error. Thetrust-anchors endpoint returns a JSON response withfollowing structure:

    {    "trustAnchors": {  // Trust bundle for the VM's trust domains        "POOL_ID.global.PROJECT_NUMBER.workload.id.goog": {            "trustAnchorsPem" : "Trust bundle containing the X.509            roots certificates"        }    }}

    The contents oftrustAnchorsPem contains the trust bundle that can thenbe used to authenticate peer X.509 credentials when establishing a mTLSconnection.

Refreshing the credentials and trust bundle

The Compute Engine control plane automatically rotates the managed workloadidentity credentials and the trust anchors periodically.

If your applications use the file system to access the workload credentials andtrust bundle, the Compute Engine guest agent automatically refreshes thecredentials and the trust bundle, for example, when the mTLS certificates arerotated.

If your applications query the metadata server, then the applications running ona VM must periodically query the metadata server endpoints to get the latest setof managed workload identity credentials and the trust bundle. Failure to do socan break applications due to certificate expiration or changes to the trustbundle, which can cause mTLS connection establishment to fail. Googlerecommends that applications query the metadata server for the managedworkload identity credentials and the trust bundle every 5 minutes.

Update certificate issuance and trust config

You can modify the certificate issuance config and trust config for a VM thatuses managed workload identities.

Update the instance template for a managed instance group

To update the certificate issuance config and trust config values in aninstance template, you have to create a new template with the new values.Therefore, updating the certificate issuance config and trust config forexisting managed instance groups (MIGs) is not supported.

Update individual Compute Engine VMs

Note: Only the certificate issuance config and trust config values can beupdated. The managed workload identity cannot be changed after you create a VM.

To update the certificate issuance config and trust config, update thecontents of theCONFIGS.json file and use thegcloud beta compute instances update commandto apply the updates:

gcloudbetacomputeinstancesupdateINSTANCE_NAME\--partner-metadata-from-fileFILENAME.json

Replace the following:

  • INSTANCE_NAME: The name of the VM that you are updating theconfig values for
  • FILENAME: The name of the modified config file, for exampleCONFIGS.json

Troubleshoot

To find methods for diagnosing and resolving common errors related toretrieving workload credentials, refer to theTroubleshoot workload to workload authenticationdocumentation.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.