Securing Google Cloud Integrations in GitHub Actions: Workload Identity, SDK Configuration, and Gemini CLI

The integration of Google Cloud services into GitHub Actions workflows represents a critical intersection of DevOps automation and identity management. As organizations migrate toward serverless architectures and automated CI/CD pipelines, the method by which these pipelines authenticate with Google Cloud infrastructure determines both the security posture and operational efficiency of the development lifecycle. The primary tools facilitating this integration are the google-github-actions/auth and google-github-actions/setup-gcloud actions, alongside emerging AI-driven workflows like Gemini CLI. These tools are not officially supported Google products covered by a standard support contract; rather, they are community-driven, open-source solutions that require users to contact Google Cloud support for broader product issues. Understanding the nuances of authentication methods, credential handling, and environment configuration is essential for preventing security incidents and ensuring reliable deployment.

Authentication Strategies and Security Posture

The core challenge in automating cloud infrastructure is establishing trust without exposing long-lived secrets. The google-github-actions/auth action provides three distinct methods for authenticating to Google Cloud, with a strong recommendation toward Workload Identity Federation (WIF) over traditional Service Account Keys. Workload Identity Federation obviates the need to export and manage long-lived credentials, instead establishing a trust delegation relationship between a specific GitHub Actions workflow invocation and permissions on Google Cloud. This approach drastically reduces the risk of credential compromise, a principle recently emphasized in the introduction of Gemini CLI GitHub Actions, which leverages WIF to eliminate the need for long-lived API keys entirely.

The preferred method, Direct Workload Identity Federation, allows the GitHub Actions runner to authenticate directly using an OIDC token. When this method is used, the action generates a token that Google Cloud validates against a configured Workload Identity Pool and Provider. The configuration requires specifying the workload_identity_provider input, which follows the format projects/PROJECT_ID/locations/global/workloadIdentityPools/POOL_ID/providers/PROVIDER_ID. If the service_account input is omitted, the action defaults to this direct federation method.

An alternative is Workload Identity Federation through a Service Account. In this scenario, the service_account input is explicitly provided. This input expects a string such as [email protected]. When this input is present, the GitHub Action uses Workload Identity Federation to impersonate the specified service account, rather than authenticating directly. This allows for more granular control over which service account permissions are utilized during the workflow.

The legacy method, Service Account Key JSON, involves storing a JSON key file as a GitHub Secret. This method is discouraged due to the inherent risks of long-lived credentials. Service Account Keys must be treated like passwords. To use this method, the credentials_json input is required. It is advisable to minify the JSON into a single-line string before storing it in a GitHub Secret. GitHub Actions masks secrets in logs, but aggressive sanitization can occur with benign characters like curly braces {} and brackets [] if the secret is multi-line. Furthermore, to generate access tokens or ID tokens using a service account key, the underlying service account must be granted the roles/iam.serviceAccountTokenCreator permission on itself.

Environment Configuration and SDK Setup

Authentication is only the first step; the authenticated identity must be properly configured for the tools that execute the workflow. The google-github-actions/setup-gcloud action is responsible for installing and configuring the Google Cloud SDK (gcloud). This action requires Google Cloud credentials to execute gcloud commands and relies on the preceding auth action to set Application Default Credentials. The setup-gcloud action then references these credentials to configure gcloud properly.

Both the auth and setup-gcloud actions run on Node 24. For users employing self-hosted GitHub Actions runners, it is mandatory to use a runner version that supports Node 24 or newer. The setup-gcloud action allows for the specification of the Cloud SDK version via the version input. This input accepts a string representing the version or a version constraint, such as "290.0.1" or ">= 197.0.1". If not specified, it defaults to latest.

A critical operational detail involves the order of workflow steps. The actions/checkout@v4 step must be executed before the auth action. The auth action exports credentials to the $GITHUB_WORKSPACE directory. GitHub Actions creates this workspace directory during the checkout step. If the checkout step is omitted or placed after the auth step, the action will fail to export credentials, causing subsequent steps to be unable to authenticate.

The auth action includes several optional parameters that control environment variable exportation and credential file generation. The create_credentials_file parameter, which defaults to true, instructs the action to securely generate a credentials file. This file is exported to $GITHUB_WORKSPACE and is available to all future steps, including Docker-based actions. The file is automatically removed at the end of the job via a post action. The export_environment_variables parameter, also defaulting to true, exports common environment variables consumed by popular downstream libraries. These include CLOUDSDK_PROJECT, CLOUDSDK_CORE_PROJECT, GCP_PROJECT, GCLOUD_PROJECT, and GOOGLE_CLOUD_PROJECT. If create_credentials_file is true, additional variables are exported: CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE, GOOGLE_APPLICATION_CREDENTIALS, and GOOGLE_GHA_CREDS_PATH. Setting export_environment_variables to false prevents the export of any environment variables, meaning future steps will not be automatically authenticated.

Workflow Implementation and Credential Management

Proper implementation requires careful attention to permissions, secret management, and artifact hygiene. When using Workload Identity Federation, the job permissions must include id-token: 'write' to allow the generation of OIDC tokens. The contents: 'read' permission is also required for standard checkout operations.

yaml jobs: job_id: permissions: contents: 'read' id-token: 'write' steps: - id: 'auth' uses: 'google-github-actions/auth@v2' with: workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' service_account: '[email protected]' - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v3' with: version: '>= 363.0.0' - name: 'Use gcloud CLI' run: 'gcloud info'

When using Service Account Keys, the workflow relies on GitHub Secrets. The service account key must be created using the Google Cloud CLI.

```bash
gcloud iam service-accounts create "my-service-account" \
--project "${PROJECT_ID}"

gcloud iam service-accounts keys create "key.json" \
--iam-account "my-service-account@${PROJECT_ID}.iam.gserviceaccount.com"
```

The contents of the generated key.json file are then uploaded as a GitHub Actions Secret. In the workflow YAML, the secret is referenced as follows:

yaml - uses: 'google-github-actions/auth@v3' with: credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'

A significant security risk arises when creating binaries, containers, or release artifacts. Credentials generated by the auth action are saved in files named gha-creds-*.json. To prevent accidentally committing these credentials to release artifacts, these files must be ignored in .gitignore, .dockerignore, and similar configuration files.

Integration Ecosystem and Gemini CLI

The auth and setup-gcloud actions serve as foundational components for a broader ecosystem of Google Cloud GitHub Actions. Once authenticated and configured, workflows can natively integrate with actions to deploy Cloud Run services, deploy App Engine apps, deploy Cloud Functions, access Secret Manager secrets, upload to Cloud Storage, and configure GKE credentials. Additionally, the bq tool can be used for BigQuery operations.

For users operating on self-hosted runners hosted on Google Cloud Platform, credentials are automatically obtained from the service account attached to the runner, simplifying the authentication configuration. However, a critical compatibility note exists regarding command-line tools: the gsutil command does not use the credentials exported by the auth action. Users must use gcloud storage instead for storage operations within their workflows.

The introduction of Gemini CLI GitHub Actions expands the capabilities of this ecosystem by incorporating AI-driven development assistance. Built with enterprise-grade security, Gemini CLI supports secure, credential-less authentication via Workload Identity Federation. It offers granular control through multi-layered controls, such as command allowlisting, which explicitly approves every shell command the agent can execute. Organizations can create custom identities for the agent, such as gemini-for-your-org, and grant only the precise permissions required. Transparency is maintained through integration with OpenTelemetry, allowing logs and metrics to be streamed to observability platforms like Google Cloud Monitoring.

Conclusion

The configuration of Google Cloud authentication within GitHub Actions requires a deliberate choice between security best practices and legacy convenience. Workload Identity Federation stands as the superior method, eliminating the risks associated with long-lived service account keys and aligning with modern zero-trust principles. Proper implementation necessitates strict adherence to step ordering, particularly ensuring that the checkout action precedes authentication to facilitate credential file export. Furthermore, developers must be aware of tool-specific limitations, such as the incompatibility of gsutil with the generated credentials, and the need to sanitize release artifacts from temporary credential files. As the ecosystem evolves with the inclusion of AI-driven tools like Gemini CLI, the emphasis on credential-less authentication, granular permission controls, and transparent observability will continue to define the standard for secure, automated cloud development.

Sources

  1. google-github-actions/auth
  2. google-github-actions/setup-gcloud
  3. Introducing Gemini CLI GitHub Actions

Related Posts