Audit Log Forwarding to Rsyslog¶
This example demonstrates how to forward Kubernetes API audit logs from an
OpenShift cluster to an external rsyslog server using the ClusterLogForwarder
resource. The filter is configured to capture only KubeVirt-related API
activity (VirtualMachine, VirtualMachineInstance,
VirtualMachineInstanceMigration), keeping the log volume focused and
manageable.
Tested with:
| Component | Version |
|---|---|
| OpenShift | v4.22.5 |
| OpenShift Logging | v6.6.0 |
Documentation: Chapter 2. Configuring log forwarding
Start rsyslog to file logging¶
First, deploy a simple rsyslog instance inside the cluster that receives forwarded logs over TCP and writes them to persistent storage.
Create new project¶
Deploy rsyslog¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
The deployment includes three containers:
- rsyslog — listens on TCP port 24224 and writes all received messages to
/log/all.logas well as per-host/program files under/log/. - jq — tails the KubeVirt audit log and pretty-prints each entry as a single line with verb, duration, status code, request URI, and user.
- cdt — builds cluster-debug-tools for additional troubleshooting.
Test rsyslog¶
Login into the pod:
Send a test message and verify:
Configure Cluster Logging¶
Install the OpenShift Logging Operator from OperatorHub before proceeding.
The operator manages the ClusterLogForwarder custom resource used in the
next step.
Create ServiceAccount and RBAC¶
Audit log collection requires a dedicated service account with the
collect-audit-logs cluster role. Without this binding, the collector pods
will not have permission to read the node-level audit log files:
Deploy Log forwarding API¶
Forward audit logs to rsyslog¶
The ClusterLogForwarder below creates a pipeline that sends audit logs to
the rsyslog service. A kubeAPIAudit filter limits the output to metadata-level
events for KubeVirt resources, dropping everything else:
Create a Virtual Machine and view the audit logs¶
Once the forwarding pipeline is active, create a VirtualMachine through the OpenShift console or CLI. The jq sidecar in the rsyslog pod formats the incoming audit events into a compact, human-readable stream: