
问题描述在 Logic App 中调用 Key Vault 的 Key 进行加密/解密操作时可能遇到的权限报错问题body: { status: 403, message: Operation failed because client does not have permission to perform the operation on the key vault. Please check your permissions in the key vault access policies https://docs.microsoft.com/en-us/azure/key-vault/general/assign-access-policy-portal.\r\nclientRequestId: xxxxxxxxxx, error: { message: Operation failed because client does not have permission to perform the operation on the key vault. Please check your permissions in the key vault access policies https://docs.microsoft.com/en-us/azure/key-vault/general/assign-access-policy-portal. }, source: keyvault-xxx.azconn-xxx-xxx.p.chinacloudsites.cn }错误截图令人困惑的是在 Key Vault 的 Access policy 中已经为 Logic App 的标识Identity赋予了 Key 操作的全部权限为什么仍然会出现权限不足的报错呢问题解答根据错误提示中的链接https://docs.microsoft.com/en-us/azure/key-vault/general/assign-access-policy-portal排查方向通常是检查访问标识Logic App 中使用的 SP 或 Identity是否具备加密、解密等权限。反复确认相关权限确实已经在 Access policy 中授予。既然如此为什么还会继续报权限错误呢问题的关键其实藏在更靠里的一层Key 本身的权限设置。在单独查看某一个具体 Key 的配置时会发现它还可以单独设置 Permitted operations允许的操作包括 Encrypt、Decrypt、Sign、Verify、Wrap Key、Unwrap Key 等。也就是说即使 Key Vault 的 Access policy 已经为 Logic App 的标识授予了权限如果具体 Key 本身没有勾选相应的允许操作调用时仍然会持续报权限不足。这一点很容易被忽略也正是这个问题最令人困惑的地方。当为这个 Key 勾选 Decrypt 后再次运行 Logic App问题得到解决。附录一证书生成的 Key 无法加密/解密Key Vault 中的 Certificates 会默认生成一个 Key但这个 Key 在门户中不可见。不过在 Logic App 的 Actions 中可以看到它。如果在加密/解密任务中选择了这个 Key同样会遇到权限报错。原因是这个由证书生成的 Key 没有启用加密/解密功能而且用户无法修改它的 Permitted operations。如果一定要使用证书生成的 Key可以先下载证书的 pfx/pem 文件再通过 Key 的方式重新上传证书文件创建一个新的 Key。这样创建出来的 Key 就可以配置加密/解密权限了。参考资料Azure Key Vault Docs:https://docs.azure.cn/zh-cn/key-vault/keys/about-keys