Skip to content

Commit 8ef9f9d

Browse files
CopilotbgavrilMS
andauthored
Remove DataProtection configuration from Sidecar (#3776)
Agent-Logs-Url: https://github.com/AzureAD/microsoft-identity-web/sessions/bf35223d-645a-489b-9d64-3769b4a891af Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bgavrilMS <12273384+bgavrilMS@users.noreply.github.com> Co-authored-by: Bogdan Gavril <bogavril@microsoft.com>
1 parent 9720661 commit 8ef9f9d

2 files changed

Lines changed: 0 additions & 41 deletions

File tree

src/Microsoft.Identity.Web.Sidecar/Program.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
using System.Diagnostics.CodeAnalysis;
55
using System.IdentityModel.Tokens.Jwt;
6-
using System.Security.Cryptography.X509Certificates;
76
using Microsoft.AspNetCore.Authentication.JwtBearer;
8-
using Microsoft.AspNetCore.DataProtection;
97
using Microsoft.Identity.Web.Sidecar.Endpoints;
108
using Microsoft.IdentityModel.JsonWebTokens;
119

@@ -49,8 +47,6 @@ public static void Main(string[] args)
4947
});
5048
}
5149

52-
ConfigureDataProtection(builder);
53-
5450
// Add the agent identities and downstream APIs
5551
builder.Services.AddAgentIdentities()
5652
.AddDownstreamApis(builder.Configuration.GetSection("DownstreamApis"));
@@ -103,40 +99,4 @@ private static void ConfigureAuthN(WebApplicationBuilder builder)
10399
options.TokenValidationParameters.NameClaimType = "sub";
104100
});
105101
}
106-
107-
private static void ConfigureDataProtection(WebApplicationBuilder builder)
108-
{
109-
var dataProtectionBuilder = builder.Services.AddDataProtection()
110-
.SetApplicationName("Microsoft.Identity.Web.Sidecar");
111-
112-
// Configure based on environment
113-
if (builder.Environment.IsProduction())
114-
{
115-
// Production configuration for Linux containers
116-
var keysPath = Environment.GetEnvironmentVariable("DATA_PROTECTION_KEYS_PATH") ?? "/app/keys";
117-
118-
// Ensure the directory exists
119-
Directory.CreateDirectory(keysPath);
120-
121-
dataProtectionBuilder.PersistKeysToFileSystem(new DirectoryInfo(keysPath));
122-
123-
// Optional: Configure key encryption if certificate is available
124-
var certPath = Environment.GetEnvironmentVariable("DATA_PROTECTION_CERT_PATH");
125-
if (!string.IsNullOrEmpty(certPath) && File.Exists(certPath))
126-
{
127-
var certPassword = Environment.GetEnvironmentVariable("DATA_PROTECTION_CERT_PASSWORD");
128-
#pragma warning disable SYSLIB0057 // Type or member is obsolete, No overload for new API accepts a password.
129-
var cert = new X509Certificate2(certPath, certPassword);
130-
#pragma warning restore SYSLIB0057 // Type or member is obsolete
131-
dataProtectionBuilder.ProtectKeysWithCertificate(cert);
132-
}
133-
}
134-
else
135-
{
136-
// Development configuration
137-
var keysPath = Path.Combine(builder.Environment.ContentRootPath, "keys");
138-
Directory.CreateDirectory(keysPath);
139-
dataProtectionBuilder.PersistKeysToFileSystem(new DirectoryInfo(keysPath));
140-
}
141-
}
142102
}

src/Microsoft.Identity.Web.Sidecar/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Settings are supplied via `appsettings.json`, environment variables, or any stan
4747

4848
- **AzureAd**: Standard Microsoft.Identity.Web web API registration; client credentials are optional if only delegated flows are required.
4949
- **DownstreamApis**: Named profiles for endpoints resolved via `{apiName}`.
50-
- **Data protection**: In production the app persists keys to `DATA_PROTECTION_KEYS_PATH` (default `/app/keys`) and optionally protects them with a certificate referenced via `DATA_PROTECTION_CERT_PATH` and `DATA_PROTECTION_CERT_PASSWORD`.
5150

5251
## Running the sidecar
5352

0 commit comments

Comments
 (0)