Receive and Customize Auditing Logs
To enable auditing logs, see KubeSphere Auditing Logs.
The KubeSphere Auditing Log system receives auditing logs only from KubeSphere by default, while it can also receive auditing logs from Kubernetes.
Users can stop receiving auditing logs from KubeSphere by changing the value of in ConfigMap kubesphere-config
in the namespace kubesphere-system
using the following command:
Change the value of auditing.enabled
as false
to stop receiving auditing logs from KubeSphere.
spec:
auditing:
enabled: false
You need to restart the KubeSphere apiserver to make the changes effective.
To make the KubeSphere Auditing Log system receive auditing logs from Kubernetes, you need to add a Kubernetes audit policy file and Kubernetes audit webhook config file to /etc/kubernetes/manifests/kube-apiserver.yaml
as follows.
apiVersion: v1
kind: Pod
metadata:
name: kube-apiserver
namespace: kube-system
spec:
containers:
- command:
- kube-apiserver
- --audit-policy-file=/etc/kubernetes/audit/audit-policy.yaml
- --audit-webhook-config-file=/etc/kubernetes/audit/audit-webhook.yaml
volumeMounts:
- mountPath: /etc/kubernetes/audit
name: k8s-audit
volumes:
- hostPath:
path: /etc/kubernetes/audit
type: DirectoryOrCreate
name: k8s-audit
This operation will restart the Kubernetes apiserver.
The file audit-policy.yaml
defines rules about what events should be recorded and what data they should include. You can use a minimal audit policy file to log all requests at the Metadata level:
For more information about the audit policy, see .
Audit webhook
The file audit-webhook.yaml
defines the webhook which the Kubernetes auditing logs will be sent to. Here is an example configuration of the Kube-Auditing webhook.
apiVersion: v1
kind: Config
clusters:
- name: kube-auditing
cluster:
insecure-skip-tls-verify: true
contexts:
- context:
cluster: kube-auditing
user: ""
name: default-context
current-context: default-context
preferences: {}
users: []
The ip
is the CLUSTER-IP
of Service kube-auditing-webhook-svc
in the namespace kubesphere-logging-system
. You can get it using this command.
kubectl get svc -n kubesphere-logging-system
Note
Edit the CRD Webhook kube-auditing-webhook
, and change the value of k8sAuditingEnabled
to true
through the following commands.
spec:
auditing:
Tip
You can also use a user of platform-admin
role to log in to the console, search Webhook
in CRDs on the Cluster Management page, and edit kube-auditing-webhook
directly.
To stop receiving auditing logs from Kubernetes, remove the configuration of auditing webhook backend, then change the value of k8sAuditingEnabled
to false
.
KubeSphere Auditing Log system provides a CRD Webhook kube-auditing-webhook
to customize auditing logs. Here is an example yaml file:
apiVersion: auditing.kubesphere.io/v1alpha1
kind: Webhook
metadata:
name: kube-auditing-webhook
spec:
auditLevel: RequestResponse
auditSinkPolicy:
alertingRuleSelector:
matchLabels:
archivingRuleSelector:
matchLabels:
type: persistence
image: kubesphere/kube-auditing-webhook:v0.1.0
archivingPriority: DEBUG
alertingPriority: WARNING
replicas: 2
receivers:
- name: alert
type: alertmanager
config:
service:
namespace: kubesphere-monitoring-system
port: 9093
Note