Skip to content

Commit 61e5b44

Browse files
authored
[Fleet] Update template and packaging code for fleet packages (elastic#1280)
* Update template and packaging code for fleet packages * Fix linting
1 parent 12577f7 commit 61e5b44

File tree

5 files changed

+76
-35
lines changed

5 files changed

+76
-35
lines changed

NOTICE.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Detection Rules
2-
Copyright 2020 Elasticsearch B.V.
2+
Copyright 2021 Elasticsearch B.V.
33

44
---
55
This product bundles rules based on https://github.com/BlueTeamLabs/sentinel-attack
6-
which is available under a "MIT" license. The files based on this license are:
6+
which is available under a "MIT" license. The rules based on this license are:
77

8-
- defense_evasion_via_filter_manager
9-
- discovery_process_discovery_via_tasklist_command
10-
- persistence_priv_escalation_via_accessibility_features
11-
- persistence_via_application_shimming
12-
- defense_evasion_execution_via_trusted_developer_utilities
8+
- "Potential Evasion via Filter Manager" (06dceabf-adca-48af-ac79-ffdf4c3b1e9a)
9+
- "Process Discovery via Tasklist" (cc16f774-59f9-462d-8b98-d27ccd4519ec)
10+
- "Potential Modification of Accessibility Binaries" (7405ddf1-6c8e-41ce-818f-48bea6bcaed8)
11+
- "Potential Application Shimming via Sdbinst" (fd4a992d-6130-4802-9ff8-829b89ae801f)
12+
- "Trusted Developer Application Usage" (9d110cb3-5f4b-4c9a-b9f5-53f0a1707ae1)
1313

1414
MIT License
1515

@@ -35,9 +35,9 @@ SOFTWARE.
3535

3636
---
3737
This product bundles rules based on https://github.com/FSecureLABS/leonidas
38-
which is available under a "MIT" license. The files based on this license are:
38+
which is available under a "MIT" license. The rules based on this license are:
3939

40-
- credential_access_secretsmanager_getsecretvalue.toml
40+
- "AWS Access Secret in Secrets Manager" (a00681e3-9ed6-447c-ab2c-be648821c622)
4141

4242
MIT License
4343

detection_rules/packaging.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import json
1111
import os
1212
import shutil
13+
import textwrap
1314
from collections import defaultdict, OrderedDict
1415
from pathlib import Path
1516
from typing import List, Optional, Tuple
@@ -27,6 +28,7 @@
2728
RELEASE_DIR = get_path("releases")
2829
PACKAGE_FILE = get_etc_path('packages.yml')
2930
NOTICE_FILE = get_path('NOTICE.txt')
31+
FLEET_PKG_LOGO = get_etc_path("security-logo-color-64px.svg")
3032

3133

3234
# CHANGELOG_FILE = Path(get_etc_path('rules-changelog.json'))
@@ -476,30 +478,44 @@ def _generate_registry_package(self, save_dir):
476478

477479
manifest = RegistryPackageManifest.from_dict(self.registry_data)
478480

479-
package_dir = Path(save_dir).joinpath(manifest.version)
481+
package_dir = Path(save_dir) / 'fleet' / manifest.version
480482
docs_dir = package_dir / 'docs'
481483
rules_dir = package_dir / 'kibana' / definitions.ASSET_TYPE
482484

483485
docs_dir.mkdir(parents=True)
484486
rules_dir.mkdir(parents=True)
485487

486-
manifest_file = package_dir.joinpath('manifest.yml')
487-
readme_file = docs_dir.joinpath('README.md')
488-
notice_file = package_dir.joinpath('NOTICE.txt')
488+
manifest_file = package_dir / 'manifest.yml'
489+
readme_file = docs_dir / 'README.md'
490+
notice_file = package_dir / 'NOTICE.txt'
491+
logo_file = package_dir / 'img' / 'security-logo-color-64px.png'
489492

490493
manifest_file.write_text(yaml.safe_dump(manifest.asdict()))
494+
495+
logo_file.parent.mkdir(parents=True)
496+
shutil.copyfile(FLEET_PKG_LOGO, logo_file)
491497
# shutil.copyfile(CHANGELOG_FILE, str(rules_dir.joinpath('CHANGELOG.json')))
492498

493499
for rule in self.rules:
494-
asset_path = rules_dir / f'rule-{rule.id}.json'
500+
asset_path = rules_dir / f'{rule.id}.json'
495501
asset_path.write_text(json.dumps(rule.get_asset(), indent=4, sort_keys=True), encoding="utf-8")
496502

497-
readme_text = ('# Detection rules\n\n'
498-
'The detection rules package stores all the security rules '
499-
'for the detection engine within the Elastic Security application.\n\n')
503+
notice_contents = Path(NOTICE_FILE).read_text()
504+
readme_text = textwrap.dedent("""
505+
# Detection rules
506+
507+
The detection rules package stores the prebuilt security rules for the Elastic Security [detection engine](https://www.elastic.co/guide/en/security/7.13/detection-engine-overview.html).
508+
509+
To download or update the rules, click **Settings** > **Install Prebuilt Security Detection Rules assets**.
510+
Then [import](https://www.elastic.co/guide/en/security/master/rules-ui-management.html#load-prebuilt-rules)
511+
the rules into the Detection engine.
512+
513+
## License Notice
514+
515+
""") + textwrap.indent(notice_contents, prefix=" ") # noqa: E501
500516

501517
readme_file.write_text(readme_text)
502-
notice_file.write_text(Path(NOTICE_FILE).read_text())
518+
notice_file.write_text(notice_contents)
503519

504520
def bump_versions(self, save_changes=False, current_versions=None):
505521
"""Bump the versions of all production rules included in a release and optionally save changes."""

detection_rules/schemas/registry_package.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"""Definitions for packages destined for the registry."""
77

88
from dataclasses import dataclass, field
9-
from typing import Dict, List, Type
9+
from typing import Dict, List, Optional, Type
1010

11-
from marshmallow import Schema, validate
11+
from marshmallow import Schema
1212
from marshmallow_dataclass import class_schema
1313

1414
from .definitions import ConditionSemVer, SemVer
@@ -18,22 +18,22 @@
1818
class RegistryPackageManifest:
1919
"""Base class for registry packages."""
2020

21+
categories: List[str]
2122
conditions: Dict[str, ConditionSemVer]
23+
description: str
24+
format_version: SemVer
25+
icons: list
26+
license: str
27+
name: str
28+
owner: Dict[str, str]
29+
release: str
30+
title: str
31+
type: str
2232
version: SemVer
2333

24-
categories: List[str] = field(default_factory=lambda: ['security'])
25-
description: str = 'Rules for the detection engine in the Security application.'
26-
format_version: SemVer = field(metadata=dict(validate=validate.Equal('1.0.0')), default='1.0.0')
27-
icons: list = field(default_factory=list)
28-
internal: bool = True
29-
license: str = 'basic'
30-
name: str = 'detection_rules'
31-
owner: Dict[str, str] = field(default_factory=lambda: dict(github='elastic/protections'))
34+
internal: Optional[bool] = None
3235
policy_templates: list = field(default_factory=list)
33-
release: str = 'experimental'
3436
screenshots: list = field(default_factory=list)
35-
title: str = 'Detection rules'
36-
type: str = 'integration'
3737

3838
@classmethod
3939
def get_schema(cls) -> Type[Schema]:

etc/packages.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,20 @@ package:
2424

2525
# elastic/integrations
2626
registry_data:
27-
# integration package schema version
28-
format_version: "1.0.0"
27+
categories: ["security"]
2928
conditions:
3029
kibana_version: "^7.13.0"
31-
# this determines the version for the package-storage generated artifact
32-
version: "0.0.1-dev.3"
30+
description: "Prebuilt detection rules for Elastic Security"
31+
format_version: "1.0.0"
32+
icons:
33+
- src: "/img/security-logo-color-64px.svg"
34+
size: "16x16"
35+
type: "image/svg+xml"
36+
license: basic
37+
name: "detection_rules"
38+
owner:
39+
github: elastic/protections
40+
release: "beta"
41+
title: "Prebuilt Security Detection Rules"
42+
type: "integration"
43+
version: "0.13.0"

etc/security-logo-color-64px.svg

Lines changed: 14 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)