Eliminating Static Credentials via GCP Workload Identity Federation for GitHub Actions

The integration of Continuous Integration and Continuous Deployment (CI/CD) pipelines with cloud infrastructure has historically relied on the exchange of long-lived credentials, a practice that introduces significant security vulnerabilities. In the context of Google Cloud Platform (GCP) and GitHub Actions, the traditional method involved generating a Service Account Key in JSON format and storing it as a GitHub Secret. While functional, this approach creates a persistent security risk because these JSON keys are long-lived credentials that grant full access to any resource the associated service account is permitted to manage. If such a key is leaked or compromised, the attacker gains indefinite access until the key is manually revoked, creating a catastrophic failure point in the security architecture.

Workload Identity Federation (WIF) represents a paradigm shift in cloud authentication by establishing a trust delegation relationship between an external workload—such as a GitHub Actions workflow invocation—and Google Cloud permissions. Instead of relying on static, exportable secrets, WIF leverages OpenID Connect (OIDC) to enable the dynamic exchange of identity tokens for short-lived GCP credentials at runtime. This mechanism ensures that authentication happens on a per-invocation basis, drastically reducing the attack surface and eliminating the operational overhead associated with manual key rotation and management.

The architectural core of this process is the Workload Identity Pool, which functions as a conceptual bridge. This bridge allows non-GCP systems, including GitHub Actions, GitLab CI/CD, and Bitbucket Pipelines, to authenticate with Google Cloud services without the need for permanent keys. By utilizing OIDC tokens, Google Cloud can verify the identity of the requesting workload at the moment of execution. If the token is validated against predefined trust conditions, GCP IAM maps the external identity to a specific service account, granting the workflow the necessary permissions for a limited duration. Once the workflow execution completes or the token expires, the access is automatically revoked, ensuring that no residual credentials remain in the environment.

The Technical Architecture of OIDC Token Exchange

The operational flow of Workload Identity Federation is a multi-step cryptographic handshake that ensures only authorized workloads can access GCP resources.

The process begins when a Google GitHub Actions workflow is triggered. The workflow first requests an identity token from GitHub’s OpenID Connect (OIDC) provider. This token is not a generic password but a signed assertion containing critical metadata. This metadata includes specific details such as the repository name, the workflow details, and the trigger event that initiated the run. GitHub signs this token to guarantee its integrity, ensuring that the token cannot be tampered with during transit.

Once the workflow possesses the signed OIDC token, it transmits the token to Google Cloud Platform (GCP) IAM for authentication. It is important to note that Google Cloud does not validate the token in isolation. Instead, the request is forwarded to a Workload Identity Pool. The pool acts as the primary validator, evaluating the token against a set of configured trust conditions. These conditions are designed to determine if the request originates from an approved repository, a specific branch, or a verified workflow.

If the token successfully meets all defined trust conditions, GCP IAM performs a mapping operation. The external identity (the GitHub workflow) is mapped to a specific Google Cloud service account. This service account is assigned predefined IAM roles that dictate exactly what actions the workflow can perform within the project. Consequently, GCP generates short-lived credentials that are valid only for the duration of the workflow's execution. This ensures that access is granted strictly on a "just-in-time" basis, removing the risk associated with static keys.

Comparative Analysis: Static Keys vs. Workload Identity Federation

The transition from service account keys to WIF addresses several systemic weaknesses in CI/CD security.

Feature Service Account JSON Keys Workload Identity Federation (WIF)
Credential Lifespan Long-lived (Indefinite until revoked) Short-lived (Temporary runtime tokens)
Storage Method Stored as GitHub Secrets No stored credentials in GitHub
Security Risk High (Key leakage leads to full access) Low (Tokens expire automatically)
Management Overhead High (Requires manual rotation) Low (Automated via OIDC trust)
Auditability Difficult to track specific workflow users High (Identity mapped via OIDC metadata)
Trust Model Secret-based (Possession of key) Identity-based (OIDC verification)

The drawbacks of the legacy approach are manifold. Because service account keys remain valid indefinitely, they require rigorous and frequent rotation through automated key management systems to mitigate risk. Furthermore, if a single key is shared across multiple workflows or different users, it becomes nearly impossible to maintain a granular audit trail of which specific entity accessed a particular Google Cloud resource, thereby increasing the risk of unauthorized internal lateral movement.

Step-by-Step Configuration of Google Cloud for WIF

Configuring Google Cloud to authenticate external systems involves a sequence of administrative steps to establish the trust relationship.

1. Establishing the Workload Identity Pool

The first phase of configuration is the creation of a Workload Identity Pool. This pool serves as the centralized bridge for federating external identities. It allows Google Cloud to recognize and categorize identities coming from third-party providers.

A sample command to initiate a pool with a specific description is as follows:

bash gcloud iam workload-identity-pools create "github-pool" \ --project="my-project" \ --location="global" \ --display-name="GitHub Actions Pool" \ --description="Pool for GitHub Actions OIDC authentication"

2. Configuring the Workload Identity Provider

After the pool is established, a provider must be created within that pool. This provider defines how Google Cloud validates the tokens received from GitHub. This step involves specifying the issuer URI and the attribute mapping, which tells GCP which pieces of information from the GitHub token correspond to GCP identity attributes.

The following command creates the OIDC provider:

bash gcloud iam workload-identity-pools providers create-oidc "github-provider" \ --project="my-project" \ --location="global" \ --workload-identity-pool="github-pool" \ --display-name="GitHub OIDC Provider" \ --issuer-uri="https://token.actions.githubusercontent.com" \ --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository,attribute.repository_owner=assertion.repository_owner" \ --attribute-condition="assertion.repository_owner == 'my-github-org'"

The critical components of this command are explained below:

  • --issuer-uri: This is the official GitHub OIDC token issuer URL, which is https://token.actions.githubusercontent.com.
  • --attribute-mapping: This maps the OIDC claims (assertions) to Google attributes. For example, google.subject=assertion.sub ensures the unique subject of the token is recognized by GCP.
  • --attribute-condition: This is a security filter. In the example above, assertion.repository_owner == 'my-github-org' ensures that only repositories owned by the specified organization can authenticate, preventing any random GitHub repository from attempting to use the pool.

3. Linking the Provider to a Service Account

Once the provider is active, it must be bound to a service account. This is achieved by granting the workloadIdentityUser role to the external identity. This step ensures that the authenticated GitHub workload can actually assume the identity of the service account and inherit its IAM roles.

Implementation in GitHub Actions

To utilize this configuration, the google-github-actions/auth action must be integrated into the workflow YAML file. This action handles the complexity of exchanging the OIDC token for a GCP access token.

Prerequisites for the Workflow

There are strict requirements for the auth action to function correctly:

  • The actions/checkout@v4 step must be executed before the auth action. If the checkout step is omitted or placed after the authentication step, subsequent steps will be unable to authenticate.
  • To prevent the accidental commitment of generated credentials into release artifacts, containers, or pull requests, the following entry must be added to .gitignore and .dockerignore files:

```text

Ignore generated credentials from google-github-actions/auth gha-creds-*.json

```

Authentication Methods Supported

The google-github-actions/auth action supports three distinct methods of authentication, listed in order of preference:

  • Direct Workload Identity Federation: The most secure method, establishing a direct trust delegation.
  • Workload Identity Federation through a Service Account: A hybrid approach using WIF to impersonate a service account.
  • Service Account Key JSON: The legacy method using static keys, which is now discouraged.

It is important to note that this action runs using Node 24.

Troubleshooting and Common Errors

Despite the robustness of WIF, configuration errors can lead to authentication failures. The following common errors must be monitored:

Audience Mismatch Errors

If the workflow returns the error The audience in the token did not match, it indicates that the workload_identity_provider value specified in the GitHub workflow does not match the actual resource name of the provider in GCP. Users must double-check the project number and the full resource path of the provider.

Attribute Condition Failures

The error The attribute condition was not met occurs when the OIDC token is valid, but the request is rejected by the provider's attribute condition. This typically happens if the repository name or the branch does not match the conditions defined during the provider creation (e.g., the token is coming from a fork or a different organization than the one specified in the attribute-condition).

To debug these issues, the provider configuration can be inspected using the following command:

bash gcloud iam workload-identity-pools providers describe github-provider \ --project="my-project" \ --location="global" \ --workload-identity-pool="github-pool" \ --format="yaml(attributeCondition, attributeMapping)"

Critical Tooling Constraints

When using the google-github-actions/auth action, there is a specific constraint regarding the use of the gsutil command. The gsutil tool will not automatically use the credentials exported by this specific GitHub Action. For all storage-related operations, users must utilize the gcloud storage command instead to ensure that the short-lived credentials are correctly applied.

Final Analysis of Security Posture

The migration from static Service Account keys to Workload Identity Federation fundamentally alters the security posture of a CI/CD pipeline. By removing the need to export long-lived credentials, the "secret sprawl" problem—where keys are accidentally committed to version control or leaked through logs—is eliminated.

The trust relationship is now shifted from "what you have" (the JSON key) to "who you are" (the OIDC identity). The use of short-lived tokens ensures that even if a runtime token were somehow intercepted, its utility is extremely limited due to its short expiration window. Furthermore, the ability to define granular attribute-conditions allows administrators to restrict access not just to a project, but to specific repositories and branches, providing a level of precision that was previously impossible with static keys.

Organizations still utilizing service account keys in GitHub secrets should treat the migration to WIF as a high-priority security objective. The operational setup time—approximately 15 minutes—is negligible compared to the risk reduction achieved by removing permanent credentials from the environment.

Sources

  1. Firefly AI Academy
  2. OneUptime Blog
  3. Google GitHub Actions Auth Repository

Related Posts