Skip to content

Commit 6f6d732

Browse files
CopilotIEvangelist
andcommitted
Address PR feedback: update API examples, add runtime callout, document default scopes
Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com>
1 parent babc661 commit 6f6d732

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

docs/app-host/certificate-trust.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ ai-usage: ai-assisted
99

1010
In Aspire, you can customize which certificates resources consider trusted for TLS/HTTPS traffic. This is particularly useful for resources that don't use the system's root trusted certificates by default, such as containerized applications, Python apps, and Node.js apps. By configuring certificate trust, you enable these resources to communicate securely with services that use certificates they wouldn't otherwise trust, including the Aspire dashboard's OTLP endpoint.
1111

12+
> [!IMPORTANT]
13+
> Certificate trust customization only applies at run time. Custom certificates aren't included in publish or deployment artifacts.
14+
1215
## When to use certificate trust customization
1316

1417
Certificate trust customization is valuable when:
@@ -34,11 +37,11 @@ var builder = DistributedApplication.CreateBuilder(args);
3437

3538
// Explicitly enable development certificate trust
3639
var nodeApp = builder.AddNpmApp("frontend", "../frontend")
37-
.WithDeveloperCertificateTrust(enabled: true);
40+
.WithDeveloperCertificateTrust(trust: true);
3841

3942
// Disable development certificate trust
4043
var pythonApp = builder.AddPythonApp("api", "../api", "main.py")
41-
.WithDeveloperCertificateTrust(enabled: false);
44+
.WithDeveloperCertificateTrust(trust: false);
4245

4346
builder.Build().Run();
4447
```
@@ -56,7 +59,7 @@ var builder = DistributedApplication.CreateBuilder(args);
5659

5760
// Load your custom certificates
5861
var certificates = new X509Certificate2Collection();
59-
certificates.Import("path/to/certificate.pem");
62+
certificates.ImportFromPemFile("path/to/certificate.pem");
6063

6164
// Create a certificate authority collection
6265
var certBundle = builder.AddCertificateAuthorityCollection("my-bundle")
@@ -75,7 +78,15 @@ In the preceding example, the certificate bundle is created with custom certific
7578

7679
Certificate trust scopes control how custom certificates interact with a resource's default trusted certificates. Different scopes provide flexibility in managing certificate trust based on your application's requirements.
7780

78-
The `WithCertificateTrustScope` API accepts a <xref:Aspire.Hosting.ApplicationModel.CertificateTrustScope> value to specify the trust behavior:
81+
The `WithCertificateTrustScope` API accepts a <xref:Aspire.Hosting.ApplicationModel.CertificateTrustScope> value to specify the trust behavior.
82+
83+
### Default trust scopes
84+
85+
Different resource types have different default trust scopes:
86+
87+
- **Append**: The default for most resources, appending custom certificates to the default trusted certificates.
88+
- **System**: The default for Python projects, which combines custom certificates with system root certificates because Python doesn't properly support Append mode.
89+
- **None**: The default for .NET projects on Windows, as there's no way to automatically change the default system store source.
7990

8091
### Append mode
8192

@@ -148,14 +159,16 @@ Use `WithExecutableCertificateTrustCallback` to customize certificate trust for
148159
var builder = DistributedApplication.CreateBuilder(args);
149160

150161
builder.AddExecutable("custom-app", "myapp", ".")
151-
.WithExecutableCertificateTrustCallback((certificates, args) =>
162+
.WithExecutableCertificateTrustCallback((ctx) =>
152163
{
153-
// Customize command line arguments
154-
args.Add("--ca-file");
155-
args.Add("/path/to/ca-bundle.pem");
164+
// Add a command line argument that must be set to enable custom certificates
165+
ctx.CertificateTrustArguments.Add("--use-custom-ca");
156166

157-
// Set environment variables
158-
// Environment variables can be set through the resource builder
167+
// Add a command line argument that expects the path to a bundle (single file) of the custom CA certificates
168+
ctx.CertificateBundleArguments.Add("--ca-file");
169+
170+
// Add an environment variable that expects the path to a bundle (single file) of the custom CA certificates
171+
ctx.CertificateBundleEnvironment.Add("EXTRA_CA_BUNDLE");
159172
});
160173

161174
builder.Build().Run();
@@ -171,13 +184,21 @@ Use `WithContainerCertificateTrustCallback` to customize certificate trust for c
171184
var builder = DistributedApplication.CreateBuilder(args);
172185

173186
builder.AddContainer("api", "myimage")
174-
.WithContainerCertificateTrustCallback((certificates, containerConfig) =>
187+
.WithContainerCertificateTrustCallback((ctx) =>
175188
{
176-
// Customize container certificate paths
177-
containerConfig.CertificatePath = "/custom/certs/path";
189+
// Override the path to default individual certificates in the container (this is a list of common certificate paths for various Linux distros by default)
190+
// This should only need to be updated if your container has certificates in non-standard paths
191+
ctx.DefaultContainerCertificatesDirectoryPaths.Clear();
192+
ctx.DefaultContainerCertificatesDirectoryPaths.Add("/path/to/custom/certs");
193+
194+
// Same as above, by default this is a collection of the default locations of the system certificate authority bundle file for common Linux distros
195+
// You should only need to customize this if your image uses non-standard certificate paths
196+
ctx.DefaultContainerCertificateAuthorityBundlePaths.Clear();
197+
ctx.DefaultContainerCertificateAuthorityBundlePaths.Add("/path/to/custom/certbundle.pem");
178198

179-
// Add environment variables for certificate configuration
180-
containerConfig.EnvironmentVariables["SSL_CERT_FILE"] = "/custom/certs/ca-bundle.pem";
199+
// Add environment variables that should be set with a path to the additional CA certificates as its value
200+
// By default this includes "SSL_CERT_DIR" for OpenSSL compatibility
201+
ctx.CertificatesDirectoryEnvironment.Add("EXTRA_CERTS");
181202
});
182203

183204
builder.Build().Run();
@@ -224,16 +245,16 @@ builder.AddContainer("service", "myservice:latest")
224245
builder.Build().Run();
225246
```
226247

227-
### Configure Python apps with certificate trust
248+
### Disable certificate trust for Python apps
228249

229-
Python applications require special handling due to their certificate trust model:
250+
Python projects use System mode by default. To disable certificate trust customization for a Python app:
230251

231252
```csharp
232253
var builder = DistributedApplication.CreateBuilder(args);
233254

234-
// Use System mode for Python apps
255+
// Disable certificate trust for Python apps
235256
builder.AddPythonModule("api", "./api", "uvicorn")
236-
.WithCertificateTrustScope(CertificateTrustScope.System);
257+
.WithCertificateTrustScope(CertificateTrustScope.None);
237258

238259
builder.Build().Run();
239260
```

0 commit comments

Comments
 (0)