透過 kubectl debug 從 Kubernetes 節點產生 CIS 合規報告 - Amazon EKS

協助改進此頁面

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

若要為本使用者指南貢獻內容,請點選每個頁面右側面板中的在 GitHub 上編輯此頁面連結。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

透過 kubectl debug 從 Kubernetes 節點產生 CIS 合規報告

本主題說明如何使用 kubectl debug 命令,為 Amazon EKS 節點產生 CIS (Center for Internet Security) 合規報告。此命令可讓您在 Kubernetes 節點上暫時建立偵錯容器,並透過 apiclient 工具執行 CIS 合規檢查。apiclient 工具是 Bottlerocket OS 的一部分,而 Bottlerocket OS 是 EKS 自動模式節點所使用的作業系統。

先決條件

開始前,請確保您具備以下條件:

  • 可存取 Amazon EKS 叢集,且已設定 kubectl (版本必須至少為 v1.32.0;可輸入 kubectl version 進行檢查)。

  • 具備適當的 IAM 許可以進行節點偵錯。

  • 有效的設定檔,可允許執行偵錯作業 (如 sysadmin)。

如需有關搭配 kubectl 使用偵錯設定檔的詳細資訊,請參閱 Kubernetes 文件中的套用設定檔時對 Pod 或節點進行偵錯

程序

  1. 確認您要執行報告的節點的 AWS 執行個體 ID。使用下列命令列出叢集中的節點。執行個體 ID 可在名稱欄位中找到,且開頭為 i-

    kubectl get nodes
    NAME                  STATUS   ROLES    AGE   VERSION
    i-0ea0ba0f8ef9ad609   Ready    <none>   62s   v1.30.10-eks-1a9dacd
  2. 執行下列命令,並將 <instance-id> 取代為您要查詢的節點的執行個體 ID:

    kubectl debug node/<instance-id> -it --profile=sysadmin --image=public.ecr.aws/amazonlinux/amazonlinux:2023 -- bash -c "yum install -q -y util-linux-core; nsenter -t 1 -m apiclient report cis --level 1 --format text"

    此命令的組成部分包括:

    • kubectl debug node/<instance-id>:在指定的 EC2 執行個體 ID 上建立偵錯工作階段。

    • -it:配置 TTY (命令列 Shell),並保持 stdin 開啟以支援互動式使用。

    • --profile=sysadmin:使用具備適當許可的指定 kubectl 設定檔。

    • --image=public.ecr.aws/amazonlinux/amazonlinux:2023:使用 amazonlinux:2023 作為偵錯的容器映像。

    • bash -c "…​":在 bash shell 中執行下列命令:

      • yum install -q -y util-linux-core:以安靜模式安裝所需的公用程式套件。

      • nsenter -t 1 -m:執行 nsenter 以輸入主機程序 (PID 1) 的命名空間。

      • apiclient report cis --level 1 --format text:執行等級 1 的 CIS 合規報告,並以文字格式輸出結果。

  3. 檢閱報告的文字輸出。

解譯輸出

此命令會產生文字格式的報告,顯示各項 CIS 控制項的合規狀態。輸出內容包括:

  • 個別的 CIS 控制項 ID

  • 每個控制項的描述

  • 每項檢查的通過、失敗或略過狀態

  • 解釋任何合規問題的詳細資訊

以下是在 Bottlerocket 執行個體上執行報告後的輸出範例:

Benchmark name:  CIS Bottlerocket Benchmark
Version:         v1.0.0
Reference:       https://www.cisecurity.org/benchmark/bottlerocket
Benchmark level: 1
Start time:      2025-04-11T01:40:39.055623436Z

[SKIP] 1.2.1     Ensure software update repositories are configured (Manual)
[PASS] 1.3.1     Ensure dm-verity is configured (Automatic)[PASS] 1.4.1     Ensure setuid programs do not create core dumps (Automatic)
[PASS] 1.4.2     Ensure address space layout randomization (ASLR) is enabled (Automatic)
[PASS] 1.4.3     Ensure unprivileged eBPF is disabled (Automatic)
[PASS] 1.5.1     Ensure SELinux is configured (Automatic)
[SKIP] 1.6       Ensure updates, patches, and additional security software are installed (Manual)
[PASS] 2.1.1.1   Ensure chrony is configured (Automatic)
[PASS] 3.2.5     Ensure broadcast ICMP requests are ignored (Automatic)
[PASS] 3.2.6     Ensure bogus ICMP responses are ignored (Automatic)
[PASS] 3.2.7     Ensure TCP SYN Cookies is enabled (Automatic)
[SKIP] 3.4.1.3   Ensure IPv4 outbound and established connections are configured (Manual)
[SKIP] 3.4.2.3   Ensure IPv6 outbound and established connections are configured (Manual)
[PASS] 4.1.1.1   Ensure journald is configured to write logs to persistent disk (Automatic)
[PASS] 4.1.2     Ensure permissions on journal files are configured (Automatic)

Passed:          11
Failed:          0
Skipped:         4
Total checks:    15

如需關於基準的資訊,請參閱 Center for Internet Security (CIS) 的 Kubernetes 基準