Skip to content

Commit 1940c2c

Browse files
author
Mik Vyatskov
committed
Update Audit Logging documentation for 1.10
Signed-off-by: Mik Vyatskov <vmik@google.com>
1 parent 7dd01bd commit 1940c2c

File tree

1 file changed

+52
-6
lines changed
  • docs/tasks/debug-application-cluster

1 file changed

+52
-6
lines changed

docs/tasks/debug-application-cluster/audit.md

+52-6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ In both cases, audit events structure is defined by the API in the
7272
`audit.k8s.io` API group. The current version of the API is
7373
[`v1beta1`][auditing-api].
7474

75+
**Note:** in case of patches, request objects are arrays, containing operations, not the appropriate
76+
API objects. You should design your system to behave correctly in this case.
77+
7578
### Log backend
7679

7780
Log backend writes audit events to a file in JSON format. You can configure
@@ -91,14 +94,56 @@ audit backend using the following kube-apiserver flags:
9194

9295
- `--audit-webhook-config-file` specifies the path to a file with a webhook
9396
configuration. Webhook configuration is effectively a [kubeconfig][kubeconfig].
94-
- `--audit-webhook-mode` define the buffering strategy, one of the following:
95-
- `batch` - buffer events and asynchronously send the set of events to the external service
96-
This is the default
97-
- `blocking` - block API server responses on sending each event to the external service
97+
- `--audit-webhook-initial-backoff` specifies the amount of time to wait after the first failed
98+
request before retrying. From the second request and so on, exponential backoff is used.
9899

99100
The webhook config file uses the kubeconfig format to specify the remote address of
100101
the service and credentials used to connect to it.
101102

103+
### Batching
104+
105+
Both log and webhook backends support batching. Using webhook as an example, here's the list of
106+
available flags. To get the same flag for log backend, replace `webhook` with `log` in the flag
107+
name. By default, batching is enabled in `webhook` and disabled in `log`. Similarly, by default
108+
throttling is enabled in `webhook` and disabled in `log`.
109+
110+
- `--audit-webhook-mode` define the buffering strategy, one of the following:
111+
- `batch` - buffer events and asynchronously process then in batches. This is the default
112+
- `blocking` - block API server responses on processing each individual event
113+
114+
The following flags are only used in the `batch` mode.
115+
116+
- `--audit-webhook-batch-buffer-size` defines the size of the buffer to store events before batching.
117+
If the rate of incoming events is too high and the buffer is overflown, events are dropped
118+
- `--audit-webhook-batch-max-size` defines the maximum number of events in one batch
119+
- `--audit-webhook-batch-max-wait` defines the maximum amount of time to wait before unconditionally
120+
batching events in the queue
121+
- `--audit-webhook-batch-throttle-qps` defines the maximum average number of batches generated
122+
per second
123+
- `--audit-webhook-batch-throttle-burst` defines the maximum number of batches generated per second
124+
if the allowed QPS was underutilized previously
125+
126+
#### How to set up parameters
127+
128+
Parameters should be set to accommodate your load on the apiserver.
129+
130+
For example, if you receive 100 requests to the kube-apiserver each second, and each request is
131+
audited only on `StageResponseStarted` and `StageResponseComplete` stages, you should account for
132+
~200 audit events being generated each second. Assuming that you have up to 100 events in a batch,
133+
you should set throttling level at at least 2 QPS. Assuming that the backend can take up to
134+
5 seconds to write events, you should set the buffer size to hold up to 5 seconds of events, i.e.
135+
10 batches, i.e. 1000 events.
136+
137+
In most cases however, the default parameters should be sufficient and you don't have to worry about
138+
setting them manually. You can look at the Prometheus metric `apiserver_audit_error_total` and
139+
in the logs to monitor the state of the auditing subsystem.
140+
141+
## Multi-cluster setup
142+
143+
If you're extending the Kubernetes API with the [aggregation layer][kube-aggregator], you can also
144+
set up audit logging for the aggregated apiserver. To do this, pass the same configuration options
145+
to the aggregated apiserver and set up the log ingesting pipeline to pick up audit logs.
146+
102147
## Log Collector Examples
103148

104149
### Use fluentd to collect and distribute audit events from log file
@@ -250,8 +295,8 @@ plugin which supports full-text search and analytics.
250295

251296
## Legacy Audit
252297

253-
__Note:__ Legacy Audit is deprecated and is disabled by default since Kubernetes 1.8.
254-
To fallback to this legacy audit, disable the advanced auditing feature
298+
__Note:__ Legacy Audit is deprecated and is disabled by default since Kubernetes 1.8. Legacy Audit
299+
will be removed in 1.12. To fallback to this legacy audit, disable the advanced auditing feature
255300
using the `AdvancedAuditing` feature gate in [kube-apiserver][kube-apiserver]:
256301

257302
```
@@ -299,3 +344,4 @@ and `audit-log-maxage` options.
299344
[fluentd_install_doc]: http://docs.fluentd.org/v0.12/articles/quickstart#step1-installing-fluentd
300345
[logstash]: https://www.elastic.co/products/logstash
301346
[logstash_install_doc]: https://www.elastic.co/guide/en/logstash/current/installing-logstash.html
347+
[kube-aggregator]: /docs/concepts/api-extension/apiserver-aggregation

0 commit comments

Comments
 (0)