- 4-container stack: ClickHouse, platform (Rocky 9), bot-detector, dashboard - Platform builds sentinel on Rocky (CGO+libpcap native), correlator static - mod-reqin-log compiled with apxs on Rocky (matching RPM build target) - ClickHouse init script patches credentials for test env (sed-based) - 8-phase test runner: schema, traffic gen, pipeline, dashboard API, bot-detector, sentinel - All 13 checks pass, 3 non-blocking warnings (empty dicts, log paths) SQL schema fixes discovered during integration: - 02_dictionaries: IPv6CIDR → String (not a valid ClickHouse type) - 03_anubis_tables: dict_anubis_ua missing has_ip/rule_id/category attrs - 03_anubis_tables: dict_anubis_country FLAT() → COMPLEX_KEY_HASHED() (String key) - 09_audit_table: CODEC before DEFAULT → DEFAULT before CODEC Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
143 lines
5.2 KiB
SQL
143 lines
5.2 KiB
SQL
-- =============================================================================
|
||
-- 03_anubis_tables.sql — Anubis crawler rule tables and dictionaries
|
||
-- Items 1–8 from bot_detector/anubis/deploy_schema.sql
|
||
-- =============================================================================
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
-- 1. TABLE SOURCE — User-Agent rules (for REGEXP_TREE dictionary)
|
||
-- -----------------------------------------------------------------------------
|
||
CREATE TABLE IF NOT EXISTS ja4_processing.anubis_ua_rules
|
||
(
|
||
id UInt64,
|
||
parent_id UInt64,
|
||
regexp String,
|
||
keys Array(String),
|
||
values Array(String)
|
||
)
|
||
ENGINE = ReplacingMergeTree()
|
||
ORDER BY id;
|
||
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
-- 2. TABLE SOURCE — IP/CIDR rules (for IP_TRIE dictionary)
|
||
-- -----------------------------------------------------------------------------
|
||
CREATE TABLE IF NOT EXISTS ja4_processing.anubis_ip_rules
|
||
(
|
||
prefix String,
|
||
bot_name LowCardinality(String),
|
||
action LowCardinality(String),
|
||
rule_id UInt64,
|
||
has_ua UInt8,
|
||
category LowCardinality(String)
|
||
)
|
||
ENGINE = ReplacingMergeTree()
|
||
ORDER BY prefix;
|
||
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
-- 3. DICTIONARY — UA REGEXP_TREE
|
||
-- dictGet('ja4_processing.dict_anubis_ua', 'bot_name', header_user_agent)
|
||
-- NOTE: Change 'CHANGE_ME' to the actual ClickHouse admin password before use.
|
||
-- -----------------------------------------------------------------------------
|
||
DROP DICTIONARY IF EXISTS ja4_processing.dict_anubis_ua;
|
||
CREATE DICTIONARY ja4_processing.dict_anubis_ua
|
||
(
|
||
regexp String,
|
||
bot_name String,
|
||
action String,
|
||
has_ip String,
|
||
rule_id String,
|
||
category String
|
||
)
|
||
PRIMARY KEY regexp
|
||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'admin' PASSWORD 'CHANGE_ME' DB 'ja4_processing' TABLE 'anubis_ua_rules'))
|
||
LAYOUT(REGEXP_TREE)
|
||
LIFETIME(MIN 300 MAX 600);
|
||
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
-- 4. DICTIONARY — IP IP_TRIE
|
||
-- dictGetOrDefault('ja4_processing.dict_anubis_ip', 'bot_name', toIPv6(src_ip), '')
|
||
-- NOTE: Change 'CHANGE_ME' to the actual ClickHouse admin password before use.
|
||
-- -----------------------------------------------------------------------------
|
||
DROP DICTIONARY IF EXISTS ja4_processing.dict_anubis_ip;
|
||
CREATE DICTIONARY ja4_processing.dict_anubis_ip
|
||
(
|
||
prefix String,
|
||
bot_name String,
|
||
action String,
|
||
rule_id UInt64,
|
||
has_ua UInt8,
|
||
category String
|
||
)
|
||
PRIMARY KEY prefix
|
||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'admin' PASSWORD 'CHANGE_ME' DB 'ja4_processing' TABLE 'anubis_ip_rules'))
|
||
LAYOUT(IP_TRIE())
|
||
LIFETIME(MIN 300 MAX 600);
|
||
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
-- 5. TABLE SOURCE — ASN rules (for Flat dictionary)
|
||
-- -----------------------------------------------------------------------------
|
||
CREATE TABLE IF NOT EXISTS ja4_processing.anubis_asn_rules
|
||
(
|
||
asn UInt32,
|
||
bot_name LowCardinality(String),
|
||
action LowCardinality(String),
|
||
category LowCardinality(String)
|
||
)
|
||
ENGINE = ReplacingMergeTree()
|
||
ORDER BY asn;
|
||
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
-- 6. TABLE SOURCE — Country rules (for Flat dictionary)
|
||
-- -----------------------------------------------------------------------------
|
||
CREATE TABLE IF NOT EXISTS ja4_processing.anubis_country_rules
|
||
(
|
||
country_code LowCardinality(String),
|
||
bot_name LowCardinality(String),
|
||
action LowCardinality(String),
|
||
category LowCardinality(String)
|
||
)
|
||
ENGINE = ReplacingMergeTree()
|
||
ORDER BY country_code;
|
||
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
-- 7. DICTIONARY — ASN Flat
|
||
-- dictGetOrDefault('ja4_processing.dict_anubis_asn', 'bot_name', src_asn, '')
|
||
-- NOTE: Change 'CHANGE_ME' to the actual ClickHouse admin password before use.
|
||
-- -----------------------------------------------------------------------------
|
||
DROP DICTIONARY IF EXISTS ja4_processing.dict_anubis_asn;
|
||
CREATE DICTIONARY ja4_processing.dict_anubis_asn
|
||
(
|
||
asn UInt32,
|
||
bot_name String,
|
||
action String,
|
||
category String
|
||
)
|
||
PRIMARY KEY asn
|
||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'admin' PASSWORD 'CHANGE_ME' DB 'ja4_processing' TABLE 'anubis_asn_rules'))
|
||
LAYOUT(FLAT())
|
||
LIFETIME(MIN 300 MAX 600);
|
||
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
-- 8. DICTIONARY — Country COMPLEX_KEY_HASHED
|
||
-- dictGetOrDefault('ja4_processing.dict_anubis_country', 'bot_name', src_country_code, '')
|
||
-- NOTE: Change 'CHANGE_ME' to the actual ClickHouse admin password before use.
|
||
-- -----------------------------------------------------------------------------
|
||
DROP DICTIONARY IF EXISTS ja4_processing.dict_anubis_country;
|
||
CREATE DICTIONARY ja4_processing.dict_anubis_country
|
||
(
|
||
country_code String,
|
||
bot_name String,
|
||
action String,
|
||
category String
|
||
)
|
||
PRIMARY KEY country_code
|
||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'admin' PASSWORD 'CHANGE_ME' DB 'ja4_processing' TABLE 'anubis_country_rules'))
|
||
LAYOUT(COMPLEX_KEY_HASHED())
|
||
LIFETIME(MIN 300 MAX 600);
|