-
Notifications
You must be signed in to change notification settings - Fork 272
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
Enforce JWT expiration for subscriptions #4166
Conversation
If a JWT expires whilst a subscription is executing, the subscription should be terminated. fixes: #3947
This comment has been minimized.
This comment has been minimized.
CI performance tests
|
Try just filtering out the response
Now simply map the response and check for expired JWT tokens.
More efficient that way.
We've already verified that our claim: - exists - is a number This last change ensures that if we can't create a valid DateTime values from our timestamp then we log an error and continue as though we didn't have an expiry date.
cc @martinbonnin @alessbell @calvincestari in case you would like to do something specific in your client with that error code |
let stream = | ||
stream | ||
.map(move |mut response: Response| { | ||
// Enforce JWT expiry for deferred and subscription responses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could it be enforced on the request side, before executing the subscription?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes good catch ! I think you can move your logic right here gary to not try to fetch data from subgraphs if your jwt is expired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've split the logic for enforcement and now enforce subscription expiration in the request as @bnjjj suggested. I've left the defer enforcement in the response. We could remove that I suppose, but it's probably better to have it than not.
Don't use chrono to measure elapsed time.
Now check for subscription expiration in the request processing.
Use sleep, not timeout_at.
As per code review suggestion.
If a JWT expires whilst a subscription is executing, the subscription should be terminated.
fixes: #3947
Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
Exceptions
It's tricky to automatically test token expiration, so I've tested this feature manually. I used:
https://www.unixtimestamp.com/
https://jwt.io/
to generate timestamps and then JWT tokens using those timestamps as
exp
claims.I ran a router configured to support JWT authn and subscription and then subscribed to a feed using
curl
and ensured my subscription timed out. Sample output snippet:Notes
Footnotes
It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. ↩
Configuration is an important part of many changes. Where applicable please try to document configuration examples. ↩
Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. ↩