Skip to content

Commit 86c0896

Browse files
Copilotmakr-code
andcommitted
Add SIEM integration foundation - audit logger enhancements and config
Co-authored-by: makr-code <150588092+makr-code@users.noreply.github.com>
1 parent a1a7fc2 commit 86c0896

3 files changed

Lines changed: 694 additions & 16 deletions

File tree

‎config/audit.yaml‎

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
# ThemisDB Audit Logging & SIEM Integration Configuration
2+
# Version: 1.5.0
3+
# Last Updated: 2026-02-10
4+
#
5+
# This configuration file controls audit logging and SIEM (Security Information
6+
# and Event Management) integration for ThemisDB, with specific support for
7+
# TaskScheduler trigger and cron events.
8+
#
9+
# SECURITY NOTE: Only authorized administrators should modify this file.
10+
# Changes to SIEM configuration require proper authorization and audit trail.
11+
# Complies with GDPR Article 32 and ISO 27001 requirements.
12+
13+
# ============================================================================
14+
# Core Audit Logging Settings
15+
# ============================================================================
16+
17+
audit_logging:
18+
# Enable/disable audit logging globally
19+
enabled: true
20+
21+
# Encrypt-then-sign: Encrypt audit entries and sign for tamper-proofing
22+
encrypt_then_sign: true
23+
24+
# Log file path (JSON Lines format)
25+
log_path: "data/logs/audit.jsonl"
26+
27+
# Encryption key ID for audit log encryption
28+
key_id: "saga_log"
29+
30+
# Hash chain for tamper-proofing (detect modifications)
31+
enable_hash_chain: true
32+
chain_state_file: "data/logs/audit_chain.json"
33+
34+
# ============================================================================
35+
# SIEM Integration Settings
36+
# ============================================================================
37+
38+
siem_integration:
39+
# Enable SIEM forwarding
40+
enable_siem: false
41+
42+
# SIEM type: "syslog", "splunk", or "elastic"
43+
# - syslog: Compatible with syslog-ng, rsyslog, and standard syslog daemons
44+
# - splunk: Splunk HTTP Event Collector (HEC)
45+
# - elastic: Elasticsearch direct indexing
46+
siem_type: "syslog"
47+
48+
# SIEM message format: "json", "cef", or "syslog"
49+
# - json: Native JSON format (best for Splunk, Elastic)
50+
# - cef: Common Event Format (industry standard, works with most SIEMs)
51+
# - syslog: RFC 5424 syslog format (best for traditional syslog systems)
52+
siem_format: "json"
53+
54+
# SIEM server connection settings
55+
siem_host: "localhost"
56+
siem_port: 514 # Default ports: syslog=514, Splunk HEC=8088, Elastic=9200
57+
58+
# Splunk-specific settings (only used when siem_type="splunk")
59+
splunk:
60+
# HTTP Event Collector (HEC) token
61+
hec_token: ""
62+
# HEC endpoint URL (e.g., "https://splunk.example.com:8088/services/collector/event")
63+
hec_url: ""
64+
# Verify SSL certificate
65+
verify_ssl: true
66+
67+
# Elasticsearch-specific settings (only used when siem_type="elastic")
68+
elasticsearch:
69+
# Index name for audit logs
70+
index: "themisdb-audit"
71+
# Index rotation pattern: "daily", "weekly", "monthly"
72+
index_rotation: "daily"
73+
# Authentication
74+
username: ""
75+
password: ""
76+
# API key (alternative to username/password)
77+
api_key: ""
78+
79+
# ============================================================================
80+
# Task Scheduler Audit Settings
81+
# ============================================================================
82+
83+
task_scheduler_audit:
84+
# Enable audit logging for task scheduler events
85+
enabled: true
86+
87+
# Log all task registrations
88+
log_task_registration: true
89+
90+
# Log all task executions (both success and failure)
91+
log_task_execution: true
92+
93+
# Log cron trigger activations
94+
log_cron_triggers: true
95+
96+
# Log CDC event trigger activations
97+
log_cdc_triggers: true
98+
99+
# Log manual task executions
100+
log_manual_executions: true
101+
102+
# Include resource consumption metrics in audit logs
103+
# (execution time, memory usage, CPU usage)
104+
include_resource_metrics: true
105+
106+
# Fields included in task scheduler audit events:
107+
# - timestamp: ISO 8601 timestamp
108+
# - event_type: Type of event (TASK_REGISTERED, TASK_EXECUTED_SUCCESS, etc.)
109+
# - task_id: Unique task identifier
110+
# - task_name: Human-readable task name
111+
# - user_id: User or service account that triggered the event
112+
# - source_ip: Source IP address (if available)
113+
# - trigger_type: CRON, CDC_EVENT, MANUAL, etc.
114+
# - cron_expression: Cron expression (for cron triggers)
115+
# - execution_time_ms: Task execution time in milliseconds
116+
# - success: Boolean indicating success or failure
117+
# - error_message: Error message (on failure)
118+
# - resource_usage: Resource consumption metrics
119+
# - anomaly_score: Anomaly detection score (0.0 = normal, >2.0 = anomalous)
120+
121+
# ============================================================================
122+
# Anomaly Detection Settings
123+
# ============================================================================
124+
125+
anomaly_detection:
126+
# Enable anomaly detection for task scheduler events
127+
enabled: true
128+
129+
# Anomaly detection threshold (standard deviations from baseline)
130+
# Values > threshold are considered anomalous
131+
# Recommended: 2.0 (95% confidence) or 3.0 (99.7% confidence)
132+
threshold: 2.0
133+
134+
# Minimum number of executions before anomaly detection is active
135+
# Need baseline data before detecting anomalies
136+
min_baseline_samples: 10
137+
138+
# Anomaly detection dimensions
139+
dimensions:
140+
# Detect tasks running longer than expected
141+
execution_time: true
142+
143+
# Detect tasks running more/less frequently than expected
144+
execution_frequency: true
145+
146+
# Detect tasks running at unusual times
147+
execution_timing: true
148+
149+
# Detect tasks consuming excessive resources
150+
resource_usage: true
151+
152+
# Actions on anomaly detection
153+
actions:
154+
# Log anomaly event (SecurityEventType::TASK_ANOMALY_DETECTED)
155+
log_event: true
156+
157+
# Disable task automatically if anomaly detected
158+
auto_disable_task: false
159+
160+
# Send high-priority SIEM alert
161+
send_siem_alert: true
162+
163+
# ============================================================================
164+
# Compliance Settings
165+
# ============================================================================
166+
167+
compliance:
168+
# GDPR compliance settings
169+
gdpr:
170+
# Enable GDPR compliance mode
171+
enabled: true
172+
173+
# Pseudonymize user identifiers in audit logs
174+
pseudonymize_users: false
175+
176+
# Data retention period (days) - GDPR Article 5(1)(e)
177+
retention_days: 365
178+
179+
# Automatically archive logs older than retention period
180+
auto_archive: true
181+
archive_path: "data/logs/archive/audit-{year}-{month}.jsonl.gz"
182+
183+
# ISO 27001 compliance settings
184+
iso27001:
185+
# Enable ISO 27001 compliance mode
186+
enabled: true
187+
188+
# Log access controls and authorization decisions
189+
log_access_controls: true
190+
191+
# Require cryptographic protection of audit logs
192+
require_encryption: true
193+
194+
# Require tamper-evident audit logs (hash chain)
195+
require_tamper_evidence: true
196+
197+
# ============================================================================
198+
# Authorization & Access Control
199+
# ============================================================================
200+
201+
authorization:
202+
# Roles allowed to modify SIEM configuration
203+
# Only users with these roles can change audit/SIEM settings
204+
siem_config_roles:
205+
- "system_admin"
206+
- "security_admin"
207+
208+
# Roles allowed to view audit logs
209+
audit_view_roles:
210+
- "system_admin"
211+
- "security_admin"
212+
- "compliance_officer"
213+
- "auditor"
214+
215+
# Roles allowed to export audit logs
216+
audit_export_roles:
217+
- "system_admin"
218+
- "security_admin"
219+
- "compliance_officer"
220+
221+
# Require MFA for sensitive audit operations
222+
require_mfa:
223+
siem_config_changes: true
224+
audit_log_export: true
225+
audit_log_deletion: true
226+
227+
# ============================================================================
228+
# Example SIEM Integration Scenarios
229+
# ============================================================================
230+
231+
# Example 1: Splunk Integration
232+
# ------------------------------
233+
# siem_integration:
234+
# enable_siem: true
235+
# siem_type: "splunk"
236+
# siem_format: "json"
237+
# splunk:
238+
# hec_token: "your-splunk-hec-token"
239+
# hec_url: "https://splunk.example.com:8088/services/collector/event"
240+
# verify_ssl: true
241+
242+
# Example 2: Syslog-ng Integration with CEF Format
243+
# -------------------------------------------------
244+
# siem_integration:
245+
# enable_siem: true
246+
# siem_type: "syslog"
247+
# siem_format: "cef"
248+
# siem_host: "syslog.example.com"
249+
# siem_port: 514
250+
251+
# Example 3: Elasticsearch/ELK Stack Integration
252+
# -----------------------------------------------
253+
# siem_integration:
254+
# enable_siem: true
255+
# siem_type: "elastic"
256+
# siem_format: "json"
257+
# siem_host: "elasticsearch.example.com"
258+
# siem_port: 9200
259+
# elasticsearch:
260+
# index: "themisdb-audit"
261+
# index_rotation: "daily"
262+
# username: "themisdb"
263+
# password: "your-password"
264+
265+
# ============================================================================
266+
# Performance & Operational Settings
267+
# ============================================================================
268+
269+
operational:
270+
# Buffer size for batch audit logging (entries)
271+
buffer_size: 100
272+
273+
# Flush interval (seconds) - write buffered logs to disk
274+
flush_interval: 10
275+
276+
# Maximum log file size (MB) before rotation
277+
max_log_file_size_mb: 100
278+
279+
# Number of rotated log files to keep
280+
max_rotated_files: 10
281+
282+
# Async SIEM forwarding (don't block on SIEM failures)
283+
async_siem_forwarding: true
284+
285+
# Retry failed SIEM forwards
286+
retry_siem_failures: true
287+
max_retry_attempts: 3
288+
retry_delay_seconds: 30

