Triage and Remediation
Remediation
Using Console
Using Console
To remediate the misconfiguration “GCP BigQuery Should Have Audit Logging Enabled” for GCP using GCP console, you can follow the below steps:
- Open the Google Cloud Console and select the project where BigQuery is enabled.
- Go to the Navigation menu and select “BigQuery”.
- In the BigQuery console, click on the “More” button (three dots) on the left-hand side and select “View in APIs Explorer”.
- In the APIs Explorer, search for “tables.insert” in the search bar.
- In the “tables.insert” API, scroll down to the “Request body” section and add the following JSON code:
- Click on the “Authorize and execute” button.
- On the next screen, click on the “Execute” button.
- Go back to the BigQuery console and click on the “More” button (three dots) on the left-hand side.
- Select “Audit logs” and ensure that the logs are enabled.
Using CLI
Using CLI
To remediate the misconfiguration of GCP BigQuery not having audit logging enabled, follow these steps using GCP CLI:If you see any results, it means audit logging is already enabled. If not, proceed to the next step.Note: Replace Note: Replace Note: Replace Note: Replace After following these steps, audit logging will be enabled for BigQuery in your GCP project, and the audit logs will be exported to the BigQuery table you created.
- Open the Cloud Shell in your GCP console.
- Run the following command to verify if audit logging is enabled for BigQuery:
- Run the following command to enable audit logging for BigQuery:
<project-id>
with your GCP project ID.- Run the following command to verify if the sink was created successfully:
- Run the following command to grant the necessary permissions to the sink:
- Run the following command to create a dataset in BigQuery to store the audit logs:
<dataset-name>
with the desired name for your dataset.- Run the following command to create a table in the dataset to store the audit logs:
<dataset-name>
and <table-name>
with the desired names for your dataset and table.- Run the following command to create a sink to export the audit logs to the BigQuery table:
<project-id>
, <dataset-name>
and <table-name>
with the names you used in steps 6 and 7.- Run the following command to verify if the sink was created successfully:
Using Python
Using Python
To remediate the misconfiguration “GCP BigQuery should have audit logging enabled” for GCP using Python, follow the below steps:This will enable audit logging for the specified dataset in GCP BigQuery.
- Install the Google Cloud SDK and authenticate using the following command:
- Install the necessary Python libraries:
- Create a Python script with the following code:
-
Replace
my_dataset
with the ID of the dataset you want to enable audit logging for. - Run the script using the following command: