Different Sink Output Schema Between Project and Organization Level Audit Logs
Firstly, I’d like to extend my gratitude to @ms4446 for the comprehensive response provided earlier.
To give some context, I recently set up a sink using Terraform following the guidance you’ve shared. During the implementation, I consulted a Google blog post and noticed some disparities in the output schema of our sinks.
For the project level sink, I can query the field protopayload_auditlog.metadataJson. However, this particular field seems to be absent from our organization level schema. Here are the snapshots for reference:
Organization BigQuery Audit Log Sink Snapshot:
Project Level Sink Snapshot:
Given the absence of the metadataJson field, I’m finding it challenging to execute the following query from the aforementioned blog:
SELECT
timestamp AS time_of_access,
protopayload_auditlog.authenticationInfo.principalEmail as user_email,
protopayload_auditlog.requestMetadata.callerIp as ip,
auth.permission as auth_permission,
auth.granted as auth_granted,
data_access.resource.labels.project_id AS job_execution_project,
SPLIT(protopayload_auditlog.resourceName, '/')[SAFE_OFFSET(1)] AS referenced_project,
SPLIT(protopayload_auditlog.resourceName, '/')[SAFE_OFFSET(3)] AS referenced_dataset,
SPLIT(protopayload_auditlog.resourceName, '/')[SAFE_OFFSET(5)] AS referenced_table, ARRAY_LENGTH(SPLIT(JSON_EXTRACT(JSON_EXTRACT(protopayload_auditlog.metadataJson, '$.tableDataRead'), '$.fields'), ',')) as num_fields,
SPLIT(JSON_EXTRACT(JSON_EXTRACT(protopayload_auditlog.metadataJson, '$.tableDataRead'), '$.fields'),",") as fields
FROM `my-project`.my_dataset.cloudaudit_googleapis_com_data_access As data_access, UNNEST(protopayload_auditlog.authorizationInfo) AS auth
WHERE
protopayload_auditlog.methodName = "google.cloud.bigquery.v2.JobService.InsertJob"
AND data_access.resource.type = 'bigquery_dataset'
AND JSON_EXTRACT(JSON_EXTRACT(protopayload_auditlog.metadataJson, '$.tableDataRead'), '$.reason') = '"JOB"';
I’m curious to understand if there’s an inherent difference between the project level and organization level audit logs. Why might we be witnessing these inconsistencies?