> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudthinker.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Firebase

> Connect Firebase with a service-account key so CloudThinker can inventory apps, audit security rules, and check deploy state.

Connect Firebase so CloudThinker can list your projects and apps, read SDK configuration, audit Firestore, Storage, and Realtime Database security rules, and check deploy state. Firebase authenticates with a **Google Cloud service-account key** (a JSON file), and the service account's IAM roles decide what CloudThinker can reach.

## Choose Firebase or Google Cloud

| Connection | What it covers | Connect it when |
| - | - | - |
| Firebase | Projects, apps, SDK config, security rules, and deploys, through `firebase-tools` | You want to audit or deploy Firebase apps |
| [Google Cloud](https://docs.cloudthinker.io/guide/connections/gcp.md) | Compute, GKE, BigQuery, IAM, and cost, through the Google Cloud CLI | You want infrastructure, identity, or cost answers |

The two are separate. You can connect both to the same project, each with its own service account.

## Prerequisites

* A Firebase project you want CloudThinker to inspect.
* Permission in that project's Google Cloud to create service accounts and keys and to assign IAM roles.
* Service account key creation allowed. If your organization enforces `constraints/iam.disableServiceAccountKeyCreation` (the default on organizations created since May 2024), ask an organization policy admin for an exception on this project first.

## Setup

Decide first how to cover several projects. Most teams use one connection per project.

| Option | How it works | Best when |
| - | - | - |
| One connection per project | Each project gets its own service account, key, alias, and **Environment**. No switching. | You work across projects often, or want different approval rules per project |
| One service account, many projects | One connection reaches every project the service account can see, but works on one active project at a time. Each switch goes through your approvals. | You mostly work in one project and look at others now and then |

> [!WARNING]
>
> Don't use **Generate new private key** in Firebase **Project settings**. It creates a key for the default `firebase-adminsdk-…@<project-id>.iam.gserviceaccount.com` account, which has broad admin rights and which your own apps may depend on. Don't remove roles from that account either.

> [tab] Google Cloud console
>
> **1. Create a dedicated service account**
>
> In the [Google Cloud console](https://console.cloud.google.com/), select the Firebase project and go to **IAM & Admin → Service Accounts**. Click **Create service account**, name it `cloudthinker-firebase`, and click **Create and continue**.
>
> **2. Grant a read-only Firebase role**
>
> Add **Firebase Viewer** (`roles/firebase.viewer`) and click **Done**. Add a write role only if you want CloudThinker to create apps or deploy through your approvals. See [Required permissions](#required-permissions).
>
> **3. Create a JSON key**
>
> Open the service account, go to the **Keys** tab, and click **Add key → Create new key**. Choose **JSON** and click **Create**.
>
> **Success state:** your browser downloads a `.json` key file.

> [tab] gcloud CLI
>
> Run these in [Cloud Shell](https://shell.cloud.google.com/) or any terminal signed in to Google Cloud.
>
> ```bash theme={null}
> PROJECT_ID=your-firebase-project-id
> SA=cloudthinker-firebase@$PROJECT_ID.iam.gserviceaccount.com
>
> gcloud iam service-accounts create cloudthinker-firebase \
>   --project="$PROJECT_ID" --display-name="CloudThinker Firebase"
>
> gcloud projects add-iam-policy-binding "$PROJECT_ID" \
>   --member="serviceAccount:$SA" --role="roles/firebase.viewer"
>
> gcloud iam service-accounts keys create cloudthinker-firebase-key.json --iam-account="$SA"
> ```
>
> The last command writes the key to `cloudthinker-firebase-key.json`. In Cloud Shell, download it with `cloudshell download cloudthinker-firebase-key.json`, and once it's uploaded to CloudThinker, delete the Cloud Shell copy with `rm cloudthinker-firebase-key.json`. Bind a write role too only if you want CloudThinker to create apps or deploy through your approvals. See [Required permissions](#required-permissions).

Then connect it in CloudThinker:

**1. Open the connect dialog**

In the sidebar, click **More → Workspace settings → Connections**, select **Firebase**, and click **Connect**.

**2. Name the connection**

Fill in **Alias** (for example `prod-firebase`) and **Description** (for example `Production Firebase project, mobile app`). Agents read the description to pick the right connection when you have several.

**3. Upload the key**

Drag the `.json` file onto the upload area, or click **choose a JSON file** to browse for it. Click **Connect**.

**Success state:** the connection shows **Connected**, and the key's `project_id` is the active project. Discovery then runs once in the background and spends credits. It never waits for approval, so it skips project switches and deploy status checks. See [What happens after you connect](https://docs.cloudthinker.io/guide/connections/overview.md#what-happens-after-you-connect).

**4. Set the environment**

Open **Firebase** in **More → Workspace settings → Connections**, click the pencil icon on the connection's row, and set **Environment** in **Edit Instance**. It labels the connection for people and agents.

## Connection details

| Field | What to enter | Example |
| - | - | - |
| **Alias** | Short name for this connection. Blank picks one for you. | `prod-firebase` |
| **Description** | What the project is. Agents use it to choose between connections. | `Production Firebase project` |
| **GOOGLE\_SERVICE\_ACCOUNT\_KEY** | The service account's JSON key file, uploaded. Its `project_id` sets the active Firebase project. | `cloudthinker-firebase-key.json` |

You don't need a separate project ID or a Firebase config file. To cover several projects, see the options in [Setup](#setup).

## Required permissions

| What you want | IAM role on the service account | Approval in CloudThinker |
| - | - | - |
| Inventory projects and apps, read SDK config, audit security rules | Firebase Viewer (`roles/firebase.viewer`) | No |
| Switch the active project | Access to the target project, such as Firebase Viewer there | Through Approvals |
| Check deploy status | Firebase Viewer (`roles/firebase.viewer`) | Through Approvals |
| Create projects, apps, or Android SHA keys, initialize features, deploy | Firebase Admin (`roles/firebase.admin`), or a narrower role for one product, such as Firebase Hosting Admin (`roles/firebasehosting.admin`) or Firebase Rules Admin (`roles/firebaserules.admin`) | Through Approvals |

Google requires more roles for some deploys. A Cloud Functions deploy, for example, also needs Cloud Functions Developer (`roles/cloudfunctions.developer`) and Service Account User (`roles/iam.serviceAccountUser`).

> [!TIP]
>
> Firebase has no **Allow writes** switch. Every change goes through [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md), and it only runs when the IAM role allows it too. Grant Firebase Viewer for audits.

## Agent capabilities

CloudThinker uses the official Firebase CLI (`firebase-tools`) toolset through this connection.

| Capability | What CloudThinker does | Approval |
| - | - | - |
| **Projects and apps** | Lists accessible projects, inspects the active project, lists iOS, Android, and web apps | No |
| **SDK configuration** | Reads the Firebase SDK config for an app | No |
| **Security rules audit** | Reads Firestore, Storage, and Realtime Database rules and flags rules that look open | No |
| **Firebase docs** | Searches Firebase and Google developer documentation | No |
| **Project and app controls** | Switches the active project, creates projects, apps, and Android SHA keys, initializes features, deploys, checks deploy status | Through Approvals |

The connection covers what `firebase-tools` exposes. It doesn't read Firestore documents, Authentication users, Crashlytics, or Remote Config.

### Verify the connection

```text theme={null}
Show my Firebase environment and list the projects you can access
```

The answer names your real `project_id` as the active project.

### Example prompts

```text theme={null}
Audit the Firestore and Storage security rules and flag anything that allows unauthenticated writes
List the apps registered in the active Firebase project as a table
Show the Firebase SDK config for my web app
```

## Troubleshooting

> [accordion] Authentication failed or credentials unavailable
>
> **Cause:** the key JSON is invalid, incomplete, or belongs to a deleted service account.
>
> **Fix:** create a new JSON key for the service account. In **More → Workspace settings → Connections**, open **Firebase**, click the pencil icon on the connection's row, and use **Replace…** in **Edit Instance** to upload it.

> [accordion] CloudThinker says no active project is selected
>
> **Cause:** the error reads `PRECONDITION_FAILED` and mentions the active project. CloudThinker sets the active project from the key's `project_id` each time the connection starts. If the saved key can't be parsed, for example because it was edited before upload, no project is selected. The resource isn't missing.
>
> **Fix:** for this prompt, name the project. Switching the active project goes through your approvals. To fix it for good, create a new JSON key and upload the downloaded file unchanged with **Replace…** in **Edit Instance**.

> [accordion] Permission denied on a project, rules, or deploy
>
> **Cause:** the service account lacks the IAM role for that Firebase product, or the project isn't visible to it.
>
> **Fix:** in **Google Cloud console → IAM**, grant Firebase Viewer for reads and rules, or Firebase Admin (or the narrower role in [Required permissions](#required-permissions)) for creates and deploys. Then retry.

> [accordion] A project doesn't appear in the project list
>
> **Cause:** the service account has no role in that project.
>
> **Fix:** in that project's **Google Cloud console → IAM**, grant the service account Firebase Viewer (`roles/firebase.viewer`), then ask again.

> [accordion] The test shows Timed out
>
> **Cause:** the test didn't finish in time. Firebase endpoints are public, so it's rarely your network.
>
> **Fix:** connect again. If it keeps timing out, [contact us](https://cloudthinker.io/contact).

> [accordion] A create or deploy action didn't run
>
> **Cause:** writes need both an IAM role that allows them and approval in CloudThinker. If you rejected the request, CloudThinker won't retry it.
>
> **Fix:** check the service account's roles, then ask again.

## Security

* **Least privilege** — grant only the permissions the agents need for your use case; start read-only and widen later.
* **Read-only by default** — use read-only credentials unless you want agents to make changes through this connection.
* **Rotate credentials** — rotate keys and tokens on your normal schedule; CloudThinker picks up the new value when you update the connection.
* **Revoke on offboarding** — remove the credential at the provider when you delete a connection or a teammate leaves.

- **Protect the key**: the JSON key is a full credential for the service account. Delete the local copy once it's uploaded, and never commit it or paste it into chat.
- **Rotate the key at least every 90 days**: create a new key, upload it with **Replace…** in **Edit Instance**, then delete the old key. See [Rotate a credential](https://docs.cloudthinker.io/guide/connections/overview.md#rotate-a-credential).

## Related

> [card] [Google Cloud connection](https://docs.cloudthinker.io/guide/connections/gcp.md)
>
> Connect the rest of your Google Cloud project.

> [card] [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md)
>
> Control how approval-gated actions get decided.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.