-
Notifications
You must be signed in to change notification settings - Fork 168
Add certificate trust customization article for Aspire 13 #5311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-13
Are you sure you want to change the base?
Conversation
Co-authored-by: IEvangelist <[email protected]>
Co-authored-by: IEvangelist <[email protected]>
|
Hey @danegsta please have a look at this PR. |
|
Hey @copilot please address all PR feedback. |
…nt default scopes Co-authored-by: IEvangelist <[email protected]>
|
I just opened a PR to simplify the certificate trust callback APIs. Most of the API will be unchanged, but the final section on configuring resources via callbacks will need to be updated. |
|
Hey @copilot please consider the dotnet/aspire#12358 as it reworks some of the callback usage. Please update this content and for the new APIs to get a clean build please don't use xref, instead just wrap those APIs as inline code. |
Co-authored-by: IEvangelist <[email protected]>
Updated the callback examples to reflect the simplified APIs from PR #12358. The callbacks now use async |
docs/app-host/certificate-trust.md
Outdated
|
|
||
| ## Custom certificate trust callbacks | ||
|
|
||
| For advanced scenarios, you can specify custom certificate trust behavior using callback APIs. These callbacks allow you to customize how certificates are configured for different resource types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| For advanced scenarios, you can specify custom certificate trust behavior using callback APIs. These callbacks allow you to customize how certificates are configured for different resource types. | |
| For advanced scenarios, you can specify custom certificate trust behavior using a callback API. This callback allow you to customize the command line arguments and environment variables required to configure certificate trust for different resource types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the introductory text to use singular "callback API" and "callback allows". Commit 9d88625
docs/app-host/certificate-trust.md
Outdated
| ### Executable resource certificate trust | ||
|
|
||
| Use `WithExecutableCertificateTrustCallback` to customize certificate trust for executable resources: | ||
|
|
||
| ```csharp | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddExecutable("custom-app", "myapp", ".") | ||
| .WithExecutableCertificateTrustCallback(async (ctx) => | ||
| { | ||
| // Add a command line argument that must be set to enable custom certificates | ||
| ctx.CertificateTrustArguments.Add("--use-custom-ca"); | ||
|
|
||
| // Add a command line argument that expects the path to a bundle (single file) of the custom CA certificates | ||
| ctx.CertificateBundleArguments.Add("--ca-file"); | ||
|
|
||
| // Add an environment variable that expects the path to a bundle (single file) of the custom CA certificates | ||
| ctx.CertificateBundleEnvironment.Add("EXTRA_CA_BUNDLE"); | ||
|
|
||
| // Add an environment variable that expects the path to a directory containing CA certificates | ||
| ctx.CertificatesDirectoryEnvironment.Add("EXTRA_CERTS_DIR"); | ||
|
|
||
| await Task.CompletedTask; | ||
| }); | ||
|
|
||
| builder.Build().Run(); | ||
| ``` | ||
|
|
||
| The callback receives an `ExecutableCertificateTrustCallbackAnnotationContext` that provides: | ||
|
|
||
| - `Certificates`: The `X509Certificate2Collection` of certificates for this resource. | ||
| - `Scope`: The `CertificateTrustScope` of trust for the resource. | ||
| - `CertificateTrustArguments`: Command line arguments required to enable certificate trust. | ||
| - `CertificateBundleArguments`: Command line arguments that will be combined with the path to the custom certificates bundle. | ||
| - `CertificateBundleEnvironment`: Environment variable names that will be set with the path to the custom certificates bundle. | ||
| - `CertificatesDirectoryEnvironment`: Environment variable names that will be set with paths to directories containing CA certificates to trust. | ||
|
|
||
| ### Container resource certificate trust | ||
|
|
||
| Use `WithContainerCertificateTrustCallback` to customize certificate trust for container resources: | ||
|
|
||
| ```csharp | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddContainer("api", "myimage") | ||
| .WithContainerCertificateTrustCallback(async (ctx) => | ||
| { | ||
| // Customize the path where custom certificates will be placed in the container | ||
| // Defaults to /usr/lib/ssl/aspire | ||
| ctx.CustomCertificatesContainerFilePath = "/custom/certs/path"; | ||
|
|
||
| // Override the default container certificate authority bundle paths | ||
| // This is a list of common certificate paths for various Linux distros by default | ||
| // You should only need to update this if your container has certificates in non-standard paths | ||
| ctx.DefaultContainerCertificateAuthorityBundlePaths.Clear(); | ||
| ctx.DefaultContainerCertificateAuthorityBundlePaths.Add("/path/to/custom/certbundle.pem"); | ||
|
|
||
| // Override the default container certificates directory paths | ||
| // By default this is a collection of common certificate directory paths for various Linux distros | ||
| // You should only need to customize this if your image uses non-standard certificate paths | ||
| ctx.DefaultContainerCertificatesDirectoryPaths.Clear(); | ||
| ctx.DefaultContainerCertificatesDirectoryPaths.Add("/path/to/custom/certs/dir"); | ||
|
|
||
| // Add environment variables that should be set with a path to the additional CA certificates directory as its value | ||
| // By default this includes "SSL_CERT_DIR" for OpenSSL compatibility | ||
| ctx.CertificatesDirectoryEnvironment.Add("EXTRA_CERTS"); | ||
|
|
||
| await Task.CompletedTask; | ||
| }); | ||
|
|
||
| builder.Build().Run(); | ||
| ``` | ||
|
|
||
| The callback receives a `ContainerCertificateTrustCallbackAnnotationContext` that provides: | ||
|
|
||
| - `Certificates`: The `X509Certificate2Collection` of certificates for this resource. | ||
| - `Scope`: The `CertificateTrustScope` of trust for the resource. | ||
| - `CustomCertificatesContainerFilePath`: The path in the container where custom certificates will be placed (defaults to `/usr/lib/ssl/aspire`). | ||
| - `DefaultContainerCertificateAuthorityBundlePaths`: List of default certificate bundle files in the container that will be replaced in Override mode. | ||
| - `DefaultContainerCertificatesDirectoryPaths`: List of default certificate directories in the container that will be appended to in Append mode. | ||
| - `CertificateTrustArguments`: Command line arguments required to enable certificate trust. | ||
| - `CertificateBundleArguments`: Command line arguments that will be combined with the path to the custom certificates bundle. | ||
| - `CertificateBundleEnvironment`: Environment variable names that will be set with the path to the custom certificates bundle. | ||
| - `CertificatesDirectoryEnvironment`: Environment variable names that will be set with paths to directories containing CA certificates (defaults include `SSL_CERT_DIR` for OpenSSL compatibility). | ||
|
|
||
| Default implementations are provided for Node.js, Python, and container resources. Container resources rely on standard OpenSSL configuration options, with default values that support the majority of common Linux distributions. You can override these defaults if necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these sections are outdated and no longer apply to the current implementation. Instead, the new WithCertificateTrustConfiguration API should be documented here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced the outdated executable and container callback sections with documentation for the new WithCertificateTrustConfiguration API that uses a unified approach with simplified context properties. Commit 9d88625
| - `CertificatesDirectoryEnvironment`: Environment variable names that will be set with paths to directories containing CA certificates (defaults include `SSL_CERT_DIR` for OpenSSL compatibility). | ||
|
|
||
| Default implementations are provided for Node.js, Python, and container resources. Container resources rely on standard OpenSSL configuration options, with default values that support the majority of common Linux distributions. You can override these defaults if necessary. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be a section here on configuring container certificate artifact paths using the WithContainerCertificatePaths API.
The API takes three optional arguments:
customCertificatesDestinationtakes a string and overrides the base path in the container where custom certificate files are placed. If not set (or set tonull) the default path of/usr/lib/ssl/aspirewill be used.defaultCertificateBundlePathstakes a list of strings and overrides the path(s) in the container where a default certificate authority bundle file is located. When theCertificateTrustScopeisOverrideorSystem, the custom certificate bundle will additionally be written to these paths. If not set (or set tonull) a set of default certificate paths for common Linux distributions will be used.defaultCertificateDirectoryPathstakes a list of strings and overrides the path(s) in the container where individual trusted certificate files are found. When theCertificateTrustScopeisAppend, these paths will be concatenated with the path to the uploaded certificate artifacts. If not set (or set tonull) a set of default certificate paths for common Linux distributions will be used.
All desired paths must be configured in a single call to WithContainerCertificatePaths as only the most recent call to the API is honored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @copilot please have a look at these comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a new section documenting the WithContainerCertificatePaths API with detailed explanations of all three optional parameters (customCertificatesDestination, defaultCertificateBundlePaths, defaultCertificateDirectoryPaths) and included a note that all desired paths must be configured in a single call. Commit 9d88625
Co-authored-by: IEvangelist <[email protected]>
| The `WithContainerCertificatePaths` API accepts three optional parameters: | ||
|
|
||
| - `customCertificatesDestination`: Overrides the base path in the container where custom certificate files are placed. If not set or set to `null`, the default path of `/usr/lib/ssl/aspire` is used. | ||
| - `defaultCertificateBundlePaths`: Overrides the path(s) in the container where a default certificate authority bundle file is located. When the `CertificateTrustScope` is Override or System, the custom certificate bundle is additionally written to these paths. If not set or set to `null`, a set of default certificate paths for common Linux distributions is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IEvangelist does it feel okay to refer to the default values in this way or would it be better to include a section with the actual values (and the distro they should match)?
Plan: Create Certificate Trust Customization Article
Based on issue #5307, I created a comprehensive draft article about the new certificate trust customization features in Aspire 13.
docs/app-host/certificate-trust.mdCertificateAuthorityCollectionresource and APIsCertificateTrustScopevalues (Append, Override, System, None)Completed Article
The article covers all aspects from issue #5307:
Core Features Documented
AddCertificateAuthorityCollection,WithCertificates,WithCertificateAuthorityCollectionWithDeveloperCertificateTrustAPIWithCertificateTrustScopeWithCertificateTrustConfigurationfor advanced scenarios with unified callback approachWithContainerCertificatePathsfor container-specific path configurationCode Examples Included
WithContainerCertificatePathsDocumentation Standards Met
Changes Made
docs/app-host/certificate-trust.md- comprehensive article with all featuresdocs/toc.yml- added article to AppHost sectiontrustinstead ofenabled)ImporttoImportFromPemFilefor better accuracyWithExecutableCertificateTrustCallbackandWithContainerCertificateTrustCallbackAPIsWithCertificateTrustConfigurationAPI with simplified callback approachWithContainerCertificatePathsAPI with all three optional parametersArguments,EnvironmentVariables,CertificateBundlePath, andCertificateDirectoriesPathWithContainerCertificatePathsThe article is ready for review!
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews