Skip to content

Comments

[Entity Analytics][Privmon] Fix Privileged user monitoring index sync in non-default spaces#230420

Merged
hop-dev merged 7 commits intoelastic:mainfrom
hop-dev:privmon-task-space-bug
Aug 5, 2025
Merged

[Entity Analytics][Privmon] Fix Privileged user monitoring index sync in non-default spaces#230420
hop-dev merged 7 commits intoelastic:mainfrom
hop-dev:privmon-task-space-bug

Conversation

@hop-dev
Copy link
Contributor

@hop-dev hop-dev commented Aug 4, 2025

Summary

Closes #13399

Fixes a bug where syncing privileged users from an index failed in spaces other than "default".

The issue was that we could not find the API key saved object, this is because we weren't specifying the namespace when we searched for it.

Test Steps

  • create a space "space2"
  • switch to space2
  • enable privileged usr monitoring advanced setting
  • create an index to sync users from:
# create index with correct mapping
PUT /my-custom-index
{
  "mappings" : {
    "properties": {
      "user.name": {
        "type": "keyword"
      }
    }
  }
}

# add a user
POST /_bulk
{ "index": { "_index": "my-custom-index" } }
{ "user": { "name": "tiago" } }
  • add a document to skip the onboarding screen
POST /logs-test-hello/_doc
{
  "message" : "sup"
}
  • go to privileged user monitoring onbaording
  • select your index to sync
  • (it should work and load the users)

@hop-dev hop-dev changed the title fix bug [Entity Analytics][Privmon] Fix index sync in non-default spaces Aug 4, 2025
@hop-dev hop-dev self-assigned this Aug 4, 2025
@hop-dev hop-dev added bug Fixes for quality problems that affect the customer experience release_note:fix Team:Entity Analytics Security Entity Analytics Team v9.0.2 backport:prev-minor backport:version Backport to applied version labels and removed v9.0.2 backport:version Backport to applied version labels labels Aug 4, 2025
const apiKey = await generateAPIKey(request, deps);

