Skip to content

Commit 7cae2d0

Browse files
authored
refactor: align microsoft entra id app settings with managed identity (#110)
1 parent df754c5 commit 7cae2d0

File tree

2 files changed

+28
-73
lines changed

2 files changed

+28
-73
lines changed

README.md

Lines changed: 27 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -78,74 +78,42 @@ pm.request.headers.upsert(`Authorization: HMAC-SHA256 Credential=${credential}&S
7878
7979
### Microsoft Entra ID
8080
81-
HMAC authentication is recommended because it does not require a Microsoft Entra tenant and an Azure App Configuration resource.
82-
83-
1. [Register an application](https://learn.microsoft.com/entra/identity-platform/quickstart-register-app) within the Microsoft Entra tenant.
84-
1. On the Overview page, in the Essentials accordion, copy the following values:
85-
* Application (client) ID
86-
* Directory (tenant) ID
87-
2. On the Certificates & secrets page, in the Client secrets tab, add a client secret.
88-
2. [Create an Azure App Configuration resource](https://learn.microsoft.com/azure/azure-app-configuration/quickstart-azure-app-configuration-create) to be emulated.
89-
1. On the Overview page, in the Essentials accordion, copy the following values:
90-
* Endpoint
91-
2. On the Access control (IAM) page, add a role assignment.
92-
1. In the Role tab, select the App Configuration Data Owner role.
93-
2. In the Members tab, assign access to the registered application.
94-
3. [Generate a self-signed certificate](#ssl--tls) with the `<endpoint>` as the [Subject Alternative Name](https://wikipedia.org/wiki/Subject_Alternative_Name).
81+
Microsoft Entra ID authentication allows you to simulate an Azure based production environment using a [Managed Identity](https://learn.microsoft.com/en-us/azure/azure-app-configuration/howto-integrate-azure-managed-service-identity).
9582
96-
The metadata address must be set using the environment variable `Authentication__Schemes__MicrosoftEntraId__MetadataAddress`.
97-
98-
```yaml
99-
services:
100-
azure-app-configuration-emulator:
101-
environment:
102-
- ASPNETCORE_HTTP_PORTS=80
103-
- ASPNETCORE_HTTPS_PORTS=443
104-
- Authentication__Schemes__MicrosoftEntraId__MetadataAddress=https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration
105-
image: tnc1997/azure-app-configuration-emulator
106-
networks:
107-
default:
108-
aliases:
109-
- <endpoint>
110-
volumes:
111-
- ./emulator.crt:/usr/local/share/azureappconfigurationemulator/emulator.crt:ro
112-
- ./emulator.key:/usr/local/share/azureappconfigurationemulator/emulator.key:ro
113-
```
83+
[Assumed Identity](https://github.com/nagyesta/assumed-identity) is a simple test double simulating how Azure Instance Metadata Service (IMDS) is handling Managed Identity tokens.
11484
115-
The valid audience should be overriden using the environment variable `Authentication__Schemes__MicrosoftEntraId__ValidAudience`.
85+
The metadata address must be set using the environment variable `Authentication__Schemes__MicrosoftEntraId__MetadataAddress`.
11686

11787
```yaml
11888
services:
89+
assumed-identity:
90+
image: nagyesta/assumed-identity
11991
azure-app-configuration-emulator:
92+
depends_on:
93+
- assumed-identity
12094
environment:
121-
- ASPNETCORE_HTTP_PORTS=80
122-
- ASPNETCORE_HTTPS_PORTS=443
123-
- Authentication__Schemes__MicrosoftEntraId__MetadataAddress=https://login.microsoftonline.com/<tenant-id>/.well-known/openid-configuration
124-
- Authentication__Schemes__MicrosoftEntraId__ValidAudience=https://<endpoint>
95+
- ASPNETCORE_HTTP_PORTS=8080
96+
- ASPNETCORE_HTTPS_PORTS=8081
97+
- Authentication__Schemes__MicrosoftEntraId__MetadataAddress=http://assumed-identity/metadata/identity/.well-known/openid-configuration
98+
- Authentication__Schemes__MicrosoftEntraId__RequireHttpsMetadata=false
99+
- Kestrel__Certificates__Default__Path=/usr/local/share/azureappconfigurationemulator/emulator.crt
100+
- Kestrel__Certificates__Default__KeyPath=/usr/local/share/azureappconfigurationemulator/emulator.key
125101
image: tnc1997/azure-app-configuration-emulator
126-
networks:
127-
default:
128-
aliases:
129-
- <endpoint>
130102
volumes:
131103
- ./emulator.crt:/usr/local/share/azureappconfigurationemulator/emulator.crt:ro
132104
- ./emulator.key:/usr/local/share/azureappconfigurationemulator/emulator.key:ro
133105
```
134106

135107
#### .NET
136108

137-
The client may authenticate requests using the Microsoft Entra tenant.
109+
The client may authenticate requests using the Managed Identity.
138110

139111
```csharp
140112
using Azure.Data.AppConfiguration;
141113
using Azure.Identity;
142114
143-
var tenantId = Environment.GetEnvironmentVariable("Authentication__Schemes__MicrosoftEntraId__TenantId");
144-
var clientId = Environment.GetEnvironmentVariable("Authentication__Schemes__MicrosoftEntraId__ClientId");
145-
var clientSecret = Environment.GetEnvironmentVariable("Authentication__Schemes__MicrosoftEntraId__ClientSecret");
146-
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
147-
148115
var endpoint = Environment.GetEnvironmentVariable("Endpoints__AzureAppConfiguration");
116+
var credential = new ManagedIdentityCredential();
149117
var client = new ConfigurationClient(new Uri(endpoint), credential);
150118
151119
var setting = new ConfigurationSetting("AzureAppConfigurationEmulator", "Hello World");
@@ -154,17 +122,19 @@ await client.SetConfigurationSettingAsync(setting);
154122

155123
```yaml
156124
services:
125+
assumed-identity:
126+
image: nagyesta/assumed-identity
157127
azure-app-configuration-emulator:
128+
depends_on:
129+
- assumed-identity
158130
environment:
159-
- ASPNETCORE_HTTP_PORTS=80
160-
- ASPNETCORE_HTTPS_PORTS=443
161-
- Authentication__Schemes__MicrosoftEntraId__MetadataAddress=https://login.microsoftonline.com/<tenant-id>/.well-known/openid-configuration
162-
- Authentication__Schemes__MicrosoftEntraId__ValidAudience=https://<endpoint>
131+
- ASPNETCORE_HTTP_PORTS=8080
132+
- ASPNETCORE_HTTPS_PORTS=8081
133+
- Authentication__Schemes__MicrosoftEntraId__MetadataAddress=http://assumed-identity/metadata/identity/.well-known/openid-configuration
134+
- Authentication__Schemes__MicrosoftEntraId__RequireHttpsMetadata=false
135+
- Kestrel__Certificates__Default__Path=/usr/local/share/azureappconfigurationemulator/emulator.crt
136+
- Kestrel__Certificates__Default__KeyPath=/usr/local/share/azureappconfigurationemulator/emulator.key
163137
image: tnc1997/azure-app-configuration-emulator
164-
networks:
165-
default:
166-
aliases:
167-
- <endpoint>
168138
volumes:
169139
- ./emulator.crt:/usr/local/share/azureappconfigurationemulator/emulator.crt:ro
170140
- ./emulator.key:/usr/local/share/azureappconfigurationemulator/emulator.key:ro
@@ -173,30 +143,15 @@ services:
173143
context: .
174144
dockerfile: ./ConsoleApplication/Dockerfile
175145
depends_on:
146+
- assumed-identity
176147
- azure-app-configuration-emulator
177148
entrypoint: /bin/sh -c "update-ca-certificates && dotnet ConsoleApplication.dll"
178149
environment:
179-
- Authentication__Schemes__MicrosoftEntraId__ClientId=<client-id>
180-
- Authentication__Schemes__MicrosoftEntraId__ClientSecret=<client-secret>
181-
- Authentication__Schemes__MicrosoftEntraId__TenantId=<tenant-id>
182-
- Endpoints__AzureAppConfiguration=https://<endpoint>
150+
- Endpoints__AzureAppConfiguration=https://azure-app-configuration-emulator:8081
183151
volumes:
184152
- ./emulator.crt:/usr/local/share/ca-certificates/emulator.crt:ro
185153
```
186154

187-
#### Postman
188-
189-
The access token may be obtained using the following configuration:
190-
191-
| Configuration | |
192-
|------------------|-------------------------------------------------------------------|
193-
| Auth Type | OAuth 2.0 |
194-
| Grant Type | Client Credentials |
195-
| Access Token URL | `https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token` |
196-
| Client ID | `<client-id>` |
197-
| Client Secret | `<client-secret>` |
198-
| Scope | `https://<endpoint>/.default` |
199-
200155
## Compatibility
201156

202157
The emulator is compatible with the following operations:

src/AzureAppConfigurationEmulator/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Secret": "c2VjcmV0"
77
},
88
"MicrosoftEntraId": {
9-
"ValidAudience": "https://azconfig.io"
9+
"ValidAudience": "https://appconfig.azure.com"
1010
}
1111
}
1212
},

0 commit comments

Comments
 (0)