Restricting the access to BigQuery datasets it's a feature request [1] that it is worked upon. You can start the thread to get automatic updates.
In the meantime you can create an Alert Policy [2] that will inform you that a BigQuery public dataset was queried and by whom (the user). I used the console to create the below alert and the minimum time to trigger it is 1 minute but programatically (e.g. [3]) you can set the duration at second levels.
1. Do a query test on a public dataset e.g.
SELECT count(gameId) FROM `bigquery-public-data.baseball.schedules` where duration_minutes >180
2. Go to Logging select BigQuery and find the performed query (Bigquery insert jobs [...user...])
2.1. Extend the log and chose "Expand all"
2.2. In jobStatistics: --> referencedTables:
click on "bigquery-public-data" (found next to projectId:)
2.3. Select "Show matching entries"
The result will look like this:
protoPayload.serviceData.jobInsertResponse.resource.jobStatistics.referencedTables.projectId="bigquery-public-data"
3. Select from on-top Create metric and configure it as follows:
Name: publicA
Description: Alert for querying BigQuery public datasets
3.1. Labels --> Add item
Name: user
Description: originator
Label type: String
Field name: protoPayload.authenticationInfo.principalEmail
Extraction regular expression: (.*)
--> Done
3.2. Units 1
3.3. Type: Counter
--> Create Metric
4. Monitoring --> Alerting --> Create Policy
4.1. Name: Alert for BigQuery public datasets
4.2. ADD Condition
4.3. Metric/Target/Find resource type and metric
4.4. Type publicA
4.5. Configuration
Condition triggers if: Any time series violates
Condition: is above
Threshold: 0
For: 1 minute
--> ADD
5. Add Notification Channel
chose your preferred option e.g. email / phone
6. Documentation (optional):
"Hello,
This is an alert for your project ${resource.project} where a user is querying a BigQuery public dataset."
--> SAVE
Please be advise that there are many other public datasets available [4] and the alert should be adjusted to include their project ID. For example, to be alerted for the Tcia public dataset [5] the Logs-based Metrics would contain: