简体   繁体   English

客户端地址未授权且调用方在 Azure 中不是受信任的服务

[英]Client address is not authorized and caller is not a trusted service in Azure

I'm working on Azure.我在 Azure 上工作。 I have a windows service which accesses the Azure Key Vault.我有一个访问 Azure Key Vault 的 Windows 服务。
My code is similar to this:我的代码类似于:

public static async Task<string> GetToken(string authority, string resource, string scope)
    {
        var authContext = new AuthenticationContext(authority);
        ClientCredential clientCred = new ClientCredential(...); //app id, app secret
        AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred);

        if (result == null)
            throw new InvalidOperationException("Failed to obtain the JWT token");

        return result.AccessToken;
    }

    public static string GetSecret(string secretName)
    {
        KeyVaultClient keyVaultClient = new KeyVaultClient(GetToken);
        try
        {
            return keyVaultClient.GetSecretAsync("my-key-vault-url", secretName).Result.Value;
        }
        catch(Exception ex)
        {
            return "Error";
        }
    }

After I build and deploy my windows service, I have started it.在我构建和部署我的 Windows 服务之后,我已经启动了它。 Then I'm getting this exception : Client address (IPaddress) is not authorized and caller is not a trusted service然后我收到此异常: Client address (IPaddress) is not authorized and caller is not a trusted service

But I'm able to do a telnet to the key vault :但是我可以对密钥保管库执行 telnet 操作:

telnet projectName-keyvault 443

I have searched for this issue, but couldn't find any solution.Any help in this regard will be highly helpful.我已经搜索了这个问题,但找不到任何解决方案。这方面的任何帮助都会非常有帮助。

The error properly shows that your client IP address is not authorized.该错误正确地表明您的客户端 IP 地址未经授权。

You need to add the client IP of Firewalls and virtual networks in your Azure keyvault If you enable that.如果启用,则需要在 Azure 密钥保管库中添加防火墙和虚拟网络的客户端 IP。

I tried your code and i am able to fetch the data from the key vault.我尝试了您的代码,并且能够从密钥保管库中获取数据。 在此处输入图片说明

what @Nancy Xiong - MSFT , has commented was the issue with my key Vault. @Nancy Xiong - MSFT 评论的是我的密钥库问题。

In firewalls and Virtual Networks of the key Vault, I have added the IP address from which it is accessing the key vault.It solved my problem.在密钥保管库的防火墙和虚拟网络中,我添加了访问密钥保管库的 IP 地址。它解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM