thulisa-n/pki-compliance-gate

GitHub: thulisa-n/pki-compliance-gate

一款基于策略即代码的 X.509 证书 PKI 合规检测引擎,在 CI/CD 流水线中自动验证证书是否符合 CA/Browser Forum 基线要求并生成审计证据。

Stars: 0 | Forks: 0

# CertGuard Engine ![Python](https://img.shields.io/badge/python-3.11%2B-blue) ![测试](https://img.shields.io/badge/tests-pytest-informational) ![CI](https://img.shields.io/badge/ci-github%20actions-black) CertGuard Engine 是一个用于 X.509 证书的 policy-as-code PKI 检测门。 它在 CI 中运行安全验证,并输出审计证据产物。 ## 30 秒简介 ``` python3 -m venv venv source venv/bin/activate pip install -r requirements.txt python src/main.py --cert tests/certificates/valid_cert.pem ``` JSON 输出: ``` python src/main.py --cert tests/certificates/valid_cert.pem --output json ``` ## 工作流程 ``` flowchart LR A[PEM Certificate] --> B[X509 Parser] B --> C[Policy Validator] C --> D[Compliance Report] C --> E[Audit Evidence] D --> F[Exit Code] ``` ## 已实施的安全控制 - Policy-as-code 验证:`policies/*.yaml` + 可选 Rego(`policies/rego/validity.rego`) - CI 合规门:`.github/workflows/compliance.yml` - SAST/SCA:`.github/workflows/security-scans.yml` - 代码分析:`.github/workflows/codeql.yml` - 密钥检测:`.github/workflows/secrets-scan.yml` - IaC 扫描(Kubernetes manifests):`.github/workflows/iac-scan.yml` - 无密钥来源签名(OIDC + Rekor):`.github/workflows/compliance.yml` - API TLS 姿态检查:`--mode apisec` - 受控豁免:`--waiver-file`(需要工单 + 有效期) ## Evaluate 退出代码 - `0`:合规且无 lint 失败 - `1`:仅低严重性策略失败 - `2`:中/高严重性失败或仅 lint 失败 - `3`:严重策略失败 ## 基于风险的门控 - `critical` 或 `high/medium` 失败将阻止合并就绪状态(`exit 2/3`)。 - 仅低严重性失败被隔离(`exit 1`),以便进行针对性修复。 - 通过带有工单和有效期要求的豁免文件支持有时限的例外。 ## 当前范围 - 范围内:证书策略验证、CI 安全门控、IaC manifest 检查、API TLS 姿态检查。 - 暂不在范围内:容器镜像扫描(此 repo 中不构建/发布任何容器镜像)。 ## 常用命令 ``` # 评估 python src/main.py --cert tests/certificates/valid_cert.pem # Triage 现有报告 python src/main.py --mode triage --report-input reports/compliance_report.json # API TLS posture 检查 python src/main.py --mode apisec --endpoint https://example.com ``` ## 模式 - `evaluate`, `triage`, `assure`, `watch`, `heal`, `summary`, `trend`, `apisec`, `signals` ## 输入 - `--cert`(`evaluate` 必填) - `--policy`(默认:`policies/cabf_policy.yaml`) - `--dcv-attestation`, `--issuance-attestation`, `--waiver-file`, `--issuer-cert` ## 关键输出 - `reports/compliance_report.json` - `reports/compliance_report.json.seal` - `audit_evidence/policy_checks.json` - `audit_evidence/lint_results.json` - `audit_evidence/waiver_results.json` - `audit_evidence/opa_results.json` - `audit_evidence/evidence_manifest.json` - `audit_evidence/compliance_decisions.jsonl` ## GitHub 中的测试证据 - PR 检查:`Compliance Gate` 从 JUnit XML 发布 `Pytest Results` 检查。 - 运行产物:下载 `certguard-compliance-artifacts-` 以获取: - `pytest-junit.xml` - `pytest-report.html`(独立的 HTML 报告) - 证据报告由 CI 生成;本地的 `reports/test-results/` 被有意进行 git-ignored 处理。 ## 来源验证 - `Compliance Gate` 使用 cosign 无密钥签名对 `release_provenance.json` 进行签名。 - 验证使用 GitHub OIDC 身份和 Rekor transparency-log 证明,而不是共置的静态密钥。 - 证据包包括: - `release_provenance.cosign.sig` - `release_provenance.cosign.crt` - `release_provenance.cosign.bundle` - 独立验证命令(CI 外): - `cosign verify-blob --bundle release_provenance.cosign.bundle --certificate release_provenance.cosign.crt --signature release_provenance.cosign.sig --certificate-oidc-issuer https://token.actions.githubusercontent.com --certificate-identity-regexp '^https://github.com/thulisa-n/pki-compliance-gate/.github/workflows/compliance.yml@refs/heads/main$' release_provenance.json` - 对于 PR workflow 运行,请将身份正则表达式替换为: - `^https://github.com/thulisa-n/pki-compliance-gate/.github/workflows/compliance.yml@refs/pull/[0-9]+/merge$` - cosign bundle 作为可移植性证据被保留,以便日后无需依赖 repo 中存储的密钥即可重新验证来源。 ## CI Workflows - `compliance.yml` - `security-scans.yml` - `codeql.yml` - `secrets-scan.yml` - `iac-scan.yml` - `standards-sync.yml` - `standards-pr-guard.yml` - `kyverno-policy.yml` - `docs-render.yml` 必需的状态检查通过 GitHub 分支保护/规则集来强制执行。 ## Repo 映射 ``` src/certguard/ core agents + engine src/main.py CLI entrypoint policies/ policy files and profiles tests/ automated tests deployments/kyverno/ kyverno policy examples .github/workflows/ CI/CD workflows ``` ## 更多文档 - `CONTRIBUTING.md` - `docs/DEVSECOPS_ALIGNMENT.md` - `docs/PROJECT_STATUS.md` - `docs/COMPLIANCE_DEBUG_WALKTHROUGH.md` - `docs/EVIDENCE_LIFECYCLE.md` - `docs/KYVERNO_POLICY_REPORTING.md`
标签:DevSecOps, Python, X.509证书, 上游代理, 无后门, 策略即代码, 聊天机器人安全, 逆向工具