Skip to content

Conversation

@CAWilson94
Copy link
Contributor

@CAWilson94 CAWilson94 commented Aug 1, 2025

Summary

This PR moves the scheduleNow call from the monitoring engine initialization to the privilege monitoring initialisation step. This change ensures the task is only scheduled after the Privileged Monitoring Engine has been properly created and is ready — resolving the dependency issue.

The flow for starting a sync with the monitoring engine is -

  1. Create privileged users.
  2. Register these with the monitoring source
  3. Initialise the privilege monitoring engine - will trigger scheduleNow, and therefore the task.

Also added a try catch around engine status for handling the case of status undefined within scheduleNow call.

Testing Changes

  1. Open fresh kibana and ES
  2. Enable Advanced Settings

UI Test:

  1. Navigate to privileged monitoring page
  2. Select index modal - create new index from here
  3. Select 'add Privileged users'

Look at kibana logs - "Running privilege monitoring task" should show
UI should have closed modal, onto the privmon screen.

Dev Tools Test:

  1. Create test index/ indicies
PUT /tatooine-
{
  "mappings": {
    "properties": {
      "user": {
        "properties": {
          "name": {
            "type": "keyword",
            "fields": {
              "text": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

  1. OPTIONAL - Add some users to this
POST tatooine-/_bulk
{ "index": {} }
{ "user": { "name": "Luke Skywalker" } }
{ "index": {} }
{ "user": { "name": "Leia Organa" } }
{ "index": {} }
{ "user": { "name": "Han Solo" } }
{ "index": {} }
{ "user": { "name": "Chewbacca" } }
{ "index": {} }
{ "user": { "name": "Obi-Wan Kenobi" } }
{ "index": {} }
{ "user": { "name": "Yoda" } }
{ "index": {} }
{ "user": { "name": "R2-D2" } }
{ "index": {} }
{ "user": { "name": "C-3PO" } }
{ "index": {} }
{ "user": { "name": "Darth Vader" } }
  1. Register Monitoring Entity Source Saved Objects
POST kbn:/api/entity_analytics/monitoring/entity_source
{
  "type": "index",
  "name": "StarWars",
  "managed": true,
  "indexPattern": "tatooine-",
  "enabled": true,
 "matchers": [
    {
      "fields": ["user.role"],
      "values": ["admin"]
    }
  ],
  "filter": {}
}
 
  1. Initialise monitoring engine:
POST kbn:/api/entity_analytics/monitoring/engine/init {}

Should all work as expected (famous last words)

…e is initalised. Add try catch around engine status to cover undefined case as well as not running.
@CAWilson94 CAWilson94 requested a review from a team as a code owner August 1, 2025 15:23
@CAWilson94 CAWilson94 added release_note:fix Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Theme: entity_analytics Feature:Entity Analytics Security Solution Entity Analytics features Team:Entity Analytics Security Entity Analytics Team backport:version Backport to applied version labels labels Aug 1, 2025
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@CAWilson94 CAWilson94 enabled auto-merge (squash) August 1, 2025 18:47
Comment on lines 147 to 150

const privMonDataClient = await secSol.getPrivilegeMonitoringDataClient();
await privMonDataClient.scheduleNow();

Copy link
Member

Choose a reason for hiding this comment

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

I believe that after this change, the schedule won't run after an update, which is the desired scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, I thought it would still be running the same task that was triggered by privmon data client init, so would pick up from there. But will put this back in if its not the case - I think update should be safe and have resources then.

@machadoum
Copy link
Member

machadoum commented Aug 4, 2025

Hey @CAWilson94!

You have identified the problem with precision. We try to schedule the engine before it is installed. But the current solution causes another problem. I think we need to solve the bug in the source.

From what I understand, it comes from:

    const currentEngineStatus = await this.getEngineStatus();

My suggestion is to update getEngineStatus so it doesn't throw an error when the engine is not installed. Instead, it should return that it is not installed.

That would require adding a new status, and we must be aware that this will impact other places that call getEngineStatus, which will also be affected, like healthCheckPrivilegeMonitoringRoute.

A quicker solution is to swallow the exception on schedule.now implementation and only log it.

@CAWilson94 CAWilson94 requested a review from machadoum August 4, 2025 07:23
@machadoum machadoum disabled auto-merge August 4, 2025 07:46
Comment on lines -21 to -24
'installing',
'started',
'stopped',
'updating',
Copy link
Member

Choose a reason for hiding this comment

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

This was wrong

'updating',
'error',
'disabled',
'not_installed',
Copy link
Member

Choose a reason for hiding this comment

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

I added a new status return by getEngineStatus, instead of throwing an error.

Comment on lines +74 to +75
} catch (e) {
logger.warn(`[Privilege Monitoring] Error scheduling task, received ${e.message}`);
Copy link
Member

Choose a reason for hiding this comment

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

If the schedule fails, we warn in the console but keep going...

const engineStatus = await privMonDataClient.getEngineStatus();

try {
if (engineStatus.status === PRIVILEGE_MONITORING_ENGINE_STATUS.STARTED) {
Copy link
Member

@machadoum machadoum Aug 4, 2025

Choose a reason for hiding this comment

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

Only schedule if the engine is enabled.

This line is the main bug fix; all other changes are extra safety checks to prevent the same bug from happening when calling scheduleNow from other areas.

Copy link
Contributor

Choose a reason for hiding this comment

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

shouldnt the scheduleNow do all those checks instead?

Comment on lines +245 to +246
status: PRIVILEGE_MONITORING_ENGINE_STATUS.NOT_INSTALLED,
error: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

This isn't strictly required for the bug fix, but it is a good way to prevent similar bugs in the future.

@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner August 4, 2025 10:45
Copy link
Contributor

@tiansivive tiansivive left a comment

Choose a reason for hiding this comment

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

I think this fixes the bug but we should double check if we can do all the required cehcks inside the ScheduleNow function

@hop-dev
Copy link
Contributor

hop-dev commented Aug 4, 2025

Tested locally 👍

Copy link
Contributor

@natasha-moore-elastic natasha-moore-elastic left a comment

Choose a reason for hiding this comment

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

Approved for Docs

@hop-dev hop-dev enabled auto-merge (squash) August 4, 2025 14:54
@hop-dev hop-dev merged commit 20ea09a into elastic:main Aug 4, 2025
12 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.1

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

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 7814 7815 +1

Async chunks

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

id before after diff
securitySolution 10.3MB 10.3MB +411.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 94.4KB 94.4KB -1.0B

History

kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Aug 4, 2025
…ource engine - bug fix (elastic#230263)

## Summary
This PR moves the scheduleNow call from the monitoring engine
initialization to the privilege monitoring initialisation step. This
change ensures the task is only scheduled after the Privileged
Monitoring Engine has been properly created and is ready — resolving the
dependency issue.

The flow for starting a sync with the monitoring engine is -
1. Create privileged users.
2. Register these with the monitoring source
3. Initialise the privilege monitoring engine - will trigger
scheduleNow, and therefore the task.

Also added a try catch around engine status for handling the case of
status undefined within scheduleNow call.

### Testing Changes
1. Open fresh kibana and ES
2. Enable Advanced Settings

**UI Test:**
1. Navigate to privileged monitoring page
2. Select index modal - create new index from here
3. Select 'add Privileged users'

Look at kibana logs - "Running privilege monitoring task" should show
UI should have closed modal, onto the privmon screen.

**Dev Tools Test:**
1. **Create test index/ indicies**

```
PUT /tatooine-
{
  "mappings": {
    "properties": {
      "user": {
        "properties": {
          "name": {
            "type": "keyword",
            "fields": {
              "text": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

```
2. **OPTIONAL - Add some users to this**
```
POST tatooine-/_bulk
{ "index": {} }
{ "user": { "name": "Luke Skywalker" } }
{ "index": {} }
{ "user": { "name": "Leia Organa" } }
{ "index": {} }
{ "user": { "name": "Han Solo" } }
{ "index": {} }
{ "user": { "name": "Chewbacca" } }
{ "index": {} }
{ "user": { "name": "Obi-Wan Kenobi" } }
{ "index": {} }
{ "user": { "name": "Yoda" } }
{ "index": {} }
{ "user": { "name": "R2-D2" } }
{ "index": {} }
{ "user": { "name": "C-3PO" } }
{ "index": {} }
{ "user": { "name": "Darth Vader" } }
```
3. **Register Monitoring Entity Source Saved Objects**
```
POST kbn:/api/entity_analytics/monitoring/entity_source
{
  "type": "index",
  "name": "StarWars",
  "managed": true,
  "indexPattern": "tatooine-",
  "enabled": true,
 "matchers": [
    {
      "fields": ["user.role"],
      "values": ["admin"]
    }
  ],
  "filter": {}
}

```
4. **Initialise monitoring engine:**
```
POST kbn:/api/entity_analytics/monitoring/engine/init {}
```
Should all work as expected (famous last words)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: machadoum <pablo.nevesmachado@elastic.co>
(cherry picked from commit 20ea09a)
@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 4, 2025
…ring source engine - bug fix (#230263) (#230451)

# Backport

This will backport the following commits from `main` to `9.1`:
- [Moved scheduleNow call to privmon engine init instead of monitoring
source engine - bug fix
(#230263)](#230263)

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

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

<!--BACKPORT [{"author":{"name":"Charlotte Alexandra
Wilson","email":"CAWilson94@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-08-04T16:04:33Z","message":"Moved
scheduleNow call to privmon engine init instead of monitoring source
engine - bug fix (#230263)\n\n## Summary \nThis PR moves the scheduleNow
call from the monitoring engine\ninitialization to the privilege
monitoring initialisation step. This\nchange ensures the task is only
scheduled after the Privileged\nMonitoring Engine has been properly
created and is ready — resolving the\ndependency issue.\n\nThe flow for
starting a sync with the monitoring engine is - \n1. Create privileged
users. \n2. Register these with the monitoring source \n3. Initialise
the privilege monitoring engine - will trigger\nscheduleNow, and
therefore the task.\n\nAlso added a try catch around engine status for
handling the case of\nstatus undefined within scheduleNow call.\n\n\n###
Testing Changes \n1. Open fresh kibana and ES \n2. Enable Advanced
Settings \n\n**UI Test:** \n1. Navigate to privileged monitoring page
\n2. Select index modal - create new index from here \n3. Select 'add
Privileged users' \n\nLook at kibana logs - \"Running privilege
monitoring task\" should show\nUI should have closed modal, onto the
privmon screen.\n\n**Dev Tools Test:** \n1. **Create test index/
indicies**\n\n```\nPUT /tatooine-\n{\n \"mappings\": {\n \"properties\":
{\n \"user\": {\n \"properties\": {\n \"name\": {\n \"type\":
\"keyword\",\n \"fields\": {\n \"text\": {\n \"type\": \"text\"\n }\n
}\n }\n }\n }\n }\n }\n}\n\n```\n2. **OPTIONAL - Add some users to
this**\n```\nPOST tatooine-/_bulk\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Luke Skywalker\" } }\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Leia Organa\" } }\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Han Solo\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\":
\"Chewbacca\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\": \"Obi-Wan
Kenobi\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\": \"Yoda\" } }\n{
\"index\": {} }\n{ \"user\": { \"name\": \"R2-D2\" } }\n{ \"index\": {}
}\n{ \"user\": { \"name\": \"C-3PO\" } }\n{ \"index\": {} }\n{ \"user\":
{ \"name\": \"Darth Vader\" } }\n``` \n3. **Register Monitoring Entity
Source Saved Objects**\n```\nPOST
kbn:/api/entity_analytics/monitoring/entity_source\n{\n \"type\":
\"index\",\n \"name\": \"StarWars\",\n \"managed\": true,\n
\"indexPattern\": \"tatooine-\",\n \"enabled\": true,\n \"matchers\":
[\n {\n \"fields\": [\"user.role\"],\n \"values\": [\"admin\"]\n }\n
],\n \"filter\": {}\n}\n \n```\n4. **Initialise monitoring engine:**
\n```\nPOST kbn:/api/entity_analytics/monitoring/engine/init {}\n```
\nShould all work as expected (famous last
words)\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
machadoum
<pablo.nevesmachado@elastic.co>","sha":"20ea09af7fa857d75449cf2a9a2b7b2316023132","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:
SecuritySolution","Theme: entity_analytics","Feature:Entity
Analytics","Team:Entity
Analytics","backport:version","v9.2.0","v9.1.1"],"title":"Moved
scheduleNow call to privmon engine init instead of monitoring source
engine - bug
fix","number":230263,"url":"https://github.com/elastic/kibana/pull/230263","mergeCommit":{"message":"Moved
scheduleNow call to privmon engine init instead of monitoring source
engine - bug fix (#230263)\n\n## Summary \nThis PR moves the scheduleNow
call from the monitoring engine\ninitialization to the privilege
monitoring initialisation step. This\nchange ensures the task is only
scheduled after the Privileged\nMonitoring Engine has been properly
created and is ready — resolving the\ndependency issue.\n\nThe flow for
starting a sync with the monitoring engine is - \n1. Create privileged
users. \n2. Register these with the monitoring source \n3. Initialise
the privilege monitoring engine - will trigger\nscheduleNow, and
therefore the task.\n\nAlso added a try catch around engine status for
handling the case of\nstatus undefined within scheduleNow call.\n\n\n###
Testing Changes \n1. Open fresh kibana and ES \n2. Enable Advanced
Settings \n\n**UI Test:** \n1. Navigate to privileged monitoring page
\n2. Select index modal - create new index from here \n3. Select 'add
Privileged users' \n\nLook at kibana logs - \"Running privilege
monitoring task\" should show\nUI should have closed modal, onto the
privmon screen.\n\n**Dev Tools Test:** \n1. **Create test index/
indicies**\n\n```\nPUT /tatooine-\n{\n \"mappings\": {\n \"properties\":
{\n \"user\": {\n \"properties\": {\n \"name\": {\n \"type\":
\"keyword\",\n \"fields\": {\n \"text\": {\n \"type\": \"text\"\n }\n
}\n }\n }\n }\n }\n }\n}\n\n```\n2. **OPTIONAL - Add some users to
this**\n```\nPOST tatooine-/_bulk\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Luke Skywalker\" } }\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Leia Organa\" } }\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Han Solo\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\":
\"Chewbacca\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\": \"Obi-Wan
Kenobi\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\": \"Yoda\" } }\n{
\"index\": {} }\n{ \"user\": { \"name\": \"R2-D2\" } }\n{ \"index\": {}
}\n{ \"user\": { \"name\": \"C-3PO\" } }\n{ \"index\": {} }\n{ \"user\":
{ \"name\": \"Darth Vader\" } }\n``` \n3. **Register Monitoring Entity
Source Saved Objects**\n```\nPOST
kbn:/api/entity_analytics/monitoring/entity_source\n{\n \"type\":
\"index\",\n \"name\": \"StarWars\",\n \"managed\": true,\n
\"indexPattern\": \"tatooine-\",\n \"enabled\": true,\n \"matchers\":
[\n {\n \"fields\": [\"user.role\"],\n \"values\": [\"admin\"]\n }\n
],\n \"filter\": {}\n}\n \n```\n4. **Initialise monitoring engine:**
\n```\nPOST kbn:/api/entity_analytics/monitoring/engine/init {}\n```
\nShould all work as expected (famous last
words)\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
machadoum
<pablo.nevesmachado@elastic.co>","sha":"20ea09af7fa857d75449cf2a9a2b7b2316023132"}},"sourceBranch":"main","suggestedTargetBranches":["9.1"],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/230263","number":230263,"mergeCommit":{"message":"Moved
scheduleNow call to privmon engine init instead of monitoring source
engine - bug fix (#230263)\n\n## Summary \nThis PR moves the scheduleNow
call from the monitoring engine\ninitialization to the privilege
monitoring initialisation step. This\nchange ensures the task is only
scheduled after the Privileged\nMonitoring Engine has been properly
created and is ready — resolving the\ndependency issue.\n\nThe flow for
starting a sync with the monitoring engine is - \n1. Create privileged
users. \n2. Register these with the monitoring source \n3. Initialise
the privilege monitoring engine - will trigger\nscheduleNow, and
therefore the task.\n\nAlso added a try catch around engine status for
handling the case of\nstatus undefined within scheduleNow call.\n\n\n###
Testing Changes \n1. Open fresh kibana and ES \n2. Enable Advanced
Settings \n\n**UI Test:** \n1. Navigate to privileged monitoring page
\n2. Select index modal - create new index from here \n3. Select 'add
Privileged users' \n\nLook at kibana logs - \"Running privilege
monitoring task\" should show\nUI should have closed modal, onto the
privmon screen.\n\n**Dev Tools Test:** \n1. **Create test index/
indicies**\n\n```\nPUT /tatooine-\n{\n \"mappings\": {\n \"properties\":
{\n \"user\": {\n \"properties\": {\n \"name\": {\n \"type\":
\"keyword\",\n \"fields\": {\n \"text\": {\n \"type\": \"text\"\n }\n
}\n }\n }\n }\n }\n }\n}\n\n```\n2. **OPTIONAL - Add some users to
this**\n```\nPOST tatooine-/_bulk\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Luke Skywalker\" } }\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Leia Organa\" } }\n{ \"index\": {} }\n{ \"user\": {
\"name\": \"Han Solo\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\":
\"Chewbacca\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\": \"Obi-Wan
Kenobi\" } }\n{ \"index\": {} }\n{ \"user\": { \"name\": \"Yoda\" } }\n{
\"index\": {} }\n{ \"user\": { \"name\": \"R2-D2\" } }\n{ \"index\": {}
}\n{ \"user\": { \"name\": \"C-3PO\" } }\n{ \"index\": {} }\n{ \"user\":
{ \"name\": \"Darth Vader\" } }\n``` \n3. **Register Monitoring Entity
Source Saved Objects**\n```\nPOST
kbn:/api/entity_analytics/monitoring/entity_source\n{\n \"type\":
\"index\",\n \"name\": \"StarWars\",\n \"managed\": true,\n
\"indexPattern\": \"tatooine-\",\n \"enabled\": true,\n \"matchers\":
[\n {\n \"fields\": [\"user.role\"],\n \"values\": [\"admin\"]\n }\n
],\n \"filter\": {}\n}\n \n```\n4. **Initialise monitoring engine:**
\n```\nPOST kbn:/api/entity_analytics/monitoring/engine/init {}\n```
\nShould all work as expected (famous last
words)\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
machadoum
<pablo.nevesmachado@elastic.co>","sha":"20ea09af7fa857d75449cf2a9a2b7b2316023132"}},{"branch":"9.1","label":"v9.1.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Charlotte Alexandra Wilson <CAWilson94@users.noreply.github.com>
Co-authored-by: machadoum <pablo.nevesmachado@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
szaffarano pushed a commit to szaffarano/kibana that referenced this pull request Aug 5, 2025
…ource engine - bug fix (elastic#230263)

## Summary 
This PR moves the scheduleNow call from the monitoring engine
initialization to the privilege monitoring initialisation step. This
change ensures the task is only scheduled after the Privileged
Monitoring Engine has been properly created and is ready — resolving the
dependency issue.

The flow for starting a sync with the monitoring engine is - 
1. Create privileged users. 
2. Register these with the monitoring source 
3. Initialise the privilege monitoring engine - will trigger
scheduleNow, and therefore the task.

Also added a try catch around engine status for handling the case of
status undefined within scheduleNow call.


### Testing Changes 
1. Open fresh kibana and ES 
2. Enable Advanced Settings 

**UI Test:** 
1. Navigate to privileged monitoring page 
2. Select index modal - create new index from here 
3. Select 'add Privileged users' 

Look at kibana logs - "Running privilege monitoring task" should show
UI should have closed modal, onto the privmon screen.

**Dev Tools Test:** 
1. **Create test index/ indicies**

```
PUT /tatooine-
{
  "mappings": {
    "properties": {
      "user": {
        "properties": {
          "name": {
            "type": "keyword",
            "fields": {
              "text": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

```
2. **OPTIONAL - Add some users to this**
```
POST tatooine-/_bulk
{ "index": {} }
{ "user": { "name": "Luke Skywalker" } }
{ "index": {} }
{ "user": { "name": "Leia Organa" } }
{ "index": {} }
{ "user": { "name": "Han Solo" } }
{ "index": {} }
{ "user": { "name": "Chewbacca" } }
{ "index": {} }
{ "user": { "name": "Obi-Wan Kenobi" } }
{ "index": {} }
{ "user": { "name": "Yoda" } }
{ "index": {} }
{ "user": { "name": "R2-D2" } }
{ "index": {} }
{ "user": { "name": "C-3PO" } }
{ "index": {} }
{ "user": { "name": "Darth Vader" } }
``` 
3. **Register Monitoring Entity Source Saved Objects**
```
POST kbn:/api/entity_analytics/monitoring/entity_source
{
  "type": "index",
  "name": "StarWars",
  "managed": true,
  "indexPattern": "tatooine-",
  "enabled": true,
 "matchers": [
    {
      "fields": ["user.role"],
      "values": ["admin"]
    }
  ],
  "filter": {}
}
 
```
4. **Initialise monitoring engine:** 
```
POST kbn:/api/entity_analytics/monitoring/engine/init {}
``` 
Should all work as expected (famous last words)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: machadoum <pablo.nevesmachado@elastic.co>
delanni pushed a commit to delanni/kibana that referenced this pull request Aug 5, 2025
…ource engine - bug fix (elastic#230263)

## Summary 
This PR moves the scheduleNow call from the monitoring engine
initialization to the privilege monitoring initialisation step. This
change ensures the task is only scheduled after the Privileged
Monitoring Engine has been properly created and is ready — resolving the
dependency issue.

The flow for starting a sync with the monitoring engine is - 
1. Create privileged users. 
2. Register these with the monitoring source 
3. Initialise the privilege monitoring engine - will trigger
scheduleNow, and therefore the task.

Also added a try catch around engine status for handling the case of
status undefined within scheduleNow call.


### Testing Changes 
1. Open fresh kibana and ES 
2. Enable Advanced Settings 

**UI Test:** 
1. Navigate to privileged monitoring page 
2. Select index modal - create new index from here 
3. Select 'add Privileged users' 

Look at kibana logs - "Running privilege monitoring task" should show
UI should have closed modal, onto the privmon screen.

**Dev Tools Test:** 
1. **Create test index/ indicies**

```
PUT /tatooine-
{
  "mappings": {
    "properties": {
      "user": {
        "properties": {
          "name": {
            "type": "keyword",
            "fields": {
              "text": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

```
2. **OPTIONAL - Add some users to this**
```
POST tatooine-/_bulk
{ "index": {} }
{ "user": { "name": "Luke Skywalker" } }
{ "index": {} }
{ "user": { "name": "Leia Organa" } }
{ "index": {} }
{ "user": { "name": "Han Solo" } }
{ "index": {} }
{ "user": { "name": "Chewbacca" } }
{ "index": {} }
{ "user": { "name": "Obi-Wan Kenobi" } }
{ "index": {} }
{ "user": { "name": "Yoda" } }
{ "index": {} }
{ "user": { "name": "R2-D2" } }
{ "index": {} }
{ "user": { "name": "C-3PO" } }
{ "index": {} }
{ "user": { "name": "Darth Vader" } }
``` 
3. **Register Monitoring Entity Source Saved Objects**
```
POST kbn:/api/entity_analytics/monitoring/entity_source
{
  "type": "index",
  "name": "StarWars",
  "managed": true,
  "indexPattern": "tatooine-",
  "enabled": true,
 "matchers": [
    {
      "fields": ["user.role"],
      "values": ["admin"]
    }
  ],
  "filter": {}
}
 
```
4. **Initialise monitoring engine:** 
```
POST kbn:/api/entity_analytics/monitoring/engine/init {}
``` 
Should all work as expected (famous last words)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: machadoum <pablo.nevesmachado@elastic.co>
@wildemat wildemat mentioned this pull request Aug 7, 2025
10 tasks
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Aug 18, 2025
…ource engine - bug fix (elastic#230263)

## Summary 
This PR moves the scheduleNow call from the monitoring engine
initialization to the privilege monitoring initialisation step. This
change ensures the task is only scheduled after the Privileged
Monitoring Engine has been properly created and is ready — resolving the
dependency issue.

The flow for starting a sync with the monitoring engine is - 
1. Create privileged users. 
2. Register these with the monitoring source 
3. Initialise the privilege monitoring engine - will trigger
scheduleNow, and therefore the task.

Also added a try catch around engine status for handling the case of
status undefined within scheduleNow call.


### Testing Changes 
1. Open fresh kibana and ES 
2. Enable Advanced Settings 

**UI Test:** 
1. Navigate to privileged monitoring page 
2. Select index modal - create new index from here 
3. Select 'add Privileged users' 

Look at kibana logs - "Running privilege monitoring task" should show
UI should have closed modal, onto the privmon screen.

**Dev Tools Test:** 
1. **Create test index/ indicies**

```
PUT /tatooine-
{
  "mappings": {
    "properties": {
      "user": {
        "properties": {
          "name": {
            "type": "keyword",
            "fields": {
              "text": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

```
2. **OPTIONAL - Add some users to this**
```
POST tatooine-/_bulk
{ "index": {} }
{ "user": { "name": "Luke Skywalker" } }
{ "index": {} }
{ "user": { "name": "Leia Organa" } }
{ "index": {} }
{ "user": { "name": "Han Solo" } }
{ "index": {} }
{ "user": { "name": "Chewbacca" } }
{ "index": {} }
{ "user": { "name": "Obi-Wan Kenobi" } }
{ "index": {} }
{ "user": { "name": "Yoda" } }
{ "index": {} }
{ "user": { "name": "R2-D2" } }
{ "index": {} }
{ "user": { "name": "C-3PO" } }
{ "index": {} }
{ "user": { "name": "Darth Vader" } }
``` 
3. **Register Monitoring Entity Source Saved Objects**
```
POST kbn:/api/entity_analytics/monitoring/entity_source
{
  "type": "index",
  "name": "StarWars",
  "managed": true,
  "indexPattern": "tatooine-",
  "enabled": true,
 "matchers": [
    {
      "fields": ["user.role"],
      "values": ["admin"]
    }
  ],
  "filter": {}
}
 
```
4. **Initialise monitoring engine:** 
```
POST kbn:/api/entity_analytics/monitoring/engine/init {}
``` 
Should all work as expected (famous last words)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: machadoum <pablo.nevesmachado@elastic.co>
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 Feature:Entity Analytics Security Solution Entity Analytics features release_note:fix Team:Entity Analytics Security Entity Analytics Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Theme: entity_analytics v9.1.1 v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants