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

Add JWT authentication type to MultipleAuthentication #2107

Merged
merged 18 commits into from
Oct 7, 2024

Conversation

merlinz01
Copy link
Contributor

@merlinz01 merlinz01 commented Aug 28, 2024

Description

Allows JWT to be included in a multiple-authentication configuration.

Category

Enhancement

Why these changes are required?

Previously one cannot use basic auth and JWT auth together

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

OSD error when basic auth and JWT auth are configured

Issues Resolved

#1814

Testing

[Please provide details of testing done: unit testing, integration testing and manual testing]

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.

@merlinz01
Copy link
Contributor Author

merlinz01 commented Aug 29, 2024

At this point what I am seeing is that the session cookie is being lost (deleted) when the browser requests /startup.js initiated by a script tag in the response. This results in all further API calls being unauthenticated and ultimately results in an endless loop of refreshing the page.

@merlinz01
Copy link
Contributor Author

The request for /startup.js is the first request after the initial HTML is loaded, and it runs through the authentication flow that APIs use.

The logic here

if (this.authNotRequired(request)) {

decides that the request needs authenticated.

This line

this.sessionStorageFactory.asScoped(request).clear();

is then called, which deletes the auth cookie.

I assume this is not the desired behavior, and it seems like it would cause problems even without my changes.

Any input?

@merlinz01
Copy link
Contributor Author

merlinz01 commented Sep 2, 2024

OK, I think I fixed the endless loop of the page refreshing with the above commit.

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.46%. Comparing base (dc3e5a9) to head (bab1646).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2107      +/-   ##
==========================================
+ Coverage   71.40%   71.46%   +0.05%     
==========================================
  Files          97       97              
  Lines        2651     2649       -2     
  Branches      404      411       +7     
==========================================
  Hits         1893     1893              
+ Misses        642      641       -1     
+ Partials      116      115       -1     

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

cwperks
cwperks previously approved these changes Sep 10, 2024
@cwperks cwperks added backport 2.x backport to 2.x branch v2.18.0 labels Oct 1, 2024
derek-ho
derek-ho previously approved these changes Oct 2, 2024
Copy link
Collaborator

@derek-ho derek-ho left a comment

Choose a reason for hiding this comment

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

Left two minor comments, but otherwise thanks for the contribution @merlinz01 ! We can also get this merged first and follow up, since it has been a while, sorry for the delay in review

@merlinz01 merlinz01 dismissed stale reviews from derek-ho and cwperks via 529db2e October 2, 2024 17:28
cwperks
cwperks previously approved these changes Oct 4, 2024
cwperks
cwperks previously approved these changes Oct 4, 2024
@cwperks
Copy link
Member

cwperks commented Oct 4, 2024

@merlinz01 Can you check the integTest failure?

Summary of all failing tests
FAIL plugins/security-dashboards-plugin/test/jest_integration/jwt_multiauth.test.ts (5.246 s)
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  ● start OpenSearch Dashboards server › Verify JWT access to dashboards

    Response Error: 401 Unauthorized

      162 |       .setProtectedHeader({ alg: 'HS256' })
      163 |       .sign(new TextEncoder().encode('99011df6ef40e4a2cd9cd6ccb2d649e0'));
    > 164 |     await wreck.get(`http://localhost:5601/app/home?token=${adminJWT}#`, {
          |     ^
      165 |       rejectUnauthorized: true,
      166 |       headers: {
      167 |         'Content-Type': 'application/json',

      at Object.<anonymous>.internals.Client._shortcut (plugins/security-dashboards-plugin/node_modules/@hapi/wreck/lib/index.js:569:15)
      at Object.<anonymous> (plugins/security-dashboards-plugin/test/jest_integration/jwt_multiauth.test.ts:164:5)

@merlinz01
Copy link
Contributor Author

Try it now.

@cwperks
Copy link
Member

cwperks commented Oct 7, 2024

Try it now.

All CI Checks green now. Thank you @merlinz01. @derek-ho Can you review again?

Copy link
Collaborator

@derek-ho derek-ho left a comment

Choose a reason for hiding this comment

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

LGTM

@derek-ho derek-ho merged commit 252d8fb into opensearch-project:main Oct 7, 2024
19 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 7, 2024
* Add JWT authentication type to MultipleAuthentication

Signed-off-by: merlinz01 <[email protected]>

* clarify comments in AuthenticationType.authHandler

Signed-off-by: merlinz01 <[email protected]>

* collect additional auth headers from all multi-auth handlers

Signed-off-by: merlinz01 <[email protected]>

* implement MultipleAuthentication.getCookie

Signed-off-by: merlinz01 <[email protected]>

* Add test for multiauth with JWT

Signed-off-by: merlinz01 <[email protected]>

* add explanatory comments in login page

Signed-off-by: merlinz01 <[email protected]>

* remove logging of JWT in test

Signed-off-by: merlinz01 <[email protected]>

* add check for empty auth options list in login page

Signed-off-by: merlinz01 <[email protected]>

* Add comments about getCookie method

Signed-off-by: merlinz01 <[email protected]>

* remove unneeded comment

Signed-off-by: merlinz01 <[email protected]>

* Don't load sample data in JWT multiauth test

Signed-off-by: merlinz01 <[email protected]>

* remove sample data code and unneeded promise handling

Signed-off-by: merlinz01 <[email protected]>

* update test for missing JWT

Signed-off-by: merlinz01 <[email protected]>

* ensure JWT signing key consistency

Signed-off-by: merlinz01 <[email protected]>

---------

Signed-off-by: merlinz01 <[email protected]>
Co-authored-by: Derek Ho <[email protected]>
(cherry picked from commit 252d8fb)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
derek-ho added a commit that referenced this pull request Oct 7, 2024
* Add JWT authentication type to MultipleAuthentication



* clarify comments in AuthenticationType.authHandler



* collect additional auth headers from all multi-auth handlers



* implement MultipleAuthentication.getCookie



* Add test for multiauth with JWT



* add explanatory comments in login page



* remove logging of JWT in test



* add check for empty auth options list in login page



* Add comments about getCookie method



* remove unneeded comment



* Don't load sample data in JWT multiauth test



* remove sample data code and unneeded promise handling



* update test for missing JWT



* ensure JWT signing key consistency



---------



(cherry picked from commit 252d8fb)

Signed-off-by: merlinz01 <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Derek Ho <[email protected]>
@merlinz01 merlinz01 deleted the add-jwt-multiauth branch October 7, 2024 16:30
@merlinz01
Copy link
Contributor Author

Thanks for your assistance! 🎉 🚀 👍

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 v2.18.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants