-
Notifications
You must be signed in to change notification settings - Fork 0
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
Review and Feedback #1
Comments
Look into and see if Wso2 implements the JSON Web Key spec. If it does, then you can leverage the |
Addresses one of the feedbacks from #1
Hi @jgrandja - Appreciate your valuable feedback. I have incorporated one of the suggestions already and I have a question for the other.
Thanks again for helping. |
You don't need a custom Your custom As far as defining the auth rules...if you define them at the endpoints using
Here are some resources that you can read on how Authorization is implemented in Spring Security: http://docs.spring.io/spring-security/site/docs/5.0.0.M2/reference/htmlsingle/#jc-authorize-requests |
Hmm, I just want to mention that we also use a Thank you so much for explaining the differences between method security versus the web security. The examples are so handy and useful ! We will use the I have another question, which is slightly off topic but if you can give any sort of advise from your experience, that would be awesome. In our applications we deal with a lot of service to service calls. Calls come from internet into one service which call another service and that would in turn call others and so on. All the services would need to share a particular request context and behave in a uniform manner (OAuth2, i18N, A/B testing profile etc). In our legacy system we achieve this using headers, and we establish the context by propagation/relay of these headers across the services. When we move to a cloud native platform, what might be an efficient way to achieve this, other than having to rely on some custom code to propagate these custom headers across ? Since this situation is not specifically related to security, it is not clean to use JWT as a carrier for all of these information either. Do you have any advise on this ? |
Yes, if the reference token is contained in a Cookie then you would use Having each Agreed that JWT is not meant to be used to propogate request context information so I don't suggest that approach. What I have seen on a number of occasions is a combination of a distributed cache that synchronizes with a local cache to the service. Each service has a local cache that is synchronized from the remote distributed cache. The local cache promotes latency since the service will get data from the local cache rather then making a network call to the distributed cache. However, there may be cache misses at times which at point a network call will happen but the goal is to prevent these network calls to the distributed cache in most cases. It's a matter of setting up caches in an efficient manner. There is a lot more to talk about with this type of design within the overall architecture but at least it's something to go on. I would suggest reaching out to the Platform Architect on the account as I'm sure they will be able to advise further on this. |
@jgrandja - Thank you for the review and feedback. I think we are at a good spot now and feel a lot comfortable. I will reach back again if there are any questions. Regarding the request context propagation, if you are using some cache are you implying something like a session store ? and the session id be getting propagated ? |
btw, the customization for Please check the code spring-security-oauth/OAuth2AuthenticationManager.java#L103 where you would see the This cause the opaque token to be relayed, rather than the inferred JWT. Since the OAuth2RestTemplate and Feign uses |
@jgrandja - any suggestions on the above finding ? |
Interesting - regarding the Boot auto-config The best way around this is to ensure this auto-config class doesn't kick in. This means if you have configured
Regarding the request context propagation, no I wasn't suggesting a session store or session id propagation. I'm specifically talking about a |
It seems |
@jgrandja - do you have any suggestions ? If I use Check OAuth2RestOperationsConfiguration.SessionScopedConfiguration and OAuth2ClientConfiguration Due to the above set up, if I make a call outbound with an Check OAuth2RestTemplate and OAuth2FeignRequestInterceptor For example, the call stack for
Note - If I don't have the Check OAuth2RestOperationsConfiguration.RequestScopedConfiguration |
Yes, the I'm not familiar with the Feign client but the best place to have questions answered time efficiently is via Gitter and by joining the appropriate room, for example, the Spring Cloud room. |
Hi @jgrandja, thank you for the feedback.
This is the catch, I am not seeing this behavior. The behavior it induces on |
Hi Karthik,
Instead of providing a specialized version of
BearerTokenExtractor
that does the swap of opaque to Jwt token, I would recommend supplying a customResourceServerTokenServices
that would encapsulate all that logic you currently have inBearerTokenExtractor
.The responsibility of a
ResourceServerTokenServices
is to convert/translate theString
representation of a token to either aOAuth2Authentication
or anOAuth2AccessToken
.So in
ResourceServerConfig.configure(ResourceServerSecurityConfigurer)
configure thisResourceServerSecurityConfigurer.tokenServices(customResourceServerTokenServices)
.NOTE: Your custom implementation of
ResourceServerTokenServices
would need a reference toJwtTokenStore
so it knows how to convert a Jwt token to aOAuth2Authentication
or anOAuth2AccessToken
.If you want to dig deeper in the stack to understand how the request flows, here is the sequence:
OAuth2AuthenticationProcessingFilter
gets called first.OAuth2AuthenticationProcessingFilter
uses the defaultTokenExtractor
(BearerTokenExtractor
) to get the token from theAuthorization
header and return it in aPreAuthenticatedAuthenticationToken
.OAuth2AuthenticationManager.authenticate()
is then called passing in thePreAuthenticatedAuthenticationToken
.OAuth2AuthenticationManager
will leverage theResourceServerTokenServices
you configured viaResourceServerSecurityConfigurer.tokenServices(customResourceServerTokenServices)
.ResourceServerTokenServices
will convert the Jwt token to anOAuth2Authentication
viaOAuth2Authentication loadAuthentication(String accessToken)
. This is where theJwtTokenStore.readAuthentication(String)
will get leveraged for the translation. If the token is opaque/reference then call the identity service to swap for the Jwt and continue with the flow as above using theJwtTokenStore
for translation.Take a look at
RemoteTokenServices
which implementsResourceServerTokenServices
. This might be of use for you.The other thing I noticed is the use of
@PreAuthorize
on your Rest endpoints:@PreAuthorize
is typically used for method level security beyond the web-tier, specifically, the service or data tier.For the web tier, you would configure your authorization rules as follows:
The text was updated successfully, but these errors were encountered: