-
Notifications
You must be signed in to change notification settings - Fork 923
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
[workspace] refactor: refactor the bulk_get handler in permission wrapper when item has permission error #8906
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
changelogs/fragments/8906.yml
Outdated
@@ -0,0 +1,2 @@ | |||
fix: | |||
- Index pattern fetch error in discover dataset modal ([#8906](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8906)) |
There was a problem hiding this comment.
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
if (!hasPermission) { | ||
ACLAuditor?.increment(ACLAuditorStateKey.VALIDATE_FAILURE, 1); | ||
throw generateDataSourcePermissionError(); | ||
} |
There was a problem hiding this comment.
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.
error: { | ||
error: 'Invalid saved objects permission', | ||
statusCode: 403, | ||
message: 'Permission denied', | ||
}, |
There was a problem hiding this comment.
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.
ACLAuditor?.increment( | ||
ACLAuditorStateKey.VALIDATE_SUCCESS, | ||
objectToBulkGet.saved_objects.length | ||
); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
671af1f
to
2f4dedd
Compare
@@ -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 = ( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
let flag = true; | ||
const processedObjects = await Promise.all( | ||
objectToBulkGet.saved_objects.map(async (object) => { | ||
try { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cfb059d
to
282c4fe
Compare
objectToBulkGet.saved_objects.map(async (object) => { | ||
try { | ||
if (validateIsWorkspaceDataSourceAndConnectionObjectType(object.type)) { | ||
const hasPermission = this.validateDataSourcePermissions( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification!!
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
282c4fe
to
225c6c2
Compare
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Qxisylolo <[email protected]>
…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>
…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>
…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>
…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>
Description
This pr fixes index pattern fetch error in discover dataset modal by return response with error instead of throwing an error
Screenshot
before:
after:
Testing the changes
Changelog
Check List
yarn test:jest
yarn test:jest_integration