Skip to content

[Cases] Case action: Registration and Oracle#168370

Merged
cnasikas merged 23 commits intoelastic:case_actionfrom
cnasikas:register_case_action
Oct 23, 2023
Merged

[Cases] Case action: Registration and Oracle#168370
cnasikas merged 23 commits intoelastic:case_actionfrom
cnasikas:register_case_action

Conversation

@cnasikas
Copy link
Copy Markdown
Member

@cnasikas cnasikas commented Oct 9, 2023

Summary

This PR is the first of many that will follow for the case connector (automatically create cases when firing a rule). The PR will be merged on a feature branch. Please refer to the Case Action RFC for further details. In this PR:

  • Init of case connector registration
  • Create the Cases Oracle SO
  • Create the CasesOracleService to interact with the Cases Oracle SO
  • Create the CryptoService to do cryptographic operations

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// Feature:Cases Cases feature labels Oct 9, 2023
@cnasikas cnasikas self-assigned this Oct 9, 2023
@cnasikas cnasikas changed the title [Cases] [Cases] Case action: Registration and Oracle Oct 9, 2023
"dynamic": false,
"properties": {}
},
"cases-oracle": {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a new saved object type that we will use for the case action. This PR will be merged on a feature branch and the definition may change as we develop.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aren't we already sure the grouping_definition should be included?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We will not index the grouping_definition so it will not be included in the mapping.

@cnasikas cnasikas marked this pull request as ready for review October 16, 2023 10:31
@cnasikas cnasikas requested review from a team as code owners October 16, 2023 10:31
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

@cnasikas cnasikas mentioned this pull request Oct 18, 2023
2 tasks
Copy link
Copy Markdown
Contributor

@adcoelho adcoelho left a comment

Choose a reason for hiding this comment

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

LGTM I am just not familiar with the SubActionConnectors

owner,
this.cryptoService.stringifyDeterministically(grouping),
]
.filter(Boolean)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice 👌

const spaceId = 'default';
const owner = 'cases';
const grouping = { 'host.ip': '0.0.0.1', 'agent.id': '8a4f500d' };
const sortedGrouping = { 'agent.id': '8a4f500d', 'host.ip': '0.0.0.1' };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where is this done in the implementation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Here https://github.com/elastic/kibana/pull/168370/files/c210a0c9cefc167ac1c1339757ec8494729abb4e#diff-6d91ad0215d2086dc33208df409ca2e693725d41e076a04b4bee371b36cfabf6R24. json-stable-stringify always return a sorted version of the object. We need the order to be the same to produce the same hash for the same grouping no matter how the object is defined (order is not guaranteed by JS neither we should care in the application level).

const spaceId = 'default';
const owner = 'cases';

// @ts-expect-error: ruleId and grouping are omitted for testing
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does ExclusiveUnion<OracleKeyWithOptionalKey, OracleKeyWithOptionalGrouping>; guarantee that either can be null but not both?

Copy link
Copy Markdown
Member Author

@cnasikas cnasikas Oct 19, 2023

Choose a reason for hiding this comment

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

This is correct. As we throw an error either way I added a test to check it.

constructor(params: ServiceParams<CasesConnectorConfig, CasesConnectorSecrets>) {
super(params);

this.registerSubActions();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where do i find more about what this and SubActionConnector are for?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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


public async increaseCounter(recordId: string): Promise<OracleRecord> {
const { id: _, version, ...record } = await this.getRecord(recordId);
const newCounter = record.counter + 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

will there be no hard limit for the counter? We will put a limit on the number of total cases that can be created on an execution but what about total cases?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This service is responsible for interacting with the cases-oracle saved object. It is the consumer's responsibility to impose any limits before updating the counter.

type: 'date',
},
/*
grouping: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this still be commented out?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, we do not want to index the grouping at the moment. No plans to query the oracle about grouping. The other data are needed for telemetry purposes. They are not actually needed by the connector. It may change as we develop though.

"dynamic": false,
"properties": {}
},
"cases-oracle": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aren't we already sure the grouping_definition should be included?

@kibana-ci
Copy link
Copy Markdown

kibana-ci commented Oct 23, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Serverless Osquery Cypress Tests #3 / ALL - Live Query should run multiline query should run multiline query
  • [job] [logs] Jest Tests #5 / EditConnector Edit external service on submit
  • [job] [logs] Jest Tests #5 / EditConnector resets to the initial connector onCancel
  • [job] [logs] Jest Tests #5 / EditConnector reverts to the initial selection if the caseData do not change
  • [job] [logs] Jest Integration Tests #5 / migration actions waitForPickupUpdatedMappingsTask resolves left wait_for_task_completion_timeout when the task does not complete within the timeout

Metrics [docs]

‼️ ERROR: no builds found for mergeBase sha [f6c1ce9]

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @cnasikas

@cnasikas cnasikas merged commit d5bbd8e into elastic:case_action Oct 23, 2023
@cnasikas cnasikas deleted the register_case_action branch October 23, 2023 17:13
cnasikas added a commit that referenced this pull request Nov 15, 2023
## Summary

This PR is a continuation of the work for the Case action. This PR
implements the basic logic of the case connector. Specifically:

1. Group the alerts based on the grouping provided by the user
2. Create the Oracle's SO IDs to fetch the records. If they do not exist
they will get created and the counter will be set to 1.
3. Create the cases' SO IDs to fetch the Cases. If they do not exist
they will get created.
4. Attach the alerts to the corresponding cases.

Not in this PR:
- Handle errors
- Retries on errors
- Reopen cases
- Time window
- Race conditions
- Circuit breakers

Depends on: #168370,
#169484

### Checklist

Delete any items that are not applicable to this PR.

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

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
@cnasikas cnasikas mentioned this pull request Nov 29, 2023
3 tasks
cnasikas added a commit that referenced this pull request Apr 12, 2024
## Summary

Depends on: #166267,
#170326,
#169484,
#173740,
#173763,
#178068,
#178307,
#178600,
#180437

PRs:
- #168370
- #169229
- #171754
- #172709
- #173012
- #175107
- #175452
- #175505
- #177033
- #178277
- #177139
- #179796

Fixes: #153837

## Testing

Run Kibana with `--run-examples` if you want to use the "Always firing"
rule.

Create a rule with a case action in observability and the stack. The
security solution is not supported. You should not be able to assign a
case action in a security solution rule.

1. Test the "Reopen closed cases" configuration.
2. Test the "Grouping by" configuration. Only one field is allowed. Not
all fields are persisted in alerts. If you select a field not part of
the alert the case action will create a case where the grouping value is
set to `unknow`.
3. Test the "Time window" feature. You can comment out the validation to
test for shorter times.
4. Verify that the case action is experimental.
5. Verify that based on the rule type the case is created in the correct
solution.
6. Verify that you cannot create a rule with the case action on the
basic license.
7. Verify that the execution of the case action fails if you do not have
permission for cases. Pending work on the system actions framework level
to not allow users to create rules with system actions where they do not
have permission.
8. Stress test the case action by creating multiple rules.

### Checklist

Delete any items that are not applicable to this PR.

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

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

## Release notes

Automatically create cases when an alert is triggered.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: adcoelho <antonio.coelho@elastic.co>
Co-authored-by: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t//

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants