Audit
Kubernetes auditing offers a chronological record of security-relevant operational actions, with support for both log and webhook formats. The type of events to record can be customized through audit policies.
Audit Logs
Activate audit logs by configuring the following parameters on kube-apiserver:
audit-log-path: The path to the audit log file
audit-log-maxage: Maximum number of days to retain old log files
audit-log-maxbackup: The maximum number of old log files to retain
audit-log-maxsize: The maximum size (in MB) of the log file before it is rotated (defaults to 100MB)
Each audit record consists of two lines:
The request line includes: a unique ID and metadata of the request (e.g., source IP, username, requested resource, etc.)
The response line includes: a unique ID (matching the request ID) and metadata of the response (e.g., HTTP status code)
For instance, the audit log format for the admin user querying the pod list in the default namespace is:
Audit Policy
Starting with v1.7+, Kubernetes supports experimental advanced auditing features, allowing customization of audit policies (to select which events to record) and audit backends (including log and webhook). Enable this by setting:
Note that with AdvancedAuditing enabled, the log format will have some changes, such as an additional 'stage' field (including stages like RequestReceived, ResponseStarted, ResponseComplete, Panic, etc.).
Audit Policy Details
The audit policy determines which events to record and is configured using:
The configuration format for defining policies is:
In a production environment, it's recommended to refer to the GCE Audit Policy for configuration guidance.
Audit Backends
Two types of audit storage backends are supported:
Logs, enabled by setting
--audit-log-path
, with an example format being:
Webhook, activated with
--audit-webhook-config-file=/etc/kubernetes/audit-webhook-kubeconfig --audit-webhook-mode=batch
, where audit-webhook-mode can be either batch or blocking. The webhook configuration file is formatted as follows:
All events are POSTed in JSON format to the webhook server, like so:
Stepping into the world of Kubernetes, we encounter the vital role of "auditing" – a security guard that dutifully chronicles the sequence of events occurring within our cluster fortress. It holds the keys to the past, presented in the form of logs and webhooks, and allows us to tailor our historical narratives with custom-crafted policies.
In the heart of our command center, we spin up these narratives by tuning our kube-apiserver's knobs with settings like audit-log-path, dictating where our tales are penned, and audit-log-maxage, determining the longevity of our archived accounts.
These stories come in pairs: a request line, detailing every who, what, and where of a cluster challenge; then its companion, the response line, echoing back with the aftermath, sealing the fate of the request with a mere HTTP status code.
Take, for instance, an admin's quest for pods in the default realm. This chronicle unfolds with timestamps and identifiers, crafting a narrative of keystrokes and code.
The sage of the audit carries on with wizardry known as policies, setting forth commandments to decide which events transcend time and which fade into oblivion, like whispers in the wind. Some speak of the time when access to configmaps was an epic chronicled in full, while trivial watches by system:kube-proxy upon endpoints and services quietly pass unrecorded.
With these policies, we shape our world and configure our memory, often drawing inspiration from the storied GCE Audit Policy. And we etch these records not only in the stones of logs but also in the winds of webhooks, casting them out to distant lands where server whispers back with certainty or doubt – enveloped in the sanctity of HTTPS.
This is our story, metered in JSON, resonating within the digital echoes of our Kubernetes abode.
最后更新于