简体   繁体   English

如何为 Azure Keyvault + SecretProviderClass + imagePullSecrets+ Private docker 存储库配置部署文件

[英]How to configure deployment file for Azure Keyvault + SecretProviderClass + imagePullSecrets+ Private docker repository

How to configure deployment file for the combination of Azure Keyvault + SecretProviderClass + imagePullSecrets+ Private docker repository.如何为 Azure Keyvault + SecretProviderClass + imagePullSecrets+ Private docker 存储库的组合配置部署文件。

We have private docker repository to maintain images, now we have a requirement maintaining the credentials of that Docker repository in Azure key vault, import it into AKS using SecretProviderClass, use that secret under 'imagePullSecrets'我们有私有 docker 存储库来维护图像,现在我们需要在 Azure 密钥保管库中维护 Docker 存储库的凭据,使用 SecretProviderClass 将其导入 AKS,使用“imagePullSecrets”下的秘密

# This is a SecretProviderClass example using system-assigned identity to access your key vault
apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
  name: azure-kvname-system-harbor
spec:
  provider: azure
  secretObjects:
  - secretName: harborcredentialvault
    data:
    - key: harborcredentialvaultkey
      objectName: harborcredentialvault
    type: kubernetes.io/dockerconfigjson
  parameters:
    usePodIdentity: "false"
    useVMManagedIdentity: "true"    # Set to true for using managed identity
    userAssignedIdentityID: ""      # If empty, then defaults to use the system assigned identity on the VM
    keyvaultName: "<Keyvault name>"
    cloudName: ""                   # [OPTIONAL for Azure] if not provided, the Azure environment defaults to AzurePublicCloud
    objects:  |
      array:
        - |
          objectName: harborcredentialvault
          objectType: secret        # object types: secret, key, or cert
          objectVersion: ""         # [OPTIONAL] object versions, default to latest if empty
    tenantId: "<tenant ID>"           # The tenant ID of the key vault
        - name: harborcredentialvault
          valueFrom: 
            secretKeyRef:
              name: keyvault-secret
              key: harborcredentialvaultkey
      imagePullSecrets:
       - name: ${harborcredentialvault}
        volumeMounts:
         - mountPath: "/mnt/secrets-store"
           name: secrets-store01-inline
           readOnly: true
       - name: secrets-store01-inline
         csi:
           driver: secrets-store.csi.k8s.io
           readOnly: true
           volumeAttributes:
             secretProviderClass: "azure-kvname-system-harbor"

As you do not provided a real question or an error im will be a bit general:由于您没有提供真正的问题或错误,我会有点笼统:

For the AKS/KeyVault integration it is important to understand that you are accessing the Key Vault with the Kubelet Identity of the Nodepool and not with the Managed Identity of the AKS as described here .对于 AKS/KeyVault 集成,重要的是要了解您正在使用 Nodepool 的 Kubelet 身份访问 Key Vault,而不是使用此处所述的 AKS 的托管身份。 So if you are using Managed Identity userAssignedIdentityID should not be empty.因此,如果您使用的是托管身份, userAssignedIdentityID不应为空。

So we need to give the Kubelet Identity access to the Key Vault, for example like this:因此,我们需要授予 Kubelet Identity 访问 Key Vault 的权限,例如:

export KUBE_ID=$(az aks show -g <resource group> -n <aks cluster name> --query identityProfile.kubeletidentity.objectId -o tsv)
export AKV_ID=$(az keyvault show -g <resource group> -n <akv name> --query id -o tsv)
az role assignment create --assignee $KUBE_ID --role "Key Vault Secrets Officer" --scope $AKV_ID

The result of $KUBE_ID needs to be also added the the SecretProviderClass : $KUBE_ID 的结果也需要添加到SecretProviderClass

userAssignedIdentityID: "RESULT"

From this official example here your SecretProviderClass looks good for this use case.从这里的官方示例中,您的SecretProviderClass看起来很适合这个用例。

This would be the pod config:这将是 pod 配置:

spec:
  containers:
  - name: demo
    image: demo
    volumeMounts:
    - name: secrets-store-inline
      mountPath: "/mnt/secrets-store"
      readOnly: true
  imagePullSecrets:
    - name: harborcredentialvault
  volumes:
  - name: secrets-store-inline
    csi:
      driver: secrets-store.csi.k8s.io
      readOnly: true
      volumeAttributes:
        secretProviderClass: "azure-kvname-system-harbor"

This should sync the Key Vault secret to a Kube.netes secret.这应该将 Key Vault 机密同步到 Kube.netes 机密。 Here is also the documentation .这也是文档

One thing you should consider is = The secrets will only sync once you start a pod mounting the secrets. Solely relying on the syncing with Kube.netes secrets feature thus does not work.您应该考虑的一件事是 = The secrets will only sync once you start a pod mounting the secrets. Solely relying on the syncing with Kube.netes secrets feature thus does not work. The secrets will only sync once you start a pod mounting the secrets. Solely relying on the syncing with Kube.netes secrets feature thus does not work.

That being said you maybe would need another pod with a public image to sync your private pull secrets for your cluster bcs your pod would not start as it can not pull the image from your private registry.话虽如此,您可能需要另一个带有公共映像的 pod 来为您的集群同步您的私有 pull secrets,因为您的 pod 无法启动,因为它无法从您的私有注册表中提取映像。

@Philip Welz answer helped me to find the below solution @Philip Welz 的回答帮助我找到了以下解决方案

SecretProviderClass sample yaml SecretProviderClass 示例 yaml

# This is a SecretProviderClass example using system-assigned identity to access your key vault
apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
  name: azure-kvname-system-harbor
spec:
  provider: azure
  secretObjects:
    - secretName: dockerconfig
      type: kubernetes.io/dockerconfigjson
      data:
        - objectName: harborcredentialvault
          key: .dockerconfigjson
  parameters:
    usePodIdentity: "false"
    useVMManagedIdentity: "true"    # Set to true for using managed identity
    userAssignedIdentityID: ""      # If empty, then defaults to use the system assigned identity on the VM
    keyvaultName: "<Keyvault name>"
    cloudName: ""                   # [OPTIONAL for Azure] if not provided, the Azure environment defaults to AzurePublicCloud
    objects:  |
      array:
        - |
          objectName: harborcredentialvault
          objectType: secret        # object types: secret, key, or cert
          objectVersion: ""         # [OPTIONAL] object versions, default to latest if empty
    tenantId: "<tenant ID>"           # The tenant ID of the key vault

Deployment sample yaml file部署示例 yaml 文件

spec:
  containers:
  - name: demo
    image: demo
    volumeMounts:
    - name: secrets-store-inline
      mountPath: "/mnt/secrets-store"
      readOnly: true
  imagePullSecrets:
    - name: dockerconfig
  volumes:
  - name: secrets-store-inline
    csi:
      driver: secrets-store.csi.k8s.io
      readOnly: true
      volumeAttributes:
        secretProviderClass: "azure-kvname-system-harbor"

Create Secret in Keyvault, make sure value should be in below JSON format在 Keyvault 中创建 Secret,确保值应为以下 JSON 格式

Key: harborcredentialvault
Value: {
"auths": {
"dockerwebsite.com": {
"username": "username",
"password": "password"
}
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 Python 中的专用端点访问 Azure Keyvault? - How to access Azure Keyvault via private endpoint in Python? Azure devops 需要访问 Azure keyvault 仅限私有链接 - Azure devops need to access Azure keyvault which is restrict to private link 如何从管道 Azure Devops 访问私有存储库? - How to access a private repository from a pipeline Azure Devops? 在 Azure 中国连接到 KeyVault - Connect to KeyVault in Azure China 使用 Azure Keyvault 优化 GetSecret - Optimization for GetSecret with Azure Keyvault Azure 数据工厂在 Devops 上配置存储库 - Azure Data Factory Configure Repository on Devops 如何将一个订阅下的一个 azure 租户(帐户)keyvault 中的密钥共享到另一个订阅中的另一个 azure 租户(帐户)keyvault - How to share a key from one azure tenant(account) keyvault under one subscription to another azure tenant(account) keyvault in another subscription 如何使用另一个二头肌模块文件中的密钥库 - How to use keyvault that is in another bicep module file Azure Keyvault 本地问题 - Azure Keyvault Local Issues 如何获取与个人用户相关的Azure keyvault的访问策略列表? - How to get the list of access policies of an Azure keyvault related to individual users?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM