Skip to content

Allow using server authentication cert config in runtime WithContainerFiles callbacks, fix MacOS keychain access spam with dev cert#13151

Merged
davidfowl merged 12 commits intomicrosoft:mainfrom
danegsta:danegsta/fileBasedCertConfig
Nov 25, 2025
Merged

Allow using server authentication cert config in runtime WithContainerFiles callbacks, fix MacOS keychain access spam with dev cert#13151
davidfowl merged 12 commits intomicrosoft:mainfrom
danegsta:danegsta/fileBasedCertConfig

Conversation

@danegsta
Copy link
Member

Description

  • Adds a new ServerAuthenticationCertificateContext property to the WithContainerFiles callback API context that can be used to include server authentication specific properties (path to the key file, pfx file, etc.) in configuration files if required.
  • Caches ASP.NET development certificate on MacOS to avoid constant keychain access prompting
  • Avoids having to write a temporary version of the pfx file for copying into a container (this depends on a DCP update to allow specifying a binary file as a base64 encoded string)
  • Adds new DistributedApplicationOptions and environment variable flags to disable using the dev cert for server authentication by default, independent of the certificate trust feature

Fixes #13137
Implements #13040

@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13151

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13151"

@danegsta danegsta added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Nov 24, 2025
@danegsta
Copy link
Member Author

I've applied the no merge label as one change in this PR depends on a DCP change that'll need to be merged first, otherwise pfx based certs won't work in containers.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for using server authentication certificate configuration in runtime WithContainerFiles callbacks and fixes MacOS keychain access spam by caching the development certificate. The changes introduce a new API context property, improve certificate caching, and add configuration options to disable dev cert usage independently of certificate trust.

Key Changes:

  • Adds ServerAuthenticationCertificateContext property to ContainerFileSystemCallbackContext for accessing certificate paths in container file generation callbacks
  • Implements MacOS-specific caching of ASP.NET development certificate key material to avoid repeated keychain prompts
  • Introduces new configuration flags (UseDeveloperCertificateForServerAuthentication) to control dev cert usage for server authentication independently of trust settings

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
src/Shared/KnownConfigNames.cs Adds new environment variable constant for server authentication configuration
src/Aspire.Hosting/IDeveloperCertificateService.cs Renames property to UseForServerAuthentication for clarity
src/Aspire.Hosting/DistributedApplicationOptions.cs Adds new option for controlling dev cert usage for server authentication
src/Aspire.Hosting/DeveloperCertificateService.cs Implements new property with configuration priority logic
src/Aspire.Hosting/Dcp/Model/Container.cs Adds RawContents field for base64-encoded binary file content
src/Aspire.Hosting/Dcp/DcpExecutor.cs Major refactor: implements certificate caching, removes temp PFX files, adds MacOS keychain cache
src/Aspire.Hosting/ApplicationModel/X509CertificateResource.cs New experimental resource type for X.509 certificates
src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs Refactors to use new ServerAuthenticationCertificateConfigurationDetails class
src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs Adds WasResolved tracking to detect reference usage
src/Aspire.Hosting/ApplicationModel/ExpressionResolver.cs Sets WasResolved flag during expression evaluation
src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs Adds new context class for server authentication certificate paths
src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs Updates to use renamed service property
src/Aspire.Hosting.Redis/RedisBuilderExtensions.cs Updates to use renamed service property
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs Updates to use renamed service property
src/Aspire.Hosting.Keycloak/KeycloakResourceBuilderExtensions.cs Updates to use renamed service property

@danegsta danegsta mentioned this pull request Nov 25, 2025
9 tasks
@danegsta danegsta removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Nov 25, 2025
@danegsta
Copy link
Member Author

#13186 was merged with the path fixes and support for copying pfx files to containers via base64 encoded strings in the resource config instead of requiring temporary files.

@davidfowl
Copy link
Contributor

Works like a charm!

@davidfowl davidfowl merged commit b521f51 into microsoft:main Nov 25, 2025
295 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 13.1 milestone Nov 25, 2025
/// <summary>
/// Indicates whether this expression was ever referenced to get its value.
/// </summary>
internal bool WasResolved { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m only generating key material that’s actually reference; if no resource actually references the pfx or pem key, I’m not exporting them. I’m using this to check the usage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont like it, can we put it outside of the reference expression.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other option (without making the API weird) would be a custom IValueProvider

private static readonly TimeSpan s_disposeTimeout = TimeSpan.FromSeconds(10);

// Well-known location on disk where dev-cert key material is cached.
private static readonly string s_macOSUserDevCertificateLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aspire", "dev-certs", "https");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I am doing that folders PR, to avoid code like this spreading 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it’ll be nice to have a central service for this.

@davidfowl
Copy link
Contributor

Are we going to need docs to tell people to set ASPIRE_DEVELOPER_CERTIFICATE_DEFAULT_SERVER_AUTHENTICATION on mac if you are doing CI?

@danegsta
Copy link
Member Author

Are we going to need docs to tell people to set ASPIRE_DEVELOPER_CERTIFICATE_DEFAULT_SERVER_AUTHENTICATION on mac if you are doing CI?

Yes, amongst all the rest of the new API that was added. I’ll open a docs issue to expand on the current certificates docs from 13.0.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-enable TLS termination on Mac

3 participants