kubernetes: kube-apiserver audit log rotation throwing permission denied

What happened: I’m setting up integration with the Splunk logforwarder agent to stream our Kubernetes audit logs from our master nodes to Splunk Enterprise but I’m seeing an odd issue in our logs, where the kube-apiserver process says permission denied when trying to rotate the logs once they’ve reached maximum capacity.

kube-apiserver[1574]: E1105 18:43:54.090393 1574 metrics.go:86] Error in audit plugin 'log' affecting 1 audit events: can't open new logfile: open /var/lib/audit.log: permission denied

What you expected to happen: I expect the logs to be rotated without issue, though there seems to be a failure in our situation.

How to reproduce it (as minimally and precisely as possible): I’ve only observed the problem once enabling the Splunk logforwarder and pointing it to the audit log file. I’ve confirmed on the Splunk side, that the forwarder agent shouldn’t be locking the file in any way and should be doing a read only operation.

I’ve confirmed I can use root privileges to rename the file myself, but then I get a subsequent permission denied error with creating the new file (can't open new logfile: open /var/lib/audit.log: permission denied). From there, if I do touch audit.log then it begins to write to the file again as expected.

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version): Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.7", GitCommit:"dd5e1a2978fd0b97d9b78e1564398aeea7e7fe92", GitTreeState:"clean", BuildDate:"2018-04-19T00:05:56Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.7", GitCommit:"dd5e1a2978fd0b97d9b78e1564398aeea7e7fe92", GitTreeState:"clean", BuildDate:"2018-04-18T23:58:35Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration: AWS/EC2
  • OS (e.g. from /etc/os-release):
VERSION="16.04.5 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.5 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
  • Kernel (e.g. uname -a): Linux *** 4.4.0-1070-aws #80-Ubuntu SMP Thu Oct 4 13:56:07 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools:
  • Others:

/kind bug

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

I am not sure if this is related, I had a similar issue recently with the rotation of kube-apiserver audit logs. The error I received, however was:

E0129 13:15:01.951796       1 metrics.go:96] Error in audit plugin 'log' affecting 1 audit events: can't rename log file: rename /var/log/kube-apiserver-audit.log /var/log/kube-apiserver-audit-2019-01-29T13-15-01.951.log: device or resource busy

It turned out that I was mounting only the file to the kube-apiserver pod and therefore the container was unable to rename it. You can check if this is your case also.

This fixed my issue:

   - hostPath:
-      path: /var/log/kube-apiserver-audit.log
+      path: /var/log/kube-apiserver-audit
-       type: FileOrCreate
     name: audit

Ok guys @arun2arunraj @arpitaashu .I’ve sorted it out. Here’s my manifest.

  containers:
  - command:
    - kube-apiserver
    - --advertise-address=xx.xx.xx.xx
    - --allow-privileged=true
    - --audit-log-maxage=1
    - --audit-log-maxbackup=1
    - --audit-log-maxsize=2
    - --audit-log-path=/var/log/kube-apiserver-audit/audit.log
    - --audit-policy-file=/etc/kubernetes/audit-policy.yaml
...
...
    volumeMounts:
    - mountPath: /var/log/kube-apiserver-audit
      name: audit-log
    - mountPath: /etc/kubernetes/audit-policy.yaml
      name: audit-policy
      readOnly: true
...
...
  volumes:
  - hostPath:
      path: /var/log/kube-apiserver-audit
      type: DirectoryOrCreate
    name: audit-log
-rw-r--r-- 1 root root 2095198 Jul 20 09:50 audit-2021-07-20T02-50-39.054.log
-rw-r--r-- 1 root root 1051370 Jul 20 09:50 audit.log