-
Notifications
You must be signed in to change notification settings - Fork 870
Add Windows CLI starter validation #15446
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
Changes from all commits
85bd147
9c8dc17
f5214ad
ae97f59
b8d5950
60f92ab
86495d1
c6d47fb
5a50c1e
3ce4a5a
f1a2fb7
6c26a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| using Aspire.Cli.Interaction; | ||
| using Aspire.Cli.Resources; | ||
| using Aspire.Cli.Telemetry; | ||
| using Aspire.Cli.Utils; | ||
| using Microsoft.AspNetCore.Certificates.Generation; | ||
|
|
||
| namespace Aspire.Cli.Certificates; | ||
|
|
@@ -31,9 +32,12 @@ internal interface ICertificateService | |
| internal sealed class CertificateService( | ||
| ICertificateToolRunner certificateToolRunner, | ||
| IInteractionService interactionService, | ||
| AspireCliTelemetry telemetry) : ICertificateService | ||
| AspireCliTelemetry telemetry, | ||
| ICliHostEnvironment hostEnvironment, | ||
|
joperezr marked this conversation as resolved.
|
||
| Func<bool>? isWindows = null) : ICertificateService | ||
| { | ||
| private const string SslCertDirEnvVar = "SSL_CERT_DIR"; | ||
| private readonly Func<bool> _isWindows = isWindows ?? OperatingSystem.IsWindows; | ||
|
|
||
| public async Task<EnsureCertificatesTrustedResult> EnsureCertificatesTrustedAsync(CancellationToken cancellationToken) | ||
| { | ||
|
|
@@ -74,6 +78,24 @@ private async Task HandleMachineReadableTrustAsync( | |
| // If not trusted at all, run the trust operation | ||
| if (trustResult.IsNotTrusted) | ||
| { | ||
| if (_isWindows() && !hostEnvironment.SupportsInteractiveInput) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I understand the motivation here, I can't help but feel that this is probably kind of custom. Also, IIUC this would make it where it would be impossible to turrn this on in GitHub actions, Azure pipelines, jenkins etc, which while it is probably a good default, it means that if someone for whatever reason does want to prompt for trust it is not possible. Totally ok to push back, but what do you think about having an env variable that we check instead that only controls this particular behavior, so something like: |
||
| { | ||
| if (!trustResult.HasCertificates) | ||
| { | ||
| var ensureResultCode = await interactionService.ShowStatusAsync( | ||
| InteractionServiceStrings.CheckingCertificates, | ||
| () => Task.FromResult(certificateToolRunner.EnsureHttpCertificateExists()), | ||
| emoji: KnownEmojis.LockedWithKey); | ||
|
|
||
| if (!IsSuccessfulEnsureResult(ensureResultCode)) | ||
| { | ||
| interactionService.DisplayMessage(KnownEmojis.Warning, string.Format(CultureInfo.CurrentCulture, ErrorStrings.CertificatesMayNotBeFullyTrusted, ensureResultCode)); | ||
| } | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| var trustResultCode = await interactionService.ShowStatusAsync( | ||
| InteractionServiceStrings.TrustingCertificates, | ||
| () => Task.FromResult(certificateToolRunner.TrustHttpCertificate()), | ||
|
|
@@ -99,6 +121,10 @@ private async Task HandleMachineReadableTrustAsync( | |
| } | ||
| } | ||
|
|
||
| private static bool IsSuccessfulEnsureResult(EnsureCertificateResult result) => | ||
| result is EnsureCertificateResult.Succeeded | ||
| or EnsureCertificateResult.ValidCertificatePresent; | ||
|
|
||
| private static void ConfigureSslCertDir(Dictionary<string, string> environmentVariables) | ||
| { | ||
| // Get the dev-certs trust path (respects DOTNET_DEV_CERTS_OPENSSL_CERTIFICATE_DIRECTORY override) | ||
|
|
||
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.
NIT: to follow precedent as well as make this file easier to parse, can we split the actual implementation of the validation to a separate file that gets ipmorted here?