【发布时间】:2019-09-02 08:54:04
【问题描述】:
我正在尝试关注这个https://azure.microsoft.com/en-us/blog/simplifying-security-for-serverless-and-web-apps-with-azure-functions-and-app-service/,以便在使用 azure 函数时从我的密钥库中安全地获取我的秘密。
我的密钥保管库有一个访问策略,允许通过函数应用的SYSTEM MANAGED IDENTITY 获取机密。
这是高级编辑器中显示的相关应用设置(slotSetting 是真还是假都没有关系,已经尝试过了。不知道它有什么作用)
{
"name": "ultrasecret",
"value": "@Microsoft.KeyVault(SecretUri=https://<vault-name>.vault.azure.net/secrets/<secret-name>/<version>)",
"slotSetting": true
}
这是我唯一的函数的脚手架版本,请查看下面的 IF 块,了解我通过暴露密钥库秘密的环境变量间接查询密钥库。
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
if ($name) {
$status = [HttpStatusCode]::OK
$secret = $env:ultrasecret
$body = "Hello $name $secret"
}
else {
$status = [HttpStatusCode]::BadRequest
$body = "Please pass a name on the query string or in the request body."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $body
})
当我发出 GET 请求时
https://<function-app-name>.azurewebsites.net/api/HttpTrigger1?name=john
这是返回的内容
Hello john @Microsoft.KeyVault(SecretUri=https://<vault-name>.vault.azure.net/secrets/<secret-name>/<version>)
所以基本上我返回的是文字设置的值,而不是秘密。这是因为 Powershell 支持处于预览状态吗?其他人搞定了吗?
非常感谢任何帮助。
【问题讨论】:
-
看来我不是唯一的......这是一个github问题github.com/MicrosoftDocs/azure-docs/issues/33480
-
我可以进一步确认它与 MSI 本身无关。我能够成功地对密钥库 API 进行手动 REST 调用(从 az 函数中)并查询密钥并在我的函数中使用它。因此,我可能需要(作为一种解决方法)手动在环境变量中设置我的秘密,而不是使用官方方式。
标签: powershell azure-functions azure-keyvault azure-managed-identity