-
Notifications
You must be signed in to change notification settings - Fork 780
Add authn/authz to OTLP endpoint, refactor dashboard endpoint creation, integration tests #2316
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
995c6fa
Dashboard authpocalypse
JamesNK 3da57b8
PR feedback
JamesNK 1f364d0
PR feedback
JamesNK 4810647
Clean up
JamesNK 54e64aa
Merge branch 'main' into jamesnk/dashboard-authpocalypse
drewnoakes e4e34bb
Update eng/Versions.props
JamesNK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Aspire.Dashboard/Authentication/OtlpApiKey/OtlpApiKeyAuthenticationHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Text.Encodings.Web; | ||
| using Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.Extensions.Options; | ||
|
|
||
| namespace Aspire.Dashboard.Authentication.OtlpApiKey; | ||
|
|
||
| public class OtlpApiKeyAuthenticationHandler : AuthenticationHandler<OtlpApiKeyAuthenticationHandlerOptions> | ||
| { | ||
| public const string ApiKeyHeaderName = "x-otlp-api-key"; | ||
|
|
||
| public OtlpApiKeyAuthenticationHandler(IOptionsMonitor<OtlpApiKeyAuthenticationHandlerOptions> options, ILoggerFactory logger, UrlEncoder encoder) : base(options, logger, encoder) | ||
| { | ||
| } | ||
|
|
||
| protected override Task<AuthenticateResult> HandleAuthenticateAsync() | ||
| { | ||
| if (string.IsNullOrEmpty(Options.OtlpApiKey)) | ||
| { | ||
| throw new InvalidOperationException("OTLP API key is not configured."); | ||
| } | ||
|
|
||
| if (Context.Request.Headers.TryGetValue(ApiKeyHeaderName, out var apiKey)) | ||
| { | ||
| if (Options.OtlpApiKey != apiKey) | ||
| { | ||
| return Task.FromResult(AuthenticateResult.Fail("Incoming API key doesn't match required API key.")); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| return Task.FromResult(AuthenticateResult.Fail($"API key from '{ApiKeyHeaderName}' header is missing.")); | ||
| } | ||
|
|
||
| return Task.FromResult(AuthenticateResult.NoResult()); | ||
| } | ||
| } | ||
|
|
||
| public static class OtlpApiKeyAuthenticationDefaults | ||
| { | ||
| public const string AuthenticationScheme = "OtlpApiKey"; | ||
| } | ||
|
|
||
| public sealed class OtlpApiKeyAuthenticationHandlerOptions : AuthenticationSchemeOptions | ||
| { | ||
| public string? OtlpApiKey { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Aspire.Dashboard.Authentication; | ||
|
|
||
| public enum OtlpAuthMode | ||
| { | ||
| None, | ||
| ApiKey, | ||
| ClientCertificate | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Aspire.Dashboard.Authentication; | ||
|
|
||
| public static class OtlpAuthorization | ||
| { | ||
| public const string PolicyName = "OtlpPolicy"; | ||
| public const string OtlpClaimName = "OtlpClaim"; | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/Aspire.Dashboard/Authentication/OtlpCompositeAuthenticationHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Security.Claims; | ||
| using System.Text.Encodings.Web; | ||
| using Aspire.Dashboard.Authentication.OtlpApiKey; | ||
| using Aspire.Dashboard.Authentication.OtlpConnection; | ||
| using Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.AspNetCore.Authentication.Certificate; | ||
| using Microsoft.Extensions.Options; | ||
|
|
||
| namespace Aspire.Dashboard.Authentication; | ||
|
|
||
| public sealed class OtlpCompositeAuthenticationHandler : AuthenticationHandler<OtlpCompositeAuthenticationHandlerOptions> | ||
| { | ||
| public OtlpCompositeAuthenticationHandler(IOptionsMonitor<OtlpCompositeAuthenticationHandlerOptions> options, ILoggerFactory logger, UrlEncoder encoder) : base(options, logger, encoder) | ||
| { | ||
| } | ||
|
|
||
| protected override async Task<AuthenticateResult> HandleAuthenticateAsync() | ||
| { | ||
| var connectionResult = await Context.AuthenticateAsync(OtlpConnectionAuthenticationDefaults.AuthenticationScheme).ConfigureAwait(false); | ||
| if (connectionResult.Failure != null) | ||
| { | ||
| return connectionResult; | ||
| } | ||
|
|
||
| var scheme = Options.OtlpAuthMode switch | ||
| { | ||
| OtlpAuthMode.ApiKey => OtlpApiKeyAuthenticationDefaults.AuthenticationScheme, | ||
| OtlpAuthMode.ClientCertificate => CertificateAuthenticationDefaults.AuthenticationScheme, | ||
| _ => null | ||
| }; | ||
|
|
||
| if (scheme is not null) | ||
| { | ||
| var result = await Context.AuthenticateAsync(scheme).ConfigureAwait(false); | ||
| if (result.Failure is not null) | ||
| { | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
| var id = new ClaimsIdentity([new Claim(OtlpAuthorization.OtlpClaimName, bool.TrueString)]); | ||
|
|
||
| return AuthenticateResult.Success(new AuthenticationTicket(new ClaimsPrincipal(id), Scheme.Name)); | ||
| } | ||
| } | ||
|
|
||
| public static class OtlpCompositeAuthenticationDefaults | ||
| { | ||
| public const string AuthenticationScheme = "OtlpComposite"; | ||
| } | ||
|
|
||
| public sealed class OtlpCompositeAuthenticationHandlerOptions : AuthenticationSchemeOptions | ||
| { | ||
| public OtlpAuthMode OtlpAuthMode { get; set; } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
...d/Otlp/Security/IOtlpConnectionFeature.cs → .../OtlpConnection/IOtlpConnectionFeature.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...p/Security/ListenOptionsOtlpExtensions.cs → ...Connection/ListenOptionsOtlpExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Aspire.Dashboard/Authentication/OtlpConnection/OtlpConnectionAuthenticationHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Text.Encodings.Web; | ||
| using Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.Extensions.Options; | ||
|
|
||
| namespace Aspire.Dashboard.Authentication.OtlpConnection; | ||
|
|
||
| public class OtlpConnectionAuthenticationHandler : AuthenticationHandler<OtlpConnectionAuthenticationHandlerOptions> | ||
| { | ||
| public OtlpConnectionAuthenticationHandler(IOptionsMonitor<OtlpConnectionAuthenticationHandlerOptions> options, ILoggerFactory logger, UrlEncoder encoder) : base(options, logger, encoder) | ||
| { | ||
| } | ||
|
|
||
| protected override Task<AuthenticateResult> HandleAuthenticateAsync() | ||
| { | ||
| if (Context.Features.Get<IOtlpConnectionFeature>() == null) | ||
| { | ||
| return Task.FromResult(AuthenticateResult.Fail("OTLP is not enabled on this connection.")); | ||
| } | ||
|
|
||
| return Task.FromResult(AuthenticateResult.NoResult()); | ||
| } | ||
| } | ||
|
|
||
| public static class OtlpConnectionAuthenticationDefaults | ||
| { | ||
| public const string AuthenticationScheme = "OtlpConnection"; | ||
| } | ||
|
|
||
| public sealed class OtlpConnectionAuthenticationHandlerOptions : AuthenticationSchemeOptions | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Dashboard.Authentication; | ||
|
|
||
| namespace Aspire.Dashboard; | ||
|
|
||
| public sealed class DashboardStartupConfiguration | ||
| { | ||
| public required Uri[] BrowserUris { get; init; } | ||
| public required Uri OtlpUri { get; init; } | ||
| public required OtlpAuthMode OtlpAuthMode { get; init; } | ||
| public required string? OtlpApiKey { get; init; } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.