ChandraVerse/zero-trust-network-lab
GitHub: ChandraVerse/zero-trust-network-lab
这是一个基于 Keycloak、WireGuard 和 OPA 实现零信任网络架构并对其进行正式安全评估的综合实验室项目。
Stars: 0 | Forks: 0
🔒 零信任网络访问实现与评估实验室
以身份为中心的安全 · WireGuard 微分段 · OPA 策略执行 · 攻击面量化
📌 概述 · 🏗️ 架构 · 🔧 技术栈 · 📁 结构 · ⚡ 快速开始 · 🔑 Keycloak · 🔨 WireGuard · 📜 OPA · 📊 评估 · ⚠️ 道德与法律 · 🤝 贡献 · 📜 许可证
## 📌 项目概述 本项目在虚拟实验室网络中完全使用开源工具设计、实现并正式评估了一种**零信任网络访问 (ZTNA)** 架构。该实现摒弃了传统的“城堡护城河”边界模型,执行核心零信任原则:**从不信任,始终验证** —— 针对每个用户、设备和每个服务请求,无论其网络位置如何。 实验室结合了用于集中身份和访问管理的 **Keycloak**、用于网段加密微分的 **WireGuard**,以及用于细粒度基于属性策略执行的 **Open Policy Agent (OPA)**。项目以一份正式的**安全评估报告**结束,量化了零信任实施前后的攻击面缩减情况。 ### 为什么本项目很重要 | 受众 | 价值 | |---|---| | **企业安全工程师** | 使用生产级开源工具实现 ZTNA 的蓝图 | | **SOC 分析师** | 演示零信任如何减少横向移动的爆炸半径 | | **网络安全研究员** | 量化的攻击面对比,以及可衡量的安全改进 | | **云安全架构师** | 商业 ZTNA 产品 (Zscaler, Cloudflare Access) 的开源替代方案 | | **学生及有志于安全行业的工程师** | 动手实践实验室,演示 NIST SP 800-207 零信任原则的实际应用 | ### 实施的核心零信任原则 - ✅ **显式验证** — 使用 Keycloak 身份 + OPA 策略对每个请求进行身份验证和授权 - ✅ **使用最小权限访问** — 基于角色、设备、时间和风险信号的动态访问范围 - ✅ **假设已遭入侵** — 即使在失陷后,微分段网络也能限制横向移动 - ✅ **持续验证** — 短期 JWT token,在出现可疑信号时重新评估会话 - ✅ **设备信任** — WireGuard peer 证书将访问绑定到特定的受信任设备 ## 🏗️ 架构 ``` +------------------------------------------------------------------+ | IDENTITY PLANE | | | | +------------------+ +------------------+ | | | Keycloak IdP | | OPA Policy | | | | (OIDC / OAuth2) | | Engine | | | | JWT issuance | | Rego policies | | | | MFA enforcement | | ABAC decisions | | | +--------+---------+ +--------+---------+ | | | | | +------------+-----------------------+----------------------------+ | JWT token | policy decision (allow/deny) +------------v-----------+ +-----------v-----------+ | Policy Enforcement | | Application Gateway | | Point (PEP) | | (reverse proxy) | | Validates JWT + | | Enforces OPA result | | calls OPA for decision| +-----------+-----------+ +------------------------+ | | Authorized traffic only +---------------------------------------v--------------------------+ | DATA PLANE (WireGuard Mesh) | | | | +------------+ +------------+ +------------+ | | | Segment A | | Segment B | | Segment C | | | | Web Tier | | App Tier | | Data Tier | | | | 10.0.1.0/24| | 10.0.2.0/24| | 10.0.3.0/24| | | +------+------+ +------+------+ +------+------+ | | | | | | | +-------WireGuard Encrypted Tunnels-+ | | (cryptographic isolation between segments) | +------------------------------------------------------------------+ | OBSERVATION PLANE | | Suricata IDS . Zeek (network logs) . Wazuh SIEM | | OPA audit log . Keycloak event log . Prometheus metrics | +------------------------------------------------------------------+ BEFORE Zero Trust: Flat network, lateral movement possible AFTER Zero Trust: Each segment cryptographically isolated, every request identity-verified + policy-checked ``` ## 🔧 技术栈 | 层级 | 工具 | 版本 | 用途 | |---|---|---|---| | **身份提供者** | Keycloak | 24.x | OIDC/OAuth2, MFA, 用户联邦, JWT 签发 | | **微分段** | WireGuard | Kernel module | 加密网络分段, 点对点隧道 | | **策略引擎** | Open Policy Agent (OPA) | 0.63.x | 在每个访问点执行基于 Rego 的 ABAC 策略 | | **策略网关** | Nginx + OPA sidecar | Latest | 执行 OPA 策略决策的反向代理 | | **网络监控** | Suricata IDS | 7.x | 网络入侵检测, 基于规则的告警 | | **流量分析** | Zeek | 6.x | 详细的网络流日志和行为分析 | | **SIEM** | Wazuh | 4.x | 日志聚合, 关联, 告警管理 | | **指标** | Prometheus + Grafana | Latest | 实时网络和安全指标仪表板 | | **自动化** | Ansible | 2.16+ | 可复现的基础设施配置 | | **编排** | Docker + Docker Compose | Latest | 服务容器化 | | **实验室 VM** | VirtualBox / Proxmox | Latest | 多 VM 实验室拓扑 | | **脚本** | Python 3.10+ / Bash | — | 攻击面分析, 评估脚本 | | **操作系统** | Ubuntu Server 22.04 LTS | — | 所有实验室节点 | ## 📁 仓库结构 ``` zero-trust-network-lab/ | +-- infrastructure/ # Lab network provisioning | +-- ansible/ | | +-- playbooks/ | | | +-- provision_nodes.yml # Provision all lab VMs | | | +-- deploy_wireguard.yml # WireGuard mesh configuration | | | +-- deploy_keycloak.yml # Keycloak IdP deployment | | | +-- deploy_opa.yml # OPA sidecar deployment | | +-- inventory/ | | +-- lab_hosts.ini # Lab VM inventory | +-- terraform/ # Optional cloud lab variant | +-- main.tf | +-- identity/ # Keycloak configuration | +-- realm-export.json # Keycloak realm export (users, roles, clients) | +-- clients/ # OIDC client configurations | +-- mfa_policy.md # MFA enforcement policy docs | +-- network/ # WireGuard micro-segmentation | +-- configs/ | | +-- wg-segment-a.conf # Segment A (web tier) config | | +-- wg-segment-b.conf # Segment B (app tier) config | | +-- wg-segment-c.conf # Segment C (data tier) config | +-- topology.md # Network topology documentation | +-- firewall_rules/ | +-- nftables_baseline.conf # Host-level firewall rules | +-- policies/ # OPA Rego policies | +-- authz/ | | +-- access_control.rego # Core ABAC access control policy | | +-- device_trust.rego # Device posture evaluation | | +-- time_based_access.rego # Time-of-day access restrictions | | +-- risk_score.rego # Dynamic risk-based access decisions | +-- tests/ | | +-- access_control_test.rego # OPA policy unit tests | +-- policy_docs.md # Plain-language policy documentation | +-- gateway/ # Policy enforcement point | +-- nginx.conf # Reverse proxy with OPA integration | +-- opa_sidecar.yml # OPA sidecar Docker config | +-- monitoring/ # Observation plane | +-- suricata/ | | +-- suricata.yaml | | +-- custom_rules/ztna_rules.rules # Custom Suricata ZTNA detection rules | +-- zeek/ | | +-- local.zeek | +-- wazuh/ | | +-- custom_decoders.xml | | +-- ztna_rules.xml | +-- grafana/ | +-- dashboards/ztna_overview.json # Grafana Zero Trust metrics dashboard | +-- evaluation/ # Security evaluation research | +-- pre_zt_assessment/ | | +-- network_scan_results/ # Nmap scans of flat network | | +-- attack_path_analysis.md # Lateral movement paths before ZT | | +-- attack_surface_metrics.csv # Quantified attack surface baseline | +-- post_zt_assessment/ | | +-- network_scan_results/ # Post-implementation scans | | +-- attack_path_analysis.md # Residual attack paths after ZT | | +-- attack_surface_metrics.csv # Post-implementation metrics | +-- attack_simulations/ | | +-- lateral_movement_test.md # Lateral movement test methodology | | +-- credential_stuffing_test.md # Credential attack simulation | +-- evaluation_report/ | +-- zero_trust_evaluation.pdf # Formal IEEE-format security evaluation | +-- zero_trust_evaluation.md # Source markdown | +-- scripts/ # Automation and analysis scripts | +-- attack_surface_analyzer.py # Quantify open ports / exposed services | +-- opa_policy_tester.py # Automated OPA policy test runner | +-- jwt_validator.py # Keycloak JWT token validator | +-- docker-compose.yml # Full lab stack (Keycloak + OPA + Nginx + Monitoring) +-- config.yml # Central lab configuration +-- .env.example # Environment variable template +-- CONTRIBUTING.md +-- LICENSE +-- README.md ``` ## ⚡ 快速开始 ### 前置条件 - 支持虚拟化的 **Linux 主机** (推荐 Ubuntu 22.04) - 用于多 VM 实验室拓扑的 **VirtualBox** 或 **Proxmox** - **Docker & Docker Compose v2** - **Python 3.10+** 和 **Ansible 2.16+** - **WireGuard** 内核模块 (包含在 Linux 内核 >= 5.6 中) - 最低硬件要求:**16 GB RAM**, **4 CPU 核心**, **60 GB 磁盘** ### 步骤 1 — 克隆仓库 ``` git clone https://github.com/ChandraVerse/zero-trust-network-lab.git cd zero-trust-network-lab ``` ### 步骤 2 — 配置环境 ``` cp .env.example .env nano .env ``` ``` # Keycloak KEYCLOAK_ADMIN=admin KEYCLOAK_ADMIN_PASSWORD=
由 Chandra Sekhar Chakraborty 用 🔒 制作
安全运营 · 零信任研究员 · 有志于 SOC 分析师
🌐 作品集 ·
💻 GitHub ·
🔗 LinkedIn
如果这个实验室对您有帮助,请考虑给它一个 ⭐
标签:DevSecOps, Keycloak, Metaprompt, NIST SP 800-207, OPA, Python, Streamlit, VPN, WireGuard, 上游代理, 单点登录, 安全合规, 安全实验室, 安全评估报告, 微分段, 攻击面评估, 无后门, 策略即代码, 系统提示词, 网络代理, 网络安全, 网络隔离, 聊天机器人安全, 自定义请求头, 访问控制, 请求拦截, 逆向工具, 隐私保护, 零信任架构, 靶场