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

[workspace] refactor: refactor the bulk_get handler in permission wrapper when item has permission error #8906

Merged

Conversation

Qxisylolo
Copy link
Contributor

@Qxisylolo Qxisylolo commented Nov 21, 2024

Description

This pr fixes index pattern fetch error in discover dataset modal by return response with error instead of throwing an error

Screenshot

before:
before

after:
截屏2024-11-21 14 50 09

Testing the changes

Changelog

  • feat: refactor the bulk_get handler in permission wrapper when item has permission error

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

opensearch-changeset-bot bot added a commit to Qxisylolo/OpenSearch-Dashboards that referenced this pull request Nov 21, 2024
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.95%. Comparing base (5f91e37) to head (12f1594).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
..._objects/workspace_saved_objects_client_wrapper.ts 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8906      +/-   ##
==========================================
+ Coverage   60.91%   60.95%   +0.03%     
==========================================
  Files        3808     3809       +1     
  Lines       91196    91275      +79     
  Branches    14400    14414      +14     
==========================================
+ Hits        55556    55635      +79     
- Misses      32085    32086       +1     
+ Partials     3555     3554       -1     
Flag Coverage Δ
Linux_1 28.97% <81.81%> (-0.03%) ⬇️
Linux_2 56.45% <ø> (+0.06%) ⬆️
Linux_3 37.97% <ø> (?)
Linux_4 29.03% <ø> (+0.01%) ⬆️
Windows_1 29.00% <81.81%> (-0.03%) ⬇️
Windows_2 56.40% <ø> (+0.06%) ⬆️
Windows_3 37.97% <ø> (-0.05%) ⬇️
Windows_4 29.03% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@@ -0,0 +1,2 @@
fix:
- Index pattern fetch error in discover dataset modal ([#8906](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8906))
Copy link
Contributor

@raintygao raintygao Nov 21, 2024

Choose a reason for hiding this comment

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

Although this PR may could fix #8891, but this is not the direct root cause, so I would suggest to change to refactor: refactor the bulk_get handler in permission wrapper when item has permission error

Comment on lines 513 to 477
if (!hasPermission) {
ACLAuditor?.increment(ACLAuditorStateKey.VALIDATE_FAILURE, 1);
throw generateDataSourcePermissionError();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We may also don't need to throw Error for this verification.

Comment on lines 533 to 474
error: {
error: 'Invalid saved objects permission',
statusCode: 403,
message: 'Permission denied',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we extract this as a function along with other generatexxxError functions on the top of this file.

Comment on lines 544 to 547
ACLAuditor?.increment(
ACLAuditorStateKey.VALIDATE_SUCCESS,
objectToBulkGet.saved_objects.length
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This represents all verification are successful, now in the new implementation we may need a flag in the map to indicate whether all objects are passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for all the comments, updated.

@Qxisylolo Qxisylolo force-pushed the fix/index_pattern_fetch_error branch from 671af1f to 2f4dedd Compare November 22, 2024 09:22
@Qxisylolo Qxisylolo changed the title [workspace] fix: index pattern fetch error in discover dataset modal [workspace] refactor: index pattern fetch error in discover dataset modal Nov 22, 2024
opensearch-changeset-bot bot added a commit to Qxisylolo/OpenSearch-Dashboards that referenced this pull request Nov 22, 2024
@Qxisylolo Qxisylolo marked this pull request as ready for review November 22, 2024 09:26
@@ -196,6 +204,32 @@ export class WorkspaceSavedObjectsClientWrapper {
return hasPermission;
}

// Data source is a workspace level object, validate if the request has access to the data source within the requested workspace.
private validateDataSourcePermissions = (
Copy link
Member

Choose a reason for hiding this comment

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

@yubonluo Could you please check if this change is compatible with the bulkGet changes you made recently regarding permission check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, the data source validation has been moved to id_consumer_wrapper, you can delete the method from the permission_wrapper.
related PR: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8888/files#diff-6f4daf9988f5262d2403821efd458faf7157c7e7473ec65a16ae2724a92d6556L209

ruanyl
ruanyl previously approved these changes Dec 24, 2024
let flag = true;
const processedObjects = await Promise.all(
objectToBulkGet.saved_objects.map(async (object) => {
try {
Copy link
Member

@SuZhou-Joe SuZhou-Joe Dec 27, 2024

Choose a reason for hiding this comment

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

Do we have to wrap the code with a try catch? I raised the concern because it seems it won't throw error and it makes it hard to understand the code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks the comment, validateIsWorkspaceDataSourceAndConnectionObjectType is unlikely to throw an exception. I will update it.

SuZhou-Joe pushed a commit to Qxisylolo/OpenSearch-Dashboards that referenced this pull request Dec 27, 2024
@SuZhou-Joe SuZhou-Joe force-pushed the fix/index_pattern_fetch_error branch from cfb059d to 282c4fe Compare December 27, 2024 08:12
objectToBulkGet.saved_objects.map(async (object) => {
try {
if (validateIsWorkspaceDataSourceAndConnectionObjectType(object.type)) {
const hasPermission = this.validateDataSourcePermissions(
Copy link
Member

Choose a reason for hiding this comment

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

It seems we do not need to validate data source permissions in bulkGet anymore, it has been done in another wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you elaborate on which wrapper performed the validation?

Copy link
Contributor

Choose a reason for hiding this comment

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

the data source validation has been moved to id_consumer_wrapper, you can delete the method from the permission_wrapper.
related PR: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8888/files#diff-6f4daf9988f5262d2403821efd458faf7157c7e7473ec65a16ae2724a92d6556L209

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification!!

Qxisylolo and others added 9 commits December 31, 2024 11:52
Signed-off-by: Qxisylolo <[email protected]>
@ruanyl ruanyl merged commit d947bd6 into opensearch-project:main Jan 8, 2025
69 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 8, 2025
…pper when item has permission error (#8906)

* return response with error

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

* set Id

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

* resolve tests

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

* Changeset file for PR #8906 created/updated

* typo

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

* fix integration tests

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

* add try catch

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

* resolve conflicts

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

* delete data source permission

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

* add try catch

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

---------

Signed-off-by: Qxisylolo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit d947bd6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Hailong-am pushed a commit that referenced this pull request Jan 9, 2025
…pper when item has permission error (#8906) (#9156)

* return response with error



* set Id



* resolve tests



* Changeset file for PR #8906 created/updated

* typo



* fix integration tests



* add try catch



* resolve conflicts



* delete data source permission



* add try catch



---------



(cherry picked from commit d947bd6)

Signed-off-by: Qxisylolo <[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: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Jan 10, 2025
…pper when item has permission error (opensearch-project#8906)

* return response with error

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

* set Id

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

* resolve tests

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

* Changeset file for PR opensearch-project#8906 created/updated

* typo

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

* fix integration tests

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

* add try catch

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

* resolve conflicts

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

* delete data source permission

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

* add try catch

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

---------

Signed-off-by: Qxisylolo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
d-rowe pushed a commit to d-rowe/OpenSearch-Dashboards that referenced this pull request Jan 17, 2025
…pper when item has permission error (opensearch-project#8906)

* return response with error

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

* set Id

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

* resolve tests

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

* Changeset file for PR opensearch-project#8906 created/updated

* typo

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

* fix integration tests

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

* add try catch

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

* resolve conflicts

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

* delete data source permission

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

* add try catch

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

---------

Signed-off-by: Qxisylolo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants