-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add ConditionalAuthenticator based on the client IP address #16453
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
Conversation
2e5128f to
3dcbf8c
Compare
|
You could probably write an integration test and send the request with an X-Forwarded-For header containing the client ip? I guess a lot of Keycloaks are deployed behind a reverse proxy anyways. |
|
Filtering IP ranges is also possible with the conditional http request header: #14605 it's more flexible but also more complicated. |
|
We use something similar of the same kind which only supports IPV4. It would be awesome to have this ConditinalAuthenticator built in to Keycloak directly instead of a separate provider. Would't it be better to use MULTIVALUED_STRING_TYPE instead of comma separated IPs? For the user it's self explaining and easier to read the IPs in the configuration view (see screenshot). At the current build there is an error which prevents the use of MULTIVALUED_STRING_TYPE properties #17851 but as soon as it is fixed it would be a better choice in my opinion. |
|
Actually I have also implemented something like that with some other devs. |
|
Hello everyone, thanks for you feedback and your suggestions :) Have a nice weekend! |
stianst
left a comment
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.
It's not really clear to me what the use-case for this one is. Could you please elaborate how this is intended to be used?
@stianst Sure! Our use-case is this: Is there an easier way to achieve this? Best |
|
We would love to have this feature as well. Many companies have security policies like this: |
180f10c to
035dacf
Compare
|
Hey everyone, sorry for not getting back to you earlier. I've modified my implementation to use the multivalue string type and to prefer the IP in the X-Forwarded-For header if it is present. i've updated the screenshot in the PR description. I've also added some tests, inspired by #14605 . Selenium does not seem to support setting request headers, so the test relies on the actual IP address during the test being the local loopback address. Could you take a look again? @raphisuter @sschu @Cyben @stianst Best |
1f4d81a to
f2d9206
Compare
072ea07 to
3aedd11
Compare
|
@stianst Is there anything I should change about this implementation? Or is this a feature that you don't want to include in Keycloak? In that case I would try to package it as a custom jar extension. |
|
My 2cs ... The capability herein proposed makes sense and I see it being helpful for others. However, the code we accept needs to be maintained, which most of the time relies on us. Sometimes competing with other priorities. This situation raises some issues for the project:
Only a few came to my mind ... The issues above are basically addressed by Keycloak Extensions, an initiative we did not yet finish discussing. I hope that after Keycloak 22 we can, together with the community, discuss an extensibility model that changes how people find/develop/test/publish extensions. |
|
Hi, Best |
|
Hey @BaraCoding I've moved this extension to a standalone plugin: https://github.com/evosec/keycloak-ipaddress-authenticator Just grab the |
Implements #16450
This authenticator accepts a list of ip addresses or subnets and matches if the client ip is in one of the specified subnets. It also allows for excluding the specified addresses, meaning that it matches if the client IP is NOT part of any of the specified subnets.
I added a dependency on com.github.seancfoley:ipaddress for parsing the ip address / subnet notation, because I did not find a utility for doing so that is already part of the project. I evaluated the apache commons-net library, but that one only supports IPv4, while the dependency by seancfoley supports both versions and also supports CIDR notation as well as netmask notation. Examples: a:b:c:d::/64, a.b.c.d/255.255.0.0
I did not include any test cases for this, because I'm not too familiar with the internals of this project and did not find a way to mock the client ip address in an automated test case. Maybe you have some pointers for me?
Example Screenshots of the new conditional authenticator: