Commit graph

239 commits

Author SHA1 Message Date
Jacek Kolezynski
d6f71349aa
[Security Solution] Remove bulk crud endpoints schemas (#213244)
**Partially addresses:** #211808,
https://github.com/elastic/security-docs/issues/5981 (internal)
**Resolves: #208329**

## Summary

This is the second part of the migration effort, containing changes for:
- BULK CRUD (removing, for v.9.0)

The PR also contains changes for ticket #208329 - as changes for
removing of dead code for handling Bulk CRUD endpoints had to be
combined together with removing the schema files for Bulk CRUD
endpoints.

This PR will be backported only to versions for Kibana v9

# Testing
1. cd x-pack/solutions/security/plugins/security_solution
2. yarn openapi:bundle:detections 
3. Take the bundled file
(docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml)
and load it into bump.sh console to see the changes.
4. Compare the changes with the [Legacy
documentation](https://www.elastic.co/guide/en/security/current/rule-api-overview.html)

You can also use this [link](https://bump.sh/jkelas2/doc/kibana_wip2/)
where I deployed the generated bundled doc.

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2025-03-14 17:15:38 +01:00
Jean-Louis Leysens
5e90e557cf
[OAS] Support examples (and more) (#212495)
## Summary

Close https://github.com/elastic/kibana/issues/188926

Adds the ability to merge in an arbitrary OAS operation object (search
[spec](https://swagger.io/specification/) for "operation object") in
code generated OAS.

This enables us to write examples next to the code:

<img width="306" alt="Screenshot 2025-02-26 at 11 24 00"
src="https://github.com/user-attachments/assets/5df92ae9-c8c5-4797-8b7c-764e937e84e9"
/>

```ts
// Inside the router declaration
  router.post(
    {
      path: `${BASE_ALERTING_API_PATH}/rule/{id?}`,
      security: DEFAULT_ALERTING_ROUTE_SECURITY,
      options: {
        access: 'public',
        summary: `Create a rule`,
        tags: ['oas-tag:alerting'],
        // NEW 👇🏻: this file can contain operation-level OAS and will merge/override anything that we auto generate
        oasOperationObject: () => path.join(__dirname, 'create_rule.examples.yaml'),
        // ☝🏻 can also be a TS-checked OpenAPIV3.OperationObject
```

Tested with create rule example overlay
([gist](https://gist.github.com/jloleysens/dc643522a3f58dc2aed3dcef966b42df))
and bump

<img width="1236" alt="Screenshot 2025-02-26 at 11 45 57"
src="https://github.com/user-attachments/assets/c21b466a-ddab-49ce-b4ba-a04fd0e6c1b7"
/>

## Docs

Added developer guide docs to
https://docs.elastic.dev/kibana-dev-docs/genereating-oas-for-http-apis#2-route-definitions

<details>

<summary>images</summary>

<img width="799" alt="Screenshot 2025-03-13 at 13 02 31"
src="https://github.com/user-attachments/assets/e89b2c5a-1984-4672-a40b-b492581e690f"
/>

<img width="819" alt="Screenshot 2025-03-13 at 13 02 39"
src="https://github.com/user-attachments/assets/1375a25a-4d91-46b4-8ce5-42c763657d96"
/>

</details>




### TO DO
- [x] Document the feature in TS
- [x] Document feature in dev docs
- [x] Add tests

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-14 14:56:28 +01:00
Janki Salvi
14871c31aa
[ResponseOps][Rules] Allow users to create a snooze schedule for rule via API (#210584)
## Summary

Resolves first part of https://github.com/elastic/kibana/issues/198783
(snooze API)
Creates a public API for adding snooze schedule to rules.
For this purpose we created new schedule schema which will be used as
standard schedule schema across rules and alerting framework.

**Note** 
The code to be reviewed for public API is under `common/routes/schedule`
and inside `external` folders.
Rest of the code is just moving existing internal API route and its code
to `/internal` folders.


### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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

### How to test
- Create a rule in kibana
- Snooze that rule via new public API
```typescript
Path: https://localhost:5601/api/alerting/rule/<rule_id>/snooze_schedule
Method: POST
Body: 
{
    "schedule": { 
       "custom": {
         "start": "2025-02-25T18:00:00.000Z",
         "duration": "15m",
         "recurring": {
            "every": "1w",
            "onWeekDay": ["TU", "FR"],
            "occurrences": 10
         }
       }
    }
}
``` 
- Verify various snooze schedule scenarios are generated correctly

#### Flaky test runner:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/8009

### Release note
Allow users to create a snooze schedule for rule via API

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: lcawl <lcawley@elastic.co>
2025-03-13 15:03:11 +00:00
Joe Reuter
4681b6c562
🌊 Streams: Prepare API for publishing (#213127)
Add streams API to documentation as an experimental feature

<img width="2555" alt="Screenshot 2025-03-07 at 11 44 54"
src="https://github.com/user-attachments/assets/f54e5e6e-0c20-4bad-9cff-27747d0f76e2"
/>

There are a couple of changes in here:
* Split streams API in internal and public and mark the public parts as
experimental
* Add the public parts to the Kibana documentation
* Add description and summary
* Adjust the server repository wrapper to pass through summary and
description

# To test

* Generate OAS bundle: `node scripts/capture_oas_snapshot --include-path
/api/streams --update`
* Apply overlays `cd oas_docs && make api-docs`
* Make sure bump.sh is installed (`npm install -g bump-cli`)
* Run for preview: `cd oas_docs && bump preview output/kibana.yaml`

# Open questions

* Does the split into public and internal make sense?
* Is it a problem if this is visible in the user-facing documentation
page before we actually release streams? Or would it be OK if the API is
marked as experimental? (mostly a question for @LucaWintergerst )

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-13 13:41:05 +00:00
Jan Monschke
e3311c516b
[Threat Hunting Investigations] Improve API docs for notes/timeline (#213584)
## Summary

[META
issue](https://github.com/elastic/security-docs-internal/issues/57)

This PR improves the API documentation for timeline/notes/pinned events
as per the definition in the meta issue.

### Notes
#### Timeline API
- `eventType`:
	- is always set to `all`
	- looks like it's been superseded by dataView?
	- I marked it as `deperecated` 
- `eventIdToNoteIds`:
- there's a type mismatch between what the frontend expects and what is
returned
	- also it does not seem to be used anymore?
	- it needs to be investigated further
#### Notes API
- `GlobalNote`:
	- looks like it's not used anymore
	- I removed it, nothing broke
- `eventIngested`, `eventTimestamp`, `eventDataView` and `overrideOwner`
are all not used on the patch note endpoint, I removed them. The
`event*` ones I have never seen before to be honest.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2025-03-12 18:55:54 +01:00
Bailey Cash
256817b281
chore/slo: add cursor based pagination fields to slo schema, show slo definition api (#213835)
## Summary

Resolves #213238 

- Adds SLO definition API doc
- Adds fields for cursor based pagination to Find SLO docs


[bundled.json](https://github.com/user-attachments/files/19186322/bundled.json)

---------

Co-authored-by: Kevin Delemme <kdelemme@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-12 11:18:23 -04:00
elastic-renovate-prod[bot]
c9144ad60e
Update dependency @redocly/cli to ^1.33.0 (main) (#214105)
This PR contains the following updates:

| Package | Type | Update | Change | Pending |
|---|---|---|---|---|
| [@redocly/cli](https://redirect.github.com/Redocly/redocly-cli) |
devDependencies | patch | [`^1.32.2` ->
`^1.33.0`](https://renovatebot.com/diffs/npm/@redocly%2fcli/1.33.0/1.33.0)
| `1.33.1` |
| [@redocly/cli](https://redirect.github.com/Redocly/redocly-cli) |
dependencies | patch | [`^1.32.2` ->
`^1.33.0`](https://renovatebot.com/diffs/npm/@redocly%2fcli/1.33.0/1.33.0)
| `1.33.1` |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://redirect.github.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMDcuMCIsInVwZGF0ZWRJblZlciI6IjM5LjEwNy4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJUZWFtOkNvcmUiLCJiYWNrcG9ydDpwcmV2LW1pbm9yIiwicmVsZWFzZV9ub3RlOnNraXAiXX0=-->

Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>
2025-03-12 14:28:00 +01:00
Cristina Amico
382630ecd1
[Fleet] Add ssl fields to agent binary source settings (#213211)
closes https://github.com/elastic/kibana/issues/207324
follow up of https://github.com/elastic/kibana/issues/207322

## Summary
Add ssl fields to agent binary source settings. The new fields allow
users to set a TLS connection to the agent binary source uri.
- The cert key will be stored either as an encrypted SO or a secret
(latter option will be available once fleet server will have this
functionality: https://github.com/elastic/fleet-server/issues/4470).
- The secret field is only available when the feature flag
`enableSSLSecrets` is enabled, otherwise the cert key is saved as an
encrypted SO.

<details>
  <summary>Screenshots</summary>
<img width="809" alt="Screenshot 2025-03-11 at 14 53 44"
src="https://github.com/user-attachments/assets/e93a04cf-c699-4e13-8cb6-870986197f92"
/>
<img width="804" alt="Screenshot 2025-03-11 at 14 53 34"
src="https://github.com/user-attachments/assets/c2c13c8f-e65c-4843-a538-d317e1359bf0"
/>



Generated policy:
<img width="797" alt="Screenshot 2025-03-06 at 17 43 02"
src="https://github.com/user-attachments/assets/12411fea-9a8b-4ee9-aa7c-123c6aefea4a"
/>

</details>

### Checklist
- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-12 09:50:32 +01:00
Lisa Cawley
86ddd8cf3a
[DOCS] Add APM rule parameter descriptions (#213186) 2025-03-12 00:55:21 +01:00
Lisa Cawley
b27f9aa5f0
Add minimal user session management API docs (#212576) 2025-03-11 23:47:07 +01:00
elastic-renovate-prod[bot]
9004980476
Update dependency @redocly/cli to ^1.32.1 (main) (#213914)
This PR contains the following updates:

| Package | Type | Update | Change | Pending |
|---|---|---|---|---|
| [@redocly/cli](https://redirect.github.com/Redocly/redocly-cli) |
devDependencies | patch | [`^1.32.0` ->
`^1.32.1`](https://renovatebot.com/diffs/npm/@redocly%2fcli/1.33.0/1.32.1)
| `1.33.0` (+1) |
| [@redocly/cli](https://redirect.github.com/Redocly/redocly-cli) |
dependencies | patch | [`^1.32.0` ->
`^1.32.1`](https://renovatebot.com/diffs/npm/@redocly%2fcli/1.33.0/1.32.1)
| `1.33.0` (+1) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://redirect.github.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMDcuMCIsInVwZGF0ZWRJblZlciI6IjM5LjEwNy4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJUZWFtOkNvcmUiLCJiYWNrcG9ydDpwcmV2LW1pbm9yIiwicmVsZWFzZV9ub3RlOnNraXAiXX0=-->

Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>
2025-03-11 22:53:19 +01:00
Lisa Cawley
37a0a69d43
[DOCS] Add minimalistic feature API docs (#212559) 2025-03-11 21:03:20 +01:00
Lisa Cawley
73c8a5184f
[DOCS] Add minimal upgrade assistant APIs (#213863) 2025-03-11 07:49:17 -07:00
elastic-renovate-prod[bot]
914533f4d3
Update dependency @redocly/cli to ^1.32.0 (main) (#212624) 2025-03-11 13:56:06 +01:00
Jen Huang
3f90203406
[UII] Support searchAfter and PIT (point-in-time) parameters for get agents list API (#213486)
## Summary

Resolves https://github.com/elastic/kibana/issues/206924.

This PR adds the following query parameters to the agent list API (`GET
/api/fleet/agents`) in order to enable fetching beyond the first 10,000
hits:
```
    searchAfter?: string;
    openPit?: boolean;
    pitId?: string;
    pitKeepAlive?: string;
```

The list agent API response can now include the following properties
```
    // the PIT ID used
    pit?: string;

    // stringified version of the last agent's `sort` field,
    // can be passed as `searchAfter` in the next request
    nextSearchAfter? string;
```

* `searchAfter` can be used with or without a `pitId`. If using
`searchAfter`, `page` parameter is not accepted.

* `searchAfter` expects a stringified array. (Reviewers: I couldn't get
the Kibana request schema to accept a multi-part query param and convert
it to an array... I think this would be better, please let me know if
you know how to get that to work 🙏)

* `pitKeepAlive` duration (i.e. `30s`, `1m`, etc) must be present when
opening a PIT or retrieving results using a PIT ID.

* These can be used with the existing `sortField` and `sortOrder`
params. They default to `enrolled_at` and `desc` respectively.

### Example using only `searchAfter`:

```
# Retrieve the first 10k hits
curl -X GET 'http://<user>:<pass>@<kibana url>/api/fleet/agents?perPage=10000'

# Grab the `nextSearchAfter` param from the response
# Pass it to the new request to retrieve the next page of 10k hits
curl -X GET 'http://<user>:<pass>@<kibana url>/api/fleet/agents?perPage=10000&searchAfter=<nextSearchAfter>'
```

### Example using `searchAfter` with point-in-time parameters:
```
# Retrieve the first 10k hits and open a PIT
curl -X GET 'http://<user>:<pass>@<kibana url>/api/fleet/agents?perPage=10000&openPit=true&pitKeepAlive=5m'

# Grab the `pit` ID from the response
# Grab the `nextSearchAfter` param from the response
# Pass both to the new request to retrieve the next page of 10k hits
curl -X GET 'http://<user>:<pass>@<kibana url>/api/fleet/agents?perPage=10000&searchAfter=<nextSearchAfter>&pitId=<pit id>&pitKeepAlive=5m'
```

## Testing
I recommend using `scripts/create_agents` to generate bulk agents and
testing the above requests. You can generate new agents between PIT
requests to test that using a PIT ID retains the original state. (An API
functional test was added for this)

Note: you may need to add `&showInactive=true` to all requests if your
fake agents become inactive.

TBD

### 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: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-07 16:01:49 -08:00
Lisa Cawley
147ccae730
Add examples for APM source map APIs (#212449) 2025-03-08 00:18:35 +01:00
Jill Guyonnet
bdbc2ef43f
[Fleet] Add retry logic to automatic agent upgrades (#212744)
## Summary

Relates https://github.com/elastic/ingest-dev/issues/4720

This PR adds retry logic to the task that handles automatic agent
upgrades originally implemented in
https://github.com/elastic/kibana/pull/211019.

Complementary fleet-server change which sets the agent's
`upgrade_attempts` to `null` once the upgrade is complete.:
https://github.com/elastic/fleet-server/pull/4528

### Approach

- A new `upgrade_attempts` property is added to agents and stored in the
agent doc (ES mapping update in
https://github.com/elastic/elasticsearch/pull/123256).
- When a bulk upgrade action is sent from the automatic upgrade task, it
pushes the timestamp of the upgrade to the affected agents'
`upgrade_attempts`.
- The default retry delays are `['30m', '1h', '2h', '4h', '8h', '16h',
'24h']` and can be overridden with the new
`xpack.fleet.autoUpgrades.retryDelays` setting.
- On every run, the automatic upgrade task will first process retries
and then query more agents if necessary (cf.
https://github.com/elastic/ingest-dev/issues/4720#issuecomment-2671660795).
- Once an agent has completed and failed the max retries defined by the
retry delays array, it is no longer retried.

### Testing

The ES query for fetching agents with existing `upgrade_attempts` needs
the updated mappings, so it might be necessary to pull the latest `main`
in the `elasticsearch` repo and run `yarn es source` instead of `yarn es
snapshot` (requires an up-to-date Java environment, currently 23).

In order to test that `upgrade_attempts` is set to `null` when the
upgrade is complete, fleet-server should be run in dev using the change
in https://github.com/elastic/fleet-server/pull/4528.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Low probability risk of incorrectly triggering agent upgrades. This
feature is currently behind the `enableAutomaticAgentUpgrades` feature
flag.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2025-03-06 21:31:24 +01:00
Nicolas Chaulet
680bf587df
[Fleet] Tabular UI for installed integrations (#212582) 2025-03-05 08:56:02 -05:00
Patryk Kopyciński
5e742f0425
[Security Assistant] Fix use default inference endpoint (#212191)
## Summary

Removes internal feature flag responsible for switching to Kibana's
internal inference endpoint instead of using a dedicated one.

How to test:

**Clean cluster:**
**1. Setup KB**
**2. Make sure the `.kibana-elastic-ai-assistant-knowledge-base-*` Data
Stream is using default Inference endpoint**
```
http://localhost:5601/app/management/data/index_management/component_templates/.kibana-elastic-ai-assistant-component-template-knowledge-base
```
<img width="1656" alt="image"
src="https://github.com/user-attachments/assets/84fda205-6272-4393-8f7d-a449fae2a090"
/>

<img width="1086" alt="image"
src="https://github.com/user-attachments/assets/19e562ec-da5f-4ec2-ab64-7bfb1d64789c"
/>

**3. Make sure there is no inference endpoint on the list**
<img width="1875" alt="image"
src="https://github.com/user-attachments/assets/3465df8b-7c0d-4faf-b113-df897694521e"
/>

**4. Make sure Security Labs content exists on KB list and you can add
and edit Document/Index entry
```
http://localhost:5601/app/management/kibana/securityAiAssistantManagement?tab=knowledge_base
```

Migration:
**1. Setup KB on at least 2 Kibana spaces on `main` branch**
**2. Switch to this PR's branch and start Kibana**
**3. Make sure there is no inference endpoint on the list**
```
http://localhost:5601/app/elasticsearch/relevance/inference_endpoints
```
<img width="1875" alt="image"
src="https://github.com/user-attachments/assets/3465df8b-7c0d-4faf-b113-df897694521e"
/>

**4. Make sure that the Data stream was rolled over**
```
http://localhost:5601/app/management/data/index_management/indices?filter=know&includeHiddenIndices=true
```
Should see two indices per Kibana space:
<img width="1741" alt="Zrzut ekranu 2025-03-3 o 15 37 55"
src="https://github.com/user-attachments/assets/e6da48c8-59e9-43b8-8eac-c2b5e0059954"
/>

The older index per space should have mapping:
<img width="1083" alt="image"
src="https://github.com/user-attachments/assets/01f6e422-77d1-4f8b-8b7e-9c541a7ea47c"
/>

Newer index per space:
<img width="1086" alt="image"
src="https://github.com/user-attachments/assets/19e562ec-da5f-4ec2-ab64-7bfb1d64789c"
/>

**4. Make sure Security Labs content exists on KB list and you can add
and edit Document/Index entry
```
http://localhost:5601/app/management/kibana/securityAiAssistantManagement?tab=knowledge_base
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-05 02:14:08 +01:00
Ievgen Sorokopud
7db897a539
[Bug] [Assistant API] - Do not allow empty conversation ID in chat/complete route (#11783) (#213049)
## Summary

BUG: https://github.com/elastic/security-team/issues/11783

This PR fixes the behaviour of the
`/api/security_ai_assistant/chat/complete` route where the
`conversationId` can be passed as an empty string. This may lead to
unexpected results described in
https://github.com/elastic/security-team/issues/11783#issuecomment-2696529040.

### Expected behaviour

We should throw a bad request (400) http error when empty
`conversationId` has been passed.

### Testing

* Use this `curl` command to test the endpoint.

```
curl --location 'http://localhost:5601/api/security_ai_assistant/chat/complete' \
--header 'kbn-xsrf: true' \
--header 'Content-Type: application/json' \
--data '{
  "connectorId": "{{my-gpt4o-ai}}",
  "conversationId": "",
  "isStream": false,
  "messages": [
    {
      "content": "Follow up",
      "role": "user"
    }
  ],
  "persist": true
}'
```

You should see next error as a response:

```
{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "[request body]: conversationId: String must contain at least 1 character(s), conversationId: No empty strings allowed"
}
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-04 13:05:51 +01:00
Patryk Kopyciński
f0d66691b8
[Security Assistant] Fix Product documentation installation banner (#212463)
## Summary

Fixes logic on fresh cluster where the ELSER was not started yet, in
this case API reports `status` as `uninstalled`, but it doesn't mean
that the Product documentation was actually uninstall, but rather it's a
default state.
Added internal `product_documentation_status` to KB status API to make
sure we keep track of the status internally and present the banner only
if the docs were intentionally uninstalled

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-04 02:28:35 +01:00
Steph Milovic
095fc222aa
[Security Assistant] Conversation pagination refactor (#211831) 2025-03-03 13:41:20 -07:00
Julia Bardi
d2913395af
[Fleet] fix latest_executed_state error (#212935)
Fix schema validation error when `latest_executed_state: {}`.

The logic sets an empty object here:
63394e6bfd/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/steps/update_latest_executed_state.ts (L63)
This caused an error on the Integration Details page:

`Failed output validation: [response
body.items.4.installationInfo.latest_executed_state.name]: expected
value of type [string] but got [undefined]`

Tested locally by manually updating `latest_executed_state` to `{}`, now
the `/epm/packages` API works as expected.

<img width="1459" alt="image"
src="https://github.com/user-attachments/assets/bbee7787-93a7-4099-ba9b-ff5d031f7637"
/>
2025-03-03 18:07:28 +00:00
Cristina Amico
151fa26a5f
[Fleet] Add SSL options to fleet server hosts settings (#208091)
Fixes https://github.com/elastic/kibana/issues/207322

## Summary
Show SSL options for fleet server host in Fleet server settings section
and in add fleet server host flyout
- Registered fleet server host as a encrypted save object and the new
mappings added under `ssl` property, mirroring what's already existing
for `logstash` and `kafka` outputs
- The new options are displayed in the UI, both when adding a new fleet
server host from the flyout and when editing an existing one.
- The values are then added to the full agent policy
- The values for `ssh.key` and `ssh.es_key` can additionally be saved as
secrets but for now this option is not enabled until [fleet server
supports it](https://github.com/elastic/fleet-server/issues/4470) - I
used the feature flag `enableSSLSecrets`

<details>
  <summary>Screenshots</summary>
<img width="803" alt="Screenshot 2025-02-14 at 10 23 41"
src="https://github.com/user-attachments/assets/e1bf8c93-e8c0-4351-b86b-a7f8a8b0ec72"
/>
<img width="801" alt="Screenshot 2025-02-14 at 10 23 36"
src="https://github.com/user-attachments/assets/f96d2a5c-0285-41d1-953b-e662ccdcd514"
/>
<img width="780" alt="Screenshot 2025-02-04 at 14 34 52"
src="https://github.com/user-attachments/assets/e854fc28-d4aa-4b01-8634-e1f37f70419b"
/>
<img width="804" alt="Screenshot 2025-02-04 at 14 35 00"
src="https://github.com/user-attachments/assets/f507c34a-774e-4aa1-94b2-b912539d6143"
/>
<img width="791" alt="Screenshot 2025-02-04 at 09 25 28"
src="https://github.com/user-attachments/assets/82c1f761-7ee5-42d0-8b8f-23848cfc0391"
/>

Generated policy:
<img width="795" alt="Screenshot 2025-02-24 at 16 43 58"
src="https://github.com/user-attachments/assets/5ef4e34f-5850-4449-8a70-7de10750bb84"
/>
<img width="796" alt="Screenshot 2025-02-24 at 16 44 15"
src="https://github.com/user-attachments/assets/bdcf70fe-72f0-4df0-9a9e-40346407a1df"
/>




</details>

### Checklist
- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-03 13:23:00 +01:00
Konrad Szwarc
2700a2a951
[EDR Workflows] OpenApi Missing Content - Response Actions (#212510)
## For reviewers:
Only `*.schema.yml` files were edited (excluding
`*.bundled.schema.yml`). Rest of the changes comes from auto generation
and can be ignored.

## Description

Part of DW team effort - elastic/security-team#11804

This PR aligns the property/schema descriptions and examples in
AsciiDocs with OpenAPI schemas. The primary goal of this PR was not to
extend or enhance the documentation but to migrate from one system to
another.

Ascii docs -
https://www.elastic.co/guide/en/security/8.17/management-api-overview.html
OpenApi generated docs -
https://www.elastic.co/docs/api/doc/kibana/operation/operation-endpointgetactionslist

Changes:

Copied missing property descriptions from AsciiDoc to OpenApi properties
Copied existing AsciiDoc examples for both requests and responses
Fixed falsy query object in some GET requests - in OpenApi it was
defined as an object, not as path query params.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Paul Tavares <56442535+paul-tavares@users.noreply.github.com>
Co-authored-by: natasha-moore-elastic <137783811+natasha-moore-elastic@users.noreply.github.com>
2025-02-28 16:44:00 +00:00
Konrad Szwarc
92867c697d
[EDR Workflows][Osquery] OpenApi Missing Content (#212032)
Part of DW team effort -
https://github.com/elastic/security-team/issues/11804

This PR aligns the property/schema descriptions and examples in
AsciiDocs with OpenAPI schemas. The primary goal of this PR was not to
extend or enhance the documentation but to migrate from one system to
another.

Ascii docs -
https://www.elastic.co/guide/en/kibana/8.17/osquery-manager-api.html
OpenApi generated docs -
https://www.elastic.co/docs/api/doc/kibana/operation/operation-osqueryfindlivequeries

Changes:
1. Copied missing property descriptions from AsciiDoc to OpenApi
properties
2. Copied existing AsciiDoc examples for both requests and responses
3. Fixed falsy query object in some GET requests - in OpenApi it was
defined as an object, not as path query params.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: natasha-moore-elastic <137783811+natasha-moore-elastic@users.noreply.github.com>
2025-02-27 12:29:04 +00:00
Patryk Kopyciński
c822109a49
[Security Assistant] Fix Knowledge Base API (#211367)
## Summary

Fixes bugs related to Security Assistant Knowledge Base API

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Hannah Mudge <Heenawter@users.noreply.github.com>
Co-authored-by: Marta Bondyra <4283304+mbondyra@users.noreply.github.com>
Co-authored-by: Davis Plumlee <56367316+dplumlee@users.noreply.github.com>
Co-authored-by: Jatin Kathuria <jatin.kathuria@elastic.co>
Co-authored-by: Chris Cowan <chris@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Arturo Lidueña <arturo.liduena@elastic.co>
Co-authored-by: Jon <jon@elastic.co>
Co-authored-by: Rodney Norris <rodney.norris@elastic.co>
Co-authored-by: Elena Shostak <165678770+elena-shostak@users.noreply.github.com>
Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
Co-authored-by: Irene Blanco <irene.blanco@elastic.co>
Co-authored-by: Cauê Marcondes <55978943+cauemarcondes@users.noreply.github.com>
Co-authored-by: Carlos Crespo <crespocarlos@users.noreply.github.com>
2025-02-25 23:00:00 +00:00
Konrad Szwarc
3492f12c6c
[EDR Workflows] OpenApi Missing Content - Endpoint Management (#212205)
Part of DW team effort -
https://github.com/elastic/security-team/issues/11804

This PR aligns the property/schema descriptions and examples in
AsciiDocs with OpenAPI schemas. The primary goal of this PR was not to
extend or enhance the documentation but to migrate from one system to
another.

Ascii docs -
https://www.elastic.co/guide/en/kibana/8.17/osquery-manager-api.html
OpenApi generated docs -
https://www.elastic.co/docs/api/doc/kibana/operation/operation-endpointgetactionslist

Changes:

Copied missing property descriptions from AsciiDoc to OpenApi properties
Copied existing AsciiDoc examples for both requests and responses
Fixed falsy query object in some GET requests - in OpenApi it was
defined as an object, not as path query params.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: natasha-moore-elastic <137783811+natasha-moore-elastic@users.noreply.github.com>
2025-02-25 13:18:56 +00:00
Gerard Soldevila
6a7c904f92
SKA: Relocate "platform" packages that remain on /packages (#208704)
## Summary

The `/packages` folder at the root of the Kibana repository used to
contain a lot of packages.
In the context of SKA, they have been gradually moved to various
locations:
* `src/platform/packages`
* `x-pack/platform/packages`
* `src/core/packages`

Currently, only `devOnly: true` packages are left in this folder. This
comprises libraries for CLI scripts as well as testing utilities.

With this PR, we are moving ~half of these packages under
`src/platform/packages/(private|shared)/`.
In particular, we are moving those packages that are being used from
platform and/or solutions.

Since they are `"devOnly": true`, this means they are ONLY used from
tests, cypress tests, storybook configs, ./scripts/ folders inside some
modules, or other non-prod-time logic. Nonetheless, they are effectively
referenced from platform and/or solutions code, hence I decided they
should be placed under `platform` folders.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-02-24 11:03:30 +00:00
elastic-renovate-prod[bot]
1d130d256e
Update dependency @redocly/cli to ^1.29.0 (main) (#212048) 2025-02-22 14:21:39 +00:00
Paulo Silva
863171c623
Asset Inventory Status API (#211647)
## Summary

It closes #210712

This PR adds the following features:

- Introduces a new `status` API for the asset inventory, which returns
the status of the entity store, including statuses like
`insufficient_privileges`, `disabled`, `initializing`, `ready`, and
`empty`.
- Implements a mechanism to check the current status of the host entity
store and processes the transform component metadata.

It also introduces the following changes:
- Implemented the use of the host entity store to support the new status
API while awaiting the readiness of the 'generic' entity store.
- Added a `metadata` field to the entity store stats object and used it
to add additional metadata from the transform components.
- Replaced the retrieval of the entity store ID with the inclusion of
`stats.id` from the transform stats.
- Unit tests were added to ensure that the new API and status behavior
are functioning correctly, covering all possible states and edge cases.

### Key Changes:
- **API Changes**: A new `status` endpoint was added to query the asset
inventory's status, leveraging the host entity store for now.
- **Metadata Changes**: The `metadata` field was added to the entity
store stats to include transform-related metadata, such as
`documents_processed` and `trigger_count`.
- **Testing**: New unit tests were added to validate the behaviour of
the status API, including scenarios like insufficient privileges, entity
store installation, and document processing status.


### How to test it locally

To test it locally, execute the following in the Kibana dev tools:

```
GET kbn:/api/asset_inventory/status
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-02-21 17:44:12 -08:00
Cristina Amico
ff84c0e85a
[Fleet] Expose ssl options for ES and remote ES outputs in UI (#208745)
Fixes https://github.com/elastic/kibana/issues/207326

## Summary
Expose SSL options for outputs of type ES and remote ES outputs to use
in case of mTLS configuration.

These options correspond to `--elastic-agent-cert,
--elastic-agent-cert-key, --certificate-authorities` CLI options
explained [in the
docs](https://www.elastic.co/guide/en/fleet/current/tls-overview.html#mutual-tls-connection)
and they need to be defined only when the user intends to configure mTLS
in the system.

Secrets inputs are disabled for now in the UI until the needed changes
to fleet server are done.

### Testing
- Create an ES or remote ES output with all the SSL fields compiled
- Either make it default or assign it as a custom output for an agent
policy
- Check that the agent policy has the input data under `fleet` section:

<img width="741" alt="Screenshot 2025-02-20 at 11 56 05"
src="https://github.com/user-attachments/assets/bc891bbc-d669-4e31-951f-d045b64328e7"
/>


<details>
  <summary>Screenshots</summary>

<img width="803" alt="Screenshot 2025-02-20 at 16 07 38"
src="https://github.com/user-attachments/assets/e489cd51-6a40-4820-bf39-7670ad2ce69b"
/>
<img width="810" alt="Screenshot 2025-02-18 at 15 31 54"
src="https://github.com/user-attachments/assets/9f155b2b-1feb-424f-b02b-b232e1e4e63e"
/>


</details>


### Checklist
- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2025-02-21 17:13:30 +00:00
Julia Bardi
c658658df7
[Fleet] allow unknown type in epm package info schema (#211689)
## Summary

Closes https://github.com/elastic/kibana/issues/211666

Allow any type in `PackageInfoSchema` and `KibanaAssetReferenceSchema`
to allow new type of epm packages without change in kibana.
Covered with unit test.


### Checklist

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

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-02-20 11:27:02 +01:00
Ido Cohen
f5c9529e37
Deprecate universal entity 2025-02-18 16:49:32 +02:00
Julia Bardi
dca5f18b7e
[Fleet] show auto upgrade agent status (#210866)
## Summary

Closes https://github.com/elastic/ingest-dev/issues/4731

Added API to query agents per each version enrolled to an agent policy,
including the count of agents that failed to upgrade to the target
version.
This API is used on the UI to calculate the status of auto upgrade
status.
- Complete status: agent count reaches or exceeds target percentage
without upgrade failures
- Not started status: 0 agents on target percentage
- In progress status: agent count doesn't reach target percentage
- Failed status: there is at least one agent in failed upgrade status on
the target version

Added click handler to navigate from the status to agent list.

[UI
Design](https://www.figma.com/design/ZH58ySPR1nhI3lRHrkds1t/%5BFleet%5D-Automatic-target-agent-version?node-id=2128-4286&p=f&t=3GvdUYkqdCAJj99q-0)



```
GET kbn:/api/fleet/agent_policies/{agentPolicyId}/auto_upgrade_agents_status

{
  "currentVersions": [
    {
      "version": "8.16.2",
      "agents": 1,
      "failedAgents": 0
    },
    {
      "version": "8.16.3",
      "agents": 0,
      "failedAgents": 1
    }
  ],
  "totalAgents": 1
}
```

<img width="985" alt="image"
src="https://github.com/user-attachments/assets/c4a40872-2fe7-48e9-ade5-fe2b36d06a0e"
/>
<img width="811" alt="image"
src="https://github.com/user-attachments/assets/1cbbebb9-2c7b-4cb5-a57d-7a0388fd437e"
/>
<img width="805" alt="image"
src="https://github.com/user-attachments/assets/be716b87-9b0f-4f16-ad05-a463169bee25"
/>
<img width="989" alt="image"
src="https://github.com/user-attachments/assets/09745005-d5ed-4a80-8e7a-7c2df427d4ad"
/>
<img width="906" alt="image"
src="https://github.com/user-attachments/assets/162d43aa-1bce-4dda-a5dd-91cb59636740"
/>


### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-02-18 11:09:01 +01:00
elastic-renovate-prod[bot]
0f5671e2b3
Update dependency @redocly/cli to ^1.28.5 (main) (#211283) 2025-02-18 00:24:54 +01:00
Abhishek Bhatia
5fbbcf97a1
[Entity Analytics] [Asset Criticality] Add "unassigned" as an asset criticality level for bulk_upload (#208884)
This pull request introduces the new `unassigned` criticality level for
the asset criticality's `bulk_upload` .

### Key Changes:

#### Schema and Configuration Updates:
* Added `unassigned` to the list of criticality levels in multiple
schema files (`kibana.serverless.yaml`, `kibana.yaml`,
`common.schema.yaml`,
`ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml`,
`serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml`).

#### TypeScript and Constants:
* Updated `AssetCriticalityLevel` enum in `common.gen.ts` to include
`unassigned`.
* Added `UNASSIGNED` to `CriticalityLevels` enum and
`CriticalityModifiers` in `constants.ts`.


#### Tests:
* Updated test cases to include `unassigned` as a valid criticality
level in `parse_asset_criticality_csv_row.test.ts`,
`validations.test.ts`, `asset_criticality_data_client.test.ts`, and
`asset_criticality_csv_upload.ts`.

#### Backend Logic:
* Modified `AssetCriticalityDataClient` to handle `unassigned`
criticality level appropriately.

<img width="1488" alt="Screenshot 2025-01-30 at 2 03 11 PM"
src="https://github.com/user-attachments/assets/938411c4-725a-451c-ab38-aca36a704e91"
/>


### 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] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [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)


### Testing Steps

The main idea for this change is that the `unassigned` criticality level
is actually marked as `deleted` in the ES documents.

ES index name for default space :
`.asset-criticality.asset-criticality-default`

#### API 

1. `POST /api/asset_criticality/upload_csv`

```
curl --location 'http://localhost:5601/api/asset_criticality/upload_csv?output=stream' \
--header 'kbn-xsrf: hello' \
--header 'Accept: multipart/form-data' \
--header 'Authorization: *******' \
--form 'file=@"<Full path of the CSV file for asset criticality>"
```

Error response : 

```
{"errors":[{"message":"Invalid criticality level \"unassigned_impact\", expected one of extreme_impact, high_impact, medium_impact, low_impact, unassigned","index":4}],"stats":{"successful":3,"failed":1,"total":4}}%
```

Success response : 

```
{"errors":[],"stats":{"successful":4,"failed":0,"total":4}}%
```

Query the ES using below query to see if the criticality level is
`deleted`

```
GET .asset-criticality.asset-criticality-default/_search
{
  "query": {
    "match": {
      "asset.criticality": "deleted"
    }
  }
}
```

### UI

1. Navigate to Entity Store page
2. Upload a csv file with incorrect asset criticality level


![image](https://github.com/user-attachments/assets/8e19573b-f9f1-40df-a8de-be3ffa6ade17)

3. Rectify and upload the same file with correct criticality levels.


![image](https://github.com/user-attachments/assets/9c1872c0-e1d5-4a58-8cd8-bde0e6b0b26b)


4. Navigate to EA Dashboard and scroll down to the Entities section.
5. Select an entity and open the flyout.
6. Try changing the asset criticality of the entity. No blank/empty
value should be present or assigned to asset criticality.
7. Should be able to successfully modify the asset criticality for the
entity.

![Screenshot 2025-02-10 at 12 58
21 PM](https://github.com/user-attachments/assets/29ca6ff2-de2b-46e8-bec0-842672323844)
![Screenshot 2025-02-10 at 12 58
11 PM](https://github.com/user-attachments/assets/1cdb5f77-01e8-49b4-8f8d-bfc42859dbae)


Confirm this by querying the ES with the query : 

```
GET .asset-criticality.asset-criticality-default/_search
{
  "query": {
    "match": {
      "asset.criticality": "deleted"
    }
  }
}
```

Ensure that the Elastic search document's `_source` contains three keys,
with `deleted` present as the ` `criticality_level` for the below three
keys.

`criticality_level`
`host.asset.criticality`
`asset.criticality`

Example : 

![Screenshot 2025-02-10 at 1 08
29 PM](https://github.com/user-attachments/assets/053eddad-f9df-4c65-b687-226d9cfd5715)


### Bulk upload

```
curl --location 'http://localhost:5601/api/asset_criticality/bulk' \
--header 'kbn-xsrf: hello' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ****' \
--data '{
  "records": [
    {
      "id_value": "host-1",
      "id_field": "host.name",
      "criticality_level": "low_impact"
    },
    {
      "id_value": "host-2",
      "id_field": "host.name",
      "criticality_level": "medium_impact"
    },
    {
      "id_value": "host-6",
      "id_field": "host.name",
      "criticality_level": "medium_impact"
    },
    {
      "id_value": "host-3",
      "id_field": "host.name",
      "criticality_level": "high_impact"
    },
    {
      "id_value": "host-4",
      "id_field": "host.name",
      "criticality_level": "high_impact"
    },
    {
      "id_value": "host-bulkupload",
      "id_field": "host.name",
      "criticality_level": "unassigned"
    }

  ]
}
```

![image](https://github.com/user-attachments/assets/f692798b-2589-42a4-8ee5-696af0e39fdc)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-02-17 15:31:27 +05:30
Nicolas Chaulet
6ecb66df7f
[Fleet] Additional datastreams permissions API (#210452) 2025-02-14 09:06:12 -05:00
elastic-renovate-prod[bot]
4676b730b2
Update dependency @redocly/cli to ^1.28.3 (main) (#210665) 2025-02-13 22:36:55 +01:00
Kenneth Kreindler
e176c84449
[Security Solution] [AI Assistant] Fix flashing citations (#209629)
## Summary

Fixes a small UI bug in the citations feature. Previously, after a
message with citations finished streaming, the citations would disappear
for a fraction of a second and then reappear again. This PR makes
improves the UI by making the citations not flash off and on after the
stream finishes.

### Changes:
- Fix flashing citations
- Refactor code related to parsing content references (to make it more
maintainable).
- Update the citations prompt slightly.

### Before:


https://github.com/user-attachments/assets/1021dd53-018a-43ba-b1f4-24aab44faca9

<img width="1782" alt="image"
src="https://github.com/user-attachments/assets/723cd29a-48a2-48e7-b031-0893484746b9"
/>


### After:


https://github.com/user-attachments/assets/21f340bc-9015-42b6-a574-0439d2f8f192

### How to test
- Enable the feature flag
```yaml
# kibana.dev.yml
xpack.securitySolution.enableExperimental: ['contentReferencesEnabled']
```
- Open the security assistant
- Ask it a question about your alerts of a document in your KB. The
response should contain citations.
- Observe the response stream carefully. Ensure the citations e.g. `[1]`
do not flash off and on when the response stream finishes. The expected
behavior is that while the message is streaming, the citations are
disabled and once the stream finishes the citations get enabled (while
always being visible).

#### Edge case to test
It is possible that citations completely disappear after streaming
finishes. This happens when the LLM produces an invalid citation.
Invalid citations are hidden client side when a message finishes
streaming. You can verify this behavior by asking GPT4o this question:
```
Prepend each line with this placeholder citation "{reference(1234)}" and append the actual citation at the end of the line. How many alerts do I have? Use the open and acknowledged alerts count tool to answer and repeat the answer 50 times on new lines.
```

While the response is getting streamed it should look like this:

<img width="200" alt="image"
src="https://github.com/user-attachments/assets/03d160bf-2404-4a4e-8701-e3183c604cc4"
/>

And when the stream finishes it should look like this:

<img width="200" alt="image"
src="https://github.com/user-attachments/assets/06367379-17da-438f-a93a-9d539067ab90"
/>


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [X] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [X]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [X] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [X] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [X] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

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

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2025-02-13 15:07:25 +00:00
Yara Tercero
d4199dcac1
[Detection Engine][Docs] Updating examples to meet old ascii docs (#207558)
# Summary

As part of the effort to add missing content for Security APIs, this PR
introduces a few missing request, response, and parameter examples for
Detection Engine Alert and migration APIs.
2025-02-05 08:02:48 +01:00
Julia Bardi
07a61abfd4
[Fleet] Add sync integrations fields to remote ES output (#208516)
## Summary

Closes https://github.com/elastic/kibana/issues/192361

Added `sync_integrations` flag to remote elasticsearch output to the API
and UI with the Remote Kibana URL and API key (secret).

To test:
- enable feature flag: `xpack.fleet.enableExperimental:
['enableSyncIntegrationsOnRemote']`
- add/edit output and enable Synchronize integrations switch
- When the switch is enabled, Kibana URL and API key is required,
otherwise optional (but still has to be valid URL)
- test preconfigured output with the new fields

<img width="724" alt="image"
src="https://github.com/user-attachments/assets/5cf4c0b1-f8c3-4447-a0ef-a8aa8e362277"
/>

Example preconfig:
```
  - name: 'Preconfiged remote output'
    type: 'remote_elasticsearch'
    id: 'remote-output2'
    hosts: ["http://192.168.64.1:9200"]
    sync_integrations: true
    kibana_url: "http://localhost:5601"
    secrets:
      service_token: token
      kibana_api_key: key
```

Added callout to help create the API key (privileges have to be
confirmed when https://github.com/elastic/kibana/issues/192363 is done)

<img width="714" alt="image"
src="https://github.com/user-attachments/assets/5a5e7a8c-0a56-4234-ad66-b15f5f53de76"
/>


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-02-03 12:27:34 +01:00
Ash
59a15be977
[SecuritySolution][Endpoint] Update request docs for isolate/release/processes (#209097) 2025-02-03 11:38:14 +01:00
Jean-Louis Leysens
53cba303e5
[OAS] Remove Elastic-Api-Version (#207071)
## Summary

We anticipate generating a single document per API version for the
foreseeable future. This PR updates our OAS document merging logic to
avoid adding the `Elastic-Api-Version` header to our spec.

This will also remove this header from current documentation.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-01-30 16:59:45 +01:00
Abhishek Bhatia
a060baee83
[Entity Analytics] [Entity Store] [API] Changes to support event.ingested as a configurable timestamp field for init and enable endpoints (#208201)
## Summary

This PR introduces support for configuring the `timestamp` field for
entity store enablement.

By default, the `timestamp` field is set to `@timestamp`, but users can
opt to use `event.ingested` or another preferred value based on their
requirements.


### Entity Store API changes

#### Entity Store enable

```
POST kbn:/api/entity_store/enable
{
  "timestampField": "event.ingested"
}
```

#### Result 

```
{
  "engines": [
    {
      "status": "started",
      "type": "user",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "event.ingested"
    },
    {
      "status": "started",
      "type": "host",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "event.ingested"
    },
    {
      "status": "started",
      "type": "universal",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "event.ingested"
    }
  ],
  "status": "running"
}
```

```
POST kbn:/api/entity_store/enable
{
}
```
#### Result

```
{
  "engines": [
    {
      "status": "started",
      "type": "host",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "@timestamp"
    },
    {
      "status": "started",
      "type": "user",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "@timestamp"
    },
    {
      "status": "started",
      "type": "universal",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "@timestamp"
    }
  ],
  "status": "running"
}
```

Different entity types can have distinct `timestampField` values, as
described below:

For instance, the `host` entity uses `event.ingested` as its
`timestampField`, while other entities default to the `@timestamp`
field.

```
POST kbn:/api/entity_store/engines/host/init
{
  "timestampField": "event.ingested"
}

POST kbn:/api/entity_store/engines/user/init
{
}
```

#### Result

```
{
  "engines": [
    {
      "status": "started",
      "type": "universal",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "@timestamp"
    },
    {
      "status": "started",
      "type": "host",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "event.ingested"
    },
    {
      "status": "started",
      "type": "user",
      "indexPattern": "",
      "filter": "",
      "fieldHistoryLength": 10,
      "timestampField": "@timestamp"
    }
  ],
  "status": "running"
}
```


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [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)


### Testing steps

- Check out this PR branch.
- Start Kibana.
- Avoid enabling the Entity Store from the UI initially. Instead, enable
it via the API by following the steps outlined below.

```
DELETE kbn:/api/entity_store/engines/user
DELETE kbn:/api/entity_store/engines/host

GET kbn:/api/entity_store/status

 All engines with the same timestamp Field
POST kbn:/api/entity_store/enable
{
  "timestampField": "event.ingested"
}

# All engines with the same timestamp Field
POST kbn:/api/entity_store/enable
{
}

# Different entity with different timestamp Field
POST kbn:/api/entity_store/engines/host/init
{
  "timestampField": "event.ingested"
}

POST kbn:/api/entity_store/engines/user/init
{
}
```

4. Afterward, you can test the functionality through the UI. First,
clear the entity data from the UI, then start the Entity Store. Note
that the UI currently does not offer a way to configure this parameter.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
2025-01-29 16:49:13 -07:00
Tiago Vila Verde
5b22aa9b66
[Entity Analytics][Entity Store] Add transform config options to the API (#208062)
## Summary


This PR adds the following parameters to the `INIT` engine API:

* `frequency`: the transform run frequency
* `timeout`: the timeout for the initial creation of the transform
* `docsPerSecond`: transform throttling option. See
[here](https://arc.net/l/quote/vxcmfnhh)
* `delay`: The transform delay duration. See
[here](https://arc.net/l/quote/mzvaexhv)
Coming soon


In addition, the PR adds these fields to the Saved Object with the
engine descriptor, as well as providing a migration with the appropriate
backfilling.

Finally, there are some utility function that were/are helpful in
working with objects.

## How to test

*NOTE*: Always make sure the security default data view exists. Easiest
way it to just navigate to some Security UI.

### Checking the new defaults

1. Initialize an engine via dev tools by calling: `POST
kbn:/api/entity_store/engines/<entity_type>/init {}`
2. Call `GET kbn:/api/entity_store/status`. This response should now
contain all the default optional values.

### Observing the parameters are being applied

1. Initialize an engine via the API. This time pass any of the `timeout,
frequency, delay and docsPerSecond` options in the request body.
2. Once the `status` changes to `started`, query the respective
transform: `GET
_transform/entities-v1-latest-security_<entity_type>_default`
3. Check that the parameters have been applied to the transform

### Checking Saved Object Migration

1. Check out `main`.
2. Initialize the store.
3. Query `GET kbn:/api/entity_store/status`. Note down the fields in the
engine object.
4. Check out this branch.
5. Restart kibana.
6. Query `GET kbn:/api/entity_store/status` again. Observe the new
fields have been added and backfilled

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-01-29 20:31:47 +00:00
Dmitrii Shevchenko
199378c60c
[Security Solution] Implement rule customization license checks (#206079)
**Resolves:** https://github.com/elastic/security-team/issues/10410

## Summary

We want to make Rule Customization available at higher license tiers.  

### **Intended Workflows/UX**  

#### **Basic/Platinum/Security Essentials License Tiers**  
- **Editing Prebuilt Rules:**  
- Allow the 8.16 behavior: only actions, exceptions, snoozing, and
enable/disable options can be modified.
- On the rule editing page, all tabs except *Actions* are disabled.
Disabled tabs will display a hover explanation:
- "Upgrade to Enterprise to enable prebuilt rule customization" for ECH.
- "Upgrade to Security Complete to enable prebuilt rule customization"
for Serverless.
<img width="356" alt="image"
src="https://github.com/user-attachments/assets/72e60933-aaaf-45a0-9660-4cd066d3afec"
/>

- Rule editing via API is not restricted (tracked separately:
https://github.com/elastic/security-team/issues/11504.

- **Bulk Actions:**  
- Modifications to rule content via bulk actions are not allowed.
Prebuilt rules are excluded from bulk actions if the license level is
insufficient. Users will see an explanation for the exclusion.
    - Serverless
<img width="737" alt="image"
src="https://github.com/user-attachments/assets/99fef72f-dd38-4c73-a9e3-7b4c8018b4ed"
/>
    - ECH

- On the API level (`_bulk_action`), an error is returned if a user
tries to modify a prebuilt rule without the required license. Response
in this case looks like this:
    ```json
    {
      "statusCode": 500,
      "error": "Internal Server Error",
      "message": "Bulk edit failed",
      "attributes": {
         "errors": [
           {
             "message": "Elastic rule can't be edited",
             "status_code": 500,
             "rules": []
           }
         ]
      }
    }
    ```

- **Rule Updates:**  
  - Updates are restricted to Elastic’s incoming updates only.  
  - The rule upgrade flyout is in read-only mode.
<img width="949" alt="image"
src="https://github.com/user-attachments/assets/16a56430-63e6-4096-8ffd-b97f828abdd4"
/>
- For previously customized rules where customization is now disabled
due to insufficient licensing, a notification will appear on the upgrade
flyout, clarifying that only an upgrade to Elastic's version is
available.

![image](https://github.com/user-attachments/assets/34ef5168-4fe3-42d0-9444-14180ed86500)
- On the API level (`_perform`), only requests with `pick_version =
target` are permitted. Requests with `rule.fields` values are not
allowed.
    API response when `pick_version` is not `target`:
    ```json
    {
"message": "Only the 'TARGET' version can be selected for a rule update;
received: 'CURRENT'",
      "status_code": 400
    }
    ```
    API response when the `fields` value is provided:
    ```json
    {
"message": "Rule field customization is not allowed. Received fields:
name, description",
      "status_code": 400
    }
    ```

- **Customized Rules:**  
- Existing customizations remain intact, and the “Modified” badge is
retained
    - On the rule management, monitoring, and update tables:

![image](https://github.com/user-attachments/assets/c7990c8f-5ed3-40ab-b0c6-ddc329e69b09)
    - On the rule update flyout:

![image](https://github.com/user-attachments/assets/f74cb0bc-e7e5-49d5-8fec-b447517b5b52)
    - On the rule details page:

![image](https://github.com/user-attachments/assets/b28990f1-9e84-481e-b966-0232495f4882)

- When we edit a rule with customizations (e.g., change rule's actions),
the rule should stay marked as customized


- **Import/Export Scenarios:**  
- These are handled separately
(https://github.com/elastic/security-team/issues/11502)

#### **Enterprise/Security Complete License Tiers**  
- All rules can be fully edited
- Upgraded prebuilt or customized rules will have an editable view,
enabling full customization
2025-01-29 18:20:47 +01:00
Sid
66dab0ae0e
[Roles] Use Query Roles API for Role Management grid screen (#194630)
Closes https://github.com/elastic/kibana/issues/186266

## Release notes

Enhanced Role management to manage larger number of roles by adding
server side filtering, pagination and querying.

## Summary
- Replaced the usage of Get Roles API with Query Role API
- Added server side pagination and filtering with a maximum limit of
10000 keys (default for max results on index). Added new label to
indicate that we show only 10k results.
- Search box replicates client side implementation by only filtering on
Role names.

### Run locally
Start ES ~with the JVM option to enable this feature~:
```
yarn es snapshot --license=trial
```
Start Kibana normally
```
yarn start --no-base-path
```

Navigate to Stack Management > Roles and verify the same behavior as the
screen recording below

### Screen recording


https://github.com/user-attachments/assets/a447e7df-8aa1-4044-a6b2-0aafe56844a9



## Technical notes
- Client side EuiInMemory table has been replaced by EuiSearchBar,
EuiBasicTable and Filters
- One new Kibana endpoint added
    -  `roles/_query` 
- Replicates existing get_role endpoint by being public and added to
Open API spec
- Extra logic to handle previously UI only filter to show/hide reserved
roles
- Parse the query to construct the correct DSL if the filter is present
- Update Get All Roles by Space internal API to use the Query Role and
filter by space id using query DSL.

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-01-29 15:38:03 +01:00
Gerard Soldevila
4a00449bdc
SKA: Relocate core mock and test-helper modules (#208538)
## Summary

This PR aims at relocating some of the Kibana modules (plugins and
packages) into a new folder structure, according to the _Sustainable
Kibana Architecture_ initiative.

> [!IMPORTANT]
> * We kindly ask you to:
> * Manually fix the errors in the error section below (if there are
any).
> * Search for the `packages[\/\\]` and `plugins[\/\\]` patterns in the
source code (Babel and Eslint config files), and update them
appropriately.
> * Manually review
`.buildkite/scripts/pipelines/pull_request/pipeline.ts` to ensure that
any CI pipeline customizations continue to be correctly applied after
the changed path names
> * Review all of the updated files, specially the `.ts` and `.js` files
listed in the sections below, as some of them contain relative paths
that have been updated.
> * Think of potential impact of the move, including tooling and
configuration files that can be pointing to the relocated modules. E.g.:
>     * customised eslint rules
>     * docs pointing to source code

> [!NOTE]
> * This PR has been auto-generated.
> * Any manual contributions will be lost if the 'relocate' script is
re-run.
> * Try to obtain the missing reviews / approvals before applying manual
fixes, and/or keep your changes in a .patch / git stash.
> * Please use
[#sustainable_kibana_architecture](https://elastic.slack.com/archives/C07TCKTA22E)
Slack channel for feedback.

Are you trying to rebase this PR to solve merge conflicts? Please follow
the steps describe
[here](https://elastic.slack.com/archives/C07TCKTA22E/p1734019532879269?thread_ts=1734019339.935419&cid=C07TCKTA22E).

#### 55 packages(s) are going to be relocated:

| Id | Target folder |
| -- | ------------- |
| `@kbn/core-analytics-browser-mocks` |
`src/core/packages/analytics/browser-mocks` |
| `@kbn/core-analytics-server-mocks` |
`src/core/packages/analytics/server-mocks` |
| `@kbn/core-application-browser-mocks` |
`src/core/packages/application/browser-mocks` |
| `@kbn/core-apps-browser-mocks` |
`src/core/packages/apps/browser-mocks` |
| `@kbn/core-base-browser-mocks` |
`src/core/packages/base/browser-mocks` |
| `@kbn/core-base-server-mocks` | `src/core/packages/base/server-mocks`
|
| `@kbn/core-capabilities-browser-mocks` |
`src/core/packages/capabilities/browser-mocks` |
| `@kbn/core-capabilities-server-mocks` |
`src/core/packages/capabilities/server-mocks` |
| `@kbn/core-chrome-browser-mocks` |
`src/core/packages/chrome/browser-mocks` |
| `@kbn/core-deprecations-browser-mocks` |
`src/core/packages/deprecations/browser-mocks` |
| `@kbn/core-deprecations-server-mocks` |
`src/core/packages/deprecations/server-mocks` |
| `@kbn/core-doc-links-browser-mocks` |
`src/core/packages/doc-links/browser-mocks` |
| `@kbn/core-doc-links-server-mocks` |
`src/core/packages/doc-links/server-mocks` |
| `@kbn/core-elasticsearch-client-server-mocks` |
`src/core/packages/elasticsearch/client-server-mocks` |
| `@kbn/core-elasticsearch-server-mocks` |
`src/core/packages/elasticsearch/server-mocks` |
| `@kbn/core-environment-server-mocks` |
`src/core/packages/environment/server-mocks` |
| `@kbn/core-execution-context-browser-mocks` |
`src/core/packages/execution-context/browser-mocks` |
| `@kbn/core-execution-context-server-mocks` |
`src/core/packages/execution-context/server-mocks` |
| `@kbn/core-fatal-errors-browser-mocks` |
`src/core/packages/fatal-errors/browser-mocks` |
| `@kbn/core-http-browser-mocks` |
`src/core/packages/http/browser-mocks` |
| `@kbn/core-http-context-server-mocks` |
`src/core/packages/http/context-server-mocks` |
| `@kbn/core-http-resources-server-mocks` |
`src/core/packages/http/resources-server-mocks` |
| `@kbn/core-http-router-server-mocks` |
`src/core/packages/http/router-server-mocks` |
| `@kbn/core-http-server-mocks` | `src/core/packages/http/server-mocks`
|
| `@kbn/core-i18n-browser-mocks` |
`src/core/packages/i18n/browser-mocks` |
| `@kbn/core-i18n-server-mocks` | `src/core/packages/i18n/server-mocks`
|
| `@kbn/core-injected-metadata-browser-mocks` |
`src/core/packages/injected-metadata/browser-mocks` |
| `@kbn/core-integrations-browser-mocks` |
`src/core/packages/integrations/browser-mocks` |
| `@kbn/core-lifecycle-browser-mocks` |
`src/core/packages/lifecycle/browser-mocks` |
| `@kbn/core-lifecycle-server-mocks` |
`src/core/packages/lifecycle/server-mocks` |
| `@kbn/core-logging-browser-mocks` |
`src/core/packages/logging/browser-mocks` |
| `@kbn/core-logging-server-mocks` |
`src/core/packages/logging/server-mocks` |
| `@kbn/core-metrics-collectors-server-mocks` |
`src/core/packages/metrics/collectors-server-mocks` |
| `@kbn/core-metrics-server-mocks` |
`src/core/packages/metrics/server-mocks` |
| `@kbn/core-node-server-mocks` | `src/core/packages/node/server-mocks`
|
| `@kbn/core-notifications-browser-mocks` |
`src/core/packages/notifications/browser-mocks` |
| `@kbn/core-overlays-browser-mocks` |
`src/core/packages/overlays/browser-mocks` |
| `@kbn/core-plugins-browser-mocks` |
`src/core/packages/plugins/browser-mocks` |
| `@kbn/core-plugins-server-mocks` |
`src/core/packages/plugins/server-mocks` |
| `@kbn/core-preboot-server-mocks` |
`src/core/packages/preboot/server-mocks` |
| `@kbn/core-rendering-browser-mocks` |
`src/core/packages/rendering/browser-mocks` |
| `@kbn/core-rendering-server-mocks` |
`src/core/packages/rendering/server-mocks` |
| `@kbn/core-saved-objects-api-server-mocks` |
`src/core/packages/saved-objects/api-server-mocks` |
| `@kbn/core-saved-objects-base-server-mocks` |
`src/core/packages/saved-objects/base-server-mocks` |
| `@kbn/core-saved-objects-browser-mocks` |
`src/core/packages/saved-objects/browser-mocks` |
| `@kbn/core-saved-objects-import-export-server-mocks` |
`src/core/packages/saved-objects/import-export-server-mocks` |
| `@kbn/core-saved-objects-migration-server-mocks` |
`src/core/packages/saved-objects/migration-server-mocks` |
| `@kbn/core-saved-objects-server-mocks` |
`src/core/packages/saved-objects/server-mocks` |
| `@kbn/core-status-server-mocks` |
`src/core/packages/status/server-mocks` |
| `@kbn/core-test-helpers-kbn-server` |
`src/dev/packages/core-test-helpers-kbn-server` |
| `@kbn/core-test-helpers-model-versions` |
`src/dev/packages/core-test-helpers-model-versions` |
| `@kbn/core-theme-browser-mocks` |
`src/core/packages/theme/browser-mocks` |
| `@kbn/core-ui-settings-browser-mocks` |
`src/core/packages/ui-settings/browser-mocks` |
| `@kbn/core-ui-settings-server-mocks` |
`src/core/packages/ui-settings/server-mocks` |
| `@kbn/core-usage-data-server-mocks` |
`src/core/packages/usage-data/server-mocks` |


<details >
<summary>Updated references</summary>

```
./.github/codeql/codeql-config.yml
./package.json
./packages/kbn-ts-projects/config-paths.json
./src/core/packages/analytics/browser-mocks/jest.config.js
./src/core/packages/analytics/server-mocks/jest.config.js
./src/core/packages/application/browser-mocks/jest.config.js
./src/core/packages/apps/browser-mocks/jest.config.js
./src/core/packages/base/browser-mocks/jest.config.js
./src/core/packages/base/server-mocks/jest.config.js
./src/core/packages/capabilities/browser-mocks/jest.config.js
./src/core/packages/capabilities/server-mocks/jest.config.js
./src/core/packages/chrome/browser-mocks/jest.config.js
./src/core/packages/deprecations/browser-mocks/jest.config.js
./src/core/packages/deprecations/server-mocks/jest.config.js
./src/core/packages/doc-links/browser-mocks/jest.config.js
./src/core/packages/doc-links/server-mocks/jest.config.js
./src/core/packages/elasticsearch/client-server-mocks/jest.config.js
./src/core/packages/elasticsearch/server-mocks/jest.config.js
./src/core/packages/environment/server-mocks/jest.config.js
./src/core/packages/execution-context/browser-mocks/jest.config.js
./src/core/packages/execution-context/server-mocks/jest.config.js
./src/core/packages/fatal-errors/browser-mocks/jest.config.js
./src/core/packages/http/browser-mocks/jest.config.js
./src/core/packages/http/context-server-mocks/jest.config.js
./src/core/packages/http/resources-server-mocks/jest.config.js
./src/core/packages/http/router-server-mocks/jest.config.js
./src/core/packages/http/server-mocks/jest.config.js
./src/core/packages/i18n/browser-mocks/jest.config.js
./src/core/packages/i18n/server-mocks/jest.config.js
./src/core/packages/injected-metadata/browser-mocks/jest.config.js
./src/core/packages/integrations/browser-mocks/jest.config.js
./src/core/packages/lifecycle/browser-mocks/jest.config.js
./src/core/packages/lifecycle/server-mocks/jest.config.js
./src/core/packages/logging/browser-mocks/jest.config.js
./src/core/packages/logging/server-mocks/jest.config.js
./src/core/packages/metrics/collectors-server-mocks/jest.config.js
./src/core/packages/metrics/server-mocks/jest.config.js
./src/core/packages/node/server-mocks/jest.config.js
./src/core/packages/notifications/browser-mocks/jest.config.js
./src/core/packages/overlays/browser-mocks/jest.config.js
./src/core/packages/plugins/browser-mocks/jest.config.js
./src/core/packages/plugins/server-mocks/jest.config.js
./src/core/packages/preboot/server-mocks/jest.config.js
./src/core/packages/rendering/browser-mocks/jest.config.js
./src/core/packages/rendering/server-mocks/jest.config.js
./src/core/packages/saved-objects/api-server-mocks/jest.config.js
./src/core/packages/saved-objects/base-server-mocks/jest.config.js
./src/core/packages/saved-objects/browser-mocks/jest.config.js
./src/core/packages/saved-objects/import-export-server-mocks/jest.config.js
./src/core/packages/saved-objects/migration-server-mocks/jest.config.js
./src/core/packages/saved-objects/server-mocks/jest.config.js
./src/core/packages/status/server-mocks/jest.config.js
./src/core/packages/theme/browser-mocks/jest.config.js
./src/core/packages/ui-settings/browser-mocks/jest.config.js
./src/core/packages/ui-settings/server-mocks/jest.config.js
./src/core/packages/usage-data/server-mocks/jest.config.js
./src/core/system/tsconfig.type_check.json
./src/dev/packages/core-test-helpers-kbn-server/jest.config.js
./src/dev/packages/core-test-helpers-model-versions/jest.config.js
./src/dev/tsconfig.type_check.json
./src/platform/packages/private/kbn-repo-packages/package-map.json
./src/platform/plugins/private/interactive_setup/tsconfig.type_check.json
./src/platform/plugins/shared/console/tsconfig.type_check.json
./src/plugins/kibana_usage_collection/tsconfig.type_check.json
./src/plugins/saved_objects_management/tsconfig.type_check.json
./src/plugins/telemetry/tsconfig.type_check.json
./src/plugins/usage_collection/tsconfig.type_check.json
./tsconfig.base.json
./tsconfig.base.type_check.json
./tsconfig.refs.json
./x-pack/platform/plugins/private/index_lifecycle_management/tsconfig.type_check.json
./x-pack/platform/plugins/private/remote_clusters/tsconfig.type_check.json
./x-pack/platform/plugins/private/snapshot_restore/tsconfig.type_check.json
./x-pack/platform/plugins/private/watcher/tsconfig.type_check.json
./x-pack/platform/plugins/shared/encrypted_saved_objects/tsconfig.type_check.json
./x-pack/platform/plugins/shared/fleet/tsconfig.type_check.json
./x-pack/platform/plugins/shared/security/tsconfig.type_check.json
./x-pack/platform/plugins/shared/spaces/tsconfig.type_check.json
./x-pack/plugins/actions/tsconfig.type_check.json
./x-pack/plugins/aiops/tsconfig.type_check.json
./x-pack/plugins/alerting/tsconfig.type_check.json
./x-pack/plugins/cases/tsconfig.type_check.json
./x-pack/plugins/enterprise_search/tsconfig.type_check.json
./x-pack/plugins/integration_assistant/tsconfig.type_check.json
./x-pack/plugins/ml/tsconfig.type_check.json
./x-pack/plugins/observability_solution/apm/tsconfig.type_check.json
./x-pack/plugins/observability_solution/apm_data_access/tsconfig.type_check.json
./x-pack/plugins/observability_solution/entity_manager/tsconfig.type_check.json
./x-pack/plugins/observability_solution/exploratory_view/tsconfig.type_check.json
./x-pack/plugins/observability_solution/observability/tsconfig.type_check.json
./x-pack/plugins/observability_solution/slo/tsconfig.type_check.json
./x-pack/plugins/observability_solution/synthetics/tsconfig.type_check.json
./x-pack/plugins/observability_solution/uptime/tsconfig.type_check.json
./x-pack/plugins/rule_registry/tsconfig.type_check.json
./x-pack/plugins/search_playground/tsconfig.type_check.json
./x-pack/plugins/serverless_search/tsconfig.type_check.json
./x-pack/plugins/stack_alerts/tsconfig.type_check.json
./x-pack/plugins/stack_connectors/tsconfig.type_check.json
./x-pack/plugins/task_manager/tsconfig.type_check.json
./x-pack/plugins/transform/tsconfig.type_check.json
./x-pack/solutions/observability/plugins/dataset_quality/tsconfig.type_check.json
./x-pack/solutions/security/packages/security-solution/ecs_data_quality_dashboard/tsconfig.type_check.json
./x-pack/solutions/security/plugins/ecs_data_quality_dashboard/tsconfig.type_check.json
./yarn.lock
.github/CODEOWNERS
```

</details><details >
<summary>Updated relative paths</summary>

```
src/core/packages/analytics/browser-mocks/jest.config.js:12
src/core/packages/analytics/browser-mocks/tsconfig.json:2
src/core/packages/analytics/server-mocks/jest.config.js:12
src/core/packages/analytics/server-mocks/tsconfig.json:2
src/core/packages/application/browser-mocks/jest.config.js:12
src/core/packages/application/browser-mocks/tsconfig.json:2
src/core/packages/apps/browser-mocks/jest.config.js:12
src/core/packages/apps/browser-mocks/tsconfig.json:2
src/core/packages/base/browser-mocks/jest.config.js:12
src/core/packages/base/browser-mocks/tsconfig.json:2
src/core/packages/base/server-mocks/jest.config.js:12
src/core/packages/base/server-mocks/tsconfig.json:2
src/core/packages/capabilities/browser-mocks/jest.config.js:12
src/core/packages/capabilities/browser-mocks/tsconfig.json:2
src/core/packages/capabilities/server-mocks/jest.config.js:12
src/core/packages/capabilities/server-mocks/tsconfig.json:2
src/core/packages/chrome/browser-mocks/jest.config.js:12
src/core/packages/chrome/browser-mocks/tsconfig.json:2
src/core/packages/deprecations/browser-mocks/jest.config.js:12
src/core/packages/deprecations/browser-mocks/tsconfig.json:2
src/core/packages/deprecations/server-mocks/jest.config.js:12
src/core/packages/deprecations/server-mocks/tsconfig.json:2
src/core/packages/doc-links/browser-mocks/jest.config.js:12
src/core/packages/doc-links/browser-mocks/tsconfig.json:2
src/core/packages/doc-links/server-mocks/jest.config.js:12
src/core/packages/doc-links/server-mocks/tsconfig.json:2
src/core/packages/elasticsearch/client-server-mocks/jest.config.js:12
src/core/packages/elasticsearch/client-server-mocks/tsconfig.json:2
src/core/packages/elasticsearch/server-mocks/jest.config.js:12
src/core/packages/elasticsearch/server-mocks/tsconfig.json:2
src/core/packages/environment/server-mocks/jest.config.js:12
src/core/packages/environment/server-mocks/tsconfig.json:2
src/core/packages/execution-context/browser-mocks/jest.config.js:12
src/core/packages/execution-context/browser-mocks/tsconfig.json:2
src/core/packages/execution-context/server-mocks/jest.config.js:12
src/core/packages/execution-context/server-mocks/tsconfig.json:2
src/core/packages/fatal-errors/browser-mocks/jest.config.js:12
src/core/packages/fatal-errors/browser-mocks/tsconfig.json:2
src/core/packages/http/browser-mocks/jest.config.js:12
src/core/packages/http/browser-mocks/tsconfig.json:2
src/core/packages/http/context-server-mocks/jest.config.js:12
src/core/packages/http/context-server-mocks/tsconfig.json:2
src/core/packages/http/resources-server-mocks/jest.config.js:12
src/core/packages/http/resources-server-mocks/tsconfig.json:2
src/core/packages/http/router-server-mocks/jest.config.js:12
src/core/packages/http/router-server-mocks/tsconfig.json:2
src/core/packages/http/server-mocks/jest.config.js:12
src/core/packages/http/server-mocks/tsconfig.json:2
src/core/packages/i18n/browser-mocks/jest.config.js:12
src/core/packages/i18n/browser-mocks/tsconfig.json:2
src/core/packages/i18n/server-mocks/jest.config.js:12
src/core/packages/i18n/server-mocks/tsconfig.json:2
src/core/packages/injected-metadata/browser-mocks/jest.config.js:12
src/core/packages/injected-metadata/browser-mocks/tsconfig.json:2
src/core/packages/integrations/browser-mocks/jest.config.js:12
src/core/packages/integrations/browser-mocks/tsconfig.json:2
src/core/packages/lifecycle/browser-mocks/jest.config.js:12
src/core/packages/lifecycle/browser-mocks/tsconfig.json:2
src/core/packages/lifecycle/server-mocks/jest.config.js:12
src/core/packages/lifecycle/server-mocks/tsconfig.json:2
src/core/packages/logging/browser-mocks/jest.config.js:12
src/core/packages/logging/browser-mocks/tsconfig.json:2
src/core/packages/logging/server-mocks/jest.config.js:12
src/core/packages/logging/server-mocks/tsconfig.json:2
src/core/packages/metrics/collectors-server-mocks/jest.config.js:12
src/core/packages/metrics/collectors-server-mocks/tsconfig.json:2
src/core/packages/metrics/server-mocks/jest.config.js:12
src/core/packages/metrics/server-mocks/tsconfig.json:2
src/core/packages/node/server-mocks/jest.config.js:12
src/core/packages/node/server-mocks/tsconfig.json:2
src/core/packages/notifications/browser-mocks/jest.config.js:12
src/core/packages/notifications/browser-mocks/tsconfig.json:2
src/core/packages/overlays/browser-mocks/jest.config.js:12
src/core/packages/overlays/browser-mocks/tsconfig.json:2
src/core/packages/plugins/browser-mocks/jest.config.js:12
src/core/packages/plugins/browser-mocks/tsconfig.json:2
src/core/packages/plugins/server-mocks/jest.config.js:12
src/core/packages/plugins/server-mocks/tsconfig.json:2
src/core/packages/preboot/server-mocks/jest.config.js:12
src/core/packages/preboot/server-mocks/tsconfig.json:2
src/core/packages/rendering/browser-mocks/jest.config.js:12
src/core/packages/rendering/browser-mocks/tsconfig.json:2
src/core/packages/rendering/server-mocks/jest.config.js:12
src/core/packages/rendering/server-mocks/tsconfig.json:2
src/core/packages/saved-objects/api-server-mocks/jest.config.js:12
src/core/packages/saved-objects/api-server-mocks/tsconfig.json:2
src/core/packages/saved-objects/base-server-mocks/jest.config.js:12
src/core/packages/saved-objects/base-server-mocks/tsconfig.json:2
src/core/packages/saved-objects/browser-mocks/jest.config.js:12
src/core/packages/saved-objects/browser-mocks/tsconfig.json:2
src/core/packages/saved-objects/import-export-server-mocks/jest.config.js:12
src/core/packages/saved-objects/import-export-server-mocks/tsconfig.json:2
src/core/packages/saved-objects/migration-server-mocks/jest.config.js:12
src/core/packages/saved-objects/migration-server-mocks/tsconfig.json:2
src/core/packages/saved-objects/server-mocks/jest.config.js:12
src/core/packages/saved-objects/server-mocks/tsconfig.json:2
src/core/packages/status/server-mocks/jest.config.js:12
src/core/packages/status/server-mocks/tsconfig.json:2
src/core/packages/theme/browser-mocks/jest.config.js:12
src/core/packages/theme/browser-mocks/tsconfig.json:2
src/core/packages/ui-settings/browser-mocks/jest.config.js:12
src/core/packages/ui-settings/browser-mocks/tsconfig.json:2
src/core/packages/ui-settings/server-mocks/jest.config.js:12
src/core/packages/ui-settings/server-mocks/tsconfig.json:2
src/core/packages/usage-data/server-mocks/jest.config.js:12
src/core/packages/usage-data/server-mocks/tsconfig.json:2
src/dev/packages/core-test-helpers-kbn-server/jest.config.js:12
src/dev/packages/core-test-helpers-kbn-server/tsconfig.json:2
src/dev/packages/core-test-helpers-model-versions/jest.config.js:12
src/dev/packages/core-test-helpers-model-versions/tsconfig.json:2
```

</details>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Alejandro Fernández Haro <afharo@gmail.com>
2025-01-29 12:14:44 +01:00
Kenneth Kreindler
5f888d0080
[Security Solution] [AI Assistant] security assistant content references (#206683)
> [!note]
> Planning to merge before the 9.0 feature freeze.
Documentation update issue:
https://github.com/elastic/security-docs/issues/6473

> [!tip] 
> ### Tip for the reviewer
> As a starting point to review this PR I would suggest reading the
section "How does it work (on a high level)" and viewing the hyperlinked
code. The linked code covers the main concepts of this feature and the
majority of the remaining changes in the PR are related to API schema
updates and tests.

## Summary

This PR adds citations to the security AI assistant. Citations are
produced when tools are used and they are displayed in the LLM response
as numbered superscript elements. A label appears when the user hovers
over the numbered elements and clicking on the label opens a new tab
that displays the cited data.

## How to test:
1. Enables the feature flags:
- Set value to `true`
[here](https://github.com/elastic/kibana/pull/206683/files#diff-f55be7c50853801c3933b48064ab9cbf0356e2941cd97c4c365be7a6ded9bffdR125)
2. Populate the security knowledge base with some information (e.g. a
document, an index, product documentation, the global threat report,
etc...).
3. Open the security assistant
4. Ask it the following questions about data in the knowledge base:
- What is an elastic search cold tier? - Make sure product docs are
installed
 - What topics are covered in the security lab content?
 - Ask it a question about one of your knowledge base documents.
- Which platform did my most recent alert happen on? - Make sure you
have a recent alert

## How does it work (on a high level)?

Citations are stored inside the
[ContentReferencesStore](https://github.com/elastic/kibana/pull/206683/files#diff-baf03ce192db4f13999748a38b4d920428358a4ffc62527a1d6ac0d9b234f306R17)
object. When tools are called, the tools [add citations to the
ContentReferencesStore](https://github.com/elastic/kibana/pull/206683/files#diff-5a333fdd9bf864dced06500263577e495c95c9b32c7dae9074090775df542d22R97-R99)
and pass the Id of the [ContentReferences back to the
LLM](https://github.com/elastic/kibana/pull/206683/files#diff-5a333fdd9bf864dced06500263577e495c95c9b32c7dae9074090775df542d22R102)
along side the result of the tool. The LLM can then use those
contentReference IDs in its response by forming a response like:
```
The sky is blue {reference(12345)}
```
The web client [parses out the
contentReference](https://github.com/elastic/kibana/pull/206683/files#diff-3a5c8305ac899a9e78903b0b60141dd997ba61e87342de2b9ec377165d99cfe6R23)
(`{reference(12345)}`) from the assistant message and[ replaces it with
the citation react
component](https://github.com/elastic/kibana/pull/206683/files#diff-db928fb87a862e3ebf7247baefc418de539f9c0f3fc5134a2ef56f921a52bdcbR125-R129).

### Tools that are cited:

Include citations for the following tools:
alert_counts_tool -> cites to alerts page
knowledge_base_retrieval_tool -> cites knowledge base management page
with specific entry pre-filtered
open_and_acknowledged_alerts_tool -> cites to specific alert
security_labs_tool -> cites knowledge base management page with specific
entry pre-filtered
knowledge_base indices -> opens ESQL view selecting the particular
document used
product_documentation ->  cites documentation

### Endpoints impacted
- POST
/internal/elastic_assistant/actions/connector/{connectorId}/_execute
- POST /api/security_ai_assistant/chat/complete
- GET /api/security_ai_assistant/current_user/conversations/_find
- GET /api/security_ai_assistant/current_user/conversations/:id
- PUT /api/security_ai_assistant/current_user/conversations/{id}

### Considerations:
- One of the main objectives of this feature was to produce in-text
citations to create a great user experience. Multiple approaches were
tested to do this reliably. Attempts were made to make the LLM return
structured JSON containing the citations however this was unreliable
with smaller models. Generation post-processing (issuing an additional
LLM call to annotate the response with citations) was also explored
however this also had limitations as the second LLM call would not
contain enough contextual information to create the citations reliably.
Eventually, the approach described in the section above was used
alongside few shot promoting.
- Instead of using the ContentReferencesStore to store citations, the
langGraph state could be used to save the citations. I looked at doing
this but currently, there are a few blockers in the langgraph API the
prevent this.
- Lang graph must be updated to @langchain/langgraph>=0.2.31 to get
access to the Command type so that tools can update the graph state.
- It seems that DynamicStructuredTools do not support the Command type
yet. This is something that we can clarify with the langchain team.
Once these blockers have been addressed, ContentReferencesStore could
easily be refactored to the graph state.
- The feature has been put behind a feature flag so we can test during
the feature freeze and sync the release of the documentation update. The
only thing that is not behind a feature flag is the new anonymization
button in the settings menu (don't think it is necessary and it means a
lot more code changes are required).

On few occasions, you can nudge the LLM a bit more to include citations
by appending "Include citations" to your message.


![image](https://github.com/user-attachments/assets/e87b010b-4c29-48c7-8b2b-f17ad1878b8b)


Furthermore, the settings menu has been updated to include anonymized
values and citation toggles:

![image](https://github.com/user-attachments/assets/efcbabe5-4325-4b6b-b387-84295cb0fb70)


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [X] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [X] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

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


## Release note

Adds in-text citations to security solution AI assistant responses.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Patryk Kopycinski <contact@patrykkopycinski.com>
2025-01-29 02:47:59 +01:00