【问题标题】:Unable to read Vault secrets - using Vault Sidecar Injector无法读取 Vault 机密 - 使用 Vault Sidecar Injector
【发布时间】:2020-11-04 12:16:59
【问题描述】:

无法使用以下设置读取存储在 Vault 中路径 /secrets/apims/ABC_CONFIG 的机密

在保险柜中创建的策略:

  vault policy write policy_name - <<EOF
    path "secret/apims/*" {
      capabilities = ["read"]
    }

在 Vault 中创建的角色

vault write auth/kubernetes/role/role_name\
    bound_service_account_names=service_account_name \
    bound_service_account_namespaces=default \
    policies=policy_name \
    ttl=24h

在外部保险库上使用 Kubernetes 保险库边车注入器。 Kubernetes 上的部署是这样的

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: "nginx-5"
  namespace: "default"
  labels:
    app: "nginx-5"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: "nginx-5"
  template:
    metadata:
      annotations: 
        vault.hashicorp.com/agent-inject: "true"
        vault.hashicorp.com/agent-inject-secret-credentials.conf: secret/ABC_CONFIG
        vault.hashicorp.com/role: role_name
      labels:
        app: "nginx-5"
    spec:
      containers:
      - name: "nginx-5"
        image: "nginx:latest"
      serviceAccountName: service_account_name

虽然 Kubernetes 已通过 Vault 成功授权,但读取特定密钥失败并出现 403。

感谢您的帮助。

【问题讨论】:

    标签: kubernetes google-kubernetes-engine hashicorp-vault


    【解决方案1】:

    看起来服务帐户和 Vault 角色中定义的角色名称都与部署中的不匹配。

    • 服务帐户 = service_account_name
    • 角色 = 角色名称
    vault write auth/kubernetes/role/role_name\
        bound_service_account_names=service_account_name \
        bound_service_account_namespaces=default \
        policies=policy_name \
        ttl=24h
    
    • 服务帐户 = sa-vault-auth
    • 角色 = apims
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: "nginx-5"
      template:
        metadata:
          annotations: 
            vault.hashicorp.com/agent-inject: "true"
            vault.hashicorp.com/agent-inject-secret-credentials.conf: secret/ABC_CONFIG
            vault.hashicorp.com/role: apims ?
          labels:
            app: "nginx-5"
        spec:
          containers:
          - name: "nginx-5"
            image: "nginx:latest"
          serviceAccountName: sa-vault-auth ?
    ...
    

    这还假设 policies=policy_name 是您最初在 Vault 中创建的策略的名称。

    【讨论】:

    • 这是我的错误,忘记清理 kubernetes 部署文件的更改名称,但我在所有地方都使用相同的角色/策略和 serviceAccount。仍然是同样的错误。我也会更新问题,谢谢。
    • 您是否发现了其他可能造成问题的内容?
    • 我真的没有,一定是某个地方的名字不匹配。
    猜你喜欢
    • 2021-10-24
    • 2022-08-23
    • 1970-01-01
    • 2018-10-02
    • 2022-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多