I need to disable Local Authentication Methods (Access Keys) for Azure App Configuration Stores.
Currently for an ASP.NET Framework application, I am using the following for accessing the App Configuration Store from my application:
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="MyConfigStore" mode="Greedy" connectionString="${ConnectionString}" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" />
<add name="Environment" mode="Greedy" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
</builders>
</configBuilders>
Here the value of ${ConnectionString} = "Endpoint=https://<app_config>.azconfig.io;Id=<Id>;Secret=<Access Key>"
Now in order to access the App Configuration through the ASP.NET application, I created a Service Principal, generated a secret to use.
I have stored the CLIENT_ID, TENANT_ID and CLIENT_SECRET values. I have also assigned the App Configuration Data Reader role to the Service Principal.
I also have a managed identity which I can use.
Now what change do I need to make at the application side in order to access the App Configuration through the ASP.NET application?
2
Answers
Check the below Workaround to access the
App Configuration
in the.NET Framework
Application.In
Azure Portal
=>App Configuration
=>Configuration explorer
,create new
Key-value
.NuGet Packages
Configuration Section from my
Web.config
file:Reading Config Value:
In Controller,
In View.cshtml:
OutPut:
References taken from MSDoc
You should use the
endpoint
instead of theconnectionString
parameter when you config your builders. This will tell the system to use theDefaultAzureCredential
to connect to Azure App Configuration.I would also put the "Environment" builder before the "AzureAppConfig" builder, so environment variables are available to the AppConfig builder during loading. It looks something like this:
Given you want to use the service principal, you should make
CLIENT_ID
,TENANT_ID
andCLIENT_SECRET
available as environment variables, so theDefaultAzureCredential
will pick them up automatically.You should NEVER put any secrets in the web.config file. You can find more information about the App Configuration builder library from the link below.
https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#azureappconfigurationbuilder