Skip to content

Commit 1de20e8

Browse files
authored
Merge branch 'obs_to_rba' into integration_testing_rba_migration
2 parents 51f0780 + da39152 commit 1de20e8

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

contentctl/objects/baseline.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
from __future__ import annotations
3-
from typing import Annotated, List,Any
3+
from typing import Annotated, List,Any, TYPE_CHECKING
4+
if TYPE_CHECKING:
5+
from contentctl.input.director import DirectorOutputDto
6+
47
from pydantic import field_validator, ValidationInfo, Field, model_serializer, computed_field
58
from contentctl.objects.deployment import Deployment
69
from contentctl.objects.security_content_object import SecurityContentObject
@@ -9,7 +12,7 @@
912

1013
from contentctl.objects.config import CustomApp
1114

12-
15+
from contentctl.objects.lookup import Lookup
1316
from contentctl.objects.constants import CONTENTCTL_MAX_SEARCH_NAME_LENGTH,CONTENTCTL_BASELINE_STANZA_NAME_FORMAT_TEMPLATE
1417

1518
class Baseline(SecurityContentObject):
@@ -19,10 +22,24 @@ class Baseline(SecurityContentObject):
1922
how_to_implement: str = Field(..., min_length=4)
2023
known_false_positives: str = Field(..., min_length=4)
2124
tags: BaselineTags = Field(...)
22-
25+
lookups: list[Lookup] = Field([], validate_default=True)
2326
# enrichment
2427
deployment: Deployment = Field({})
25-
28+
29+
30+
@field_validator('lookups', mode="before")
31+
@classmethod
32+
def getBaselineLookups(cls, v:list[str], info:ValidationInfo) -> list[Lookup]:
33+
'''
34+
This function has been copied and renamed from the Detection_Abstract class
35+
'''
36+
director:DirectorOutputDto = info.context.get("output_dto",None)
37+
search: str | None = info.data.get("search",None)
38+
if search is None:
39+
raise ValueError("Search was None - is this file missing the search field?")
40+
41+
lookups = Lookup.get_lookups(search, director)
42+
return lookups
2643

2744
def get_conf_stanza_name(self, app:CustomApp)->str:
2845
stanza_name = CONTENTCTL_BASELINE_STANZA_NAME_FORMAT_TEMPLATE.format(app_label=app.label, detection_name=self.name)

contentctl/objects/lookup.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
LOOKUPS_TO_IGNORE.add("ut_shannon_lookup") #In the URL toolbox app which is recommended for ESCU
1919
LOOKUPS_TO_IGNORE.add("identity_lookup_expanded") #Shipped with the Asset and Identity Framework
2020
LOOKUPS_TO_IGNORE.add("cim_corporate_web_domain_lookup") #Shipped with the Asset and Identity Framework
21+
LOOKUPS_TO_IGNORE.add("cim_corporate_email_domain_lookup") #Shipped with the Enterprise Security
22+
LOOKUPS_TO_IGNORE.add("cim_cloud_domain_lookup") #Shipped with the Enterprise Security
23+
2124
LOOKUPS_TO_IGNORE.add("alexa_lookup_by_str") #Shipped with the Asset and Identity Framework
2225
LOOKUPS_TO_IGNORE.add("interesting_ports_lookup") #Shipped with the Asset and Identity Framework
2326
LOOKUPS_TO_IGNORE.add("asset_lookup_by_str") #Shipped with the Asset and Identity Framework
@@ -89,18 +92,18 @@ def match_type_to_conf_format(self)->str:
8992
@staticmethod
9093
def get_lookups(text_field: str, director:DirectorOutputDto, ignore_lookups:set[str]=LOOKUPS_TO_IGNORE)->list[Lookup]:
9194
# Comprehensively match all kinds of lookups, including inputlookup and outputlookup
92-
inputLookupsToGet = set(re.findall(r'inputlookup(?:\s*(?:(?:append|strict|start|max)\s*=\s*(?:true|t|false|f))){0,4}\s+([^\s\|]+)', text_field))
93-
outputLookupsToGet = set(re.findall(r'outputlookup(?:\s*(?:(?:append|create_empty|override_if_empty|max|key_field|allow_updates|createinapp|create_context|output_format)\s*=\s*[^\s]*))*\s+([^\s\|]+)',text_field))
94-
lookupsToGet = set(re.findall(r'(?:(?<!output)(?<!input))lookup(?:\s*(?:(?:local|update)\s*=\s*(?:true|t|false|f))){0,2}\s+([^\s\|]+)', text_field))
95+
inputLookupsToGet = set(re.findall(r'[^\w]inputlookup(?:\s*(?:(?:append|strict|start|max)\s*=\s*(?:true|t|false|f))){0,4}\s+([^\s\|]+)', text_field, re.IGNORECASE))
96+
outputLookupsToGet = set(re.findall(r'[^\w]outputlookup(?:\s*(?:(?:append|create_empty|override_if_empty|max|key_field|allow_updates|createinapp|create_context|output_format)\s*=\s*[^\s]*))*\s+([^\s\|]+)',text_field,re.IGNORECASE))
97+
lookupsToGet = set(re.findall(r'[^\w](?:(?<!output)(?<!input))lookup(?:\s*(?:(?:local|update)\s*=\s*(?:true|t|false|f))){0,2}\s+([^\s\|]+)', text_field, re.IGNORECASE))
9598

9699

97100
input_lookups = Lookup.mapNamesToSecurityContentObjects(list(inputLookupsToGet-LOOKUPS_TO_IGNORE), director)
98101
output_lookups = Lookup.mapNamesToSecurityContentObjects(list(outputLookupsToGet-LOOKUPS_TO_IGNORE), director)
99102
lookups = Lookup.mapNamesToSecurityContentObjects(list(lookupsToGet-LOOKUPS_TO_IGNORE), director)
100103

104+
all_lookups = set(input_lookups + output_lookups + lookups)
101105

102-
103-
return lookups + input_lookups + output_lookups
106+
return list(all_lookups)
104107

105108

106109

0 commit comments

Comments
 (0)