Workload Identity Federation (WIF) 可讓 Apigee 工作負載使用外部供應商的憑證,取得 Apigee API 的 Google 安全性權杖。本頁說明如何使用邊車容器,為 Apigee Hybrid 設定 WIF。這個方法是使用 Kubernetes Projected 服務帳戶權杖的替代方案,如「在 AKS 和 EKS 上啟用 Workload Identity 聯盟」一文所述。如要使用外部或自訂的識別資訊提供者 (IDP) 擷取驗證權杖,請使用 Sidecar 方法。
使用這個方法時,您可以在非 GKE 平台上,搭配 Workload Identity Federation 使用 Sidecar,從偏好的識別資訊提供者 (IdP) 掛接安全權杖,以進行服務帳戶驗證。
事前準備
這個程序假設您已為 Google Cloud 雲端專案設定 Workload Identity Federation,包括建立身分集區和 provider,以及授予 Kubernetes 服務帳戶適當的 IAM 權限。詳情請參閱「在 AKS 和 EKS 上啟用 Workload Identity 聯盟」。
設定 Apigee Hybrid
如要透過 Sidecar 驗證啟用 Workload Identity 聯盟,請在 overrides.yaml 檔案中設定 Sidecar。指定邊車容器,以及在邊車和 Apigee Hybrid 元件之間共用資料的任何磁碟區。如果您使用 Vault,請新增 Sidecar 從 IDP 擷取權杖時所需的註解。
您只需要為所有元件設定一次 overrides.yaml 檔案中的 gcp.federatedWorkloadIdentity.sidecarSpec 區段。套用設定後,Helm 資訊套件會在遇到 APIGEE_COMPONENT 值時,為每個元件插入適當的元件名稱。
在 overrides.yaml 檔案中新增以下設定。選取符合您用途的範例,例如 Kubernetes Secret、服務帳戶 JSON 金鑰檔案或 Vault:
密鑰或檔案
gcp: federatedWorkloadIdentity: enabled: true type: "sidecar" sidecarSpec: volumes: source-creds - name: secret: secretName: apigee-hybrid-APIGEE_COMPONENT container: - name: apigee-fwi-sidecar env: APIGEE_COMPONENT image: your-custom-sidecar-image volumeMounts: - name: shared-mount mountPath: /shared - name: source-creds mountPath: /source-creds readonly: true
保管箱
gcp: federatedWorkloadIdentity: enabled: true type: "sidecar" sidecarSpec: annotations: - vault.hashicorp.com/agent-inject: 'true' - vault.hashicorp.com/agent-pre-populate-only: 'false' - vault.hashicorp.com/log-level: 'trace' - vault.hashicorp.com/ca-cert: VAULT_CA_CERT_PATH - vault.hashicorp.com/namespace: 'VAULT_NAMESPACE' - vault.hashicorp.com/agent-service-account-token-volume-name: VAULT_TOKEN # for example: 'vault-token' - vault.hashicorp.com/secret-volume-path: VAULT_SECRET_VOLUME_PATH # for example: '/var/vault-data' - vault.hashicorp.com/service: VAULT_SERVICE_URL:8200 # For example: '127.0.0.1:8200' or 'https://dev-hcvault.nam.nsroot.net:8200' volumes: source-creds - name: secret: secretName: apigee-hybrid-APIGEE_COMPONENT container: - name: apigee-fwi-sidecar env: APIGEE_COMPONENT image: your-custom-sidecar-image volumeMounts: - name: shared-mount mountPath: /shared - name: source-creds mountPath: /source-creds readonly: true
如果您的 Sidecar 需要透過 Vault 註解注入密鑰,您可以將密鑰新增至需要 Sidecar 的每個元件。例如:
mart: annotations: vault.hashicorp.com/agent-inject: "true" vault.hashicorp.com/role: "VAULT_ROLE" vault.hashicorp.com/agent-inject-secret-token: "VAULT_SECRET_PATH" vault.hashicorp.com/agent-inject-template-token: | }- with secret "VAULT_SECRET_PATH" -}} {{ .Data.data.token }} {{- end -} runtime: annotations: vault.hashicorp.com/agent-inject: "true" vault.hashicorp.com/role: "VAULT_ROLE" vault.hashicorp.com/agent-inject-secret-token: "VAULT_SECRET_PATH" vault.hashicorp.com/agent-inject-template-token: | {{- with secret "secrets/my-secret-path" -}} {{ .Data.data.token }} {{- end -}} ... other components ...
其中:
gcp.federatedWorkloadIdentity.enabled:必須為true。gcp.federatedWorkloadIdentity.type:必須為"sidecar"。這會告知 Apigee Hybrid 使用 Sidecar 方法進行 Workload Identity Federation。gcp.federatedWorkloadIdentity.sidecarSpec.container:自訂補充容器的 Kubernetes 容器規格。您必須指定可從 IdP 擷取權杖的自訂image。gcp.federatedWorkloadIdentity.sidecarSpec.volumes:要在混合 Pod 中掛接的其他磁碟區清單。這是權杖掛接的磁碟區。gcp.federatedWorkloadIdentity.sidecarSpec.annotations:(僅限 Vault) 要套用至混合式 Pod 的註解對應。[component].annotations:(僅限保管箱,選用) 如有需要,可將註解對應至個別混合元件。
更新 overrides.yaml 檔案後,請將變更套用至叢集。
執行下列指令,更新每個混合式元件:
- 確認您位於
apigee-charts/目錄。 - 升級 Apigee Operator/Controller:
helm upgrade operator apigee-operator/ \ --install \ --namespace APIGEE_NAMESPACE \ -f OVERRIDES_FILE
- 升級 Apigee 資料儲存庫:
helm upgrade datastore apigee-datastore/ \ --install \ --namespace APIGEE_NAMESPACE \ -f OVERRIDES_FILE
- 升級 Apigee 遙測功能:
helm upgrade telemetry apigee-telemetry/ \ --install \ --namespace APIGEE_NAMESPACE \ -f OVERRIDES_FILE
- 升級 Apigee Redis:
helm upgrade redis apigee-redis/ \ --install \ --namespace APIGEE_NAMESPACE \ -f OVERRIDES_FILE
- 升級 Apigee Ingress 管理工具:
helm upgrade ingress-manager apigee-ingress-manager/ \ --install \ --namespace APIGEE_NAMESPACE \ -f OVERRIDES_FILE
- 升級 Apigee 機構:
helm upgrade ORG_NAME apigee-org/ \ --install \ --namespace APIGEE_NAMESPACE \ -f OVERRIDES_FILE
- 升級環境。
一次只能安裝一個環境。使用
--set env=ENV_NAME 指定環境。helm upgrade ENV_RELEASE_NAME apigee-env/ \ --install \ --namespace APIGEE_NAMESPACE \ --set env=ENV_NAME \ -f OVERRIDES_FILE
- 升級環境群組 (
virtualhosts)。您一次只能升級一個環境群組 (虛擬主機)。使用
--set envgroup=ENV_GROUP_NAME 指定環境群組。針對 overrides.yaml 檔案中提及的每個環境群組,重複執行下列指令:helm upgrade ENV_GROUP_RELEASE_NAME apigee-virtualhost/ \ --install \ --namespace APIGEE_NAMESPACE \ --set envgroup=ENV_GROUP_NAME \ -f OVERRIDES_FILE
如需詳細資訊,請參閱:
gcp.federatedWorkloadIdentity.typegcp.federatedWorkloadIdentity.sidecarSpec.annotationsgcp.federatedWorkloadIdentity.sidecarSpec.containergcp.federatedWorkloadIdentity.sidecarSpec.volumes