
關於kubeaudit
kubeaudit是一款針對Kubernetes集群安全的審計工具,該工具基於命令行實現其功能,並通過Golang包幫助廣大研究人員審計Kubernetes集群中的各種安全問題,其中包括以非root權限運行或使用只讀root文件系統等等。
工具安裝Brew下載源碼廣大研究人員還可以直接訪問該項目的【Releases頁面】下載最新的官方穩定版。自定義構建該項目可能隨時會進行代碼更新,如需使用最新版本的功能,你可以選擇進行自定義構建,在構建前別忘了在本地設備上安裝並配置好Go v1.17+環境,然後運行下列命令:go get -v github.com/Shopify/kubeauditDocker使用該項目還提供了一個Docker鏡像:shopify/kubeaudit,廣大研究人員也可以通過Docker鏡像來運行kubeaudit。工具使用
Manifest模式我們可以通過「-f/--manifest」選項來給工具提供一個Kubernetes Manifest文件,此時kubeaudit將會審計這個Manifest文件。
kubeaudit all -f "/path/to/manifest.yml"$ kubeaudit all -f "internal/test/fixtures/all_resources/deployment-apps-v1.yml"---------------- Results for --------------- apiVersion: apps/v1 kind: Deployment metadata: name: deployment namespace: deployment-apps-v1---------------------------------------------- [error] AppArmorAnnotationMissing Message: AppArmor annotation missing. The annotation 'container.apparmor.security.beta.kubernetes.io/container' should be added. Metadata: Container: container MissingAnnotation: container.apparmor.security.beta.kubernetes.io/container-- [error] AutomountServiceAccountTokenTrueAndDefaultSA Message: Default service account with token mounted. automountServiceAccountToken should be set to 'false' or a non-default service account should be used.-- [error] CapabilityShouldDropAll Message: Capability not set to ALL. Ideally, you should drop ALL capabilities and add the specific ones you need to the add list. Metadata: Container: container Capability: AUDIT_WRITE...如果沒有報錯並且沒有安全問題的話,則會返回下列內容:All checks completed. 0 high-risk vulnerabilities found自動修復Manifest模式還支持使用「autofix」命令自動修復所有的安全問題:kubeaudit autofix -f "/path/to/manifest.yml"集群模式kubeaudit支持檢測當前環境是否是集群中的一個容器,並嘗試審計該集群中所有的Kubernetes資源:本地模式kubeaudit將會使用本地kubeconfig文件($HOME/.kube/config)嘗試與一個集群進行連接,可以使用「--kubeconfig」選項來指定kubeconfig路徑:kubeaudit all --kubeconfig "/path/to/config" --context my_cluster許可證協議項目地址https://github.com/Shopify/kubeaudit參考資料https://pkg.go.dev/github.com/Shopify/kubeaudithttps://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/