无法读取Vault机密-使用Vault Sidecar Injector

时间:2020-07-15 04:04:00

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

使用以下设置无法读取路径为/ secrets / apims / ABC_CONFIG的保管箱中存储的机密

在保险柜中创建的政策:

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

在保险柜中创建的角色

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已成功获得保险柜的授权,但读取特定密钥失败并显示403。

image1

image2

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

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

  • 服务帐户= service_account_name
  • 角色= role_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是您最初在保险柜中创建的策略的名称。