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

Fix dashboard auth when unsecured #5499

Merged
merged 3 commits into from
Sep 3, 2024
Merged

Fix dashboard auth when unsecured #5499

merged 3 commits into from
Sep 3, 2024

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Aug 30, 2024

Description

Fixes #5490
Fixes #4851

Changes to auth caused the dashboard's unsecured mode to fail. I don't exactly understand what is going on, but I think that:

  1. Request would come into ASP.NET Core and the HttpContext.User would be set with a claim <- good
  2. The request user is set as Blazor's auth state <- good
  3. Blazor Server circuit is created and uses SignalR user as new auth state. SignalR user is a default unauthenticated principal. I'm not sure why it's different from the HttpContext's user. <- bad
  4. AuthorizeRouteView in dashboard sees unauthorized user and displays message in browser.

I fixed this by making an auth scheme handler just for unsecured mode and made it the default auth scheme if dashboard is configured to be unsecured. My guess is the SignalR was attempting to run the default auth scheme (cookies) when it gets its user and was failing because cookies isn't used in unsecured mode.

I'm not sure how to test this simply. It might require a playwright test 😬

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
      • Link to aspire-docs issue:
    • No
Microsoft Reviewers: Open in CodeFlow

@radical
Copy link
Member

radical commented Aug 30, 2024

I'm not sure how to test this simply. It might require a playwright test 😬

Aspire.Dashboard.Tests has some playwright tests.

https://github.com/dotnet/aspire/blob/main/tests/Aspire.Dashboard.Tests/Integration/Playwright/AppBarTests.cs

Comment on lines -32 to -37
var scheme = GetRelevantAuthenticationScheme();
if (scheme == null)
{
var id = new ClaimsIdentity([new Claim(OtlpAuthorization.OtlpClaimName, bool.FalseString)]);
return AuthenticateResult.Success(new AuthenticationTicket(new ClaimsPrincipal(id), Scheme.Name));
}
Copy link
Member

Choose a reason for hiding this comment

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

So this is what didn't work with SignalR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. It worked with the initial request (otherwise the page would have been a 401) but didn't with SignalR,. The SignalR failed then flowed into Blazor, which then caused the authorized route view component to display Unauthorized.

@adamint adamint merged commit 764cac2 into main Sep 3, 2024
11 checks passed
@adamint adamint deleted the jamesnk/unsecured-auth-fix branch September 3, 2024 15:41
@JamesNK
Copy link
Member Author

JamesNK commented Sep 4, 2024

/backport to release/8.2

Copy link
Contributor

github-actions bot commented Sep 4, 2024

Started backporting to release/8.2: https://github.com/dotnet/aspire/actions/runs/10692819322

@NapalmCodes
Copy link

Has this been released? I am running into this problem as well due to https needing disabled to work with a custom container component that cannot trust dotnet dev-certs.

@adkirsch
Copy link

Has this been released? I am running into this problem as well due to https needing disabled to work with a custom container component that cannot trust dotnet dev-certs.

Would like to know as well. Just started a new project yesterday with freshly updated workload and nuget packages.

@davidfowl
Copy link
Member

@joperezr When does the 8.2 patch ship?

@joperezr
Copy link
Member

For consumers of docker image: The 8.2.0 version of the container that has the fix for this has shipped to the nightly registry of MCR. It can be found here: https://mcr.microsoft.com/en-us/product/dotnet/nightly/aspire-dashboard/ and can be pulled via docker pull mcr.microsoft.com/dotnet/nightly/aspire-dashboard:8.2. It would take a couple of more weeks to also ship to the non-nightly mcr registry.

For people using .NET Aspire dashboard via the AppHost (most common case): The fix will ship in .NET Aspire 8.2.1 patch, which is scheduled to ship on 9/26.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants