이 문서에서는 Google Distributed Cloud용 Cloud 감사 로그를 사용하는 방법을 설명합니다.
Google Distributed Cloud는 클러스터의 Kubernetes API 서버로 전송된 호출을 시간순으로 기록하는 Kubernetes 감사 로깅을 사용합니다. 감사 로그는 의심스러운 API 요청을 조사하고 통계를 수집하는 데 유용합니다. GKE On-Prem API 감사 로깅에 대한 자세한 내용은 Cloud API 감사 로깅을 참조하세요.
Cloud 감사 로그 정보
감사 로그는 Google Cloud 프로젝트의 Cloud 감사 로그에 기록됩니다. Cloud 감사 로그에 작성하면 디스크에 작성하거나 온프레미스 로깅 시스템에서 로그를 캡처하는 것보다 다양한 이점이 있습니다.
모든 GKE 클러스터의 감사 로그를 중앙화할 수 있습니다.
Cloud 감사 로그에 기록된 로그 항목은 변경할 수 없습니다.
Cloud 감사 로그 항목은 400일 동안 보관됩니다.
Cloud 감사 로그 기능은 Google Distributed Cloud 요금에 포함되어 있습니다.
Google Distributed Cloud를 구성하여 디스크 또는 Cloud 감사 로그에 로그를 작성할 수 있습니다.
디스크 기반 감사 로깅
Cloud 감사 로그가 명시적으로 중지된 경우 Google Distributed Cloud의 감사 로그가 영구 디스크에 기록되므로 클러스터를 다시 시작하고 업그레이드할 때 로그가 사라지지 않습니다. Google Distributed Cloud는 감사 로그 항목을 최대 1GiB까지 보관합니다.
제어 영역 노드에 로그인하여 디스크 기반 감사 로그에 액세스합니다. 로그는 /var/log/apiserver/ 디렉터리에 있습니다.
Cloud 감사 로그
모든 Kubernetes API 서버의 관리자 활동 감사 로그 항목이 사용자 클러스터를 만들 때 지정한 프로젝트 및 위치를 통해 Google Cloud로 전송됩니다. Cloud 감사 로그에 로그 항목을 버퍼링하고 기록하기 위해 Google Distributed Cloud는 제어 영역 노드에서 실행되는 audit-proxy 데몬 세트를 배포합니다.
제한사항
Google Distributed Cloud의 Cloud 감사 로그에는 다음과 같은 제한사항이 있습니다.
데이터 액세스 로깅은 지원되지 않습니다.
Kubernetes 감사 정책은 수정할 수 없습니다.
Cloud 감사 로그의 복원력은 확장 네트워크 중단에 대해 우수하지 않습니다. 로그 항목을 Google Cloud로 내보낼 수 없으면 10 GiB 디스크 버퍼에 캐시됩니다. 해당 디스크 버퍼가 채워지면 가장 오래된 항목이 삭제됩니다.
Cloud 감사 로그의 서비스 계정 만들기
Google Distributed Cloud에서 Cloud Logging 및 Cloud Monitoring을 사용하려면 먼저 다음을 구성해야 합니다.
Google Cloud 프로젝트 내에 Cloud Monitoring 작업공간이 아직 없으면 만듭니다.
출력에 두 로그 항목이 표시됩니다. 각 로그 항목에서 logName 필드의 값은 projects/PROJECT_ID/logs/externalaudit.googleapis.com%2Factivity이고 protoPayload.serviceName은 anthosgke.googleapis.com과 동일합니다.
감사 정책
Kubernetes 감사 정책은 어떤 이벤트를 로그 항목으로 기록할지에 대한 규칙을 정의하고 로그 항목에 포함되어야 하는 데이터를 지정합니다. 이 정책을 변경하여 Cloud 감사 로그의 동작을 수정하는 작업은 지원되지 않습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-12-23(UTC)"],[],[],null,["This document describes how to use Cloud Audit Logs for Google Distributed Cloud\n(software only) on bare metal. Google Distributed Cloud uses [Kubernetes Audit\nLogging](https://kubernetes.io/docs/tasks/debug-application-cluster/audit/),\nwhich keeps a chronological record of calls made to a cluster Kubernetes API\nserver. Audit logs are useful for investigating suspicious API requests and for\ncollecting statistics. For information about audit logging for the\nGKE On-Prem API, see [Cloud API audit\nlogging](/kubernetes-engine/distributed-cloud/bare-metal/docs/how-to/audit-logging-api).\n| **Note:** Starting with Google Distributed Cloud release 1.9.0, Cloud Audit Logs is enabled by default. Cloud Audit Logs is automatically enabled for 1.8.x clusters that are upgraded to 1.32.400-gke.68 unless it was explicitly disabled for the 1.8.x cluster by setting `disableCloudAuditLogging` to `true`.\n\nAbout Cloud Audit Logs\n\nAudit logs are written to [Cloud Audit Logs](/logging/docs/audit) in your\nGoogle Cloud project. Writing to Cloud Audit Logs has several benefits over writing to\ndisk or capturing logs in an on-premises logging system:\n\n- Audit logs for all GKE clusters can be centralized.\n- Log entries written to Cloud Audit Logs are immutable.\n- Cloud Audit Logs entries are retained for 400 days.\n- Cloud Audit Logs feature is included in the price of Google Distributed Cloud software-only.\n- You can configure Google Distributed Cloud to write logs to disk or to Cloud Audit Logs.\n\nDisk-based audit logging\n\nIf Cloud Audit Logs is disabled explicitly, audit logs are written to a persistent\ndisk so that cluster restarts and upgrades don't cause the logs to disappear.\nGoogle Distributed Cloud software-only retains up to 1 GiB of audit log\nentries.\n\nAccess the disk-based audit logs by logging into control plane Nodes. The logs\nare located in the `/var/log/apiserver/` directory.\n\nCloud Audit Logs\n\nAdmin Activity audit log entries from all Kubernetes API servers are sent to\nGoogle Cloud, using the project and location that you specify when you\ncreate a user cluster. To buffer and write log entries to Cloud Audit Logs,\nGoogle Distributed Cloud deploys an `audit-proxy` daemon set that runs on the control\nplane nodes.\n\nLimitations\n\nOn bare metal, Cloud Audit Logs has the following limitations:\n\n- Data access logging isn't supported.\n- Modifying the Kubernetes audit policy is not supported.\n- Cloud Audit Logs isn't resilient to extended network outages. If the log entries can't be exported to Google Cloud, they are cached in a 10 GiB disk buffer. If that buffer fills, then the oldest entries are dropped.\n - One project can support up to approximately 1000 service accounts for use with Cloud Audit Logs. Multiple clusters can use the same service account.\n\nCreating a service account for Cloud Audit Logs\n\nBefore you can use Cloud Logging and Cloud Monitoring with\nGoogle Distributed Cloud software-only, you must first configure the following:\n\n1. Create a Cloud Monitoring Workspace within the Google Cloud project, if you\n don't have one already.\n\n In the Google Cloud console, click the following button and follow the\n workflow.\n\n [Go to Monitoring](https://console.cloud.google.com/monitoring)\n2. Click the following buttons to enable the required APIs:\n\n [Enable the Anthos Audit API](https://console.cloud.google.com/apis/library/anthosaudit.googleapis.com)\n\n [Enable the Stackdriver API](https://console.cloud.google.com/apis/library/stackdriver.googleapis.com)\n\n [Enable the Monitoring API](https://console.cloud.google.com/apis/library/monitoring.googleapis.com)\n\n [Enable the Logging API](https://console.cloud.google.com/apis/library/logging.googleapis.com)\n3. Assign the following IAM roles to the service account used by\n the Stackdriver agents:\n\n - `logging.logWriter`\n - `monitoring.metricWriter`\n - `stackdriver.resourceMetadata.writer`\n - `monitoring.dashboardEditor`\n\n| **Warning:** before deleting this service account, be sure to replace it with the new service account in the cluster configuration first! See [Rotate service\n| account keys](/kubernetes-engine/distributed-cloud/bare-metal/docs/how-to/update-secrets). If you forget to do this, follow [the guide to clean\n| up](/kubernetes-engine/distributed-cloud/bare-metal/docs/troubleshooting/observability#sa-leakage).\n\nAccessing Cloud Audit Logs \n\nConsole\n\n1. In the Google Cloud console, go to the **Logs Explorer** page in the\n **Logging** menu.\n\n [Go to the Logs Explorer](https://console.cloud.google.com/logs/query)\n\n If the **Legacy Logs Viewer** page opens, choose **Upgrade to the new\n Logs Explorer** from the **Upgrade** drop-down menu.\n2. Click **Query** to access the field for submitting queries.\n\n3. Fill the field with the following query:\n\n resource.type=\"k8s_cluster\"\n logName=\"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/logs/externalaudit.googleapis.com%2Factivity\"\n protoPayload.serviceName=\"anthosgke.googleapis.com\"\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your project ID.\n4. Click **Run query** to display all audit logs from clusters that were\n configured to sign in to this project.\n\ngcloud\n\nList the first two log entries in your project's Admin Activity log that\napply to the `k8s_cluster` resource type: \n\n gcloud logging read \\\n 'logName=\"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/logs/externalaudit.googleapis.com%2Factivity\" \\\n AND resource.type=\"k8s_cluster\" \\\n AND protoPayload.serviceName=\"anthosgke.googleapis.com\" ' \\\n --limit 2 \\\n --freshness 300d\n\nReplace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your project ID.\n\nThe output shows two log entries. Notice that for each log entry, the\n`logName` field has the value\n`projects/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/logs/externalaudit.googleapis.com%2Factivity`\nand `protoPayload.serviceName` is equal to `anthosgke.googleapis.com`.\n\nAudit policy\n\nThe Kubernetes audit policy defines rules for which events are recorded as log\nentries and specifies what data the log entries should include. Changing this\npolicy to modify Cloud Audit Logs behavior isn't supported."]]