-
Notifications
You must be signed in to change notification settings - Fork 1.6k
oauth2 + spring session + failover #104
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
I don't think there is a JDBC implementation of Spring Session (I might be wrong I guess). If there was it would be pretty routine to install it. Why not get it working with Redis first? All you need to do is declare the dependencies for vanilla use cases. |
There already is EnableJdbcHttpSession and that's not problem to configure. But at first I just want to know if there is some possibility to resolve my csrf issue without disabling csrf. |
I don't understand the question then. If you have spring session set up correctly then everything you need is there in the session. |
@dsyer problem is, that if I use the header HeaderHttpSessionStrategy and click on one of those two link which are navigating to /ui or /admin I'm asked for credentials (basic auth), because there is only header information (x-auth-token) and no cookie. So here is the question how to pass headers or if it's even possible while using only header strategy. |
Why do you want to use the header strategy? A UI with a browser client (like an auth server) is better with the default cookie strategy, I would have thought. I feel like maybe I'm missing something. |
I'm thinking about header strategy, because in the future I'd like to have some /api accessible for external services (not implemented by me). So for this I just want to create auth with header strategy. But maybe I'm thinking about it in bad way and it could be achieved simpler. Maybe I can add header in header filter to have both of them (cookie + header). |
@dsyer I have now following application. It's based on your double and authorization server from oauth2. Instead of using JWT I've configured auth server to use inmemory store and I'm using redis to store sessions in backend store. Now when I access url localhost:8080 I'm redirected to localhost:9999/uaa/login what is ok. Then I log in, approve the ticket and after that, I'm navigated back to localhost:8080 but instead of index.html I'm getting |
From |
@dsyer thanks...I've added |
@dsyer can you please help me to resolve I hope last issue (application is updated an seams to be working)? Currently when I authenticate on uaa server I'm navigated back to gateway at localhost:8080/login. Problem is that gateway doesn't know about session as can be viewd in 2.nd step in securityfilterchain (SecurityContextPersistenceFilter) . Thanks
|
I'm not sure I follow that, but it's normal to have 2 sessions (one at the auth server and one at the client app). So I don't think there's an issue with the sessions or cookies. Your logs say "Could not obtain access token". So that would be an issue (probably a config error). |
@dsyer it debug it looks like the AccessTokenRequest.preservedState is null hovewer state is provided in requests /login?code=nYd9AN&state=x7GTpX. Am I missing something? |
Do you actually have a session on the client app? If not that could be the problem. |
@dsyer I'm sharing the session using spring-session (persited in redis) so it should be there. But while I have |
|
@dsyer you are right, cookies are created. But I don't understand what's going on in that last 3 steps
|
That all looks good to me (except the 401 of course). It seems like you have screwed up the client configuration somehow. What makes you think the problem is with the state in the session? Look at DEBUG logs on the auth server to find out why the access token is not granted? |
@dsyer I've debuged the code and getting this This is my client configuration
and this is uaa config
|
Does it work without Spring Session? |
@dsyer yes it works without Spring Session. Do you have some hint what could be wrong here? |
I think the sessions might be colliding in Redis. Your browser is sending 2 cookies to the auth server, and I would only expect one, for instance. How about if you configure the auth server to store sessions in a different database or something? |
@dsyer I've disabled the spring-session on uaa and it's working. I'm wondering if the session could be shared from within uaa. I don't understand how those sessions are now working. Please correct me in following steps:
Is it ok from security perspective to have uaa with it's own session? Many thanks |
That's normal. I don't know why you would have any concerns about that. I think this is probably a bug in Spring Session (2 cookies with different paths shouldn't collide like that). Maybe you could create a new ticket there? |
@dsyer I've created spring-projects/spring-session#543. |
I don't think you should be sharing sessions between the app and the auth server. That's what is causing all the problems. N.B. |
@dsyer sorry that was my typo I used |
I don't get it. All those sessions are necessary. You just have to avoid them sharing storage (I think that's the bug). |
@dsyer when I'm navigating between apps:
so I was thinking about steps 4 and 5 when I want to reuse sessions created in earlier steps instead of creating new one. So in step 4 use u1 and in step 5 use a1. Is this somehow possible or I'm thinking wrong about it?
Why avoid sharing storage? As I read that could be potential security issue. I'm still thinking about high availability and failover in case something goes wrong. Would it be ok if I store sessions to separate spaces in redis per application? |
I believe there is a bug which mixes up the storage between your gateway and your auth server in redis (since the two systems work fine if only one of them has a redis session). That's not (just) a security issue, it's a bug that prevents you from authenticating in your gateway. Properly sharing sessions between the auth server and the gateway might fix that, but it might even be better if they are separate anyway (which we know works fine). There is always a security risk with sharing session data, but you can make rational decisions about that. If two processes are part of the same app logically and you control them both, then it's not completely crazy to share a session between them. But on the other hand, since the only thing I would store in the session is security data (like an access token for instance), there isn't necessarily a huge benefit in doing so. Shared session data is better as a means of scaling up a single process to many of the same type IMO, not so much for creating large distributed apps. |
May I ask about the actual fix here? I am having the same exact behavior, but the oauth server does not share any session with client application. It seems that the OAuth2ClientContext preserved state is always empty when the user is redirected from the login screen. Because of that, I am getting a 401, because the request as a state, but not the context? I took a look at what is stored in redis, but the keys only shows the SPRING_SECUIRTY_SAVED_REQUEST without anything related to the state? |
I don’t think that’s the same problem then is it? Does the code from the “complete” sample work for you? If it does then there isn’t really an issue with the guide, I guess. |
Yes indeed, I just realized that when redis is configured to persist as json, it will miss some of the objects to be serialized, compared to the default jdk serialization strategy. The context being one of them. |
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to follow your double example. I'm trying to create sample where I want to have users authenticated/authorized with oauth2 and if possible session persisted in jdbc (to support basic failover in replicated application).
Instead of working with cookie, I'd like to work with http headers only. My current issue is that when I get to gateway at localhost:8080/login, what will forward me to uaa service at localhost:8080/uaa/login will generate another csrf token and after successful login it complains about the token found in header which is basically the token from gateway.
Many thanks
The text was updated successfully, but these errors were encountered: