Chapter 14 · IAM, Admin/Server SDKs, Service Accounts, Authentication, and Trust Boundaries

Workload Identity / Service Accounts, Keyless Credentials, Secrets, Rotation, and Local Development

Design keyless workload authentication with ADC, attached service identities and Workload Identity Federation while keeping service-account keys out of client and routine local workflows.

Intermediate → Advanced150–180 minutesADC · workload identity · keyless authFirebase JS 12.19.0 · Admin 14.4.0 · CLI 15.30.0 · Rules tests 5.0.2Last reviewed: September 2026

1. Credentials are deployment architecture, not a JSON file

Execution and safety note

Use the Emulator Suite, a Firebase demo project, or an isolated test project for destructive, security-sensitive, billing-sensitive, migration, backup/restore, or write-heavy exercises unless the lesson explicitly marks managed verification as required. Treat shown output as expected evidence unless it is explicitly identified as captured output, and re-check current Firebase/Google Cloud edition, mode, quota, pricing, and security documentation before production execution.

A common tutorial initializes the Admin SDK with a downloaded service-account key and stops there. That is convenient but operationally dangerous: a long-lived private key can be copied, committed, leaked in a support bundle or shipped into a container image. Modern Google Cloud authentication provides safer ways for workloads and developers to obtain short-lived credentials without owning a persistent key file.

Chapter 14 reproducibility baseline · reviewed 16 September 2026

AtlasMart continues the same mandatory environment used in Chapters 01–13: project ID demo-atlasmart-firestore, Standard edition / Native mode / (default) database, Firestore emulator 127.0.0.1:8080, Authentication emulator 127.0.0.1:9099, Emulator UI 127.0.0.1:4000, Firebase CLI 15.30.0, Firebase JavaScript SDK 12.19.0, Firebase Admin Node.js SDK 14.4.0 carrying @google-cloud/firestore 9.1.0, @firebase/rules-unit-testing 5.0.2, and Node.js 22+. Mandatory work remains local/no-cost. Standard Native Core is the canonical lab; Enterprise Native Core/Pipeline and MongoDB compatibility differences are called out explicitly.

Trust boundary that must not be blurred

A Firebase Authentication ID token represents an end user. A Google Cloud access token or attached service account represents a workload. Firestore mobile/web SDK calls are authorized by Security Rules using request.auth; Admin/server libraries bypass those Rules and are authorized with IAM. If a backend receives a user ID token, verifying that token establishes user identity only—the backend must still make its own application authorization decision before using its more powerful workload identity. App Check, when enabled, is an additional app/device attestation signal and does not replace either user authorization or IAM.

Pinned versions and current release check

Firebase CLI 15.30.0 was released 9 September 2026. Firebase Admin Node.js 14.4.0 was released 10 September 2026, requires Node.js 22+, and uses @google-cloud/firestore 9.1.0. The Auth emulator issues unsigned ID tokens for local testing; Admin SDK accepts those only when FIREBASE_AUTH_EMULATOR_HOST is explicitly configured. Never carry that emulator environment variable into production.

Learning outcomes

01

Explain Application Default Credentials as credential discovery, not as one credential type.

02

Use attached service identities or Workload Identity Federation in production instead of service-account keys whenever practical.

03

Distinguish local user ADC, service-account impersonation, external workload federation and JSON keys by risk and lifecycle.

04

Keep emulator-only development credential-free and prevent emulator environment variables from leaking into production.

05

Design rotation/revocation and secret handling around independent workload identities.

2. How ADC chooses credentials

Application Default Credentials (ADC) is a standard way for Google-authenticated client libraries to locate credentials. In simplified priority order, ADC can use credentials pointed to by GOOGLE_APPLICATION_CREDENTIALS, a well-known local ADC file created by tooling, or credentials supplied by the runtime metadata service/attached identity. The safe architecture chooses the source deliberately rather than hoping the library finds “something that works.”

Environment Preferred pattern Credential lifetime / custody Risk note
Firestore emulator No Google Cloud credential None Best mandatory lab path
Developer workstation User ADC; service-account impersonation when service parity is needed Short-lived tokens derived from user auth Keep personal/user privileges narrow and auditable
Google Cloud runtime Attach a user-managed service account / service identity Platform-provided short-lived credentials Avoid default overprivileged identity
External cloud/on-prem/GitHub/GitLab Workload Identity Federation Short-lived federated credentials Avoid persistent Google service-account keys
Legacy environment with no federation path Service-account key as last resort Long-lived private key until rotated/revoked High custody burden; protect and rotate aggressively

3. Mandatory lab: prove the emulator path needs no cloud credential

local and production credential posture
# Mandatory emulator path: no Google Cloud credentials are needed.export FIRESTORE_EMULATOR_HOST="127.0.0.1:8080"export FIREBASE_AUTH_EMULATOR_HOST="127.0.0.1:9099"export GCLOUD_PROJECT="demo-atlasmart-firestore"node backend-path.test.mjs# Optional real-project local development, only in an isolated project:# gcloud auth application-default login# Prefer user ADC or service-account impersonation over downloading a JSON key.# Never do this in browser code or commit the referenced file:# export GOOGLE_APPLICATION_CREDENTIALS="./service-account-key.json"
backend/admin.js · emulator-safe initialization
// Never ship this module to a browser bundle.process.env.FIRESTORE_EMULATOR_HOST = "127.0.0.1:8080";process.env.FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099";process.env.GCLOUD_PROJECT = "demo-atlasmart-firestore";import { initializeApp } from "firebase-admin/app";import { getAuth } from "firebase-admin/auth";import { getFirestore } from "firebase-admin/firestore";initializeApp({ projectId: "demo-atlasmart-firestore" });export const adminAuth = getAuth();export const adminDb = getFirestore();

With both emulator host variables configured, the Admin SDK talks to local emulators. This is precisely why mandatory labs do not ask learners to create or download service-account keys. The emulator trust model is not production IAM; it is a deterministic local environment for application behavior.

Critical production guardrail

The Auth emulator accepts unsigned test ID tokens only when the Admin SDK is explicitly configured for the emulator. Never set FIREBASE_AUTH_EMULATOR_HOST in production. Production Firebase services reject emulator tokens.

4. Workload Identity Federation: exchange external identity for short-lived Google credentials

Workload Identity Federation (WIF) allows an external workload—such as a CI job, AWS/Azure workload or OIDC-capable platform—to authenticate using its native identity and obtain short-lived Google credentials. The key security improvement is that the external environment does not need a persistent service-account private key.

Property Service-account JSON key Workload Identity Federation
Secret at rest Private key file exists No long-lived Google private key required
Rotation Operator/process must rotate key Short-lived credentials are minted as needed
Attribution All holders impersonate same key identity Can preserve external subject/provider attributes in policy/audit design
Leak impact Key can remain usable until revoked/expired by policy Short-lived token and federation trust/configuration bound exposure
Setup complexity Low initially Higher initial configuration, lower key custody burden

5. Service accounts are resources; keys are credentials

Do not confuse a service account with a service-account key. A service account is an IAM principal/resource. It can be attached to a Google Cloud runtime or impersonated/federated without a downloadable private key. Keyless operation therefore does not mean “no service account”; it means the workload obtains short-lived credentials through a trusted platform/federation flow.

optional isolated-cloud IAM sketch · not part of mandatory lab
PROJECT_ID="YOUR_ISOLATED_PROJECT"SA="atlasmart-orders-api@${PROJECT_ID}.iam.gserviceaccount.com"# Create one workload identity for one service responsibility.gcloud iam service-accounts create atlasmart-orders-api   --project="$PROJECT_ID"   --display-name="AtlasMart orders API"# roles/datastore.user permits Firestore entity read/write operations.# It is still broader than per-customer authorization; application code must enforce that.gcloud projects add-iam-policy-binding "$PROJECT_ID"   --member="serviceAccount:${SA}"   --role="roles/datastore.user"# Inspect exactly what the principal has before deployment.gcloud projects get-iam-policy "$PROJECT_ID"   --flatten="bindings[].members"   --filter="bindings.members:serviceAccount:${SA}"   --format="table(bindings.role)"

6. Wrong approach: ship a service-account JSON file with the app

never do this
// NEVER put a service-account JSON object in browser/mobile code.// NEVER commit it to Git.// NEVER embed it in a desktop/mobile binary.initializeApp({  credential: cert(JSON.parse(process.env.PUBLIC_SERVICE_ACCOUNT_JSON))});

A browser/mobile application is an untrusted environment. Any embedded secret can be extracted. The correct client identity is Firebase Authentication (plus App Check where appropriate), while privileged credentials remain in trusted runtime infrastructure.

7. Secrets, credentials and rotation are different concerns

Artifact Example Handling
End-user token Firebase ID token Short-lived bearer token; verify; never log raw value
Refresh token Firebase Auth refresh token Long-lived session credential; protect client storage and revoke when necessary
Workload access token ADC/WIF/attached service identity result Short-lived; library/runtime manages refresh
Service-account private key Downloaded JSON key Avoid if possible; secret storage, inventory, rotation and emergency revoke required
Application secret Payment API secret Use secret manager/runtime injection; not a replacement for workload identity
Emulator token Unsigned Auth emulator ID token Local only; production must reject

Rotation plans should answer: which workloads depend on this credential, how do you deploy the replacement, how do you prove the old credential no longer works, and how do you detect unexpected use during the transition?

8. Enterprise and MongoDB compatibility boundary

Enterprise Native server clients use the same privileged IAM/ADC trust model: Core and Pipeline operations do not make server SDKs subject to client Security Rules. Firestore with MongoDB compatibility has its own connection model and can authenticate through supported Google/OIDC workload identities or database-user credentials such as SCRAM depending on the connection path. Do not reuse a Native-mode mobile/web security diagram for a MongoDB driver.

9. Verification and cleanup

  • Search the lab directory for private_key, client_email, GOOGLE_APPLICATION_CREDENTIALS and raw Bearer values; none should be committed.
  • Mandatory emulator scripts succeed with no cloud credential.
  • Production deployment design names one explicit workload identity per service responsibility.
  • Optional cloud test records the exact principal and roles, then removes temporary bindings/resources.
  • Document an emergency disable/revocation procedure before first production deployment.

Production judgment and bridge to Lesson 5

The safest credential is often the one you never download. Prefer attached identities in Google Cloud and federation/impersonation elsewhere. Keep human local-development credentials distinct from production workloads. Lesson 5 combines all of Chapter 14 into one end-to-end AtlasMart access architecture with explicit trust, audit, failure and recovery boundaries.

Knowledge check

  1. What is ADC?
  2. Why is an attached service account safer than a downloaded key?
  3. What problem does Workload Identity Federation solve?
  4. Should FIREBASE_AUTH_EMULATOR_HOST ever be set in production?
  5. Does keyless mean there is no workload identity?
Review the answers

1. A standard credential discovery mechanism used by Google client libraries; it is not a single credential type.

2. The platform can provide short-lived credentials without distributing a persistent private key file.

3. It lets external workloads exchange trusted external identity for short-lived Google credentials instead of storing service-account keys.

4. No. It changes Admin Auth verification behavior to accept emulator-issued unsigned tokens.

5. No. The workload still has an identity; it simply obtains short-lived credentials without a persistent key file.

Summary

AtlasMart now treats credentials as an architecture choice. Emulator work is credential-free, developers use bounded ADC/impersonation, production workloads use attached/federated identities where possible, and service-account keys are a last-resort secret with explicit lifecycle controls.

Authoritative references

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only Ethereum or ERC-20 compatible assets to this address.