kua-University/Security-Intelligence-Threat-detection-system12
GitHub: kua-University/Security-Intelligence-Threat-detection-system12
一套基于 Docker 容器化部署的安全智能威胁检测系统,涵盖前后端应用、监控告警及完整的 DevSecOps 流水线。
Stars: 0 | Forks: 0
# SITDS - 安全智能威胁检测系统
### 生产环境 DevOps 架构
## 项目结构
```
sitds/
├── backend/ # Node.js/Express API
│ ├── Dockerfile # Multi-stage production build
│ ├── .dockerignore
│ ├── package.json # Pinned deps + helmet, winston, rate-limit
│ ├── server.js # Hardened Express server
│ └── db.js # MySQL pool (env-var driven)
│
├── frontend/ # Static HTML/CSS/JS
│ ├── Dockerfile # Nginx static server
│ ├── .dockerignore
│ ├── nginx-frontend.conf # SPA serving config
│ ├── index.html
│ ├── style.css
│ └── script.js
│
├── nginx/ # Reverse proxy
│ ├── Dockerfile
│ └── nginx.conf # HTTPS, rate limiting, security headers
│
├── monitoring/ # Observability stack
│ ├── prometheus.yml # Scrape config
│ └── grafana/provisioning/ # Auto-provisioned datasource
│
├── scripts/
│ ├── deploy.sh # One-command deployment
│ ├── setup-server.sh # Ubuntu server bootstrap
│ ├── generate-ssl.sh # Self-signed cert generator
│ ├── logs.sh # Log viewer shortcut
│ └── init.sql # DB schema (auto-runs on first start)
│
├── .github/workflows/
│ └── ci-cd.yml # Full CI/CD: lint→SAST→build→scan→deploy
│
├── docker-compose.yml # Development stack
├── docker-compose.prod.yml # Production overrides (limits, replicas)
├── .env.example # Template — copy to .env
├── .gitignore
├── ARCHITECTURE.md
└── SECURITY_CHECKLIST.md
```
## 快速开始 (Windows/本地开发)
### 1. 前置条件
- 已安装并运行 [Docker Desktop](https://www.docker.com/products/docker-desktop/)
### 2. 克隆并配置
```
git clone
cd sitds
# 复制并填写 environment variables
cp .env.example .env
# 编辑 .env — 更改所有 CHANGE_ME 值
```
### 3. 生成 SSL 证书 (仅限开发环境)
```
bash scripts/generate-ssl.sh
```
### 4. 启动所有服务
```
docker compose up -d --build
```
### 5. 访问应用
| 服务 | URL |
|-----------|------------------------------|
| Dashboard | https://localhost |
| API | https://localhost/api/health |
| Grafana | http://localhost:3001 |
## 生产环境部署 (Ubuntu 服务器)
### 1. 初始化服务器 (以 root 用户运行一次)
```
sudo bash scripts/setup-server.sh
```
这将安装 Docker,配置 UFW 防火墙、Fail2Ban 并进行内核加固。
### 2. 克隆仓库并配置
```
cd /opt/sitds
git clone .
cp .env.example .env
nano .env # fill in all values
```
### 3. 获取正式的 SSL 证书
```
# 安装 certbot
sudo apt install certbot -y
sudo certbot certonly --standalone -d yourdomain.com
# 复制 certs
sudo cp /etc/letsencrypt/live/yourdomain.com/fullchain.pem nginx/ssl/cert.pem
sudo cp /etc/letsencrypt/live/yourdomain.com/privkey.pem nginx/ssl/key.pem
```
### 4. 部署
```
bash scripts/deploy.sh
```
### 5. 生产模式 (带资源限制)
```
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
```
## CI/CD 流水线 (GitHub Actions)
将以下 secrets 添加到你的 GitHub 仓库 (Settings → Secrets):
| Secret | 值 |
|------------------|------------------------------------|
| `DEPLOY_HOST` | 你的服务器 IP 或域名 |
| `DEPLOY_USER` | SSH 用户名 (例如 `ubuntu`) |
| `DEPLOY_SSH_KEY` | SSH 私钥 (RSA/ED25519) |
| `DEPLOY_PORT` | SSH 端口 (默认: 22) |
每次推送到 `main` 分支时的流水线阶段:
1. `lint` — npm audit (遇到 HIGH/CRITICAL CVEs 时失败)
2. `security-scan` — Gitleaks (机密信息) + Semgrep (SAST)
3. `build` — Docker 多阶段构建 + 推送到 GHCR
4. `vulnerability-scan` — Trivy 扫描构建的镜像
5. `deploy` — SSH 部署到生产服务器
## 常用命令
```
# 查看所有 logs
bash scripts/logs.sh
# 查看特定 service logs
bash scripts/logs.sh backend
bash scripts/logs.sh nginx
bash scripts/logs.sh mysql
# 检查 service health
docker compose ps
# 重启 service
docker compose restart backend
# 停止一切
docker compose down
# 停止并移除 volumes (警告: 删除 DB 数据)
docker compose down -v
```
## 安全说明
- 所有凭据均在 `.env` 文件中——切勿提交该文件
- 数据库位于隔离的内部 Docker 网络中
- Nginx 是唯一暴露了端口的容器
- 完整的 DevSecOps 检查清单请参阅 `SECURITY_CHECKLIST.md`
**作者:** Abel Tesfay | ugr/187803/16 | 软件架构与设计
标签:API集成, DevSecOps, Docker, Docker Compose, Express, GitHub Advanced Security, GNU通用公共许可证, Grafana, Helmet, HTTPS, MITM代理, Nginx, NIDS, Node.js, OISF, SAST, Shell脚本, SITDS, SSL证书, Winston, 上游代理, 反向代理, 可观测性, 威胁检测系统, 安全加固, 安全响应头, 安全智能, 安全检查清单, 安全运营, 安全防御评估, 容器化, 开源框架, 扫描框架, 持续交付, 持续集成, 数据可视化, 数据库, 日志管理, 特权提升, 生产架构, 监控告警, 盲注攻击, 自动化部署, 自定义脚本, 自定义请求头, 请求拦截, 调试辅助, 负载均衡, 静态应用安全测试, 静态网站