|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * security/audit-log-view.adoc |
| 4 | + |
| 5 | +[id="security-audit-log-basic-filtering_{context}"] |
| 6 | += Filtering audit logs |
| 7 | + |
| 8 | +You can use `jq` or another JSON parsing tool to filter the API server audit logs. |
| 9 | + |
| 10 | +[NOTE] |
| 11 | +==== |
| 12 | +The amount of information logged to the API server audit logs is controlled by the audit log policy that is set. |
| 13 | +==== |
| 14 | + |
| 15 | +The following procedure provides examples of using `jq` to filter audit logs on control plane node `node-1.example.com`. See the link:https://stedolan.github.io/jq/manual/[jq Manual] for detailed information on using `jq`. |
| 16 | + |
| 17 | +.Prerequisites |
| 18 | + |
| 19 | +* You have access to the cluster as a user with the `cluster-admin` role. |
| 20 | +* You have installed `jq`. |
| 21 | + |
| 22 | +.Procedure |
| 23 | + |
| 24 | +* Filter OpenShift API server audit logs by user: |
| 25 | ++ |
| 26 | +[source,terminal] |
| 27 | +---- |
| 28 | +$ oc adm node-logs node-1.example.com \ |
| 29 | + --path=openshift-apiserver/audit.log \ |
| 30 | + | jq 'select(.user.username == "myusername")' |
| 31 | +---- |
| 32 | + |
| 33 | +* Filter OpenShift API server audit logs by user agent: |
| 34 | ++ |
| 35 | +[source,terminal] |
| 36 | +---- |
| 37 | +$ oc adm node-logs node-1.example.com \ |
| 38 | + --path=openshift-apiserver/audit.log \ |
| 39 | + | jq 'select(.userAgent == "cluster-version-operator/v0.0.0 (linux/amd64) kubernetes/$Format")' |
| 40 | +---- |
| 41 | + |
| 42 | +* Filter Kubernetes API server audit logs by a certain API version and only output the user agent: |
| 43 | ++ |
| 44 | +[source,terminal] |
| 45 | +---- |
| 46 | +$ oc adm node-logs node-1.example.com \ |
| 47 | + --path=kube-apiserver/audit.log \ |
| 48 | + | jq 'select(.requestURI | startswith("/apis/apiextensions.k8s.io/v1beta1")) | .userAgent' |
| 49 | +---- |
| 50 | + |
| 51 | +* Filter Kubernetes API server audit logs by excluding a verb: |
| 52 | ++ |
| 53 | +[source,terminal] |
| 54 | +---- |
| 55 | +$ oc adm node-logs node-1.example.com \ |
| 56 | + --path=kube-apiserver/audit.log \ |
| 57 | + | jq 'select(.verb != "get")' |
| 58 | +---- |
0 commit comments