Search code examples
node.jsgoogle-compute-enginefirebase-admingoogle-iam

Authenticating Firebase Admin SDK on GCE VM with Application Default Credentials


I can't seem to authenticate with the Firebase Admin SDK on a GCE VM. With

admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  databaseURL: `https://${PROJECT_ID}-default-rtdb.firebaseio.com`,
});

my app indicates

Error: 7 PERMISSION_DENIED: Request had insufficient authentication scopes.

From what I can tell, this is because the scopes are missing on the Application Default Credentials? Isn't this supposed to be configured automatically?

I've verified that if I take the compute service account, generate a json key, and then pass it to the admin sdk manually everything works, so I'm not clear why it doesn't correctly fetch the credentials.


Solution

  • Turns out there's a checkbox that needs to be checked when creating the instance

    enter image description here