Skip to content

[Automatic Migrations] Siem migrations new endpoint scheme#219597

Merged
logeekal merged 45 commits intoelastic:mainfrom
logeekal:siem_migrations_new_endpoint
May 22, 2025
Merged

[Automatic Migrations] Siem migrations new endpoint scheme#219597
logeekal merged 45 commits intoelastic:mainfrom
logeekal:siem_migrations_new_endpoint

Conversation

@logeekal
Copy link
Contributor

@logeekal logeekal commented Apr 29, 2025

Summary

Resolves https://github.com/elastic/security-team/issues/12483

This PR changes REST API Endpoints scheme to align with https://github.com/elastic/security-team/issues/12483. Below is the summary of changes done.

API Scheme changes

The REST API scheme has been changed to reflect https://github.com/elastic/security-team/issues/12483. This is pretty much self explanatory as defined in below openapi schema yaml :

Introduction of Delete Migration API

This PR also adds DELETE method on route /rules/siem_migrations/{migration_id} for deleting a migrations. Deleting a migration does below operations:

  • Stops a migration if it is running
  • Deletes the rules, resources related to migration and migration document itself.

File Reorganizations

Directly structure has been changed a little bit to reflect the endpoint. There is a sub-directory called rules which deals with only rules of the migration and the root directly only contains the endpoints related to the migration.

Before

//siem_migrations/rules/api

├── create.ts
├── get.ts
├── start.ts
├── update.ts
├── 
├── 
├── 

After

//siem_migrations/rules/api


├── create.ts
├── delete.ts
├── get.ts
├── rules
│   ├── add.ts
│   ├── get.ts
│   └── update.ts
├── 
├── 
├── 

Migration Strategy

TL,DR;

flowchart TD
    StartM[Start Migration] --> isMigExists{Does Migration Index Exists}
    isMigExists -->|Yes|FetchMDoc[Fetch Migration Docs]
    isMigExists -->|No|CreateMIndex[Create MigrationIndex]
    CreateMIndex --> FetchMDoc
    FetchMDoc --> FetchMRules[Fetch Migration Stats Rules index]
    FetchMRules --> FilterMigration{Filter Migration Docs not in Migration Index}
    FilterMigration --> |is Empty|END[END]
    FilterMigration --> |is Not Empty| CreateMDocs[Create Migration Docs]
    CreateMDocs --> END
Loading

At the time of merging this PR, the Migration indices can be in 3 states:

There are migrations created after #216164 and this means that there are some migrations existing in .kibana-siem-migrations-migrations-<space_id> and migrations created before above mentioned PR will only exist in .kibana-siem-migrations-rules-<space_id>.

In this case migrateRuleMigrationIndex will create migration in below steps:

  1. Look for all migration Documents in .kibana-siem-migrations-migrations-<space_id>
  2. Get all Migrations stats from .kibana-siem-migrations-rules-<space_id> which includes below properties
    • migration_id : will help in reconciling the migration id in .kibana-siem-migrations-migrations-<space_id>` index
    • created_at : Date on which migration_id was created.
    • created_by: User who created the migrations.
  3. A new document with above migration will be added to .kibana-siem-migrations-migrations-<space_id>.
  4. Now both .kibana-siem-migrations-migrations-<space_id> and .kibana-siem-migrations-rules-<space_id> will be in sync.

Alternatively, there are no migration created after #216164. In that case, there is a possibility that .kibana-siem-migrations-migrations-<space_id>, will not even exist.

In this case migrateRuleMigrationIndex will create migration in below steps:

  1. Create the .kibana-siem-migrations-migrations-<space_id> index.
  2. Do steps mentioned in above scenario.

Once the migrations has been run successfully, both .kibana-siem-migrations-migrations-<space_id> index and .kibana-siem-migrations-rules-<space_id> will be in sync.

  1. In this case, migration will not run, since it tries to filter the migrations by id which exist in kibana-siem-migrations-rules-<space_id> but do not exist in kibana-siem-migrations-migrations-<space_id>

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

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.

@prodsecmachine
Copy link
Collaborator

prodsecmachine commented May 2, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@logeekal logeekal added release_note:feature Makes this part of the condensed release notes backport:version Backport to applied version labels v9.1.0 labels May 2, 2025
@logeekal logeekal changed the title Siem migrations new endpoint [Automatic Migrations] Siem migrations new endpoint May 2, 2025
@logeekal logeekal marked this pull request as ready for review May 2, 2025 07:58
@logeekal logeekal requested review from a team as code owners May 2, 2025 07:58
Copy link
Contributor

@kqualters-elastic kqualters-elastic left a comment

Choose a reason for hiding this comment

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

talked through some of this during our syncs, and desk tested this most recent iteration locally and with frontend changes based on this branch, everything looks good to me 👍

Copy link
Contributor

@semd semd left a comment

Choose a reason for hiding this comment

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

Tested locally, index migrators create the expected documents. Regular rule migration workflow works as usual. LGTM.
Thanks Jatin! 🚀

@logeekal logeekal enabled auto-merge (squash) May 22, 2025 13:28
@logeekal logeekal disabled auto-merge May 22, 2025 14:50
@logeekal logeekal enabled auto-merge (squash) May 22, 2025 14:51
@logeekal logeekal changed the title [Automatic Migrations] Siem migrations new endpoint [Automatic Migrations] Siem migrations new endpoint scheme May 22, 2025
@logeekal logeekal merged commit bf642b0 into elastic:main May 22, 2025
12 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

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

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #83 / Synthetics API Tests SyncGlobalParams parsed params for previously added http monitors

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 9.2MB 9.2MB +1.0KB

History

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 219597

Questions ?

Please refer to the Backport tool documentation

@logeekal
Copy link
Contributor Author

💚 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

logeekal added a commit to logeekal/kibana that referenced this pull request May 26, 2025
## Summary

Resolves elastic/security-team#12483

This PR changes REST API Endpoints scheme to align with
elastic/security-team#12483. Below is the
summary of changes done.

### API Scheme changes

The REST API scheme has been changed to reflect
elastic/security-team#12483. This is pretty
much self explanatory as defined in below openapi schema yaml :

-
[x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml](https://github.com/elastic/kibana/pull/219597/files#diff-3025af9eca156f3308474e2b42808da1531423457b7791daf6660db95a53b978)

### Introduction of Delete Migration API

This PR also adds `DELETE` method on route
`/rules/siem_migrations/{migration_id}` for deleting a migrations.
Deleting a migration does below operations:

- Stops a migration if it is running
- Deletes the rules, resources related to migration and migration
document itself.

### File Reorganizations

Directly structure has been changed a little bit to reflect the
endpoint. There is a sub-directory called `rules` which deals with only
`rules` of the migration and the root directly only contains the
endpoints related to the migration.

#### Before

```
//siem_migrations/rules/api

├── create.ts
├── get.ts
├── start.ts
├── update.ts
├──
├──
├──
```

#### After

```
//siem_migrations/rules/api

├── create.ts
├── delete.ts
├── get.ts
├── rules
│   ├── add.ts
│   ├── get.ts
│   └── update.ts
├──
├──
├──
```

## Migration Strategy

### TL,DR;
```mermaid
flowchart TD
    StartM[Start Migration] --> isMigExists{Does Migration Index Exists}
    isMigExists -->|Yes|FetchMDoc[Fetch Migration Docs]
    isMigExists -->|No|CreateMIndex[Create MigrationIndex]
    CreateMIndex --> FetchMDoc
    FetchMDoc --> FetchMRules[Fetch Migration Stats Rules index]
    FetchMRules --> FilterMigration{Filter Migration Docs not in Migration Index}
    FilterMigration --> |is Empty|END[END]
    FilterMigration --> |is Not Empty| CreateMDocs[Create Migration Docs]
    CreateMDocs --> END
```

At the time of merging this PR, the Migration indices can be in 3
states:

### There are migrations created after
elastic#216164 and this means that there
are `some` migrations existing in
`.kibana-siem-migrations-migrations-<space_id>` and migrations created
before above mentioned PR will only exist in
`.kibana-siem-migrations-rules-<space_id>`.

In this case `migrateRuleMigrationIndex` will create migration in below
steps:

1. Look for **all** migration Documents in
`.kibana-siem-migrations-migrations-<space_id>`
2. Get **all** Migrations stats from
`.kibana-siem-migrations-rules-<space_id>` which includes below
properties
- migration_id : will help in reconciling the migration id in
.kibana-siem-migrations-migrations-<space_id>` index
    - created_at : Date on which migration_id was created.
    - created_by: User who created the migrations.
3. A new document with above migration will be added to
`.kibana-siem-migrations-migrations-<space_id>`.
4. Now both `.kibana-siem-migrations-migrations-<space_id>` and
`.kibana-siem-migrations-rules-<space_id>` will be in sync.

### Alternatively, there are no migration created after
elastic#216164. In that case, there is a
possibility that `.kibana-siem-migrations-migrations-<space_id>`, will
not even exist.

In this case `migrateRuleMigrationIndex` will create migration in below
steps:

1. Create the `.kibana-siem-migrations-migrations-<space_id>` index.
2. Do steps mentioned in above scenario.

### Once the migrations has been run successfully, both
`.kibana-siem-migrations-migrations-<space_id>` index and
`.kibana-siem-migrations-rules-<space_id>` will be in sync.

1. In this case, migration will not run, since it tries to filter the
migrations by `id` which exist in
`kibana-siem-migrations-rules-<space_id>` but do not exist in
`kibana-siem-migrations-migrations-<space_id>`

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### 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.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit bf642b0)

# Conflicts:
#	x-pack/test/security_solution_cypress/cypress/urls/navigation.ts
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 26, 2025
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @logeekal

logeekal added a commit to logeekal/kibana that referenced this pull request May 26, 2025
## Summary

Resolves elastic/security-team#12483

This PR changes REST API Endpoints scheme to align with
elastic/security-team#12483. Below is the
summary of changes done.

### API Scheme changes

The REST API scheme has been changed to reflect
elastic/security-team#12483. This is pretty
much self explanatory as defined in below openapi schema yaml :

