Troubleshoot workload to workload authentication

This document explains how to troubleshoot common errors related to Authenticate workloads to other workloads over mTLS.

For additional information, see Troubleshoot Workload Identity Federation.

Before you begin

  • If you haven't already, set up authentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
    1. Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    2. Set a default region and zone.

The generated credentials directory doesn't exist

If you get an error that the /var/run/secrets/workload-spiffe-credentials directory doesn't exist, do the following:

  1. Ensure that your compute instance supports workload-to-workload authentication by using one of the following interfaces to verify that managed workload identities are enabled:

    Console

    1. In the Google Cloud console, go to the VM instances page.

      Go to VM instances

    2. In the Name column of the VM instances page, click the instance name to view additional details about the instance.

    3. In the Security and access section of the Details page, verify that "Workload identity certificates" has a value of "Enabled".

    gcloud

    To view whether the managed workload identities feature is enabled for a compute instance, use the gcloud alpha compute instances describe command.

    gcloud alpha compute instances describe INSTANCE_NAME \
        --zone=ZONE \
        --format="table(name,zone,identityCertificate)"
    

    Replace the following:

    • INSTANCE_NAME: the name of the instance.

    • ZONE: the zone where the instance is located.

    REST

    To view the details of a compute instance, make a GET request to the instances.get method. By appending a $fields query parameter to the request, you can restrict the output to just the fields of interest.

    GET https://compute.googleapis.com/compute/alpha/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME$fields=name,identityCertificate,identity
    

    Replace the following:

    • PROJECT_ID: the ID of the project where the instance is located

    • ZONE: the zone where the instance is located

    • INSTANCE_NAME: the name of the instance

  2. Review the instance values for identityCertificate and identity.

  3. If the identityCertificate property is set to false, then this compute instance doesn't support this feature.

    To resolve this issue, create a new instance that supports workload-to-workload authentication. For details, see Enable managed workload identities on existing VMs.

  4. Confirm that the VM runs a guest OS with Compute Engine guest agent version 20260921.00 or later, which includes the managed workload identity certificate refresher as a locally bundled extension. For more information about this version, see the Guest environment release notes.

    To check the current Compute Engine guest agent version, use the gcloud CLI to view the serial port output:

    gcloud compute instances get-serial-port-output INSTANCE_NAME \
        | grep "GCE Agent Started"
    

    Replace the following:

    • INSTANCE_NAME: the name of the compute instance.

    To update the Compute Engine guest agent, see Update the guest environment.

  5. Confirm that automatic credential provisioning is enabled in the guest agent configuration file. In the /etc/default/instance_configs.cfg file on the VM, the enabled option in the MWLID section must be set to true:

    [MWLID]
    enabled = true
    

    Also confirm that the enable_local_plugins option in the Core section of the guest agent configuration file is set to true (the default value).

  6. Check the managed workload identity extension (MWLIDExtension) logs in Cloud Logging to diagnose credential refresh errors or verify whether credential provisioning is enabled.

    To filter for MWLIDExtension logs, in the Logs Explorer, run the following query:

    resource.type="gce_instance"
    resource.labels.instance_id="INSTANCE_ID"
    log_name="projects/PROJECT_ID/logs/MWLIDExtension"
    

    Replace the following:

    • INSTANCE_ID: the numerical ID of the compute instance.

    • PROJECT_ID: the ID of the project where the instance is located.

    For common error messages in these logs and how to resolve them, see Common errors in MWLIDExtension logs.

Common errors in MWLIDExtension logs

This section describes common error messages that appear in MWLIDExtension logs and how to resolve them.

Workload isn't permitted to get credentials

This error occurs when the attestation policy doesn't authorize the compute instance to receive credentials for the configured managed workload identity. The MWLIDExtension logs contain an error message similar to the following:

Workload is not permitted to get credentials. Please ensure you have configured an attestation policy that allows your workload to get a credential for the requested workload identity 'WORKLOAD_IDENTITY'.

In the preceding error message, WORKLOAD_IDENTITY is the SPIFFE ID of the configured managed workload identity.

To resolve this error, do the following:

  1. List the attestation rules for the managed workload identity to confirm that at least one rule matches an identifier of the compute instance (the attached service account email address, attached service account UID, instance name, or instance ID):

    gcloud iam workload-identity-pools managed-identities list-attestation-rules \
        MANAGED_IDENTITY_ID \
        --namespace="NAMESPACE_ID" \
        --workload-identity-pool="POOL_ID" \
        --location="global"
    

    Replace the following:

    • MANAGED_IDENTITY_ID: the ID of the managed workload identity.

    • NAMESPACE_ID: the ID of the namespace in the workload identity pool.

    • POOL_ID: the ID of the workload identity pool.

  2. If no rule authorizes the compute instance to receive credentials for the configured identity, update the attestation policy. For instructions, see Define a workload attestation policy with attestation rules.

Managed workload identity isn't authorized to request certificates from the CA pool

When you use a custom CA with Certificate Authority Service, this error occurs if the subordinate CA pool doesn't exist or doesn't grant the required IAM roles to your workload identity pool. The MWLIDExtension logs contain an error message similar to the following:

Please ensure that the CaPool exists and you have authorized the Managed Workload Identity to request certificates from the CaPool.

To resolve this error, do the following:

  1. Confirm that the subordinate CA pool exists and has the required IAM roles granted to the managed workload identities in your workload identity pool:

    gcloud privateca pools get-iam-policy SUBORDINATE_CA_POOL_ID \
        --location="SUBORDINATE_CA_POOL_REGION"
    

    Replace the following:

    • SUBORDINATE_CA_POOL_ID: the ID of the subordinate CA pool.

    • SUBORDINATE_CA_POOL_REGION: the region of the subordinate CA pool.

    The output must contain bindings for the roles/privateca.poolReader and roles/privateca.workloadCertificateRequester roles, similar to the following:

    bindings:
    - members:
      - principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/name/locations/global/workloadIdentityPools/POOL_ID/*
      role: roles/privateca.poolReader
    - members:
      - principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/name/locations/global/workloadIdentityPools/POOL_ID/*
      role: roles/privateca.workloadCertificateRequester
    

    In the preceding output:

    • PROJECT_NUMBER: the project number of the project that contains the workload identity pool.

    • POOL_ID: the ID of the workload identity pool.

  2. If either role binding is missing, grant the required permissions. For instructions, see Authorize managed workload identities to request certificates from the CA pool.

Internal error when fetching workload credentials or trust bundles

If the MWLIDExtension logs contain an INTERNAL error message, such as Failed to fetch Workload Certificates and Private Key. or Failed to fetch Workload Trust Bundles., contact Cloud Customer Care or your Google Cloud contact and include the full error message from the logs.