Skip to content

Firebase Service Account Setup

Sk Niyaj Ali edited this page Dec 25, 2024 · 3 revisions

Table of Contents

  1. Creating a Service Account
  2. Setting up Service Account in CI

Creating a Service Account

Prerequisites

  • Firebase project admin access
  • Google Cloud Console access
  • Project owner or editor role

Steps to Create Service Account

  1. Access Google Cloud Console

    • Go to Google Cloud Console
    • Select your Firebase project
    • Ensure you're using the same project as your Firebase app
  2. Navigate to Service Accounts

    • In the left sidebar, go to "IAM & Admin" > "Service Accounts"
    • Look for the existing Firebase Admin SDK service account or create a new one
  3. Create a New Service Account

    • Click "CREATE SERVICE ACCOUNT"
    • Fill in the details:
      • Name: firebase-ci-service-account
      • ID: Will be auto-generated
      • Description: "Service account for CI/CD deployments"
    • Click "CREATE AND CONTINUE"
  4. Grant Required Permissions

    • Add the following roles:
      • Firebase Admin
      • Firebase App Distribution Admin (if using App Distribution)
      • Firebase Hosting Admin (if using Hosting)
      • Firebase Test Lab Admin (if using Test Lab)
    • Click "CONTINUE"
  5. Generate Key File

    • Click on the newly created service account
    • Go to the "KEYS" tab
    • Click "ADD KEY" > "Create new key"
    • Choose JSON format
    • Click "CREATE"
    • The key file will be automatically downloaded
    • Keep this file secure and never commit it to version control

Setting up Service Account in CI

GitHub Actions Setup

  1. Encode Service Account Key

    On macOS/Linux:

    base64 -i path/to/service-account-key.json

    On Windows (PowerShell):

    [Convert]::ToBase64String([System.IO.File]::ReadAllBytes("path/to/service-account-key.json"))

    Or navigate to the website to encode or decode here

  2. Add to GitHub Secrets

    • Go to your GitHub repository
    • Navigate to Settings > Secrets and variables > Actions
    • Click "New repository secret"
    • Name: FIREBASE_SERVICE_ACCOUNT
    • Value: Paste the Base64 encoded string
    • Click "Add secret"