-
[x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml](https://github.com/elastic/kibana/pull/219597/files#diff-3025af9eca156f3308474e2b42808da1531423457b7791daf6660db95a53b978)

### Introduction of Delete Migration API

This PR also adds `DELETE` method on route
`/rules/siem_migrations/{migration_id}` for deleting a migrations.
Deleting a migration does below operations:

- Stops a migration if it is running
- Deletes the rules, resources related to migration and migration
document itself.

### File Reorganizations

Directly structure has been changed a little bit to reflect the
endpoint. There is a sub-directory called `rules` which deals with only
`rules` of the migration and the root directly only contains the
endpoints related to the migration.

#### Before

```
//siem_migrations/rules/api

├── create.ts
├── get.ts
├── start.ts
├── update.ts
├──
├──
├──
```

#### After

```
//siem_migrations/rules/api

├── create.ts
├── delete.ts
├── get.ts
├── rules
│   ├── add.ts
│   ├── get.ts
│   └── update.ts
├──
├──
├──
```

## Migration Strategy

### TL,DR;
```mermaid
flowchart TD
    StartM[Start Migration] --> isMigExists{Does Migration Index Exists}
    isMigExists -->|Yes|FetchMDoc[Fetch Migration Docs]
    isMigExists -->|No|CreateMIndex[Create MigrationIndex]
    CreateMIndex --> FetchMDoc
    FetchMDoc --> FetchMRules[Fetch Migration Stats Rules index]
    FetchMRules --> FilterMigration{Filter Migration Docs not in Migration Index}
    FilterMigration --> |is Empty|END[END]
    FilterMigration --> |is Not Empty| CreateMDocs[Create Migration Docs]
    CreateMDocs --> END
```

At the time of merging this PR, the Migration indices can be in 3
states:

### There are migrations created after
elastic#216164 and this means that there
are `some` migrations existing in
`.kibana-siem-migrations-migrations-<space_id>` and migrations created
before above mentioned PR will only exist in
`.kibana-siem-migrations-rules-<space_id>`.

In this case `migrateRuleMigrationIndex` will create migration in below
steps:

1. Look for **all** migration Documents in
`.kibana-siem-migrations-migrations-<space_id>`
2. Get **all** Migrations stats from
`.kibana-siem-migrations-rules-<space_id>` which includes below
properties
- migration_id : will help in reconciling the migration id in
.kibana-siem-migrations-migrations-<space_id>` index
    - created_at : Date on which migration_id was created.
    - created_by: User who created the migrations.
3. A new document with above migration will be added to
`.kibana-siem-migrations-migrations-<space_id>`.
4. Now both `.kibana-siem-migrations-migrations-<space_id>` and
`.kibana-siem-migrations-rules-<space_id>` will be in sync.

### Alternatively, there are no migration created after
elastic#216164. In that case, there is a
possibility that `.kibana-siem-migrations-migrations-<space_id>`, will
not even exist.

In this case `migrateRuleMigrationIndex` will create migration in below
steps:

1. Create the `.kibana-siem-migrations-migrations-<space_id>` index.
2. Do steps mentioned in above scenario.

### Once the migrations has been run successfully, both
`.kibana-siem-migrations-migrations-<space_id>` index and
`.kibana-siem-migrations-rules-<space_id>` will be in sync.

1. In this case, migration will not run, since it tries to filter the
migrations by `id` which exist in
`kibana-siem-migrations-rules-<space_id>` but do not exist in
`kibana-siem-migrations-migrations-<space_id>`

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### 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.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit bf642b0)

# Conflicts:
#	x-pack/test/security_solution_cypress/cypress/urls/navigation.ts
@logeekal
Copy link
Contributor Author

💚 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

logeekal added a commit that referenced this pull request May 27, 2025
…221536)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Automatic Migrations] Siem migrations new endpoint
(#219597)](#219597)

<!--- Backport version: 10.0.0 -->

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

<!--BACKPORT [{"author":{"name":"Jatin
Kathuria","email":"jatin.kathuria@elastic.co"},"sourceCommit":{"committedDate":"2025-05-22T15:23:17Z","message":"[Automatic
Migrations] Siem migrations new endpoint (#219597)\n\n##
Summary\n\nResolves
https://github.com/elastic/security-team/issues/12483\n\nThis PR changes
REST API Endpoints scheme to align
with\nhttps://github.com/elastic/security-team/issues/12483. Below is
the\nsummary of changes done.\n\n### API Scheme changes\n\nThe REST API
scheme has been changed to
reflect\nhttps://github.com/elastic/security-team/issues/12483. This is
pretty\nmuch self explanatory as defined in below openapi schema yaml
:\n\n-\n[x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml](https://github.com/elastic/kibana/pull/219597/files#diff-3025af9eca156f3308474e2b42808da1531423457b7791daf6660db95a53b978)\n\n###
Introduction of Delete Migration API\n\nThis PR also adds `DELETE`
method on route\n`/rules/siem_migrations/{migration_id}` for deleting a
migrations.\nDeleting a migration does below operations:\n\n- Stops a
migration if it is running\n- Deletes the rules, resources related to
migration and migration\ndocument itself.\n\n### File
Reorganizations\n\nDirectly structure has been changed a little bit to
reflect the\nendpoint. There is a sub-directory called `rules` which
deals with only\n`rules` of the migration and the root directly only
contains the\nendpoints related to the migration.\n\n####
Before\n\n```\n//siem_migrations/rules/api\n\n├── create.ts\n├──
get.ts\n├── start.ts\n├── update.ts\n├── \n├── \n├── \n```\n\n####
After\n\n```\n//siem_migrations/rules/api\n\n\n├── create.ts\n├──
delete.ts\n├── get.ts\n├── rules\n│   ├── add.ts\n│   ├── get.ts\n│  
└── update.ts\n├── \n├── \n├── \n```\n\n## Migration Strategy\n\n###
TL,DR; \n```mermaid\nflowchart TD\n StartM[Start Migration] -->
isMigExists{Does Migration Index Exists}\n isMigExists
-->|Yes|FetchMDoc[Fetch Migration Docs]\n isMigExists
-->|No|CreateMIndex[Create MigrationIndex]\n CreateMIndex -->
FetchMDoc\n FetchMDoc --> FetchMRules[Fetch Migration Stats Rules
index]\n FetchMRules --> FilterMigration{Filter Migration Docs not in
Migration Index}\n FilterMigration --> |is Empty|END[END]\n
FilterMigration --> |is Not Empty| CreateMDocs[Create Migration Docs]\n
CreateMDocs --> END\n```\n\n\n\nAt the time of merging this PR, the
Migration indices can be in 3\nstates:\n\n### There are migrations
created after\nhttps://github.com//pull/216164 and this
means that there\nare `some` migrations existing
in\n`.kibana-siem-migrations-migrations-<space_id>` and migrations
created\nbefore above mentioned PR will only exist
in\n`.kibana-siem-migrations-rules-<space_id>`.\n\nIn this case
`migrateRuleMigrationIndex` will create migration in below\nsteps:\n\n1.
Look for **all** migration Documents
in\n`.kibana-siem-migrations-migrations-<space_id>`\n2. Get **all**
Migrations stats from\n`.kibana-siem-migrations-rules-<space_id>` which
includes below\nproperties\n- migration_id : will help in reconciling
the migration id in\n.kibana-siem-migrations-migrations-<space_id>`
index\n - created_at : Date on which migration_id was created.\n -
created_by: User who created the migrations.\n3. A new document with
above migration will be added
to\n`.kibana-siem-migrations-migrations-<space_id>`.\n4. Now both
`.kibana-siem-migrations-migrations-<space_id>`
and\n`.kibana-siem-migrations-rules-<space_id>` will be in sync.\n\n###
Alternatively, there are no migration created
after\nhttps://github.com//pull/216164. In that case,
there is a\npossibility that
`.kibana-siem-migrations-migrations-<space_id>`, will\nnot even
exist.\n\nIn this case `migrateRuleMigrationIndex` will create migration
in below\nsteps:\n\n1. Create the
`.kibana-siem-migrations-migrations-<space_id>` index.\n2. Do steps
mentioned in above scenario.\n\n### Once the migrations has been run
successfully, both\n`.kibana-siem-migrations-migrations-<space_id>`
index and\n`.kibana-siem-migrations-rules-<space_id>` will be in
sync.\n\n1. In this case, migration will not run, since it tries to
filter the\nmigrations by `id` which exist
in\n`kibana-siem-migrations-rules-<space_id>` but do not exist
in\n`kibana-siem-migrations-migrations-<space_id>`\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] The PR
description includes the appropriate Release Notes section,\nand the
correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"bf642b00395079ef0e2f334b4fca65d2ff15d94c","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport
missing","release_note:feature","backport:version","v9.1.0","v8.19.0"],"title":"[Automatic
Migrations] Siem migrations new endpoint
scheme","number":219597,"url":"https://github.com/elastic/kibana/pull/219597","mergeCommit":{"message":"[Automatic
Migrations] Siem migrations new endpoint (#219597)\n\n##
Summary\n\nResolves
https://github.com/elastic/security-team/issues/12483\n\nThis PR changes
REST API Endpoints scheme to align
with\nhttps://github.com/elastic/security-team/issues/12483. Below is
the\nsummary of changes done.\n\n### API Scheme changes\n\nThe REST API
scheme has been changed to
reflect\nhttps://github.com/elastic/security-team/issues/12483. This is
pretty\nmuch self explanatory as defined in below openapi schema yaml
:\n\n-\n[x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml](https://github.com/elastic/kibana/pull/219597/files#diff-3025af9eca156f3308474e2b42808da1531423457b7791daf6660db95a53b978)\n\n###
Introduction of Delete Migration API\n\nThis PR also adds `DELETE`
method on route\n`/rules/siem_migrations/{migration_id}` for deleting a
migrations.\nDeleting a migration does below operations:\n\n- Stops a
migration if it is running\n- Deletes the rules, resources related to
migration and migration\ndocument itself.\n\n### File
Reorganizations\n\nDirectly structure has been changed a little bit to
reflect the\nendpoint. There is a sub-directory called `rules` which
deals with only\n`rules` of the migration and the root directly only
contains the\nendpoints related to the migration.\n\n####
Before\n\n```\n//siem_migrations/rules/api\n\n├── create.ts\n├──
get.ts\n├── start.ts\n├── update.ts\n├── \n├── \n├── \n```\n\n####
After\n\n```\n//siem_migrations/rules/api\n\n\n├── create.ts\n├──
delete.ts\n├── get.ts\n├── rules\n│   ├── add.ts\n│   ├── get.ts\n│  
└── update.ts\n├── \n├── \n├── \n```\n\n## Migration Strategy\n\n###
TL,DR; \n```mermaid\nflowchart TD\n StartM[Start Migration] -->
isMigExists{Does Migration Index Exists}\n isMigExists
-->|Yes|FetchMDoc[Fetch Migration Docs]\n isMigExists
-->|No|CreateMIndex[Create MigrationIndex]\n CreateMIndex -->
FetchMDoc\n FetchMDoc --> FetchMRules[Fetch Migration Stats Rules
index]\n FetchMRules --> FilterMigration{Filter Migration Docs not in
Migration Index}\n FilterMigration --> |is Empty|END[END]\n
FilterMigration --> |is Not Empty| CreateMDocs[Create Migration Docs]\n
CreateMDocs --> END\n```\n\n\n\nAt the time of merging this PR, the
Migration indices can be in 3\nstates:\n\n### There are migrations
created after\nhttps://github.com//pull/216164 and this
means that there\nare `some` migrations existing
in\n`.kibana-siem-migrations-migrations-<space_id>` and migrations
created\nbefore above mentioned PR will only exist
in\n`.kibana-siem-migrations-rules-<space_id>`.\n\nIn this case
`migrateRuleMigrationIndex` will create migration in below\nsteps:\n\n1.
Look for **all** migration Documents
in\n`.kibana-siem-migrations-migrations-<space_id>`\n2. Get **all**
Migrations stats from\n`.kibana-siem-migrations-rules-<space_id>` which
includes below\nproperties\n- migration_id : will help in reconciling
the migration id in\n.kibana-siem-migrations-migrations-<space_id>`
index\n - created_at : Date on which migration_id was created.\n -
created_by: User who created the migrations.\n3. A new document with
above migration will be added
to\n`.kibana-siem-migrations-migrations-<space_id>`.\n4. Now both
`.kibana-siem-migrations-migrations-<space_id>`
and\n`.kibana-siem-migrations-rules-<space_id>` will be in sync.\n\n###
Alternatively, there are no migration created
after\nhttps://github.com//pull/216164. In that case,
there is a\npossibility that
`.kibana-siem-migrations-migrations-<space_id>`, will\nnot even
exist.\n\nIn this case `migrateRuleMigrationIndex` will create migration
in below\nsteps:\n\n1. Create the
`.kibana-siem-migrations-migrations-<space_id>` index.\n2. Do steps
mentioned in above scenario.\n\n### Once the migrations has been run
successfully, both\n`.kibana-siem-migrations-migrations-<space_id>`
index and\n`.kibana-siem-migrations-rules-<space_id>` will be in
sync.\n\n1. In this case, migration will not run, since it tries to
filter the\nmigrations by `id` which exist
in\n`kibana-siem-migrations-rules-<space_id>` but do not exist
in\n`kibana-siem-migrations-migrations-<space_id>`\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] The PR
description includes the appropriate Release Notes section,\nand the
correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"bf642b00395079ef0e2f334b4fca65d2ff15d94c"}},"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/219597","number":219597,"mergeCommit":{"message":"[Automatic
Migrations] Siem migrations new endpoint (#219597)\n\n##
Summary\n\nResolves
https://github.com/elastic/security-team/issues/12483\n\nThis PR changes
REST API Endpoints scheme to align
with\nhttps://github.com/elastic/security-team/issues/12483. Below is
the\nsummary of changes done.\n\n### API Scheme changes\n\nThe REST API
scheme has been changed to
reflect\nhttps://github.com/elastic/security-team/issues/12483. This is
pretty\nmuch self explanatory as defined in below openapi schema yaml
:\n\n-\n[x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml](https://github.com/elastic/kibana/pull/219597/files#diff-3025af9eca156f3308474e2b42808da1531423457b7791daf6660db95a53b978)\n\n###
Introduction of Delete Migration API\n\nThis PR also adds `DELETE`
method on route\n`/rules/siem_migrations/{migration_id}` for deleting a
migrations.\nDeleting a migration does below operations:\n\n- Stops a
migration if it is running\n- Deletes the rules, resources related to
migration and migration\ndocument itself.\n\n### File
Reorganizations\n\nDirectly structure has been changed a little bit to
reflect the\nendpoint. There is a sub-directory called `rules` which
deals with only\n`rules` of the migration and the root directly only
contains the\nendpoints related to the migration.\n\n####
Before\n\n```\n//siem_migrations/rules/api\n\n├── create.ts\n├──
get.ts\n├── start.ts\n├── update.ts\n├── \n├── \n├── \n```\n\n####
After\n\n```\n//siem_migrations/rules/api\n\n\n├── create.ts\n├──
delete.ts\n├── get.ts\n├── rules\n│   ├── add.ts\n│   ├── get.ts\n│  
└── update.ts\n├── \n├── \n├── \n```\n\n## Migration Strategy\n\n###
TL,DR; \n```mermaid\nflowchart TD\n StartM[Start Migration] -->
isMigExists{Does Migration Index Exists}\n isMigExists
-->|Yes|FetchMDoc[Fetch Migration Docs]\n isMigExists
-->|No|CreateMIndex[Create MigrationIndex]\n CreateMIndex -->
FetchMDoc\n FetchMDoc --> FetchMRules[Fetch Migration Stats Rules
index]\n FetchMRules --> FilterMigration{Filter Migration Docs not in
Migration Index}\n FilterMigration --> |is Empty|END[END]\n
FilterMigration --> |is Not Empty| CreateMDocs[Create Migration Docs]\n
CreateMDocs --> END\n```\n\n\n\nAt the time of merging this PR, the
Migration indices can be in 3\nstates:\n\n### There are migrations
created after\nhttps://github.com//pull/216164 and this
means that there\nare `some` migrations existing
in\n`.kibana-siem-migrations-migrations-<space_id>` and migrations
created\nbefore above mentioned PR will only exist
in\n`.kibana-siem-migrations-rules-<space_id>`.\n\nIn this case
`migrateRuleMigrationIndex` will create migration in below\nsteps:\n\n1.
Look for **all** migration Documents
in\n`.kibana-siem-migrations-migrations-<space_id>`\n2. Get **all**
Migrations stats from\n`.kibana-siem-migrations-rules-<space_id>` which
includes below\nproperties\n- migration_id : will help in reconciling
the migration id in\n.kibana-siem-migrations-migrations-<space_id>`
index\n - created_at : Date on which migration_id was created.\n -
created_by: User who created the migrations.\n3. A new document with
above migration will be added
to\n`.kibana-siem-migrations-migrations-<space_id>`.\n4. Now both
`.kibana-siem-migrations-migrations-<space_id>`
and\n`.kibana-siem-migrations-rules-<space_id>` will be in sync.\n\n###
Alternatively, there are no migration created
after\nhttps://github.com//pull/216164. In that case,
there is a\npossibility that
`.kibana-siem-migrations-migrations-<space_id>`, will\nnot even
exist.\n\nIn this case `migrateRuleMigrationIndex` will create migration
in below\nsteps:\n\n1. Create the
`.kibana-siem-migrations-migrations-<space_id>` index.\n2. Do steps
mentioned in above scenario.\n\n### Once the migrations has been run
successfully, both\n`.kibana-siem-migrations-migrations-<space_id>`
index and\n`.kibana-siem-migrations-rules-<space_id>` will be in
sync.\n\n1. In this case, migration will not run, since it tries to
filter the\nmigrations by `id` which exist
in\n`kibana-siem-migrations-rules-<space_id>` but do not exist
in\n`kibana-siem-migrations-migrations-<space_id>`\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n\n- [x] Any text
added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] The PR
description includes the appropriate Release Notes section,\nand the
correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"bf642b00395079ef0e2f334b4fca65d2ff15d94c"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 27, 2025
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
## Summary

Resolves elastic/security-team#12483

This PR changes REST API Endpoints scheme to align with
elastic/security-team#12483. Below is the
summary of changes done.

### API Scheme changes

The REST API scheme has been changed to reflect
elastic/security-team#12483. This is pretty
much self explanatory as defined in below openapi schema yaml :

-
[x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml](https://github.com/elastic/kibana/pull/219597/files#diff-3025af9eca156f3308474e2b42808da1531423457b7791daf6660db95a53b978)

### Introduction of Delete Migration API

This PR also adds `DELETE` method on route
`/rules/siem_migrations/{migration_id}` for deleting a migrations.
Deleting a migration does below operations:

- Stops a migration if it is running
- Deletes the rules, resources related to migration and migration
document itself.

### File Reorganizations

Directly structure has been changed a little bit to reflect the
endpoint. There is a sub-directory called `rules` which deals with only
`rules` of the migration and the root directly only contains the
endpoints related to the migration.

#### Before

```
//siem_migrations/rules/api

├── create.ts
├── get.ts
├── start.ts
├── update.ts
├── 
├── 
├── 
```

#### After

```
//siem_migrations/rules/api


├── create.ts
├── delete.ts
├── get.ts
├── rules
│   ├── add.ts
│   ├── get.ts
│   └── update.ts
├── 
├── 
├── 
```

## Migration Strategy

### TL,DR; 
```mermaid
flowchart TD
    StartM[Start Migration] --> isMigExists{Does Migration Index Exists}
    isMigExists -->|Yes|FetchMDoc[Fetch Migration Docs]
    isMigExists -->|No|CreateMIndex[Create MigrationIndex]
    CreateMIndex --> FetchMDoc
    FetchMDoc --> FetchMRules[Fetch Migration Stats Rules index]
    FetchMRules --> FilterMigration{Filter Migration Docs not in Migration Index}
    FilterMigration --> |is Empty|END[END]
    FilterMigration --> |is Not Empty| CreateMDocs[Create Migration Docs]
    CreateMDocs --> END
```



At the time of merging this PR, the Migration indices can be in 3
states:

### There are migrations created after
elastic#216164 and this means that there
are `some` migrations existing in
`.kibana-siem-migrations-migrations-<space_id>` and migrations created
before above mentioned PR will only exist in
`.kibana-siem-migrations-rules-<space_id>`.

In this case `migrateRuleMigrationIndex` will create migration in below
steps:

1. Look for **all** migration Documents in
`.kibana-siem-migrations-migrations-<space_id>`
2. Get **all** Migrations stats from
`.kibana-siem-migrations-rules-<space_id>` which includes below
properties
- migration_id : will help in reconciling the migration id in
.kibana-siem-migrations-migrations-<space_id>` index
    - created_at : Date on which migration_id was created.
    - created_by: User who created the migrations.
3. A new document with above migration will be added to
`.kibana-siem-migrations-migrations-<space_id>`.
4. Now both `.kibana-siem-migrations-migrations-<space_id>` and
`.kibana-siem-migrations-rules-<space_id>` will be in sync.

### Alternatively, there are no migration created after
elastic#216164. In that case, there is a
possibility that `.kibana-siem-migrations-migrations-<space_id>`, will
not even exist.

In this case `migrateRuleMigrationIndex` will create migration in below
steps:

1. Create the `.kibana-siem-migrations-migrations-<space_id>` index.
2. Do steps mentioned in above scenario.

### Once the migrations has been run successfully, both
`.kibana-siem-migrations-migrations-<space_id>` index and
`.kibana-siem-migrations-rules-<space_id>` will be in sync.

1. In this case, migration will not run, since it tries to filter the
migrations by `id` which exist in
`kibana-siem-migrations-rules-<space_id>` but do not exist in
`kibana-siem-migrations-migrations-<space_id>`

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### 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.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
@jmikell821 jmikell821 added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Jun 2, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:feature Makes this part of the condensed release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants