As per the error seems to be you have given invalid json file of service account which is not parsed by the Git actions workflow. As per this official github :

  1. (Optional) Create a Google Cloud Service Account. If you already have a Service Account, take note of the email address and skip this step :
    # TODO: replace ${PROJECT_ID} with your value below.             
    gcloud iam service-accounts create "my-service-account" \
      --project "${PROJECT_ID}"
  1. Create a Service Account Key JSON for the Service Account.
# TODO: replace ${PROJECT_ID} with your value below.
gcloud iam service-accounts keys create "key.json" \
  --iam-account "my-service-account@${PROJECT_ID}.iam.gserviceaccount.com"
  1. Upload the contents of this file as a GitHub Actions Secret. Use the name of the GitHub Actios secret as the credentials_json value in the GitHub Actions YAML:
 uses: 'google-github-actions/auth@v2'
  with:
      credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' # Replace with the name of your GitHub Actions secret

Can you validate the above steps as per your yaml seems to be you need to give correct service account JSON file and also credentials json format need to be taken care.

---------- or else you can also achieve by using Workload Identity Federation through a Service Account by following this official github

Edit : Sinethemba Nontshintshi, achieved this by Changing the approach and used the Workload Identity Federation through a Service Account method to authenticate, by using this guide on how to set it up in GCP and in the YAML file it is passed as follows :

 - name: Authenticate Google Cloud             
   uses: google-github-actions/auth@v2             
   with: 
     service_account: 'your-service account'              
     workload_identity_provider: 'your-workload-identity-provider'
Answer from Hemanth Kumar on Stack Overflow
🌐
GitHub
github.com › google-github-actions › auth
GitHub - google-github-actions/auth: A GitHub Action for authenticating to Google Cloud. · GitHub
The following inputs are for generating OAuth 2.0 access tokens for authenticating to Google Cloud as an output for use in future steps in the workflow. These options only apply to access tokens generated by this action.
Starred by 1.3K users
Forked by 295 users
Languages   TypeScript 98.8% | JavaScript 1.2%
Top answer
1 of 1
4

As per the error seems to be you have given invalid json file of service account which is not parsed by the Git actions workflow. As per this official github :

  1. (Optional) Create a Google Cloud Service Account. If you already have a Service Account, take note of the email address and skip this step :
    # TODO: replace ${PROJECT_ID} with your value below.             
    gcloud iam service-accounts create "my-service-account" \
      --project "${PROJECT_ID}"
  1. Create a Service Account Key JSON for the Service Account.
# TODO: replace ${PROJECT_ID} with your value below.
gcloud iam service-accounts keys create "key.json" \
  --iam-account "my-service-account@${PROJECT_ID}.iam.gserviceaccount.com"
  1. Upload the contents of this file as a GitHub Actions Secret. Use the name of the GitHub Actios secret as the credentials_json value in the GitHub Actions YAML:
 uses: 'google-github-actions/auth@v2'
  with:
      credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' # Replace with the name of your GitHub Actions secret

Can you validate the above steps as per your yaml seems to be you need to give correct service account JSON file and also credentials json format need to be taken care.

---------- or else you can also achieve by using Workload Identity Federation through a Service Account by following this official github

Edit : Sinethemba Nontshintshi, achieved this by Changing the approach and used the Workload Identity Federation through a Service Account method to authenticate, by using this guide on how to set it up in GCP and in the YAML file it is passed as follows :

 - name: Authenticate Google Cloud             
   uses: google-github-actions/auth@v2             
   with: 
     service_account: 'your-service account'              
     workload_identity_provider: 'your-workload-identity-provider'
Discussions

google-github-actions/auth@v2 Cannot Parse Google Service Account Key From Secret Manager
Hello! I am building an expo app and at this point I have a yml file for my pipeline which builds eas successfully, but upon submission, I get an error of eas submit seeing my pub/priv key which is part of the Google Service Account json secret. This is a github repository secret. More on discuss.google.dev
🌐 discuss.google.dev
0
0
October 1, 2024
Using GitHub Actions to authenticate to Google Workload Identity Federation for credentials to use in a Python script - Stack Overflow
name: name_of_your_job on: workflow_dispatch: jobs: build: permissions: contents: 'read' id-token: 'write' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - id: 'auth' name: 'Authenticate to Google Cloud' uses: 'google-github-actions/auth@v2' with: workload_identity_provider: ... More on stackoverflow.com
🌐 stackoverflow.com
google-github-actions/auth@v2 Cannot Parse Google Service Account Key From Secret Manager
Here are a few things to try, if you’re trying to authenticate using a service account key that’s stored as a secret in your GitHub repo. Can you confirm that your service account key is stored in a GitHub Actions secret within your GitHub repo in the following format? More on googlecloudcommunity.com
🌐 googlecloudcommunity.com
0
0
October 1, 2024
google-github-actions/auth failed with did not inject $ACTIONS_ID_TOKEN_REQUEST_TOKEN or $ACTIONS_ID_TOKEN_REQUEST_URL - Stack Overflow
In github actions I'm running an action that is trying to use github to GCP federated id: # see https://github.com/marketplace/actions/authenticate-to-google-cloud#setup - id: 'auth' nam... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › google-github-actions › setup-gcloud
GitHub - google-github-actions/setup-gcloud: A GitHub Action for installing and configuring the gcloud CLI. · GitHub
jobs: job_id: # Add "id-token" with the intended permissions. permissions: contents: 'read' id-token: 'write' steps: - id: 'auth service account 1' uses: 'google-github-actions/auth@v2' with: workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' service_account: 'service-account-1@my-project.iam.gserviceaccount.com' - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v3' - name: 'Use gcloud CLI' run: 'gcloud auth list --filter=status:ACTIVE --format="value(account)"' # service-account-1@my-project.iam.gserviceacco
Starred by 1.9K users
Forked by 527 users
Languages   TypeScript 95.3% | JavaScript 4.7%
🌐
Google Cloud
cloud.google.com › blog › products › identity-security › enabling-keyless-authentication-from-github-actions
Enabling keyless authentication from GitHub Actions | Google Cloud Blog
December 7, 2021 - But now, with GitHub's introduction of OIDC tokens into GitHub Actions Workflows, you can authenticate from GitHub Actions to Google Cloud using Workload Identity Federation, removing the need to export a long-lived JSON service account key.
🌐
GitHub
github.com › marketplace › actions › authenticate-to-google-cloud
Authenticate to Google Cloud · Actions · GitHub Marketplace · GitHub
The following inputs are for generating OAuth 2.0 access tokens for authenticating to Google Cloud as an output for use in future steps in the workflow. These options only apply to access tokens generated by this action.
🌐
Firefly
firefly.ai › academy › setting-up-workload-identity-federation-between-github-actions-and-google-cloud-platform
Firefly | Setting Up Workload Identity Federation Between GitHub Actions and Google Cloud Platform
name: 'Terraform' on: push: branches: ... the repository to the GitHub Actions runner - name: Checkout uses: actions/checkout@v3 - id: auth uses: google-github-actions/auth@v2.0.0 with: workload_identity_provider: 'projects/583679955132/locations/global/workloadIdentityPools/gith...
🌐
Google
discuss.google.dev › google cloud › serverless applications
google-github-actions/auth@v2 Cannot Parse Google Service Account Key From Secret Manager - Serverless Applications - Google Developer forums
October 1, 2024 - Hello! I am building an expo app and at this point I have a yml file for my pipeline which builds eas successfully, but upon submission, I get an error of eas submit seeing my pub/priv key which is part of the Google Service Account json secret. This is a github repository secret.
Find elsewhere
🌐
Tridnguyen
tridnguyen.com › articles › set-up-google-cloud-workload-identity-federation-for-github-actions
Set up Google Cloud Workload Identity Federation for GitHub Actions | Tri Nguyen
- id: auth uses: google-github-actions/auth@v2 with: workload_identity_provider: projects/xxx/locations/global/workloadIdentityPools/github/providers/github-tnguyen14 service_account: [email protected]
🌐
Littlerobots
littlerobots.nl › blog › google-cloud-workflow-identity-federation-with-github-actions
GCP workflow identity federation w/ Github actions...for the rest of us
- name: "Setup GCP auth" uses: "google-github-actions/auth@v2" id: auth with: token_format: "access_token" project_id: "your-project-id" workload_identity_provider: "projects/123456789/locations/global/workloadIdentityPools/github/providers/github" service_account: "github@your-project-id.iam.gserviceaccount.com"
🌐
Alexander Hose
alexanderhose.com › how-to-integrate-github-actions-with-google-cloud-platform
How to Integrate GitHub Actions with Google Cloud Platform
April 11, 2025 - Here's the complete GitHub Actions workflow configuration: name: Deploy code to GCP on: push: branches: [ "main" ] pull_request: branches: [ "main" ] workflow_dispatch: jobs: build: runs-on: ubuntu-latest permissions: id-token: write contents: read steps: - name: 'Checkout code' uses: 'actions/checkout@v2' - name: 'Authenticate with GCP' id: auth uses: 'google-github-actions/auth@v2' with: project_id: 'security-alexanderhose' workload_identity_provider: 'projects/243190957191/locations/global/workloadIdentityPools/github-actions-provider/providers/github-actions-pool' - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v2' - name: 'Describe Secrets' run: | gcloud secrets describe "my-secret" --project="security-alexanderhose"
🌐
CICube
cicube.io › home › workflow hub › how to authenticate to google cloud from github actions
How to Authenticate to Google Cloud from GitHub Actions - Workflow Hub - CI Cube
May 23, 2024 - name: 'Usage of auth GitHub Action' on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: 'google-github-actions/auth@v2' with: project_id: 'my-project' workload_identity_provider: > 'projects/12/locations/global/workloadIdentityPools/po...
Top answer
1 of 1
1

