-
Notifications
You must be signed in to change notification settings - Fork 350
[KEYCLOAK-10864] - Add support for Looser path normalization #483
Conversation
Make working with backends like jenkins easier
Is it normal to get no feedback on PR in this repo ? :) Posted on the mailing list, Create a Jira case and everything else thanks |
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.
Tested this, looks good.
Additionally I think it's a bug, that the normal behavior is to sent the decoded URL to upstream.
Nice, i kinda had lost faith on this :)
I do agree , as a user when i started looking into my issue i was buffled as to why i was not getting the raw path when it was not required |
@primeroz @bruegth if I understood correctly the issue, the bug you reported applies only to Jenkins and no other server, correct? If yes, I don't see us moving forward with this, but if you have more use case scenarios I'm more than happy to take a look. @primeroz I understand your frustration, but please keep in mind that people inside Keycloak organization, are working not only on Gatekeeper and the sentence in the mailing list: "But this is more of a POC than anything else since I am not sure the implication of those changes and if is a good idea at all to do this.", rings a bell that this PR requires more time for testing. @stianst I still need to test the changes here, but if it's specific to Jenkins, I'd say that Gatekeeper should not cover it. Otherwise, we need to adapt to every particularity from other servers outside. |
@abstractj , let me apologize if what i wrote was offensive , i did not mean that and i guess i did not think enough when i wrote it ... i hoped the on the more technical side
That is not really fair to say in my opinion. The question that stands, and the reason why i wrote that this was a POC , is that I am sure there are plenty of reason to do a very Also , to be on the safe side, i ended up writing a separate function https://github.com/keycloak/keycloak-gatekeeper/pull/483/files#diff-4c166b743d95629a9ab37eb6fe3df22aR74 rather than changing the current normalization function ... again because i did not want to introduce any security issues in a piece of code that seems to work just fine in 99.999% of cases.
Again i don't think this is the right point of view on the issue, i would ask more if gatekeeper should support a looser normalization of the path before proxying the request upstream to allow services like jenkins, that do exploit the url in ways that are If the answer is no i would totally be fine with it by the way thanks |
We actually have this problem with rabbitmq when you leave the default vhost setting. And some internal angular apps, as they try to use encoded |
@primeroz it's all good. Would be possible to add more details about how to reproduce the issue you mentioned in the same Jira (step by step)? That would help with the review process. We did something similar in this Jira. @razzeee thanks for reporting this. Would you mind adding your scenario in the comments of the same Jira + steps to reproduce? The reason why I'm asking this is that I would like to make sure that the change submitted by @primeroz, also covers the issues you have with rabbitmq. |
@abstractj
Together with default OAuthURI = "/oauth" and optinally BaseURI = "/base-uri" and hardcoded:
all will result in e.g.: "/base-uri//oauth//authorize" If I fix WithOAuthURI by removing slashes between, nearly all tests will fail with 404. This is also useless in entryMiddleware:
But in forwarding.go this is missing:
because of this:
So at all, I think this PR should be refactored as bugfix, so that FlagRemoveDuplicateSlashes not needed anymore and also RawPath will be used in forwarder to prevent sending decoded path to upstream. See my branch: https://github.com/bruegth/keycloak-gatekeeper/tree/native-go-proxy |
I'm working on the same project as @bruegth is and before he cooked up the custom version we're running right now, we could just not query routes that included encoded |
In my case i can report the same url i did report in the JIRA case , when using jenkins a URL like
hit the proxy , but when is proxied upstream, after normalization, the |
I can try to get something , the only issue i can see for jenkins is that since the configuration that requires that special url is the reverse proxy one i will need to make it work with the whitelisting on the proxy ... but yeah i think it should work. i will give it a shot |
@abstractj note that in the case of jenkins you will just see an error in the ui , it won't really tell you that the problem is a malformed url ... to figure that was the issue i had to go through logs an use an upstream service to print back the url it received and noticed it was malformed. |
@abstractj example here https://github.com/primeroz/keycloak-10864-test-jenkins instructions in readme |
@abstractj I think joining efforts to merge this with #535 runs counter to the idea of having just 1 issue per PR and one squashed commit per PR. #535 is a bug fix and this is a feature enhancement plus a bugfix for something not listed as a bug in JIRA. Also #535 is ready to go, including testing. I would much prefer you accept #535 as is and then open separate PRs for this "-loose-path-normalization" flag (or maybe "--santize-path") if it is still needed and for removing Let us please not make the perfect the enemy of the good. |
@abstractj @Nuru my understanding is that the #535 would superseed this one, looking at https://github.com/keycloak/keycloak-gatekeeper/pull/535/files#diff-4c166b743d95629a9ab37eb6fe3df22aR70 for everything other thant the If that is the case i can wait for #535 to be merged in and rework this ( or maybe close and recreate) to only handle the use of different flags in the same middleware handler by using a flag at cli. |
@primeroz Yes, thank you, #535 is meant to supersede this PR for the purpose of ensuring the upstream server gets the exact same request that Gatekeeper gets, thus closing KEYCLOAK-10864 and some other open bugs. It does not provide a flag or remove @abstractj This PR (#483) also (in addition to fixing KEYCLOAK-10864) makes changes to how Gatekeeper parses the request for the purpose of applying access control, and #535 purposely avoids making any such changes because that is a separate issue about which I think there has not been enough discussion. I would prefer we do as @primeroz proposes: merge #535 and get that into the release pipeline, after which everyone can continue to work on whatever remaining features you want that it does not provide. |
I honestly don't see why Gatekeeper would make any changes/normalize the request path at all. I can honely see that causing problems like this. |
@stianst You can see #200, #201, and #202 for the motivation to normalize the URLs before applying resource protection rules. The idea was to make it harder to circumvent resource protections through generating URLs that the upstream would consider equivalent but that Gatekeeper, in its implementation details, would consider different. I have my doubts about whether #202 was the right solution to #200, but I do not want to spend the time or energy getting into that. What I can say is that a naïve solution to KEYCLOAK-10864 that simply strips out the URL normalization will re-introduce #200. This is why I submitted #535: to fix KEYCLOAK-10864 without re-introducing #200 or getting into a discussion about whether #201 and/or #202 was the right fix. I am happy to leave that question open and have the discussion about it continue here or elsewhere. This PR has already been open 8 months; I would just like to get KEYCLOAK-10864 fixed sooner, and #535 can do that without risk of reintroducing #200, so I think it is a safer and easier option. |
@Nuru Makes sense to normalize the path within Gatekeeper for sure, while use the originial path when invoking upstream. I assume that's what your PR is doing. |
Closes louketo#528 Closes louketo#483 by superseding it as a bug fix, not an option
Superseded by #626. If there are any comments or questions, of if the issue persists. Please, let me know. |
Fix https://issues.jboss.org/browse/KEYCLOAK-10864
Make working with backends like jenkins , which expect an undecoded path with "//" , easier
Add a new flag to enable "--loose-path-normalization" with default to false so not to affect any current setup and not open up security issues