mrzasad/complianceShield-pro
GitHub: mrzasad/complianceShield-pro
面向受监管企业的端到端数据合规管道工具,自动拦截数据流并对照 GDPR 和 PECA 框架进行实时审计、PII 加密与审计日志生成。
Stars: 0 | Forks: 0
# 🛡️ ComplianceShield — PECA/GDPR 数据管道
一个生产级 **Streamlit 应用程序**,用于拦截原始数据,并对照 **PECA 2016**(巴基斯坦电子犯罪法)和 **GDPR** 合规框架对其进行审计,对敏感 PII 字段进行加密,并生成不可变的结构化审计日志。
## 架构
```
Raw Data Source
│
▼
┌──────────────────────────────────────────────────────────┐
│ Stage 1 · INTERCEPT │
│ DataInterceptor — SHA-256 checksum, batch ID, metadata │
└──────────────────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────┐
│ Stage 2 · AUDIT (GDPR + PECA) │
│ ComplianceAuditor — PII detection, rule matching, │
│ violation scoring, CRITICAL/HIGH/MEDIUM/LOW risk rating │
└──────────────────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────┐
│ Stage 3 · ENCRYPT │
│ DataEncryptor — AES-256-GCM (or Fernet / RSA-OAEP+AES) │
│ All PII fields replaced with ENC: │
└──────────────────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────┐
│ Stage 4 · LOG │
│ ComplianceLogger — append-only JSON structured log, │
│ exportable as JSON Lines (SIEM) or CSV │
└──────────────────────────────────────────────────────────┘
```
## 合规框架
### GDPR
| 规则 ID | 条款 | 字段 | 风险 |
|---------|---------|-------|------|
| GDPR-ART25-001 | Art. 25 – 数据最小化 | national_id | 高 |
| GDPR-ART32-001 | Art. 32 – 处理安全 | credit_card | 严重 |
| GDPR-ART35-001 | Art. 35 – 需要 DPIA | dob | 中 |
| GDPR-ART5-001 | Art. 5 – 目的限制 | ip_address | 中 |
| GDPR-ART5-002 | Art. 5 – 合法性 | email | 中 |
### PECA 2016
| 规则 ID | 条款 | 字段 | 风险 |
|---------|---------|-------|------|
| PECA-SEC14-001 | Sec. 14 – 身份信息 | national_id | 高 |
| PECA-SEC18-001 | Sec. 18 – 数据保护 | phone | 中 |
| PECA-SEC34-001 | Sec. 34 – 尊严/隐私 | dob | 低 |
| PECA-SEC14-002 | Sec. 14 – 身份信息 | credit_card | 严重 |
## 加密
| 算法 | 密钥长度 | 模式 | 备注 |
|-----------|----------|------|-------|
| AES-256-GCM | 256位 | 认证 | 默认 — 推荐 |
| Fernet (AES-128-CBC) | 128位 | HMAC-SHA256 | 简单对称加密 |
| RSA-OAEP + AES | 2048位 RSA + 256位 AES | 混合 | 密钥封装 |
加密值格式:`ENC:`
## 快速开始
### 本地运行 (Python)
```
pip install -r requirements.txt
streamlit run app.py
```
### Docker
```
docker compose up --build
# 打开 http://localhost:8501
```
### Docker (手动)
```
docker build -t complianceshield .
docker run -p 8501:8501 complianceshield
```
## 生产环境扩展
### Apache Spark
将 `DataInterceptor.intercept()` 替换为 PySpark 作业:
```
spark = SparkSession.builder.appName("ComplianceShield").getOrCreate()
df = spark.read.json("s3a://raw-data/landing/")
df = df.rdd.mapPartitions(compliance_audit_udf).toDF()
df.write.format("delta").mode("append").save("s3a://processed/compliant/")
```
### Apache Airflow DAG
```
from airflow import DAG
from airflow.operators.python import PythonOperator
with DAG("compliance_pipeline", schedule="@hourly") as dag:
ingest = PythonOperator(task_id="ingest", python_callable=intercept)
audit = PythonOperator(task_id="audit", python_callable=audit_records)
encrypt = PythonOperator(task_id="encrypt", python_callable=encrypt_fields)
log_task = PythonOperator(task_id="log", python_callable=write_audit_log)
ingest >> audit >> encrypt >> log_task
```
### 密钥管理(生产环境)
- 将 AES 密钥存储在 **Azure Key Vault** 或 **AWS KMS** 中
- 实施每 90 天自动密钥轮换
- 使用**硬件安全模块 (HSM)**存储 RSA 私钥
- 将所有密钥访问事件记录到合规审计跟踪中
## 文件结构
```
compliance_pipeline/
├── app.py # Streamlit UI
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── README.md
└── pipeline/
├── __init__.py `
├── interceptor.py # Stage 1: Data interception + checksums
├── auditor.py # Stage 2: GDPR/PECA rule engine
├── encryptor.py # Stage 3: AES-256-GCM encryption
├── logger.py # Stage 4: Structured audit logging
└── spark_engine.py # Spark/Airflow execution simulation
```
标签:GDPR, Kubernetes, Streamlit, 审计日志, 数据加密, 数据合规, 网络安全, 访问控制, 请求拦截, 逆向工具, 隐私保护