‎include/utils/audit_logger.h‎

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ enum class SecurityEventType {
112112
BACKUP_CREATED,
113113
RESTORE_COMPLETED,
114114

115+
// Task Scheduler Events (SIEM Integration)
116+
TASK_REGISTERED,
117+
TASK_UNREGISTERED,
118+
TASK_ENABLED,
119+
TASK_DISABLED,
120+
TASK_UPDATED,
121+
TASK_EXECUTED_SUCCESS,
122+
TASK_EXECUTED_FAILURE,
123+
TASK_CRON_TRIGGERED,
124+
TASK_CDC_TRIGGERED,
125+
TASK_MANUAL_TRIGGERED,
126+
TASK_TIMEOUT,
127+
TASK_RESOURCE_LIMIT_EXCEEDED,
128+
TASK_ANOMALY_DETECTED,
129+
115130
// Generic
116131
CUSTOM_EVENT
117132
};
@@ -128,10 +143,17 @@ struct AuditLoggerConfig {
128143

129144
// SIEM integration
130145
bool enable_siem = false;
131-
std::string siem_type = "syslog"; // "syslog" or "splunk"
146+
std::string siem_type = "syslog"; // "syslog", "splunk", or "elastic"
147+
std::string siem_format = "json"; // "json", "cef", or "syslog"
132148
std::string siem_host = "localhost";
133-
uint16_t siem_port = 514; // syslog default
149+
uint16_t siem_port = 514; // syslog default (514), Splunk HEC (8088), Elastic (9200)
134150
std::string splunk_token; // Splunk HEC token
151+
std::string elastic_index = "themisdb-audit"; // Elasticsearch index
152+
153+
// Task Scheduler SIEM settings
154+
bool enable_task_scheduler_audit = true;
155+
bool enable_anomaly_detection = true;
156+
double anomaly_threshold = 2.0; // Standard deviations from baseline
135157
};
136158

137159
// Minimal Audit Logger supporting Encrypt-then-Sign batches (single-entry for now)
@@ -213,6 +235,33 @@ class AuditLogger {
213235
* @brief Get the configured log file path
214236
*/
215237
std::string getLogPath() const { return cfg_.log_path; }
238+
239+
/**
240+
* @brief Log a task scheduler event with resource metrics and anomaly detection
241+
* @param event_type Task scheduler event type
242+
* @param task_id Task identifier
243+
* @param user_id User/service account executing the task
244+
* @param details Event details including resource consumption and metrics
245+
*/
246+
void logTaskSchedulerEvent(
247+
SecurityEventType event_type,
248+
const std::string& task_id,
249+
const std::string& user_id,
250+
const nlohmann::json& details = {}
251+
);
252+
253+
/**
254+
* @brief Calculate anomaly score for a task execution
255+
* @param task_id Task identifier
256+
* @param execution_time_ms Execution time in milliseconds
257+
* @param resource_usage Resource consumption metrics
258+
* @return Anomaly score (0.0 = normal, >2.0 = anomalous)
259+
*/
260+
double calculateAnomalyScore(
261+
const std::string& task_id,
262+
double execution_time_ms,
263+
const nlohmann::json& resource_usage
264+
);
216265

217266
private:
218267
std::shared_ptr<themis::FieldEncryption> enc_;
@@ -226,6 +275,17 @@ class AuditLogger {
226275
uint64_t entry_count_ = 0;
227276
std::chrono::system_clock::time_point last_timestamp_;
228277
mutable std::mutex chain_mu_;
278+
279+
// Task scheduler baseline metrics for anomaly detection
280+
struct TaskBaseline {
281+
double avg_execution_time_ms = 0.0;
282+
double stddev_execution_time_ms = 0.0;
283+
size_t execution_count = 0;
284+
std::chrono::system_clock::time_point last_execution;
285+
double avg_frequency_seconds = 0.0; // Average time between executions
286+
};
287+
std::map<std::string, TaskBaseline> task_baselines_;
288+
mutable std::mutex baselines_mu_;
229289

230290
static std::vector<uint8_t> sha256(const std::vector<uint8_t>& data);
231291
void appendJsonLine(const nlohmann::json& j);
@@ -234,6 +294,15 @@ class AuditLogger {
234294
void saveChainState();
235295
std::string computeEntryHash(const nlohmann::json& entry) const;
236296
static std::string securityEventTypeToString(SecurityEventType type);
297+
298+
// SIEM format converters
299+
std::string formatAsJson(const nlohmann::json& event) const;
300+
std::string formatAsCef(const nlohmann::json& event, SecurityEventType event_type) const;
301+
std::string formatAsSyslog(const nlohmann::json& event, SecurityEventType event_type) const;
302+
303+
// Anomaly detection helpers
304+
void updateTaskBaseline(const std::string& task_id, double execution_time_ms);
305+
double calculateZScore(double value, double mean, double stddev) const;
237306
};
238307

239308
} // namespace utils

0 commit comments

Comments
 (0)