This page explains how to analyze Identity and Access Management (IAM) policies asynchronously and write results to BigQuery. The process is similar to analyzing IAM policies except the analysis result is written to BigQuery tables.
Before you begin
Enable the Cloud Asset API.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
You must enable the API in the project you will use to send the query. This doesn't have to be the same resource that you scope your query to.
Required roles and permissions
The following roles and permissions are required to run a policy analysis and export the results to BigQuery.
Required IAM roles
To get the permissions that you need to analyze a policy and export the results to BigQuery, ask your administrator to grant you the following IAM roles on the project, folder, or organization that you will scope your query to:
- BigQuery Data Editor (
roles/bigquery.dataEditor) - Cloud Asset Viewer (
roles/cloudasset.viewer) -
To analyze policies with custom IAM roles:
Role Viewer (
roles/iam.roleViewer) -
To use the Google Cloud CLI to analyze policies:
Service Usage Consumer (
roles/serviceusage.serviceUsageConsumer)
For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to analyze a policy and export the results to BigQuery. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to analyze a policy and export the results to BigQuery:
-
bigquery.datasets.create -
bigquery.jobs.create -
bigquery.tables.create -
bigquery.tables.get -
bigquery.tables.updateData -
bigquery.tables.update -
cloudasset.assets.analyzeIamPolicy -
cloudasset.assets.searchAllResources -
cloudasset.assets.searchAllIamPolicies -
To analyze policies with custom IAM roles:
iam.roles.get -
To use the Google Cloud CLI to analyze policies:
serviceusage.services.use
You might also be able to get these permissions with custom roles or other predefined roles.
Required Google Workspace permissions
If you want to see if a principal has certain roles or permissions as a result
of their membership in a Google Workspace group, you need the groups.read
Google Workspace permission. This permission is contained in the Groups Reader
Admin role, and in more powerful roles such as the Groups Admin or Super Admin
roles. See Assign specific admin roles for more
information.
Analyze policies and export results
Console
In the Google Cloud console, go to the Policy Analyzer page.
In the Analyze policies section, find the query template you want to use, then click Create query. If you want to create a custom query, click Create custom query.
In the Select query scope field, select the project, folder, or organization that you want to scope the query to. Policy Analyzer will analyze access for that project, folder, or organization, as well as any resources within that project, folder, or organization.
Ensure that your query parameters are set:
- If you're using a query template, confirm the prefilled query parameters.
- If you're creating a custom query, set the resources, principals, roles, and permissions that you want to query for.
For more information about the types of queries you can create, see Analyze IAM policies.
In the pane labeled with the name of the query, click Analyze > Export result only. The Export results pane opens.
In the Set export destination section, enter the following information:
- Project: The project where your BigQuery dataset is located.
- Dataset: The BigQuery dataset that you want to export results to.
- Table: The prefix of the BigQuery tables to which the analysis results will be written. If a table with the specified prefix doesn't exist, BigQuery creates a new table.
Click Continue.