I have my code for ASP.NET Core 3.1 project running using Visual Studio 2022 (Version: 17.4.5) hosted with AWS Workspace.
I am using ManagedIdentity to access Azure Key Vault (Azure.Identity 1.4.0).
Program.cs:
public static class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args).ConfigureAppConfiguration((context, config) =>
{
var objBuiltConfig = config.Build();
var userAssignedClientId = objBuiltConfig[AppKeys.UserAssignedClientId];
var objSecretClient = new SecretClient(new Uri(objBuiltConfig[AppKeys.KeyVaultURL]), new DefaultAzureCredential(new DefaultAzureCredentialOptions{ManagedIdentityClientId = userAssignedClientId}));
config.AddAzureKeyVault(objSecretClient, new KeyVaultSecretManager());
}).ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
I opened the Visual Studio 2022 using Administrator Mode and then filled all the details to authenticate myself using the Account settings option of Visual Studio 2022 and run the application and came across the below error :
Azure.Identity.AuthenticationFailedException
HResult=0x80131500
Message=ManagedIdentityCredential authentication failed: Service request failed.
Status: 404 (Not Found)
Content:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
</body>
</html>
Headers:
Date: Thu, 16 Feb 2023 09:20:47 GMT
Connection: close
Server: EC2ws
Content-Length: 337
Content-Type: text/html
Source=Azure.Identity
StackTrace:
at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex)
at Azure.Identity.ManagedIdentityCredential.<GetTokenImplAsync>d__9.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Identity.ManagedIdentityCredential.<GetTokenAsync>d__7.MoveNext()
at Azure.Identity.DefaultAzureCredential.<GetTokenFromSourcesAsync>d__14.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Identity.DefaultAzureCredential.<GetTokenImplAsync>d__12.MoveNext()
at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex)
at Azure.Identity.DefaultAzureCredential.<GetTokenImplAsync>d__12.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Identity.DefaultAzureCredential.<GetTokenAsync>d__11.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy.AccessTokenCache.<GetHeaderValueFromCredentialAsync>d__9.MoveNext()
at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy.AccessTokenCache.<GetHeaderValueAsync>d__6.MoveNext()
at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy.AccessTokenCache.<GetHeaderValueAsync>d__6.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy.<AuthenticateAndAuthorizeRequestAsync>d__12.MoveNext()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Security.KeyVault.ChallengeBasedAuthenticationPolicy.<AuthorizeRequestOnChallengeAsyncInternal>d__9.MoveNext()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.Pipeline.BearerTokenAuthenticationPolicy.<ProcessAsync>d__11.MoveNext()
at Azure.Core.Pipeline.RedirectPolicy.<ProcessAsync>d__5.MoveNext()
at Azure.Core.Pipeline.RetryPolicy.<ProcessAsync>d__11.MoveNext()
at Azure.Core.Pipeline.RetryPolicy.<ProcessAsync>d__11.MoveNext()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Core.Pipeline.HttpPipeline.<SendRequestAsync>d__18.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Security.KeyVault.KeyVaultPipeline.<SendRequestAsync>d__29.MoveNext()
at Azure.Security.KeyVault.KeyVaultPipeline.<GetPageAsync>d__17`1.MoveNext()
at Azure.Core.PageResponseEnumerator.FuncAsyncPageable`1.<AsPages>d__2.MoveNext()
at Azure.Core.PageResponseEnumerator.FuncAsyncPageable`1.<AsPages>d__2.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
at Azure.AsyncPageable`1.<GetAsyncEnumerator>d__6.MoveNext()
at Azure.AsyncPageable`1.<GetAsyncEnumerator>d__6.MoveNext()
at Azure.AsyncPageable`1.<GetAsyncEnumerator>d__6.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.<LoadAsync>d__10.MoveNext()
at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.<LoadAsync>d__10.MoveNext()
at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at TestProject.Program.Main(String[] args) in D:\Users\User101\TestProject\Program.cs:line 16
This exception was originally thrown at this call stack:
[External Code]
After upgrading the Azure.Identity nuget package from 1.4.0 to 1.8.2 the issue got resolved. Validation was done including smoke testing and found the swagger url working fine.