DEV Community

Kazutora Hattori
Kazutora Hattori

Posted on

[Solved] Cause and solution for "Failed to get Firebase project" when deploying Firebase GitHub Actions

Introduction

Have you ever experienced the following error when attempting to automatically deploy Firebase Hosting using GitHub Actions?

Error: Failed to get Firebase project ***.
Please make sure the project exists and your account has permission to access it.

This error is caused by a mismatch between the service account key and the project ID.
This article provides simple solutions to resolve this issue.

Problem

When attempting to automatically deploy Firebase Hosting using GitHub Actions, an error occurred with the following configuration:

- name: Deploy to Firebase Hosting
run: firebase deploy --only hosting --project ${{ secrets.FIREBASE_PROJECT_ID }}
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/firebase-key.json
Enter fullscreen mode Exit fullscreen mode

The following appears in the log:

Error: Failed to get Firebase project ***.
Please make sure the project exists and your account has permission to access it.
Enter fullscreen mode Exit fullscreen mode

This error essentially means:
"This service account key does not allow access to that project." In other words, the Firebase project ID and the service account's originating project

The cause was a mismatch between these two.

Cause Details

Firebase service accounts have their originating project embedded in them.
You can tell which project it's for by looking at the email address format.

firebase-adminsdk-fbsvc@myproject-12345.iam.gserviceaccount.com
Enter fullscreen mode Exit fullscreen mode

In this case, myproject-12345 is the key's project ID.

On the other hand, suppose you set the following in GitHub Secrets:

Name Value
FIREBASE_PROJECT_ID myproject-99999 (incorrect)
FIREBASE_KEY (Base64 key for another project)

This mismatch causes the error.

→ The Firebase CLI blocks the connection because the key and project ID do not match.

Solution

① Issue the correct service account key

Access the Firebase Console
https://console.firebase.google.com/

Select the relevant project (e.g., kadai5-56bec)

Left menu → Settings → "Project Settings"

Select "Service Accounts" from the top tab

Click "Generate New Private Key" in the "Firebase Admin SDK" section

A JSON file will be downloaded (e.g., firebase-adminsdk-fbsvc.json).

② Convert the service account to Base64 and register it on GitHub

Running Ubuntu / WSL

base64 firebase-adminsdk-fbsvc.json | xsel --clipboard --input

GitHub → Repository →
Settings → Secrets and variables → Actions

Name Value
FIREBASE_KEY = Base64 string copied above
FIREBASE_PROJECT_ID = kadai5-56bec ← Same as the domain portion of the key!
③ Modify GitHub Actions (main.yml)

- name: Setup Firebase Service Account
run: |
echo "${{ secrets.FIREBASE_KEY }}" | base64 -d > ./firebase-key.json
echo "GOOGLE_APPLICATION_CREDENTIALS=${{ github.workspace }}/firebase-key.json" >> $GITHUB_ENV

- name: Deploy to Firebase Hosting
run: firebase deploy --only hosting --project ${{ secrets.FIREBASE_PROJECT_ID }}
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/firebase-key.json
Enter fullscreen mode Exit fullscreen mode

④ Push and retry
git commit --allow-empty -m "Fix: correct Firebase project ID and key"
git push

Example of a successful log
✔ Deploy complete!

Summary

At first glance, this error might seem like a permissions error, but the real cause is a mismatched project ID.

To ensure stable automated deployments with Firebase Hosting,
I believe the most reliable solution is to use a key issued through the official Firebase console.

Top comments (0)