feat(elastic): add Elastic Security collector (#423)#424
Open
SamuelHassine wants to merge 5 commits into
Open
Conversation
Detection-expectation collector that queries the Elasticsearch _search API for Elastic Security detection alerts. Modeled on the splunk-es collector (pyoaev CollectorDaemon, expectation and trace services). Supports API key or basic authentication, ECS source.ip/destination.ip/url.path matching, and retry with configurable offset.
There was a problem hiding this comment.
Pull request overview
Adds a new Elastic Security collector to the OpenAEV collectors monorepo, modeled after the existing splunk-es collector, to validate detection expectations by querying Elasticsearch (POST /<index>/_search) and reporting verdicts and Kibana traces.
Changes:
- Introduces an Elasticsearch client (
ElasticClientAPI) that builds query DSL, supports API key/basic auth, and retries for ingestion latency. - Adds expectation + trace service providers and a collector daemon wiring them into the existing generic expectation/trace manager patterns.
- Adds pytest-based unit tests and polyfactory fixtures for the Elastic query/response model.
Reviewed changes
Copilot reviewed 46 out of 51 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| elastic/tests/test_create_collector.py | Validates collector initialization and config error cases. |
| elastic/tests/services/test_expectation_service_essential.py | Core expectation-service behavior tests (signatures, batching, matching). |
| elastic/tests/services/test_converter_essential.py | Converter unit tests for alert→OAEV mapping. |
| elastic/tests/services/test_client_api_essential.py | Client API tests for auth, query building, and retries. |
| elastic/tests/services/fixtures/factories.py | Polyfactory factories for configs, alerts, and test data. |
| elastic/tests/services/fixtures/init.py | Fixture package marker. |
| elastic/tests/services/conftest.py | Shared pytest fixtures for services tests. |
| elastic/tests/services/init.py | Services tests package marker. |
| elastic/tests/conftest.py | Test-wide mocking of OpenAEV calls and settings sources. |
| elastic/tests/init.py | Tests package marker. |
| elastic/src/services/utils/parent_process_parser.py | Extracts UUIDs and reconstructs URL/parent-process identifiers. |
| elastic/src/services/utils/config_loader.py | Wrapper config loader with logging and error handling. |
| elastic/src/services/utils/init.py | Exposes utils module API. |
| elastic/src/services/trace_service.py | Builds OpenAEV expectation traces (Kibana links). |
| elastic/src/services/models.py | Elastic alert/search response models and parsing helpers. |
| elastic/src/services/expectation_service.py | Expectation processing: signature extraction, fetch, convert, match. |
| elastic/src/services/exception.py | Elastic service exception hierarchy. |
| elastic/src/services/converter.py | Converts ElasticAlert objects into OAEV matchable structures. |
| elastic/src/services/client_api.py | Elasticsearch _search client with auth + retry + query DSL building. |
| elastic/src/services/init.py | Re-exports service components for external use. |
| elastic/src/py.typed | Marks package as typed for type checkers. |
| elastic/src/models/configs/elastic_configs.py | Pydantic settings for Elastic connectivity/auth/retry configuration. |
| elastic/src/models/configs/config_loader.py | Root settings loader and daemon config-flattening. |
| elastic/src/models/configs/collector_configs.py | Base collector/OpenAEV config settings models. |
| elastic/src/models/configs/base_settings.py | Shared BaseSettings configuration (env parsing, freezing, etc.). |
| elastic/src/models/configs/init.py | Config models export surface. |
| elastic/src/models/init.py | Exposes top-level ConfigLoader. |
| elastic/src/config.yml.sample | Sample YAML config for local/manual deployment. |
| elastic/src/collector/trace_service_provider.py | Protocol for trace services. |
| elastic/src/collector/trace_manager.py | Trace creation/submission logic to OpenAEV. |
| elastic/src/collector/signature_registry.py | Signature subscription/handler registry used by the collector. |
| elastic/src/collector/models.py | Collector-side Pydantic models (ExpectationResult/Trace/etc.). |
| elastic/src/collector/expectation_service_provider.py | Protocol for expectation service providers. |
| elastic/src/collector/expectation_manager.py | Generic expectation fetch/process/update loop. |
| elastic/src/collector/expectation_handler.py | Delegates expectation processing to the service provider. |
| elastic/src/collector/exception.py | Collector exception hierarchy. |
| elastic/src/collector/collector.py | CollectorDaemon implementation wiring services + managers. |
| elastic/src/collector/init.py | Collector package export surface. |
| elastic/src/.env.sample | Sample environment configuration. |
| elastic/src/main.py | CLI entrypoint to run the collector. |
| elastic/src/init.py | Package export surface. |
| elastic/README.md | Collector documentation and configuration reference. |
| elastic/pyproject.toml | Poetry packaging, dependencies, scripts, and tooling config. |
| elastic/manifest-metadata.json | Collector manifest metadata for platform/manager. |
| elastic/Dockerfile_ubi9 | UBI9-based container build. |
| elastic/Dockerfile | Alpine-based container build. |
| elastic/docker-compose.yml | Local docker-compose example configuration. |
| elastic/.gitignore | Ignores config/build/cache artifacts. |
| elastic/.dockerignore | Excludes config/build/cache artifacts from image context. |
| elastic/.build.env | Build-time metadata for collector command. |
#423) Cover the parent process parser, signature registry, expectation handler/manager, trace manager/service, converter and client error paths to bring patch coverage above the codecov threshold.
- Remove the dead ElasticAlert._raw PrivateAttr: it was assigned through the constructor (ElasticAlert(..., _raw=source)), which Pydantic v2 ignores, so it always stayed None and was never read anywhere. - Correct the _build_trace_url_from_expectation docstring to describe the actual behavior: it builds a Kibana KQL query from source/destination IPs only, not the full Elasticsearch _search query (no parent-process url.path match, no @timestamp window). - Fix the README configuration section: the loader selects a single source (first of .env, config.yml, environment variables), it does not merge env vars over YAML over defaults. - Fix the documented default collector name (Elastic, not Elastic Security) to match ConfigLoaderCollector.
Member
Author
Review and fix summaryDid an independent senior review of the full changed files (not just the diff) and addressed the Copilot review threads. Changes pushed in e34e6a9:
Deliberately not changed:
Status:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds an OpenAEV collector for Elastic Security. It validates OpenAEV detection expectations by querying Elasticsearch for Elastic Security detection alerts that match the attack signatures produced during a simulation, then reports a verdict and a trace linking back to the alerts.
Modeled on the existing
splunk-escollector (pyoaev CollectorDaemon plus expectation/trace service providers), with the SIEM-specific layer rewritten for Elasticsearch.What it does
_searchAPI (default index.alerts-security.alerts-*)source.ip,destination.ip, and parent process viaurl.path, bounded by the expectation time windowImplementation notes
_searchquery DSL, replacing the Splunk SPL clientsource.ip/destination.ip/url.path/ rule name), tolerant of flattened or nested_sourceReview feedback addressed
ElasticAlert._rawPrivateAttr: it was passed through the constructor (which Pydantic v2 ignores) so it was alwaysNoneand never read._build_trace_url_from_expectationdocstring to match the actual behavior: it builds a Kibana KQL query from source/destination IPs only, not the full Elasticsearch_searchquery..env,config.yml, environment variables); it does not merge them.Elastic, notElastic Security) to matchConfigLoaderCollector.[[ ... ]]override block to stay consistent with every other collector in the repo; the docker image build is green in CI.Test plan
bash run_test.sh elastic(pytest) green locally (43 passed)Notes
src/img/elastic-logo.png) is a placeholder and should be replaced with the official Elastic Security logo before release.Closes #423