如何: 使用秘钥的作用域限定

应用程序从秘钥存储介质中读取时,需要使用作用域来限定

You can read guidance on setting up secret store components to configure a secret store for an application. 一旦配置完毕,默认情况下 任何 该仓库内定义的密钥都可以从 Dapr 应用程序访问。

要限制 Dapr 应用程序访问密钥的话, 您可以通过向应用程序配置添加密钥作用域政策并限制权限来定义密钥作用域。 Follow these instructions to define an application configuration.

The secret scoping policy applies to any secret store, whether that is a local secret store, a Kubernetes secret store or a public cloud secret store. For details on how to set up a secret stores read How To: Retrieve a secret

观看这个 视频 演示如何让你的应用程序使用密钥作用域。

场景1:拒绝访问所有密钥仓库

此示例使用 Kubernetes。 默认 Kubernetes 的密钥仓库会添加到您的 Dapr 应用程序。 在某些情况下,可能有必要拒绝某个应用程序访问 Dapr 密钥。 要添加此配置,请按照下面的步骤:

定义下面 appconfig.yaml 配置,并使用命令 kubectl apply -f appconfig.yaml 到 Kubernetes 集群。

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  secrets:
    scopes:
      - storeName: kubernetes
        defaultAccess: deny

For applications that need to be denied access to the Kubernetes secret store, follow these instructions, and add the following annotation to the application pod.

dapr.io/config: appconfig

定义后,应用程序不再能访问 Kubernetes 密钥仓库的任何密钥。

场景2:只允许访问密钥仓库中的某些密钥

这个示例使用一个名为 vault 的密钥仓库。 例如,这可能是已经设置在您的应用程序上的 Hashicorp 密钥仓库组件。 允许 Dapr 应用程序只访问在 vault 密钥仓库的 secret1secret2 密钥, 需要定义下面的 appconfig.yaml:

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  secrets:
    scopes:
      - storeName: vault
        defaultAccess: deny
        allowedSecrets: ["secret1", "secret2"]

此示例定义了名为 vault 的密钥仓库配置。 密钥仓库的默认访问权限是deny,而有些密钥可以通过应用程序基于allowedSecrets列表访问。 Follow these instructions to apply configuration to the sidecar.

场景3:拒绝访问密钥仓库中的某些敏感密钥

定义以下 config.yaml:

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  secrets:
    scopes:
      - storeName: vault
        defaultAccess: allow # this is the default value, line can be omitted
        deniedSecrets: ["secret1", "secret2"]

这个示例使用一个名为 vault 的密钥仓库。 上面的配置明确禁止从名为 vault 的密钥仓库访问 secret1secret2 ,但允许访问所有其他密钥。 Follow these instructions to apply configuration to the sidecar.

权限优先级

allowedSecretsdeniedSecrets列表值优先于defaultAccess策略。

场景默认权限允许的密钥被拒绝的密钥权限
1 - 仅默认访问拒绝/允许为空为空拒绝/允许
2 - 默认拒绝允许列表拒绝[“s1”]为空只能访问"s1"
3 - 默认允许拒绝列表允许为空[“s1”]仅限"s1"无法访问
4 - 默认允许允许列表允许[“s1”]为空只能访问"s1"
5 - 默认拒绝拒绝列表拒绝为空[“s1”]拒绝
6 - 两个列表的默认拒绝/允许拒绝/允许[“s1”][“s2”]只能访问"s1"

相关链接

howto-secrets/