-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 conflict checks for sharing saved objects #168655
Conversation
…-ref HEAD~1..HEAD --fix'
Pinging @elastic/kibana-security (Team:Security) |
const match1 = buildNode('is', `${type}.id`, esKuery.escapeKuery(`${type}:${origin}`)); // here we are looking for the raw document `_id` field, which has a `type:` prefix | ||
const match2 = buildNode('is', `${type}.originId`, esKuery.escapeKuery(origin)); // here we are looking for the saved object's `originId` field, which does not have a `type:` prefix | ||
acc.push([match1, match2]); | ||
|
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.
To reviewers: there are a few ways we can structure this logic. I am not 100% set on the current implementation. Alternatively, we could have an explicit case for updateObjectsSpaces
that distinctly handles when the shared object has an origin ID, rather than relying on re-using the initial two kuery nodes. This may make it more readable. Let me know what you think.
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 code looks fine for fixing the bug.
I pulled the PR, tested locally following the instructions and it works as intended.
BTW, I couldn't reproduce the bug when using search queries to create saved queries.
...ects/core-saved-objects-api-server-internal/src/lib/apis/utils/find_shared_origin_objects.ts
Outdated
Show resolved
Hide resolved
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.
LGTM
@TinaHeiligers You could not reproduce the issue in the main branch? If the issue was being able to create a saved query, I just slightly updated the instructions. The save query option doesn't appear unless there is a "filter pill" defined. |
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.
LGTM; ++ nice comments!
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Public APIs missing exports
History
To update your PR or re-run it, just comment with: |
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.
lgtm! thanks for resolving this!
verified several scenarios of sharing and copying saved objects across spaces with users having varying levels of permissions.
Closes elastic#168049 ## Summary This PR adjusts the KQL filters when collecting references to saved objects for the purpose of updating their spaces (i.e. sharing saved objects to spaces). An additional filter is added to specifically exclude ID -> ID matches - an ID match would mean the object has already been shared to the destination space and there is no conflict. Filters to match the shared object's ID or origin ID to the destination space's objects' origin ID, and to match the shared object's origin ID to the destination space's objects' IDs remain in place to properly check for conflicts with potential copies. ### Manual Testing - Create 2 spaces: A and B - Add a sample data set (e.g. flight) to space A - In Discover, create a saved query called "s1" with a filter pill that uses the sample data logs data view - Create another saved query called "s2" with a filter pill that uses the sample data logs data view - Go to `Stack Management->Saved` Objects and share the "s1" query to space B - Now share the "s2" query to space B. From the main branch you will see that there is a conflict that disallows sharing the second query. This is because it is also attempting to share the referenced data view, which is already in space B. However, this should not be a conflict - from this PR you will be able to successfully share both queries. ### Automated Testing - packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/find_shared_origin_objects.test.ts - packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts - x-pack/test/spaces_api_integration/common/suites/get_shareable_references.ts --------- Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit 460f5e3)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…9000) # Backport This will backport the following commits from `main` to `8.11`: - [Fixes conflict checks for sharing saved objects (#168655)](#168655) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jeramy Soucy","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-10-16T16:18:19Z","message":"Fixes conflict checks for sharing saved objects (#168655)\n\nCloses #168049\r\n\r\n## Summary\r\n\r\nThis PR adjusts the KQL filters when collecting references to saved\r\nobjects for the purpose of updating their spaces (i.e. sharing saved\r\nobjects to spaces). An additional filter is added to specifically\r\nexclude ID -> ID matches - an ID match would mean the object has already\r\nbeen shared to the destination space and there is no conflict. Filters\r\nto match the shared object's ID or origin ID to the destination space's\r\nobjects' origin ID, and to match the shared object's origin ID to the\r\ndestination space's objects' IDs remain in place to properly check for\r\nconflicts with potential copies.\r\n\r\n### Manual Testing\r\n- Create 2 spaces: A and B\r\n- Add a sample data set (e.g. flight) to space A\r\n- In Discover, create a saved query called \"s1\" with a filter pill that\r\nuses the sample data logs data view\r\n- Create another saved query called \"s2\" with a filter pill that uses\r\nthe sample data logs data view\r\n- Go to `Stack Management->Saved` Objects and share the \"s1\" query to\r\nspace B\r\n- Now share the \"s2\" query to space B. From the main branch you will see\r\nthat there is a conflict that disallows sharing the second query. This\r\nis because it is also attempting to share the referenced data view,\r\nwhich is already in space B. However, this should not be a conflict -\r\nfrom this PR you will be able to successfully share both queries.\r\n\r\n### Automated Testing\r\n-\r\npackages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/find_shared_origin_objects.test.ts\r\n-\r\npackages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts\r\n-\r\nx-pack/test/spaces_api_integration/common/suites/get_shareable_references.ts\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"460f5e333631500b2d7984c212ab4d15f5ca4d8e","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Security","release_note:skip","backport:prev-minor","v8.11.0","v8.12.0"],"number":168655,"url":"https://github.com/elastic/kibana/pull/168655","mergeCommit":{"message":"Fixes conflict checks for sharing saved objects (#168655)\n\nCloses #168049\r\n\r\n## Summary\r\n\r\nThis PR adjusts the KQL filters when collecting references to saved\r\nobjects for the purpose of updating their spaces (i.e. sharing saved\r\nobjects to spaces). An additional filter is added to specifically\r\nexclude ID -> ID matches - an ID match would mean the object has already\r\nbeen shared to the destination space and there is no conflict. Filters\r\nto match the shared object's ID or origin ID to the destination space's\r\nobjects' origin ID, and to match the shared object's origin ID to the\r\ndestination space's objects' IDs remain in place to properly check for\r\nconflicts with potential copies.\r\n\r\n### Manual Testing\r\n- Create 2 spaces: A and B\r\n- Add a sample data set (e.g. flight) to space A\r\n- In Discover, create a saved query called \"s1\" with a filter pill that\r\nuses the sample data logs data view\r\n- Create another saved query called \"s2\" with a filter pill that uses\r\nthe sample data logs data view\r\n- Go to `Stack Management->Saved` Objects and share the \"s1\" query to\r\nspace B\r\n- Now share the \"s2\" query to space B. From the main branch you will see\r\nthat there is a conflict that disallows sharing the second query. This\r\nis because it is also attempting to share the referenced data view,\r\nwhich is already in space B. However, this should not be a conflict -\r\nfrom this PR you will be able to successfully share both queries.\r\n\r\n### Automated Testing\r\n-\r\npackages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/find_shared_origin_objects.test.ts\r\n-\r\npackages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts\r\n-\r\nx-pack/test/spaces_api_integration/common/suites/get_shareable_references.ts\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"460f5e333631500b2d7984c212ab4d15f5ca4d8e"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/168655","number":168655,"mergeCommit":{"message":"Fixes conflict checks for sharing saved objects (#168655)\n\nCloses #168049\r\n\r\n## Summary\r\n\r\nThis PR adjusts the KQL filters when collecting references to saved\r\nobjects for the purpose of updating their spaces (i.e. sharing saved\r\nobjects to spaces). An additional filter is added to specifically\r\nexclude ID -> ID matches - an ID match would mean the object has already\r\nbeen shared to the destination space and there is no conflict. Filters\r\nto match the shared object's ID or origin ID to the destination space's\r\nobjects' origin ID, and to match the shared object's origin ID to the\r\ndestination space's objects' IDs remain in place to properly check for\r\nconflicts with potential copies.\r\n\r\n### Manual Testing\r\n- Create 2 spaces: A and B\r\n- Add a sample data set (e.g. flight) to space A\r\n- In Discover, create a saved query called \"s1\" with a filter pill that\r\nuses the sample data logs data view\r\n- Create another saved query called \"s2\" with a filter pill that uses\r\nthe sample data logs data view\r\n- Go to `Stack Management->Saved` Objects and share the \"s1\" query to\r\nspace B\r\n- Now share the \"s2\" query to space B. From the main branch you will see\r\nthat there is a conflict that disallows sharing the second query. This\r\nis because it is also attempting to share the referenced data view,\r\nwhich is already in space B. However, this should not be a conflict -\r\nfrom this PR you will be able to successfully share both queries.\r\n\r\n### Automated Testing\r\n-\r\npackages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/find_shared_origin_objects.test.ts\r\n-\r\npackages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts\r\n-\r\nx-pack/test/spaces_api_integration/common/suites/get_shareable_references.ts\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"460f5e333631500b2d7984c212ab4d15f5ca4d8e"}}]}] BACKPORT--> Co-authored-by: Jeramy Soucy <[email protected]>
Closes elastic#168049 ## Summary This PR adjusts the KQL filters when collecting references to saved objects for the purpose of updating their spaces (i.e. sharing saved objects to spaces). An additional filter is added to specifically exclude ID -> ID matches - an ID match would mean the object has already been shared to the destination space and there is no conflict. Filters to match the shared object's ID or origin ID to the destination space's objects' origin ID, and to match the shared object's origin ID to the destination space's objects' IDs remain in place to properly check for conflicts with potential copies. ### Manual Testing - Create 2 spaces: A and B - Add a sample data set (e.g. flight) to space A - In Discover, create a saved query called "s1" with a filter pill that uses the sample data logs data view - Create another saved query called "s2" with a filter pill that uses the sample data logs data view - Go to `Stack Management->Saved` Objects and share the "s1" query to space B - Now share the "s2" query to space B. From the main branch you will see that there is a conflict that disallows sharing the second query. This is because it is also attempting to share the referenced data view, which is already in space B. However, this should not be a conflict - from this PR you will be able to successfully share both queries. ### Automated Testing - packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/find_shared_origin_objects.test.ts - packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts - x-pack/test/spaces_api_integration/common/suites/get_shareable_references.ts --------- Co-authored-by: kibanamachine <[email protected]>
Closes #168049
Summary
This PR adjusts the KQL filters when collecting references to saved objects for the purpose of updating their spaces (i.e. sharing saved objects to spaces). An additional filter is added to specifically exclude ID -> ID matches - an ID match would mean the object has already been shared to the destination space and there is no conflict. Filters to match the shared object's ID or origin ID to the destination space's objects' origin ID, and to match the shared object's origin ID to the destination space's objects' IDs remain in place to properly check for conflicts with potential copies.
Manual Testing
Stack Management->Saved
Objects and share the "s1" query to space BAutomated Testing