【问题标题】:Azure Key Vault 401 authentication errorsAzure Key Vault 401 身份验证错误
【发布时间】:2019-03-13 02:28:13
【问题描述】:

我正在为我的 azure 无状态服务结构应用程序从密钥库中获取密钥值,并且在 100 个密钥库机密中只有 2 个密钥库机密出现 401 依赖错误(如果我通过连接的应用程序洞察力检查)。 下面给出的是通过应用程序洞察显示的关键保险库机密之一的依赖错误的屏幕截图。

这里的请求路径是https://mykeyvaultname.vault.azure.net:443/secrets/PushMessagingSecretsTopicName/?api-version=7.0

下面给出了我获取密钥库秘密的代码-

    public async Task<string> GetSecretAsync(string secretName, string clientId, string appKey, string vaultAddress)
            {
                string secretValue = string.Empty;
                if (string.IsNullOrEmpty(secretName))
                    throw new ArgumentNullException(nameof(secretName));

                if (string.IsNullOrEmpty(clientId))
                    throw new ArgumentNullException(nameof(clientId));

                if (string.IsNullOrEmpty(appKey))
                    throw new ArgumentNullException(nameof(appKey));

                if (string.IsNullOrEmpty(vaultAddress))
                    throw new ArgumentNullException(nameof(vaultAddress));

                var secretIdentifier = vaultAddress + "secrets/" + secretName;
                string cacheKey = secretIdentifier + clientId + appKey;

                secretValue = await GetSecretValue(clientId, appKey, secretIdentifier, cacheKey);

                return secretValue;
            }

private async Task<string> GetSecretValue(string clientId, string appKey, string secretIdentifier, string cacheKey)
        {
            IAdAuthentication authToken = new AdAuthentication
            {
                ClientId = clientId,
                AppKey = appKey
            };
            KeyVaultClient keyVaultClient = new KeyVaultClient(authToken.GetAuthenticationTokenAsync);

            // Get secret from the KeyVault.

            SecretBundle secret = null;

            Task tskGetSecret = Task.Run(async () =>
            {
                        //Here I am getting exception with response
                        secret = await keyVaultClient.GetSecretAsync(secretIdentifier).ConfigureAwait(false);
            });
            await Task.WhenAny(tskGetSecret);

            if (tskGetSecret.IsFaulted || tskGetSecret.IsCanceled)
            {
                secret = null;
            }

            string secretValue = string.Empty;
            if (secret != null && secret.Value != null)
            {
                secretValue = secret.Value.Trim();
            }

            return secretValue;
        }

我已经进一步调试了这个问题,下面给出的是我的发现-

  1. 在获取特定 keyVaultSecret 的值时发生异常。

  2. 除了异常,secret 的值也被成功获取。

  3. 例外是:Microsoft.Rest.TransientFaultHandling.HttpRequestWithStatusException: 'Response status code indicates server error: 401 (Unauthorized).'

堆栈跟踪:-

at Microsoft.Rest.RetryDelegatingHandler.<>c__DisplayClass11_0.<<SendAsync>b__1>d.MoveNext()

【问题讨论】:

    标签: dependencies azure-application-insights http-status-code-401 azure-keyvault


    【解决方案1】:

    我正在关闭此问题,因为进一步调试我发现该问题不是间歇性的,并且与特定的密钥保管库机密无关。获取应用程序的第一个密钥保管库机密值时总是会出现问题。我将关闭此问题并打开new issue 并提供适当的详细信息。

    【讨论】:

      猜你喜欢
      • 2018-04-06
      • 2020-10-21
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      • 2017-03-11
      • 2020-07-22
      • 1970-01-01
      • 2023-04-10
      相关资源
      最近更新 更多