urbanlotusai/arc-centralized-firewall-blueprint
GitHub: urbanlotusai/arc-centralized-firewall-blueprint
基于 Terraform 的 AWS 集中式网络安全蓝图,通过 Transit Gateway 和 Network Firewall 实现一次部署的中心辐射型流量检测架构。
Stars: 0 | Forks: 0
# ARC 集中式网络防火墙蓝图
### 使用 AWS Network Firewall 的中心辐射型网络 — 一次 `terraform apply` 搞定
**SourceFuse ARC 蓝图**





## 这是什么?
这是一个**即拿即用的 Terraform 蓝图**,它使用 **6 个 [SourceFuse ARC](https://registry.terraform.io/namespaces/modules/sourcefuse)
模块**,在 AWS 上构建集中式中心辐射型网络安全架构。一次 `terraform apply` 即可为您提供:
- 一个 **Hub(检查)VPC**,用于检查所有跨 VPC 和发往互联网的流量
- **AWS Network Firewall**,包含用于域名拦截和 IPS 的有状态 Suricata 规则
- **Transit Gateway**,用于连接各个辐射端 VPC 并通过 Hub 路由流量
- **KMS CMK**,用于加密所有防火墙告警日志和流日志
- **S3 日志存储桶**(通过 KMS 加密),支持自定义保留策略
- **Route53 私有托管区域**,用于在所有 VPC 之间进行集中式 DNS 解析
无需手动配置 Transit Gateway 路由表、防火墙策略关联或 S3 日志投递权限。这些复杂且容易出错的部分都已经解决并锁定。
## 为什么使用这个蓝图?
| 优势 | 对您意味着什么 |
|---|---|
| **几分钟,而不是几天** | 构建带有 Network Firewall 的生产级中心辐射型网络通常需要花几天时间编写网络 Terraform 代码 — 而本蓝图只需一条命令即可完成部署。 |
| **默认安全** | 所有防火墙告警和流日志在静态存储时均通过 KMS 加密。辐射端 VPC 无法直接通信 — 所有流量都必须经过检查点。 |
| **纵深防御** | 无状态规则用于快速允许/拒绝 + 有状态 Suricata 规则用于域名拦截、IPS 特征签名和 TLS SNI 检测。 |
| **代码化域名黑名单** | 在 `modules/04-network-firewall/tfvars/
.tfvars` 中传入要拦截的域名列表 — 系统会自动生成 Suricata IPS 规则。无需手动编辑规则。 |
| **全流量可视化** | 告警日志(被拦截/可疑流量)和流日志(所有流量)会发送到 S3。您可以使用 Athena 进行查询,或将其接入您的 SIEM。 |
| **可移植且可审计** | 纯 Terraform 代码。支持版本控制,可跨环境和账户复现。 |
| **对初学者友好** | 提供一个 `Makefile`、可直接复制粘贴的 tfvars 示例,以及适用于 macOS、Linux 和 Windows 的分步文档。 |
## 架构
```
Spoke VPC A ──┐
Spoke VPC B ──┼──► Transit Gateway (arc-transit-gateway)
Spoke VPC C ──┘ │
▼
Hub (Inspection) VPC (arc-network)
│
▼
AWS Network Firewall (arc-network-firewall)
├── Stateless: pass/drop/forward-to-SFE
└── Stateful (Suricata): domain blocking, IPS
│
▼
S3 Log Bucket (arc-s3, KMS-encrypted)
├── alert/ ← blocked + suspicious flows
└── flow/ ← all traffic flows
Route53 Private Zone (arc-route53)
└── centralized DNS for spoke resolution
```
所有辐射端 VPC 的出站流量和跨辐射端流量都会流经防火墙。各个辐射端之间绝不会直接进行路由或直接访问互联网。
## 6 个 ARC 模块
| 模块 | 版本 | 角色 |
|---|---|---|
| [arc-kms](https://registry.terraform.io/modules/sourcefuse/arc-kms/aws) | 1.0.11 | 客户管理密钥 (Customer Managed Key) — 加密所有防火墙日志 |
| [arc-s3](https://registry.terraform.io/modules/sourcefuse/arc-s3/aws) | 0.0.7 | KMS 加密的防火墙日志存储桶(告警 + 流日志) |
| [arc-network](https://registry.terraform.io/modules/sourcefuse/arc-network/aws) | 3.0.14 | 包含防火墙子网的 Hub(检查)VPC |
| [arc-network-firewall](https://registry.terraform.io/modules/sourcefuse/arc-network-firewall/aws) | 0.0.3 | AWS Network Firewall + 有状态/无状态策略 |
| [arc-transit-gateway](https://registry.terraform.io/modules/sourcefuse/arc-transit-gateway/aws) | 0.0.1 | 用于中心辐射型路由的 Transit Gateway |
| [arc-route53](https://registry.terraform.io/modules/sourcefuse/arc-route53/aws) | 0.0.1 | 集中式私有 DNS 解析 |
## 快速开始
### 1. 前置条件
- **Terraform** `>= 1.3`([安装指南](docs/INSTALL.md))
- 已配置 **AWS 凭证**(`aws configure`)
- 每个待接入的辐射端 VPC 的 **VPC ID、子网 ID 和路由表 ID**
### 2. 克隆
```
git clone https://github.com/urbanlotusai/arc-centralized-firewall-blueprint.git
cd arc-centralized-firewall-blueprint
```
本蓝图使用**相互独立的模块级 Terraform state** — 没有根目录 `main.tf`。每个 `modules/NN-name/` 都独立执行应用,模块间的取值(例如 Hub VPC ID 和日志存储桶名称)通过 `terraform_remote_state` 数据源解析,而不是通过父模块传递。
### 3. 初始化 state 后端(每个环境执行一次)
```
make bootstrap ENV=dev REGION=us-east-1 NAMESPACE=myorg
```
为每个模块的后端创建所需的 S3 state 存储桶 + DynamoDB 锁定表。
### 4. 部署所有模块
```
make apply ENV=dev REGION=us-east-1 NAMESPACE=myorg
```
此命令会按顺序对 `modules/01-kms` 到 `modules/06-route53` 执行 `terraform init` + `apply`。`spoke_vpc_id` 和 `spoke_subnet_ids` 变量默认为占位值 — 您可以直接修改 `modules/05-transit-gateway/tfvars/general.tfvars`,或者在运行时使用 `-var` 覆盖并传入您实际的辐射端 VPC 详细信息。
### 使用合规配置文件部署单个模块
```
./scripts/apply-module.sh 04-network-firewall dev us-east-1 hipaa
```
将 `modules/04-network-firewall/tfvars/hipaa.tfvars` 复制为该模块的 `terraform.tfvars`,然后单独对其进行 init/plan/apply。
| 步骤 | 使用 `make`(所有模块) | 单个模块 |
|---|---|---|
| 验证 | `make validate` | `cd modules/ && terraform validate` |
| 预览 | `make plan` | `./scripts/apply-module.sh ` 然后检查 plan |
| 部署 | `make apply` | `./scripts/apply-module.sh ` |
### 5. 更新辐射端路由表
应用部署后,通过 Transit Gateway 路由辐射端的出站流量:
```
TGW_ID=$(terraform output -raw transit_gateway_id)
aws ec2 create-route \
--route-table-id \
--destination-cidr-block 0.0.0.0/0 \
--transit-gateway-id $TGW_ID
```
### 6. 验证防火墙日志
```
aws s3 ls s3://$(cd modules/02-s3 && terraform output -raw bucket_id)/network-firewall/
# 你应该会在流量产生后的几分钟内看到 alert/ 和 flow/ 前缀出现
```
## 关键输出
每个模块的输出都位于其独立的 state 中 — 请在该 `modules/NN-name/` 目录下运行 `terraform output`:
```
cd modules/03-network && terraform output vpc_id # hub (inspection) VPC ID
cd modules/04-network-firewall && terraform output arn # AWS Network Firewall ARN
cd modules/04-network-firewall && terraform output policy_arn # firewall policy ARN
cd modules/05-transit-gateway && terraform output transit_gateway_id # TGW ID — add to spoke route tables
cd modules/05-transit-gateway && terraform output transit_gateway_arn
cd modules/02-s3 && terraform output bucket_id # S3 bucket name for firewall logs
cd modules/02-s3 && terraform output bucket_arn
cd modules/06-route53 && terraform output zone_id # private hosted zone ID
cd modules/01-kms && terraform output key_arn # CMK ARN
```
## 合规配置文件
| 配置文件 | 效果 |
|---|---|
| `general` | 开启 KMS 轮换,S3 日志保留 90 天 |
| `hipaa` | S3 防火墙日志保留 365 天 |
| `pci` | S3 防火墙日志保留 365 天 |
使用 `./scripts/apply-module.sh ` 将配置文件应用到任何模块。
## 项目结构
```
arc-centralized-firewall-blueprint/
├── bootstrap/ # creates the S3 + DynamoDB state backend (apply first)
│ ├── main.tf · variables.tf · outputs.tf
├── modules/ # each folder is an independent Terraform root
│ ├── 01-kms/
│ │ ├── config.hcl # static backend key
│ │ ├── main.tf # own backend "s3" {}, own provider, own module block
│ │ ├── variables.tf
│ │ ├── outputs.tf
│ │ └── tfvars/{general,hipaa,pci}.tfvars
│ ├── 02-s3/
│ ├── 03-network/
│ ├── 04-network-firewall/ # also owns the Suricata blocked-domains rule group
│ ├── 05-transit-gateway/
│ └── 06-route53/
├── scripts/
│ └── apply-module.sh # apply one module with a chosen compliance profile
├── Makefile # bootstrap / init / plan / apply / validate / fmt
├── .terraform-version # tfenv pin (1.9.8)
├── sample-app/ # verify.sh proving inspection traffic flows through the firewall
├── docs/
│ ├── INSTALL.md # macOS · Linux · Windows setup guide
│ └── DEPLOYMENT.md # full deployment reference + rollback
├── GETTING-STARTED.md # beginner walkthrough
├── CONTRIBUTING.md
├── CHANGELOG.md · LICENSE · NOTICE · VERSION
└── README.md
```
## 文档
- **[GETTING-STARTED.md](GETTING-STARTED.md)** — 面向新手的从零到上线完整指南
- **[docs/INSTALL.md](docs/INSTALL.md)** — 在 macOS / Linux / Windows 上安装 Terraform 和 AWS CLI
- **[docs/DEPLOYMENT.md](docs/DEPLOYMENT.md)** — 完整的部署、辐射端接入、规则更新和回滚说明
- **`modules/*/tfvars/{general,hipaa,pci}.tfvars`** — 各模块合规配置文件示例
## 重要说明
- **Terraform 不会更新辐射端路由表** — 部署应用完成后,您必须手动在每个辐射端 VPC 的路由表中添加一条 `0.0.0.0/0 → transit-gateway-id` 的路由。这是有意设计的,以避免引发意外的流量中断。
- **Network Firewall 大约需要 15 分钟才能变为 READY 状态** — 在将实际线上流量路由经过它之前,执行 `aws network-firewall describe-firewall --firewall-arn --query 'FirewallStatus.Status'` 应当返回 `"READY"`。
- **添加更多辐射端** — 要接入额外的辐射端,请添加第二个 `module "transit_gateway"` 样式的资源(或者在设置 `create_transit_gateway = false` 的情况下重新应用 `modules/05-transit-gateway`),并指向新辐射端的 VPC 详细信息。
- **被拦截的域名列表** — 在 `modules/04-network-firewall/tfvars/.tfvars` 中更新 `blocked_domains` 并重新应用该模块,即可原地更新 Suricata 规则组,且不会导致防火墙停机。该规则组资源现在位于 `modules/04-network-firewall/` 内部(它已从旧的根目录 `main.tf` 中移出,根目录文件现已不存在)。
- **销毁前请清空 S3 存储桶** — 如果 `force_destroy = false`(默认值),您必须在销毁 `modules/02-s3` 之前运行 `aws s3 rm s3:// --recursive`。
## 许可证
Apache License 2.0 — 详见 [LICENSE](LICENSE) 和 [NOTICE](NOTICE)。
### 由 [SourceFuse](https://www.sourcefuse.com) 构建
**ARC** (Accelerated Reference Cloud) 蓝图系列的一部分。
在 [Terraform Registry](https://registry.terraform.io/namespaces/modules/sourcefuse) 上探索所有 ARC 模块。
标签:AWS, DPI, ECS, Metaprompt, Terraform, 漏洞探索, 网络安全, 网络架构, 防火墙, 隐私保护