Back to Kibana

@kbn/attack-discovery-schedules-common

x-pack/solutions/security/packages/kbn-attack-discovery-schedules-common/README.md

9.5.05.8 KB
Original Source

@kbn/attack-discovery-schedules-common

Shared package for attack discovery schedule infrastructure, used by both elastic_assistant (public API) and discoveries (internal API).

Overview

This package provides the data client, transforms, field definitions, and types needed to manage attack discovery schedules backed by the Kibana Alerting Framework. Both the public schedule API (elastic_assistant) and the internal schedule API (discoveries) depend on this shared infrastructure.

For background on why the Alerting Framework is used for scheduling, see docs/adr_scheduling_strategy.md.

Structure

All implementation code lives under impl/:

kbn-attack-discovery-schedules-common/
├── impl/
│   ├── constants.ts                          # AAD config, alert context, app path
│   ├── build_alert_id_to_attack_ids_map/     # buildAlertIdToAttackIdsMap, AttackWithAlertIds
│   ├── data_client/                          # AttackDiscoveryScheduleDataClient (CRUD via RulesClient)
│   ├── fields/
│   │   ├── field_map.ts                      # Elasticsearch field map
│   │   └── field_names.ts                    # ALERT_ATTACK_DISCOVERY_* constants
│   ├── schedule_params_extended.ts           # Zod schema extending schedule params
│   ├── transforms/
│   │   ├── convert_alerting_rule_to_schedule.ts
│   │   ├── convert_schedule_actions_to_alerting_actions.ts
│   │   ├── create_schedule_execution_summary.ts
│   │   └── transform_to_alert_documents/     # Alert document generation + hashing
│   │       ├── get_alert_risk_score/
│   │       └── get_alert_url/
│   ├── types.ts                              # Type aliases for alerting rule types
│   ├── update_alerts_with_attack_ids/        # Updates security alerts with attack IDs
│   └── __mocks__/                            # Test mocks
├── docs/
│   └── adr_scheduling_strategy.md            # Architecture decision record
├── index.ts                                  # Curated public API
└── kibana.jsonc

Public API

Constants

ExportDescription
ATTACK_DISCOVERY_ALERTS_AAD_CONFIGAlerts-as-data configuration for the attack discovery rule type
ATTACK_DISCOVERY_ALERTS_CONTEXTAlert context identifier ('security.attack.discovery')
SECURITY_APP_PATHPath to the security app ('/app/security')
ALERTS_INDEX_PATTERNSecurity alerts index pattern base ('.alerts-security.alerts-'); exported from impl/update_alerts_with_attack_ids, not impl/constants.ts

Data client

ExportKindDescription
AttackDiscoveryScheduleDataClientClassCRUD for schedules backed by RulesClient, supports tag-based filtering
AttackDiscoveryScheduleDataClientParamsTypeConstructor params: actionsClient, filterTags?, logger, rulesClient
CreateAttackDiscoveryScheduleDataClientParamsTypeFactory function params
FilterTagsType{ includeTags?: string[], excludeTags?: string[] }

Field map and field names

ExportKindDescription
attackDiscoveryAlertFieldMapObjectElasticsearch FieldMap for attack discovery alert documents
ALERT_ATTACK_DISCOVERYConstantBase field path
ALERT_ATTACK_DISCOVERY_*ConstantsIndividual alert field paths (26 constants)
ALERT_ATTACK_IDSConstantAlert-to-attack ID mapping field
ALERT_RISK_SCOREConstantRisk score field

Extended schema

ExportKindDescription
AttackDiscoveryScheduleParamsExtendedZod schemaExtends AttackDiscoveryScheduleParams with optional insightType and workflowConfig

Transforms

ExportKindDescription
convertAlertingRuleToScheduleFunctionConverts a SanitizedRule to an AttackDiscoverySchedule response
convertScheduleActionsToAlertingActionsFunctionSplits schedule actions into general and system actions
createScheduleExecutionSummaryFunctionExtracts last execution summary from a rule
generateAttackDiscoveryAlertHashFunctionSHA-256 hash for alert deduplication
transformToBaseAlertDocumentFunctionConverts an AttackDiscovery to an AttackDiscoveryAlertDocumentBase
AttackDiscoveryAlertDocumentBaseTypeBase alert document shape (before runtime fields)

Update alerts

ExportKindDescription
updateAlertsWithAttackIdsFunctionUpdates security alerts with attack IDs via updateByQuery
UpdateAlertsWithAttackIdsParamsType{ alertIdToAttackIdsMap, esClient, spaceId }

Alert-to-attack ID mapping

ExportKindDescription
buildAlertIdToAttackIdsMapFunctionBuilds a map of alert ID → attack IDs from a set of attacks
AttackWithAlertIdsTypeInput shape ({ alertIds, ... }) consumed by buildAlertIdToAttackIdsMap

Types

ExportKindDescription
AttackDiscoveryAlertDocumentTypeFull alert document (re-exported from @kbn/elastic-assistant-common)
AttackDiscoveryExecutorOptionsTypeRuleExecutorOptions for the attack discovery rule type
AttackDiscoveryScheduleContextTypeAlertInstanceContext with attack field
AttackDiscoveryScheduleFindOptionsType{ page?, perPage?, sort? }
AttackDiscoveryScheduleSortType{ sortDirection?, sortField? }
AttackDiscoveryScheduleTypeTypeRuleType<...> for the attack discovery rule type