Issue with Google Drive API Authentication using GitHub Actions

I created my workload identity pool according to the Google GitHub Actions Auth documentation without any service account. Then I tried to connect to Google Drive, which requires an OAuth 2.0 access token. I used the following configuration:

- name: Authenticate with Google Cloud
    uses: 'google-github-actions/auth@v2'
    with:
        project_id: 'my-project'
        workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'

- name: Upload files to Google Drive
    uses: 'Burak-Atak/drive-upload@master'
    with:
      google_credentials_file_path: ${{ env.GOOGLE_APPLICATION_CREDENTIALS }}
      files_to_create: "app.spec"
      drive_folder_id: "242fgdfg345345"
      files_to_update: "requirements.txt"
      file_ids_to_update: "asdas3534fdgg"

However, I got the following error with below code:

def authenticate_google(self):
    credentials, project_id = load_credentials_from_file(
        os.environ["GOOGLE_APPLICATION_CREDENTIALS"],
        scopes=[
            'https://www.googleapis.com/auth/drive.file',
            'https://www.googleapis.com/auth/drive',
            'https://www.googleapis.com/auth/drive.metadata'
        ]
    )

    return build("drive", "v3", credentials=credentials)
googleapiclient.errors.HttpError: <HttpError 401 when requesting https://www.googleapis.com/upload/drive/v3/files?fields=id&alt=json&uploadType=multipart returned "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.". Details: "[{'message': 'Invalid Credentials', 'domain': 'global', 'reason': 'authError', 'location': 'Authorization', 'locationType': 'header'}]">

I realized I should use OAuth 2.0 for the Google Drive API. Then I changed my configuration to this:

- name: Authenticate with Google Cloud
  uses: google-github-actions/auth@v2
  with:
    workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
    project_id: '<PROJECT_ID>'
    service_account: '<PROJECT_ID>@<PROJECT_ID>.iam.gserviceaccount.com'
    token_format: 'access_token'
    access_token_lifetime: '60s'
    access_token_scopes: 'https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/drive.metadata'

- name: Upload files to Google Drive
    uses: 'Burak-Atak/drive-upload@master'
    with:
      google_credentials_file_path: ${{ env.GOOGLE_APPLICATION_CREDENTIALS }}
      files_to_create: "app.spec"
      drive_folder_id: "242fgdfg345345"
      files_to_update: "requirements.txt"
      file_ids_to_update: "asdas3534fdgg"

After this change, I started to get the following error even though I have the Service Account Token Creator and Owner roles in my service account:

google-github-actions/auth failed with: failed to generate Google Cloud OAuth 2.0 Access Token for <PROJECT_ID>@<PROJECT_ID>.iam.gserviceaccount.com: {
  "error": {
    "code": 403,
    "message": "Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist).",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "IAM_PERMISSION_DENIED",
        "domain": "iam.googleapis.com",
        "metadata": {
          "permission": "iam.serviceAccounts.getAccessToken"
        }
      }
    ]
  }
}

Solution

I figured out that I should add a service account to my workload pool. Check the "Connected service accounts" part in the Google Cloud Console. If there is no connected service account, you should add one.

🌐
Medium
mahendranp.medium.com › gcp-workload-identity-federation-with-github-actions-1d320f62417c
GCP: Enabling keyless authentication from GitHub Actions | by Mahendran | Medium
March 4, 2024 - build: runs-on: ubuntu-latest environment: dev # Fetches the env variables for dev permissions: contents: read id-token: write steps: - name: Checkout actions-oidc-debugger uses: actions/checkout@v3 - id: auth name: Authenticate to Google Cloud uses: google-github-actions/auth@v2 with: create_credentials_file: true workload_identity_provider: '${{ vars.WORKLOAD_IDENTITY_PROVIDER }}' service_account: '${{ secrets.SERVICE_ACCOUNT }}' - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v2 - name: set credentials file run: >- gcloud auth login --cred-file=${{steps.auth.outputs.credentials_file_path}} - name: Use gcloud CLI run: gcloud info - id: upload-file uses: google-github-actions/upload-cloud-storage@v2 with: path: CHANGELOG.md destination: '${{ vars.GCP_BUCKET }}' process_gcloudignore: false
🌐
GitHub
github.com › sethvargo › oidc-auth-google-cloud › releases
Releases · google-github-actions/auth
August 28, 2025 - Release: v2.1.13 by @google-github-actions-bot in #507 · Full Changelog: v2.1.12...v2.1.13 · sethvargo and google-github-actions-bot · Assets 2 · Loading · There was an error while loading. Please reload this page. 1 person reacted · 29 Nov 03:52 · sethvargo · v2 ·
Author   google-github-actions
🌐
Google Cloud
googlecloudcommunity.com › google cloud › serverless applications
google-github-actions/auth@v2 Cannot Parse Google Service Account Key From Secret Manager - #2 by David-French - Serverless Applications - Google Developer forums
October 1, 2024 - Here are a few things to try, if you’re trying to authenticate using a service account key that’s stored as a secret in your GitHub repo. Can you confirm that your service account key is stored in a GitHub Actions secret within your GitHub repo in the following format?
🌐
Medium
medium.com › google-cloud › ci-cd-on-github-actions-enabling-keyless-authentication-and-workload-identity-f55efb95343c
CI CD Github Actions enabling Keyless Authentication Workload Identity | Google Cloud - Community
April 29, 2024 - We need to pass the permissions ... google-github-actions/auth action, allows to authenticate the current repository to Google Cloud via the Workload Identity Provider and the associated Service Account...
🌐
GitHub
github.com › google-github-actions › auth › blob › main › docs › EXAMPLES.md
auth/docs/EXAMPLES.md at main · google-github-actions/auth
Future authentication calls will be made with the Service Account's OAuth 2.0 Access token. jobs: job_id: permissions: contents: 'read' id-token: 'write' - uses: 'google-github-actions/auth@v3' with: project_id: 'my-project' workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' service_account: 'my-service-account@my-project.iam.gserviceaccount.com' # NOTE: 'steps.auth.outputs.auth_token' will be a federated authentication # token, it does not correspond to the service account.
Author   google-github-actions
🌐
GitHub
github.com › google-github-actions › auth › blob › main › README.md
auth/README.md at main · google-github-actions/auth
The following inputs are for generating OAuth 2.0 access tokens for authenticating to Google Cloud as an output for use in future steps in the workflow. These options only apply to access tokens generated by this action.
Author   google-github-actions