导出合规报告

Compliance Service 以 ZIP 格式导出报告,包括 HTML、CSV、Excel 文件和元数据。

导出 Scan 的报告

导出最新的 Scan 报告

# Export the latest Scan ZIP
NS=compliance-system
SCAN=os-scan

kubectl create --raw "/apis/reports.compliance.security.alauda.io/v1alpha1/namespaces/${NS}/scans/${SCAN}/export/zip" -f - <<< '{}' > ${SCAN}.zip

Scan ZIP 文件包含:

  • report.html - 多个标签页:Overview、Rule Summary 和每个 node
  • report.xls - 多个工作表
  • report.csv - 分段数据
  • metadata.txt - ScanID、筛选条件和统计信息

导出历史 Scan 报告

# Get Scan history scanID
kubectl get scan -n compliance-system os-scan -o yaml | grep scanID

# Export historical Scan report by scanID
NS=compliance-system
SCAN=os-scan
SCANID=be4637ee-8d06-4aaf-9f5b-ca315475599d

kubectl create --raw "/apis/reports.compliance.security.alauda.io/v1alpha1/namespaces/${NS}/scans/${SCAN}/export/zip?scanID=${SCANID}" -f - <<< '{}' > ${SCAN}-${SCANID}.zip

导出 ScanSuite 的报告

导出最新的 ScanSuite 报告

# Export the latest ScanSuite ZIP
NS=compliance-system
SUITE=test-scan

kubectl create --raw "/apis/reports.compliance.security.alauda.io/v1alpha1/namespaces/${NS}/scansuites/${SUITE}/export/zip" -f - <<< '{}' > ${SUITE}.zip

ScanSuite ZIP 文件包含聚合后的 CSV 和 Excel 输出、元数据,以及每个子 Scan 报告。

导出历史 ScanSuite 报告

# Get ScanSuite history runID
kubectl get scansuite -n compliance-system test-scan -o yaml | grep runID

# Export historical ScanSuite report by runID
NS=compliance-system
SUITE=test-scan
RUNID=20260106-035650-004246

kubectl create --raw "/apis/reports.compliance.security.alauda.io/v1alpha1/namespaces/${NS}/scansuites/${SUITE}/export/zip?runID=${RUNID}" -f - <<< '{}' > ${SUITE}-${RUNID}.zip

使用 CURL 导出报告

你也可以使用带有 bearer token 身份验证的 CURL 导出报告。

使用 CURL 导出 Scan 报告

APISERVER="https://<platform-address>/kubernetes/<cluster-name>"
TOKEN="<Bearer_token>"
NS=compliance-system
SCAN=os-scan
SCANID=be4637ee-8d06-4aaf-9f5b-ca315475599d

curl -k -X POST \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{}' \
  --output "${SCAN}-${SCANID}.zip" \
  "${APISERVER}/apis/reports.compliance.security.alauda.io/v1alpha1/namespaces/${NS}/scans/${SCAN}/export/zip?scanID=${SCANID}"

使用 CURL 导出 ScanSuite 报告

APISERVER="https://<platform-address>/kubernetes/<cluster-name>"
TOKEN="<Bearer_token>"
NS=compliance-system
SUITE=test-scan

curl -k -X POST \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{}' \
  --output "${SUITE}.zip" \
  "${APISERVER}/apis/reports.compliance.security.alauda.io/v1alpha1/namespaces/${NS}/scansuites/${SUITE}/export/zip"

注意:

  • 需要使用 -d '{}',因为 API 需要 POST 请求体。
  • 使用 --output <file> 保存二进制 ZIP 文件,并避免终端输出干扰。
  • 为了向后兼容,仍然支持旧版 URL 模式,但对于所有新脚本和示例,建议使用 namespaces/{ns}/... 模式。