Skip to content

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Feb 20, 2024

Lots of dashboard changes for the reasons of auth. Work in progress.

  • Change dashboard endpoint configuration from code to configuration + code. Allows external endpoint configuration when starting the dashboard. This gives people who want to launch the dashboard a lot more flexibility over endpoint configuration. For example, the TLS cert can be different per endpoint via configuration, Kestrel:Endpoints:Otlp:Certification:...=xxx.
  • Enable auth on OTLP endpoints
    • Add composite auth
    • Add API key auth (enabled via config)
    • Add client cert auth (enabled via config)
    • Change connection validation to happen in auth instead of gRPC interceptor.
  • Integration tests of all the scenarios (http vs https vs different certs vs mTLS vs api key auth)
Microsoft Reviewers: Open in CodeFlow

@JamesNK JamesNK requested a review from halter73 February 21, 2024 03:47
@mitchdenny mitchdenny added this to the preview 4 (Mar) milestone Feb 23, 2024
@davidfowl
Copy link
Member

Do we need to test this with anything?

@joperezr
Copy link
Member

Friendly reminder that this PR is assigned to the Preview 4 milestone which is snapping in a couple of hours. Please ensure it is merged by 4pm PST in order to ensure the change will be part of Preview 4.

@mitchdenny
Copy link
Member

I might be blind, but I'm not seeing where we make use of these values when we launch the dashboard from the apphost? Is that going to be done separately?

@JamesNK
Copy link
Member Author

JamesNK commented Feb 29, 2024

They're mostly for cloud providers to opt-in to using. We might add API key auth in the local environment.

@JamesNK JamesNK force-pushed the jamesnk/dashboard-authpocalypse branch from c47e359 to 984afa0 Compare March 7, 2024 03:50
@JamesNK
Copy link
Member Author

JamesNK commented Mar 7, 2024

I think this PR is mergable as a starting point for dashboard auth. I think there will still be changes, especially to the OTLP API key auth based on feedback, but this is a good starting point.

I don't want to leave this changing around, building up merge conflicts.

Copy link
Member

@kvenkatrajan kvenkatrajan left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for providing tests.

private const string DashboardUrlVariableName = "ASPNETCORE_URLS";
private const string DashboardUrlDefaultValue = "http://localhost:18888";
internal const string DashboardOtlpAuthModeVariableName = "DOTNET_DASHBOARD_OTLP_AUTH_MODE";
internal const string DashboardOtlpApiKeyVariableName = "DOTNET_DASHBOARD_OTLP_API_KEY";
Copy link
Member

Choose a reason for hiding this comment

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

Are we planning to add the keyperfile configuration/volume info here to support ACA? We can do it in a separate PR post this merge.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe. Will talk more with people to figure out exact requirements. But I don't think that blocks this PR. Merging something that isn't the final result is ok.

case OtlpAuthMode.None:
break;
case OtlpAuthMode.ApiKey:
otlpApiKey = configuration[DashboardOtlpApiKeyVariableName];
Copy link
Member

Choose a reason for hiding this comment

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

Similarly here do we to fork out logic to retreive apiKey for ACA scenario? How would we determine from the appModel whether the dashboard is hosted in ACA? Can be in a separate PR - just curious

Copy link
Member Author

Choose a reason for hiding this comment

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

Still to figure out.

@iphdav
Copy link

iphdav commented Mar 10, 2024

One question: Has the industry adopted x-otlp-api-key as the name of the HTTP Header for the API Key? It is obviously easy to use any header when emitting the telemetry. Should the Options class in the Dashboard app allow a different key http header name to be specified as well as the key's value?
Great work though, this will be great.

@JamesNK
Copy link
Member Author

JamesNK commented Mar 10, 2024

I made it up. If there is a standard then let me know.

I don't see a reason to make the name configurable.

@iphdav
Copy link

iphdav commented Mar 10, 2024

I have just adopted your new standard James :-)

@JamesNK
Copy link
Member Author

JamesNK commented Mar 11, 2024

I'm still looking for someone to review this. Please review this so I don't have to keep rebasing changes to avoid merge conflicts.

@davidfowl
Copy link
Member

I'll review

Copy link
Member

@drewnoakes drewnoakes left a comment

Choose a reason for hiding this comment

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

Would be good to document the new options in the dashboard's README.md file.

Also, lots of new public types here. Can these be internal, so we aren't tied to back compat in future? I don't see why consumers would need to use these types.

Comment on lines +308 to +327
OnCertificateValidated = context =>
{
var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier,
context.ClientCertificate.Subject,
ClaimValueTypes.String, context.Options.ClaimsIssuer),
new Claim(ClaimTypes.Name,
context.ClientCertificate.Subject,
ClaimValueTypes.String, context.Options.ClaimsIssuer)
};

context.Principal = new ClaimsPrincipal(new ClaimsIdentity(claims, context.Scheme.Name));
context.Success();

return Task.CompletedTask;
}
Copy link
Member

Choose a reason for hiding this comment

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

Checking my understanding here: the dashboard will accept any valid certificate here, not a pre-shared/specific one?

If that's the case, then this isn't mTLS (as I understand it), as the identity of the other party is not restricted to a given certificate. Any cert that's trusted on the machine will be accepted. Maybe we're ok with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right. I was planning to get feedback whether more to lock down the client cert was required.

Copy link
Member

Choose a reason for hiding this comment

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

The ability to lock down the cert should be supported (file a follow up).

@JamesNK JamesNK force-pushed the jamesnk/dashboard-authpocalypse branch from cee44ec to 995c6fa Compare March 14, 2024 03:11
@JamesNK
Copy link
Member Author

JamesNK commented Mar 14, 2024

Would be good to document the new options in the dashboard's README.md file.

That's the plan, but I'll wait for concensus about the changes before updating docs.

@JamesNK
Copy link
Member Author

JamesNK commented Mar 14, 2024

I'll review

@davidfowl I'm interested in your feedback about how I changed the configuration of endpoints. The new system allows for basic configuration using ASPNETCORE_URLS + DOTNET_DASHBOARD_OTLP_ENDPOINT_URL or using more advanced Kestrel config, e.g. Kestrel::Endpoints::OtlpEndpoint::xxxx.

@drewnoakes
Copy link
Member

@JamesNK @davidfowl can we get this merged in please? I have more auth work to submit that'll conflict a little with this.

Comment on lines +233 to +244
values[$"Kestrel:Endpoints:{endpointName}:Url"] = url;

if (protocols != null)
{
values[$"Kestrel:Endpoints:{endpointName}:Protocols"] = protocols.ToString();
}

if (requiredClientCertificate)
{
values[$"Kestrel:Endpoints:{endpointName}:ClientCertificateMode"] = ClientCertificateMode.RequireCertificate.ToString();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

My only question (non blocking) was why do this instead of using the API to create named endpoints?

Copy link
Member Author

@JamesNK JamesNK Mar 18, 2024

Choose a reason for hiding this comment

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

From PR description:

  • Change dashboard endpoint configuration from code to configuration + code. Allows external endpoint configuration when starting the dashboard. This gives people who want to launch the dashboard a lot more flexibility over endpoint configuration. For example, the TLS cert can be different per endpoint via configuration, Kestrel:Endpoints:Otlp:Certification:...=xxx.

Without this, we'd need to recreate a lot of configuration infrastructure ourselves, i.e. provide a way to configure the TLS cert for each endpoint from a cert store, or from a pdf, or from a cert+key, etc.

Copy link
Member

Choose a reason for hiding this comment

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

I see

@drewnoakes
Copy link
Member

Pushed a fix to resolve a simple conflict in eng/Versions.props.

@JamesNK JamesNK changed the title Dashboard authpocalypse Add authn/authz to OTLP endpoint, refactor dashboard endpoint creation, integration tests Mar 18, 2024
@JamesNK JamesNK enabled auto-merge (squash) March 18, 2024 23:38
@JamesNK JamesNK merged commit 1c55890 into main Mar 19, 2024
@JamesNK JamesNK deleted the jamesnk/dashboard-authpocalypse branch March 19, 2024 00:24
JamesNK added a commit that referenced this pull request Mar 19, 2024
… creation, integration tests (#2316)"

This reverts commit 1c55890.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 21, 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.

8 participants