A Python tool that generates Software Bill of Materials (SBOM) files for GitHub repositories using GitHub's Dependency Graph API. This tool efficiently creates SPDX-format SBOMs with vulnerability information for entire organizations.
- 🚀 Fast & Efficient: Uses GitHub's pre-analyzed dependency graphs instead of parsing files manually
- 📊 Comprehensive: Includes direct dependencies, transitive dependencies, and vulnerability data
- 🔒 Security-Focused: Integrates Dependabot alerts and security advisories
- 📄 Standards-Compliant: Generates SPDX 2.3 format SBOMs
- 🏢 Batch Processing: Process entire organizations or repository lists
- 🛡️ Multi-Ecosystem: Supports npm, pip, Maven, Go, Ruby, and more automatically
- Python 3.6 or higher
- GitHub Personal Access Token with appropriate permissions
requestslibrary
- Clone this repository:
git clone <repository-url>
cd github-sbom-generator- Install required dependencies:
pip install requests- Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token (classic)"
- Select the following scopes:
repo(for private repositories)public_repo(for public repositories)security_events(for vulnerability information)
- Copy the generated token
export GITHUB_TOKEN="your_github_personal_access_token"Or pass it directly using the --token parameter.
Create a text file (e.g., repos.txt) with one repository name per line:
webapp-frontend
api-backend
mobile-app
data-pipeline
infrastructure-tools
# This is a comment - lines starting with # are ignored
python github_sbom_generator.py repos.txt --organization your-org-namepython github_sbom_generator.py repos.txt \
--organization your-org-name \
--output-dir ./output \
--token ghp_your_token_here \
--no-vulnerabilities| Option | Description | Required | Default |
|---|---|---|---|
repo_list |
Path to text file containing repository names | ✅ | - |
--organization |
GitHub organization name | ✅ | - |
--token |
GitHub personal access token | ❌* | GITHUB_TOKEN env var |
--output-dir |
Directory to save SBOM files | ❌ | sboms |
--no-vulnerabilities |
Skip vulnerability information | ❌ | Include vulnerabilities |
*Required via either --token parameter or GITHUB_TOKEN environment variable.
The tool generates individual SBOM files for each repository in JSON format following SPDX 2.3 standards:
sboms/
├── webapp-frontend-sbom.json
├── api-backend-sbom.json
├── mobile-app-sbom.json
└── data-pipeline-sbom.json
Each SBOM includes:
- Repository metadata: Name, URL, license information
- Dependencies: All direct and transitive dependencies with versions
- Package URLs (PURLs): Standard package identifiers
- Vulnerability information: Security alerts from Dependabot
- Ecosystem data: Package manager and language information
{
"spdxVersion": "SPDX-2.3",
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "SBOM for myorg/webapp-frontend",
"documentNamespace": "https://github.com/myorg/webapp-frontend/sbom",
"creationInfo": {
"created": "2025-08-15T10:30:00Z",
"creators": ["Tool: GitHub-Dependency-Graph", "Tool: GitHub-SBOM-Generator"]
},
"packages": [
{
"SPDXID": "SPDXRef-Package-Root",
"name": "webapp-frontend",
"downloadLocation": "https://github.com/myorg/webapp-frontend.git",
"licenseDeclared": "MIT"
},
{
"SPDXID": "SPDXRef-Package-1",
"name": "react",
"versionInfo": "18.2.0",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceType": "purl",
"referenceLocator": "pkg:npm/react@18.2.0"
}
]
}
]
}The tool leverages these GitHub API endpoints:
| Endpoint | Purpose |
|---|---|
/repos/{org}/{repo} |
Repository metadata and license information |
/repos/{org}/{repo}/dependency-graph/sbom |
Pre-generated SBOM from GitHub |
/repos/{org}/{repo}/dependabot/alerts |
Security vulnerability alerts |
GitHub's Dependency Graph automatically supports:
- JavaScript/Node.js: npm, Yarn
- Python: pip, pipenv, poetry
- Java: Maven, Gradle
- Go: go mod
- Ruby: RubyGems, Bundler
- PHP: Composer
- C#/.NET: NuGet
- Rust: Cargo
- And more...
The tool handles common scenarios gracefully:
- Private repositories: Requires appropriate token permissions
- Missing dependency graphs: Creates minimal SBOMs with repository info
- Rate limiting: Implements proper error handling and logging
- Network issues: Retries and continues with remaining repositories
- Requires GitHub Dependency Graph to be enabled for the repository
- Private repositories need
reposcope permissions - Vulnerability information requires
security_eventsscope - Some older or archived repositories may not have dependency graphs
# GitHub Actions example
name: Generate SBOMs
on:
schedule:
- cron: '0 2 * * 1' # Weekly on Monday at 2 AM
jobs:
generate-sboms:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: pip install requests
- name: Generate SBOMs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python github_sbom_generator.py repos.txt --organization myorg
- name: Upload SBOMs
uses: actions/upload-artifact@v3
with:
name: sboms
path: sboms/FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt github_sbom_generator.py ./
RUN pip install -r requirements.txt
ENTRYPOINT ["python", "github_sbom_generator.py"]docker build -t sbom-generator .
docker run -v $(pwd)/repos.txt:/app/repos.txt \
-v $(pwd)/output:/app/sboms \
-e GITHUB_TOKEN=$GITHUB_TOKEN \
sbom-generator repos.txt --organization myorg"Dependency graph not available"
- Ensure the repository has dependency files
- Check if dependency graph is enabled in repository settings
- Verify token has appropriate permissions
"Rate limit exceeded"
- Use a personal access token instead of default GitHub Actions token
- Implement delays between requests for large repository lists
"404 Not Found"
- Verify organization and repository names are correct
- Ensure token has access to the specified repositories
Enable debug logging for troubleshooting:
import logging
logging.basicConfig(level=logging.DEBUG)- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Never commit GitHub tokens to version control
- Use environment variables or secure secret management
- Regularly rotate personal access tokens
- Follow principle of least privilege for token scopes
- GitHub CLI - Command line tool for GitHub
- SPDX Tools - Python library for SPDX
- Syft - Generate SBOMs from container images
- CycloneDX - Alternative SBOM format