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

#1396 Lost context User in MultiplexingMiddleware #1462

Merged

Conversation

Ugway77
Copy link
Contributor

@Ugway77 Ugway77 commented Apr 7, 2021

Fixes #1396

Current Behavior

If using RouteClaimsRequirement then Claims are lost after passing MultiplexingMiddleware because it creates new HttpContext and does not copy User property.

Proposed Changes

  • Copy User property when creating new HttpContext in MultiplexingMiddleware and, maybe, use source HttpContext and simplify code if only one downstream route found.

@Kation
Copy link

Kation commented May 28, 2021

Link #1396

@raman-m
Copy link
Member

raman-m commented Jun 30, 2023

Please do the following:

  • Merge PR 1
  • Rebase feature branch onto develop
  • Resolve all merge conflicts

@raman-m raman-m added waiting Waiting for answer to question or feedback from issue raiser conflicts Feature branch has merge conflicts labels Jul 11, 2023
@raman-m raman-m force-pushed the fix_contextuser_lost_after_multiplexing branch from ea7b0d8 to 2f2b834 Compare August 24, 2023 11:09
@raman-m raman-m added bug Identified as a potential bug proposal Proposal for a new functionality in Ocelot needs feedback Issue is waiting on feedback before acceptance and removed waiting Waiting for answer to question or feedback from issue raiser conflicts Feature branch has merge conflicts labels Aug 24, 2023
@raman-m raman-m changed the title Fix contextuser lost after multiplexing Fix lost context User after multiplexing in 'MultiplexingMiddleware' Aug 24, 2023
@raman-m
Copy link
Member

raman-m commented Aug 24, 2023

@Ugway77
Hi Алексей!
I thought you needed a help to resolve merge conflicts. 😉
The feature branch has been rebased onto ThreeMammals:develop successfully!
Welcome to code review!


If you are going to contribute in future...
I see that develop branch in your fork is old.
Could you Sync fork please? So, the develop branch will be updated with all top commits!
Could you add me as collaborator to your forked repo please? I will update develop branch.


Is this PR related to some issue in backlog?

@raman-m
Copy link
Member

raman-m commented Aug 24, 2023

@Kation commented on May 28, 2021:

Could you review the current solution and confirm please that the solution fixes #1396 (your user scenario)?
Thanks you!

@raman-m
Copy link
Member

raman-m commented Aug 24, 2023

@tmkhan @aliprogrammer69 @andrei-manulife
As a participant in the discussion of issue #1396,
Could you review the code please?
Your verification of the solution is also welcomed!

Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

Diff samples

+ No unit and acceptance tests!
- No unit and acceptance tests!
! No unit and acceptance tests!
# No unit and acceptance tests!
@@ No unit and acceptance tests! @@

LaTeX samples

  • $\color{green}{No\ unit\ and\ acceptance\ tests!}$
  • $\color{red}{No\ unit\ and\ acceptance\ tests!}$
  • $\color{orange}{No\ unit\ and\ acceptance\ tests!}$

LaTeX samples with size

$\color{orange}{No\ unit\ and\ acceptance\ tests!}$

$\color{orange}{No\ unit\ and\ acceptance\ tests!}$

$\color{orange}{No\ unit\ and\ acceptance\ tests!}$

$\color{orange}{No\ unit\ and\ acceptance\ tests!}$

$\color{orange}{No\ unit\ and\ acceptance\ tests!}$


Proposed changes must be covered by tests!
Current tests should not be failed.

@ggnaegi
Copy link
Member

ggnaegi commented Feb 15, 2024

@raman-m @Ugway77 doesn't seem to respond, could we create another PR instead? I would like to tackle this issue for the annual release, and then, in a second step, the modifications in the Multiplexing Middleware. Thanks!

@raman-m raman-m changed the title Fix lost context User after multiplexing in 'MultiplexingMiddleware' #1396 Lost context User in MultiplexingMiddleware Feb 15, 2024
@raman-m raman-m self-assigned this Feb 15, 2024
@raman-m raman-m added Aggregation Ocelot feature: Request Aggregation high High priority 2023 Annual 2023 release and removed needs feedback Issue is waiting on feedback before acceptance labels Feb 15, 2024
@raman-m raman-m added this to the Annual 2023 milestone Feb 15, 2024
@raman-m
Copy link
Member

raman-m commented Feb 15, 2024

@ggnaegi I will take care of this PR having assigned High priority
Will start development right after merging #1963

...doesn't seem to respond, could we create another PR instead?

We have feature branch: Ugway77:fix_contextuser_lost_after_multiplexing
We can reuse the branch, no need to create separate one.
But sure, we could have some pair programming 😉

@raman-m raman-m added Jan'24 January 2024 release and removed 2023 Annual 2023 release labels Feb 15, 2024
@raman-m raman-m modified the milestones: Annual 2023, January'24 Feb 15, 2024
@raman-m raman-m force-pushed the fix_contextuser_lost_after_multiplexing branch from 2f2b834 to 0c4c838 Compare February 19, 2024 13:03
@raman-m
Copy link
Member

raman-m commented Feb 19, 2024

Information

Class: Ocelot.Multiplexer.MultiplexingMiddleware
Assembly: Ocelot
File(s): src/Ocelot/Multiplexer/MultiplexingMiddleware.cs


Line coverage: 54.1% (+1.0)
Branch coverage: 42.3% (+3.9)

@raman-m
Copy link
Member

raman-m commented Feb 21, 2024

@ggnaegi commented

Please, review and I'm going to merge.
Because this is system core upgrade in multiplexer I'm not sure on updating docs.
Should we write in docs that current User is multiplexed for the rest of pipeline middlewares?

1st, User can setup Ocelot app authentication (app instance access) in own way, so seems this is out of the scope of our responsibility, but we forward User property when multiplexing.

2nd, downstream route can authenticate if AuthenticationProviderKey exists, and User property of app instance (current request) will be overwritten by new auth result of downstream after multiplexing.

3rd, I paid my attention to entire Ocelot pipeline.
Our lovely MultiplexingMiddleware

app.UseMultiplexingMiddleware();

is defined before AuthenticationMiddleware:
app.UseAuthenticationMiddleware();

So, because of that pipeline middleware order we can't get authenticated user of current request when multiplexing. But in theory we can setup Ocelot to authenticate each request (per app instance) and forward this user. But it is impossible because of pipeline design.
Look at my acceptance test: it has a lot of coding hacks to finally get auth user of the request.
Also, seems Ocelot breaks regular ASP.NET conveyor and my custom auth setup in AddMvcCore have failed (per app instance),
https://github.com/Ugway77/Ocelot/blob/fix_contextuser_lost_after_multiplexing/test/Ocelot.AcceptanceTests/AggregateTests.cs#L560-L567
and I have to authenticate manually right in the place. This is bad.
I expect that other ASP.NET middlewares are broken too: it will be impossible to setup their DI services.

@ggnaegi
Copy link
Member

ggnaegi commented Feb 21, 2024

@raman-m commented on Feb 21

It is why I decided to refactor the multiplexer: The code is very difficult to read and to understand. As soon as we are done with this PR, I'm going to rebase the Multiplexer-PR. I'm going to review the code tomorrow!

@raman-m raman-m merged commit 108bede into ThreeMammals:develop Feb 22, 2024
2 checks passed
@raman-m raman-m mentioned this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Aggregation Ocelot feature: Request Aggregation bug Identified as a potential bug high High priority Jan'24 January 2024 release proposal Proposal for a new functionality in Ocelot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How can I implement policy based authorization with Ocelot?
5 participants