Skip to content

Commit e3841fb

Browse files
[FR] Update Docs for Prebuilt Rule Customization (#4787)
* Update Docs for Prebuilt Rule Customization
1 parent 718b64f commit e3841fb

File tree

3 files changed

+53
-65
lines changed

3 files changed

+53
-65
lines changed

CLI.md

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ and will accept any valid rule in the following formats:
8787
```console
8888
Usage: detection_rules import-rules-to-repo [OPTIONS] [INPUT_FILE]...
8989

90-
Import rules from json, toml, yaml, or Kibana exported rule file(s).
90+
Import rules from json, toml, or yaml files containing Kibana exported rule(s).
9191

9292
Options:
9393
-ac, --action-connector-import Include action connectors in export
@@ -102,6 +102,8 @@ Options:
102102
-ske, --skip-errors Skip rule import errors
103103
-da, --default-author TEXT Default author for rules missing one
104104
-snv, --strip-none-values Strip None values from the rule
105+
-lc, --local-creation-date Preserve the local creation date of the rule
106+
-lu, --local-updated-date Preserve the local updated date of the rule
105107
-h, --help Show this message and exit.
106108
```
107109

@@ -145,16 +147,11 @@ Usage: detection_rules kibana [OPTIONS] COMMAND [ARGS]...
145147

146148
Options:
147149
--ignore-ssl-errors TEXT
148-
--space TEXT Kibana space
149-
--provider-name TEXT Elastic Cloud providers: cloud-basic and cloud-saml (for SSO)
150-
--provider-type TEXT Elastic Cloud providers: basic and saml (for SSO)
151-
-ku, --kibana-user TEXT
152-
--kibana-url TEXT
153-
-kp, --kibana-password TEXT
154-
-kc, --kibana-cookie TEXT Cookie from an authed session
150+
--space TEXT Kibana space
155151
--api-key TEXT
156-
--cloud-id TEXT ID of the cloud instance.
157-
-h, --help Show this message and exit.
152+
--cloud-id TEXT ID of the cloud instance.
153+
--kibana-url TEXT
154+
-h, --help Show this message and exit.
158155

159156
Commands:
160157
export-rules Export custom rules from Kibana.
@@ -178,15 +175,10 @@ python -m detection_rules kibana search-alerts -h
178175
Kibana client:
179176
Options:
180177
--ignore-ssl-errors TEXT
181-
--space TEXT Kibana space
182-
--provider-name TEXT Elastic Cloud providers: cloud-basic and cloud-saml (for SSO)
183-
--provider-type TEXT Elastic Cloud providers: basic and saml (for SSO)
184-
-ku, --kibana-user TEXT
185-
--kibana-url TEXT
186-
-kp, --kibana-password TEXT
187-
-kc, --kibana-cookie TEXT Cookie from an authed session
178+
--space TEXT Kibana space
188179
--api-key TEXT
189-
--cloud-id TEXT ID of the cloud instance.
180+
--cloud-id TEXT ID of the cloud instance.
181+
--kibana-url TEXT
190182

191183
Usage: detection_rules kibana search-alerts [OPTIONS] [QUERY]
192184

@@ -202,7 +194,7 @@ Options:
202194
```
203195

204196
Running the following command will print out a table showing any alerts that have been generated recently.
205-
`python3 -m detection_rules kibana --provider-name cloud-basic --kibana-url <url> --kibana-user <username> --kibana-password <password> search-alerts`
197+
`python3 -m detection_rules kibana --provider-name cloud-basic --kibana-url <url> --api-key <api-key> search-alerts`
206198

207199
```console
208200

@@ -243,15 +235,10 @@ python -m detection_rules kibana import-rules -h
243235
Kibana client:
244236
Options:
245237
--ignore-ssl-errors TEXT
246-
--space TEXT Kibana space
247-
--provider-name TEXT Elastic Cloud providers: cloud-basic and cloud-saml (for SSO)
248-
--provider-type TEXT Elastic Cloud providers: basic and saml (for SSO)
249-
-ku, --kibana-user TEXT
250-
--kibana-url TEXT
251-
-kp, --kibana-password TEXT
252-
-kc, --kibana-cookie TEXT Cookie from an authed session
238+
--space TEXT Kibana space
253239
--api-key TEXT
254-
--cloud-id TEXT ID of the cloud instance.
240+
--cloud-id TEXT ID of the cloud instance.
241+
--kibana-url TEXT
255242
256243
Usage: detection_rules kibana import-rules [OPTIONS]
257244
@@ -261,11 +248,11 @@ Options:
261248
-f, --rule-file FILE
262249
-d, --directory DIRECTORY Recursively load rules from a directory
263250
-id, --rule-id TEXT
251+
-nt, --no-tactic-filename Allow rule filenames without tactic prefix. Use this if rules have been exported with this flag.
264252
-o, --overwrite Overwrite existing rules
265253
-e, --overwrite-exceptions Overwrite exceptions in existing rules
266254
-ac, --overwrite-action-connectors
267255
Overwrite action connectors in existing rules
268-
-nt, --no-tactic-filename Allow rule filenames without tactic prefix. Use this if rules have been exported with this flag.
269256
-h, --help Show this message and exit.
270257
```
271258

@@ -422,14 +409,12 @@ Options:
422409
-f, --rule-file FILE
423410
-d, --directory DIRECTORY Recursively load rules from a directory
424411
-id, --rule-id TEXT
412+
-nt, --no-tactic-filename Allow rule filenames without tactic prefix. Use this if rules have been exported with this flag.
425413
-o, --outfile PATH Name of file for exported rules
426414
-r, --replace-id Replace rule IDs with new IDs before export
427-
--stack-version [7.8|7.9|7.10|7.11|7.12|7.13|7.14|7.15|7.16|8.0|8.1|8.2|8.3|8.4|8.5|8.6|8.7|8.8|8.9|8.10|8.11|8.12|8.13|8.14]
428-
Downgrade a rule version to be compatible
429-
with older instances of Kibana
430-
-s, --skip-unsupported If `--stack-version` is passed, skip rule
431-
types which are unsupported (an error will
432-
be raised otherwise)
415+
--stack-version [7.8|7.9|7.10|7.11|7.12|7.13|7.14|7.15|7.16|8.0|8.1|8.2|8.3|8.4|8.5|8.6|8.7|8.8|8.9|8.10|8.11|8.12|8.13|8.14|8.15|8.16|8.17|8.18|9.0]
416+
Downgrade a rule version to be compatible with older instances of Kibana
417+
-s, --skip-unsupported If `--stack-version` is passed, skip rule types which are unsupported (an error will be raised otherwise)
433418
--include-metadata Add metadata to the exported rules
434419
-ac, --include-action-connectors
435420
Include Action Connectors in export
@@ -458,15 +443,10 @@ python -m detection_rules kibana upload-rule -h
458443
Kibana client:
459444
Options:
460445
--ignore-ssl-errors TEXT
461-
--space TEXT Kibana space
462-
--provider-name TEXT Elastic Cloud providers: cloud-basic and cloud-saml (for SSO)
463-
--provider-type TEXT Elastic Cloud providers: basic and saml (for SSO)
464-
-ku, --kibana-user TEXT
465-
--kibana-url TEXT
466-
-kp, --kibana-password TEXT
467-
-kc, --kibana-cookie TEXT Cookie from an authed session
446+
--space TEXT Kibana space
468447
--api-key TEXT
469-
--cloud-id TEXT ID of the cloud instance.
448+
--cloud-id TEXT ID of the cloud instance.
449+
--kibana-url TEXT
470450

471451
Usage: detection_rules kibana upload-rule [OPTIONS]
472452

@@ -476,6 +456,7 @@ Options:
476456
-f, --rule-file FILE
477457
-d, --directory DIRECTORY Recursively load rules from a directory
478458
-id, --rule-id TEXT
459+
-nt, --no-tactic-filename Allow rule filenames without tactic prefix. Use this if rules have been exported with this flag.
479460
-r, --replace-id Replace rule IDs with new IDs before export
480461
-h, --help Show this message and exit.
481462
```
@@ -484,6 +465,8 @@ Options:
484465

485466
This command should be run with the `CUSTOM_RULES_DIR` envvar set, that way proper validation is applied to versioning when the rules are downloaded. See the [custom rules docs](docs-dev/custom-rules-management.md) for more information.
486467

468+
Note: This command can be used for exporting pre-built, customized pre-built, and custom rules. By default, all rules will be exported. Use the `-cro` flag to only export custom rules, or the `-eq` flag to filter by query.
469+
487470
```
488471
python -m detection_rules kibana export-rules -h
489472
@@ -494,15 +477,10 @@ python -m detection_rules kibana export-rules -h
494477
Kibana client:
495478
Options:
496479
--ignore-ssl-errors TEXT
497-
--space TEXT Kibana space
498-
--provider-name TEXT Elastic Cloud providers: cloud-basic and cloud-saml (for SSO)
499-
--provider-type TEXT Elastic Cloud providers: basic and saml (for SSO)
500-
-ku, --kibana-user TEXT
501-
--kibana-url TEXT
502-
-kp, --kibana-password TEXT
503-
-kc, --kibana-cookie TEXT Cookie from an authed session
480+
--space TEXT Kibana space
504481
--api-key TEXT
505-
--cloud-id TEXT ID of the cloud instance.
482+
--cloud-id TEXT ID of the cloud instance.
483+
--kibana-url TEXT
506484
507485
Usage: detection_rules kibana export-rules [OPTIONS]
508486
@@ -523,6 +501,10 @@ Options:
523501
-s, --skip-errors Skip errors when exporting rules
524502
-sv, --strip-version Strip the version fields from all rules
525503
-nt, --no-tactic-filename Exclude tactic prefix in exported filenames for rules. Use same flag for import-rules to prevent warnings and disable its unit test.
504+
-lc, --local-creation-date Preserve the local creation date of the rule
505+
-lu, --local-updated-date Preserve the local updated date of the rule
506+
-cro, --custom-rules-only Only export custom rules
507+
-eq, --export-query TEXT Apply a query filter to exporting rules e.g. "alert.attributes.tags: \"test\"" to filter for rules that have the tag "test"
526508
-h, --help Show this message and exit.
527509
528510
```

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,29 @@ Usage: detection_rules [OPTIONS] COMMAND [ARGS]...
103103
Commands for detection-rules repository.
104104

105105
Options:
106-
-d, --debug / -n, --no-debug Print full exception stacktrace on errors
106+
-D, --debug / -N, --no-debug Print full exception stacktrace on errors
107107
-h, --help Show this message and exit.
108108

109109
Commands:
110-
create-rule Create a detection rule.
111-
dev Commands for development and management by internal...
112-
es Commands for integrating with Elasticsearch.
113-
import-rules Import rules from json, toml, or Kibana exported rule...
114-
kibana Commands for integrating with Kibana.
115-
mass-update Update multiple rules based on eql results.
116-
normalize-data Normalize Elasticsearch data timestamps and sort.
117-
rule-search Use KQL or EQL to find matching rules.
118-
test Run unit tests over all of the rules.
119-
toml-lint Cleanup files with some simple toml formatting.
120-
validate-all Check if all rules validates against a schema.
121-
validate-rule Check if a rule staged in rules dir validates against a...
122-
view-rule View an internal rule or specified rule file.
110+
build-limited-rules Import rules from json, toml, or Kibana exported rule file(s), filter out unsupported ones, and write to output NDJSON file.
111+
build-threat-map-entry Build a threat map entry.
112+
create-rule Create a detection rule.
113+
custom-rules Commands for supporting custom rules.
114+
dev Commands related to the Elastic Stack rules release lifecycle.
115+
es Commands for integrating with Elasticsearch.
116+
export-rules-from-repo Export rule(s) and exception(s) into an importable ndjson file.
117+
generate-rules-index Generate enriched indexes of rules, based on a KQL search, for indexing/importing into elasticsearch/kibana.
118+
import-rules-to-repo Import rules from json, toml, or yaml files containing Kibana exported rule(s).
119+
kibana Commands for integrating with Kibana.
120+
mass-update Update multiple rules based on eql results.
121+
normalize-data Normalize Elasticsearch data timestamps and sort.
122+
rule-search Use KQL or EQL to find matching rules.
123+
test Run unit tests over all of the rules.
124+
toml-lint Cleanup files with some simple toml formatting.
125+
typosquat Commands for generating typosquat detections.
126+
validate-all Check if all rules validates against a schema.
127+
validate-rule Check if a rule staged in rules dir validates against a schema.
128+
view-rule View an internal rule or specified rule file.
123129
```
124130

125131
Note:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "detection_rules"
3-
version = "1.2.13"
3+
version = "1.2.14"
44
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Security’s Detection Engine."
55
readme = "README.md"
66
requires-python = ">=3.12"

0 commit comments

Comments
 (0)