Securing GitHub Actions Workflows with Google Cloud Workload Identity Federation

The integration of continuous integration and continuous deployment (CI/CD) pipelines with cloud infrastructure requires robust, secure authentication mechanisms. As organizations migrate development workflows to GitHub Actions and deploy workloads to Google Cloud Platform (GCP), the management of credentials becomes a critical security concern. The google-github-actions/auth action serves as the primary mechanism for authenticating GitHub Actions workflows to Google Cloud. While traditional methods relying on static Service Account Keys exist, industry best practices strongly recommend the adoption of Workload Identity Federation (WIF). This approach eliminates the need for long-lived credentials, establishing a secure trust delegation relationship between a specific GitHub Actions workflow invocation and the permissions granted on Google Cloud.

Authentication Mechanisms and Security Implications

The google-github-actions/auth action supports three distinct methods for authenticating to Google Cloud, each with varying degrees of security and operational complexity. The first and preferred method is Direct Workload Identity Federation. This method allows the GitHub Actions runner to obtain short-lived credentials directly from Google Cloud based on the identity of the GitHub repository and workflow, without requiring an intermediate service account key to be stored in GitHub Secrets. The second method, Workload Identity Federation through a Service Account, involves using a service account to facilitate the federation but still avoids the direct use of static keys. The third method, Service Account Key JSON, relies on exporting a long-lived credential and storing it as a secret. This method is discouraged because it introduces significant security risks associated with key rotation, potential leakage, and the management of persistent credentials.

Workload Identity Federation is recommended over Service Account Keys because it obviates the need to export a long-lived credential. Instead, it establishes a trust delegation relationship between a particular GitHub Actions workflow invocation and permissions on Google Cloud. This means that access is granted transiently, only for the duration of the workflow run, and is tied to specific conditions such as the repository name and branch. This reduces the attack surface significantly, as there are no static keys to steal or rotate.

It is critical to note that this action is not an officially supported Google product and is not covered by a Google Cloud support contract. Developers seeking bug fixes or feature requests related to Google Cloud products should contact Google Cloud support directly, while issues with the GitHub Action itself are managed through the open-source community.

Operational Requirements and Configuration Constraints

Proper configuration of the auth action is essential for successful authentication and subsequent deployment steps. One of the most critical operational requirements is the ordering of workflow steps. The actions/checkout@v4 step must be executed before the google-github-actions/auth step. Omitting the checkout step or placing it after the authentication step will cause future steps to be unable to authenticate. This dependency exists because the authentication process relies on the presence of the repository code and metadata to validate the federated identity token.

Another critical aspect of configuration involves the management of temporary credential files. During the authentication process, the action may generate temporary credential files, specifically those matching the pattern gha-creds-*.json. To prevent these files from being accidentally committed to version control or included in release artifacts, developers must add this pattern to their .gitignore, .dockerignore, and similar exclusion files. The recommended ignore rule is # Ignore generated credentials from google-github-actions/auth gha-creds-*.json.

Furthermore, users must be aware of tool compatibility. The gsutil command will not use the credentials exported by this GitHub Action. Instead, developers should use gcloud storage for any storage-related operations within their workflows. This distinction is crucial because gsutil often relies on different credential file formats or environment variables that may not align with the short-lived tokens generated by the auth action.

Runtime Environment and Technical Specifications

The google-github-actions/auth action runs using Node 24. This runtime version has implications for the infrastructure used to execute the workflows. If developers are using self-hosted GitHub Actions runners, they must ensure that the runner version supports Node 24 or newer. Using an outdated runner that does not support this Node version will result in authentication failures. This requirement highlights the importance of keeping CI/CD infrastructure up to date with modern runtime environments to support the latest security features and integrations.

The integration is part of the broader suite of Google GitHub Actions, which are verified integrations available on the GitHub Marketplace. The organization google-github-actions controls the domain and has been verified by GitHub, ensuring that the actions provided are maintained by the official team responsible for Google Cloud integrations. This verification adds a layer of trust for users adopting these tools in their production environments.

Implementing Workload Identity Federation

Setting up Workload Identity Federation involves a series of steps in both Google Cloud and GitHub. The process begins in Google Cloud by creating a Workload Identity Pool and a provider within that pool. Attribute mapping is configured to link GitHub-specific attributes, such as the repository name, to Google Cloud identities. This mapping ensures that only specific repositories or branches can authenticate.

Next, a service account is created in Google Cloud, for example, named github-actions-sa. This service account is linked to the identity provider by adding a binding IAM policy. This step is vital because it grants the service account the ability to assume roles based on the identities validated by the provider. The binding can be restricted to a specific repository in GitHub, further enhancing security. The gcloud command can be used to link the service account to the identity provider and restrict authentication to a specific repository.

