-
Notifications
You must be signed in to change notification settings - Fork 41.2k
ConnectionDetails for external providers in Spring Security modules #36777
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
Comments
@ParkerM Can you share a bit more information about how you use Testcontainers with Keycloak? Are you using https://testcontainers.com/modules/keycloak/ ? |
@philwebb yep, that's the one. Right now it looks a bit like the TestConfiguration + Bean method + injected DynamicPropertyRegistry approach described in the docs here (plus a few startup tasks that would ideally be rolled into the image or exist as opinionated defaults). This class is imported for int tests, and applied for the test application as I did manage to get the test application to start up with this configuration after some finagling — I was experiencing some sort of lifecycle issue with eager connections failing startup before the container was ready. Removing In any case, I'm curious whether the goals of the ConnectionDetails abstraction fundamentally align here (even if it's for my own selfish understanding of the API and its goals). If my understanding is correct then the Spring Security configs could potentially be a good fit, since most contain a representation of remote service(s) and the credentials used to connect. This would also provide more sensible means for programmatically accessing validated connection properties. My current approach involves injecting Boot's ConfigurationProperties beans and clumsily accessing deeply nested properties. Separating that concern into ConnectionDetails would make for more obvious injections and provide more convenient options for test stubs and such. Apologies if the info above isn't what you were looking for. If so let me know and I can expand or perhaps create an example project on my own time. |
We talked about this yesterday and we think the The approach would be the following:
Step 2 and 3 is the tricky bit. I've not looked at the Keycloak testcontainer in detail, but I remember from the standalone Keycloak that one has to do some realm / client setup before it's usable. |
Yeah, I currently have realm import do most of the work then use the Keycloak client to adjust some ports before the tests run (maybe the future will see something like a configurer DSL that simplifies test setup). My original plan was to just implement my own |
Would definitely like to see this happen as well, for any generic OpenID or OAuth2 provider. I'm specifically thinking about Dex and custom-built authorization servers. I'd want |
I'm just seeing this now @philwebb. Apologies for the delay. @rwinch and I have been talking about introducing integration testing support (spring-authorization-server#258) for Spring Authorization Server. I'm not familiar with the ConnectionDetails abstraction so I would need to look into this and see if this is an entry point for the support. |
Moving into 3.4.x to consider alongside #39391 which doesn't tackle Testcontainers or Spring Authorization Server. |
I've been looking at #39391 which tackles part of this, and I'm struggling to figure out exactly how broad the connection details should be. It's not clear to me where we should draw the line in terms of what the connection details should override and what should come from the normal configuration. Just focussing on the OAuth2 client side of things for now, @ParkerM, @Kehrlann, @PhilKes, could you please provide some more details about how you're configuring things at the moment (the application.properties or application.yaml) with |
Hey @wilkinsona, The one thing you absolutely need is the I have a lightweight Testcontainers module for the Dex IDP. I did my own starter with ConnectionDetails. Let's say you register your OAuth2 clients dynamically, then you need:
For the rest I'd imagine it comes from configuration:
Keycloak in a container, why?
In my experience, Keycloak in a container is a pain - slow to start and the config is huge. I'm using Dex, and custom apps built with Spring-Auth-Server, as a substitute for online IDPs (Okta, Azure). Learnings from using Dex in TestcontainersThe problem I had with Dex is that there is a lifecycle issue, at least in tests:
So when you run in tests and both have dynamic ports, this is harder to know. Current flow:
Any provider that does strict redirect uri checking would have the same problem. |
In my case I was working on a federated login sort of thing that used spring authorization server as a primary OAuth2 provider and Keycloak as an "external" IdP. So, while I did need to set some I didn't really foresee On the other hand, In my particular case I was using Keycloak as a SAML provider, so I was interested in configuring the
We support Keycloak as a provider and occasionally use it in production-like environments, but in this case I selected it for easy-to-run-in-a-container reasons. Namely for the convenience of realm export/import as a way to "serialize" a production instance so it can be reproduced in an ephemeral container with little fuss and minor additional configuration (and it's FOSS and supports SAML). The additional configuration not handled by the realm file boils down to (re-)configuring callback URI's via the Keycloak API. |
Part of my dev workflow involves using Testcontainers with Keycloak for integration testing against a local, preconfigured IdP/authorization server. It would be awesome if I could use the very same configuration with a running instance through spring-boot-testcontainers, but from what I can tell this isn't currently possible unless the respective configurators implement or expose a
ConnectionDetails
in some way. (I assume I could achieve something like it if I replace the Spring Security autoconfigurations with my own, but I'd prefer to stick with conventions as much as possible.)The use cases that come to mind are:
spring.security.oauth2.client.provider
spring.security.saml2.relyingparty.registration.<id>.assertingparty
Does this seem like a sensible use case for the
ConnectionDetail
abstraction? I've noticed the current implementations seem concerned with strictly persistent connections, so perhaps this does not fit the intent. But, since the provider auto-configurations can lead to startup failure when the server is unreachable, the connections at least have some sort of persistent essence.The text was updated successfully, but these errors were encountered: