Skip to content

Repository files navigation

Python 3.12 FastAPI Docker Keycloak MariaDB Redis License

πŸ›‘οΈ AI-Based Network Intrusion Detection System

A production-grade, zero-trust network intrusion detection system with AI-driven anomaly detection, mutual TLS, hash-chained audit logging, and enterprise-grade identity management.

Features β€’ Architecture β€’ Tech Stack β€’ Quick Start β€’ API Reference β€’ Security Model β€’ Deployment β€’ Testing


✨ Features

πŸ€– AI-Driven Anomaly Detection

  • Credential stuffing detection β€” Identifies mass login attempts from a single IP targeting different usernames
  • Impossible travel analysis β€” Flags logins from geographically impossible IP locations in short timeframes
  • Brute-force escalation patterns β€” Detects rapid failure rate increases before account lockout triggers
  • Off-hours access monitoring β€” Alerts on successful authentications outside configured business hours
  • Session anomaly detection β€” Identifies abnormal session creation rates per user
  • Dynamic risk scoring β€” Computes a 0–100 risk score per user/IP based on weighted anomaly signals

πŸ” Zero Trust Security

  • Mutual TLS (mTLS) β€” Bidirectional certificate-based authentication for all sensor-to-server communication
  • Private PKI β€” Automated certificate lifecycle via step-ca with ACME protocol
  • Zero Trust Network Access (ZTNA) β€” Device identity verification, geo-allowlisting, user-agent filtering, and risk-score-based access gating
  • CRL (Certificate Revocation List) β€” Real-time revocation with 60-second refresh intervals

🏒 Enterprise Identity & Access Management

  • Keycloak SSO β€” OIDC/OAuth2 integration with MFA support for all administrative access
  • Role-Based Access Control (RBAC) β€” Four distinct roles: Super Admin, Security Analyst, Auditor, Sensor Manager
  • PII Data Masking β€” Automatic field-level masking based on JWT role claims
  • Session Management β€” Redis-backed sessions with idle timeout (15 min), absolute timeout (8 hrs), and concurrent session limits

πŸ“‹ Tamper-Proof Audit Logging

  • Hash-chained logs β€” SHA-256 chain linking each entry to its predecessor, making tampering detectable
  • Append-only storage β€” Immutable log shipping to Grafana Loki
  • Structured logging β€” JSON-structured events via structlog for every authentication attempt, config change, and data access

πŸ”‘ Secrets Management & Rotation

  • Centralized secrets β€” Runtime secret injection via Infisical (self-hosted)
  • Automated rotation health checks β€” Continuous monitoring of certificate expiry, API key age, and secret staleness
  • SOPS + age encryption β€” Encrypted secrets at rest in configuration files

πŸ›°οΈ Sensor Network Management

  • UUID-based sensor identity β€” Each sensor registered with unique identifiers
  • Short-lived certificates β€” 30-day auto-rotating certificates via ACME protocol
  • Bootstrap enrollment β€” Single-use, 1-hour API keys for initial sensor onboarding
  • CRUD operations β€” Full sensor lifecycle management through the REST API

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        NIDS Architecture                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    mTLS     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Sensor   │◄──────────►│           FastAPI App (:8000)        β”‚  β”‚
β”‚  β”‚  Network  β”‚            β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚  β”‚ Auth   β”‚ Sensors β”‚ Security   β”‚   β”‚  β”‚
β”‚                           β”‚  β”‚ Router β”‚ Router  β”‚ Router     β”‚   β”‚  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   OIDC/     β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”‚  β”‚
β”‚  β”‚Dashboard │◄──JWT──────►│  β”‚      Middleware Layer          β”‚   β”‚  β”‚
β”‚  β”‚  (User)  β”‚             β”‚  β”‚  ZTNA β”‚ Audit β”‚ Rate Limit    β”‚   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”‚  β”‚
β”‚                           β”‚  β”‚      Service Layer             β”‚   β”‚  β”‚
β”‚                           β”‚  β”‚  Anomaly β”‚ mTLS β”‚ Rotation    β”‚   β”‚  β”‚
β”‚                           β”‚  β”‚  Lockout β”‚ CRL  β”‚ Session     β”‚   β”‚  β”‚
β”‚                           β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚  β”‚
β”‚                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                    β”‚       β”‚       β”‚                 β”‚
β”‚                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚                 β”‚                  β”‚       β”‚       β”‚          β”‚     β”‚
β”‚           β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β” β”Œβ”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”‚     β”‚
β”‚           β”‚ MariaDB   β”‚    β”‚Keycloak β”‚ β”‚Redis β”‚ β”‚ Loki   β”‚  β”‚     β”‚
β”‚           β”‚  11.4     β”‚    β”‚  26.0   β”‚ β”‚  7   β”‚ β”‚ 3.0    β”‚  β”‚     β”‚
β”‚           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚     β”‚
β”‚                 β”‚                                            β”‚     β”‚
β”‚           β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚     β”‚
β”‚           β”‚ step-ca   β”‚    β”‚Infisical β”‚   β”‚  fail2ban    β”‚  β”‚     β”‚
β”‚           β”‚  (PKI)    β”‚    β”‚(Secrets) β”‚   β”‚(IP Blocking) β”‚  β”‚     β”‚
β”‚           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚     β”‚
β”‚                 β”‚                                            β”‚     β”‚
β”‚                 └────────────nids-internalβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                                                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Network Isolation

Network Access Services
nids-internal Private (no external access) MariaDB, Redis, Loki, step-ca, Infisical
nids-frontend Bridged (external access) FastAPI App, Keycloak

🧰 Tech Stack

Layer Technology Purpose
API Framework FastAPI 0.115+ Async REST API with automatic OpenAPI docs
Language Python 3.12 Core application runtime
Database MariaDB 11.4 Persistent storage for sensors, API keys, audit state
Cache / Sessions Redis 7 (Alpine) Session storage, rate limiting, anomaly event streams
Identity Provider Keycloak 26.0 OIDC/OAuth2 SSO, MFA, user federation
PKI / mTLS step-ca (Smallstep) Private CA, automated cert issuance & renewal
Audit Logging Grafana Loki 3.0 Append-only, immutable log aggregation
Secrets Management Infisical Centralized runtime secret injection
IP Blocking fail2ban Network-level brute-force protection
Service Mesh Linkerd Internal mTLS, per-route metrics, retries (K8s)
Migrations Alembic Database schema versioning
ORM SQLAlchemy 2.0 Async database operations
Structured Logging structlog JSON-formatted, contextual logging
Containerization Docker + Compose Multi-service orchestration
Orchestration Kubernetes Production deployment with NetworkPolicies

πŸš€ Quick Start

Prerequisites

1. Clone the Repository

git clone https://github.com/<your-username>/NIDS.git
cd NIDS

2. Configure Environment

cp .env.example .env

Open .env and replace all change_me_* values with strong, unique passwords:

DB_ROOT_PASSWORD=<strong-password>
DB_PASSWORD=<strong-password>
REDIS_PASSWORD=<strong-password>
KEYCLOAK_ADMIN_PASSWORD=<strong-password>
KEYCLOAK_CLIENT_SECRET=<generated-secret>
STEP_CA_PASSWORD=<strong-password>
INFISICAL_ENCRYPTION_KEY=<32-byte-hex-key>
INFISICAL_AUTH_SECRET=<strong-secret>

Tip

Generate secure random passwords with:

openssl rand -base64 32

3. Start the Services

Development (with hot-reload):

docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d

Production:

docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

4. Verify All Services Are Running

docker compose ps
Service URL Description
NIDS API http://localhost:8000 FastAPI application
API Docs http://localhost:8000/docs Swagger UI
Keycloak http://localhost:8080 Admin console
Loki http://localhost:3100 Log aggregation
step-ca https://localhost:9000 Certificate authority
Infisical http://localhost:8085 Secrets dashboard

5. Health Check

curl http://localhost:8000/health

Expected response:

{
  "status": "healthy",
  "database": "connected",
  "redis": "connected",
  "keycloak": "reachable",
  "loki": "reachable"
}

πŸ“‘ API Reference

Base URL: http://localhost:8000

Authentication

Method Endpoint Description Auth
POST /auth/login Authenticate user via Keycloak None
POST /auth/logout Revoke session and tokens Bearer JWT
POST /auth/refresh Rotate refresh token Refresh Token
GET /auth/sessions List active sessions Bearer JWT
DELETE /auth/sessions/{id} Revoke a specific session Bearer JWT

Sensors

Method Endpoint Description Auth
POST /sensors/register Register a new sensor Bearer JWT (Sensor Manager+)
GET /sensors/ List all sensors Bearer JWT
GET /sensors/{id} Get sensor details Bearer JWT
PUT /sensors/{id} Update sensor metadata Bearer JWT (Sensor Manager+)
DELETE /sensors/{id} Decommission a sensor Bearer JWT (Super Admin)
POST /sensors/data Submit sensor telemetry mTLS Certificate
POST /sensors/{id}/api-key Generate bootstrap API key Bearer JWT (Sensor Manager+)
POST /sensors/{id}/certificate Issue mTLS certificate API Key (Bootstrap)

Audit

Method Endpoint Description Auth
GET /audit/logs Query audit logs Bearer JWT (Auditor+)
GET /audit/chain/verify Verify hash-chain integrity Bearer JWT (Super Admin)

Security

Method Endpoint Description Auth
GET /security/anomalies List detected anomalies Bearer JWT (Analyst+)
GET /security/risk-score Get risk score for user/IP Bearer JWT (Analyst+)
GET /security/rotation-status Check secret/cert rotation health Bearer JWT (Super Admin)

Health

Method Endpoint Description Auth
GET /health System health check None
GET /health/ready Readiness probe (K8s) None

Note

Full interactive API documentation is available at /docs (Swagger UI) and /redoc (ReDoc) when the server is running.


πŸ”’ Security Model

Defense in Depth

The security architecture is organized into three progressive phases:

Phase 1 β€” Foundation          Phase 2 β€” Enhanced            Phase 3 β€” Advanced
─────────────────────         ────────────────────          ──────────────────────
βœ… Keycloak SSO + MFA          βœ… mTLS via step-ca            βœ… AI Anomaly Detection
βœ… RBAC (4 roles)               βœ… CRL Revocation              βœ… ZTNA Policy Engine
βœ… Redis Sessions               βœ… Hash-Chained Audit Logs     βœ… Infisical Secrets
βœ… Brute-Force Protection       βœ… JWT Token Lifecycle          βœ… Linkerd Service Mesh
βœ… fail2ban IP Blocking          βœ… Data Masking (PII)          βœ… Rotation Health Checks
βœ… SOPS + age Encryption        βœ… Environment-Aware CORS      βœ… Dynamic Risk Scoring

RBAC Matrix

Capability Super Admin Security Analyst Auditor Sensor Manager
Manage users & global config βœ… ❌ ❌ ❌
View dashboards & alerts βœ… βœ… ❌ ❌
Investigate incidents βœ… βœ… ❌ ❌
Read audit logs βœ… ❌ βœ… ❌
Generate/revoke API keys βœ… ❌ ❌ βœ…
View sensor health βœ… ❌ ❌ βœ…
Unmask PII fields βœ… ❌ ❌ ❌
View raw payloads βœ… ❌ ❌ ❌

Data Masking Rules

Data Type Super Admin Analyst Auditor Sensor Manager
IP Addresses Full Masked Masked N/A
Hostnames Full Masked Masked N/A
Raw Payloads Full Metadata only Hidden N/A
Usernames Full Masked Masked N/A
Sensor Metadata Full Full Read-only Full

🚒 Deployment

Docker Compose (Recommended for Single-Node)

# Production with optimized settings
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

# View logs
docker compose logs -f app

# Stop all services
docker compose down

# Stop and remove volumes (⚠️ destroys data)
docker compose down -v

Kubernetes (Production Multi-Node)

The k8s/ directory provides Linkerd service mesh configuration with:

  • Namespace-level mTLS injection β€” All pods in the nids namespace get automatic mTLS sidecars
  • Deny-all NetworkPolicies β€” Only explicitly allowed service-to-service traffic is permitted
  • ServiceProfile β€” Per-route metrics and retry policies for the NIDS API
  • ServerAuthorization β€” Only authenticated mesh identities can reach the API
# Install Linkerd
curl -fsL https://run.linkerd.io/install | sh
linkerd install --crds | kubectl apply -f -
linkerd install | kubectl apply -f -
linkerd check

# Apply NIDS manifests
kubectl apply -f k8s/linkerd-annotations.yml

# Verify mesh injection
linkerd viz stat deploy -n nids

Environment Profiles

Variable Development Staging Production
ENVIRONMENT development staging production
MTLS_ENABLED false true true
ZTNA_ENABLED false false true
ANOMALY_DETECTION_ENABLED true true true
CORS_ORIGINS http://localhost:3000 https://staging-* https://dashboard.*

πŸ§ͺ Testing

The project includes a comprehensive test suite covering all security layers:

# Run all tests
docker compose exec app pytest tests/ -v

# Run specific test modules
docker compose exec app pytest tests/test_anomaly.py -v       # AI anomaly detection
docker compose exec app pytest tests/test_auth.py -v           # Authentication flows
docker compose exec app pytest tests/test_lockout.py -v        # Brute-force protection
docker compose exec app pytest tests/test_ztna.py -v           # Zero Trust policies
docker compose exec app pytest tests/test_loki.py -v           # Audit logging
docker compose exec app pytest tests/test_rotation.py -v       # Secret rotation

# Run with coverage
docker compose exec app pytest tests/ --cov=. --cov-report=html

Test Coverage

Module Tests Coverage Area
test_anomaly.py Credential stuffing, impossible travel, brute-force escalation, risk scoring
test_auth.py Login, logout, token refresh, session management
test_auth_flow.py End-to-end authentication workflows
test_lockout.py Progressive lockout, permanent lock, exponential backoff
test_ztna.py Device ID enforcement, user-agent filtering, geo-allowlist
test_loki.py Log shipping, hash-chain integrity, structured events
test_rotation.py Certificate expiry warnings, secret age checks, health metrics
test_data_masking.py PII masking per role, unmask audit trail
test_sensors.py Sensor CRUD, bootstrap enrollment, certificate issuance
test_session_keycloak.py Idle/absolute timeouts, concurrent session limits
test_token_revocation.py JWT blacklisting, refresh token rotation
test_rate_limits.py Per-IP and per-token rate limiting
test_compose_security.py Docker Compose security configuration validation
test_security_regressions.py Regression tests for previously fixed vulnerabilities

πŸ“ Project Structure

NIDS/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py                    # FastAPI application entry point
β”‚   β”œβ”€β”€ config.py                  # Pydantic settings with env validation
β”‚   β”œβ”€β”€ database.py                # SQLAlchemy async engine & session
β”‚   β”œβ”€β”€ Dockerfile                 # Production container image
β”‚   β”œβ”€β”€ Dockerfile.dev             # Development image with hot-reload
β”‚   β”œβ”€β”€ requirements.txt           # Python dependencies
β”‚   β”œβ”€β”€ alembic/                   # Database migration scripts
β”‚   β”œβ”€β”€ models/                    # SQLAlchemy ORM models
β”‚   β”‚   β”œβ”€β”€ sensor.py              #   Sensor registration & metadata
β”‚   β”‚   β”œβ”€β”€ api_key.py             #   Bootstrap API key model
β”‚   β”‚   β”œβ”€β”€ audit_log.py           #   Audit log entries
β”‚   β”‚   └── audit_chain_state.py   #   Hash-chain state tracking
β”‚   β”œβ”€β”€ schemas/                   # Pydantic request/response schemas
β”‚   β”œβ”€β”€ routers/                   # API route handlers
β”‚   β”‚   β”œβ”€β”€ auth.py                #   Authentication endpoints
β”‚   β”‚   β”œβ”€β”€ sensors.py             #   Sensor management endpoints
β”‚   β”‚   β”œβ”€β”€ audit.py               #   Audit log queries
β”‚   β”‚   β”œβ”€β”€ health.py              #   Health & readiness probes
β”‚   β”‚   └── security.py            #   Anomaly & risk score endpoints
β”‚   β”œβ”€β”€ services/                  # Business logic layer
β”‚   β”‚   β”œβ”€β”€ anomaly_service.py     #   AI-driven anomaly detection engine
β”‚   β”‚   β”œβ”€β”€ keycloak_service.py    #   Keycloak admin API integration
β”‚   β”‚   β”œβ”€β”€ mtls_service.py        #   mTLS certificate operations
β”‚   β”‚   β”œβ”€β”€ crl_service.py         #   CRL refresh loop
β”‚   β”‚   β”œβ”€β”€ loki_service.py        #   Audit log shipping to Loki
β”‚   β”‚   β”œβ”€β”€ session_service.py     #   Redis session management
β”‚   β”‚   β”œβ”€β”€ lockout_service.py     #   Brute-force lockout logic
β”‚   β”‚   β”œβ”€β”€ rotation_service.py    #   Secret & cert rotation health
β”‚   β”‚   β”œβ”€β”€ infisical_service.py   #   Centralized secrets fetching
β”‚   β”‚   β”œβ”€β”€ sensor_service.py      #   Sensor data processing
β”‚   β”‚   β”œβ”€β”€ audit_service.py       #   Audit chain operations
β”‚   β”‚   └── token_revocation_service.py  # JWT blacklisting
β”‚   β”œβ”€β”€ middleware/                 # Request processing pipeline
β”‚   β”‚   β”œβ”€β”€ ztna.py                #   Zero Trust access enforcement
β”‚   β”‚   β”œβ”€β”€ audit.py               #   Request/response audit logging
β”‚   β”‚   β”œβ”€β”€ data_masking.py        #   PII field masking per role
β”‚   β”‚   └── rate_limit.py          #   Rate limiting configuration
β”‚   β”œβ”€β”€ dependencies/              # FastAPI dependency injection
β”‚   └── utils/                     # Shared utilities
β”œβ”€β”€ tests/                         # Comprehensive test suite (19 modules)
β”œβ”€β”€ keycloak/
β”‚   └── realm-export.json          # Pre-configured Keycloak realm
β”œβ”€β”€ loki/
β”‚   └── loki-config.yml            # Loki storage & retention config
β”œβ”€β”€ fail2ban/
β”‚   β”œβ”€β”€ jail.local                 # fail2ban jail configuration
β”‚   └── filter.d/                  # Custom filter rules
β”œβ”€β”€ k8s/
β”‚   └── linkerd-annotations.yml    # Kubernetes + Linkerd manifests
β”œβ”€β”€ secrets/                       # SOPS-encrypted secrets (gitignored)
β”œβ”€β”€ docker-compose.yml             # Base service definitions
β”œβ”€β”€ docker-compose.dev.yml         # Development overrides
β”œβ”€β”€ docker-compose.prod.yml        # Production overrides
β”œβ”€β”€ init-db.sql                    # Database initialization script
β”œβ”€β”€ auth-map.md                    # Authentication strategy documentation
β”œβ”€β”€ .env.example                   # Environment template
└── .gitignore

βš™οΈ Configuration Reference

All configuration is managed via environment variables with sensible defaults. See .env.example for the full list.

Key Configuration Groups

πŸ—„οΈ Database
Variable Default Description
DB_HOST mariadb Database hostname
DB_PORT 3306 Database port
DB_NAME nids Database name
DB_USER nids Database user
DB_PASSWORD β€” Database password (required)
πŸ” Keycloak
Variable Default Description
KEYCLOAK_URL http://keycloak:8080 Keycloak base URL
KEYCLOAK_REALM nids Realm name
KEYCLOAK_CLIENT_ID nids-api OIDC client ID
KEYCLOAK_CLIENT_SECRET β€” OIDC client secret (required)
πŸ€– Anomaly Detection
Variable Default Description
ANOMALY_DETECTION_ENABLED true Enable/disable anomaly engine
ANOMALY_WINDOW 3600 Sliding window in seconds
ANOMALY_FAILED_LOGIN_THRESHOLD 10 Failed logins before flagging
ANOMALY_OFF_HOURS_START 22 Off-hours start (24h)
ANOMALY_OFF_HOURS_END 6 Off-hours end (24h)
πŸ›‘οΈ ZTNA
Variable Default Description
ZTNA_ENABLED false Enable Zero Trust enforcement
ZTNA_REQUIRE_DEVICE_ID false Require device identity header
ZTNA_GEO_ALLOWLIST "" Comma-separated country codes
ZTNA_RISK_SCORE_THRESHOLD 70 Block if risk score β‰₯ this value
πŸ”„ Rotation & Certificates
Variable Default Description
ROTATION_CHECK_INTERVAL 3600 Health check interval (seconds)
CERT_EXPIRY_WARNING_DAYS 7 Days before cert expiry to warn
SECRET_MAX_AGE_DAYS 90 Max secret age before rotation alert
CERT_VALIDITY_DAYS 30 Sensor certificate validity period

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -m 'feat: add my feature'
  4. Push to the branch: git push origin feature/my-feature
  5. Open a Pull Request

Important

All contributions must include tests. Run the full test suite before submitting a PR.


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


Built with security-first principles β€’ Every layer verified β€’ Zero trust by default

About

Zero-trust network intrusion detection system with AI anomaly detection, mTLS, Keycloak SSO, and hash-chained audit logging

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages