Skip to content

Database

One PostgreSQL 16 instance (postgres_db) with the pgvector and pg_cron extensions. Database cyber_intelligence, three schemas:

Schema Holds Written by
cyber_sentinel DNS traffic, CTI results and verdicts — the data dns_log_processor, n8n
cyber_sentinel_ai Everything that drives the AI pipeline — settings, prompts, allow-lists, audit, vector memory AI Config UI, n8n, Tranco sync
cyber_sentinel_sandbox What the browser sandbox saw — requests, DNS, observables, CTI checks (Data & CTI) sandbox_log_processor, n8n Sandbox Scan

The SQL lives in config/postgres/ and is applied in this order. Every file is idempotent and re-runs on each deployment.

# File Playbook Creates
1 db_deployment.sql 04.3 cyber_sentinel schema, app role, tables, views
2 db_partitioning_retention.sql 04.3 partitions, retention functions, pg_cron jobs
3 db_ai_pipeline.sql 04.3 cyber_sentinel_ai schema, scoring, allow-list, work queue, API call log and VirusTotal budget, Deep Recon, Failure Guard
4 db_blocklists.sql 04.3 own blocklists: entries, AI classifications, name patterns, classifier prompt, publish log
5 db_sandbox.sql 04.3 cyber_sentinel_sandbox schema, ingest role, check queue, session views
6 db_ai_config_editor.sql 04.5 AI Config UI role, audit log, guard triggers

Schema cyber_sentinel

