Skip to content

Commit 30ab01a

Browse files
CopilotIEvangelist
andcommitted
Update callback APIs to use async Task and simplified context objects
Co-authored-by: IEvangelist <[email protected]>
1 parent 6f6d732 commit 30ab01a

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

docs/app-host/certificate-trust.md

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Use `WithExecutableCertificateTrustCallback` to customize certificate trust for
159159
var builder = DistributedApplication.CreateBuilder(args);
160160

161161
builder.AddExecutable("custom-app", "myapp", ".")
162-
.WithExecutableCertificateTrustCallback((ctx) =>
162+
.WithExecutableCertificateTrustCallback(async (ctx) =>
163163
{
164164
// Add a command line argument that must be set to enable custom certificates
165165
ctx.CertificateTrustArguments.Add("--use-custom-ca");
@@ -169,12 +169,24 @@ builder.AddExecutable("custom-app", "myapp", ".")
169169

170170
// Add an environment variable that expects the path to a bundle (single file) of the custom CA certificates
171171
ctx.CertificateBundleEnvironment.Add("EXTRA_CA_BUNDLE");
172+
173+
// Add an environment variable that expects the path to a directory containing CA certificates
174+
ctx.CertificatesDirectoryEnvironment.Add("EXTRA_CERTS_DIR");
175+
176+
await Task.CompletedTask;
172177
});
173178

174179
builder.Build().Run();
175180
```
176181

177-
The callback provides access to the certificate collection and allows you to specify command-line arguments required to configure trusted certificates.
182+
The callback receives an `ExecutableCertificateTrustCallbackAnnotationContext` that provides:
183+
184+
- `Certificates`: The `X509Certificate2Collection` of certificates for this resource.
185+
- `Scope`: The `CertificateTrustScope` of trust for the resource.
186+
- `CertificateTrustArguments`: Command line arguments required to enable certificate trust.
187+
- `CertificateBundleArguments`: Command line arguments that will be combined with the path to the custom certificates bundle.
188+
- `CertificateBundleEnvironment`: Environment variable names that will be set with the path to the custom certificates bundle.
189+
- `CertificatesDirectoryEnvironment`: Environment variable names that will be set with paths to directories containing CA certificates to trust.
178190

179191
### Container resource certificate trust
180192

@@ -184,26 +196,46 @@ Use `WithContainerCertificateTrustCallback` to customize certificate trust for c
184196
var builder = DistributedApplication.CreateBuilder(args);
185197

186198
builder.AddContainer("api", "myimage")
187-
.WithContainerCertificateTrustCallback((ctx) =>
199+
.WithContainerCertificateTrustCallback(async (ctx) =>
188200
{
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");
201+
// Customize the path where custom certificates will be placed in the container
202+
// Defaults to /usr/lib/ssl/aspire
203+
ctx.CustomCertificatesContainerFilePath = "/custom/certs/path";
193204

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
205+
// Override the default container certificate authority bundle paths
206+
// This is a list of common certificate paths for various Linux distros by default
207+
// You should only need to update this if your container has certificates in non-standard paths
196208
ctx.DefaultContainerCertificateAuthorityBundlePaths.Clear();
197209
ctx.DefaultContainerCertificateAuthorityBundlePaths.Add("/path/to/custom/certbundle.pem");
198210

199-
// Add environment variables that should be set with a path to the additional CA certificates as its value
211+
// Override the default container certificates directory paths
212+
// By default this is a collection of common certificate directory paths for various Linux distros
213+
// You should only need to customize this if your image uses non-standard certificate paths
214+
ctx.DefaultContainerCertificatesDirectoryPaths.Clear();
215+
ctx.DefaultContainerCertificatesDirectoryPaths.Add("/path/to/custom/certs/dir");
216+
217+
// Add environment variables that should be set with a path to the additional CA certificates directory as its value
200218
// By default this includes "SSL_CERT_DIR" for OpenSSL compatibility
201219
ctx.CertificatesDirectoryEnvironment.Add("EXTRA_CERTS");
220+
221+
await Task.CompletedTask;
202222
});
203223

204224
builder.Build().Run();
205225
```
206226

227+
The callback receives a `ContainerCertificateTrustCallbackAnnotationContext` that provides:
228+
229+
- `Certificates`: The `X509Certificate2Collection` of certificates for this resource.
230+
- `Scope`: The `CertificateTrustScope` of trust for the resource.
231+
- `CustomCertificatesContainerFilePath`: The path in the container where custom certificates will be placed (defaults to `/usr/lib/ssl/aspire`).
232+
- `DefaultContainerCertificateAuthorityBundlePaths`: List of default certificate bundle files in the container that will be replaced in Override mode.
233+
- `DefaultContainerCertificatesDirectoryPaths`: List of default certificate directories in the container that will be appended to in Append mode.
234+
- `CertificateTrustArguments`: Command line arguments required to enable certificate trust.
235+
- `CertificateBundleArguments`: Command line arguments that will be combined with the path to the custom certificates bundle.
236+
- `CertificateBundleEnvironment`: Environment variable names that will be set with the path to the custom certificates bundle.
237+
- `CertificatesDirectoryEnvironment`: Environment variable names that will be set with paths to directories containing CA certificates (defaults include `SSL_CERT_DIR` for OpenSSL compatibility).
238+
207239
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.
208240

209241
## Common scenarios

0 commit comments

Comments
 (0)