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

Replace hs-jose with jose-jwt #3598

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

wolfgangwalther
Copy link
Member

hs-jose depends heavily on Template Haskell, but jose-jwt does not - one more step towards cross-compiling.

The new jose-jwt does not do more than the basic JWT verification for us - i.e. it checks the key and signature, but does not check exp, aud, iat and nbf values. Thus, we have to do those ourself. I added some tests to confirm the previous behavior first, then made sure the refactor returns the same kind of error messages. Some of those could certainly be improved, because they have only been showing hs-jose's JWTError types. Not here, though.

One "problem" remains: Two tests regarding the JWT cache were failing after this, because... parsing JWTs just became too fast. Thus the assumption assert (first_dur - second_dur) > 0.3 just didn't hold anymore. I tried rewriting those tests to use relative numbers, but now I have a different test failing: test_server_timing_jwt_should_not_decrease_when_caching_disabled. I could just revert the change to that test and call it a day... but I'd like to first discuss how much sense this test actually makes.


Some test results from postgrest-loadtest. Straight away on main it has a throughput of 551 req/s for me. Of course, that doesn't say much, because the loadtest does not use any JWT anyway. So I added a very basic token, with empty payload, to all loadtests and then ran the loadtest again with and without cache on both main and this branch.

branch without cache with cache
main 535 req/s 552 req/s
replace-jose 545 req/s 552 req/s

Clearly JWT parsing performance has improved. Note that this is for the most minimal JWT you can assume, so no payload/claims at all. Performance for bigger JWT is probably dominated by performance of JSON parsing, not sure though.

@wolfgangwalther wolfgangwalther force-pushed the replace-jose branch 2 times, most recently from a1c15b1 to e5d0951 Compare June 16, 2024 16:35
Copy link
Member

@steve-chavez steve-chavez left a comment

Choose a reason for hiding this comment

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

parsing JWTs just became too fast.

Sounds good! Lighter dependencies are always better.

@wolfgangwalther wolfgangwalther force-pushed the replace-jose branch 2 times, most recently from 7633239 to d9aadb3 Compare June 16, 2024 19:48
@wolfgangwalther
Copy link
Member Author

One thing that jose-jwt also supports: JWE, so encrypted tokens. We currently only do JWS, so signed tokens. Could be an extensions for the future.

Timing dependent tests in the IO tests don't work too well when the next
commit increases the JWT parsing performance.

The remaining IO tests are for coverage and basic breakage. Loadtests
are adapted so that performance regressions for JWT caching would be
detected that way.
This removes one more dependency on Template Haskell.
@wolfgangwalther wolfgangwalther merged commit 465170c into PostgREST:main Jun 17, 2024
21 checks passed
@wolfgangwalther wolfgangwalther deleted the replace-jose branch June 17, 2024 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants