Skip to content

Commit 25226b7

Browse files
Connect to APIView app config using managed identity (#9731)
* Connect to APIView app config using managed identity
1 parent 0b4c7c6 commit 25226b7

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/dotnet/APIView/APIViewWeb/CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,21 @@ Following configuration is required to connect local debug instance to Azure res
118118
"ApiKey": "",
119119
"PYTHONEXECUTABLEPATH": "<Full path to python executable>",
120120
"BackgroundTaskDisabled": true,
121-
"APPCONFIG": "<connection string to app configuration>"
121+
"APPCONFIG_URL": "https://<your-app-config-name>.azconfig.io"
122122
}
123123

124124
Note: User requires following role based access to storage account and cosmos DB for local debugging and make sure that user is logged in to Azure from Visual studio to access Azure resources.
125125

126126
- `Storage Blob Contributor` to access storage account
127127
- `Cosmos DB Built-in Data Contributor` to access Cosmos DB
128128

129-
### Role based access requierd for deployed instances
129+
### Role based access required for deployed instances
130130

131131
APIView Azure web app instance requires role based access to storage and cosmos DB instances to access using managed identity. Following are the required RBAC roles.
132132

133133
- `Storage Blob Contributor` to access storage account
134134
- `Cosmos DB Built-in Data Contributor` to access Cosmos DB
135+
- `App Configuration Data Reader` to access App configuration.
135136

136137
### Compile TypeScript code
137138

src/dotnet/APIView/APIViewWeb/Program.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using System;
12
using Azure.Identity;
23
using Microsoft.AspNetCore;
34
using Microsoft.AspNetCore.Hosting;
45
using Microsoft.AspNetCore.Server.Kestrel.Core;
56
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
68

79
namespace APIViewWeb
810
{
@@ -19,11 +21,15 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
1921
{
2022
config.AddEnvironmentVariables(prefix: "APIVIEW_");
2123
IConfiguration settings = config.Build();
22-
string connectionString = settings.GetValue<string>("APPCONFIG");
24+
string appConfigUrl = settings.GetValue<string>("APPCONFIG_URL");
25+
if(string.IsNullOrEmpty(appConfigUrl))
26+
{
27+
throw new InvalidOperationException("App Configuration URL is not set in APIView environment variable. This should be set using environment name APIVIEW_APPCONFIG_URL and value 'https://<your-app-config-name>.azconfig.io'");
28+
}
2329
// Load configuration from Azure App Configuration
2430
config.AddAzureAppConfiguration(options =>
2531
{
26-
options.Connect(connectionString).ConfigureKeyVault(kv =>
32+
options.Connect(new Uri(appConfigUrl), new DefaultAzureCredential()).ConfigureKeyVault(kv =>
2733
{
2834
kv.SetCredential(new DefaultAzureCredential());
2935
});

0 commit comments

Comments
 (0)