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

[Session Index] Attach alias to index when index name changes #210176

Conversation

SiddharthMantri
Copy link
Contributor

@SiddharthMantri SiddharthMantri commented Feb 7, 2025

Closes #210179

Summary

While attempting to attach an alias to the session index, we were using .kibana_security_session_1 as the index name. However, the session index, if upgraded using the Upgrade assistant gets renamed to .kibana_security_session_1-reindexed-for-9 and .kibana_security_session_1 is set as an alias pointing to this index. When we try to reattach the alias using this as the index name, ES throws an error. This doesn't affect Kibana functionality but it increases the number of errors thrown in the logs.

This PR corrects this issue by attaching the alias to the index only when alias isn't already present. We now only assign the alias if not present - and not during creation of the index as it is created with the alias in it's settings.

Release note

Fixes the assignment of the Session index alias by only attaching it if not already present.

How to test

To see the error in the logs, you'll need at least 7.x and 8.x checked out locally. Once done, run bootstrap.

Step 1: On 7.17

  • Start ES with yarn es snapshot --license trial -E path.data=/tmp/esdata
  • Start Kibana and login with elastic user
  • You can check the contents of Kibana session index:
GET .kibana_security_session_1/_search
{
  "query": {
    "match_all": {}
  }
}

Should return a single document

  • You can now shut kibana and ES

Step 2: on 8.x

  • Make a backup of the esdata above cp -r /tmp/esdata /tmp/esdatabkp
  • Start ES as above yarn es snapshot --license trial -E path.data=/tmp/esdata
  • Start kibana and login
  • Navigate to Upgrade assistant. You should see at least 2 System indices that require migration (Security and Kibana)
  • Start the migrate index process (Step 2 in the UA interface)
  • Once done, trigger a local restart of kibana either by restarting using the start script or just triggering a file save on any file in your IDE
  • You should start seeing the error described above in 100ms increments till it reaches 10000ms and then it's every 10 seconds
  • Navigate to Dev tools and run
GET .kibana_security_session/_alias

You should see the index as

.kibana_security_session_reindexed-for-9 {
    aliases: {
        // aliases of the index including kibana_security_session_1
    }
}

Verify the fix

To verify, we have a couple of options - either clone the PR and go through the same steps as Step 2 above but for 9.0. The easier option is replace the code of function attachAliasToIndex in session_index.ts in 8.x with the changes in this PR. This should restart your kibana server and you will no longer see the error in the logs.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

@SiddharthMantri SiddharthMantri added backport release_note:fix Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v9.0.0 backport:prev-major Backport to (8.x, 8.18, 8.17, 8.16) the previous major branch and other branches in development v8.18.0 v9.1.0 v8.19.0 labels Feb 7, 2025
@SiddharthMantri SiddharthMantri marked this pull request as ready for review February 7, 2025 12:13
@SiddharthMantri SiddharthMantri requested a review from a team as a code owner February 7, 2025 12:13
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@SiddharthMantri SiddharthMantri changed the title [Session Index] Attach alias to index [Session Index] Attach alias to index when index name changes Feb 7, 2025
@kc13greiner kc13greiner self-requested a review February 7, 2025 15:23
Copy link
Contributor

@kc13greiner kc13greiner left a comment

Choose a reason for hiding this comment

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

A couple questions!

Copy link
Contributor

@kc13greiner kc13greiner left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for all the info

@SiddharthMantri
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

@SiddharthMantri SiddharthMantri merged commit 45d9fa0 into elastic:main Feb 12, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.17, 8.18, 8.x, 9.0

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 12, 2025
…c#210176)

Closes elastic#210179

## Summary

While attempting to attach an alias to the session index, we were using
`.kibana_security_session_1` as the index name. However, the session
index, if upgraded using the Upgrade assistant gets renamed to
`.kibana_security_session_1-reindexed-for-9` and
`.kibana_security_session_1` is set as an alias pointing to this index.
When we try to reattach the alias using this as the index name, ES
throws an error. This doesn't affect Kibana functionality but it
increases the number of errors thrown in the logs.

**This PR corrects this issue by attaching the alias to the index only
when alias isn't already present. We now only assign the alias if not
present - and not during creation of the index as it is created with the
alias in it's settings.**

### Release note
Fixes the assignment of the Session index alias by only attaching it if
not already present.

## How to test

To see the error in the logs, you'll need at least 7.x and 8.x checked
out locally. Once done, run bootstrap.

#### Step 1: On 7.17
- Start ES with `yarn es snapshot --license trial -E
path.data=/tmp/esdata`
- Start Kibana and login with elastic user
- You can check the contents of Kibana session index:

```
GET .kibana_security_session_1/_search
{
  "query": {
    "match_all": {}
  }
}
```
Should return a single document
- You can now shut kibana and ES

#### Step 2: on 8.x
- Make a backup of the esdata above `cp -r /tmp/esdata /tmp/esdatabkp`
- Start ES as above `yarn es snapshot --license trial -E
path.data=/tmp/esdata`
- Start kibana and login
- Navigate to Upgrade assistant. You should see at least 2 System
indices that require migration (Security and Kibana)
- Start the migrate index process (Step 2 in the UA interface)
- Once done, trigger a local restart of kibana either by restarting
using the start script or just triggering a file save on any file in
your IDE
- You should start seeing the error described above in 100ms increments
till it reaches 10000ms and then it's every 10 seconds
- Navigate to Dev tools and run
```
GET .kibana_security_session/_alias
```
You should see the index as
```
.kibana_security_session_reindexed-for-9 {
    aliases: {
        // aliases of the index including kibana_security_session_1
    }
}
```

#### Verify the fix
To verify, we have a couple of options - either clone the PR and go
through the same steps as Step 2 above but for 9.0. The easier option is
replace the code of function `attachAliasToIndex` in `session_index.ts`
in 8.x with the changes in this PR. This should restart your kibana
server and you will no longer see the error in the logs.

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [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)

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 45d9fa0)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 12, 2025
…c#210176)

Closes elastic#210179

## Summary

While attempting to attach an alias to the session index, we were using
`.kibana_security_session_1` as the index name. However, the session
index, if upgraded using the Upgrade assistant gets renamed to
`.kibana_security_session_1-reindexed-for-9` and
`.kibana_security_session_1` is set as an alias pointing to this index.
When we try to reattach the alias using this as the index name, ES
throws an error. This doesn't affect Kibana functionality but it
increases the number of errors thrown in the logs.

**This PR corrects this issue by attaching the alias to the index only
when alias isn't already present. We now only assign the alias if not
present - and not during creation of the index as it is created with the
alias in it's settings.**

### Release note
Fixes the assignment of the Session index alias by only attaching it if
not already present.

## How to test

To see the error in the logs, you'll need at least 7.x and 8.x checked
out locally. Once done, run bootstrap.

#### Step 1: On 7.17
- Start ES with `yarn es snapshot --license trial -E
path.data=/tmp/esdata`
- Start Kibana and login with elastic user
- You can check the contents of Kibana session index:

```
GET .kibana_security_session_1/_search
{
  "query": {
    "match_all": {}
  }
}
```
Should return a single document
- You can now shut kibana and ES

#### Step 2: on 8.x
- Make a backup of the esdata above `cp -r /tmp/esdata /tmp/esdatabkp`
- Start ES as above `yarn es snapshot --license trial -E
path.data=/tmp/esdata`
- Start kibana and login
- Navigate to Upgrade assistant. You should see at least 2 System
indices that require migration (Security and Kibana)
- Start the migrate index process (Step 2 in the UA interface)
- Once done, trigger a local restart of kibana either by restarting
using the start script or just triggering a file save on any file in
your IDE
- You should start seeing the error described above in 100ms increments
till it reaches 10000ms and then it's every 10 seconds
- Navigate to Dev tools and run
```
GET .kibana_security_session/_alias
```
You should see the index as
```
.kibana_security_session_reindexed-for-9 {
    aliases: {
        // aliases of the index including kibana_security_session_1
    }
}
```

#### Verify the fix
To verify, we have a couple of options - either clone the PR and go
through the same steps as Step 2 above but for 9.0. The easier option is
replace the code of function `attachAliasToIndex` in `session_index.ts`
in 8.x with the changes in this PR. This should restart your kibana
server and you will no longer see the error in the logs.

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [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)

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 45d9fa0)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 12, 2025
…c#210176)

Closes elastic#210179

## Summary

While attempting to attach an alias to the session index, we were using
`.kibana_security_session_1` as the index name. However, the session
index, if upgraded using the Upgrade assistant gets renamed to
`.kibana_security_session_1-reindexed-for-9` and
`.kibana_security_session_1` is set as an alias pointing to this index.
When we try to reattach the alias using this as the index name, ES
throws an error. This doesn't affect Kibana functionality but it
increases the number of errors thrown in the logs.

**This PR corrects this issue by attaching the alias to the index only
when alias isn't already present. We now only assign the alias if not
present - and not during creation of the index as it is created with the
alias in it's settings.**

### Release note
Fixes the assignment of the Session index alias by only attaching it if
not already present.

## How to test

To see the error in the logs, you'll need at least 7.x and 8.x checked
out locally. Once done, run bootstrap.

#### Step 1: On 7.17
- Start ES with `yarn es snapshot --license trial -E
path.data=/tmp/esdata`
- Start Kibana and login with elastic user
- You can check the contents of Kibana session index:

```
GET .kibana_security_session_1/_search
{
  "query": {
    "match_all": {}
  }
}
```
Should return a single document
- You can now shut kibana and ES

#### Step 2: on 8.x
- Make a backup of the esdata above `cp -r /tmp/esdata /tmp/esdatabkp`
- Start ES as above `yarn es snapshot --license trial -E
path.data=/tmp/esdata`
- Start kibana and login
- Navigate to Upgrade assistant. You should see at least 2 System
indices that require migration (Security and Kibana)
- Start the migrate index process (Step 2 in the UA interface)
- Once done, trigger a local restart of kibana either by restarting
using the start script or just triggering a file save on any file in
your IDE
- You should start seeing the error described above in 100ms increments
till it reaches 10000ms and then it's every 10 seconds
- Navigate to Dev tools and run
```
GET .kibana_security_session/_alias
```
You should see the index as
```
.kibana_security_session_reindexed-for-9 {
    aliases: {
        // aliases of the index including kibana_security_session_1
    }
}
```

#### Verify the fix
To verify, we have a couple of options - either clone the PR and go
through the same steps as Step 2 above but for 9.0. The easier option is
replace the code of function `attachAliasToIndex` in `session_index.ts`
in 8.x with the changes in this PR. This should restart your kibana
server and you will no longer see the error in the logs.

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [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)

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 45d9fa0)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.16 Backport failed because of merge conflicts
8.17 Backport failed because of merge conflicts
8.18
8.x
9.0

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

Manual backport

To create the backport manually run:

node scripts/backport --pr 210176

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Feb 12, 2025
…210176) (#210738)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[Session Index] Attach alias to index when index name changes
(#210176)](#210176)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT
[{"author":{"name":"Sid","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-02-12T07:00:21Z","message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport","release_note:fix","Team:Security","v9.0.0","backport:prev-major","v8.18.0","v9.1.0","v8.19.0"],"title":"[Session
Index] Attach alias to index when index name
changes","number":210176,"url":"https://github.com/elastic/kibana/pull/210176","mergeCommit":{"message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210176","number":210176,"mergeCommit":{"message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Sid <[email protected]>
kibanamachine added a commit that referenced this pull request Feb 12, 2025
…210176) (#210739)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Session Index] Attach alias to index when index name changes
(#210176)](#210176)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT
[{"author":{"name":"Sid","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-02-12T07:00:21Z","message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport","release_note:fix","Team:Security","v9.0.0","backport:prev-major","v8.18.0","v9.1.0","v8.19.0"],"title":"[Session
Index] Attach alias to index when index name
changes","number":210176,"url":"https://github.com/elastic/kibana/pull/210176","mergeCommit":{"message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210176","number":210176,"mergeCommit":{"message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Sid <[email protected]>
kibanamachine added a commit that referenced this pull request Feb 12, 2025
…210176) (#210740)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Session Index] Attach alias to index when index name changes
(#210176)](#210176)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT
[{"author":{"name":"Sid","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-02-12T07:00:21Z","message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport","release_note:fix","Team:Security","v9.0.0","backport:prev-major","v8.18.0","v9.1.0","v8.19.0"],"title":"[Session
Index] Attach alias to index when index name
changes","number":210176,"url":"https://github.com/elastic/kibana/pull/210176","mergeCommit":{"message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210176","number":210176,"mergeCommit":{"message":"[Session
Index] Attach alias to index when index name changes (#210176)\n\nCloses
https://github.com/elastic/kibana/issues/210179\r\n\r\n##
Summary\r\n\r\nWhile attempting to attach an alias to the session index,
we were using\r\n`.kibana_security_session_1` as the index name.
However, the session\r\nindex, if upgraded using the Upgrade assistant
gets renamed to\r\n`.kibana_security_session_1-reindexed-for-9`
and\r\n`.kibana_security_session_1` is set as an alias pointing to this
index.\r\nWhen we try to reattach the alias using this as the index
name, ES\r\nthrows an error. This doesn't affect Kibana functionality
but it\r\nincreases the number of errors thrown in the
logs.\r\n\r\n**This PR corrects this issue by attaching the alias to the
index only\r\nwhen alias isn't already present. We now only assign the
alias if not\r\npresent - and not during creation of the index as it is
created with the\r\nalias in it's settings.**\r\n\r\n### Release
note\r\nFixes the assignment of the Session index alias by only
attaching it if\r\nnot already present.\r\n\r\n## How to test\r\n\r\nTo
see the error in the logs, you'll need at least 7.x and 8.x
checked\r\nout locally. Once done, run bootstrap.\r\n\r\n#### Step 1: On
7.17\r\n- Start ES with `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start Kibana and login with elastic
user\r\n- You can check the contents of Kibana session
index:\r\n\r\n```\r\nGET .kibana_security_session_1/_search\r\n{\r\n
\"query\": {\r\n \"match_all\": {}\r\n }\r\n}\r\n```\r\nShould return a
single document\r\n- You can now shut kibana and ES\r\n\r\n\r\n#### Step
2: on 8.x\r\n- Make a backup of the esdata above `cp -r /tmp/esdata
/tmp/esdatabkp`\r\n- Start ES as above `yarn es snapshot --license trial
-E\r\npath.data=/tmp/esdata`\r\n- Start kibana and login\r\n- Navigate
to Upgrade assistant. You should see at least 2 System\r\nindices that
require migration (Security and Kibana)\r\n- Start the migrate index
process (Step 2 in the UA interface)\r\n- Once done, trigger a local
restart of kibana either by restarting\r\nusing the start script or just
triggering a file save on any file in\r\nyour IDE\r\n- You should start
seeing the error described above in 100ms increments\r\ntill it reaches
10000ms and then it's every 10 seconds\r\n- Navigate to Dev tools and
run\r\n```\r\nGET .kibana_security_session/_alias\r\n```\r\nYou should
see the index as \r\n```\r\n.kibana_security_session_reindexed-for-9
{\r\n aliases: {\r\n // aliases of the index including
kibana_security_session_1\r\n }\r\n}\r\n```\r\n\r\n#### Verify the
fix\r\nTo verify, we have a couple of options - either clone the PR and
go\r\nthrough the same steps as Step 2 above but for 9.0. The easier
option is\r\nreplace the code of function `attachAliasToIndex` in
`session_index.ts`\r\nin 8.x with the changes in this PR. This should
restart your kibana\r\nserver and you will no longer see the error in
the logs.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies
following conditions. \r\n\r\nReviewers should verify this PR satisfies
this list as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"45d9fa01feaba65d433473519215982c5a600947"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Sid <[email protected]>
@SiddharthMantri SiddharthMantri added backport:version Backport to applied version labels and removed backport:prev-major Backport to (8.x, 8.18, 8.17, 8.16) the previous major branch and other branches in development labels Feb 12, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.17, 8.18, 8.x, 9.0

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

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 backport release_note:fix Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.18.0 v8.19.0 v9.0.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix issue with attaching alias to session index if it was reindexed for 9.0
4 participants