记得添加,把配置文件挂载进去
- mountPath: /etc/kubernetes/auditname: audit-policyreadOnly: true.....- hostPath:path: /etc/kubernetes/audit/type: DirectoryOrCreatename: audit-policy
/etc/kubernetes/manifests/kube-apiserver.yaml 具体配置文件如下
apiVersion: v1
kind: Pod
metadata:annotations:kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint: 10.211.55.4:6443creationTimestamp: nulllabels:component: kube-apiservertier: control-planename: kube-apiservernamespace: kube-system
spec:containers:- command:- kube-apiserver- --advertise-address=10.211.55.4- --allow-privileged=true- --authorization-mode=Node,RBAC- --client-ca-file=/etc/kubernetes/pki/ca.crt- --enable-admission-plugins=NodeRestriction- --enable-bootstrap-token-auth=true- --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt- --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt- --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key- --etcd-servers=https://127.0.0.1:2379- --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt- --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname- --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt- --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key- --requestheader-allowed-names=front-proxy-client- --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt- --requestheader-extra-headers-prefix=X-Remote-Extra-- --requestheader-group-headers=X-Remote-Group- --requestheader-username-headers=X-Remote-User- --secure-port=6443- --service-account-issuer=https://kubernetes.default.svc.cluster.local- --service-account-key-file=/etc/kubernetes/pki/sa.pub- --service-account-signing-key-file=/etc/kubernetes/pki/sa.key- --service-cluster-ip-range=10.96.0.0/12- --tls-cert-file=/etc/kubernetes/pki/apiserver.crt- --tls-private-key-file=/etc/kubernetes/pki/apiserver.key- --audit-log-path=/var/log/kubernetes/audit/audit.log- --audit-policy-file=/etc/kubernetes/audit/audit-default-policy.yamlimage: registry.aliyuncs.com/google_containers/kube-apiserver:v1.23.17imagePullPolicy: IfNotPresentlivenessProbe:failureThreshold: 8httpGet:host: 10.211.55.4path: /livezport: 6443scheme: HTTPSinitialDelaySeconds: 10periodSeconds: 10timeoutSeconds: 15name: kube-apiserverreadinessProbe:failureThreshold: 3httpGet:host: 10.211.55.4path: /readyzport: 6443scheme: HTTPSperiodSeconds: 1timeoutSeconds: 15resources:requests:cpu: 250mstartupProbe:failureThreshold: 24httpGet:host: 10.211.55.4path: /livezport: 6443scheme: HTTPSinitialDelaySeconds: 10periodSeconds: 10timeoutSeconds: 15volumeMounts:- mountPath: /etc/ssl/certsname: ca-certsreadOnly: true- mountPath: /etc/ca-certificatesname: etc-ca-certificatesreadOnly: true- mountPath: /etc/pkiname: etc-pkireadOnly: true- mountPath: /etc/kubernetes/pkiname: k8s-certsreadOnly: true- mountPath: /usr/local/share/ca-certificatesname: usr-local-share-ca-certificatesreadOnly: true- mountPath: /usr/share/ca-certificatesname: usr-share-ca-certificatesreadOnly: true- mountPath: /etc/kubernetes/auditname: audit-policyreadOnly: truehostNetwork: truepriorityClassName: system-node-criticalsecurityContext:seccompProfile:type: RuntimeDefaultvolumes:- hostPath:path: /etc/ssl/certstype: DirectoryOrCreatename: ca-certs- hostPath:path: /etc/ca-certificatestype: DirectoryOrCreatename: etc-ca-certificates- hostPath:path: /etc/pkitype: DirectoryOrCreatename: etc-pki- hostPath:path: /etc/kubernetes/pkitype: DirectoryOrCreatename: k8s-certs- hostPath:path: /usr/local/share/ca-certificatestype: DirectoryOrCreatename: usr-local-share-ca-certificates- hostPath:path: /usr/share/ca-certificatestype: DirectoryOrCreatename: usr-share-ca-certificates- hostPath:path: /etc/kubernetes/audit/type: DirectoryOrCreatename: audit-policy
status: {}
策略文件如下所示
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
# do not log requests to the following
- level: NonenonResourceURLs:- "/healthz*"- "/logs"- "/metrics"- "/swagger*"- "/version"# limit level to Metadata so token is not included in the spec/status
- level: MetadataomitStages:- RequestReceivedresources:- group: authentication.k8s.ioresources:- tokenreviews# extended audit of auth delegation
- level: RequestResponseomitStages:- RequestReceivedresources:- group: authorization.k8s.ioresources:- subjectaccessreviews# log changes to pods at RequestResponse level
- level: RequestResponseomitStages:- RequestReceivedresources:- group: "" # core API group; add third-party API services and your API services if neededresources: ["pods"]verbs: ["create", "patch", "update", "delete"]# log everything else at Metadata level
- level: MetadataomitStages:- RequestReceived
移动云帮助中心
云原生安全-从k8s日志审计视角检测自动化工具攻击
http://elkeid.bytedance.com/docs/ElkeidData/k8s_rule.html
https://github.com/jetstack/kubernetes.github.io/blob/master/docs/tasks/debug-application-cluster/audit.md
https://www.armosec.io/blog/kubernetes-audit-log-security/
https://www.datadoghq.com/blog/key-kubernetes-audit-logs-for-monitoring-cluster-security/
https://sysdig.com/learn-cloud-native/kubernetes-security/kubernetes-audit-log/
https://www.datadoghq.com/blog/monitor-kubernetes-audit-logs/#what-are-kubernetes-audit-logshttps://www.youtube.com/watch?v=h0h9QWhGFS4
Reference table for all security alerts - Microsoft Defender for Cloud | Microsoft Learn
https://github.com/knownsec/KCon/blob/master/2021/kubernetes%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E6%B4%BB%E5%8A%A8%E6%A3%80%E6%B5%8B.pdf
https://cloud.tencent.com/developer/article/1988827