Fix enforcement of unique policy name of policies across spaces#239631
Merged
MichelLosier merged 27 commits intoelastic:mainfrom Nov 4, 2025
Merged
Fix enforcement of unique policy name of policies across spaces#239631MichelLosier merged 27 commits intoelastic:mainfrom
MichelLosier merged 27 commits intoelastic:mainfrom
Conversation
Contributor
Author
|
/ci |
1 similar comment
Contributor
Author
|
/ci |
…e spaceids provided
895b415 to
b77ded2
Compare
Contributor
Author
|
/ci |
Contributor
Author
|
/ci |
Contributor
Author
|
/ci |
Contributor
Author
|
/ci |
Contributor
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]
History
|
Contributor
|
Starting backport for target branches: 9.1, 9.2 |
Contributor
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
MichelLosier
added a commit
to MichelLosier/kibana
that referenced
this pull request
Nov 4, 2025
…tic#239631) Resolves: elastic#228746 Fixes fleet policy name uniqueness not being consistently enforced across spaces when name or space changes occur: * When creating an agent policy with packages (like system), the name incrementation accounts for package names that already exist in the spaces to be set for the new policy. * Creating or updating an agent policy for multiple spaces that has the same name of another policy that is not in the current namespace now results in an error. * When an agent policy with multiple spaces has an integration policy name updated to one that already exists in another space that is not the current namespace now results in an error. (cherry picked from commit e15311c) # Conflicts: # x-pack/platform/plugins/shared/fleet/server/services/agent_policy.test.ts # x-pack/platform/test/fleet_api_integration/apis/space_awareness/agent_policies.ts # x-pack/platform/test/fleet_api_integration/apis/space_awareness/api_helper.ts # x-pack/platform/test/fleet_api_integration/apis/space_awareness/package_policies.ts
Contributor
Author
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
MichelLosier
added a commit
to MichelLosier/kibana
that referenced
this pull request
Nov 4, 2025
…tic#239631) Resolves: elastic#228746 Fixes fleet policy name uniqueness not being consistently enforced across spaces when name or space changes occur: * When creating an agent policy with packages (like system), the name incrementation accounts for package names that already exist in the spaces to be set for the new policy. * Creating or updating an agent policy for multiple spaces that has the same name of another policy that is not in the current namespace now results in an error. * When an agent policy with multiple spaces has an integration policy name updated to one that already exists in another space that is not the current namespace now results in an error. (cherry picked from commit e15311c) # Conflicts: # x-pack/platform/plugins/shared/fleet/server/services/agent_policy.test.ts # x-pack/platform/plugins/shared/fleet/server/services/agent_policy_create.ts # x-pack/platform/plugins/shared/fleet/server/services/package_policies/upgrade.test.ts # x-pack/platform/plugins/shared/fleet/server/services/package_policy.ts # x-pack/platform/test/fleet_api_integration/apis/space_awareness/agent_policies.ts # x-pack/platform/test/fleet_api_integration/apis/space_awareness/api_helper.ts # x-pack/platform/test/fleet_api_integration/apis/space_awareness/package_policies.ts
MichelLosier
added a commit
that referenced
this pull request
Nov 5, 2025
…#239631) (#241884) # Backport This will backport the following commits from `main` to `9.2`: - [Fix enforcement of unique policy name of policies across spaces (#239631)](#239631) <!--- Backport version: 10.1.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Michel Losier","email":"michel.losier@elastic.co"},"sourceCommit":{"committedDate":"2025-11-04T20:25:43Z","message":"Fix enforcement of unique policy name of policies across spaces (#239631)\n\nResolves: https://github.com/elastic/kibana/issues/228746\n\nFixes fleet policy name uniqueness not being consistently enforced\nacross spaces when name or space changes occur:\n\n* When creating an agent policy with packages\n(like system), the name incrementation accounts for package names that\nalready exist in the spaces to be set for the new policy.\n* Creating or updating an agent policy for multiple spaces that has the\nsame name of another policy that is not in the current namespace now\nresults in an error.\n* When an agent policy with multiple spaces has an integration policy\nname updated to one that already exists in another space that is not the\ncurrent namespace now results in an error.","sha":"e15311c5a7ad2052046f5da0cea0c5815dfd4d73","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:version","v9.3.0","v9.1.7","v9.2.1"],"title":"Fix enforcement of unique policy name of policies across spaces","number":239631,"url":"https://github.com/elastic/kibana/pull/239631","mergeCommit":{"message":"Fix enforcement of unique policy name of policies across spaces (#239631)\n\nResolves: https://github.com/elastic/kibana/issues/228746\n\nFixes fleet policy name uniqueness not being consistently enforced\nacross spaces when name or space changes occur:\n\n* When creating an agent policy with packages\n(like system), the name incrementation accounts for package names that\nalready exist in the spaces to be set for the new policy.\n* Creating or updating an agent policy for multiple spaces that has the\nsame name of another policy that is not in the current namespace now\nresults in an error.\n* When an agent policy with multiple spaces has an integration policy\nname updated to one that already exists in another space that is not the\ncurrent namespace now results in an error.","sha":"e15311c5a7ad2052046f5da0cea0c5815dfd4d73"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","9.2"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239631","number":239631,"mergeCommit":{"message":"Fix enforcement of unique policy name of policies across spaces (#239631)\n\nResolves: https://github.com/elastic/kibana/issues/228746\n\nFixes fleet policy name uniqueness not being consistently enforced\nacross spaces when name or space changes occur:\n\n* When creating an agent policy with packages\n(like system), the name incrementation accounts for package names that\nalready exist in the spaces to be set for the new policy.\n* Creating or updating an agent policy for multiple spaces that has the\nsame name of another policy that is not in the current namespace now\nresults in an error.\n* When an agent policy with multiple spaces has an integration policy\nname updated to one that already exists in another space that is not the\ncurrent namespace now results in an error.","sha":"e15311c5a7ad2052046f5da0cea0c5815dfd4d73"}},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
wildemat
pushed a commit
to wildemat/kibana
that referenced
this pull request
Nov 5, 2025
…tic#239631) Resolves: elastic#228746 Fixes fleet policy name uniqueness not being consistently enforced across spaces when name or space changes occur: * When creating an agent policy with packages (like system), the name incrementation accounts for package names that already exist in the spaces to be set for the new policy. * Creating or updating an agent policy for multiple spaces that has the same name of another policy that is not in the current namespace now results in an error. * When an agent policy with multiple spaces has an integration policy name updated to one that already exists in another space that is not the current namespace now results in an error.
viduni94
pushed a commit
to viduni94/kibana
that referenced
this pull request
Nov 5, 2025
…tic#239631) Resolves: elastic#228746 Fixes fleet policy name uniqueness not being consistently enforced across spaces when name or space changes occur: * When creating an agent policy with packages (like system), the name incrementation accounts for package names that already exist in the spaces to be set for the new policy. * Creating or updating an agent policy for multiple spaces that has the same name of another policy that is not in the current namespace now results in an error. * When an agent policy with multiple spaces has an integration policy name updated to one that already exists in another space that is not the current namespace now results in an error.
MichelLosier
added a commit
that referenced
this pull request
Nov 6, 2025
…#239631) (#241885) # Backport This will backport the following commits from `main` to `9.1`: - [Fix enforcement of unique policy name of policies across spaces (#239631)](#239631) <!--- Backport version: 10.1.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Michel Losier","email":"michel.losier@elastic.co"},"sourceCommit":{"committedDate":"2025-11-04T20:25:43Z","message":"Fix enforcement of unique policy name of policies across spaces (#239631)\n\nResolves: https://github.com/elastic/kibana/issues/228746\n\nFixes fleet policy name uniqueness not being consistently enforced\nacross spaces when name or space changes occur:\n\n* When creating an agent policy with packages\n(like system), the name incrementation accounts for package names that\nalready exist in the spaces to be set for the new policy.\n* Creating or updating an agent policy for multiple spaces that has the\nsame name of another policy that is not in the current namespace now\nresults in an error.\n* When an agent policy with multiple spaces has an integration policy\nname updated to one that already exists in another space that is not the\ncurrent namespace now results in an error.","sha":"e15311c5a7ad2052046f5da0cea0c5815dfd4d73","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:version","v9.3.0","v9.1.7","v9.2.1"],"title":"Fix enforcement of unique policy name of policies across spaces","number":239631,"url":"https://github.com/elastic/kibana/pull/239631","mergeCommit":{"message":"Fix enforcement of unique policy name of policies across spaces (#239631)\n\nResolves: https://github.com/elastic/kibana/issues/228746\n\nFixes fleet policy name uniqueness not being consistently enforced\nacross spaces when name or space changes occur:\n\n* When creating an agent policy with packages\n(like system), the name incrementation accounts for package names that\nalready exist in the spaces to be set for the new policy.\n* Creating or updating an agent policy for multiple spaces that has the\nsame name of another policy that is not in the current namespace now\nresults in an error.\n* When an agent policy with multiple spaces has an integration policy\nname updated to one that already exists in another space that is not the\ncurrent namespace now results in an error.","sha":"e15311c5a7ad2052046f5da0cea0c5815dfd4d73"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","9.2"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239631","number":239631,"mergeCommit":{"message":"Fix enforcement of unique policy name of policies across spaces (#239631)\n\nResolves: https://github.com/elastic/kibana/issues/228746\n\nFixes fleet policy name uniqueness not being consistently enforced\nacross spaces when name or space changes occur:\n\n* When creating an agent policy with packages\n(like system), the name incrementation accounts for package names that\nalready exist in the spaces to be set for the new policy.\n* Creating or updating an agent policy for multiple spaces that has the\nsame name of another policy that is not in the current namespace now\nresults in an error.\n* When an agent policy with multiple spaces has an integration policy\nname updated to one that already exists in another space that is not the\ncurrent namespace now results in an error.","sha":"e15311c5a7ad2052046f5da0cea0c5815dfd4d73"}},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
eokoneyo
pushed a commit
to eokoneyo/kibana
that referenced
this pull request
Dec 2, 2025
…tic#239631) Resolves: elastic#228746 Fixes fleet policy name uniqueness not being consistently enforced across spaces when name or space changes occur: * When creating an agent policy with packages (like system), the name incrementation accounts for package names that already exist in the spaces to be set for the new policy. * Creating or updating an agent policy for multiple spaces that has the same name of another policy that is not in the current namespace now results in an error. * When an agent policy with multiple spaces has an integration policy name updated to one that already exists in another space that is not the current namespace now results in an error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves: #228746
This fixes a couple scenarios:
Implementation overview
This fix makes sure that create and update agent policy handlers pass the provided
space_idsto the agentPolicyService class so that they can be used in cross-space saved object queries when validating name uniqueness, while making sure thespace_idsfield is not persisted in the actual SO since this field is derived from the actual SO namespaces value.The uniqueness check happens in a couple places:
Release notes
Fixes fleet policy name uniqueness not being consistently enforced across spaces when name or space changes occur
Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesbackport:*labels.Identify risks
Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.
Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.