我试图使用服务原则从Azure函数访问批处理池,并遇到我不理解的身份验证问题。带有服务原则的初始登录很好,但是使用凭据访问批处理池会返回401。
下面是我的代码的简缩版本,并在关键位置进行注释。
module.exports.dispatch = function (context) {
MsRest.loginWithServicePrincipalSecret('AppId', 'Secret', 'TennantId', function(err, credentials){
if (err) throw err;
// This works as it prints the credentials
context.log(credentials);
var batch_client = new batch.ServiceClient(credentials, accountUrl);
batch_client.pool.get('mycluster', function(error, result){
if(error === null)
{
context.log('Accessed pool');
context.log(result);
}
else
{
//Request to batch service returns a 401
if(error.statusCode === 404)
{
context.log('Pool not found yet returned 404...');
}
else
{
context.log('Error occurred while retrieving pool data');
context.log(error);
}
//'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly.
context.res = { body: error.body.message.value };
context.done();
}
});
});
};如何使用服务原则进行初始登录没有问题,但它返回的凭据却无法访问批处理池?
实际的错误是检查请求上的auth标头,我可以看到,授权标头甚至不存在。
我已经三次检查了批处理帐户的访问控制,App和机密是属于批处理帐户所有者的。知道接下来该做什么吗?
发布于 2017-11-02 16:17:18
不能使用与批处理一起从端点返回的相同OAuth令牌。假设您的服务主体拥有正确的RBAC权限,那么使用Azure批处理端点:https://batch.core.windows.net/ (假设您使用的是公共Azure)。
您不需要获得批处理帐户的共享密钥凭据,如果使用AAD服务主体,则应该使用通过AAD的凭据。
https://stackoverflow.com/questions/47077954
复制相似问题