erDiagram
    dns_queries ||--o{ threat_indicators : "analysed as"
    ai_analysis_results ||--o{ threat_indicators : "verdict"
    dic_threat_levels ||--o{ ai_analysis_results : "score"
    dic_indicator_types ||--o{ threat_indicators : "type"
    threat_indicators ||--o{ threat_indicator_details : "per provider"
    dic_source_providers ||--o{ threat_indicator_details : "source"
    threat_data_raw ||--o{ threat_indicator_details : "raw payload"
    dns_queries ||--o{ network_events : "related"
    threat_indicators ||--o{ network_events : "related"

Links to and from dns_queries, threat_indicators and network_events are kept by the application: a partitioned table can only be a foreign-key target through its full partition key.

Tables

Object What it does
dns_queries Every DNS query and answer from Pi-hole's log, with the client IP. query_type: query, reply (forwarded to Unbound), cached (Pi-hole cache), blocked (gravity / denylist). Partitioned by month.
threat_indicators Links a DNS query to its verdict; counts re-scans. Partitioned by month.
ai_analysis_results Final verdict: score 1–5, label, summary in English and Polish.
threat_indicator_details Which CTI provider contributed to a verdict, with a pointer to its raw response.
threat_data_raw Raw JSON responses from VirusTotal, ThreatFox, URLhaus, urlscan.io, Shodan InternetDB and RDAP (JSONB).
network_events Reserved for IDS / packet-capture events. Partitioned by month.
partition_maintenance_log Every partition added or dropped, including failures.

Dictionaries

Object What it does
dic_threat_levels The 1–5 scale: wording, recommended action and whether the level counts as malicious. Editable in the AI Config UI.
dic_indicator_types Observable types: FQDN, IP, HASH.
dic_source_providers CTI providers.

Views

Object Used by
v_threat_scale_for_agent The threat scale as text, injected into the AI agent prompt.
v_latest_threat_reports Latest verdict per DNS query.
v_pending_analysis Previous work queue, still read by the DNS Traffic dashboard.
v_partition_info Rows and size per partition.

Schema cyber_sentinel_ai

erDiagram
    ai_analysis_results ||--|| verdict_audit : "1:1"
    ai_analysis_results ||--o{ verdict_vectors : "embedding"
    ai_analysis_results ||--o{ pihole_block_log : "block attempt"
    ai_analysis_results ||--o{ deep_recon : "second look"
    prompt_templates ||--o{ verdict_audit : "prompt_version"
    recon_prompt_templates ||--o{ deep_recon : "prompt_version"
    blocklist_prompt_templates ||--o{ blocklist_classifications : "prompt_version"
    blocklist_classifications ||--o| blocklist_entries : "fqdn (candidate)"
    pihole_block_log ||--o{ blocklist_entries : "fqdn (malicious)"
    domain_allowlist_staging ||--o{ domain_allowlist : "weekly sync"

ai_analysis_results belongs to cyber_sentinel. The AI schema extends each verdict without changing the CTI tables.

Pipeline configuration — edited in the AI Config UI

Object What it does
ai_settings Every threshold and switch the workflows read: VirusTotal budget and gate, scoring limits, AI deviation, cache, email and Pi-hole thresholds, urlscan.io search, Shodan, Deep Recon (recon_*).
prompt_templates Versioned system prompt for the AI agent. Exactly one version is active.
recon_prompt_templates Versioned system prompt for the Deep Recon analyst. Exactly one version is active.
trusted_infrastructure Big providers (by AS owner or domain) whose low-detection noise is ignored and whose score is capped.
domain_allowlist Domains never sent for analysis: Tranco top list (weekly) plus manual entries.
domain_allowlist_exclusions Platforms where anyone can publish under a subdomain (github.io, ngrok.io, …). They override Tranco entries.
v_manual_allowlist The only way to edit the allow-list from the UI — manual rows only.
blocklist_name_patterns Name fragments (telemetry, track, …) that make a domain a candidate for AI classification.
blocklist_prompt_templates Versioned system prompt for the blocklist classifier. Exactly one version is active.
blocklist_entries Own blocklists: one row per domain and list (malicious, tracking, telemetry) with status candidate / approved / rejected, source, expiry and who reviewed it. AI and the malicious sync add rows; the UI approves, rejects and adds manual ones.

Pipeline data — written by n8n

Object What it does
v_pending_observables Work queue: new domain + IP pairs, without private IPs, allow-listed domains and pairs analysed in the last cache_ttl_days.
api_call_log One row per outgoing CTI / AI request: provider, caller, endpoint, HTTP status, outcome. Partitioned by month, kept 3 months. VirusTotal claims of the main workflow also stop overlapping runs from taking the same pair.
vt_lookup_log View on api_call_log (VirusTotal calls of the main workflow); a table until v2.2.
api_provider_quota Providers' own usage counters, written hourly by API Usage Monitor (kept 14 days).
v_vt_budget VirusTotal calls used today (the higher of the local count and VirusTotal's counter), in the last minute, calls left, reserve, next reset.
v_api_usage_today / v_api_usage_daily Usage per provider today with limit and share; calls per day, provider and caller.
api_alert_log Providers e-mailed for crossing api_alert_threshold_pct, one row per UTC day.
ops_settings Text settings Failure Guard needs while Vault may be down (e-mail sender and recipient). Written by playbook 04.3.
workflow_failure_alerts Workflows Failure Guard stopped: failures, first failure, failed node, error.
verdict_audit Per verdict: rule score, final score, what the agent changed and why, model, prompt version, evidence. Also the "already analysed" cache.
verdict_vectors Vector memory of past verdicts (3072-dim Gemini embeddings) searched by the agent's historical_verdicts tool.
pihole_block_log Every automatic Pi-hole block attempt and its result.
v_pending_recon Deep Recon queue: verdicts with score ≥ recon_min_score from the last recon_lookback_days, without a recent recon of the same domain. Empty while recon_enabled = 0.
deep_recon One row per re-assessed verdict: domain age and registrar (RDAP), certificate history (crt.sh), page scan (urlscan.io links and facts), and the analyst's result — page type, brand, credential harvesting, confirms / contradicts, proposed score and reason (score_changed when it differs from the verdict).
v_blocklist_ai_queue Domains waiting for blocklist classification: pattern match, enough queries, not classified, not on a list, not manually allow-listed.
blocklist_classifications One AI answer per domain: category, vendor, confidence, breakage risk, reason. A domain here is not sent to the AI again.
v_blocklist_published Approved, not expired, not manually allow-listed entries — exactly what goes into the files.
blocklist_publish_log One row per publish run: dry run, no change, published (with pull request) or error.

Logs

Object What it does
config_change_log Who changed which setting, prompt or list, with old and new values. Append-only.
domain_allowlist_sync_log Result of each Tranco sync.

Functions

Object What it does
compute_threat_score() Deterministic 1–5 score from VirusTotal, ThreatFox and URLhaus results, with a step-by-step trace.
is_allowlisted() Allow-list check; the most specific rule wins.
setting() Reads one value from ai_settings; fails on a missing key.
sp_sync_domain_allowlist() Applies the weekly Tranco list as a delta; aborts if the list is suspiciously short.
claim_next_observable() Returns the next pending observable and logs the claim, or nothing when the queue is empty or the VirusTotal budget is used up.
api_call_result() Fills in the HTTP status of the main workflow's VirusTotal claim.
api_calls_record() Logs a batch of calls (the Log API calls nodes).
api_claim() / api_call_finish() VirusTotal claim and result for the simulator; the only way the UI writes the log.
api_quota_record() / api_usage_alerts_due() Stores a provider counter; returns the providers to e-mail today and marks them.
recon_requeue() Removes one deep_recon row so its verdict gets a new second look; the only way the UI deletes from that table.
blocklist_record_classifications() Stores one AI batch and turns telemetry / tracking answers into review candidates.
blocklist_sync_malicious() Copies Pi-hole auto-blocks into the malicious list and extends their expiry.
blocklist_render() Full content of the three list files.
blocklist_is_protected() TRUE when a manual allow-list entry covers the domain.

Roles

Role Access
postgres Superuser; runs the deployment scripts and pg_cron jobs.
app role (postgres_user) n8n and dns_log_processor: read/write in cyber_sentinel and cyber_sentinel_ai, read-only on the audit log; in cyber_sentinel_sandbox read, plus the check results (claim_checks(), record_checks()).
sandbox_ingest (sandbox_db_user) sandbox_log_processor only: EXECUTE on the ingest functions of cyber_sentinel_sandbox, no table privileges.
ai_config_editor AI Config UI only: the configuration objects above, nothing from the data tables (read-only on cyber_sentinel_sandbox for the Sandbox page). Reads deep_recon, the recon queue, the VirusTotal budget, the API call log and Failure Guard alerts; logs simulator calls through api_claim() / api_call_finish() only. Guard triggers stop it from breaking the pipeline (active prompts are read-only, one prompt of each kind always active, malicious levels stay a contiguous top range).

Passwords come from vault.yml and are copied to HashiCorp Vault.

Partitioning and Retention

dns_queries, threat_indicators, network_events, cyber_sentinel_ai.api_call_log and the sandbox's url_events and dns_queries are partitioned by month (<table>_pYYYYMM) with a default partition catching anything outside the range. The list lives in cyber_sentinel.partitioned_tables(). Two pg_cron jobs run on the 1st of each month:

Job Time Action
evt_drop_old_partitions 02:00 Drops partitions older than 3 months (same for all tables, so links between them stay complete)
evt_add_future_partitions 03:00 Creates partitions for the next 3 months
SELECT * FROM cyber_sentinel.v_partition_info;
SELECT * FROM cyber_sentinel.partition_maintenance_log ORDER BY executed_at DESC LIMIT 20;
SELECT * FROM cron.job_run_details ORDER BY start_time DESC LIMIT 20;