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

Fixes saml login flow to work with anonymous auth #1839

Merged

Conversation

DarshitChanpura
Copy link
Member

@DarshitChanpura DarshitChanpura commented Mar 21, 2024

Description

This PR fixes 2 things:

  1. Anonymous login button would not show if only 1 auth option was supplied
  2. Broken SAML auth flow when anonymous auth is enabled.
  3. Automatic login as anonymous user upon SAML user logout. (Discovered while fixing this bug)

Category

  • Bug fix

Why these changes are required?

  • For SAML and anonymous auth options to function when both options are enabled
  • To prevent auto login as anonymous user upon SAML user logout

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

  • At present, SAML auth flow is broken since anonymous auth automatically assumes the Anonymous user when no auth credentials are found. See security plugin PR[1] for more details.

[1] - Companion PR: opensearch-project/security#4152

Issues Resolved

Testing

  • Automated + Manual

Manual testing:

Screen.Recording.2024-04-11.at.11.55.53.AM.mov

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.

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
…orrectly

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
…ion header

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.16%. Comparing base (64995fc) to head (4317901).

❗ Current head 4317901 differs from pull request most recent head 1ad7343. Consider uploading reports for the commit 1ad7343 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1839      +/-   ##
==========================================
- Coverage   68.25%   68.16%   -0.09%     
==========================================
  Files          94       94              
  Lines        2416     2422       +6     
  Branches      330      330              
==========================================
+ Hits         1649     1651       +2     
- Misses        689      694       +5     
+ Partials       78       77       -1     

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

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura DarshitChanpura changed the title Fixes saml login flow Fixes saml login flow to work with anonymous auth Mar 21, 2024
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
server/auth/types/basic/basic_auth.ts Outdated Show resolved Hide resolved
test/constant.ts Show resolved Hide resolved
@DarshitChanpura DarshitChanpura marked this pull request as ready for review April 9, 2024 17:05
@DarshitChanpura DarshitChanpura added the backport 2.x backport to 2.x branch label Apr 9, 2024
Copy link
Collaborator

@stephen-crawford stephen-crawford left a comment

Choose a reason for hiding this comment

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

Overall looks good, two small comments.

server/auth/types/authentication_type.ts Outdated Show resolved Hide resolved
server/auth/types/authentication_type.ts Outdated Show resolved Hide resolved
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
derek-ho
derek-ho previously approved these changes Apr 9, 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.

You are the 🐐

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Copy link
Member

@cwperks cwperks left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @DarshitChanpura!

FYI I don't think there is a way to setup Basic Auth + Anonymous without it automatically logging in as anonymous when first loading OSD. I think the issue is in auth_handler_factory.ts where even if multi-auth is enabled and only one auth_type is in the list it will create an instance of the single auth type instead of using MultipleAuthentication

@derek-ho derek-ho merged commit 681d1b1 into opensearch-project:main Apr 12, 2024
13 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 12, 2024
* Fixes anonymous auth flow to work with SAML

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds hardcoded credentials for anonymous user

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates basic auth header to be a config constant

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes unneeded usage of anonymous auth header constant

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates logic to display anonymous auth login button

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds test to check whether anonymous auth login button is displayed correctly

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes integrationtests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds integration tests for anonymous auth login with basic authorization header

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Generates random password for anonymous user

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes lint errors

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds saml auth header to differentiate saml requests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes linter errors

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes basic auth tests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes console loggers

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes lint error

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Addresses feedback

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Resolves #1840

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Replace magic value with constant

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Renames query param and removes unused variables

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Uses enum instead of magic constant

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Extracts template function to a separate util file

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Renames test

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes unnecessary modifications required to solve this bug

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes import

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes unused param

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes unused method param

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes incorrect method param

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

---------

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
(cherry picked from commit 681d1b1)
derek-ho pushed a commit that referenced this pull request Apr 12, 2024
* Fixes anonymous auth flow to work with SAML

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds hardcoded credentials for anonymous user

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates basic auth header to be a config constant

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes unneeded usage of anonymous auth header constant

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Updates logic to display anonymous auth login button

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds test to check whether anonymous auth login button is displayed correctly

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes integrationtests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds integration tests for anonymous auth login with basic authorization header

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Generates random password for anonymous user

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes lint errors

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Adds saml auth header to differentiate saml requests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes linter errors

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes basic auth tests

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes console loggers

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes lint error

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Addresses feedback

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Resolves #1840

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Replace magic value with constant

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Renames query param and removes unused variables

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Uses enum instead of magic constant

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Extracts template function to a separate util file

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Renames test

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes unnecessary modifications required to solve this bug

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Fixes import

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes unused param

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes unused method param

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

* Removes incorrect method param

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>

---------

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
(cherry picked from commit 681d1b1)

Co-authored-by: Darshit Chanpura <35282393+DarshitChanpura@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
4 participants