Google-cloud-node: Auth multiple projects (for bigquery join across two projects)

Created on 7 Sep 2016  路  5Comments  路  Source: googleapis/google-cloud-node

Hi. I'm wondering if there's any way to configure authentication with more than one one project? (e.g. both project-1-key.json and project-2-key.json). I have a query that needs to do a join between two projects (which we can do on the BigQuery interface). However It seems each api endpoint only allows for a single auth config. I did try configuring the global gcloud with project-1 and the bigquery config with project-2. But second config seems to take preference and I still get Access Denied: Table table-name:project-1

TLDR, I'm wondering if there's a way to achieve something like the following:

var config = {
  projectId: ['project-1', 'project-2'],
  keyFilename: ['/path/to/project-1-key.json', '/path/to/project-2-key.json']
};

Environment details

  • OS: OS X
  • Node.js version: v6.5.0
  • npm version: 3.10.6
  • google-cloud-node version: 0.39.0
question bigquery

Most helpful comment

Ok, I think I figured a better way around. Seems from inside the second project, you can add the service accounts from other projects as members/roles. So you want to give it the email of project-1's service account (the one used for auth in the config).

screen shot 2016-09-07 at 3 58 50 pm

Which essentially does this...
https://cloud.google.com/iam/docs/granting-roles-to-service-accounts

All 5 comments

Hmm, very interesting question! @jgeewax @omaray any ideas if such a query is possible from a service account?

Ok, I think I figured a better way around. Seems from inside the second project, you can add the service accounts from other projects as members/roles. So you want to give it the email of project-1's service account (the one used for auth in the config).

screen shot 2016-09-07 at 3 58 50 pm

Which essentially does this...
https://cloud.google.com/iam/docs/granting-roles-to-service-accounts

Thanks for sharing! I'll add it to our FAQ.

This issue was moved to GoogleCloudPlatform/gcloud-common#191

Great suggestion!! I was kind struggling a little with this point!

Was this page helpful?
0 / 5 - 0 ratings