Skip to content

Latest commit

 

History

History
493 lines (391 loc) · 10.5 KB

API.md

File metadata and controls

493 lines (391 loc) · 10.5 KB

CLUESTREAM REST API Reference

REST API for CLUESTREAM live mode. It accepts submitted event batches and is available only when running with --mode live or CLUESTREAM_MODE=live. All endpoints require authentication (except /api/v1/health).


Table of Contents

  1. Authentication
  2. Endpoints
  3. Error Responses
  4. Rate Limiting
  5. CORS
  6. Examples

Authentication

All API endpoints (except health) require a Bearer token obtained from the web dashboard login (POST /api/login) or via the CLI.

# Get a session token via the dashboard (returns csrfToken and sets cookie)
curl -X POST http://localhost:8765/api/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"<startup-password>"}'

# Use the token for API requests
curl -X GET http://localhost:8080/api/v1/alerts \
  -H "Authorization: Bearer <session-token>"

Sessions expire after 30 minutes of inactivity. Session tokens are regenerated on every login to prevent session fixation.


Endpoints

Health Check

GET /api/v1/health

No authentication required. Returns server status and storage statistics.

Response:

{
  "status": "ok",
  "mode": "live",
  "alerts": 14,
  "iocs": 8,
  "cases": 2,
  "evidence": 1
}

Analyze Events

POST /api/v1/analyze
Content-Type: application/json
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Run detection on a batch of events and return detected alerts.

Request body:

{
  "events": [
    {
      "event_type": "authentication_failure",
      "source_ip": "10.0.0.5",
      "username": "admin",
      "timestamp": "2026-12-02T10:00:00Z"
    }
  ],
  "detection": {
    "ssh_bruteforce": {
      "threshold": 3,
      "window_minutes": 10
    }
  },
  "mode": "live"
}

Response:

{
  "alerts": [
    {
      "alert_type": "SSH_BRUTEFORCE",
      "name": "SSH brute-force from 10.0.0.5",
      "severity": "HIGH",
      "confidence": 85,
      "description": "Multiple authentication failures from 10.0.0.5",
      "source_ip": "10.0.0.5",
      "username": "admin",
      "mitre_attack": "T1110",
      "timestamp": "2026-12-02T10:05:00Z"
    }
  ],
  "count": 1,
  "status": "success",
  "persisted": true,
  "alerts_stored": 1
}

Alerts and alert-linked IOCs produced by analyze are now persisted to the live SQLite database.


Ingest Forwarder Logs

POST /api/v1/logs
Content-Type: application/json
Authorization: Bearer <collector-token>

Separate collector endpoint (default 127.0.0.1:9000) for Winlogbeat, Filebeat, rsyslog and Fluent Bit. The token comes from collectors.http.token_file, not from the dashboard session store. See COLLECTION.md.

Accepts a JSON array, {"events": [...]}, {"logs": [...]}, {"records": [...]} or one event object. Strings are parsed as raw log lines; objects are parsed as vendor JSON. Max 10,000 events per batch and 64 MB body.

Response:

{
  "status": "ok",
  "events_ingested": 3,
  "events_rejected": 0,
  "alert_count": 0,
  "alerts": [],
  "persisted": true,
  "alerts_stored": 0,
  "iocs_stored": 0
}

Collector Status

GET /api/v1/status
Authorization: Bearer <session-token>

Returns collector lifecycle and storage statistics. Never returns tokens or event contents.

Response:

{
  "status": "ok",
  "streaming": {"running": true, "events_ingested": 42, "alerts_produced": 2,
                "errors": 0, "buffer": {"size": 0, "max_size": 10000, "dropped": 0},
                "sources": [{"host": "127.0.0.1", "port": 9000,
                             "running": true, "authenticated": true,
                             "events_received": 42, "errors": 0}]},
  "storage": {"alerts": 2, "iocs": 1, "cases": 0, "evidence": 0,
              "raw_evidence": 2, "retention_audit": 0}
}

Retention and Evidence Vault

GET /api/v1/retention
GET /api/v1/raw-evidence?alert_id=<id>&limit=100
GET /api/v1/raw-evidence/{evidence_id}
POST /api/v1/maintenance/purge        (Admin session required)

The vault is disabled by default (alert_evidence_hours: 0). When enabled, each alert may hold a sealed, expiring copy of its source events. Metadata endpoints never return the vault key; the single-record endpoint verifies and decrypts the evidence. A failed integrity check returns HTTP 500 with a generic message.

{
  "status": "ok",
  "normal_events_hours": 0,
  "alert_evidence_hours": 72,
  "max_events_per_alert": 25,
  "vault_enabled": true
}

POST /api/v1/maintenance/purge deletes expired records and returns the count plus recent retention_audit entries.


List Alerts

GET /api/v1/alerts?limit=100&offset=0&severity=HIGH
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Retrieve stored alerts with optional severity filter and pagination.

Query parameters:

Parameter Type Default Description
limit int 100 Maximum results (1–1000)
offset int 0 Offset for pagination
severity string all Filter by severity (LOW/MEDIUM/HIGH/CRITICAL)

Response:

{
  "alerts": [...],
  "count": 14,
  "offset": 0,
  "limit": 100
}

List IOCs

GET /api/v1/iocs?type=ip
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Retrieve extracted indicators of compromise with optional type filter.

Query parameters:

Parameter Type Description
type string Filter by IOC type (ip, domain, url, email, hash, etc.)

Response:

{
  "iocs": [
    {
      "id": "uuid",
      "type": "ip",
      "value": "10.0.0.5",
      "severity": "HIGH",
      "confidence": 90,
      "source": "detection",
      "created_at": "2026-12-02T10:05:00Z"
    }
  ],
  "count": 1
}

Case Management

Create a Case

POST /api/v1/cases
Content-Type: application/json
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Request body:

{
  "title": "SSH Brute-force Investigation",
  "description": "Multiple SSH authentication failures from 10.0.0.5",
  "severity": "HIGH"
}

Response (201):

{
  "id": "uuid",
  "title": "SSH Brute-force Investigation",
  "description": "Multiple SSH authentication failures from 10.0.0.5",
  "status": "open",
  "severity": "HIGH",
  "created_at": "2026-12-02T10:05:00Z",
  "updated_at": "2026-12-02T10:05:00Z"
}

List Cases

GET /api/v1/cases?limit=100&offset=0&status=open
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Get Case by ID

GET /api/v1/cases/{case_id}
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Update a Case

PATCH /api/v1/cases/{case_id}
Content-Type: application/json
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Request body (partial update):

{
  "status": "investigating",
  "severity": "CRITICAL"
}

RBAC: cases:write permission required (Analyst, Analyst Manager, Admin).


Evidence Management

Store Evidence

POST /api/v1/evidence
Content-Type: application/json
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Store evidence linked to a case with SHA-256 integrity hash.

Request body:

{
  "case_id": "uuid",
  "filename": "/var/log/auth.log",
  "sha256": "a1b2c3d4e5f6...",
  "description": "SSH authentication logs from attack source"
}

Response (201):

{
  "id": "uuid",
  "case_id": "uuid",
  "filename": "/var/log/auth.log",
  "sha256": "a1b2c3d4e5f6...",
  "status": "stored"
}

List Evidence

GET /api/v1/evidence?case_id={case_id}
Authorization: Bearer <token>
X-CSRF-Token: <csrf-token>

Error Responses

All errors return JSON with error and status fields:

{
  "error": "Authentication required",
  "status": 401
}
Status Meaning
400 Bad request (invalid input)
401 Authentication required
403 Forbidden (CSRF or origin check failed)
404 Not found
429 Rate limit exceeded
500 Internal server error
503 Storage not available

Rate Limiting

API endpoints are rate-limited per client IP and endpoint:

Endpoint Type Limit Window
General API 100 requests 60 seconds
Write endpoints (/upload, /clear, /cases) Stricter 60 seconds

Rate limit responses include a Retry-After header.


CORS

Cross-Origin Resource Sharing is supported with origin allowlisting. Only origins listed in mode.live_cors_origins are allowed. The * wildcard is supported but not recommended for production.

Headers added to allowed responses:

  • Access-Control-Allow-Origin
  • Access-Control-Allow-Methods
  • Access-Control-Allow-Headers
  • Access-Control-Allow-Credentials
  • Access-Control-Max-Age

Examples

Complete workflow: analyze → case → evidence

# 1. Login and get token
TOKEN=$(curl -s -X POST http://localhost:8765/api/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"<pwd>"}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('csrfToken',''))")

# 2. Analyze events
curl -s -X POST http://localhost:8080/api/v1/analyze \
  -H "Authorization: Bearer $TOKEN" \
  -H "X-CSRF-Token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"events":[{"event_type":"authentication_failure","source_ip":"10.0.0.5","username":"admin"}]}'

# 3. Create a case
curl -s -X POST http://localhost:8080/api/v1/cases \
  -H "Authorization: Bearer $TOKEN" \
  -H "X-CSRF-Token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title":"SSH Investigation","severity":"HIGH"}'

# 4. Store evidence
curl -s -X POST http://localhost:8080/api/v1/evidence \
  -H "Authorization: Bearer $TOKEN" \
  -H "X-CSRF-Token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"case_id":"<case-id>","filename":"auth.log","sha256":"abc123"}'

SDK / Client Libraries

No official client libraries are provided. The API is a simple REST/JSON interface that can be consumed by any HTTP client. Example languages: Python (requests), Bash (curl), JavaScript (fetch), Go (net/http).


Changes from Offline Mode

Feature Offline Live
Network access None TCP/HTTP
REST API No Yes
Persistent storage Report files Yes (SQLite for live records)
Multi-user No (single-user) Yes (RBAC)
MFA No Yes (TOTP)
Alert access No Yes (API/dashboard polling of stored alerts)