簡體   English   中英

使用 RBAC 連接到 Azure 服務總線停止工作

[英]Connect to Azure Service Bus using RBAC stopped working

我正在使用托管身份連接到 Azure 服務總線,它曾經可以正常工作。

今天早上,我意識到這種方法不再適用於本地(使用 Visual Studio)以及已部署的應用程序(使用托管標識)。

我有一個自定義令牌提供程序 class:

public class AzureServicebusManagedIdentityTokenProvider : TokenProvider
{
    private const string Resource = "https://servicebus.azure.net/";

    protected readonly string TenantId;

    public AzureServicebusManagedIdentityTokenProvider(string tenantId = null)
    {
        TenantId = string.IsNullOrWhiteSpace(tenantId) ? null : tenantId;
    }

    public override async Task<SecurityToken> GetTokenAsync(string appliesTo, TimeSpan timeout)
    {
        string accessToken = await GetAccessToken(Resource);
        return new JsonSecurityToken(accessToken, appliesTo);
    }

    private async Task<string> GetAccessToken(string resource)
    {
        var authProvider = new AzureServiceTokenProvider();
        return await authProvider.GetAccessTokenAsync(resource, TenantId);
    }
}

然后例如發送消息:

var sbMessageSender = new MessageSender(new ServiceBusConnection("<my connectionstring>")
{
    TransportType = TransportType.Amqp,
    TokenProvider = new AzureServicebusManagedIdentityTokenProvider("<my tenant id>")
}, "my queue name", RetryPolicy.Default);
var json = JsonConvert.SerializeObject(<message to send>);
var message = new Message(Encoding.UTF8.GetBytes(json));
await sbMessageSender.SendAsync(message);

拋出此錯誤:

Put token failed. status-code: 401, status-description: InvalidIssuer: Token issuer is invalid. TrackingId:5c6c17c7-7a9e-49f3-adf7-5dbfb35b3daf, SystemTracker:NoSystemTracker, Timestamp:2019-10-29T08:56:17.

我已檢查我是否具有“Azure 服務總線數據所有者”角色,並且 Visual Studio 中的“Azure 應用程序身份驗證”工具已設置為適當的帳戶。

我正在使用這些 nuget 包:

  • Microsoft.Azure.Services.AppAuthentication v1.3.1
  • Microsoft.Azure.ServiceBus v3.4.0

不確定我是否在做一些愚蠢的事情(因為它曾經工作過),但任何幫助將不勝感激。

這似乎是由於 Azure 中的問題造成的。 根據我的支持票上的回復:

...此問題是由最新的服務更新引起的,其中命名空間的后端訂閱 ID 信息存在同步問題。 這僅在更新命名空間時發生。 由於 RBAC 身份驗證依賴於使用存儲的訂閱 ID 構建 ARM 資源ID,因此您會看到身份驗證問題。 該問題現已解決,不應再次發生。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM