Repository navigation
[KEYCLOAK-12305] [Testsuite] Check LDAP federated user (in)valid login(s) using various authentication methods, bind credential types, and connection encryption mechanisms - #7049
Conversation
|
Brief testing results on my machine (prior Travis has had chance to complete):
|
|
JFTR, verified the reported Travis failure. Seems to be a red-herring, caused by Ubuntu ca-certificates-java package bug. Doesn'
8000
t happen with Ubuntu 16.04 |
There was a problem hiding this comment.
I've added few minor inline comments.
However it seems that most major problem would be to fix the startTLS tests to reliably work in travis and on all environments (including OpenJDK11, Ubuntu etc).
Few possibilities:
- Add some "Assume" checks to the StartTLS tests and ignore them for unstable environments (EG. OpenJDK 11). We need to make sure that tests run at least in the pipeline during run of LDAP tests. If they don't run on travis, it is fine IMO.
- Another idea would be to add some "sleep" somewhere after start of LDAP server (maybe server just needs some more time for initialization). This just comes to my mind when @tsaarni mentioned, that he doesn't see the issue whe he is debugging. Debugging usually takes some time, so it is possible that LDAP server had some additional time to initialize etc. If it is additional 5 seconds after server startup, it helps to avoid the issue. More like 5 is not ideal as it negatively impacts the testsuite time
- Something better to make sure that test is stable on all environments and never hangs and doesn't even need to wait. But I don't know if something like this exists :-)
|
I tried uplifting Apache DS. StartTLS hangs seem to disappear, it now works for me with JDK11 as well as JDK8! Though while uplifting ApacheDS I broke two other LDAP tests. See here for the errors. These seem completely unrelated to StartTLS and are maybe related to a change I needed to do in RangedAttributeInterceptor.java to get the embedded-ldap server to compile. I must confess I don't really know what I'm doing so I'm not sure if I will figure out this 😊. Here is the patch I have, done on top of this pull request Nordix@6bf7f43 The easiest way I figured out to uplift was by removing the file and in-memory DirectoryServerFactories since it seemed to me that only in-memory was ever used. I followed this example. I think this should be in-memory database, at least ApacheDS comment for AvlPartition says "An XDBM Partition backed by in memory AVL Trees". |
|
Small update on my previous comment: The failures of I did that now in Nordix@637959c but that apparently breaks all searches. I'm trying to figure out what is going on. |
|
@tsaarni We use in-memory when running LDAP tests in the testsuite. However we use file when using LDAPEmbeddedServer and KerberosEmbeddedServer as standalone classes (both of them have main method). This helps to ensure that restart of LDAPEmbeddedServer doesn't mean that you loose your LDAP data, but they are persistent among server restarts. It will be good to still have both available. |
|
Hey Tero,
+100 if it would be feasible to overcome the startTLS JDK11 hang with Apache DS LdapServer version bump. With the currently used Apache DS version was yesterday able to reproduce the hang even with JDK 1.8 on Xenial Xerus: Interestingly, it doesn't hang when not using some debug option at all, or when debugging just SSL ( Per inspection of related OpenJDK bugs, socketRead0 can hang during SSL with misbehaving server, or under higher load. So AFAICT, there definitely seems to be something wonky with the current Apache DS version, we use, since (maybe depending on the server load?) sometimes the tests run without issues, other time they end up with "possible truncation attack?" and corresponding thread, performing the SSL/TLS (re)negotiation hangs indefinitely.
TL;DR: So from the above, I see two ways how to address this: 1) either update the Apache DS version, or 2) update the tests (add some sleeps) so the server doesn't end up with high load while processing the StartTLS requests. But given the latter is just a workaround (might be hard to achieve in real testing CI scenario, when there are multiple tests run in parallel anyway), I would prefer the Apache DS version bump.
Woot, nice. Thx! Will try that. Do you want / need some help to get the Apache DS version bump fully working with the other existing LDAP tests too? (need to adjust the current PR to address Marek's comments yet, but for now I would assume there's no startTLS subcase hang with JDK11 anymore, and could help you later with getting those in-memory / file store based DSFs working with the bumped server, if needed. Those other failing tests are a black-box for me now, but assuming as far as we are able to provide those two DSFs to them, they require, we should be good to go.
See Marek's reply below for clarification, why we need that file store based DSF, so that one would need to be preserved, if the server bump should work. |
Right, thanks Marek! @ the end didn't actually touch (try to fix) the StartTLS hang issue with JDK11 (solely present on Ubuntu?) issue. since Tero is currently working @ separate PR (JIRA ID to come yet?) to get the Apache DS version bumped to latest upstream version, not prone to this problem any more. @tsaarni TYVM for taking care for this one! |
|
I've now submitted KEYCLOAK-14162 and #7069. Hopefully this fixes the StartTLS problem! |
|
@iankko I have one proposal regarding the test cases: there is a method |
@tsaarni Right, good catch! Will add it, thanks |
|
@tsaarni @mposolda Ready for (re)review. Fixed conflict, rebased to master, added that confidentiality requirement for both startTLS & LDAPs cases. Verified, it works without issues (the previous hang disappeared) for all possible combinations of the following:
|
There was a problem hiding this comment.
I see there is lots of travis failures in LDAP tests and also UserFederationConnectionTest. I think this is probably caused by the "setConfidentialityRequired(true)" when using StartTLS or SSL support.
IMO it will be good to remove this change and still allow connection over "ldap" even if support for "ldaps" or StartTLS is enabled. This is what I also mentioned in the inline comment.
The alternative could be to add another configuration option for the LDAPEmbeddedServer like "confidentialityRequired" and explicitly enable this just for the StartTLS tests? However by default this "confidentialityRequired" should be false IMO.
There was a problem hiding this comment.
Still requires some work as LDAPUserLoginTest is still failing.
Travis is using Keycloak on Wildfly. Is it possible that it works for you when testing with Keycloak on Undertow and it is failing on Travis with Keycloak on Wildfly. Just a quick hint, not really sure if this is the reason or not...
|
I think it fails because truststore is not configured when running Wildfly. Creating Elytron default SSL context fixed the problem for me (see diff below), though I'm not sure if this is the optimal way to do this? Also, not sure if it would be more appropriate to create new diff --git a/testsuite/integration-arquillian/servers/auth-server/jboss/common/jboss-cli/keycloak-server-subsystem.cli b/testsuite/integration-arquillian/servers/auth-server/jboss/common/jboss-cli/keycloak-server-subsystem.cli
index 3362d7b189..48a5d73457 100644
--- a/testsuite/integration-arquillian/servers/auth-server/jboss/common/jboss-cli/keycloak-server-subsystem.cli
+++ b/testsuite/integration-arquillian/servers/auth-server/jboss/common/jboss-cli/keycloak-server-subsystem.cli
@@ -8,6 +8,12 @@ echo ** Adding truststore spi**
hostname-verification-policy => "WILDCARD", \
disabled => "false"})
+echo ** Adding truststore for default SSL context e.g. for LDAP client **
+/subsystem=elytron/key-store=default-trust-store:add(path="${auth.server.truststore:${jboss.home.dir}/standalone/configuration/keycloak.truststore}",credential-reference={clear-text="${auth.server.truststore.password:secret}"})
+/subsystem=elytron/trust-manager=default-trust-manager:add(key-store=default-trust-store,algorithm="SunX509")
+/subsystem=elytron/client-ssl-context=default-ssl-context:add(trust-manager=default-trust-manager)
+/subsystem=elytron:write-attribute(name=default-ssl-context, value=default-ssl-context)
+
echo ** Adding login-protocol spi **
/subsystem=keycloak-server/spi=login-protocol/:add
/subsystem=keycloak-server/spi=login-protocol/provider=saml/:add(enabled=true,properties={knownProtocols => "[\"http=${auth.server.http.port}\",\"https=${auth.server.https.port}\"]"}) |
|
@tsaarni Hmm... AFAIK the truststore is set and it is used for example for X509 related Keycloak tests . But as you pointed, I also assume the problem here is somewhere around truststore setup/configuration. |
|
@mposolda I found the problem by looking at Wireshark traffic capture, Keycloak rejected the TLS server with an alert about unknown CA. I tried to find out where in the code the truststore could be configured but I was not able to find it yet. That's when I ended up trying with the above diff instead. |
|
@mposolda One question: are the other X509 tests using Keycloak subsystem specific Elytron truststore? LDAP client within Keycloak is not Elytron aware and requires configuration of default-ssl-context. |
|
@tsaarni AFAIR the X509 tests doesn't use the elytron. I recall the truststore is somehow copied to the wildfly distribution during preparation of the auth-server-wildfly server for the testsuite. Then the truststore is set either through the truststore SPI or through the system properties. I see the properties auth.server.truststore and auth.server.truststore.password used in arquillian.xml during startup of auth-server-wildfly. So possibly the certificate needs to be added to the truststore pointed from here? |
|
@mposolda the file but it still did not work. I wonder how does the truststore SPI interact with something like the LDAP client in |
But is it the same file (truststore with the same content)? Verbose testing prints for me the tests are set to use the keystore under: Maybe it would be enough just to unify the paths (make the embedded ldap server use the Keycloak one), IDK, need to try it |
|
@iankko I've just recalled that we already have some existing tests, which allows Keycloak server to connect to ApacheDS with the usage of SSL (ldaps URL). The test is UserFederationConnectionTest.testLdapConnectionsSsl() . So it means that truststore is already correctly set. It is just not used for the "StartTLS" case, but it is only used for the "SSL" case. I suppose the reason can be the "Use Truststore SPI " switch of the LDAP provider. By default, it has value "Only for ldaps" . So maybe if you switch this to "Always" for the StartTLS tests, it will help? |
Yes, AFAICT (based on the testing) the truststore seems to be correctly set (it even works for SSL tests, just the StartTLS ones return
Will check this yet, thanks |
@mposolda JFTR, having Browsing the internet for the explanation / reason of the failure revealed, this might be caused by unsupported client certificate. Digging further (wondering if this might be caused by invalid hostname verification in the certificate or something else yet). |
|
When I set I'm trying to learn more about this and I think I may have found how Truststore SPI interacts with the LDAP client code in Java: Does this mean that LDAP client will forcibly get TLS connection, regardless of connection URL being |
|
@tsaarni Hi, just small update that @iankko is on PTO for this week. So if you are eventually able to continue with his work and fix the failing test, it will be nice. If you manage to figure this by the end of this week, then feel free to comment here. It will be fine if you manage to send PR with @iankko's commit for this PR and then possibly another commit of yours, which will fix the test. Just an idea in case if you have some spare time to look at this :) Thanks for your help! |
|
I could not think any easy way to make truststore SPI to work with Java LDAP client. As I wrote previously I found alternatives though: As I wrote previously I could use Elytron to define default SSL context with the truststore. Java LDAP client picks up that also in case of StartTLS. It also works simply by setting default truststore: diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml b/testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml
index f56f9bed90..fc07ff659e 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml
+++ b/testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml
@@ -141,6 +141,8 @@
-Dauth.server.truststore=${auth.server.truststore}
-Dauth.server.truststore.password=${auth.server.truststore.password}
-Dauth.server.db.host=${auth.server.db.host}
+ -Djavax.net.ssl.trustStore=${auth.server.truststore}
+ -Djavax.net.ssl.trustStorePassword=${auth.server.truststore.password}
</property>
<property name="javaVmArguments">
${auth.server.jboss.jvm.debug.args}though this does not work exactly like this: for some reason variables are not expanding correctly and I get |
|
@mposolda I might have an idea how to use Truststore SPI for LDAP StartTLS:
I have a work-in-progress implementation here Nordix@6d05d65. However this this does not work yet, and I would appreciate some help: I need to call How would I go to solve this? |
|
@tsaarni Thanks for the update! In high-level view, it will be good to do anything, which will help to:
Regarding the "Always Use Truststore" switch, it was just an idea from me that failing tests have something to do with this switch. But it is possible that the switch "Always Use Truststore" is not the way to go and it rather doesn't work at all when you use StartTLS. So not sure if it makes sense to spend time to have things working with this switch? I rather leave to you, but hopefully it is a way to have StartTLS working as expected with ApacheDS in the testsuite... |
|
@tsaarni @iankko Will it be helpful to do this in stages?
This will help to have at least some tests working in latest Keycloak master. Then we can follow with StartTLS as another step. In general, using smaller PRs is usually better and also it will help with the ability to be done by different people (So @iankko can finish his work ASAP and then @tsaarni can follow with the StartTLS tests working). WDYT? |
|
At least currently I feel pretty convinced that the test is failing because of interactions between LDAP provider, Truststore SPI and Java LDAP client :-) It think it works with embedded undertow because truststore SPI is disabled in that case. I interpreted that On the other hand: personally I'm more interested in Elytron since I understood it should be able to hot-reload certificates when they are rotated, without needing to do any restarts. That feature alone would make other alternatives quite obsolete in my mind. Anyways, we can do this in stages like @mposolda proposes. |
|
@tsaarni @iankko +1 to do that in stages. So if you both agree, we can just keep this @iankko's PR with the StartTLS to have Ignored annotations and create separate JIRA(s) to fix them. WDYT? Regarding the LDAP Provider, Truststore SPI and Java LDAP client - it is possible that this combination is broken as you pointed. So it is possible that you will need to fix the bug if you want to make this working. However maybe as first step, you can try to have StartTLS tests working with the default setup of the "Use Truststore SPI" flag - which is with the value "Only for ldaps" ? Then to have it working with the "Always" can be another step? Just to explain a bit more, the "only for ldaps" is the default value of the "Use Truststore SPI" flag. This value means that LDAP provider should try to use Truststore SPI just in case that "ldaps" connection is made. This is the default value for the "Use Truststore SPI" flag and it is the default value for both Keycloak on Wildfly and Keycloak on Undertow. With the StartTLS, the connection to LDAP still starts with "ldap" and hence the Truststore SPI shouldn't be used in this case - this apply for both Wildfly and Undertow. So in this case, the used truststore is not driven by Truststore SPI, but instead it is driven by system properties "javax.net.ssl.truststore" and "javax.net.ssl.truststorePassword" . So if it works on undertow and doesn't work on Wildfly, then probably something doesn't work as expected in the setup of those system properties. Again, just a hint, I am not 100% sure about that... :-) |
AFAICT from the previous testing, this seems to be the case (the currently proposed StartTLS tests are failing already in the It think it works with embedded undertow because truststore SPI is disabled in that case.
Maybe it was supposed to work with StartTLS too, but TBH I doubt it ever worked. IMHO though setting the instead of always using the default SSL socket factory, like it's done now.
I was able previously to solve the [**] Simply moved the
See above. AFAICT I doubt it was ever working for the StartTLS case due to always using the default socket factory when calling the
+1 |
If using I could then try adding Truststore SPI support for "always" scenario separately. |
@tsaarni +1 |
Filed KEYCLOAK-14343 for the Will update this PR with the suggested pom changes yet (fix the conflict, rebase etc.) |
login(s) using various authentication methods, bind credential types, and connection encryption mechanisms The tests cover various possible combinations of the following: * Authentication method: Anonymous or Simple (default), * Bind credential: Secret (default) or Vault, * Connection encryption: Plaintext (default), SSL, or startTLS Also, ignore the StartTLS LDAP tests for now till KEYCLOAK-14343 & KEYCLOAK-14354 are corrected (due these issues they aren't working with auth server Wildfly). They will be re-enabled later via KEYCLOAK-14358 once possible Signed-off-by: Jan Lieskovsky <jlieskov@redhat.com>
Thanks for the hint, Tero!
Right, great catch! Reproduced this behaviour yesterday too & filed KEYCLOAK-14354 to track the problem. Also, seems to have got a fix for it (official PR to come soon), but since it will take some time that PR to get reviewed (verified if it doesn't cause regression in other LDAP tests), have disabled the StartTLS tests for now (till both of KEYCLOAK-14343 & KEYCLOAK-14354 are fixed). Will re-enable them back within KEYCLOAK-14358 once they are fixed
|
|
@mposolda @tsaarni All done (rebased to current As mentioned already, marked the StartTLS tests to be ignored for now (due to the KEYCLOAK-14343 & KEYCLOAK-14354 issues), since they aren't working with the auth server Wildfly. They will be re-enabled back once these two issues are corrected |
|
@iankko @tsaarni The PR is merged and KEYCLOAK-12305 JIRA resolved. So if I understand correctly, the next step might be:
|
|
I'm working with https://issues.redhat.com/browse/KEYCLOAK-14343 though I'm fighting with Wildfly modules and since I'm a total newbie, I'm now quite lost. I could submit WIP PR and ask help from you :) |
@mposolda Woot, thx!
Yes, looking into this one (since it seems it's another testing feature that (n)ever worked & not used just by this LDAP login user test). Will report the progress back |
No problem, no worries. Thx for looking into this! |
|
@tsaarni Hmm... Strange that you need to find with the Wildfly modules. I hope that no change in them will be needed, but maybe I am wrong... +1 for the WIP PR. We can possibly discuss the details here? I think you can explicitly mark the PR as "draft" or something like that, so that it is more explicit that it is work in progress. |
Uh oh!
There was an error while loading. Please reload this page.