Skip to content

Commit fa70f8c

Browse files
Christdejolaals
authored andcommitted
Remove explanatory comments from auth/db configuration
1 parent 01a623a commit fa70f8c

2 files changed

Lines changed: 0 additions & 113 deletions

File tree

api/Configurations/CustomServiceConfigurations.cs

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,6 @@ public static class CustomServiceConfigurations
1515
{
1616
private const string AzurePostgresScope = "https://ossrdbms-aad.database.windows.net/.default";
1717

18-
/// <summary>
19-
/// Build a <see cref="TokenCredential"/> for authenticating against Azure resources.
20-
///
21-
/// The set of credential types to try is configured via
22-
/// <c>AzureAd:AllowedAuthMethods</c>, an ordered list whose entries may be
23-
/// <c>"WorkloadIdentity"</c>, <c>"ClientSecret"</c> and/or <c>"AzureCliBootstrap"</c>
24-
/// (case-insensitive). The order of the list determines the order in which
25-
/// credentials are tried when more than one method is enabled (i.e. it controls
26-
/// the order inside the resulting <see cref="ChainedTokenCredential"/>).
27-
///
28-
/// In cloud (AKS with Azure Workload Identity), set
29-
/// <c>"AllowedAuthMethods": [ "WorkloadIdentity" ]</c> and rely on the standard
30-
/// <c>AZURE_CLIENT_ID</c>, <c>AZURE_TENANT_ID</c>, <c>AZURE_FEDERATED_TOKEN_FILE</c>
31-
/// and <c>AZURE_AUTHORITY_HOST</c> environment variables injected by the
32-
/// azure-workload-identity mutating webhook.
33-
///
34-
/// For local development set
35-
/// <c>"AllowedAuthMethods": [ "AzureCliBootstrap" ]</c>. This uses the developer's
36-
/// <c>az login</c> session to bootstrap Key Vault access on startup. Key Vault then
37-
/// supplies the app registration's client secret into configuration, so all subsequent
38-
/// Azure calls (e.g. Graph API in <c>EmailService</c>) authenticate as the app
39-
/// registration — not the developer's personal identity.
40-
///
41-
/// For CI, set e.g.
42-
/// <c>"AllowedAuthMethods": [ "ClientSecret" ]</c> together with
43-
/// <c>AzureAd:ClientSecret</c> (or <c>AZURE_CLIENT_SECRET</c>). When environment
44-
/// variables are used, the .NET configuration array binding pattern is e.g.
45-
/// <c>AzureAd__AllowedAuthMethods__0=ClientSecret</c>.
46-
/// </summary>
4718
public static TokenCredential CreateCredential(IConfiguration config)
4819
{
4920
string? tenantId = config["AzureAd:TenantId"];
@@ -164,15 +135,6 @@ public static TokenCredential CreateCredential(IConfiguration config)
164135
return new ChainedTokenCredential([.. credentials]);
165136
}
166137

167-
/// <summary>
168-
/// Build a <see cref="TokenCredential"/> for runtime Azure resource access (storage,
169-
/// Graph API, etc.). This method reads the same <c>AzureAd:AllowedAuthMethods</c> list
170-
/// but explicitly excludes <c>"AzureCliBootstrap"</c> — ensuring the developer's
171-
/// personal identity is never used beyond Key Vault bootstrap.
172-
///
173-
/// Call this <b>after</b> Key Vault secrets have been loaded into configuration so that
174-
/// <c>AzureAd:ClientSecret</c> is available.
175-
/// </summary>
176138
public static TokenCredential CreateRuntimeCredential(IConfiguration config)
177139
{
178140
string? tenantId = config["AzureAd:TenantId"];
@@ -207,7 +169,6 @@ public static TokenCredential CreateRuntimeCredential(IConfiguration config)
207169
{
208170
if (string.Equals(method, "AzureCliBootstrap", StringComparison.OrdinalIgnoreCase))
209171
{
210-
// Intentionally skipped — bootstrap credential must not leak into runtime.
211172
continue;
212173
}
213174
else if (string.Equals(method, "WorkloadIdentity", StringComparison.OrdinalIgnoreCase))
@@ -267,41 +228,6 @@ public static TokenCredential CreateRuntimeCredential(IConfiguration config)
267228
return new ChainedTokenCredential([.. credentials]);
268229
}
269230

270-
/// <summary>
271-
/// Configure the database connection for the application.
272-
///
273-
/// When <c>Database:UseInMemoryDatabase</c> is <c>true</c>, an in-memory SQLite database
274-
/// is used (local development).
275-
///
276-
/// Otherwise, the method reads <c>Database:AllowedAuthMethods</c> — an ordered list whose
277-
/// entries may be <c>"AppRegIdentity"</c> and/or <c>"ConnectionString"</c> (case-insensitive).
278-
/// Methods are tried in the order specified; the first one that succeeds wins.
279-
///
280-
/// <list type="bullet">
281-
/// <item>
282-
/// <term>AppRegIdentity</term>
283-
/// <description>
284-
/// Acquires an Entra ID (Azure AD) access token via <see cref="CreateRuntimeCredential"/>
285-
/// and connects to PostgreSQL using <c>UsePeriodicPasswordProvider</c> (token refreshed
286-
/// every 55 minutes). Requires <c>Database:Server</c>, <c>Database:PostgresDatabase</c>
287-
/// and <c>Database:User</c> to be configured.
288-
/// </description>
289-
/// </item>
290-
/// <item>
291-
/// <term>ConnectionString</term>
292-
/// <description>
293-
/// Uses a traditional connection string from <c>Database:postgresConnectionString</c>
294-
/// (typically loaded from Azure Key Vault).
295-
/// </description>
296-
/// </item>
297-
/// </list>
298-
///
299-
/// If the list is empty or absent, defaults to <c>["ConnectionString"]</c> for backward
300-
/// compatibility.
301-
///
302-
/// When <paramref name="environmentName"/> is <c>"Test"</c>, database configuration is
303-
/// skipped entirely — test infrastructure is expected to register the DbContext itself.
304-
/// </summary>
305231
public static IServiceCollection ConfigureDatabase(
306232
this IServiceCollection services,
307233
IConfiguration configuration,
@@ -434,11 +360,6 @@ string environmentName
434360
return services;
435361
}
436362

437-
/// <summary>
438-
/// Configure PostgreSQL using Entra ID (Azure AD) token-based authentication via the
439-
/// app registration identity. The token is used as the PostgreSQL password and refreshed
440-
/// periodically via <c>UsePeriodicPasswordProvider</c>.
441-
/// </summary>
442363
private static void ConfigureDatabaseWithAppRegIdentity(
443364
IServiceCollection services,
444365
IConfiguration configuration
@@ -462,7 +383,6 @@ IConfiguration configuration
462383

463384
var credential = CreateRuntimeCredential(configuration);
464385

465-
// Probe: acquire an initial token to verify connectivity before registering the DbContext.
466386
Console.WriteLine("Requesting Entra ID token via credential...");
467387
var tokenRequestContext = new TokenRequestContext([AzurePostgresScope]);
468388
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3));
@@ -523,10 +443,6 @@ IConfiguration configuration
523443
);
524444
}
525445

526-
/// <summary>
527-
/// Configure PostgreSQL using a traditional connection string (typically loaded from
528-
/// Azure Key Vault via the <c>Database:postgresConnectionString</c> configuration key).
529-
/// </summary>
530446
private static void ConfigureDatabaseWithConnectionString(
531447
IServiceCollection services,
532448
IConfiguration configuration

api/Database/Context/DesignTimeContextFactory.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ namespace api.Database.Context
99
{
1010
/// <summary>
1111
/// This class is not called by anything explicitly, but is used by EF core when adding migrations and updating database.
12-
///
13-
/// Supports the same <c>Database:AllowedAuthMethods</c> configuration as the runtime
14-
/// <see cref="CustomServiceConfigurations.ConfigureDatabase"/>:
15-
/// <list type="bullet">
16-
/// <item>
17-
/// <term>AppRegIdentity</term>
18-
/// <description>
19-
/// Acquires a single Entra ID token and uses it as the PostgreSQL password.
20-
/// Requires <c>Database:Server</c>, <c>Database:PostgresDatabase</c> and
21-
/// <c>Database:User</c>.
22-
/// </description>
23-
/// </item>
24-
/// <item>
25-
/// <term>ConnectionString</term>
26-
/// <description>
27-
/// Uses <c>Database:postgresConnectionString</c> from config or falls back to
28-
/// the <c>Database--postgresConnectionString</c> secret in Azure Key Vault.
29-
/// </description>
30-
/// </item>
31-
/// </list>
32-
/// Defaults to <c>["ConnectionString"]</c> when the list is absent or empty (backward
33-
/// compatible).
3412
/// </summary>
3513
public class DesignTimeContextFactory : IDesignTimeDbContextFactory<SaraDbContext>
3614
{
@@ -144,10 +122,6 @@ public SaraDbContext CreateDbContext(string[] args)
144122
return new SaraDbContext(optionsBuilder.Options);
145123
}
146124

147-
/// <summary>
148-
/// Acquire a single Entra ID token and build a connection string with it as the password.
149-
/// Migrations are short-lived so a single token (valid ~1 hour) is sufficient.
150-
/// </summary>
151125
private static string BuildAppRegIdentityConnectionString(IConfiguration config)
152126
{
153127
var server =
@@ -196,9 +170,6 @@ private static string BuildAppRegIdentityConnectionString(IConfiguration config)
196170
}.ToString();
197171
}
198172

199-
/// <summary>
200-
/// Resolve the connection string from config or fall back to Azure Key Vault.
201-
/// </summary>
202173
private static string ResolveKeyVaultConnectionString(IConfiguration config)
203174
{
204175
string? connectionString = config["Database:postgresConnectionString"];

0 commit comments

Comments
 (0)