hahwul/cyclonedx-cr
GitHub: hahwul/cyclonedx-cr
从 Crystal shard 项目自动生成 CycloneDX SBOM,支持 JSON、XML、CSV 多格式输出与 CI/CD 流水线集成。
Stars: 4 | Forks: 0
# cyclonedx-cr (Crystal)
一款用于从 Crystal shard 项目生成 [CycloneDX](https://cyclonedx.org/) 软件物料清单 (SBOM) 的 Crystal 工具。
## 功能特性
- 🔍 从 Crystal `shard.yml` 和 `shard.lock` 文件生成 CycloneDX SBOM
- 📋 支持多种输出格式:JSON、XML、CSV
- 📊 兼容 CycloneDX 规范版本 1.4、1.5、1.6 和 1.7
- 🔗 自动为依赖项生成 Package URLs (PURLs)
- 🐳 支持 Docker 容器化使用
- ⚡ 使用 Crystal 实现的快速轻量级方案
## 安装
### 二进制发布版
从 [releases 页面](https://github.com/hahwul/cyclonedx-cr/releases)下载最新的二进制文件。
### Homebrew (macOS/Linux)
```
brew install hahwul/cyclonedx-cr/cyclonedx-cr
```
### Docker
```
docker run --rm -v $(pwd):/workspace -w /workspace ghcr.io/hahwul/cyclonedx-cr:latest
```
### 作为 Shard 依赖项
将 cyclonedx-cr 添加到您的 `shard.yml` 中:
```
development_dependencies:
cyclonedx-cr:
github: hahwul/cyclonedx-cr
```
然后运行:
```
shards install
bin/cyclonedx-cr
```
### 从源码构建
要求:[Crystal](https://crystal-lang.org/) 1.6.2+
```
git clone https://github.com/hahwul/cyclonedx-cr.git
cd cyclonedx-cr
shards install
shards build --release
```
## 使用方法
### 基本用法
从您的 Crystal 项目生成 SBOM:
```
cyclonedx-cr
```
这将读取当前目录下的 `shard.yml` 和 `shard.lock`,并以 JSON 格式将 SBOM 输出到 stdout。
### 命令行选项
```
Usage: cyclonedx-cr [arguments]
-i FILE, --input=FILE shard.lock file path (default: shard.lock)
-s FILE, --shard=FILE shard.yml file path (default: shard.yml)
-o FILE, --output=FILE Output file path (default: stdout)
--spec-version VERSION CycloneDX spec version (options: 1.4, 1.5, 1.6, 1.7, default: 1.6)
--output-format FORMAT Output format (options: json, xml, csv, default: json)
-h, --help Show this help
```
### 示例
#### 生成 JSON SBOM 到文件
```
cyclonedx-cr -o sbom.json
```
#### 使用特定规范版本生成 XML SBOM
```
cyclonedx-cr --output-format xml --spec-version 1.5 -o sbom.xml
```
#### 从自定义 shard 文件生成 CSV SBOM
```
cyclonedx-cr -s my-shard.yml -i my-shard.lock --output-format csv -o sbom.csv
```
#### Docker 使用
```
# 为当前目录生成 SBOM
docker run --rm -v $(pwd):/workspace -w /workspace ghcr.io/hahwul/cyclonedx-cr:latest -o sbom.json
# 使用自定义 shard 文件
docker run --rm -v $(pwd):/workspace -w /workspace ghcr.io/hahwul/cyclonedx-cr:latest \
-s custom-shard.yml -i custom-shard.lock --output-format xml -o sbom.xml
```
#### GitHub Actions
```
name: Generate and Upload SBOM
on:
release:
types: [created]
jobs:
generate-sbom:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Checkout the repository code
- name: Checkout code
uses: actions/checkout@v4
# Generate SBOM using hahwul/cyclonedx-cr action
- name: Generate SBOM
uses: hahwul/cyclonedx-cr@v1.2.0
with:
shard_file: ./shard.yml # Explicitly map to shard_file
lock_file: ./shard.lock # Explicitly map to lock_file
output_file: ./sbom.xml # Map to output_file
output_format: xml # Map to output_format
spec_version: 1.6 # Optional, specify if needed
# Upload SBOM to GitHub Release
- name: Upload SBOM to Release
uses: softprops/action-gh-release@v2
with:
files: ./sbom.xml
token: ${{ secrets.GITHUB_TOKEN }}
```
## 要求
您的 Crystal 项目必须包含:
- `shard.yml` 文件(项目配置)
- `shard.lock` 文件(锁定的依赖版本)
在您的 Crystal 项目中运行 `shards install` 以生成 `shard.lock` 文件。
## 输出格式
### JSON(默认)
标准 CycloneDX JSON 格式,适用于大多数 SBOM 工具和平台。
### XML
CycloneDX XML 格式,兼容需要 XML 输入的工具。
### CSV
简化的逗号分隔值格式,用于基本分析和报告。
## CycloneDX 规范版本
- **1.7**:支持全部功能的最新版本
- **1.6**(默认):具有广泛兼容性的最新稳定版本
- **1.5**:具有广泛工具兼容性的稳定版本
- **1.4**:用于兼容旧版工具的历史版本
## 许可证
本项目采用 MIT 许可证授权 - 详情请参阅 [LICENSE](LICENSE) 文件。
## 相关项目
- [CycloneDX](https://cyclonedx.org/) - OWASP CycloneDX SBOM 标准
- [Crystal](https://crystal-lang.org/) - The Crystal 编程语言
- [Shards](https://github.com/crystal-lang/shards) - Crystal 包管理器
标签:Crystal, CSV, CycloneDX, DevSecOps, Docker, GPT, JSON, Linux安全, PURL, SBOM, Shard, SOC Prime, WebSocket, XML, 上游代理, 二进制发布, 云安全监控, 依赖分析, 包管理, 安全合规, 安全防御评估, 开发工具, 开源工具, 数据集, 文档安全, 漏洞管理, 硬件无关, 网络代理, 请求拦截, 跌倒检测, 软件物料清单, 静态分析