Skip to content
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

Add certificate allow list configuration #5172

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Aug 5, 2024

Fixes #2995

Adds an optional allow list to certification authentication.

The allow list is optional for two reasons:

  1. Backwards compatibility
  2. I investigated Azure API management to see what it does for certificate validation. Configuration to require a specific certificate - https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-mutual-certificates-for-clients#policy-to-validate-client-certificates - is supported as an optional step that people can choose to add.
Microsoft Reviewers: Open in CodeFlow

@@ -61,6 +61,11 @@ public sealed class ResourceServiceClientCertificateOptions
public StoreLocation? Location { get; set; }
}

public sealed class AllowedCertificateRule
{
public string? Thumbprint { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why this is nullable. Why would we want an instance of this with a null thumbprint?

If the system was configured with a single rule having a null thumbprint, I don't think any connection would ever be accepted.

X509Certificate2.Thumbprint doens't seem to be nullable either.

Copy link
Member Author

@JamesNK JamesNK Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property is set by configuration so it could be left out and be null. In that case it has no impact because it will never match a cert.

But I will add some validation logic for letting the person launching the dashboard that they're made a mistake.

In case you're wondering why there is AllowedCertificateRule rather than a string list of thumbprints, it leaves open the option for extra options when allowing certificates, e.g. allow certs based on issuer.

@@ -560,6 +560,27 @@ private static void ConfigureAuthentication(WebApplicationBuilder builder, Dashb
{
OnCertificateValidated = context =>
{
var options = context.HttpContext.RequestServices.GetRequiredService<IOptions<DashboardOptions>>().Value;
if (options.Otlp.AllowedCertificates is { Count: > 0 } allowList)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my knowledge, why do we need our own custom option? Doesn't Kestrel have an existing setting for which certs are valid?

Copy link
Member Author

@JamesNK JamesNK Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kestrel and ASP.NET Core cert auth provides settings for allowing or rejecting invalid certs. However, just because a cert is valid doesn't necessarily mean that it should be allowed to be authenticated.

https://learn.microsoft.com/en-us/aspnet/core/security/authentication/certauth?view=aspnetcore-8.0 - see OnCertificateValidated

Called after the certificate has been validated, passed validation and a default principal has been created. This event allows you to perform your own validation and augment or replace the principal.

This PR adds configuration and code for that check.

Comment on lines +46 to +47
s => Assert.Contains("ASPNETCORE_URLS", s),
s => Assert.Contains("DOTNET_DASHBOARD_OTLP_ENDPOINT_URL", s));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but I noticed this test is wrong when adding the allow certs test.

@JamesNK
Copy link
Member Author

JamesNK commented Aug 6, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@JamesNK JamesNK force-pushed the jamesnk/certificate-allow-list branch from a48228f to 34df34a Compare August 7, 2024 06:18
@JamesNK JamesNK enabled auto-merge (squash) August 7, 2024 06:18
@JamesNK JamesNK merged commit 8cda5c9 into main Aug 7, 2024
11 checks passed
@JamesNK JamesNK deleted the jamesnk/certificate-allow-list branch August 7, 2024 07:06
@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dashboard OTLP auth follow up work
3 participants