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

fix(opensearch): show search results only if user has access permission to the index #5097

Merged
merged 11 commits into from
Jun 27, 2024

Conversation

tsdk02
Copy link
Contributor

@tsdk02 tsdk02 commented Jun 24, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

/search and /search/{domain} are currently checking for analytics ACL before hitting opensearch and returning results.

Additionally we have to check access permissions per index:

  • payment attempts/intents => PaymentRead | PaymentWrite
  • refunds => RefundRead | RefundWrite
  • disputes => DisputeRead | DisputeWrite

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Checking access permissions to an index for a user is necessary to show results appropriately.

How did you test it?

  • Open the dashboard locally and hit the get_global_search_results API through the global search feature (command+k).
  • Search using a query (eg: USD), to get the results corresponding to respective indexes (if user has access permission)
  • Evaluate and verify the results

Screenshot 2024-06-24 at 2 09 09 PM

Screenshot 2024-06-25 at 11 26 25 PM

Screenshot 2024-06-24 at 2 09 42 PM

Screenshot 2024-06-25 at 11 26 44 PM

Alternatively, it can also be verified through Postman:

  • Hit the /search and /search/{domain} API's to retrieve the data
Screenshot 2024-06-24 at 1 45 52 PM Screenshot 2024-06-24 at 2 16 30 PM

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@tsdk02 tsdk02 requested review from lsampras and ivor11 June 24, 2024 09:40
@tsdk02 tsdk02 self-assigned this Jun 24, 2024
@tsdk02 tsdk02 requested review from a team as code owners June 24, 2024 09:40
lsampras
lsampras previously approved these changes Jun 24, 2024
Copy link
Member

@lsampras lsampras left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link
Member

Choose a reason for hiding this comment

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

@racnan Can you verify this file changes

lsampras
lsampras previously approved these changes Jun 25, 2024
.change_context(UserErrors::InternalServerError)
.change_context(OpenSearchError::UnknownError)?;
let permissions = role_info.get_permissions_set();
let accessible_indexes: Vec<_> = vec![
Copy link
Contributor

Choose a reason for hiding this comment

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

can this permission vector be kept in a common place for both global_search and index_search?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, moved it to a consts file.

analytics::search::msearch_results(
&state.opensearch_client,
req,
&auth.merchant_account.merchant_id,
&auth.merchant_id,
accessible_indexes,
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens when user has neither of the permissions? accessible_indexes = vec![]?, will msearch run on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved this by changing the OpenMserchOutput struct to handle cases when the user has none of the permissions to access indexes.

Copy link
Contributor

Choose a reason for hiding this comment

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

can you share the the output of this test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-06-26 at 1 50 44 PM
Screenshot 2024-06-26 at 1 50 08 PM

@tsdk02 tsdk02 requested review from a team as code owners June 25, 2024 14:16
@tsdk02 tsdk02 force-pushed the show-results-user-access branch from eef82cf to b5e7678 Compare June 25, 2024 16:42
lsampras
lsampras previously approved these changes Jun 26, 2024
.ok_or(OpenSearchError::IndexAccessNotPermittedError(index))?;
analytics::search::search_results(&state.opensearch_client, req, &auth.merchant_id)
.await
.map(ApplicationResponse::Json)
},
&auth::JWTAuth(Permission::Analytics),
Copy link
Contributor

Choose a reason for hiding this comment

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

is Analytics permission also required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed with @lsampras and he suggested to check the Analytics Permission also as of now

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jun 27, 2024
Merged via the queue into main with commit 9c49ded Jun 27, 2024
11 checks passed
@Gnanasundari24 Gnanasundari24 deleted the show-results-user-access branch June 27, 2024 07:51
pixincreate added a commit that referenced this pull request Jun 28, 2024
…ay/hyperswitch into iatapay-through-hyperswitch-cypress

* 'iatapay-through-hyperswitch-cypress' of github.com:juspay/hyperswitch:
  feat(router): skip apple pay session call if the browser is not Safari (#5136)
  fix(opensearch): show search results only if user has access permission to the index  (#5097)
  chore(version): 2024.06.27.0
  feat(users): add endpoint for terminate auth select (#5135)
  feat(users): implemented openidconnect (#5124)
  feat(router): add payments manual-update api (#5045)
  fix(docs): open-api fix for payment response (#5103)
  refactor(connector): [AdyenPlatform]Throw 4xx instead of 5xx for source_balance_account (#4990)
  feat: realtime user analytics (#5098)
  refactor(connector): added amount conversion framework for cashtocode (#4857)
  feat(email): Add `auth_id` in email types and send `auth_id` in email URLs (#5120)
  refactor(connector): add amount framework to payme & Trustpay with googlePay, ApplePay for bluesnap, Noon & Trustpay (#4833)
  fix(connector): [BOA/CYBS] make risk information message optional (#5107)
  chore(version): 2024.06.25.1
  fix(router): skip serialize if none for assurance_details_required in googlepay session response (#5118)
  refactor: separate DB queries and HTML creation for payout links (#4967)
  feat(router): updated `last_used_at` field for apple pay and google pay for CITs (#5087)
  fix(payment_methods): use existing field value of `nick_name` in db if not sent during request (#5105)
  chore(version): 2024.06.25.0
pixincreate added a commit that referenced this pull request Jun 28, 2024
…ay/hyperswitch into refactor-error-handling-in-cypress

* 'iatapay-through-hyperswitch-cypress' of github.com:juspay/hyperswitch:
  chore: clean up
  feat(router): skip apple pay session call if the browser is not Safari (#5136)
  fix(opensearch): show search results only if user has access permission to the index  (#5097)
  chore(version): 2024.06.27.0
  feat(users): add endpoint for terminate auth select (#5135)
  feat(users): implemented openidconnect (#5124)
  feat(router): add payments manual-update api (#5045)
  fix(docs): open-api fix for payment response (#5103)
  refactor(connector): [AdyenPlatform]Throw 4xx instead of 5xx for source_balance_account (#4990)
  feat: realtime user analytics (#5098)
  refactor(connector): added amount conversion framework for cashtocode (#4857)
  feat(email): Add `auth_id` in email types and send `auth_id` in email URLs (#5120)
  refactor(connector): add amount framework to payme & Trustpay with googlePay, ApplePay for bluesnap, Noon & Trustpay (#4833)
  fix(connector): [BOA/CYBS] make risk information message optional (#5107)
  chore(version): 2024.06.25.1
  fix(router): skip serialize if none for assurance_details_required in googlepay session response (#5118)
  refactor: separate DB queries and HTML creation for payout links (#4967)
  feat(router): updated `last_used_at` field for apple pay and google pay for CITs (#5087)
  fix(payment_methods): use existing field value of `nick_name` in db if not sent during request (#5105)
  chore(version): 2024.06.25.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix(opensearch): show search results only if user has access to the index
5 participants