我有一个使用 dapr 的 .NET Aspire 应用程序。我目前正在尝试使用 YAML 配置从 Azure Key Vault 中获取 Secret。在 ASP.NET Aspire 中检索服务总线的秘密失败,但 keyvault.yaml 似乎可以工作,因为使用
检索秘密
curl http://localhost:49688/v1.0/secrets/azurekeyvault/some-servicebus-connectionstring 检索秘密。
但是,servicebus.yaml 无法正确检索密钥。我做错了什么?
keyvault.yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: azurekeyvault
spec:
type: secretstores.azure.keyvault
metadata:
- name: vaultName
value: some-kv2-we-dev
- name: azureClientId
value: c6911f11-237e-44ad-a704-c8243067a0b1
servicebus.yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: servicebus-pubsub
namespace: default
spec:
type: pubsub.azure.servicebus
version: v1
metadata:
- name: connectionString
secretKeyRef:
name: some-servicebus-connectionstring
key: some-servicebus-connectionstring
- name: topic
value: "some-topic"
- name: subscriptionName
value: "some-subscription"
auth:
secretStore: azurekeyvault
servicebus.yaml
配置存在缩进的潜在问题,并且可能存在 key
中的 secretKeyRef
字段的问题。
keyvault.yaml
看起来不错。此处不需要进行任何更改,除非 vaultName
或 azureClientId
出现问题。servicebus.yaml:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: servicebus-pubsub
namespace: default
spec:
type: pubsub.azure.servicebus
version: v1
metadata:
- name: connectionString
secretKeyRef:
name: some-servicebus-connectionstring # This should match the secret name in Key Vault
key: some-servicebus-connectionstring # Optional if key matches the name in Key Vault
- name: topic
value: "some-topic"
- name: subscriptionName
value: "some-subscription"
auth:
secretStore: azurekeyvault
>=1.5.0
和 Azure Key Vault 集成的兼容 Dapr运行时版本(例如
secretKeyRef
)。运行成功: