Secure GitHub Actions to Google Cloud Integration via Workload Identity Federation

The integration of GitHub Actions with Google Cloud Platform (GCP) represents a critical intersection of continuous integration/continuous deployment (CI/CD) pipelines and cloud infrastructure management. Traditionally, this integration relied on long-lived service account keys, which pose significant security risks due to the potential for credential leakage and the difficulty of rotating static secrets. The modern standard for this integration involves Workload Identity Federation (WIF), a mechanism that establishes a trust delegation relationship between a specific GitHub Actions workflow invocation and permissions on Google Cloud. This approach obviates the need to export long-lived credentials, instead utilizing short-lived tokens issued by GitHub as an identity provider. The google-github-actions organization provides a suite of verified actions within the GitHub Marketplace to facilitate this secure, native integration, covering authentication, SDK setup, and deployment to various Google Cloud services such as Cloud Run, App Engine, and Cloud Functions.

Workload Identity Federation Architecture

Workload Identity Federation is recommended over service account keys because it eliminates the storage of long-lived credentials in version control or secrets management systems. Instead, it creates a trust delegation relationship where GitHub acts as an external identity provider for Google Cloud. This setup allows a GitHub Actions workflow to assume a Google Cloud service account role based on attributes validated by the provider, such as the repository name or branch. There are three primary ways to configure authentication with the google-github-actions/auth action: direct Workload Identity Federation, Workload Identity Federation through a service account, and the legacy method using a Service Account Key JSON. The preferred method is direct federation, which streamlines the authentication process and enhances security by ensuring credentials are ephemeral.

The configuration process begins in Google Cloud by creating a service account, such as github-actions-sa, within the IAM & Admin section of the console. Once created, the service account must be linked to the identity provider through an IAM policy binding. This binding grants the service account the ability to assume roles based on the identities validated by the GitHub provider. The binding is typically restricted to a specific GitHub repository to ensure least-privilege access. For instance, the gcloud command is used to bind the service account to the identity provider and restrict authentication to the intended repository. This step is crucial because it defines the scope of the trust relationship, ensuring that only authorized workflows from specific repositories can assume the service account’s permissions.

Authentication and Credential Management

The google-github-actions/auth action serves as the foundational component for GCP authentication in GitHub workflows. It runs using Node 24 and supports both JSON key and federated identity authentication. When using Workload Identity Federation, the action obtains short-lived credentials rather than static keys. A critical configuration detail is the requirement to run the actions/checkout@v4 step before the auth action. Omitting the checkout step or placing it after authentication will cause subsequent steps to fail because the workflow will be unable to authenticate properly. Additionally, users must be aware that the gsutil command will not utilize the credentials exported by this action; instead, the gcloud storage command must be used for storage operations.

To prevent accidental credential leaks, best practices dictate adding specific patterns to .gitignore, .dockerignore, and similar files. The pattern gha-creds-*.json should be included to ignore generated credentials from the google-github-actions/auth action, preventing them from being committed to release artifacts or binaries. The authentication step can also be configured with the create_credentials_file option set to true, which generates a temporary file used to authenticate requests securely. Furthermore, setting export_environment_variables to true allows tools like Terraform or other infrastructure deployment utilities to utilize the credentials during the deployment process. These temporary credentials are essential for maintaining security while enabling complex CI/CD operations.

Google Cloud SDK Configuration

For workflows that require command-line interface (CLI) interactions with Google Cloud, the google-github-actions/setup-gcloud action is utilized. This action installs the Google Cloud SDK (gcloud) and is required for executing gcloud commands within the workflow. Like the authentication action, it runs using Node 24, necessitating that self-hosted GitHub Actions runners support this version or newer. The action integrates natively with other Google Cloud GitHub Actions, allowing for a cohesive workflow setup.

The setup process involves specifying the version of the Cloud SDK to install. The version parameter is optional and defaults to latest, but it can be set to a specific version string or constraint, such as ">= 363.0.0" or "290.0.1". This flexibility ensures that workflows can pin to specific SDK versions for reproducibility or leverage the latest features. The action requires Google Cloud credentials to execute gcloud commands, which are typically provided by the preceding auth step. A common workflow pattern includes setting up the Cloud SDK and then running a command like gcloud info to verify the setup and output configuration details for debugging purposes.

Deployment to Google Cloud Services

The google-github-actions/deploy-cloudrun action facilitates the deployment of applications to Google Cloud Run. It supports deploying either a container image or from source code. A key feature of this action is that the resulting service URL is available as a GitHub Actions output, which can be referenced in subsequent steps for verification or notification. For example, a workflow can use a curl command to access the URL output by the deploy step, ensuring the service is live and responsive. This action also requires Google Cloud credentials authorized to access any secrets being requested during deployment.

The configuration of the deploy-cloudrun action involves specifying the target entity, which can be a service, a job, or metadata. The service parameter accepts the ID of the Cloud Run service or its fully-qualified identifier. Similarly, the job parameter is used for deploying Cloud Run Jobs. Alternatively, the metadata parameter allows for a complete YAML service description to be provided, offering granular control over the deployment configuration. At least one of these parameters is required, and they are mutually exclusive in the sense that providing metadata negates the need for service or job. The action also runs on Node 24, maintaining consistency with the rest of the suite.

Workflow Permissions and Best Practices

A secure and functional GitHub Actions workflow requires precise permission scopes. For Workload Identity Federation to function, the workflow must have the id-token: 'write' permission. This permission allows GitHub to generate the OIDC token required for authentication with Google Cloud. Additionally, contents: 'read' is necessary for checking out the repository code. These permissions are defined in the permissions block of the workflow job. Without the id-token write permission, the auth action will fail to obtain the federated identity token.

Testing the integration involves triggering the GitHub Actions workflow by pushing changes to the main branch or opening a pull request. Upon execution, the workflow authenticates with Google Cloud using the federated identity token issued by GitHub. Validation is performed by examining the GitHub Actions logs. Successful authentication is indicated by log entries showing the workload_identity_provider connecting GitHub Actions to the Google Cloud Workload Identity Pool, and the service_account assuming the role. Logs should also confirm that create_credentials_file and export_environment_variables are functioning as expected. Following these steps ensures a secure integration that eliminates static service account keys, adhering to modern security best practices.

Supported Integrations and Limitations

The google-github-actions suite is a verified collection of integrations controlled by the organization google-github-actions, which manages the associated domain. The suite supports a wide range of Google Cloud services, including authentication, Cloud Run, App Engine, Cloud Functions, Secret Manager, Cloud Storage, and GKE credentials. This broad coverage allows for comprehensive CI/CD pipelines within the GitHub ecosystem. However, it is important to note that these actions are not officially supported Google products and are not covered by a Google Cloud support contract. For bugs or feature requests related to Google Cloud products themselves, users are directed to contact Google Cloud support directly.

The reliance on Node 24 for execution across multiple actions (auth, setup-gcloud, deploy-cloudrun) underscores the importance of runner compatibility. Users employing self-hosted runners must ensure their environments meet this requirement. Furthermore, the distinction between gsutil and gcloud storage highlights a nuance in credential usage that can trip up developers accustomed to older workflows. Adhering to the specified commands and permissions ensures stability and security in production environments.

Action Primary Function Node Version Key Requirement
google-github-actions/auth Authentication to GCP Node 24 id-token: 'write' permission
google-github-actions/setup-gcloud Install Cloud SDK Node 24 GCP credentials for CLI
google-github-actions/deploy-cloudrun Deploy to Cloud Run Node 24 Authorized GCP credentials

Conclusion

The migration from static service account keys to Workload Identity Federation represents a significant advancement in the security posture of GitHub Actions integrations with Google Cloud. By leveraging the google-github-actions suite, developers can establish robust, ephemeral authentication mechanisms that reduce the attack surface associated with long-lived credentials. The careful configuration of IAM bindings, workflow permissions, and SDK versions ensures that deployments to Cloud Run, App Engine, and other services are both secure and efficient. While these tools are not officially supported by Google Cloud, their widespread adoption and verification by the google-github-actions organization make them a reliable standard for modern cloud-native development workflows. Adhering to best practices, such as ignoring generated credentials and using gcloud storage instead of gsutil, further solidifies the integrity of the CI/CD pipeline.

Sources

  1. Firefly AI Academy: Setting Up Workload Identity Federation
  2. Google GitHub Actions Auth
  3. Google GitHub Actions Deploy Cloud Run
  4. Google GitHub Actions Setup Gcloud
  5. Google GitHub Actions Organization

Related Posts