-
Notifications
You must be signed in to change notification settings - Fork 478
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
Enable local dev OIDC #6529
base: main
Are you sure you want to change the base?
Enable local dev OIDC #6529
Changes from all commits
0f6ffed
c0c335f
dea1492
97ba097
115bba4
7849572
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 |
---|---|---|
|
@@ -11,23 +11,69 @@ internal class DashboardOptions | |
{ | ||
public string? DashboardPath { get; set; } | ||
public string? DashboardUrl { get; set; } | ||
public DashboardAuthMode DashboardAuthMode { get; set; } | ||
public string? DashboardToken { get; set; } | ||
public OpenIdConnectPolicyOptions? OpenIdConnect { get; set; } = new(); | ||
public OpenIdConnectSettings? OpenIdConnectSettings { get; set; } = new(); | ||
public string? OtlpGrpcEndpointUrl { get; set; } | ||
public string? OtlpHttpEndpointUrl { get; set; } | ||
public string? OtlpApiKey { get; set; } | ||
public string AspNetCoreEnvironment { get; set; } = "Production"; | ||
} | ||
|
||
internal enum DashboardAuthMode | ||
{ | ||
Unsecured, | ||
OpenIdConnect, | ||
BrowserToken | ||
} | ||
|
||
internal sealed class OpenIdConnectPolicyOptions | ||
{ | ||
public string NameClaimType { get; set; } = "name"; | ||
public string UsernameClaimType { get; set; } = "preferred_username"; | ||
|
||
/// <summary> | ||
/// Gets the optional name of a claim that users authenticated via OpenID Connect are required to have. | ||
/// If specified, users without this claim will be rejected. If <see cref="RequiredClaimValue"/> | ||
/// is also specified, then the value of this claim must also match <see cref="RequiredClaimValue"/>. | ||
/// </summary> | ||
public string RequiredClaimType { get; set; } = ""; | ||
|
||
/// <summary> | ||
/// Gets the optional value of the <see cref="RequiredClaimType"/> claim for users authenticated via | ||
/// OpenID Connect. If specified, users not having this value for the corresponding claim type are | ||
/// rejected. | ||
/// </summary> | ||
public string RequiredClaimValue { get; set; } = ""; | ||
} | ||
|
||
internal class OpenIdConnectSettings | ||
{ | ||
public string? Authority { get; set; } | ||
public string? MetadataAddress { get; set; } | ||
public string? ClientId { get; set; } | ||
public string? ClientSecret { get; set; } | ||
public ICollection<string> Scope { get; } = []; | ||
} | ||
|
||
internal class ConfigureDefaultDashboardOptions(IConfiguration configuration, IOptions<DcpOptions> dcpOptions) : IConfigureOptions<DashboardOptions> | ||
{ | ||
public void Configure(DashboardOptions options) | ||
{ | ||
options.DashboardPath = dcpOptions.Value.DashboardPath; | ||
options.DashboardUrl = configuration["ASPNETCORE_URLS"]; | ||
options.DashboardToken = configuration["AppHost:BrowserToken"]; | ||
options.DashboardUrl = configuration[KnownConfigNames.AspNetCoreUrls]; | ||
|
||
options.OtlpGrpcEndpointUrl = configuration["DOTNET_DASHBOARD_OTLP_ENDPOINT_URL"]; | ||
options.OtlpHttpEndpointUrl = configuration["DOTNET_DASHBOARD_OTLP_HTTP_ENDPOINT_URL"]; | ||
if (Enum.TryParse<DashboardAuthMode>(configuration[DashboardConfigNames.DashboardFrontendAuthModeName.ConfigKey], out var dashboardAuthMode)) | ||
{ | ||
options.DashboardAuthMode = dashboardAuthMode; | ||
} | ||
|
||
options.DashboardToken = configuration["AppHost:BrowserToken"]; | ||
configuration.Bind("Dashboard:Frontend:OpenIdConnect", options.OpenIdConnect); | ||
configuration.Bind("Authentication:Schemes:OpenIdConnect", options.OpenIdConnectSettings); | ||
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. I agree with @JamesNK comment on the earlier PR that these two related sections seem a bit too disconnected. Just because this is the section normal web apps use to configure OpenIdConnect doesn't mean that we have to do that for the dashboard, right? Could we include everything under "Dashboard:Frontend:OpenIdConnect"? We could forward it to "Authentication:Schemes:OpenIdConnect" in the orchestrated apps. Another option might be to add the 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. Is it really just the configuration keys you think need to be changed over? Currently the appsettings config would look something like this...
I'm guessing you'd rather see something like....
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. @halter73 Let me know if I’m interpreting this correctly and I will make the changes 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. Sorry for the delay. I just got back from vacation. I don't have much background on this PR, I only dropped a review because @eerhardt requested it. I have a deeper understanding of the inner workings of the OpenIdConnectHandler than the Aspire dashboard. Is the intention of this PR to only enable/configure OIDC for the dashboard? Or can this configuration also be used by the projects orchestrated by aspire? If it's the former, I would like to see something like your second example. It makes it much more clear the configuration only applies to the dashboard. The "AuthMode" might not even be necessary since the presence of the "Dashboard:OpenIdConnect" configuration section ought to be enough to indicate that you want to use it. However, if the idea is to be able to share OIDC configuration between the dashboard and other projects, it does make more sense to have it split out the way you currently have it. But then, I don't see what things like I can see why 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. This is just for the dashboard, that’s why I thought it made sense to put it in the normal location you’d use for any app instead of encapsulating it. If there was a way to forward the entire section to the context then I think we can avoid taking a dependency on the OpenIdConnect package and it should support every option in whatever version of the package the user is consuming. I tried to sort that out but came up empty. It seemed like it would be there already since you can take config and bind it, but I don’t see a clear path to just copying the config section since the config builder in the context doesn’t even exist at that point 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.
It would be nice if there was a one-liner like It doesn't seem like it would be too hard to write custom code that calls 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. Yes! That’s exactly what I was trying originally but the only way I could think of to do it was feed a root like authentication__ and go grab all the env variables that start with that and bring them over directly. Doesn’t seem like a very good solution, but it might be doable |
||
options.OtlpGrpcEndpointUrl = configuration[KnownConfigNames.DashboardOtlpGrpcEndpointUrl]; | ||
options.OtlpHttpEndpointUrl = configuration[KnownConfigNames.DashboardOtlpHttpEndpointUrl]; | ||
options.OtlpApiKey = configuration["AppHost:OtlpApiKey"]; | ||
|
||
options.AspNetCoreEnvironment = configuration["ASPNETCORE_ENVIRONMENT"] ?? "Production"; | ||
|
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.
Is this relying on the default options binding in OpenIdConnectConfigureOptions? If so, would it make more sense to forward the entire "Authentication:Schemes:OpenIdConnect"
IConfigurationSection
via environment variables instead of just what we remember to include in "OpenIdConnectSettings"?Also, would it make sense to make the scheme name and/or configuration section prefix configurable?
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.
Originally it was, but earlier feedback was to switch to POCO to avoid the dependency on it. If there was a way to copy that entire section in then I guess you don't need the reference and could just copy that section in directly, but since there's currently no way to bring the whole section in I think POCO is a reasonable approach for now that doesn't really bind you in any way long term.
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.
@davidfowl Can you explain your earlier feedback? I don't like that it's using the same default configuration section
OpenIdConnectConfigureOptions
does but only supports a subset of the options supported by that. If the goal is just to remove Microsoft.AspNetCore.Authentication.OpenIdConnect PackageReference, I would just forward the entire "Authentication:Schemes:OpenIdConnect"IConfigurationSection
via environment variables.