Once the backend configuration in Google Cloud is complete, the GitHub Actions workflow must be updated to use the federated identity token. The workflow YAML file should include the google-github-actions/auth action with the workload_identity_provider and service_account inputs. For example, the provider might be specified as projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider, and the service account as [email protected].

Deploying to Google Cloud Run

A common use case for authenticated GitHub Actions workflows is deploying applications to Google Cloud Run. The google-github-actions/deploy-cloudrun action facilitates this process by deploying a container image or from source to Cloud Run. The resulting service URL is available as a GitHub Actions output, which can be used in subsequent steps, such as running integration tests or notifying other systems.

This action requires Google Cloud credentials that are authorized to access the secrets and resources being deployed. Like the auth action, it runs using Node 24, requiring compatible self-hosted runners if applicable. The workflow must include the necessary permissions for the GitHub Actions token, specifically contents: 'read' and id-token: 'write'. The id-token: 'write' permission is essential for the Workload Identity Federation to function, as it allows GitHub to sign the JWT token that is exchanged for Google Cloud credentials.

An example workflow configuration demonstrates how these components work together. The auth step is used to authenticate with Google Cloud using the federated identity provider. Then, the deploy-cloudrun step deploys the service. The service ID or fully-qualified identifier is specified in the service input, and the container image to be deployed is specified in the image input. Alternatively, metadata in YAML format can be provided instead of a service ID.

yaml jobs: job_id: permissions: contents: 'read' id-token: 'write' steps: - uses: 'actions/checkout@v4' - uses: 'google-github-actions/auth@v3' with: workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' service_account: '[email protected]' - id: 'deploy' uses: 'google-github-actions/deploy-cloudrun@v3' with: service: 'hello-cloud-run' image: 'us-docker.pkg.dev/cloudrun/container/hello:latest' - name: 'Use output' run: 'curl "${{ steps.deploy.outputs.url }}"'

Testing and Validation

After configuring the workflow, it is essential to test the integration to verify that GitHub Actions successfully authenticates with Google Cloud. This can be done by triggering a GitHub Actions workflow, such as by pushing changes to the main branch or opening a pull request. The workflow will authenticate with Google Cloud using the federated identity token issued by GitHub.

Upon execution, developers should check the GitHub Actions logs to verify successful authentication. The logs will show the key steps where Workload Identity Federation is being used. Specifically, the workload_identity_provider input connects GitHub Actions with Google Cloud’s Workload Identity Pool. The service_account input indicates that short-lived credentials are being obtained via WIF instead of using long-lived service account keys. Additionally, if create_credentials_file: true is set, a temporary file is created for authentication. If export_environment_variables: true is set, environment variables are exported for tools like Terraform to use during infrastructure deployment.

Best Practices for Secure Integration

Implementing Workload Identity Federation with GitHub Actions requires adherence to several best practices to ensure security, efficiency, and scalability. First, always prefer Workload Identity Federation over Service Account Keys to eliminate the risk of credential leakage. Second, ensure that the actions/checkout step is always run before the auth step to prevent authentication failures. Third, strictly manage temporary credential files by adding the gha-creds-*.json pattern to ignore files. Fourth, use gcloud storage instead of gsutil for storage operations to ensure compatibility with the exported credentials. Finally, maintain up-to-date runners that support Node 24 to ensure compatibility with the latest versions of the Google GitHub Actions.

By following these guidelines, organizations can securely integrate GitHub Actions with Google Cloud, enabling robust CI/CD pipelines without the overhead and risks associated with static credentials.

Conclusion

The integration of GitHub Actions with Google Cloud via Workload Identity Federation represents a significant advancement in secure DevOps practices. By eliminating the need for long-lived Service Account Keys and establishing transient, trust-based authentication, organizations can reduce their security risk profile while maintaining high levels of automation. The google-github-actions/auth and google-github-actions/deploy-cloudrun actions provide a robust framework for implementing this integration, provided that developers adhere to strict configuration requirements, such as step ordering, permission settings, and runtime compatibility. As cloud infrastructure continues to evolve, the adoption of federation-based authentication will become the standard for securing CI/CD pipelines, ensuring that access is granted only when and where it is needed.

Sources

  1. Google GitHub Actions Auth
  2. Authenticate to Google Cloud
  3. Setting Up Workload Identity Federation Between GitHub Actions and Google Cloud Platform
  4. Deploy Cloud Run
  5. Google GitHub Actions

Related Posts