const soClient = core.savedObjects.getScopedClient(request, {
const soClient = core.savedObjects.getUnsafeInternalClient({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this isn't the fix just a nicer way of getting a client

@hop-dev hop-dev marked this pull request as ready for review August 4, 2025 15:34
@hop-dev hop-dev requested a review from a team as a code owner August 4, 2025 15:34
@hop-dev hop-dev requested a review from machadoum August 4, 2025 15:34
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-entity-analytics (Team:Entity Analytics)

@hop-dev hop-dev enabled auto-merge (squash) August 4, 2025 15:34
@jaredburgettelastic
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@jaredburgettelastic jaredburgettelastic left a comment

Choose a reason for hiding this comment

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

I haven't diagnosed exactly why, but local testing didn't pass on this PR yet for me 🤔

Index sync fails entirely, and here is the error log I'm seeing

[2025-08-04T19:04:36.984-05:00][ERROR][plugins.securitySolution] [Privileged Monitoring Engine][namespace: default] Error initializing privilege monitoring engine: Error: Namespace cannot be specified by the caller when the spaces extension is enabled. Spaces currently determines the namespace.

@machadoum
Copy link
Member

desk-tested
Screenshot 2025-08-05 at 09 06 56

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @hop-dev

@hop-dev
Copy link
Contributor Author

hop-dev commented Aug 5, 2025

@elasticmachine merge upstream

@hop-dev hop-dev merged commit 6f9d1a3 into elastic:main Aug 5, 2025
12 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.1

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 5, 2025
…stic#230420)

## Summary

Closes [elastic#13399](elastic/security-team#13399)

Fixes a bug where syncing privileged users from an index failed in
spaces other than "default".

The issue was that we could not find the API key saved object, this is
because we weren't specifying the namespace when we searched for it.

### Test Steps

- create a space "space2"
- switch to space2
- enable privileged usr monitoring advanced setting
- create an index to sync users from:

```
# create index with correct mapping
PUT /my-custom-index
{
  "mappings" : {
    "properties": {
      "user.name": {
        "type": "keyword"
      }
    }
  }
}

# add a user
POST /_bulk
{ "index": { "_index": "my-custom-index" } }
{ "user": { "name": "tiago" } }
```

- add a document to skip the onboarding screen

```
POST /logs-test-hello/_doc
{
  "message" : "sup"
}
```
- go to privileged user monitoring onbaording
- select your index to sync
- (it should work and load the users)

(cherry picked from commit 6f9d1a3)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
9.1

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

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Aug 5, 2025
#230420) (#230563)

# Backport

This will backport the following commits from `main` to `9.1`:
- [[Entity Analytics][Privmon] Fix index sync in non-default spaces
(#230420)](#230420)

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

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

<!--BACKPORT [{"author":{"name":"Mark
Hopkin","email":"mark.hopkin@elastic.co"},"sourceCommit":{"committedDate":"2025-08-05T12:04:06Z","message":"[Entity
Analytics][Privmon] Fix index sync in non-default spaces (#230420)\n\n##
Summary\n\nCloses
[#13399](https://github.com/elastic/security-team/issues/13399)\n\nFixes
a bug where syncing privileged users from an index failed in\nspaces
other than \"default\".\n\nThe issue was that we could not find the API
key saved object, this is\nbecause we weren't specifying the namespace
when we searched for it.\n\n### Test Steps\n\n- create a space
\"space2\"\n- switch to space2\n- enable privileged usr monitoring
advanced setting\n- create an index to sync users from:\n\n```\n# create
index with correct mapping\nPUT /my-custom-index\n{\n \"mappings\" : {\n
\"properties\": {\n \"user.name\": {\n \"type\": \"keyword\"\n }\n }\n
}\n}\n\n# add a user\nPOST /_bulk\n{ \"index\": { \"_index\":
\"my-custom-index\" } }\n{ \"user\": { \"name\": \"tiago\" } }\n```\n\n-
add a document to skip the onboarding screen\n\n```\nPOST
/logs-test-hello/_doc\n{\n \"message\" : \"sup\"\n}\n```\n- go to
privileged user monitoring onbaording\n- select your index to sync\n-
(it should work and load the
users)","sha":"6f9d1a3a323f939f1471c41bad856449f8f55ffd","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","backport:prev-minor","Team:Entity
Analytics","v9.2.0"],"title":"[Entity Analytics][Privmon] Fix index sync
in non-default
spaces","number":230420,"url":"https://github.com/elastic/kibana/pull/230420","mergeCommit":{"message":"[Entity
Analytics][Privmon] Fix index sync in non-default spaces (#230420)\n\n##
Summary\n\nCloses
[#13399](https://github.com/elastic/security-team/issues/13399)\n\nFixes
a bug where syncing privileged users from an index failed in\nspaces
other than \"default\".\n\nThe issue was that we could not find the API
key saved object, this is\nbecause we weren't specifying the namespace
when we searched for it.\n\n### Test Steps\n\n- create a space
\"space2\"\n- switch to space2\n- enable privileged usr monitoring
advanced setting\n- create an index to sync users from:\n\n```\n# create
index with correct mapping\nPUT /my-custom-index\n{\n \"mappings\" : {\n
\"properties\": {\n \"user.name\": {\n \"type\": \"keyword\"\n }\n }\n
}\n}\n\n# add a user\nPOST /_bulk\n{ \"index\": { \"_index\":
\"my-custom-index\" } }\n{ \"user\": { \"name\": \"tiago\" } }\n```\n\n-
add a document to skip the onboarding screen\n\n```\nPOST
/logs-test-hello/_doc\n{\n \"message\" : \"sup\"\n}\n```\n- go to
privileged user monitoring onbaording\n- select your index to sync\n-
(it should work and load the
users)","sha":"6f9d1a3a323f939f1471c41bad856449f8f55ffd"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/230420","number":230420,"mergeCommit":{"message":"[Entity
Analytics][Privmon] Fix index sync in non-default spaces (#230420)\n\n##
Summary\n\nCloses
[#13399](https://github.com/elastic/security-team/issues/13399)\n\nFixes
a bug where syncing privileged users from an index failed in\nspaces
other than \"default\".\n\nThe issue was that we could not find the API
key saved object, this is\nbecause we weren't specifying the namespace
when we searched for it.\n\n### Test Steps\n\n- create a space
\"space2\"\n- switch to space2\n- enable privileged usr monitoring
advanced setting\n- create an index to sync users from:\n\n```\n# create
index with correct mapping\nPUT /my-custom-index\n{\n \"mappings\" : {\n
\"properties\": {\n \"user.name\": {\n \"type\": \"keyword\"\n }\n }\n
}\n}\n\n# add a user\nPOST /_bulk\n{ \"index\": { \"_index\":
\"my-custom-index\" } }\n{ \"user\": { \"name\": \"tiago\" } }\n```\n\n-
add a document to skip the onboarding screen\n\n```\nPOST
/logs-test-hello/_doc\n{\n \"message\" : \"sup\"\n}\n```\n- go to
privileged user monitoring onbaording\n- select your index to sync\n-
(it should work and load the
users)","sha":"6f9d1a3a323f939f1471c41bad856449f8f55ffd"}}]}]
BACKPORT-->

Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
delanni pushed a commit to delanni/kibana that referenced this pull request Aug 5, 2025
…stic#230420)

## Summary

Closes [elastic#13399](elastic/security-team#13399)

Fixes a bug where syncing privileged users from an index failed in
spaces other than "default".

The issue was that we could not find the API key saved object, this is
because we weren't specifying the namespace when we searched for it.

### Test Steps

- create a space "space2"
- switch to space2
- enable privileged usr monitoring advanced setting
- create an index to sync users from:

```
# create index with correct mapping
PUT /my-custom-index
{
  "mappings" : {
    "properties": {
      "user.name": {
        "type": "keyword"
      }
    }
  }
}

# add a user
POST /_bulk
{ "index": { "_index": "my-custom-index" } }
{ "user": { "name": "tiago" } }
```

- add a document to skip the onboarding screen

```
POST /logs-test-hello/_doc
{
  "message" : "sup"
}
```
- go to privileged user monitoring onbaording
- select your index to sync
- (it should work and load the users)
@wildemat wildemat mentioned this pull request Aug 7, 2025
10 tasks
@mistic mistic added v9.1.2 and removed v9.1.1 labels Aug 7, 2025
@jaredburgettelastic jaredburgettelastic changed the title [Entity Analytics][Privmon] Fix index sync in non-default spaces [Entity Analytics][Privmon] Fix Privileged user monitoring index sync in non-default spaces Aug 11, 2025
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Aug 18, 2025
…stic#230420)

## Summary

Closes [elastic#13399](elastic/security-team#13399)

Fixes a bug where syncing privileged users from an index failed in
spaces other than "default".

The issue was that we could not find the API key saved object, this is
because we weren't specifying the namespace when we searched for it.

### Test Steps

- create a space "space2"
- switch to space2
- enable privileged usr monitoring advanced setting
- create an index to sync users from:

```
# create index with correct mapping
PUT /my-custom-index
{
  "mappings" : {
    "properties": {
      "user.name": {
        "type": "keyword"
      }
    }
  }
}

# add a user
POST /_bulk
{ "index": { "_index": "my-custom-index" } }
{ "user": { "name": "tiago" } }
```

- add a document to skip the onboarding screen

```
POST /logs-test-hello/_doc
{
  "message" : "sup"
}
```
- go to privileged user monitoring onbaording
- select your index to sync
- (it should work and load the users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes for quality problems that affect the customer experience release_note:fix Team:Entity Analytics Security Entity Analytics Team v9.1.2 v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants