[英]Azure keyvault from on prem .net app without exposing clientid/clientsecret?
[英]Azure KeyVault: how to create clientId and clientSecret?
我想将我的应用程序连接到 KeyVault。 通常,我可以创建一个New Client Secret并在我的代码中使用它。
var _keyVaultClient = new KeyVaultClient(
async (string authority, string resource, string scope) =>
{
var authContext = new AuthenticationContext(authority);
var clientCred = new ClientCredential(clientId, clientSecret);
var result = await authContext.AcquireTokenAsync(resource, clientCred);
return result.AccessToken;
});
我可以从 Azure 门户创建一个新的客户端密钥。
现在,我在 KeyVault 中找不到这个选项。
在Program.cs我有类似的东西
var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));
configApp.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());
在本地工作,但是当我将应用程序部署到 Azure 时出现此错误:
物理根目录为“C:\home\site\wwwroot”的应用程序“/LM/W3SVC/1699246683/ROOT”已从 Program.Main 退出,退出代码为“0”。 捕获的 stdout 和 stderr 日志的前 30KB 字符:
[10:15:57 FTL] 主机意外终止 Azure.Identity.CredentialUnavailableException:DefaultAzureCredential 无法从包含的凭据中检索令牌。
EnvironmentCredential 身份验证不可用。 环境变量没有完全配置。
ManagedIdentityCredential 身份验证不可用,找不到托管标识端点。
SharedTokenCacheCredential 身份验证不可用。 在缓存中找不到帐户。
at Azure.Identity.DefaultAzureCredential.GetTokenAsync(Boolean isAsync, TokenRequestContext requestContext, CancellationToken cancellationToken) at Azure.Identity.DefaultAzureCredential.GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) at Azure.Security.KeyVault.ChallengeBasedAuthenticationPolicy.AuthenticateRequestAsync(HttpMessage message, Boolean async) at Azure.Security.KeyVault.ChallengeBasedAuthenticationPolicy.ProcessCoreAsync(HttpMessage message, ReadOnlyMemory
1 pipeline, Boolean async) at Azure.Core.Pipeline.RetryPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory
1 pipeline, Boolean async) at Azure.Core.Pipeline.RetryPolicy .ProcessAsync(HttpMessage 消息,ReadOnlyMemory1 pipeline, Boolean async) at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory
1 管道)位于 Azure.Core.H.Pip pPipelineSynchronousPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory1 pipeline) at Azure.Core.Pipeline.HttpPipeline.SendRequestAsync(Request request, CancellationToken cancellationToken) at Azure.Security.KeyVault.KeyVaultPipeline.SendRequestAsync(Request request, CancellationToken cancellationToken) at Azure.Security.KeyVault.KeyVaultPipeline.GetPageAsync[T](Uri firstPageUri, String nextLink, Func
1 itemFactory, String operationName, CancellationToken cancellationToken) at Azure.Core.PageResponseEnumerator.FuncAsyncPageable1.AsPages(String continuationToken, Nullable
1 pageSizeHint)+MoveNext() at 8803648786 .Core.PageResponseEnumerator.FuncAsyncPageable1.AsPages(String continuationToken, Nullable
1 pageSizeHint)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at Azure.AsyncPageable1.GetAsyncEnumerator(CancellationToken cancellationToken)+MoveNext() at Azure.AsyncPageable
1.GetAsyncEnumerato r(CancellationToken cancellationToken)+MoveNext() 在 Azure.AsyncPageable1.GetAsyncEnumerator(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.LoadAsync() at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.LoadAsync() at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.Load() at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList
1 个提供商)在 Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() 在 Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration() 在 Microsoft.Extensions.Hosting.HostBuilder.Build() 在 Skoruba.IdentityServer4.STS.Identity.Program。 Main(String[] args) 在 C:\Projects\IdentityServer4\src\Skoruba.IdentityServer4.STS.Identity\Program.cs:line 26进程 ID:13436。文件版本:13.1.20234.8。 说明:IIS ASP.NET 核心模块 V2 请求处理程序。 提交:c75b3f7a2fb9fe21fd96c93c070fdfa88a2fbe97
您正在使用DefaultAzureCredential
,它结合了通常用于在部署时进行身份验证的凭据和用于在开发环境中进行身份验证的凭据。 DefaultAzureCredential 将尝试按顺序通过以下机制进行身份验证。
它在您本地工作的原因很可能是它能够使用您本地盒子中的一个(上面的橙色盒子)进行身份验证。
现在对于已部署的环境,您需要执行以下任一操作:
或者,2. 在环境变量中设置客户端凭据(例如,在 Web 应用程序的情况下,在应用程序设置中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.