ynotbhatc/rego_policy_libraries
GitHub: ynotbhatc/rego_policy_libraries
该仓库提供 461 条开箱即用的 OPA Rego v1 策略,覆盖 50 多项主流合规框架与 22 个平台,帮助团队快速实现自动化的合规检查与策略执行。
Stars: 11 | Forks: 0
# Rego 策略库
[](LICENSE)
[](https://www.openpolicyagent.org/)
[](https://www.openpolicyagent.org/docs/latest/policy-language/)
[-brightgreen)](benchmarks/cis/os/linux/rhel_9/)
[](https://github.com/ynotbhatc/rego_policy_libraries/stargazers)
## 为什么选择这个仓库?
从头开始编写合规策略既昂贵又容易出错。一个典型的企业仅为了 CIS RHEL 9 部署 OPA 就需要 338 项单独的控制检查——这还仅仅是一个操作系统的一个框架。
这个库为您提供了**第一天即可投入使用的、完整且有效的策略集**,涵盖 22 个平台、50 多个监管框架,以及从 CIS 和 DISA STIG 到 NERC-CIP 及 IEC 62443 的所有主要合规标准。所有策略:
- 使用 **Rego v1 语法**(`import rego.v1`)—— 无弃用警告,向前兼容
- 返回**结构化的 JSON 报告**(合规、得分、违规项列表)—— 可直接对接仪表板或 CI
- **支持独立加载** —— 使用一个框架或全部 505 个策略均可;无耦合
- 采用 **Apache 2.0 许可协议** —— 商业使用不受限制
## 覆盖范围一览
| 标准 / 框架 | 路径 | 控制 / 要求项 |
|---------------------|------|------------------------|
| **CIS RHEL 9 v2.0.0** | `benchmarks/cis/os/linux/rhel_9/` | **338/338 (100%)** ✅ |
| CIS RHEL 8 | `benchmarks/cis/os/linux/rhel_8/` | 完整 |
| CIS Ubuntu 22.04/24.04/20.04 | `benchmarks/cis/os/linux/ubuntu_*/` | 完整 |
| CIS Windows Server 2019/2022 | `benchmarks/cis/os/windows/` | 9 个部分 |
| CIS AWS / Azure / GCP | `benchmarks/cis/cloud/` | 基础 |
| CIS Docker / Kubernetes / OpenShift | `benchmarks/cis/containers/` | 完整 |
| DISA STIG RHEL 8/9, Ubuntu, Windows, OpenShift 4, Kubernetes | `benchmarks/stig/` | 完整 |
| NIST 800-53 rev5 | `frameworks/federal/nist_800_53/` | 所有控制系列 |
| NIST 800-82 (OT) | `frameworks/federal/nist_800_82/` | 完整 |
| FISMA / FedRAMP / CMMC | `frameworks/federal/` | 完整 |
| ISO 27001:2022 | `frameworks/management/iso27001/` | 完整 ISMS |
| SOC 2 Type II | `frameworks/management/soc2/` | 所有 TSC |
| PCI-DSS v4.0 | `frameworks/financial/pci_dss/` | 所有 12 项要求 |
| SOX ITGC | `frameworks/financial/sox/` | 完整 |
| HIPAA | `frameworks/privacy/hipaa/` | 完整 |
| GDPR | `frameworks/privacy/gdpr/` | 完整 |
| NERC-CIP (CIP-002 – CIP-015) | `frameworks/critical_infrastructure/nerc_cip/` | 14 项标准 |
| IEC 62443 (所有部分) | `frameworks/critical_infrastructure/iec_62443/` | 51 项 SR,SL 1–4 |
| NIST IR 7628 (AMI / 智能电网) | `frameworks/critical_infrastructure/ami/` | 完整 |
| DORA / NIS2 | `frameworks/regulatory/` | 完整 |
| NCSC CAF 4.0 | `frameworks/management/ncsc_caf/` | 23 项网络成果 |
| 数字主权 | `frameworks/sovereignty/` | 7 个领域 |
| **CSA CCM v4.0** | `frameworks/management/csa_ccm/` | 16 个领域,197 项控制 |
| **ISO/IEC 27701:2019** | `frameworks/privacy/iso27701/` | PIMS, PII 控制者, PII 处理者, DSR |
| **NIST SP 800-171 Rev 3** | `frameworks/federal/nist/sp_800_171/` | 14 个系列,110 项 CUI 要求 |
| **CCPA / CPRA** | `frameworks/privacy/ccpa/` | 消费者权利,敏感 PI,数据实践 |
| **EU AI Act (2024/1689)** | `governance/eu_ai_act/` | 禁止,高风险,透明度,GPAI,治理 |
## 开箱即用的内容
| 领域 | 策略 | 覆盖范围 |
|--------|----------|----------|
| **CIS Benchmarks + DISA STIGs** | 246 | 22 个平台:Linux, Windows, 云,容器,数据库,网络 + RHEL 8/9 及 Windows 2022 STIGs。CIS benchmark 版本已更新至 2026 年 5 月发布版本;针对高价值目标(RHEL 9, Ubuntu 22.04, Windows Server 2022)提供**二级(Level 2)安全加固配置** |
| **监管框架** | 186 | ISO 27001, SOC 2, PCI-DSS, SOX, FISMA, FedRAMP, CMMC, GDPR, HIPAA, NERC-CIP, IEC 62443, DORA, NIS2, NY DFS, SEC Cyber, SWIFT CSP, HITRUST, TISAX, CFR Part 11, NCSC CAF, 数字主权, CSA CCM v4.0, ISO 27701, NIST SP 800-171 r3, CCPA/CPRA |
| **执行** | 9 | Ansible, Terraform, Dockerfile, Kubernetes 准入控制, Git 批准/剧本文档,**CI/CD 流水线门控**,**SLSA 供应链治理** |
| **治理** | 19 | AI 代理授权,MCP 工具调用强制执行,GEISA (API/ADM/LEE/VEE),**EU AI Act (法规 2024/1689)** 套件,**OIDC token 验证**,**FinOps 标签** |
| **威胁检测** | 1 | 加密货币挖矿程序检测 |
**亮点:** CIS RHEL 9 v2.0.0 —— 横跨 14 个模块,涵盖 **338/338 项控制 (100%)**。
## 快速开始
### 选项 A — OCI bundle(生产环境推荐)
直接从 GitHub Container Registry 拉取预构建的 bundle —— 无需克隆:
```
# 拉取完整的 505-policy bundle
oras pull ghcr.io/ynotbhatc/rego_policy_libraries:latest
# 使用 bundle 启动 OPA
podman run -d --name opa -p 8181:8181 \
-v "$(pwd)/bundle.tar.gz:/bundle.tar.gz:ro" \
openpolicyagent/opa:1.10.0 run --server --addr :8181 --bundle /bundle.tar.gz
```
提供带版本号的标签:`ghcr.io/ynotbhatc/rego_policy_libraries:v1.0.0`
安装 `oras`:https://oras.land/docs/installation
### 选项 B — Git clone
```
# Clone
git clone https://github.com/ynotbhatc/rego_policy_libraries.git
cd rego_policy_libraries
# 启动 OPA
podman run -d --name opa -p 8181:8181 openpolicyagent/opa run --server --addr :8181
# 加载所有 CIS RHEL 9 policies
for f in benchmarks/cis/os/linux/rhel_9/*.rego; do
curl -s -X PUT --data-binary @"$f" \
"http://localhost:8181/v1/policies/$(basename $f .rego)"
done
# 根据你的系统 facts 进行评估
curl -s -X POST http://localhost:8181/v1/data/cis_rhel9/compliance_assessment \
-H 'Content-Type: application/json' \
-d '{"input": {"os_family": "RedHat", ...}}'
```
## 策略分类
```
rego_policy_libraries/
├── benchmarks/ # Technical security baselines
│ ├── cis/
│ │ ├── os/linux/ # RHEL 8/9/10, Ubuntu 20/22/24, Debian, Rocky, Amazon Linux
│ │ ├── os/windows/ # Windows Server 2016/2019/2022, Windows 10/11
│ │ ├── cloud/ # AWS, Azure, GCP Foundations
│ │ ├── containers/ # Docker, Kubernetes, OpenShift
│ │ ├── databases/ # MySQL 8, Oracle 19c, PostgreSQL 13/14/15
│ │ ├── web_servers/ # Apache 2.4, Nginx 1.20
│ │ └── network/ # Cisco IOS, Juniper Junos, Palo Alto, Fortinet, Arista
│ └── stig/ # DISA STIGs — RHEL 8/9, Ubuntu, Windows
│
├── frameworks/ # Regulatory compliance
│ ├── federal/ # NIST 800-53/171/800-82, CSF 2.0, AI RMF, FISMA, FedRAMP, CMMC
│ ├── management/ # ISO 27001, SOC 2, Corporate, NCSC CAF 4.0
│ ├── financial/ # PCI-DSS, SOX, SWIFT CSP, NY DFS, SEC Cyber
│ ├── privacy/ # GDPR, HIPAA, HITRUST, CFR Part 11, TISAX
│ ├── regulatory/ # DORA, NIS2
│ ├── critical_infrastructure/ # NERC-CIP (CIP-002–CIP-015), IEC 62443, NIST IR 7628
│ └── sovereignty/ # Digital Sovereignty (7 domains)
│
├── enforcement/ # Gate-style policy enforcement
│ ├── ansible/ # Block non-compliant playbooks at check-in and runtime
│ ├── terraform/ # Validate plans before apply
│ ├── dockerfile/ # Lint Dockerfiles at build time
│ ├── kubernetes/ # Admission control for K8s manifests
│ ├── git/ # Approval and playbook-documentation policies
│ ├── cicd/ # CI/CD pipeline gating
│ └── supply_chain/ # SLSA-style supply-chain governance
│
├── governance/ # AI and operational governance
│ ├── ai/ # AI agent action classification and authorization
│ ├── mcp/ # MCP server tool-call enforcement
│ ├── eu_ai_act/ # EU AI Act (Regulation 2024/1689) — prohibited, high-risk, GPAI, transparency
│ ├── geisa/ # GEISA runtime compliance (API, ADM, LEE, VEE)
│ ├── oidc/ # OIDC token validation for portal/MCP access control
│ └── finops/ # Resource tagging policies
│
└── threat_detection/
└── crypto_mining/ # Detect unauthorized cryptocurrency miners
```
## CIS Benchmark 覆盖范围
| 平台 | 路径 | 控制项 |
|----------|------|----------|
| **RHEL 9** | `benchmarks/cis/os/linux/rhel_9/` | **338/338 (100%)** ✅ |
| RHEL 8 | `benchmarks/cis/os/linux/rhel_8/` | 完整 |
| Ubuntu 22.04 | `benchmarks/cis/os/linux/ubuntu_22_04/` | 完整 |
| Ubuntu 20.04 / 24.04 | `benchmarks/cis/os/linux/ubuntu_20_04/` | 完整 |
| Debian 11 | `benchmarks/cis/os/linux/debian_11/` | 完整 |
| Rocky Linux 8 / 9 | `benchmarks/cis/os/linux/rocky_linux_8/` | 完整 |
| Amazon Linux 2023 | `benchmarks/cis/os/linux/amazon_linux_2023/` | 完整 |
| Windows Server 2019/2022 | `benchmarks/cis/os/windows/` | 模块化(9 个部分) |
| AWS / Azure / GCP | `benchmarks/cis/cloud/` | 基础 |
| Docker / Kubernetes / OpenShift | `benchmarks/cis/containers/` | 完整 |
| MySQL / Oracle / PostgreSQL | `benchmarks/cis/databases/` | 完整 |
| Cisco / Juniper / Palo Alto / Fortinet / Arista | `benchmarks/cis/network/` | 完整 |
## IEC 62443 覆盖范围
用于 IEC 62443 工业自动化和控制系统 (IACS) 安全的完整库 —— 包含第 3-3 部分中的全部 51 项系统要求 (SRs) 以及第 2 部分的管理要求。
| 文件 | 部分 | 标题 | SRs |
|------|------|-------|-----|
| `fr1_identification_authentication.rego` | 3-3 FR 1 | 识别与认证控制 (IAC) | SR 1.1–1.13 (13) |
| `fr2_use_control.rego` | 3-3 FR 2 | 使用控制 (UC) | SR 2.1–2.12 (12) |
| `fr3_system_integrity.rego` | 3-3 FR 3 | 系统完整性 (SI) | SR 3.1–3.9 (9) |
| `fr4_data_confidentiality.rego` | 3-3 FR 4 | 数据机密性 (DC) | SR 4.1–4.3 (3) |
| `fr5_restricted_data_flow.rego` | 3-3 FR 5 | 受限数据流 / 区域与管道 (RDF) | SR 5.1–5.4 (4) |
| `fr6_timely_response.rego` | 3-3 FR 6 | 事件及时响应 (TRE) | SR 6.1–6.2 (2) |
| `fr7_resource_availability.rego` | 3-3 FR 7 | 资源可用性 (RA) | SR 7.1–7.8 (8) |
| `part2_security_management.rego` | 2-1 | 安全管理系统 (CSMS) | — |
| `part2_patch_management.rego` | 2-3 | IACS 环境中的补丁管理 | — |
| `part2_service_provider.rego` | 2-4 | IACS 服务提供商安全计划 (SP.01–SP.10) | — |
| `part3_risk_assessment.rego` | 3-2 | 安全风险评估 (ZCR 1–5) | — |
| `iec_62443_main.rego` | 所有 | 主要协调器 —— 汇总所有部分 | 总计 51 |
**安全等级 (SL) 分层:** 所有 FR 模块均强制执行区分 SL 级别的要求 —— 违规项会标记其适用的 SL(从 SL 1 基准到 SL 4 针对国家级黑客威胁的防护)。
**OPA endpoint:** `POST /v1/data/iec_62443_main/iec_62443_compliance_report`
```
{
"standard": "IEC 62443",
"target_sl": 2,
"compliant": false,
"fr_compliance_score": 71,
"sr_compliance_score": 84,
"passing_frs": 5,
"total_frs": 7,
"passing_srs": 43,
"total_srs": 51,
"part3_3_foundational_requirements": {
"FR1_identification_authentication": { "compliant": true, "passing_srs": 13 },
"FR5_restricted_data_flow": { "compliant": false, "violations": ["..."] }
}
}
```
## NERC-CIP 覆盖范围
涵盖 `frameworks/critical_infrastructure/nerc_cip/` 中所有活跃 CIP 标准(CIP-002 到 CIP-015)的完整库。
**OPA endpoint:** `POST /v1/data/nerc_cip_main`
**数据源:** 14 个 CIP 策略使用的每个 `input.*` 字段均记录在 [`frameworks/critical_infrastructure/nerc_cip/DATA_SOURCES.md`](frameworks/critical_infrastructure/nerc_cip/DATA_SOURCES.md) 中 —— 每个条目列出了现实世界中的源系统(GRC、CMDB、LMS、PACS、SIEM、INSM 平台、漏洞扫描器等)、收集方法(Ansible 模块或 REST endpoint),以及该集成目前是已启用还是处于测试状态。
## 将策略加载到 OPA
### 单个策略
```
curl -X PUT --data-binary @benchmarks/cis/os/linux/rhel_9/pam_validation.rego \
http://localhost:8181/v1/policies/cis_rhel9_pam
```
### 目录中的所有策略
```
for f in benchmarks/cis/os/linux/rhel_9/*.rego; do
curl -s -X PUT --data-binary @"$f" \
"http://localhost:8181/v1/policies/$(basename $f .rego)"
done
```
### 推荐的 3 容器模式(领域隔离)
```
# Security benchmarks (CIS, NIST, DISA STIGs)
podman run -d --name opa-security -p 8181:8181 openpolicyagent/opa run --server --addr :8181
# Regulatory frameworks (ISO 27001, SOC 2, PCI-DSS, SOX, FISMA, GDPR, HIPAA)
podman run -d --name opa-compliance -p 8182:8182 openpolicyagent/opa run --server --addr :8182
# OT / Critical infrastructure (NERC-CIP, IEC 62443, NIST IR 7628, AMI)
podman run -d --name opa-ot -p 8183:8183 openpolicyagent/opa run --server --addr :8183
```
将 `benchmarks/` 加载到 `:818`,将 `frameworks/`(减去 critical_infrastructure)加载到 `:8182`,将 `frameworks/critical_infrastructure/` + `governance/` 加载到 `:8183`。
## 输入 / 输出契约
每个策略都暴露一个 `compliance_assessment` 规则,该规则接受系统事实作为输入并返回结构化报告:
```
{
"compliant": false,
"summary": {
"total_controls": 338,
"passing_controls": 301,
"failing_controls": 37,
"compliance_percentage": 89.05,
"overall_compliance": "FAIL"
},
"violations": [
"1.1.1 Ensure mounting of cramfs filesystems is disabled",
"5.2.4 Ensure SSH X11 forwarding is disabled"
],
"section_compliance": {
"1_filesystem": true,
"2_services": false,
...
}
}
```
## 作为 Git Submodule 使用
```
# 添加到你的项目
git submodule add https://github.com/ynotbhatc/rego_policy_libraries.git policies
git submodule update --init --recursive
# 更新到最新版本
git submodule update --remote policies
git add policies && git commit -m "Update policy library"
```
## 要求
- [Open Policy Agent](https://www.openpolicyagent.org/) v0.60+
- 所有策略均使用 `import rego.v1` (Rego v1 语法)
## Ansible 自动化合规 (AAC) 的一部分
该库是 [AAC](https://github.com/ynotbhatc/compliance) 背后的策略引擎 —— 这是一个基于 Ansible Automation Platform + OPA + PostgreSQL 构建的合规自动化平台。AAC 使用这些策略针对 CIS、NIST、SOC 2、PCI-DSS 及其他 30 多个框架持续评估基础设施,并存储历史记录作为审计凭证。
## GitHub 上的更多 Rego 策略
社区中其他优秀的“策略即代码”工作的指引 —— **向以下每个项目的拥有者和作者致以完全的敬意**。这些是参考链接,而非直接引入的副本:我们链接到它们以便您能找到;这些策略保留在它们各自的代码库中,受其原维护者和许可协议的管理。
### 策略库
| 仓库 | 拥有者 / 作者 | 涵盖内容 |
|---|---|---|
| [redhat-cop/rego-policies](https://github.com/redhat-cop/rego-policies) | Red Hat 社区实践 | 用于 OPA、Gatekeeper 和 Conftest 的 Kubernetes/OpenShift + 常规配置合规策略 |
| [kubewarden/rego-policies-library](https://github.com/kubewarden/rego-policies-library) | Kubewarden 项目 (SUSE) | Kubernetes 安全与合规准入策略(兼容 Gatekeeper/Kubewarden,编译为 Wasm) |
| [conforma/policy](https://github.com/conforma/policy) | Conforma / Konflux-CI (企业合同) | 软件供应链验证 —— 镜像证明、构建来源、流水线定义验证 |
| [raedrizk/ansible-policy-as-code](https://github.com/raedrizk/ansible-policy-as-code) | Raed Rizk ([@raedrizk](https://github.com/raedrizk)) | AAP 治理 / 流水线强制执行 —— 作业模板命名,EE 安全,分支限制,基于时间的访问,SCM 分支强制执行,超级用户限制 |
### 风格、代码检查与工具
| 仓库 | 拥有者 / 作者 | 简介 |
|---|---|---|
| [open-policy-agent/rego-style-guide](https://github.com/open-policy-agent/rego-style-guide) | Open Policy Agent 维护者 | 官方 Rego 风格指南 / 编写最佳实践(补充 Regal linter) |
| [open-policy-agent/rego-python](https://github.com/open-policy-agent/rego-python) | Open Policy Agent | 用于处理 Rego AST 的 Python 库 |
| [itaysk/regogo](https://github.com/itaysk/regogo) | Itay Shakury ([@itaysk](https://github.com/itaysk)) | 封装 Rego 引擎以进行通用 JSON 查询(jq 风格)的 Go 库 |
## 贡献
1. 将新的 `.rego` 文件放入相应的分类路径中
2. 在顶部添加 `import rego.v1`
3. 暴露一个具有标准输出结构的 `compliance_assessment` 规则
4. 提交一个 PR
## 许可证
Apache 2.0
标签:Anthropic, CIS基准, DevSecOps, DNS解析, LNA, OPA, 上游代理, 开源项目, 策略引擎, 网络安全挑战, 请求拦截, 靶场