Vertex AI is now Gemini Enterprise Agent Platform! We are currently updating our content to reflect this change. Please bear with us if you encounter naming inconsistencies during this transition.
Google Cloud 콘솔에서 기술 적용
체크포인트
Export audit logs and use BigQuery to analyze logs
내 진행 상황 확인하기
/ 100
Export audit logs and use BigQuery to analyze logs
내 진행 상황 확인하기
/ 100
이 실습에는 학습을 지원하는 AI 도구가 통합되어 있을 수 있습니다.
Overview
In this lab, you will investigate Cloud Audit Logs. Cloud Audit Logs maintains two audit logs for each project and organization: Admin Activity and Data Access.
Google Cloud services write audit log entries to these logs to help you answer the questions of "who did what, where, and when" within your Google Cloud projects.
Objectives
In this lab, you will learn how to perform the following tasks:
View audit logs in the Activity page.
View and filter audit logs in Cloud Logging.
Retrieve log entries with gcloud.
Export audit logs.
Setup and requirements
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Google Skills using an incognito window.
Note the lab's access time (for example, 1:15:00), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
Activate Google Cloud Shell
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
You can list the active account name with this command:
[core]
project = qwiklabs-gcp-44776a13dea667a6
Note:
Full documentation of gcloud is available in the
gcloud CLI overview guide
.
Check project permissions
Before you begin your work on Google Cloud, you need to ensure that your project has the correct permissions within Identity and Access Management (IAM).
In the Google Cloud console, on the Navigation menu (), select IAM & Admin > IAM.
Confirm that the default compute Service Account {project-number}-compute@developer.gserviceaccount.com is present and has the editor role assigned. The account prefix is the project number, which you can find on Navigation menu > Cloud overview > Dashboard.
Note: If the account is not present in IAM or does not have the `editor` role, follow the steps below to assign the required role.
In the Google Cloud console, on the Navigation menu (), click Cloud overview > Dashboard.
Replace {project-number} with your project number.
For Select a role, select Project (or Basic) > Editor.
Click Save.
Task 1. Enable data access audit logs
In this task, you enable data access audit logs.
Data access audit logs (except for BigQuery) are disabled by default, so you must first enable all audit logs. Logging charges for the volume of log data that exceeds the free monthly logs allotment.
All logs received by Logging count towards the logs allotment limit, except for the Cloud Audit Logs that are enabled by default. This includes all Google Cloud Admin Activity audit logs, System Event logs, plus data access audit logs from BigQuery only.
If you have not activated cloud shell yet then, on the Google Cloud Console title bar, click Activate Cloud Shell (). If prompted, click Continue.
At the command prompt, run this command to retrieve the current IAM policy for your project and save it as policy.json:
Click the Open Editor button to view the Cloud Shell code editor.
If an error indicates that the code editor could not be loaded because third-party cookies are disabled, click Open in New Window and switch to the new tab.
In the Cloud Shell code editor, click the policy.json file to expose its contents.
Add the following text to the policy.json file to enable data Access audit logs for all services. This text should be added just after the first { and before "bindings": [. (Be careful not to change anything else in the file).
Admin Activity logs contain log entries for API calls or other administrative actions that modify the configuration or metadata of resources. For example, the logs record when VM instances and App Engine applications are created and when permissions are changed.
To view the logs, you must have the Cloud Identity and Access Management roles Logging/Logs Viewer or Project/Viewer.
Admin Activity logs are always enabled so there is no need to enable them. There is no charge for your Admin Activity audit logs.
Note: You can view audit log entries in the Logs Viewer, Cloud Logging, and in the Cloud SDK. You can also export audit log entries to Pub/Sub, BigQuery, or Cloud Storage.
Use the Cloud Logging page
In the Google Cloud console, on the Navigation menu (), click View all products > Observability > Logging > Logs Explorer.
Copy and paste the following in the Query builder field.
Locate the log entry indicating that a Cloud Storage bucket was deleted. This entry will refer to storage.googleapis.com, which calls the storage.buckets.delete method to delete a bucket. The bucket name is the same name as your project id.
Within that entry, click on the storage.googleapis.com text and select Show matching entries.
Notice a line was added to the query preview textbox (located where the query builder had been) to show only storage events.
You should now see only the cloud storage entries.
Within that entry, click on the storage.buckets.delete text and select Show matching entries.
Notice another line was added to the Query preview textbox and now you can only see storage delete entries.
This technique can be used to easily locate desired events.
In the Query results, expand the Cloud Storage delete entry and then expand the protoPayload field.
Expand the authenticationInfo field and notice you can see the email address of the user that
performed this action.
Feel free to explore other fields in the entry.
Use the Cloud SDK
Log entries can also be read using the Cloud SDK command:
Example output:
gcloud logging read [FILTER]
In the Cloud Shell pane, use this command to retrieve only the audit activity for storage bucket deletion:
Note: If Cloud Shell is disconnected, then click reconnect.
gcloud logging read \
"logName=projects/$DEVSHELL_PROJECT_ID/logs/cloudaudit.googleapis.com%2Factivity \
AND protoPayload.serviceName=storage.googleapis.com \
AND protoPayload.methodName=storage.buckets.delete"
Task 4. Export the audit logs
In this task, you export audit logs. Individual audit log entries are kept for a specified length of time and are then deleted. The Cloud Logging Quota Policy explains how long log entries are retained. You cannot otherwise delete or modify audit logs or their entries.
Audit log type
Retention period
Admin Activity
400 days
Data Access
30 days
For longer retention, you can export audit log entries like any other Cloud Logging log entries and keep them for as long as you wish.
Export audit logs
When exporting logs, the current filter will be applied to what is exported.
In Logs Explorer, enter a query string in the Query builder to display all the audit logs. (This can be done by deleting all lines in the filter except the first one.) Your filter will look like what is shown below.
Click the Create sink button. The Logs Router Sinks page appears. Now, click on Logs Router.
On this page, you should be able to see the AuditLogsExport sink.
To the right of the AuditLogsExport sink, click the button with three dots () and select View sink details.
This will show information about the sink that you created.
Click Cancel when done.
Note: You could also export log entries to Pub/Sub or Cloud Storage. Exporting to Pub/Sub can be useful if you want to flow through an ETL process prior to storing in a database (Cloud Operations > PubSub > Dataflow > BigQuery/Bigtable).
Exporting to Cloud Storage will batch up entries and write them into Cloud Storage objects approximately once an hour.Note: All future logs will now be exported to BigQuery and the BigQuery tools can be used to perform analysis on the audit log data. The export does not export existing log entries.
In Cloud Shell, run the following commands to generate some more activity that you will view in the audit logs exported to BigQuery:
In this task, you export logs to a BigQuery dataset. You then analyze the logs using Query editor.
Note: When you export logs to a BigQuery dataset, Cloud Logging creates dated tables to hold the exported log entries. Log entries are placed in tables whose names are based on the entries' log names.
In the Google Cloud console, in the Navigation menu (), click BigQuery, then click Done.
In the left pane, under the Explorer section, click your project. This starts with (qwiklabs-gcp-xxx). You should see an auditlogs_dataset dataset under it.
Verify that the BigQuery dataset has appropriate permissions to allow the export writer to store log entries. Click on the auditlogs_dataset dataset.
From the Sharing dropdown, select Permissions.
On the Dataset Permission page, you will see the service account listed as BigQuery Data Editor member. If it's not already listed, you can add a service account under Add Principal and grant it the data editor role.
Click the Close button to close the Share Dataset screen.
Expand the dataset to see the table with your exported logs. (Click on the expand icon to expand the dataset.)
Click on the table name and take a moment to review the schemas and details of the tables that are being used.
Click the Query button.
In Cloud Shell, run the following commands again to generate some more activity that you will view in the audit logs exported to BigQuery:
Delete the text provided in the Query editor window and paste in the query below. This query will return the users that deleted virtual machines in the last 7 days.
#standardSQL
SELECT
timestamp,
resource.labels.instance_id,
protopayload_auditlog.authenticationInfo.principalEmail,
protopayload_auditlog.resourceName,
protopayload_auditlog.methodName
FROM
`auditlogs_dataset.cloudaudit_googleapis_com_activity_*`
WHERE
PARSE_DATE('%Y%m%d', _TABLE_SUFFIX) BETWEEN
DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY) AND
CURRENT_DATE()
AND resource.type = "gce_instance"
AND operation.first IS TRUE
AND protopayload_auditlog.methodName = "v1.compute.instances.delete"
ORDER BY
timestamp,
resource.labels.instance_id
LIMIT
1000
Click the Run button. After a couple of seconds you will see each time someone deleted a virtual machine within the past 7 days. You should see two entries, which is the activity you generated in this lab. Remember, BigQuery is only showing activity since the export was created.
Delete the text in the Query_editor window and paste in the query below. This query will return the users that deleted storage buckets in the last 7 days.
#standardSQL
SELECT
timestamp,
resource.labels.bucket_name,
protopayload_auditlog.authenticationInfo.principalEmail,
protopayload_auditlog.resourceName,
protopayload_auditlog.methodName
FROM
`auditlogs_dataset.cloudaudit_googleapis_com_activity_*`
WHERE
PARSE_DATE('%Y%m%d', _TABLE_SUFFIX) BETWEEN
DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY) AND
CURRENT_DATE()
AND resource.type = "gcs_bucket"
AND protopayload_auditlog.methodName = "storage.buckets.delete"
ORDER BY
timestamp,
resource.labels.instance_id
LIMIT
1000
Click the Run button. After a couple seconds you will see entries showing each time someone deleted a storage bucket within the past 7 days.
Note: As you can see, the ability to analyze audit logs in BigQuery is very powerful. In this activity, you viewed just two examples of querying audit logs.
Click Check my progress to verify the objective.
Export audit logs and use BigQuery to analyze logs
Congratulations!
In this lab, you have done the following:
Viewed audit logs on the activity page.
Viewed and filtered audit logs in Cloud Operations.
Retrieved log entries with gcloud.
Exported audit logs.
End your lab
When you have completed your lab, click End Lab. Google Skills removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
1 star = Very dissatisfied
2 stars = Dissatisfied
3 stars = Neutral
4 stars = Satisfied
5 stars = Very satisfied
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2026 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
시작하기 전에
실습에서는 정해진 기간 동안 Google Cloud 프로젝트와 리소스를 만듭니다.
실습에는 시간 제한이 있으며 일시중지 기능이 없습니다. 실습을 종료하면 처음부터 다시 시작해야 합니다.
화면 왼쪽 상단에서 실습 시작을 클릭하여 시작합니다.
시크릿 브라우징 사용
실습에 입력한 사용자 이름과 비밀번호를 복사합니다.
비공개 모드에서 콘솔 열기를 클릭합니다.
콘솔에 로그인
실습 사용자 인증 정보를 사용하여
로그인합니다. 다른 사용자 인증 정보를 사용하면 오류가 발생하거나 요금이 부과될 수 있습니다.
약관에 동의하고 리소스 복구 페이지를 건너뜁니다.
실습을 완료했거나 다시 시작하려고 하는 경우가 아니면 실습 종료를 클릭하지 마세요. 이 버튼을 클릭하면 작업 내용이 지워지고 프로젝트가 삭제됩니다.
현재 이 콘텐츠를 이용할 수 없습니다
이용할 수 있게 되면 이메일로 알려드리겠습니다.
감사합니다
이용할 수 있게 되면 이메일로 알려드리겠습니다.
한 번에 실습 1개만 가능
모든 기존 실습을 종료하고 이 실습을 시작할지 확인하세요.
시크릿 브라우징을 사용하여 실습 실행하기
이 실습을 실행하는 가장 좋은 방법은 시크릿 모드 또는 시크릿 브라우저 창을 사용하는 것입니다. 개인 계정과 학생 계정 간의 충돌로 개인 계정에 추가 요금이 발생하는 일을 방지해 줍니다.
Configuring and Viewing Audit Logs in Cloud Logging