配置说明
rho-aias 的所有配置通过 YAML 文件管理,默认配置文件为 config.yml。
完整配置示例
server:
port: 8081 # API 服务端口
# 日志配置
log:
level: info # 日志级别: debug/info/warn/error
format: console # 输出格式: console/json
output_dir: ./logs # 日志目录
max_age_days: 30 # 日志保留天数
rotation_hours: 1 # 按小时分割
# eBPF/XDP 配置
ebpf:
interface_name: ens33 # 绑定的网卡名称
# 业务数据库配置(封禁记录、情报状态等)
business:
database_path: ./data/business.db # 业务数据库路径
# 威胁情报配置
intel:
enabled: false
auto_refresh_on_start: true # 启动时自动刷新
persistence_dir: ./data/intel
batch_size: 1000
sources:
ipsum:
enabled: true
periodic: true # 是否开启周期性更新
schedule: "0 1 * * *" # 每天凌晨 1 点更新
url: http://localhost/ipsum.txt
format: ipsum
spamhaus:
enabled: true
periodic: true
schedule: "0 2 * * *" # 每天凌晨 2 点更新
url: http://localhost/drop.txt
format: spamhaus
# 地域封禁配置
geo_blocking:
enabled: false
auto_refresh_on_start: true
mode: whitelist # whitelist 或 blacklist
allowed_countries:
- CN # 中国
allow_private_networks: true # 允许私有网段绕过地域检查
persistence_dir: ./data/geo
batch_size: 1000
sources:
maxmind:
enabled: true
periodic: true
schedule: "0 3 * * *" # 每天凌晨 3 点更新
url: http://localhost/GeoLite2-Country.mmdb
format: maxmind-db
# 手动规则持久化
manual:
enabled: true
persistence_dir: ./data/manual
auto_load: true # 启动时自动加载
# 认证配置
auth:
enabled: false
jwt_secret: "" # 建议从环境变量 JWT_SECRET 读取
jwt_issuer: "rho-aias"
token_duration: 1440 # Token 有效期(分钟),默认 24 小时
database_path: "./data/auth.db"
captcha_enabled: true
captcha_duration: 5 # 验证码有效期(分钟)
api_keys: [] # 预定义 API Key
# 阻断日志配置
blocklog:
buffer_size: 1000 # 异步写入缓冲区
flush_interval: 5 # 刷盘间隔(秒)
geo_enrich: # IP 归属地自动补全
enabled: true
batch_size: 500 # 每批处理数
# WAF 联动配置(仅 WAF 审计日志,不含 Rate Limit)
waf:
enabled: true
waf_log_path: /caddy-logs/waf_audit.log
ban_duration: 3600 # 封禁时长(秒)
offset_state_file: ./data/waf_offset.json # 偏移量持久化文件路径
# Rate Limit 独立模块配置(已从 WAF 中分离)
rate_limit:
enabled: false
log_path: /caddy-logs/rate_limit.log
ban_duration: 3600 # 封禁时长(秒)
offset_state_file: ./data/ratelimit_offset.json # 偏移量持久化文件路径
# SSH 防爆破配置(基于 eBPF probes 内核级检测)
failguard:
enabled: true
ssh_ports: [22] # 监控的 SSH 端口列表
short_conn_seconds: 2 # preauth 短连接判定阈值(秒)
mode: normal # 检测模式: normal/ddos/aggressive
max_retry: 5 # 触发封禁的失败次数阈值
find_time: 600 # 滑动窗口时长(秒)
ban_duration: 3600 # 封禁时长(秒)
# 异常检测配置(基于 IQR 基线算法)
anomaly_detection:
enabled: true
sample_rate: 100 # 采样率(100 表示 1%)
check_interval: 1 # 检测间隔(秒)
min_packets: 100 # 全局最小包数门槛
cleanup_interval: 300 # 清理间隔(秒)
block_duration: 60 # 临时封禁时长(秒)
ports: # 检测端口(为空则全部)
- 80
- 443
- 8080
- 53
baseline: # IQR 基线配置
min_sample_count: 10 # 最小学习样本数
iqr_multiplier: 2.5 # IQR 倍数
min_threshold: 100 # 最小 PPS 阈值
max_age: 1800 # 基线最大有效期(秒)
block_duration: 60 # 基线触发封禁时长(秒)
attacks:
syn_flood:
enabled: true
ratio_threshold: 0.5 # SYN 包占比阈值
min_packets: 1000 # TCP 最小包数
block_duration: 60 # 封禁时长
udp_flood:
enabled: true
ratio_threshold: 0.8
min_packets: 1000
block_duration: 60
icmp_flood:
enabled: true
ratio_threshold: 0.5
min_packets: 100
block_duration: 60
ack_flood:
enabled: true
ratio_threshold: 0.95 # ACK 占比阈值(正常流量远低于此值)
min_packets: 500 # TCP 最小包数
block_duration: 60
# Egress 出口限速配置(TC eBPF 令牌桶限速)
egress_limit:
enabled: false # 总开关(默认关闭)
rate_mbps: 1.0 # 限速速率(Mbps)
burst_bytes: 250000 # 突发上限(Bytes)
drop_log_enabled: false # 丢包日志开关
drop_log_sample_rate: 1 # 丢包日志采样率配置模块详解
服务配置 (server)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
port | int | 8081 | API 服务监听端口 |
日志配置 (log)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
level | string | info | 日志级别:debug/info/warn/error |
format | string | console | 输出格式:console/json |
output_dir | string | ./logs | 日志文件目录 |
max_age_days | int | 30 | 日志保留天数 |
rotation_hours | int | 1 | 日志分割周期(小时) |
eBPF 配置 (ebpf)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
interface_name | string | - | XDP 绑定的网卡名称(必填) |
业务数据库配置 (business)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
database_path | string | ./data/business.db | 业务数据库路径,存储封禁记录、情报状态等数据 |
威胁情报配置 (intel)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | false | 是否启用威胁情报 |
auto_refresh_on_start | bool | true | 启动时自动刷新 |
persistence_dir | string | ./data/intel | 持久化目录 |
batch_size | int | 1000 | 批量更新大小 |
情报源配置 (intel.sources)
每个情报源支持以下参数:
| 参数 | 类型 | 说明 |
|---|---|---|
enabled | bool | 是否启用此情报源 |
periodic | bool | 是否启用周期性更新(默认 true) |
schedule | string | Cron 表达式,如 0 1 * * * 表示每天凌晨 1 点 |
url | string | 数据源 URL |
format | string | 格式类型:ipsum、spamhaus |
地域封禁配置 (geo_blocking)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | false | 是否启用地域封禁 |
auto_refresh_on_start | bool | true | 启动时自动刷新 |
mode | string | whitelist | 模式:whitelist(白名单)或 blacklist(黑名单) |
allowed_countries | []string | - | 允许/封禁的国家代码列表(ISO 3166-1 alpha-2) |
allow_private_networks | bool | true | 允许私有网段绕过地域检查 |
persistence_dir | string | ./data/geo | 持久化目录 |
batch_size | int | 1000 | 批量更新大小 |
GeoIP 数据源配置 (geo_blocking.sources)
| 参数 | 类型 | 说明 |
|---|---|---|
enabled | bool | 是否启用 |
periodic | bool | 是否周期性更新 |
schedule | string | Cron 表达式 |
url | string | MMDB 文件 URL |
format | string | 格式:maxmind-db |
手动规则配置 (manual)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | true | 是否启用手动规则持久化 |
persistence_dir | string | ./data/manual | 持久化目录 |
auto_load | bool | true | 启动时自动加载已保存的规则 |
认证配置 (auth)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | false | 是否启用认证 |
jwt_secret | string | - | JWT 密钥(建议从环境变量 JWT_SECRET 读取) |
jwt_issuer | string | rho-aias | JWT 签发者 |
token_duration | int | 1440 | Token 有效期(分钟) |
database_path | string | ./data/auth.db | SQLite 数据库路径 |
captcha_enabled | bool | true | 是否启用验证码 |
captcha_duration | int | 5 | 验证码有效期(分钟) |
api_keys | []APIKeyConfig | - | 预定义的 API Key 列表 |
API Key 配置
auth:
api_keys:
- name: "Master Admin Key"
key: "${MASTER_API_KEY}" # 支持环境变量
permissions: ["*"] # 全部权限
- name: "Read-only Key"
key: "sk_live_your-key"
permissions:
- "firewall:read"
- "intel:read"
- "geo:read"
- "blocklog:read"阻断日志配置 (blocklog)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
buffer_size | int | 1000 | 异步写入缓冲区大小 |
flush_interval | int | 5 | 缓冲区刷盘间隔(秒) |
IP 归属地补全配置 (blocklog.geo_enrich)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | - | 是否启用 IP 归属地自动补全 |
batch_size | int | 500 | 每批处理的记录数 |
WAF 联动配置 (waf)
注意:v2.0 起 Rate Limit 已从 WAF 模块中拆分为独立的
rate_limit配置段。WAF 配置仅管理 WAF 审计日志。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | false | 是否启用 WAF 日志监控 |
waf_log_path | string | /logs/waf_audit.log | WAF 审计日志路径(Caddy + Coraza) |
ban_duration | int | 3600 | 封禁时长(秒) |
offset_state_file | string | ./data/waf_offset.json | 偏移量持久化文件路径 |
Rate Limit 独立配置 (rate_limit)
v2.0 新增独立配置段,原位于
waf.rate_limit_log_path和相关逻辑已迁移至此。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | false | 是否启用 Rate Limit 日志监控 |
log_path | string | /logs/rate_limit.log | Rate Limit 日志路径 |
ban_duration | int | 3600 | 封禁时长(秒) |
offset_state_file | string | ./data/ratelimit_offset.json | 偏移量持久化文件路径 |
详见 WAF 集成 文档中关于 Rate Limit 的说明。
SSH 防爆破配置 (failguard)
注意:v2.0 已从日志扫描模式升级为 eBPF probes 内核级检测。旧版配置中的
log_path、fail_regex、ignore_regex、ignore_ips、offset_state_file已移除。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | false | 是否启用 FailGuard |
ssh_ports | []int | [22] | 监控的 SSH 端口列表 |
short_conn_seconds | int | 2 | preauth 短连接判定阈值(秒) |
mode | string | normal | 检测模式:normal、ddos、aggressive |
max_retry | int | 5 | 滑动窗口内触发封禁的失败次数阈值 |
find_time | int | 600 | 滑动窗口时长(秒) |
ban_duration | int | 3600 | 封禁时长(秒) |
详见 SSH 防爆破。
异常检测配置 (anomaly_detection)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | false | 是否启用异常检测 |
sample_rate | int | 100 | 采样率(100=1%,1=100%) |
check_interval | int | 1 | 检测间隔(秒) |
min_packets | int | 100 | 全局最小包数门槛(单 IP 每秒少于此值跳过攻击检测) |
cleanup_interval | int | 300 | 清理过期数据间隔(秒) |
block_duration | int | 60 | 临时封禁时长(秒) |
ports | []int | - | 检测端口列表(为空则检测所有端口,同时应用于 TCP/UDP) |
IQR 基线配置 (anomaly_detection.baseline)
注意:v2.0 已将基线算法从 3σ(标准差)升级为 IQR(四分位距)。原
sigma_multiplier参数替换为iqr_multiplier。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
min_sample_count | int | 10 | 最小样本数(不足时仅学习不检测) |
iqr_multiplier | float64 | 2.5 | IQR 倍数(替代旧的 sigma_multiplier) |
min_threshold | int | 100 | 最小 PPS 阈值 |
max_age | int | 1800 | 基线最大年龄(秒),过期后重建 |
block_duration | int | 60 | 基线触发的封禁时长(秒) |
攻击类型配置 (anomaly_detection.attacks)
每种攻击类型支持:
| 参数 | 类型 | 说明 |
|---|---|---|
enabled | bool | 是否启用此类型检测 |
ratio_threshold | float64 | 协议包占比阈值(0.0-1.0) |
min_packets | int | 触发检测的最小包数 |
block_duration | int | 封禁时长(秒) |
支持的攻击类型:syn_flood、udp_flood、icmp_flood、ack_flood
详见 异常检测。
Egress 出口限速配置 (egress_limit)
v2.0 新增模块。基于 TC eBPF 令牌桶算法实现出口流量控制。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | bool | false | 是否启用 Egress 限速(默认关闭) |
rate_mbps | float64 | 1.0 | 限速速率(Mbps) |
burst_bytes | uint64 | 250000 | 突发上限(Bytes) |
drop_log_enabled | bool | false | 是否记录被丢弃的包信息 |
drop_log_sample_rate | uint32 | 1 | 丢包日志采样率(N 表示每 N 个包记录 1 个) |
详见 Egress 出口限速。
环境变量
支持在配置文件中使用 ${VAR_NAME} 语法引用环境变量:
auth:
jwt_secret: "${JWT_SECRET}"
api_keys:
- name: "Master Key"
key: "${MASTER_API_KEY}"
permissions: ["*"]启动前设置环境变量:
export JWT_SECRET="your-strong-secret-key"
export MASTER_API_KEY="sk_live_your-master-key"动态配置
rho-aias 支持运行时动态修改大部分模块的核心配置参数,无需重启服务。动态配置通过 API 或数据库写入,在启动时也会从数据库恢复上次保存的配置。
支持动态配置的模块:
| 模块 | 可配置参数 |
|---|---|
failguard | enabled, max_retry, find_time, ban_duration, mode |
waf | enabled, ban_duration |
rate_limit | enabled, ban_duration |
anomaly_detection | enabled, min_packets, ports, baseline., attacks. |
geo_blocking | enabled, mode, allowed_countries, sources |
intel | enabled, sources |
blocklog_events | enabled, sample_rate(XDP 事件上报配置) |
egress_limit | enabled, rate_mbps, burst_bytes, drop_log_enabled, drop_log_sample_rate |
动态配置优先级
启动时的配置优先级为:数据库动态配置 > YAML 配置 > 代码默认值
规则来源位掩码
rho-aias 使用位掩码标记规则来源,支持多源聚合:
| 来源 | 位掩码 | 说明 |
|---|---|---|
| IPSum | 0x01 | IPSum 威胁情报 |
| Spamhaus | 0x02 | Spamhaus 威胁情报 |
| 手动规则 | 0x04 | 通过 API 手动添加 |
| WAF 联动 | 0x08 | WAF 自动封禁 |
| DDoS 防护 | 0x10 | DDoS 检测自动封禁 |
| 频率限制 | 0x20 | Rate Limit 封禁 |
| 异常检测 | 0x40 | IQR 基线 + 攻击类型检测封禁 |
| IP 白名单 | 0x80 | 全局白名单,直接放行 |
| SSH 防爆破 | 0x100 | FailGuard SSH 暴力破解防护(eBPF 模式) |
当同一 IP 被多个来源标记时,位掩码会合并,删除时会检查是否还有其他来源。
Cron 表达式说明
配置中的 schedule 字段使用标准 Cron 表达式:
┌───────────── 分钟 (0 - 59)
│ ┌───────────── 小时 (0 - 23)
│ │ ┌───────────── 日期 (1 - 31)
│ │ │ ┌───────────── 月份 (1 - 12)
│ │ │ │ ┌───────────── 星期几 (0 - 6,0 为周日)
│ │ │ │ │
* * * * *常用示例:
| 表达式 | 说明 |
|---|---|
0 1 * * * | 每天凌晨 1 点 |
0 */6 * * * | 每 6 小时 |
0 0 * * 0 | 每周日午夜 |
0 0 1 * * | 每月 1 日午夜 |