Jwt for secure inbound and outbound communication#321
Conversation
|
Note: jwt dependencies needs to be added to the wildfly modules |
|
Looking good! I'll play with it a bit tonight or tomorrow, and if possible see if there's any feedback to provide. |
|
I'm looking at the PR a little and I wonder what the use of JwtAuthFilter is. It parses the incoming JWT token using SmallRye JWT. Isn't this however more of a task for the existing MP JWT implementation to do? (which happens to be SmallRye JWT again for WildFly and Quarkus). Would it not be better to omit JwtAuthFilter, and annotate or programmatically protect the coordinator methods with roles? Or am I missing something? |
Likewise, MP JWT already captures the inbound token. For a similar project I just did something like: public class MyFilter implements ClientRequestFilter {
@Inject
JsonWebToken jwtToken;
public void filter(ClientRequestContext context) {
String rawToken = jwtToken.getRawToken();
// [check empty ...]
context.getHeaders()
.putSingle("Authorization", "Bearer " + token)l
}
} |
Good point, JwtAuthFilter was initially intended for a standalone jar without a MP JWT runtime but I see what you mean. I will use the roles as you suggested and remove the JwtAuthFilter. Thanks |
Yes, I wanted to Inject the token but I thought that for registered filters would have been harder to make it work. Let me have another try and see if I can make it work as in your example. |
|
I think the shift in the PR would be to implement the JWT secure inbound connection relying to the container's (WildFly, Quarkus or else) mp jwt implementation. I believe this is the right approach as it avoids duplication and gives more flexibility (the container chooses the mp jwt implementation) but it is less consistent with the outbound connection which is managed by lra coordinator instead (I need to document it). I will add integration tests with arquillian/WildFly to test the secured inbound connections. |
4a5d1c1 to
facbdb7
Compare
|
@arjantijms I have addressed your comments and refined the PR. Could I ask you another review? |
Thanks! I'll check it out tonight! (I'm currently busy with a somewhat related task; JWT authentication in Jakarta Security ;)) |
|
Note: |
|
Sorry for the long delay in getting back to this. I finally was able to play with the code a bit, and test it in a small application. I found a few things:
Given the above, it may be good to
|
Thank you for your useful observations! I will surely update the PR to include your suggestions. The only point I am not sure about is: |
Yes, true. The expiration should be taken into account. Maybe we should not go for a re-request (with the refresh token). The documentation should simply say that the lifetime of the LRA and the token should match in this case. The Additionally, storing the token on disk (the ObjectStore) may be an additional risk compared to just storing it in memory. Of course a process memory space can be read too by an attacker who gets access to the system, but it's a thing to be aware of. Probably the idea of storing the token with the LRA is better left out of this PR and we could consider it as an opt-in (with system token fallback) for a future PR. |
| * </p> | ||
| */ | ||
| @Target({ ElementType.METHOD, ElementType.TYPE }) | ||
| @Retention(RetentionPolicy.RUNTIME) |
There was a problem hiding this comment.
This annotation is something that can be considered, in the future, to be proposed to be integrated in the LRA annotation defined in the MP LRA spec, e.g. @PropagateToken → @LRA(propagateToken=true)
client filter and thread classLoader for providers
centralize (in service-base) the client filter logic used in client and server filter
mmusgrov
left a comment
There was a problem hiding this comment.
I am by no means an expert in JWT but the changes look reasonable and I defer to Arjan's review for the expert analysis.
It would be nice to see the coordinator markdown doc included in the LRA documentation - asciidoc has an include directive that can be used to achieve that.
I did not fully understand section 6.4 (Recovery Thread and Service Token) so it would be useful if we can follow up on the recovery tests (ServiceTokenProviderTest) with quickstart that demonstrates how to do it from the participants point of view.
Thanks @arjantijms for providing your review.
| @@ -0,0 +1,180 @@ | |||
| # LRA Security | |||
There was a problem hiding this comment.
This would be useful to have in the docs. It can be included in the top level doc by adding the following to docs/src/main/asciidoc/index.adoc:
include::../../../../coordinator/docs/security.md[]
A more brittle solution would be to create a symlink in the docs dir:
ln -s ../../../../coordinator/docs/security.md security.md
Remark: the resulting markdown tables do not render cleanly in the final asciidoc.
There was a problem hiding this comment.
Good point Mike, I am thinking of creating a doc folder to store these kind of documentation files. I will update the PR with the current location of that doc.
Thanks Mike, a quickstart is surely useful. The token can be passed by the client and forwarded, but for the Reaper thread the token must be generated by the coordinator itself (as the reaper thread runs periodically without a client request). |
Like you say the coordinator needs to call the participants during recovery but I did not fully understand section 6.4 and how it obtain the clients' token? |
The client Token is obtained from the ClientRequestContext: see https://github.com/jbosstm/lra/pull/321/changes#diff-f1593b1349b91adc0202797accc074b3d3a592c9902a13db261ef4dcd5f108a9R39 It is quite similar to what the ServerLRAFilter does here: |
addresses #314
When JWT is enabled:
cc @arjantijms
jbosstm/jboss-as#102