首页 文章

VSTS:使用System.AccessToken创建服务 endpoints

提问于
浏览
0

目前,我们使用特定的用户名和PAT来进行Azure DevOps REST API调用,但从维护和脆弱性的角度来看,这不是一个好的解决方案 . 我们想要使用OAuth令牌 .

我们遇到问题的一个案例是尝试从我们的管道生成服务 endpoints . 我可以使用以下命令检查 endpoints 是否存在于Powershell脚本中:

Invoke-RestMethod -Uri https://xxx.visualstudio.com/projectname/_apis/serviceendpoint/endpoints?api-version=5.0-preview.2 -Method Get -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Verbose -Debug

不幸的是,当我尝试使用以下内容创建 endpoints (如果它不存在)时,我得到403(禁止) . 这是电话:

Invoke-RestMethod -Uri https://xxx.visualstudio.com/projectname/_apis/serviceendpoint/endpoints?api-version=5.0-preview.2 -Method Post -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Body $RequestBody -Verbose -Debug

看起来调用它的用户没有创建资源(或至少服务 endpoints )的权限 . 我是运行该版本的人,但我不相信这是我的访问权限,因为我是整个组织的管理员,可以做任何事情 . 我还修改了内置的Project Collection Build Service用户对发布管道的访问权限,以获得完全访问权限并仍然可以解决问题 . 我想要实现的是不可能的?

1 回答

  • 1

    OAuth访问令牌是使用“Project Collection Build Service(xxx)”帐户创建的,而不是您的帐户,因此您需要为“Project Collection Build Service(xxx)”帐户授予创建服务 endpoints 的权限 .

相关问题