在 Azure Kubernetes 服務的 Istio 型服務網格附加元件中,Istio 憑證授權單位 (CA) 預設會產生自簽署的根憑證和金鑰,並使用這些根憑證和金鑰簽署工作負載憑證。 若要保護根 CA 金鑰,您應該使用在安全的離線機器上執行的根 CA。 您可以使用根 CA,發送發出中繼憑證給在每個叢集中執行的 Istio CA 。 Istio CA 可以使用系統管理員指定的憑證和金鑰來簽署工作負載憑證,並將系統管理員指定的根憑證分發至工作負載作為信任的根。 本文說明如何在 Azure Kubernetes 服務的 Istio 型服務網格附加元件中,自備 Istio CA 的憑證和金鑰。
本文說明如何使用 Azure Key Vault 將根憑證、簽署憑證和金鑰作為輸入提供給 Istio 型服務網格附加元件,進而設定 Istio 憑證授權單位
開始之前
驗證 Azure CLI 版本
附加元件需要安裝 Azure CLI 版本 2.57.0 或更新版本。 您可以執行az --version以驗證版本。 若要安裝或升級,請參閱[安裝 Azure CLI][azure-cli-install]。
設定 Azure Key Vault
您需要 Azure Key Vault 資源,才能將憑證和金鑰輸入提供給 Istio 附加元件。
您需要離線產生根憑證、中繼憑證、中繼金鑰和憑證鏈結。 此處的步驟 1-3 具有說明如何產生這些檔案的範例。
使用憑證和金鑰在 Azure Key Vault 中建立密碼:
az keyvault secret set --vault-name $AKV_NAME --name root-cert --file <path-to-folder/root-cert.pem> az keyvault secret set --vault-name $AKV_NAME --name ca-cert --file <path-to-folder/ca-cert.pem> az keyvault secret set --vault-name $AKV_NAME --name ca-key --file <path-to-folder/ca-key.pem> az keyvault secret set --vault-name $AKV_NAME --name cert-chain --file <path-to-folder/cert-chain.pem>為您的叢集啟用密碼存放 CSI 驅動程式的 Azure Key Vault 提供者:
az aks enable-addons --addons azure-keyvault-secrets-provider --resource-group $RESOURCE_GROUP --name $CLUSTER附註
輪替憑證時,若要控制密碼同步至叢集的速度,您可以使用 Azure Key Vault 密碼提供者附加元件的
--rotation-poll-interval參數。 例如:az aks addon update --resource-group $RESOURCE_GROUP --name $CLUSTER --addon azure-keyvault-secrets-provider --enable-secret-rotation --rotation-poll-interval 20s如果你的 Key Vault 使用 Azure RBAC 作為權限模型,請依 照此處的指示,將 Azure 角色 "Key Vault Secrets User" 分配給該附加元件的使用者指派管理身份。 或者,如果您的金鑰庫正在使用金庫存取原則權限模型,請授權該附加元件的使用者指派受控識別,以使用存取原則存取 Azure Key Vault 資源:
OBJECT_ID=$(az aks show --resource-group $RESOURCE_GROUP --name $CLUSTER --query 'addonProfiles.azureKeyvaultSecretsProvider.identity.objectId' -o tsv) az keyvault set-policy --name $AKV_NAME --object-id $OBJECT_ID --secret-permissions get
使用外掛程式 CA 憑證設定 Istio 型服務網格附加元件
在引用稍早建立的 Azure Key Vault 密碼時,為現有的 AKS 叢集啟用 Istio 服務網格附加元件:
az aks mesh enable --resource-group $RESOURCE_GROUP --name $CLUSTER \ --root-cert-object-name root-cert \ --ca-cert-object-name ca-cert \ --ca-key-object-name ca-key \ --cert-chain-object-name cert-chain \ --key-vault-id /subscriptions/$SUBSCRIPTION/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.KeyVault/vaults/$AKV_NAME附註
對於使用由 Istio CA 產生的自簽署根憑證且具有 Istio 附加元件的現有叢集,不支援切換至外掛程式 CA。 您必須先在這些叢集上停用網格,然後使用上述指令再次啟用網格,以傳遞外掛程式 CA 輸入。
驗證 Istio 控制平面已挑選自訂憑證授權單位:
kubectl logs deploy/istiod-asm-1-17 -c discovery -n aks-istio-system | grep -v validationController | grep x509預期的輸出應該會類似:
2023-11-06T15:49:15.493732Z info x509 cert - Issuer: "CN=Intermediate CA - A1,O=Istio,L=cluster-A1", Subject: "", SN: e191d220af347c7e164ec418d75ed19e, NotBefore: "2023-11-06T15:47:15Z", NotAfter: "2033-11-03T15:49:15Z" 2023-11-06T15:49:15.493764Z info x509 cert - Issuer: "CN=Root A,O=Istio", Subject: "CN=Intermediate CA - A1,O=Istio,L=cluster-A1", SN: 885034cba2894f61036f2956fd9d0ed337dc636, NotBefore: "2023-11-04T01:40:02Z", NotAfter: "2033-11-01T01:40:02Z" 2023-11-06T15:49:15.493795Z info x509 cert - Issuer: "CN=Root A,O=Istio", Subject: "CN=Root A,O=Istio", SN: 18e2ee4089c5a7363ec306627d21d9bb212bed3e, NotBefore: "2023-11-04T01:38:27Z", NotAfter: "2033-11-01T01:38:27Z"
憑證授權單位輪替
基於安全性或原則的緣故,您可能需要定期輪替憑證授權單位。 本區段會逐步引導您處理中繼 CA 和根 CA 輪替情境。
中繼憑證授權單位輪替
您可以輪替中繼 CA,同時保持根 CA 不變。 使用新憑證和金鑰檔案更新 Azure Key Vault 資源中的密碼:
az keyvault secret set --vault-name $AKV_NAME --name root-cert --file <path-to-folder/root-cert.pem> az keyvault secret set --vault-name $AKV_NAME --name ca-cert --file <path-to-folder/ca-cert.pem> az keyvault secret set --vault-name $AKV_NAME --name ca-key --file <path-to-folder/ca-key.pem> az keyvault secret set --vault-name $AKV_NAME --name cert-chain --file <path/cert-chain.pem>等候
--rotation-poll-interval的持續時間。 檢查叢集上的憑證是否已根據 Azure Key Vault 資源上更新的新中繼 CA 重新整理。kubectl logs deploy/istiod-asm-1-17 -c discovery -n aks-istio-system | grep -v validationController預期的輸出應該會類似:
2023-11-07T06:16:21.091844Z info Update Istiod cacerts 2023-11-07T06:16:21.091901Z info Using istiod file format for signing ca files 2023-11-07T06:16:21.354423Z info Istiod has detected the newly added intermediate CA and updated its key and certs accordingly 2023-11-07T06:16:21.354910Z info x509 cert - Issuer: "CN=Intermediate CA - A2,O=Istio,L=cluster-A2", Subject: "", SN: b2753c6a23b54d8364e780bf664672ce, NotBefore: "2023-11-07T06:14:21Z", NotAfter: "2033-11-04T06:16:21Z" 2023-11-07T06:16:21.354967Z info x509 cert - Issuer: "CN=Root A,O=Istio", Subject: "CN=Intermediate CA - A2,O=Istio,L=cluster-A2", SN: 17f36ace6496ac2df88e15878610a0725bcf8ae9, NotBefore: "2023-11-04T01:40:22Z", NotAfter: "2033-11-01T01:40:22Z" 2023-11-07T06:16:21.355007Z info x509 cert - Issuer: "CN=Root A,O=Istio", Subject: "CN=Root A,O=Istio", SN: 18e2ee4089c5a7363ec306627d21d9bb212bed3e, NotBefore: "2023-11-04T01:38:27Z", NotAfter: "2033-11-01T01:38:27Z" 2023-11-07T06:16:21.355012Z info Istiod certificates are reloaded工作負載會收到來自 Istio 控制平面的憑證 (預設為 24 小時有效)。 如果您未重新啟動 Pod,全部工作負載都會在 24 小時內根據新的中繼 CA 取得新的葉憑證。 如果您想要強迫全部這些工作負載立即從新的中繼 CA 取得新的葉憑證,則需要重新啟動工作負載。
kubectl rollout restart deployment <deployment name> -n <deployment namespace>
根憑證授權單位輪替
您需要使用根憑證檔案來更新 Azure Key Vault 密碼,讓舊根憑證和新根憑證串接:
az keyvault secret set --vault-name $AKV_NAME --name root-cert --file <path-to-folder/root-cert.pem> az keyvault secret set --vault-name $AKV_NAME --name ca-cert --file <path-to-folder/ca-cert.pem> az keyvault secret set --vault-name $AKV_NAME --name ca-key --file <path-to-folder/ca-key.pem> az keyvault secret set --vault-name $AKV_NAME --name cert-chain --file <path/cert-chain.pem>root-cert.pem的內容遵循下列格式:-----BEGIN CERTIFICATE----- <contents of old root certificate> -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- <contents of new root certificate> -----END CERTIFICATE-----一旦憑證同步至叢集後,檢查
istiod記錄。kubectl logs deploy/istiod-asm-1-17 -c discovery -n aks-istio-system預期輸出:
2023-11-07T06:42:00.287916Z info Updating new ROOT-CA 2023-11-07T06:42:00.287928Z info update root cert and generate new dns certs 2023-11-07T06:42:00.288254Z info Update trust anchor with new root cert 2023-11-07T06:42:00.288279Z info trustBundle updating Source IstioCA with certs 2023-11-07T06:42:00.288298Z info Istiod has detected the newly added intermediate CA and updated its key and certs accordingly 2023-11-07T06:42:00.288303Z info Istiod certificates are reloaded您必須等候 24 小時 (葉憑證有效性的預設時間),或強制重新啟動全部工作負載。 如此一來,全部工作負載就會同時辨識新舊憑證授權單位以進行 mTLS 驗證。
kubectl rollout restart deployment <deployment name> -n <deployment namespace>您現在可以只使用新的 CA 來更新 Azure Key Vault 密碼 (無需使用舊 CA):
az keyvault secret set --vault-name $AKV_NAME --name root-cert --file <path-to-folder/root-cert.pem> az keyvault secret set --vault-name $AKV_NAME --name ca-cert --file <path-to-folder/ca-cert.pem> az keyvault secret set --vault-name $AKV_NAME --name ca-key --file <path-to-folder/ca-key.pem> az keyvault secret set --vault-name $AKV_NAME --name cert-chain --file <path/cert-chain.pem>一旦憑證同步至叢集後,檢查
istiod記錄。kubectl logs deploy/istiod-asm-1-17 -c discovery -n aks-istio-system | grep -v validationController預期輸出:
2023-11-07T08:01:17.780299Z info x509 cert - Issuer: "CN=Intermediate CA - B1,O=Istio,L=cluster-B1", Subject: "", SN: 1159747c72cc7ac7a54880cd49b8df0a, NotBefore: "2023-11-07T07:59:17Z", NotAfter: "2033-11-04T08:01:17Z" 2023-11-07T08:01:17.780330Z info x509 cert - Issuer: "CN=Root B,O=Istio", Subject: "CN=Intermediate CA - B1,O=Istio,L=cluster-B1", SN: 2aba0c438652a1f9beae4249457023013948c7e2, NotBefore: "2023-11-04T01:42:12Z", NotAfter: "2033-11-01T01:42:12Z" 2023-11-07T08:01:17.780345Z info x509 cert - Issuer: "CN=Root B,O=Istio", Subject: "CN=Root B,O=Istio", SN: 3f9da6ddc4cb03749c3f43243a4b701ce5eb4e96, NotBefore: "2023-11-04T01:41:54Z", NotAfter: "2033-11-01T01:41:54Z"從本文所顯示的範例輸出中,您可以看到我們已從根 A (在啟用附加元件時使用) 移至根 B。