-
Notifications
You must be signed in to change notification settings - Fork 0
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 permission control service for saved objects and workspace saved objects client wrapper #230
add permission control service for saved objects and workspace saved objects client wrapper #230
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## workspace-pr-integr #230 +/- ##
=======================================================
+ Coverage 66.96% 66.99% +0.02%
=======================================================
Files 3323 3325 +2
Lines 64208 64439 +231
Branches 10309 10382 +73
=======================================================
+ Hits 42998 43168 +170
- Misses 18687 18730 +43
- Partials 2523 2541 +18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
0cb02db
to
98d21a6
Compare
...kspace/server/saved_objects/integration_tests/workspace_saved_objects_client_wrapper.test.ts
Outdated
Show resolved
Hide resolved
8ff9e88
to
1a52b29
Compare
ee72f38
to
7db84d9
Compare
savedObjects: SavedObjectsBulkGetObject[] | ||
): Promise<Record<string, TransformedPermission>> { | ||
const detailedSavedObjects = await this.bulkGetSavedObjects(request, savedObjects); | ||
return detailedSavedObjects.reduce((total, current) => { |
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 still need to check user's permissions to savedObjects
before returning the results, isn't it?
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 function is for get the principals of specific object. It's a part of permission validation. Since we do the permission validation in the server side. We need to get the principals of specific object without check user's permission. This function should not expose to the frontend. This function was only be used in ${WORKSPACES_API_BASE_URL}/principals
, I think we can remove it.
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.
I see, if there is no clear use case, I suggest to remove it.
* It means OSD can not recognize who the user is even if authentication is enabled, | ||
* use a fake user that won't be granted permission explicitly. | ||
*/ | ||
payload[PrincipalType.Users] = [`_user_fake_${Date.now()}_`]; |
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.
Is there an example of when authentication is enabled but OSD can not recognize who the user is?
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.
@SuZhou-Joe Could you help me elaborate more that part?
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.
There are three auth status, unknown(no authentication), noauthenticated(authN fail) and authenticated(authN success). I do not know how we can reproduce the case for noauthenticated(as before we handle the unauthenticated request user will be redirect to login page) but I have to write specific if/else to handle according to the interface. Change the comment and please find the latest change in wanglam#4
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Show resolved
Hide resolved
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
* The params here will be combined with bool clause and is used for filtering with ACL structure. | ||
*/ | ||
ACLSearchParams?: { | ||
workspaces?: string[]; |
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.
Cannot really remember the difference of ACLSearchParams.workspaces
vs SavedObjectsFindOptions.workspaces
, could you help me to recall? :D
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.
From the code, the SavedObjectsFindOptions.workspaces
support pass *
to match workspaces. The ACLSearchParams.workspaces
doesn't support that. @SuZhou-Joe Could we remove the ACLSearchParams.workspaces
? It's a little bit confused.
The SavedObjectsFindOptions.workspaces
support *
to match all workspaces. It's using 'and' operator when generate search dsl. Here is the code.
The ACLSearchParams.workspaces
doesn't support *
to match all workspaces. It's using 'or' operator with permission modes and principals, which means used to find all permitted saved objects.
They are the differences in the repository part.
In the WorkspaceSavedObjectClientWrapper
, the ACLSearchParams.workspaces will be set to all permitted
workspaces, if no workspaces
passed. It will always return saved objects inner permitted saved objects.
*/ | ||
options.workspaces = undefined; | ||
options.ACLSearchParams.workspaces = permittedWorkspaceIds; | ||
options.ACLSearchParams.permissionModes = options.ACLSearchParams.permissionModes ?? [ |
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 options.ACLSearchParams.permissionModes
be an empty array []
? What's the consequence when permissionModes = []
is passed in options?
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.
For now, it can be an an empty array. If empty array passed, I think it will return all the results. @SuZhou-Joe Shall we add an empty array check when generate search dsl function?
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.
Discussed with @wanglam offline, just for transparency, when listing workspaces, passing empty array makes it to return all workspaces including those workspaces that the current user doesn't have access to.
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, add fail fast check in generate search dsl function. https://github.com/wanglam/OpenSearch-Dashboards/pull/4/files#diff-428b7d9ca0d879eea511a66eec222df247a1fe9ff32e13feb7ab53677b6ff044
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts
Outdated
Show resolved
Hide resolved
@ruanyl I've addressed all the comments and add an unit test for workspace saved objects client wrapper. Would you like to help me review it again? |
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: tygao <tygao@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
633f9b8
to
6e28b92
Compare
* support disable permission check for workspace Signed-off-by: Hailong Cui <ihailong@amazon.com> * fix typos Signed-off-by: Hailong Cui <ihailong@amazon.com> --------- Signed-off-by: Hailong Cui <ihailong@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
* feat: add workspace into includeHiddenTypes of client wrapper and permission control client Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * fix: hiddenType side effect Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
* feat: address concerns on ensureRawRequest Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: add check for empty array Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: make find api backward compatible Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: remove useless code Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
786de38
to
6386883
Compare
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.
Great work! Thanks for keeping polishing the code based the comments and discussions, it looks good to me now 👍
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
…objects client wrapper (#230) * feat: add basic workspace saved objects client wrapper Signed-off-by: Lin Wang <wonglam@amazon.com> * feat: add unit test (#2) Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: update client wrapper Signed-off-by: tygao <tygao@amazon.com> * feat: init permission control in workspace plugin Signed-off-by: Lin Wang <wonglam@amazon.com> * Support disable permission check on workspace (#228) * support disable permission check for workspace Signed-off-by: Hailong Cui <ihailong@amazon.com> * fix typos Signed-off-by: Hailong Cui <ihailong@amazon.com> --------- Signed-off-by: Hailong Cui <ihailong@amazon.com> * feat: add ACLSearchParams consumer in repository (#3) Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * fix: ACLSearchParams missing in search dsl Signed-off-by: Lin Wang <wonglam@amazon.com> * test: add integration test for workspace saved objects client wrapper Signed-off-by: Lin Wang <wonglam@amazon.com> * style: add empty line under license Signed-off-by: Lin Wang <wonglam@amazon.com> * test: enable workspace permission control for integration tests Signed-off-by: Lin Wang <wonglam@amazon.com> * feat: add workspace into includeHiddenTypes (#249) * feat: add workspace into includeHiddenTypes of client wrapper and permission control client Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * fix: hiddenType side effect Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * fix workspace client wrapper integration tests Signed-off-by: Lin Wang <wonglam@amazon.com> * add permissions fields to workspace CRUD APIs Signed-off-by: Lin Wang <wonglam@amazon.com> * Move WorkspacePermissionMode inside workspace plugin Signed-off-by: Lin Wang <wonglam@amazon.com> * Address pr comments Signed-off-by: Lin Wang <wonglam@amazon.com> * Remove ACLSearchParams in public SavedObjectsFindOptions Signed-off-by: Lin Wang <wonglam@amazon.com> * Remove lodash and Add default permissionModes Signed-off-by: Lin Wang <wonglam@amazon.com> * feat: address concerns on ensureRawRequest (#4) * feat: address concerns on ensureRawRequest Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: add check for empty array Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: make find api backward compatible Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: remove useless code Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * Update annotations and error Signed-off-by: Lin Wang <wonglam@amazon.com> * Add unit tests for worksapce saved objects client wrapper Signed-off-by: Lin Wang <wonglam@amazon.com> * Remove getPrincipalsOfObjects in permission Signed-off-by: Lin Wang <wonglam@amazon.com> * Fix permissionEnabled flag missed in workspace plugin setup test Signed-off-by: Lin Wang <wonglam@amazon.com> * Change back to Not Authorized error Signed-off-by: Lin Wang <wonglam@amazon.com> * Fix unit tests for query_params and plugin setup Signed-off-by: Lin Wang <wonglam@amazon.com> * Fix unittests in workspace server utils Signed-off-by: Lin Wang <wonglam@amazon.com> * feat: add workspacesSearchOperators to decouple ACLSearchParams Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: update test cases Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: optimize test cases Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: optimize comment Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: omit defaultSearchOperator in public savedobjetcs client Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: omit workspacesSearchOperator field Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: Lin Wang <wonglam@amazon.com> Signed-off-by: SuZhou-Joe <suzhou@amazon.com> Signed-off-by: tygao <tygao@amazon.com> Signed-off-by: Hailong Cui <ihailong@amazon.com> Co-authored-by: Lin Wang <wonglam@amazon.com> Co-authored-by: SuZhou-Joe <suzhou@amazon.com> Co-authored-by: Hailong Cui <ihailong@amazon.com>
Description
Testing the changes
Check List
yarn test:jest
yarn test:jest_integration
yarn test:ftr