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

Can not share multiple saved queries that use the same data view #168049

Closed
nickpeihl opened this issue Oct 4, 2023 · 5 comments · Fixed by #168655
Closed

Can not share multiple saved queries that use the same data view #168049

nickpeihl opened this issue Oct 4, 2023 · 5 comments · Fixed by #168655
Assignees
Labels
bug Fixes for quality problems that affect the customer experience Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.11.0

Comments

@nickpeihl
Copy link
Member

Kibana version:
8.11.0, main

Describe the bug:

It is not possible to share multiple saved queries that use the same data view to a different space. When sharing the second saved query, the related data view is compared to the data views already in the space. Since the data view already exists in the space the UI blocks sharing the saved query.

Steps to reproduce:

  1. Add Sample data logs to Kibana
  2. Create a saved query with a filter pill that uses the sample data logs data view
  3. Create a second saved query with a filter pill that also uses the sample data logs data view
  4. Create a new space
  5. From the default space, share the first saved query with the new space
  6. Then try to share the second saved query with the same new space
  7. The flyout will not allow sharing the second saved query and it reports "A copy of this saved objects exists in at least one other space". This is likely referring to the data view that is referenced by both queries.

Screenshots (if relevant):

shareable-objects-bug.mp4

Any additional context:

Unfortunately, I think this issue is blocking this feature. Until that issue is resolved, I believe any saved objects that use references like data views will be similarly blocked.

@nickpeihl nickpeihl added bug Fixes for quality problems that affect the customer experience Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.11.0 labels Oct 4, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@pgayvallet
Copy link
Contributor

cc @elastic/kibana-security

@kertal
Copy link
Member

kertal commented Oct 5, 2023

I don't think @elastic/kibana-data-discovery can fix this, so it should be labeled with Team:Security. And I think this should be fixed rather sooner than later, because since we enabled saved query space sharing, and it's high likely common to have multiple saved queries with same data views, this might make the feature unusable for this cases.

@nickpeihl nickpeihl added the Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! label Oct 5, 2023
@legrego
Copy link
Member

legrego commented Oct 5, 2023

We (@elastic/kibana-security) triaged this today:

  • Enable merging saved objects with the same origin #130311 is not blocking this, as it's related to copying saved objects, not sharing.
  • There is a bug in the conflict detection logic used in this form. It is incorrectly identifying the previously-shared data view as a copy, as opposed to the same instance.

@jeramysoucy will be prioritizing a fix for this. We do not yet know the level of effort involved in the fix, but he will keep this issue updated as he learns more.

@kertal kertal removed the Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. label Oct 5, 2023
@jeramysoucy
Copy link
Contributor

jeramysoucy commented Oct 11, 2023

@jeramysoucy will be prioritizing a fix for this. We do not yet know the level of effort involved in the fix, but he will keep this issue updated as he learns more.

I have opened this PR to resolve the issue.

In working on this issue, I noticed that the behavior of un-sharing saved objects from spaces may not be ideal (this was also reported by @teresaalvarezsoler). In the example of this issue, if one of the saved queries is un-shared from the second space, the data view is also unshared even though it is still referenced by the other saved query in that space. I opened a separate issue to track this.

jeramysoucy added a commit that referenced this issue Oct 16, 2023
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
- 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]>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this issue Oct 16, 2023
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)
kibanamachine added a commit that referenced this issue Oct 16, 2023
…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]>
dej611 pushed a commit to dej611/kibana that referenced this issue Oct 17, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.11.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants