Skip to content

[Saved objects client - bulkUpdate] Passing the correct namespace to migrateInputDocument#222313

Merged
cesco-f merged 13 commits intoelastic:mainfrom
cesco-f:fix-bulk-update-namespace
Jun 19, 2025
Merged

[Saved objects client - bulkUpdate] Passing the correct namespace to migrateInputDocument#222313
cesco-f merged 13 commits intoelastic:mainfrom
cesco-f:fix-bulk-update-namespace

Conversation

@cesco-f
Copy link
Contributor

@cesco-f cesco-f commented Jun 3, 2025

While working on this PR I noticed an issue when trying to bulk update saved objects overriding the current space for the operation.

@cesco-f cesco-f requested a review from a team as a code owner June 3, 2025 09:02
@github-actions github-actions bot added the author:obs-ux-management PRs authored by the obs ux management team label Jun 3, 2025
id,
type,
namespace,
namespace: getNamespaceId(objectNamespace),
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks correct but we should not set a namespace if this is a multinamespace saved object type. So we need to do something similar to the update method where either namespace or namespaces is set depending on if this is multi/single namespace.

https://github.com/elastic/kibana/blob/main/src/core/packages/saved-objects/api-server-internal/src/lib/apis/update.ts#L162-L179

wdyt @TinaHeiligers

Copy link
Contributor

@jeramysoucy jeramysoucy Jun 4, 2025

Choose a reason for hiding this comment

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

++
May even have to look back at this section where "namespaces" is set, and adjust to account for "namespace" vs "namespaces" throughout the rest of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey team 😊

Can we maybe merge this to fix my use case and open another PR to fix the multinamespace saved object type?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can make push some changes to take care of this. I will take a look on Monday.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the delay. I pushed c122b83
I believe it will handle the difference between single and multi-namespace types correctly. I also officially tagged @TinaHeiligers for a review.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this isn't a bug and could be a callee error because we haven't had any other reports of namespace issues. I'll take a look at the diffs.

Copy link
Contributor

@TinaHeiligers TinaHeiligers Jun 9, 2025

Choose a reason for hiding this comment

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

So we need to do something similar to the update method where either namespace or namespaces is set depending on if this is multi/single namespace.

If bulkUpdate now supports upsert, then probably yes. When I worked on the API making it BWC, bulkUpdate didn't support upsert, nor did it support partial updates.

Using getNamespaceId might mess with the namespaces array, so we'll need to watch the tests carefully.

@rudolf rudolf added the Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// label Jun 3, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@rudolf rudolf added the bug Fixes for quality problems that affect the customer experience label Jun 3, 2025
@cesco-f cesco-f force-pushed the fix-bulk-update-namespace branch from d3abb6e to 791a5ee Compare June 5, 2025 09:22
@jeramysoucy jeramysoucy requested a review from TinaHeiligers June 9, 2025 16:09
Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

left a comment.

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Just left a question to clarify what kind of namespace (string or id) we need for encryption. Otherwise lgtm

type,
namespace,
namespaces,
...(savedObjectNamespace && { namespace: savedObjectNamespace }),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't comment on the right place, but in line 297 should we fallback to namespace or namespaceString for the encryption helper?

Copy link
Contributor

@jeramysoucy jeramysoucy Jun 13, 2025

Choose a reason for hiding this comment

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

It actually doesn't matter if we pass a namespace ID or a namespace string to the encryption extension - it will always get "normalized" and used appropriately. However, you brought to my attention that the parameters might have always been wrong here.

The object should be encrypted based on its descriptor, not the current namespace or the provided object namespace. So... let me think about this...

Disregard...I forgot that we do not use namespace in the descriptor for multi-namespace ESOs.

type,
id,
objectNamespace || namespace,
savedObjectNamespaces ?? savedObjectNamespace,
Copy link
Contributor

@jeramysoucy jeramysoucy Jun 13, 2025

Choose a reason for hiding this comment

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

Encryption should always be based on the object's actual namespace(s). For multi-namespace objects, we pick the first namespace to use in the encryption descriptor (we also "normalize" the parameters to handle passing an namespace vs namespace string). So because namespaces can be overridden in bulk update per object, we should be careful here not to use either the provided object namespace or the current namespace, because it might render an multi-namespace ESO undecryptable. Does this make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think we really need tests for this logic specifically (bulk update, object space override on a multispace encrypted object), but I have not had time to do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

😓 Ahhh...nevermind! No namespace is used for the ESO descriptor for multi-namespace objects. Disregard. We can revert this back to what was there.

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

History

@cesco-f cesco-f merged commit 9794168 into elastic:main Jun 19, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/15752738765

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 19, 2025
…migrateInputDocument (elastic#222313)

While working on [this
PR](elastic#221515) I noticed an issue
when trying to bulk update saved objects overriding the current space
for the operation.

---------

Co-authored-by: “jeramysoucy” <jeramy.soucy@elastic.co>
Co-authored-by: Shahzad <shahzad31comp@gmail.com>
Co-authored-by: Rudolf Meijering <skaapgif@gmail.com>
(cherry picked from commit 9794168)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@cesco-f cesco-f deleted the fix-bulk-update-namespace branch June 19, 2025 08:23
kibanamachine added a commit that referenced this pull request Jun 19, 2025
…ace to migrateInputDocument (#222313) (#224522)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Saved objects client - bulkUpdate] Passing the correct namespace to
migrateInputDocument
(#222313)](#222313)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Francesco
Fagnani","email":"fagnani.francesco@gmail.com"},"sourceCommit":{"committedDate":"2025-06-19T08:01:33Z","message":"[Saved
objects client - bulkUpdate] Passing the correct namespace to
migrateInputDocument (#222313)\n\nWhile working on
[this\nPR](#221515) I noticed an
issue\nwhen trying to bulk update saved objects overriding the current
space\nfor the operation.\n\n---------\n\nCo-authored-by: “jeramysoucy”
<jeramy.soucy@elastic.co>\nCo-authored-by: Shahzad
<shahzad31comp@gmail.com>\nCo-authored-by: Rudolf Meijering
<skaapgif@gmail.com>","sha":"97941682dbf5703197b5068fad4b9cb583a24631","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:Core","release_note:fix","backport:version","v9.1.0","v8.19.0","author:obs-ux-management"],"title":"[Saved
objects client - bulkUpdate] Passing the correct namespace to
migrateInputDocument","number":222313,"url":"https://github.com/elastic/kibana/pull/222313","mergeCommit":{"message":"[Saved
objects client - bulkUpdate] Passing the correct namespace to
migrateInputDocument (#222313)\n\nWhile working on
[this\nPR](#221515) I noticed an
issue\nwhen trying to bulk update saved objects overriding the current
space\nfor the operation.\n\n---------\n\nCo-authored-by: “jeramysoucy”
<jeramy.soucy@elastic.co>\nCo-authored-by: Shahzad
<shahzad31comp@gmail.com>\nCo-authored-by: Rudolf Meijering
<skaapgif@gmail.com>","sha":"97941682dbf5703197b5068fad4b9cb583a24631"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/222313","number":222313,"mergeCommit":{"message":"[Saved
objects client - bulkUpdate] Passing the correct namespace to
migrateInputDocument (#222313)\n\nWhile working on
[this\nPR](#221515) I noticed an
issue\nwhen trying to bulk update saved objects overriding the current
space\nfor the operation.\n\n---------\n\nCo-authored-by: “jeramysoucy”
<jeramy.soucy@elastic.co>\nCo-authored-by: Shahzad
<shahzad31comp@gmail.com>\nCo-authored-by: Rudolf Meijering
<skaapgif@gmail.com>","sha":"97941682dbf5703197b5068fad4b9cb583a24631"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Francesco Fagnani <fagnani.francesco@gmail.com>
Co-authored-by: “jeramysoucy” <jeramy.soucy@elastic.co>
Co-authored-by: Shahzad <shahzad31comp@gmail.com>
Co-authored-by: Rudolf Meijering <skaapgif@gmail.com>
rudolf added a commit to rudolf/kibana that referenced this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author:obs-ux-management PRs authored by the obs ux management team backport:version Backport to applied version labels bug Fixes for quality problems that affect the customer experience release_note:fix Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v8.19.0 v9.1.0

7 participants