Skip to content
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

[Reponse Ops][Alerting] Excluding ECS experimental fields from ECS component template #170571

Merged
merged 15 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 161 additions & 1 deletion packages/kbn-alerts-as-data-utils/src/field_maps/ecs_field_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,169 @@ import { EcsMetadata, FieldMap } from './types';

const EXCLUDED_TYPES = ['constant_keyword'];

// ECS fields that have reached Stage 2 in the RFC process
// are included in the generated Yaml but are still considered
// experimental. Some are correctly marked as beta but most are
// not.

// More about the RFC stages here: https://elastic.github.io/ecs/stages.html

// The following RFCS are currently in stage 2:
// https://github.com/elastic/ecs/blob/main/rfcs/text/0002-rfc-environment.md
// https://github.com/elastic/ecs/blob/main/rfcs/text/0009-data_stream-fields.md
// https://github.com/elastic/ecs/blob/main/rfcs/text/0015-create-file-elf.md
// https://github.com/elastic/ecs/blob/main/rfcs/text/0027-faas-fields.md
// https://github.com/elastic/ecs/blob/main/rfcs/text/0028-cgroups.md
// https://github.com/elastic/ecs/blob/main/rfcs/text/0034-device-fields.md
// https://github.com/elastic/ecs/blob/main/rfcs/text/0035-tty-output.md
// https://github.com/elastic/ecs/blob/main/rfcs/text/0037-host-metrics.md
// https://github.com/elastic/ecs/blob/main/rfcs/text/0040-volume-device.md

// Fields from these RFCs are manually identified as experimental below.
// The next time this list is updated, we should check the above list of RFCs to
// see if any have moved to Stage 3 and remove them from the list and check if
// there are any new stage 2 RFCs with fields we should identify as experimental.

const EXPERIMENTAL_FIELDS = [
'data_stream.type',
'data_stream.dataset',
'data_stream.namespace',
'device.id',
'device.manufacturer',
'device.model.identifier',
'device.model.name',
'faas.coldstart',
'faas.execution',
'faas.id',
'faas.name',
'faas.trigger',
'faas.trigger.request_id',
'faas.trigger.type',
'faas.version',
'file.elf.architecture',
'file.elf.byte_order',
'file.elf.cpu_type',
'file.elf.creation_date',
'file.elf.exports',
'file.elf.segments',
'file.elf.segments.sections',
'file.elf.segments.type',
'file.elf.header.abi_version',
'file.elf.header.class',
'file.elf.header.data',
'file.elf.header.entrypoint',
'file.elf.header.object_version',
'file.elf.header.os_abi',
'file.elf.header.type',
'file.elf.header.version',
'file.elf.imports',
'file.elf.sections',
'file.elf.sections.chi2',
'file.elf.sections.entropy',
'file.elf.sections.flags',
'file.elf.sections.name',
'file.elf.sections.physical_offset',
'file.elf.sections.physical_size',
'file.elf.sections.type',
'file.elf.sections.virtual_address',
'file.elf.sections.virtual_size',
'file.elf.shared_libraries',
'file.elf.telfhash',
'host.network.egress.bytes',
'host.network.ingress.bytes',
'process.io',
'process.io.bytes_skipped',
'process.io.bytes_skipped.length',
'process.io.bytes_skipped.offset',
'process.io.max_bytes_per_process_exceeded',
'process.io.text',
'process.io.total_bytes_captured',
'process.io.total_bytes_skipped',
'process.io.type',
'process.tty.columns',
'process.tty.rows',
'service.environment',
'threat.enrichments.indicator.file.elf.architecture',
'threat.enrichments.indicator.file.elf.byte_order',
'threat.enrichments.indicator.file.elf.cpu_type',
'threat.enrichments.indicator.file.elf.creation_date',
'threat.enrichments.indicator.file.elf.exports',
'threat.enrichments.indicator.file.elf.segments',
'threat.enrichments.indicator.file.elf.segments.sections',
'threat.enrichments.indicator.file.elf.segments.type',
'threat.enrichments.indicator.file.elf.header.abi_version',
'threat.enrichments.indicator.file.elf.header.class',
'threat.enrichments.indicator.file.elf.header.data',
'threat.enrichments.indicator.file.elf.header.entrypoint',
'threat.enrichments.indicator.file.elf.header.object_version',
'threat.enrichments.indicator.file.elf.header.os_abi',
'threat.enrichments.indicator.file.elf.header.type',
'threat.enrichments.indicator.file.elf.header.version',
'threat.enrichments.indicator.file.elf.imports',
'threat.enrichments.indicator.file.elf.sections',
'threat.enrichments.indicator.file.elf.sections.chi2',
'threat.enrichments.indicator.file.elf.sections.entropy',
'threat.enrichments.indicator.file.elf.sections.flags',
'threat.enrichments.indicator.file.elf.sections.name',
'threat.enrichments.indicator.file.elf.sections.physical_offset',
'threat.enrichments.indicator.file.elf.sections.physical_size',
'threat.enrichments.indicator.file.elf.sections.type',
'threat.enrichments.indicator.file.elf.sections.virtual_address',
'threat.enrichments.indicator.file.elf.sections.virtual_size',
'threat.enrichments.indicator.file.elf.shared_libraries',
'threat.enrichments.indicator.file.elf.telfhash',
'threat.indicator.file.elf.architecture',
'threat.indicator.file.elf.byte_order',
'threat.indicator.file.elf.cpu_type',
'threat.indicator.file.elf.creation_date',
'threat.indicator.file.elf.exports',
'threat.indicator.file.elf.segments',
'threat.indicator.file.elf.segments.sections',
'threat.indicator.file.elf.segments.type',
'threat.indicator.file.elf.header.abi_version',
'threat.indicator.file.elf.header.class',
'threat.indicator.file.elf.header.data',
'threat.indicator.file.elf.header.entrypoint',
'threat.indicator.file.elf.header.object_version',
'threat.indicator.file.elf.header.os_abi',
'threat.indicator.file.elf.header.type',
'threat.indicator.file.elf.header.version',
'threat.indicator.file.elf.imports',
'threat.indicator.file.elf.sections',
'threat.indicator.file.elf.sections.chi2',
'threat.indicator.file.elf.sections.entropy',
'threat.indicator.file.elf.sections.flags',
'threat.indicator.file.elf.sections.name',
'threat.indicator.file.elf.sections.physical_offset',
'threat.indicator.file.elf.sections.physical_size',
'threat.indicator.file.elf.sections.type',
'threat.indicator.file.elf.sections.virtual_address',
'threat.indicator.file.elf.sections.virtual_size',
'threat.indicator.file.elf.shared_libraries',
'threat.indicator.file.elf.telfhash',
'volume.bus_type',
'volume.default_access',
'volume.device_name',
'volume.device_type',
'volume.dos_name',
'volume.file_system_type',
'volume.mount_name',
'volume.nt_name',
'volume.product_id',
'volume.product_name',
'volume.removable',
'volume.serial_number',
'volume.size',
'volume.vendor_id',
'volume.vendor_name',
'volume.writable',
];

export const ecsFieldMap: FieldMap = Object.fromEntries(
Object.entries(EcsFlat)
.filter(([_, value]) => !EXCLUDED_TYPES.includes(value.type))
.filter(
([key, value]) => !EXCLUDED_TYPES.includes(value.type) && !EXPERIMENTAL_FIELDS.includes(key)
)
.map(([key, _]) => {
const value: EcsMetadata = EcsFlat[key as keyof typeof EcsFlat];
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ const EcsOptional = rt.partial({
'destination.user.id': schemaString,
'destination.user.name': schemaString,
'destination.user.roles': schemaStringArray,
'device.id': schemaString,
'device.manufacturer': schemaString,
'device.model.identifier': schemaString,
'device.model.name': schemaString,
'dll.code_signature.digest_algorithm': schemaString,
'dll.code_signature.exists': schemaBoolean,
'dll.code_signature.signing_id': schemaString,
Expand Down Expand Up @@ -304,12 +300,6 @@ const EcsOptional = rt.partial({
'event.timezone': schemaString,
'event.type': schemaStringArray,
'event.url': schemaString,
'faas.coldstart': schemaBoolean,
'faas.execution': schemaString,
'faas.id': schemaString,
'faas.name': schemaString,
'faas.trigger': schemaUnknown,
'faas.version': schemaString,
'file.accessed': schemaDate,
'file.attributes': schemaStringArray,
'file.code_signature.digest_algorithm': schemaString,
Expand All @@ -326,41 +316,6 @@ const EcsOptional = rt.partial({
'file.device': schemaString,
'file.directory': schemaString,
'file.drive_letter': schemaString,
'file.elf.architecture': schemaString,
'file.elf.byte_order': schemaString,
'file.elf.cpu_type': schemaString,
'file.elf.creation_date': schemaDate,
'file.elf.exports': schemaUnknownArray,
'file.elf.header.abi_version': schemaString,
'file.elf.header.class': schemaString,
'file.elf.header.data': schemaString,
'file.elf.header.entrypoint': schemaStringOrNumber,
'file.elf.header.object_version': schemaString,
'file.elf.header.os_abi': schemaString,
'file.elf.header.type': schemaString,
'file.elf.header.version': schemaString,
'file.elf.imports': schemaUnknownArray,
'file.elf.sections': rt.array(
rt.partial({
chi2: schemaStringOrNumber,
entropy: schemaStringOrNumber,
flags: schemaString,
name: schemaString,
physical_offset: schemaString,
physical_size: schemaStringOrNumber,
type: schemaString,
virtual_address: schemaStringOrNumber,
virtual_size: schemaStringOrNumber,
})
),
'file.elf.segments': rt.array(
rt.partial({
sections: schemaString,
type: schemaString,
})
),
'file.elf.shared_libraries': schemaStringArray,
'file.elf.telfhash': schemaString,
'file.extension': schemaString,
'file.fork_name': schemaString,
'file.gid': schemaString,
Expand Down Expand Up @@ -440,9 +395,7 @@ const EcsOptional = rt.partial({
'host.ip': schemaStringArray,
'host.mac': schemaStringArray,
'host.name': schemaString,
'host.network.egress.bytes': schemaStringOrNumber,
'host.network.egress.packets': schemaStringOrNumber,
'host.network.ingress.bytes': schemaStringOrNumber,
'host.network.ingress.packets': schemaStringOrNumber,
'host.os.family': schemaString,
'host.os.full': schemaString,
Expand Down Expand Up @@ -676,7 +629,6 @@ const EcsOptional = rt.partial({
'process.hash.ssdeep': schemaString,
'process.hash.tlsh': schemaString,
'process.interactive': schemaBoolean,
'process.io': schemaUnknown,
'process.name': schemaString,
'process.parent.args': schemaStringArray,
'process.parent.args_count': schemaStringOrNumber,
Expand Down Expand Up @@ -893,7 +845,6 @@ const EcsOptional = rt.partial({
'server.user.name': schemaString,
'server.user.roles': schemaStringArray,
'service.address': schemaString,
'service.environment': schemaString,
'service.ephemeral_id': schemaString,
'service.id': schemaString,
'service.name': schemaString,
Expand Down Expand Up @@ -1003,41 +954,6 @@ const EcsOptional = rt.partial({
'threat.indicator.file.device': schemaString,
'threat.indicator.file.directory': schemaString,
'threat.indicator.file.drive_letter': schemaString,
'threat.indicator.file.elf.architecture': schemaString,
'threat.indicator.file.elf.byte_order': schemaString,
'threat.indicator.file.elf.cpu_type': schemaString,
'threat.indicator.file.elf.creation_date': schemaDate,
'threat.indicator.file.elf.exports': schemaUnknownArray,
'threat.indicator.file.elf.header.abi_version': schemaString,
'threat.indicator.file.elf.header.class': schemaString,
'threat.indicator.file.elf.header.data': schemaString,
'threat.indicator.file.elf.header.entrypoint': schemaStringOrNumber,
'threat.indicator.file.elf.header.object_version': schemaString,
'threat.indicator.file.elf.header.os_abi': schemaString,
'threat.indicator.file.elf.header.type': schemaString,
'threat.indicator.file.elf.header.version': schemaString,
'threat.indicator.file.elf.imports': schemaUnknownArray,
'threat.indicator.file.elf.sections': rt.array(
rt.partial({
chi2: schemaStringOrNumber,
entropy: schemaStringOrNumber,
flags: schemaString,
name: schemaString,
physical_offset: schemaString,
physical_size: schemaStringOrNumber,
type: schemaString,
virtual_address: schemaStringOrNumber,
virtual_size: schemaStringOrNumber,
})
),
'threat.indicator.file.elf.segments': rt.array(
rt.partial({
sections: schemaString,
type: schemaString,
})
),
'threat.indicator.file.elf.shared_libraries': schemaStringArray,
'threat.indicator.file.elf.telfhash': schemaString,
'threat.indicator.file.extension': schemaString,
'threat.indicator.file.fork_name': schemaString,
'threat.indicator.file.gid': schemaString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,6 @@ describe('stripNonEcsFields', () => {
]);
});

// https://github.com/elastic/sdh-security-team/issues/736
describe('fields that exists in the alerts mapping but not in local ECS(ruleRegistry) definition', () => {
ymao1 marked this conversation as resolved.
Show resolved Hide resolved
it('should strip object type "device" field if it is supplied as a keyword', () => {
const { result, removed } = stripNonEcsFields({
device: 'test',
message: 'test message',
});

expect(result).toEqual({
message: 'test message',
});

expect(removed).toEqual([
{
key: 'device',
value: 'test',
},
]);
});
});

describe('array fields', () => {
it('should not strip arrays of objects when an object is expected', () => {
const { result, removed } = stripNonEcsFields({
Expand Down