traefik-forward-auth icon indicating copy to clipboard operation
traefik-forward-auth copied to clipboard

Use X-Forwarded-Prefix if present to handle PathPrefixStrip traefik rules

Open seuf opened this issue 6 years ago • 19 comments

When Traefik is configured with PathPrefixStrip rules, the X-Forwarded-Uri is equal to / instead of the prefix. This fix use the X-Forwarded-Prefix Header when present to allow correct redirection and rules matching.

seuf avatar Jun 11 '19 10:06 seuf

Thank you for the pull request!

This feature was also proposed against v0 in #39 which I was planning to merge into this branch.

There's a few changes that will be needed here:

  • My understanding of PathPrefixStrip is that X-Forwarded-Prefix will contain the stripped part, not the entire path. As such, the full path is the concatenation of X-Forwarded-Prefix and X-Forwarded-Uri (as done here: https://github.com/thomseddon/traefik-forward-auth/pull/39/files#diff-dc18d370e42b9d70e5569705202625aeR211)
  • Would you be willing to also add support for the X-Replaced-Path case?
  • Please could you add some tests to verify the intended behaviour

thomseddon avatar Jun 11 '19 11:06 thomseddon

Hi @thomseddon do you know when you will have time to review / merge this ? Thanks.

seuf avatar Jun 21 '19 08:06 seuf

I'm hoping to have a look at this and a few others next week :)

thomseddon avatar Jun 21 '19 08:06 thomseddon

Hello!

Sorry for the delay in reviewing this, I've just had a look through, the main thing I'm not sure about is the modification the r.URL in the Server RootHandler - what was you're thinking behind this?

The idea is that the rules are based on the requests. So the RootHandler rewrite the incoming request according to the Headers X-Forwarded-Uri and X-Replaced-Path if presents.

seuf avatar Jul 08 '19 16:07 seuf

Right, I thought so.

I just wondered if it was more logical to write rules based on the original request, or based on the modified request - do you have a use case where you needed the former?

thomseddon avatar Jul 08 '19 16:07 thomseddon

I've tried to use a PathPrefixStrip rule in traefik ingress and the returned uri was / instead of the wanted path. If we handle the request path in the root handler, the logic of rules and redirects after login are simpler.

Le lun. 8 juil. 2019 18:27, Thom Seddon [email protected] a écrit :

Right, I thought so.

I just wondered if it was more logical to write rules based on the original request, or based on the modified request - do you have a use case where you needed the former?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/thomseddon/traefik-forward-auth/pull/49?email_source=notifications&email_token=AAKGIJ3X2RM6BLAVCXTOQSTP6NTHRA5CNFSM4HW5BOC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZNUABI#issuecomment-509296645, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKGIJ7NI5AXYMF4ROTH2F3P6NTHRANCNFSM4HW5BOCQ .

seuf avatar Jul 08 '19 16:07 seuf

Do I need to change something ? We really need this feature to be merged in upstream

seuf avatar Jul 25 '19 15:07 seuf

@thomseddon Do you plan to merge this ? Do you need more changes ?

seuf avatar Sep 13 '19 13:09 seuf

Sorry, I didn't see your change request. I've added the fix you suggested.

seuf avatar Jan 30 '20 13:01 seuf

HI @seuf and @thomseddon, I stumbled upon this issue as well and wanted to see this PR merged asap as well as I am also using PathPrefixStrip routes in my production setup. Please take a look into this asap.

sriramsv avatar Feb 18 '20 20:02 sriramsv

I've rebased over master to avoid conflicts

seuf avatar Feb 19 '20 13:02 seuf

ping ?

seuf avatar Apr 06 '20 12:04 seuf

ping ?

seuf avatar Jun 22 '20 07:06 seuf

@thomseddon I've pushed an update on the function to check the X-Forwared-Prefix first as you suggested. is it ok for you ?

seuf avatar Jul 17 '20 09:07 seuf

+1 ?

seuf avatar Oct 07 '20 11:10 seuf

This would be great so StripPrefix can be used.

dicksnel avatar Dec 09 '20 10:12 dicksnel

I'm glad I found this issue - I had no idea what I was doing wrong! 😖

If this works, it would be great if it could be merged. As they say, perfect is the enemy of shipped...

dhirschfeld avatar Feb 24 '21 02:02 dhirschfeld

I can confirm that running this PR works! :tada:

dhirschfeld avatar Feb 24 '21 04:02 dhirschfeld

+1 ?

seuf avatar Apr 13 '21 13:04 seuf