Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed with: failed to parse service account key JSON credentials: unexpected token #465

Closed
steezeburger opened this issue Jan 31, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@steezeburger
Copy link

TL;DR

I followed the docs and included my credentials json as a one line secret in an environment for my github action, yet I get this error

Error: google-github-actions/auth failed with: failed to parse service account key JSON credentials: unexpected token '�', "�*^���ǿi�("... is not valid JSON

Expected behavior

For it to accept the json in the secret

Observed behavior

It did not accept the json in the secret

Action YAML

name: Deploy to Google Cloud Functions

on:
  push:
    branches:
      - main  # or your default branch
  workflow_dispatch:  # allows manual triggers

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: cicd
    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '>=22.0.0'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - id: 'auth'
        uses: google-github-actions/auth@v2
        with:
          credentials_json: '${{ secrets.GCP_SA_KEY }}'
          project_id: ${{ vars.GCP_PROJECT_ID }}

      - name: Setup Google Cloud SDK
        uses: google-github-actions/setup-gcloud@v2
        with:
          project_id: ${{ vars.GCP_PROJECT_ID }}

      - name: Deploy to Cloud Run Functions
        run: |
          just deploy

Log output

Run google-github-actions/auth@v2
  with:
    credentials_json: ***
    project_id: swap-routing-api-dev
    create_credentials_file: true
    export_environment_variables: true
    universe: googleapis.com
    cleanup_credentials: true
    access_token_lifetime: 3600s
    access_token_scopes: https://www.googleapis.com/auth/cloud-platform
    id_token_include_email: false
Error: google-github-actions/auth failed with: failed to parse service account key JSON credentials: unexpected token '�', "�*^���ǿi�("... is not valid JSON

Additional information

No response

@steezeburger steezeburger added the bug Something isn't working label Jan 31, 2025
Copy link

Hi there @steezeburger 👋!

Thank you for opening an issue. Our team will triage this as soon as we can. Please take a moment to review the troubleshooting steps which lists common error messages and their resolution steps.

@steezeburger
Copy link
Author

steezeburger commented Jan 31, 2025

My issue was caused because the json was wrapped in single quotes in the secret value. I think they did not play well with the single quotes in the example usage, i.e. credentials_json: '${{ secrets.GCP_SA_KEY }}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant