Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

feat(connectors): table-aware field aliases for Sentinel KQL translation (#376)

Bobby Okafor1897cd1fbfda
diff --git a/services/connectors/app/federated/translators/kql.py b/services/connectors/app/federated/translators/kql.py
index 5c0c1d549..8f20e9cee 100644
--- a/services/connectors/app/federated/translators/kql.py
+++ b/services/connectors/app/federated/translators/kql.py
@@ -17,10 +17,21 @@ Shape:
from __future__ import annotations
-from typing import Any
+from typing import Any, Final
from app.federated.query import Indicator, QueryError, UnifiedQuery
+_SENTINEL_TABLE_FIELD_ALIASES: Final[dict[str, dict[str, str]]] = {
+ "SecurityIncident": {
+ "device.name": "CompromisedEntity",
+ "severity": "Severity",
+ "message": "AlertName",
+ },
+ "SigninLogs": {
+ "user.name": "UserPrincipalName",
+ },
+}
+
def _kql_quote(value: Any) -> str:
if isinstance(value, bool):
@@ -32,8 +43,27 @@ def _kql_quote(value: Any) -> str:
return f'"{escaped}"'
-def _indicator_to_kql(indicator: Indicator) -> str:
- field_token = indicator.field
+def _resolve_kql_field(field: str, table: str) -> str:
+ aliases = _SENTINEL_TABLE_FIELD_ALIASES.get(table)
+
+ if aliases is None:
+ return field
+
+ return aliases.get(field, field)
+
+
+def _indicator_to_kql(
+ indicator: Indicator,
+ *,
+ table: str,
+) -> str:
+ """Render a single ``Indicator`` as a KQL where-clause."""
+
+ field_token = _resolve_kql_field(
+ indicator.field,
+ table,
+ )
+
op = indicator.operator
value = indicator.value
@@ -71,7 +101,8 @@ def to_kql(query: UnifiedQuery, *, table: str = "CommonSecurityLog") -> str:
# KQL's "search" verb does free-text across all string columns;
# we use it as a where-clause so the pipeline shape stays uniform.
lines.append(f"| where * contains {_kql_quote(query.free_text)}")
+
for indicator in query.indicators:
- lines.append(f"| where {_indicator_to_kql(indicator)}")
+ lines.append(f"| where {_indicator_to_kql(indicator, table=table)}")
lines.append(f"| take {query.limit}")
return "\n".join(lines)
diff --git a/services/connectors/tests/test_kql_aliases.py b/services/connectors/tests/test_kql_aliases.py
new file mode 100644
index 000000000..2db6a70e8
--- /dev/null
+++ b/services/connectors/tests/test_kql_aliases.py
@@ -0,0 +1,83 @@
+from app.federated.query import Indicator, UnifiedQuery
+from app.federated.translators import to_kql
+
+
+def test_kql_translator_aliases_user_name_for_signinlogs():
+ q = UnifiedQuery(
+ indicators=(
+ Indicator(
+ field="user.name",
+ operator="eq",
+ ),
+ ),
+ )
+
+ kql = to_kql(q, table="SigninLogs")
+
+ assert "UserPrincipalName" in kql
+ assert "user.name" not in kql
+
+
+def test_kql_translator_aliases_securityincident_fields():
+ q = UnifiedQuery(
+ indicators=(
+ Indicator(
+ field="device.name",
+ operator="eq",
+ value="host01",
+ ),
+ Indicator(
+ field="severity",
+ operator="eq",
+ value="High",
+ ),
+ Indicator(
+ field="message",
+ operator="contains",
+ value="mimikatz",
+ ),
+ ),
+ )
+
+ kql = to_kql(q, table="SecurityIncident")
+
+ assert "CompromisedEntity" in kql
+ assert "Severity" in kql
+ assert "AlertName" in kql
+
+ assert "device.name" not in kql
+ assert "severity" not in kql
+ assert "message" not in kql
+
+
+def test_kql_translator_unknown_fields_pass_through():
+ q = UnifiedQuery(
+ indicators=(
+ Indicator(
+ field="source.ip",
+ operator="eq",
+ value="10.0.0.5",
+ ),
+ ),
+ )
+
+ kql = to_kql(q, table="SigninLogs")
+
+ assert "source.ip" in kql
+
+
+def test_kql_translator_unknown_tables_pass_through():
+ q = UnifiedQuery(
+ indicators=(
+ Indicator(
+ field="user.name",
+ operator="eq",
+ value="alice",
+ ),
+ ),
+ )
+
+ kql = to_kql(q, table="SomeFutureTable")
+
+ assert "user.name" in kql