Skip to content

Commit 9d88625

Browse files
CopilotIEvangelist
andcommitted
Replace deprecated callback APIs with new simplified APIs
Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com>
1 parent 30ab01a commit 9d88625

File tree

1 file changed

+33
-59
lines changed

1 file changed

+33
-59
lines changed

docs/app-host/certificate-trust.md

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -147,96 +147,70 @@ builder.AddContainer("service", "myimage")
147147
builder.Build().Run();
148148
```
149149

150-
## Custom certificate trust callbacks
150+
## Custom certificate trust configuration
151151

152-
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.
152+
For advanced scenarios, you can specify custom certificate trust behavior using a callback API. This callback allows you to customize the command line arguments and environment variables required to configure certificate trust for different resource types.
153153

154-
### Executable resource certificate trust
154+
### Configure certificate trust with a callback
155155

156-
Use `WithExecutableCertificateTrustCallback` to customize certificate trust for executable resources:
156+
Use `WithCertificateTrustConfiguration` to customize how certificate trust is configured for a resource:
157157

158158
```csharp
159159
var builder = DistributedApplication.CreateBuilder(args);
160160

161-
builder.AddExecutable("custom-app", "myapp", ".")
162-
.WithExecutableCertificateTrustCallback(async (ctx) =>
161+
builder.AddContainer("api", "myimage")
162+
.WithCertificateTrustConfiguration(async (ctx) =>
163163
{
164-
// Add a command line argument that must be set to enable custom certificates
165-
ctx.CertificateTrustArguments.Add("--use-custom-ca");
166-
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");
164+
// Add a command line argument
165+
ctx.Arguments.Add("--use-system-ca");
169166

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");
167+
// Set environment variables with certificate paths
168+
// CertificateBundlePath resolves to the path of the custom certificate bundle file
169+
ctx.EnvironmentVariables["MY_CUSTOM_CERT_VAR"] = ctx.CertificateBundlePath;
172170

173-
// Add an environment variable that expects the path to a directory containing CA certificates
174-
ctx.CertificatesDirectoryEnvironment.Add("EXTRA_CERTS_DIR");
171+
// CertificateDirectoriesPath resolves to paths containing individual certificates
172+
ctx.EnvironmentVariables["CERTS_DIR"] = ctx.CertificateDirectoriesPath;
175173

176174
await Task.CompletedTask;
177175
});
178176

179177
builder.Build().Run();
180178
```
181179

182-
The callback receives an `ExecutableCertificateTrustCallbackAnnotationContext` that provides:
180+
The callback receives a `CertificateTrustConfigurationCallbackAnnotationContext` that provides:
181+
182+
- `Scope`: The `CertificateTrustScope` for the resource.
183+
- `Arguments`: Command line arguments for the resource. Values can be strings or path providers like `CertificateBundlePath` or `CertificateDirectoriesPath`.
184+
- `EnvironmentVariables`: Environment variables for configuring certificate trust. The dictionary key is the environment variable name; values can be strings or path providers. By default, includes `SSL_CERT_DIR` and may include `SSL_CERT_FILE` if Override or System scope is configured.
185+
- `CertificateBundlePath`: A value provider that resolves to the path of a custom certificate bundle file.
186+
- `CertificateDirectoriesPath`: A value provider that resolves to paths containing individual certificates.
183187

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.
188+
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.
190189

191-
### Container resource certificate trust
190+
### Configure container certificate paths
192191

193-
Use `WithContainerCertificateTrustCallback` to customize certificate trust for container resources:
192+
For container resources, you can customize where certificates are stored and accessed using `WithContainerCertificatePaths`:
194193

195194
```csharp
196195
var builder = DistributedApplication.CreateBuilder(args);
197196

198197
builder.AddContainer("api", "myimage")
199-
.WithContainerCertificateTrustCallback(async (ctx) =>
200-
{
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";
204-
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
208-
ctx.DefaultContainerCertificateAuthorityBundlePaths.Clear();
209-
ctx.DefaultContainerCertificateAuthorityBundlePaths.Add("/path/to/custom/certbundle.pem");
210-
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
218-
// By default this includes "SSL_CERT_DIR" for OpenSSL compatibility
219-
ctx.CertificatesDirectoryEnvironment.Add("EXTRA_CERTS");
220-
221-
await Task.CompletedTask;
222-
});
198+
.WithContainerCertificatePaths(
199+
customCertificatesDestination: "/custom/certs/path",
200+
defaultCertificateBundlePaths: ["/etc/ssl/certs/ca-certificates.crt"],
201+
defaultCertificateDirectoryPaths: ["/etc/ssl/certs"]);
223202

224203
builder.Build().Run();
225204
```
226205

227-
The callback receives a `ContainerCertificateTrustCallbackAnnotationContext` that provides:
206+
The `WithContainerCertificatePaths` API accepts three optional parameters:
228207

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).
208+
- `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.
209+
- `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.
210+
- `defaultCertificateDirectoryPaths`: Overrides the path(s) in the container where individual trusted certificate files are found. When the `CertificateTrustScope` is Append, these paths are concatenated with the path to the uploaded certificate artifacts. If not set or set to `null`, a set of default certificate paths for common Linux distributions is used.
238211

239-
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.
212+
> [!NOTE]
213+
> All desired paths must be configured in a single call to `WithContainerCertificatePaths` as only the most recent call to the API is honored.
240214
241215
## Common scenarios
242216

0 commit comments

Comments
 (0)