Skip to main content
策略定義自動回應規則,並廣播到所有代理。當策略建立時,會立即透過 SSE 事件串流推送到線上的代理。

POST /api/policy

建立新策略並廣播到所有已連線的代理。
name
string
required
人類可讀的策略名稱。
description
string
策略目的的選用說明。
rules
object[]
required
要執行的策略規則陣列。
rules[].type
string
required
規則類型:block_ipalert_thresholdauto_respondcustom
rules[].config
object
required
規則特定的設定(因類型而異)。
rules[].enabled
boolean
default:"true"
規則是否啟用。
org_id
string
將策略範圍限定在特定組織。
curl -X POST https://localhost:8443/api/policy \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Block Brute Force Sources",
    "description": "Automatically block IPs after repeated SSH failures",
    "rules": [
      {
        "type": "block_ip",
        "config": {
          "trigger": "brute_force",
          "threshold": 50,
          "duration": "24h",
          "scope": "host"
        },
        "enabled": true
      },
      {
        "type": "alert_threshold",
        "config": {
          "severity": "critical",
          "countPerHour": 5,
          "notifyChannels": ["telegram", "email"]
        },
        "enabled": true
      }
    ]
  }'
{
  "ok": true,
  "data": {
    "id": "pol_abc123",
    "name": "Block Brute Force Sources",
    "version": "v3",
    "rules": [
      {
        "type": "block_ip",
        "config": {
          "trigger": "brute_force",
          "threshold": 50,
          "duration": "24h",
          "scope": "host"
        },
        "enabled": true
      },
      {
        "type": "alert_threshold",
        "config": {
          "severity": "critical",
          "countPerHour": 5,
          "notifyChannels": ["telegram", "email"]
        },
        "enabled": true
      }
    ],
    "broadcastedTo": 8,
    "createdAt": "2026-03-07T12:00:00.000Z"
  }
}

規則類型

自動封鎖觸發特定威脅類型的來源 IP。
設定欄位類型說明
triggerstring啟動封鎖的威脅類型
thresholdnumber封鎖前的事件數量
durationstring封鎖持續時間(例如 1h24h7dpermanent
scopestringhost(本機防火牆)或 fleet(所有代理)
當威脅計數超過閾值時發送通知。
設定欄位類型說明
severitystring計數的最低嚴重程度
countPerHournumber每小時閾值
notifyChannelsstring[]要發出警報的通知頻道
偵測到威脅時觸發自動回應動作。
設定欄位類型說明
triggerstring啟動回應的威脅類型
actionstring回應動作:kill_processquarantine_fileblock_ipisolate_host
minConfidencenumber最低 AI 信心分數(0.0—1.0)
requireApprovalboolean如果為 true,發送審核請求而非自動執行
使用者定義的規則,具有任意設定。由代理的規則引擎評估。
設定欄位類型說明
conditionstring自訂條件運算式
actionstring要執行的動作
paramsobject附加參數

GET /api/policy/active

回傳目前啟用的策略及其所有規則。
curl -X GET https://localhost:8443/api/policy/active \
  -H "Authorization: Bearer YOUR_TOKEN"
{
  "ok": true,
  "data": {
    "id": "pol_abc123",
    "name": "Block Brute Force Sources",
    "version": "v3",
    "rules": [...],
    "createdAt": "2026-03-07T12:00:00.000Z"
  }
}

GET /api/policy/agent/:id

回傳指派給特定代理的策略規則,包括任何代理特定的覆寫。
id
string
required
代理 ID。
curl -X GET https://localhost:8443/api/policy/agent/agent-a1b2c3d4 \
  -H "Authorization: Bearer YOUR_TOKEN"
{
  "ok": true,
  "data": {
    "agentId": "agent-a1b2c3d4",
    "policyVersion": "v3",
    "rules": [
      {
        "type": "block_ip",
        "config": {
          "trigger": "brute_force",
          "threshold": 50,
          "duration": "24h",
          "scope": "host"
        },
        "enabled": true
      }
    ],
    "appliedAt": "2026-03-07T12:01:00.000Z"
  }
}
策略以遞增方式進行版本控制。每次建立新策略都會遞增版本(v1、v2、v3 等)。代理在心跳回應中報告其目前的策略版本,方便識別運行過時策略的代理。