排解部署具備權限的 Autopilot 工作負載問題


本頁面說明如何解決在 Google Kubernetes Engine (GKE) Autopilot 叢集中部署具備特殊權限工作負載時發生的問題。

允許清單同步處理問題

部署 AllowlistSynchronizer 時,GKE 會嘗試安裝並同步處理您指定的允許清單檔案。如果同步處理失敗,AllowlistSynchronizerstatus 欄位會回報錯誤。

取得 AllowlistSynchronizer 物件的狀態:

kubectl get allowlistsynchronizer ALLOWLIST_SYNCHRONIZER_NAME -o yaml

輸出結果會與下列內容相似:

...
status:
  conditions:
  - type: Ready
    status: "False"
    reason: "SyncError"
    message: "some allowlists failed to sync: example-allowlist-1.yaml"
    lastTransitionTime: "2024-10-12T10:00:00Z"
    observedGeneration: 2
  managedAllowlistStatus:
    - filePath: "gs://path/to/allowlist1.yaml"
      generation: 1
      phase: Installed
      lastSuccessfulSync: "2024-10-10T10:00:00Z"
    - filePath: "gs://path/to/allowlist2.yaml"
      phase: Failed
      lastError: "Initial install failed: invalid contents"
      lastSuccessfulSync: "2024-10-08T10:00:00Z"

conditions.message 欄位和 managedAllowlistStatus.lastError 欄位 會提供錯誤的詳細資訊。請參考這些資訊解決問題。

部署具備特殊權限的工作負載時發生問題

成功安裝許可清單後,請在叢集中部署相應的具備權限工作負載。在某些情況下,GKE 可能會拒絕工作負載。

請嘗試下列解決方法:

  • 確認叢集的 GKE 版本符合工作負載的版本需求。
  • 確認您部署的工作負載適用於許可清單檔案。

如要查看特權工作負載遭拒的原因,請向 GKE 要求提供有關許可清單違規事項的詳細資訊:

  1. 取得叢集中已安裝的允許清單:

    kubectl get workloadallowlist
    

    找出應套用至具特殊權限工作負載的許可清單名稱。

  2. 在文字編輯器中開啟具備權限工作負載的 YAML 資訊清單。如果無法存取 YAML 資訊清單 (例如工作負載部署程序使用其他工具),請與工作負載供應商聯絡,提出問題。略過其餘步驟。

  3. 在具備權限的工作負載 Pod 規格的 spec.metadata.labels 區段中新增下列標籤:

    labels:
      cloud.google.com/matching-allowlist: ALLOWLIST_NAME
    

    ALLOWLIST_NAME 替換為您在上一個步驟中取得的允許清單名稱。請使用 kubectl get workloadallowlist 指令輸出中的名稱,而非允許清單檔案的路徑。

  4. 儲存資訊清單,然後將工作負載套用至叢集:

    kubectl apply -f WORKLOAD_MANIFEST_FILE
    

    WORKLOAD_MANIFEST_FILE 替換為資訊清單檔案的路徑。

    輸出內容會詳細說明工作負載中哪些欄位與指定的允許清單不符,如下列範例所示:

    Error from server (GKE Warden constraints violations): error when creating "STDIN": admission webhook "warden-validating.common-webhooks.networking.gke.io" denied the request:
    
    ===========================================================================
    Workload Mismatches Found for Allowlist (example-allowlist-1):
    ===========================================================================
    HostNetwork Mismatch: Workload=true, Allowlist=false
    HostPID Mismatch: Workload=true, Allowlist=false
    Volume[0]: data
             - data not found in allowlist. Verify volume with matching name exists in allowlist.
    Container[0]:
    - Envs Mismatch:
            - env[0]: 'ENV_VAR1' has no matching string or regex pattern in allowlist.
            - env[1]: 'ENV_VAR2' has no matching string or regex pattern in allowlist.
    - Image Mismatch: Workload=k8s.gcr.io/diff/image, Allowlist=k8s.gcr.io/pause2. Verify that image string or regex match.
    - SecurityContext:
            - Capabilities.Add Mismatch: the following added capabilities are not permitted by the allowlist: [SYS_ADMIN SYS_PTRACE]
    - VolumeMount[0]: data
            - data not found in allowlist. Verify volumeMount with matching name exists in allowlist.
    

    在這個例子中,發生了下列違規行為:

    • 工作負載指定 hostNetwork: true,但允許清單未指定 hostNetwork: true
    • 工作負載指定 hostPID: true,但允許清單未指定 hostPID: true
    • 工作負載指定名為 data 的磁碟區,但允許清單未指定名為 data 的磁碟區。
    • 容器指定了名為 ENV_VAR1ENV_VAR2 的環境變數,但允許清單未指定這些環境變數。
    • 容器指定映像檔 k8s.gcr.io/diff/image,但允許清單指定 k8s.gcr.io/pause2
    • 容器新增了 SYS_ADMINSYS_PTRACE 功能,但允許清單不允許新增這些功能。
    • 容器指定名為 data 的磁碟區掛接,但允許清單未指定名為 data 的磁碟區掛接。

如果您部署的第三方供應商提供的工作負載有違規情形,請向該供應商回報問題,以解決違規事項。提供上一個步驟的輸出內容。

具備特殊權限的工作負載和允許清單的錯誤與功能要求

合作夥伴有責任建立、開發及維護自己的高權限工作負載和允許清單。如果遇到錯誤,或是對特許工作負載或許可清單有功能要求,請與對應的合作夥伴聯絡。

後續步驟