azure - 如何使用 pwsh 脚本生成的新密码重置 azure 管道服务连接的密码
问题描述
我在 Azure 管道中创建了一堆服务连接,以通过 SSH 隧道访问 Unix/Linux VM,是否可以使用脚本、bash 或 pwsh 更改服务连接的密码?新密码使用脚本生成并存储在 azure key vault 中。
解决方案
是否可以使用脚本、bash 或 pwsh 更改服务连接的密码?新密码使用脚本生成并存储在 azure key vault 中。
是的。您可以使用 Rest API 来实现:<a href="https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints/update-service-endpoint?view=azure- devops-rest-6.0" rel="nofollow noreferrer">端点 - 更新服务端点
这是 PWSH 示例:
$token = "PAT"
$url=" https://dev.azure.com/{Oranization}/{Project}/_apis/serviceendpoint/endpoints/{serviceconnectionid}?api-version=6.0-preview.4"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
Write-Host "Currentconfiguration = $($response | ConvertTo-Json -Depth 100)"
$response.authorization.parameters.password= "$(keyvaultname)"
$json = @($response) | ConvertTo-Json -Depth 99
$updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Basic $token"}
若要获取 Azue Key Vault 值,可以使用 Azure CLI:az keyvault secret show
az keyvault secret show [--id]
[--name]
[--query-examples]
[--subscription]
[--vault-name]
[--version]
然后您可以将获得的秘密值注入 pwsh 变量并将其应用于 Rest API 示例。
推荐阅读
- ios - iOS - 无法让自定义视图在 UIViewController 中居中
- c++ - 检测 std::shared_ptr 是否持有原始数组(并获取其大小)
- python - 网页美化 html带bs4
- php - MongoDB 不会在 PHP 中发出 JSON 文件
- bash - 如何授予 apache 用户使用 ssh 密钥的权限
- java - 当我尝试在按钮上使用 setText() 时,为什么 Android Studio 会显示错误?
- python - 在python中通过局部平均实现图像缩小太慢
- xero-api - GetInvoicesAsync 仅获取 100 张发票,即使还有更多
- css - 在引导程序中自定义范围滑块以在可能的点上显示点或标记
- azure - 在 Azure 队列触发功能单元测试中模拟 ExecutionContext