Skip to content
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

Remove callback to Delta to check the token, validate it locally #4340

Merged
merged 8 commits into from
Oct 9, 2023

Conversation

imsdu
Copy link
Collaborator

@imsdu imsdu commented Oct 6, 2023

Fixes #4275

delta {
public-iri = "https://test.nexus.bbp.epfl.ch"
internal-iri = "http://delta:8080"
authorization {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't really test this part in the integration tests anymore as we need the public keys for the realm.
In the different envs, we will get notified if Delta can't interact with the storage though

shinyhappydan
shinyhappydan previously approved these changes Oct 6, 2023
Comment on lines 30 to 40
def validate(audiences: Option[NonEmptySet[String]], keySet: JWKSet): Either[InvalidAccessToken, JWTClaimsSet] = {
val proc = new DefaultJWTProcessor[SecurityContext]
val keySelector = new JWSVerificationKeySelector(JWSAlgorithm.RS256, new ImmutableJWKSet[SecurityContext](keySet))
proc.setJWSKeySelector(keySelector)
audiences.foreach { aud =>
proc.setJWTClaimsSetVerifier(new DefaultJWTClaimsVerifier(aud.toSet.asJava, null, null, null))
}
Either
.catchNonFatal(proc.process(jwtToken, null))
.leftMap(err => InvalidAccessToken(subject, issuer, err.getMessage))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm expecting there might be complication with this, but it might be better if we has a constructor that returned an already validated token? There is something about validate being a method you can optionally call which feels a bit weird. Not a big deal though since you've got testing to cover

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes from the way we do things in IdentitiesImpl, we do some surface checks first and extract the issuer to:

  • Get the matching realm and the public keys associated to it
  • Validate the token with the keys
    I will check if there is a way to improve that a bit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other thing: if we don't use the JWTClaimsSet then it's probably clearer to return Unit

Comment on lines +30 to +43
def validate(audiences: Option[NonEmptySet[String]], keySet: JWKSet): Either[InvalidAccessToken, Unit] = {
val proc = new DefaultJWTProcessor[SecurityContext]
val keySelector = new JWSVerificationKeySelector(JWSAlgorithm.RS256, new ImmutableJWKSet[SecurityContext](keySet))
proc.setJWSKeySelector(keySelector)
audiences.foreach { aud =>
proc.setJWTClaimsSetVerifier(new DefaultJWTClaimsVerifier(aud.toSet.asJava, null, null, null))
}
Either
.catchNonFatal(proc.process(jwtToken, null))
.bimap(
err => InvalidAccessToken(subject, issuer, err.getMessage),
_ => ()
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As someone unfamiliar with this process, it's not clear what an audience or keySet is. And it's not clear what about them is being validated

I think with some name changes and perhaps pulling some code into private methods this could be made really clear.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is already documented in the realm documentation:
https://bluebrainnexus.io/snapshot/docs/delta/api/realms-api.html#payload
And in the configuration file

@imsdu imsdu merged commit f480c08 into BlueBrain:master Oct 9, 2023
@imsdu imsdu deleted the 4275-remove-delta-callback branch October 9, 2023 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove/Cache the callback from storage to Delta to get the subject/realm information
3 participants