Cross Project Data access and Slot Utilization in Big Query - google-bigquery

I have a Project A and Project B both with flat rate pricing models.
Project A has all the data that Users from Project B want to access.
We have assigned Users from Project B data viewer role on Project A.
How can we ensure (other than selecting Project B from the Dropdown menu on the top) that Users from Project B will always use Slots from Project B's Slot pool whilst accessing data from Project A?

In the scenario below, Project B's slots will be used as it is where the jobs are created:
Project A: owns data and the datasets.
Project B: users from this project run query jobs.
So in the case that you want to ensure that the users from project B will use project B slots you have to create the job in project B but having access to the project A.
You could also use authorized views to share specific query results to particular users or groups without giving them access to the underlying tables, or the whole dataset.
For the comment that you say to access data without the BigQuery Job User?
The answer is yes you can access the data.
What you can add is the permission bigquery.jobs.create instead of adding the role BigQuery Job User that has that permission between others. You can check in this document what are the permissions required or if you want to set a role in order to create a BigQuery job.

Related

How to restrict the table/view access in Bigquery?

Suppose I have 2 users available for the same project. The requirement is to restrict the table access in the same project to one user. How can it be managed it in Bigquery? what kind of access controls to be applied and how?
Thanks in advance.
You can use table level ACLS and set Bigquery roles/bigquery.dataViewer for users on the tables you wish to grant access. More details here https://cloud.google.com/bigquery/docs/table-access-controls-intro
This approach doesn't require creating a separate dataset(as a workaround for table level access) for access control which use to be the case earlier.
Depending on requirements, and the strictness of them, this is what I do:
Grant the user access to a specific table within a dataset by granting the BigQuery Data Viewer role at the table level.
You can do this as follows:
-> Open the table in the console and click Share, then click Add Principal
And to make it easier for the user to navigate the metadata of the table, such as schema, details and preview, I grant them the BigQuery Metadata Viewer role at the dataset level.
You should only do this of course if it is ok for the user to see which other tables within the dataset are there. (they can't see the data in the other tables, just the schema etc)
The advantage is that it will be easier for the user to see the schema and a preview of the data.
More info can be found here:
https://cloud.google.com/bigquery/docs/table-access-controls

SESSION_USER equivalent from Big Query in Data Studio reports

We are creating dashboards for clients using data studio.
Each client should see their data in the dashboard, based on their login credentials. It is simple to create an authorized_view in Big Query to let certain users see certain rows of an underlying shared table. But how would one achieve to then move this into a dashboard which can be shared with each client, yet show only the individuals client in the dashboard instead of the data that was visible to the report creator?
So let's say we have a large table with a bunch of columns and one column email which contains the email of users. Now, we want the dashboard to show metrics for each user based on this email column.
On DataStudio in the datasource schema review step, make sure the flag USING VIEWER’S CREDENTIALS is on. By turning it on, the query when being executed will use the viewer’s credential instead of the owner who created the report.
After you finish create proper visualization on Data Studio, final step is to share the report to eg: store managers using the share option of Data Studio which is similar to share a Google Docs. You can confidently share it with the whole organization or with the email group of eg: store managers, permission already be controlled at data level.
Read more about this topic here.

Running queries in BigQuery without being a project User

It seems the only way to share a dataset so that another person can run queries on the tables from the dataset is to make that person a Project user. See permissions
This means that the user would have access to all the datasets on the project. This seems to me that is is highly inconvenient. Am I missing something?
For user to run query - user need to have bigquery.jobs.create permission
If your user already has this permission in any other project - you can just simply share your dataset with this user with Can View Access Level
If user is new and does not have yet bigquery.jobs.create in any other project - you can just add this user to your project with this permission only.
And still you need add this user to ACL for that
specific dataset
Important: Please also note - if you give user permission to create jobs in your project - you will be billed for respective queries.
If user has its "own" project and only has view access to you data - in this case bill goes to user's project

Join BigQuery tables in different projects using Service Accounts

I have service accounts per BigQuery project. I need to put joins on tables in different projects using service accounts configured on each project.
Here is what i have:
Service_EmailAccount1 -> project1
Service_EmailAccount2 -> project2
I can connect to tables using these service accounts in respective projects but when I try to join data on different tables which are in different projects, I get access errors.
Reason is when i build the BigQuery service , I am using a JSON file which is specific to project as it contains the project id.
How can I join tables in different projects using service accounts?
Assuming you run your query by Service_EmailAccount1
In this case you should just share your respective dataset in project2 with Service_EmailAccount1
And you must make sure both datasets are in the same location
That's all you need
See more about Access Control concept in BigQuery
I believe that the following idea might be helpful, for example, you are using service_emailaccount1 to get access of project1,
go to bigquery, click the project name, then choose -> switch project -> manage projects, you will go to IAm & Admin page
choose project1 and then you will see the permission page for the project.
add service_emalaccount2 to be a viewer/editor to this project1(if account1 is the owner)
Then, I believe that both accounts will access project1.
This is what I will do to get access to several projects, and I am not sure we can use different service account to querying from different project in one query. Thx

BigQuery - Grant Access to Other Google Cloud Platform Projects

I'm trying to setup customer access to some of my BigQuery data. I'll start off with my requirements, then what I think the solution needs to be, though I'm not sure how to execute.
Requirements
Separate billing per customer for queries
I don't want to make my dataset public
Read only access to specific datasets
Accessible via Excel connector
No access rights to my main project
They manage their own access privileges, I don't want to have to add and remove individual users from direct dataset access on behalf of all our clients.
Nice to have - Web UI access
What I've Done
Created a new Google Developer Project
Added a view-only user on that project
Added a service account
Granted access to my BigQuery dataset to the service account
Here are the options for granting dataset access from the documentation:
I imagine that I need to setup some sort of special group, but I can't figure out how to do it.
Thanks in advance!
In BigQuery there are two different concepts:
The first one is billing (for queries and any other billable
activity) that is linked with a Google Cloud Project.
The second one is access to a dataset.
Having said that, to fulfil your requirements you'd create a separate project for each of the customers, and grant access to the datasets in the granularity that you would want.
That way you would have the costs for each of the projects separated but billed to you. Be careful to give them only read access to the project, unless you want them to be able to create other services like VM or deploy GAE apps, as they'd be billed to you as well.
For example dataset [MyDatasetA] to users X and Y in projects Project1 and Project2, but access to [MyDatasetB] to users Y and Z in projects Project2 and Project3.
Thus, each project is accountable for the queries their users run, and you have your access control on each dataset without it being public.
Separate billing per customer for queries. Done with the independent projects.
I don't want to make my dataset public. Done with fine grained control access.
Read only access to specific datasets. Same as above.
Accessible via Excel connector. It should work without problems as they'd be first class BQ users.
No access rights to my main project. Again possible if they are restricted to their own projects.
They manage their own access privileges. This is trickier. I think they'd need more than read access to the datasets or more than read access to the projects to be able to add new users, if you use the project groups as access control.
Nice to have - Web UI access. Check out https://bigquery.cloud.google.com/
The project groups are groups that allow to select members with Viewer, Developer or Owner roles in one click, without the hassle of adding each member manually.
You get already three groups set-up for you to use: Viewers, Editors and Owners of the original project.
But you may create your own Google Groups and give those groups the permission you want.
The hint when doing so, is that new users will usually need to Display your project so that it appears in the BQ online browser. This is done by clicking on the arrow to the side of the project name in the BQ online browser followed by Switch to project then Display project with the project name that the Dataset belongs to.
Edit: Improved the explanation about Group access