-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution] Initial rule upgrade/install endpoints implementation #155517
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.../prebuilt_rules/api/perform_rule_installation/perform_rule_installation_request_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import * as t from 'io-ts'; | ||
|
||
export const RuleVersionSpecifier = t.exact( | ||
t.type({ | ||
rule_id: t.string, | ||
version: t.number, | ||
}) | ||
); | ||
export type RuleVersionSpecifier = t.TypeOf<typeof RuleVersionSpecifier>; | ||
|
||
export const InstallSpecificRulesRequest = t.exact( | ||
t.type({ | ||
mode: t.literal(`SPECIFIC_RULES`), | ||
rules: t.array(RuleVersionSpecifier), | ||
}) | ||
); | ||
|
||
export const InstallAllRulesRequest = t.exact( | ||
t.type({ | ||
mode: t.literal(`ALL_RULES`), | ||
}) | ||
); | ||
|
||
export const PerformRuleInstallationRequestBody = t.union([ | ||
InstallAllRulesRequest, | ||
InstallSpecificRulesRequest, | ||
]); | ||
|
||
export type PerformRuleInstallationRequestBody = t.TypeOf< | ||
typeof PerformRuleInstallationRequestBody | ||
>; |
32 changes: 32 additions & 0 deletions
32
...prebuilt_rules/api/perform_rule_installation/perform_rule_installation_response_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { RuleResponse } from '../../../rule_schema/model/rule_schemas'; | ||
import type { AggregatedPrebuiltRuleError } from '../../model/prebuilt_rules/aggregated_prebuilt_rules_error'; | ||
|
||
export enum SkipRuleInstallReason { | ||
ALREADY_INSTALLED = 'ALREADY_INSTALLED', | ||
} | ||
|
||
export interface SkippedRuleInstall { | ||
rule_id: string; | ||
reason: SkipRuleInstallReason; | ||
} | ||
|
||
export interface PerformRuleInstallationResponseBody { | ||
summary: { | ||
total: number; | ||
succeeded: number; | ||
skipped: number; | ||
failed: number; | ||
}; | ||
results: { | ||
created: RuleResponse[]; | ||
skipped: SkippedRuleInstall[]; | ||
}; | ||
errors: AggregatedPrebuiltRuleError[]; | ||
} |
71 changes: 71 additions & 0 deletions
71
...ion_engine/prebuilt_rules/api/perform_rule_upgrade/perform_rule_upgrade_request_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { enumeration } from '@kbn/securitysolution-io-ts-types'; | ||
import * as t from 'io-ts'; | ||
|
||
export enum PickVersionValues { | ||
BASE = 'BASE', | ||
CURRENT = 'CURRENT', | ||
TARGET = 'TARGET', | ||
} | ||
|
||
export const TPickVersionValues = enumeration('PickVersionValues', PickVersionValues); | ||
|
||
export const RuleUpgradeSpecifier = t.exact( | ||
t.intersection([ | ||
t.type({ | ||
rule_id: t.string, | ||
/** | ||
* This parameter is needed for handling race conditions with Optimistic Concurrency Control. | ||
* Two or more users can call installation/_review and installation/_perform endpoints concurrently. | ||
* Also, in general the time between these two calls can be anything. | ||
* The idea is to only allow the user to install a rule if the user has reviewed the exact version | ||
* of it that had been returned from the _review endpoint. If the version changed on the BE, | ||
* installation/_perform endpoint will return a version mismatch error for this rule. | ||
*/ | ||
revision: t.number, | ||
/** | ||
* The target version to upgrade to. | ||
*/ | ||
version: t.number, | ||
}), | ||
t.partial({ | ||
pick_version: TPickVersionValues, | ||
}), | ||
]) | ||
); | ||
export type RuleUpgradeSpecifier = t.TypeOf<typeof RuleUpgradeSpecifier>; | ||
|
||
export const UpgradeSpecificRulesRequest = t.exact( | ||
t.intersection([ | ||
t.type({ | ||
mode: t.literal(`SPECIFIC_RULES`), | ||
rules: t.array(RuleUpgradeSpecifier), | ||
}), | ||
t.partial({ | ||
pick_version: TPickVersionValues, | ||
}), | ||
]) | ||
); | ||
|
||
export const UpgradeAllRulesRequest = t.exact( | ||
t.intersection([ | ||
t.type({ | ||
mode: t.literal(`ALL_RULES`), | ||
}), | ||
t.partial({ | ||
pick_version: TPickVersionValues, | ||
}), | ||
]) | ||
); | ||
|
||
export const PerformRuleUpgradeRequestBody = t.union([ | ||
UpgradeAllRulesRequest, | ||
UpgradeSpecificRulesRequest, | ||
]); | ||
export type PerformRuleUpgradeRequestBody = t.TypeOf<typeof PerformRuleUpgradeRequestBody>; |
32 changes: 32 additions & 0 deletions
32
...on_engine/prebuilt_rules/api/perform_rule_upgrade/perform_rule_upgrade_response_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { RuleResponse } from '../../../rule_schema'; | ||
import type { AggregatedPrebuiltRuleError } from '../../model/prebuilt_rules/aggregated_prebuilt_rules_error'; | ||
|
||
export enum SkipRuleUpgradeReason { | ||
RULE_UP_TO_DATE = 'RULE_UP_TO_DATE', | ||
} | ||
|
||
export interface SkippedRuleUpgrade { | ||
rule_id: string; | ||
reason: SkipRuleUpgradeReason; | ||
} | ||
|
||
export interface PerformRuleUpgradeResponseBody { | ||
summary: { | ||
total: number; | ||
succeeded: number; | ||
skipped: number; | ||
failed: number; | ||
}; | ||
results: { | ||
updated: RuleResponse[]; | ||
skipped: SkippedRuleUpgrade[]; | ||
}; | ||
errors: AggregatedPrebuiltRuleError[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...n/detection_engine/prebuilt_rules/model/prebuilt_rules/aggregated_prebuilt_rules_error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export interface AggregatedPrebuiltRuleError { | ||
message: string; | ||
status_code?: number; | ||
rules: Array<{ | ||
rule_id: string; | ||
name?: string; | ||
}>; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the endpoint open to returning other kind of information other than
stats
in the future; do we have any future use cases for that?Just wandering why we would hold all data within the single
stats
property instead of making the stats themselves first-class properties.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, I do not anticipate extending the endpoint to return information other than
stats
. However, it's always good practice to keep future use cases in mind and design with flexibility for potential changes. If a new use case does arise in the future, it would be pretty straightforward to adapt this endpoint.