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

Cookie compression and splitting for JWT #1651

Merged

Conversation

jochen-kressin
Copy link
Contributor

@jochen-kressin jochen-kressin commented Nov 14, 2023

Description

This PR will port the cookie compression and splitting behaviour as implemented already for OIDC and SAML to also be used for the JWT authentication type.
This is done to support token payloads that are too large to store in a single cookie.

Category

Enhancement

Why these changes are required?

When the user authenticates with a JWT, the token is stored in a cookie. However, if the JWT is too large to store in a single cookie, the authentication will fail. To remedy this, we implemented the same approach as we've previously done for SAML and OpenId: compression and cookie splitting.

What is the old behavior before changes and new behavior after changes?

The old behaviour was that large JWTs would cause the authentication to fail. Now, we support larger tokens by splitting it up in multiple cookies, the number of which can be defined in the configuration.

For end users that are already authenticated, existing cookies should continue to work.

Issues Resolved

#1638

Testing

[Please provide details of testing done: unit testing, integration testing and manual testing]
Manual testing:
I've tested with large JWTs, and I've tested that having an existing cookie still works after the splitting was implemented.
I did start testing multi auth, but then quickly noticed that JWT isn't supported in multi auth

Unit tests:
I had to edit the existing JWT unit tests a bit. I did not change any logic, but only extended certain "mocks" with properties required by the new implementation.

Integration tests:
Since there already were Selenium tests for JWT, I stuck with that and added a test with a JWT that is too large for one cookie.

Additional notes

Even though we now support large tokens in the cookies, the user may still run into a problem with a "Too long http header exception".

{"statusCode":401,"error":"Unauthorized","message":"[too_long_http_header_exception] HTTP header is larger than 8192 bytes."}

This can however be configured in opensearch.yml, e.g. with http.max_header_size: 16kb
I have not investigated if this change has any negative side effects.

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@jochen-kressin
Copy link
Contributor Author

Sorry for the review requests all - I meant to submit this as a draft. The draft status should be correct now.

@jochen-kressin jochen-kressin force-pushed the cookie-splitting-for-jwt branch 2 times, most recently from 034db8c to ce5b30e Compare December 11, 2023 15:19
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
…mports

Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Copy link

codecov bot commented Dec 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d64ee48) 67.09% compared to head (9f51173) 67.09%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1651   +/-   ##
=======================================
  Coverage   67.09%   67.09%           
=======================================
  Files          94       94           
  Lines        2404     2404           
  Branches      318      318           
=======================================
  Hits         1613     1613           
  Misses        713      713           
  Partials       78       78           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jochen-kressin
Copy link
Contributor Author

Another thing I found while testing this was that the logout doesn't work for JWT.
I believe it is just the logout path that is wrong in the JWT routes file.
Didn't want to update it in the scope of this issue, in case there are any edge cases I don't know about.
But feel free to ping me if you want me to change it in this PR.

@jochen-kressin jochen-kressin marked this pull request as ready for review December 12, 2023 13:13
@jochen-kressin jochen-kressin changed the title DRAFT: Cookie compression and splitting for JWT Cookie compression and splitting for JWT Dec 12, 2023
@stephen-crawford
Copy link
Contributor

Hi @jochen-kressin, for the logout issue--do you think you could open an issue or separate PR to fix it? Thank you!

@cwperks
Copy link
Member

cwperks commented Dec 18, 2023

Thank you for this PR @jochen-kressin! While I was reviewing this issue I noticed it happened because the token was too large. This PR should fix that.

cwperks
cwperks previously approved these changes Dec 18, 2023
@jochen-kressin
Copy link
Contributor Author

Hi @jochen-kressin, for the logout issue--do you think you could open an issue or separate PR to fix it? Thank you!

@cwperks Will do! While testing I also noticed that the SAML logout throws an error. Will check again if I configured something wrong, otherwise I'll add an issue for that as well.

Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
@jochen-kressin
Copy link
Contributor Author

While adding the logout issue, I realized I had forgotten something related to this issue.
Just as for SAML and OIDC, we should clear the split cookies when logging out. I've added that now.

I added #1710 for the logout issue. I considered fixing the issue within this PR, but then thought it best to keep it separate so that we can get this PR merged.

The SAML logout issue I mentioned: I believe that was a misconfiguration on my part, so I'm not adding an issue for that.
The issue I had was that the IdP would redirect back to the logout route after I was already logged out, resulting in a 401 error. But that redirect is configurable with the IdP, so I just updated it there.

Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
@cwperks cwperks added the backport 2.x backport to 2.x branch label Jan 4, 2024
@peternied peternied merged commit 7cad47c into opensearch-project:main Jan 4, 2024
12 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 4, 2024
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
(cherry picked from commit 7cad47c)
cwperks pushed a commit that referenced this pull request Jan 4, 2024
Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
(cherry picked from commit 7cad47c)

Co-authored-by: Jochen Kressin <126353411+jochen-kressin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants