#!/bin/bash
# 配置參數
LOG_FILE="/var/log/k8s_security_audit.log"
# 檢查并創建日志文件
if [ ! -f "$LOG_FILE" ]; then
touch "$LOG_FILE"
fi
# 記錄日志函數
log() {
echo "$(date +"%Y-%m-%d %H:%M:%S") - $1" >> "$LOG_FILE"
}
# 檢查安全配置
log "Starting security audit..."
kubectl get nodes -o wide
kubectl get pods --all-namespaces -o wide
kubectl get roles --all-namespaces
kubectl get rolebindings --all-namespaces
kubectl get clusterroles
kubectl get clusterrolebindings
log "Security audit completed successfully."