網址:https://github.com/Shopify/kubeaudit
可以用來稽核 kubernetes 叢集的工具,檢查的項目有
- 確保容器以非 root 身份執行
 
- 確保容器的根目錄是唯讀
 
- 移除有危險的 capability
 
- 不執行 privileged
 
- 陸續增加中
 
安裝
直接從 github release 下載二進位檔案,然後放到 /usr/local/bin 就可以了。
使用
有三種模式
- Manifest mode
 
- Local mode
 
- Cluster mode
 
Manifest mode
Manifest mode 就是掃檔案,意思是如果你有寫好的 yaml 檔案,kubeaudit 可以直接掃 yaml 檔案
kubeaudit all -f "/path/to/manifest.yml"
掃完會輸出掃描結果。
需要修正的話,可以用 autofix 來自動修正。
kubeaudit autofix -f "/path/to/manifest.yml"
怕改爛的話,可以輸出到另外一個檔案
kubeaudit autofix -f "/path/to/manifest.yml" -o "/path/to/fixed"
Cluster mode
Cluster mode 就是掃描當前的 Kubernetes 叢集,不要加上 -f 參數就可以
kubeaudit all
Local mode
Local mode 是在你管理多座 kubernetes 叢集時,可以指定 kubeconfig 跟 context,例如
kubeaudit all --kubeconfig "/path/to/config" --context my_cluster
設定
大部份掃描工具都會提供設定,讓開發者可以決定要掃描哪些項目,kubeaudit 也有,格式是 yaml 。
enabledAuditors:
  # Auditors are enabled by default if they are not explicitly set to "false"
  apparmor: false
  asat: false
  capabilities: true
  deprecatedapis: true
  hostns: true
  image: true
  limits: true
  mounts: true
  netpols: true
  nonroot: true
  privesc: true
  privileged: true
  rootfs: true
  seccomp: true
auditors:
  capabilities:
    # add capabilities needed to the add list, so kubeaudit won't report errors
    allowAddList: ['AUDIT_WRITE', 'CHOWN']
  deprecatedapis:
    # If no versions are specified and the'deprecatedapis' auditor is enabled, WARN
    # results will be genereted for the resources defined with a deprecated API.
    currentVersion: '1.22'
    targetedVersion: '1.25'
  image:
    # If no image is specified and the 'image' auditor is enabled, WARN results
    # will be generated for containers which use an image without a tag
    image: 'myimage:mytag'
  limits:
    # If no limits are specified and the 'limits' auditor is enabled, WARN results
    # will be generated for containers which have no cpu or memory limits specified
    cpu: '750m'
    memory: '500m'
- enabledAuditors 是要啟用的稽核項目
 
- auditors 下方則是每個稽核項目的設定
 
總結
透過使用 kubeaudit 這個工具,可以稽核 kubernetes 叢集,避免放上有危險的設定,是很實用的工具。