License Compliance Scanner Design: LicenseGuard
Overview
LicenseGuard is a modular, extensible tool for scanning Software Bill of Materials (SBOMs) to enforce license compliance policies. It parses SBOMs (CycloneDX or SPDX formats), evaluates components against configurable allow/deny lists, generates compliance reports, and produces required license notices (e.g., attributions, copyright statements).
Key Goals :
Zero false positives : Normalize licenses using SPDX identifiers.
Policy-driven : Allow/deny lists with risk scoring (e.g., copyleft, viral).
Notices automation : Aggregate and format notices for redistribution.
Scalable : CLI, API, CI/CD integration (GitHub Actions, Jenkins).
Open-source friendly : MIT-licensed, Python-based.
Supported SBOM Formats :
CycloneDX (JSON/XML, v1.4+)
SPDX (JSON, v2.3+)
License Categories (predefined, extensible):
Allowed : Permissive (MIT, Apache-2.0).
Restricted : Copyleft (GPLv2+, AGPL).
Notices Required : Attribution (BSD, CC-BY).
High Risk : Patent grants, commercial restrictions.
Architecture
code Copy code
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ SBOM Input │───▶│ SBOM Parser │───▶│ Components │
│ (CycloneDX/SPDX)│ │ (cyclonedx-lib, │ │ List (POM) │
└─────────────────┘ │ spdx-tools) │ └──────────┬──────┘
└──────────────────┘ │
│
┌─────────────────┐ ┌──────────────────┐ │
│ Policy Config │───▶│ Policy Engine │◀──────────────┘
│ (YAML/JSON) │ │ (allow/deny, │
└─────────────────┘ │ risk scores) │
└──────────────────┘
│
▼
┌──────────────────┐ ┌─────────────────┐
│ Compliance │───▶│ Report │
│ Checker │ │ (JSON/HTML/CSV) │
└──────────────────┘ └─────────────────┘
│
▼
┌──────────────────┐
│ Notice Generator │───▶┌─────────────────┐
│ (aggregate texts)│ │ Notices.txt │
└──────────────────┘ │ (ATTRIB, LICENSE)│
└─────────────────┘
Core Components
SBOM Parser :
Extracts components, dependencies, licenses (declared + detected).
Builds Package Object Model (POM) : List of dicts with {name, version, purl, licenses: [spdx_ids], supplier, hashes}.
Handles transitive deps (recursion).
License normalization: Maps "MIT License" → "MIT", detects "dual" (e.g., "GPL-2.0 OR MIT").
Policy Engine :
YAML config:
yaml Copy code
policies:
allow:
- MIT
- Apache-2.0
deny:
- GPL-2.0-or-later
- AGPL-1.0
notices_required:
- BSD-3-Clause # Needs copyright notice
risk_threshold: high # fail on 'copyleft'
custom_rules:
- match: purl_prefix("npm:")
deny: proprietary # NPM-specific
Supports globs (GPL-*), SPDX expressions ((A OR B) AND C), inheritance.
Compliance Checker :
For each component:
Status : ALLOWED | DENIED | WARNING | UNKNOWN.
Score : 0-100 (e.g., copyleft = -50).
Aggregates: Overall compliance score, violation tree (sorted by risk).
Notice Generator :
Fetches license texts (from SPDX License List API or cache).
Aggregates:
ATTRIB.txt : Copyright notices.
LICENSE.txt : Full license texts (deduped).
THIRDPARTY.txt : Component list with licenses.
Formats per policy (e.g., Apache NOTICE format).
Reporter :
Outputs: JSON (machine-readable), HTML (visual tree), SARIF (for GitHub CodeQL), CSV.
Exit codes: 0 (compliant), 1 (warnings), 2 (failures).
Data Models (Python TypedDict)
python Copy code
from typing import List, Dict, Any
from dataclasses import dataclass
@dataclass
class Component:
name: str
version: str
purl: str # Package URL
licenses: List[str] # SPDX IDs
supplier: str
hashes: Dict[str, str]
@dataclass
class CheckResult:
component: Component
status: str # ALLOWED/DENIED/...
score: int
reason: str
notice_required: bool
Workflow
Load SBOM → Parse to POM.
Load policy → Compile rules.
For each component: Match licenses → Assign status/score.
Generate report: Violations first, then full list.
If compliant: Generate notices.
code Copy code
licenseguard scan sbom.json --policy policy.yaml --output report.json --notices
CLI Interface
bash Copy code
# Install: pip install licenseguard
licenseguard --version
licenseguard scan [OPTIONS] <SBOM_FILE>
Options:
--policy POLICY_FILE YAML/JSON policy (default: allowlist.yaml)
--output FORMAT json|html|sarif|csv (default: json)
--notices Generate notices/ dir
--fail-on WARN|DENY Exit code on threshold
--cache-dir DIR License text cache
--verbose Debug logs
Example Run :
code Copy code
$ licenseguard scan app.cdx.json --policy strict.yaml --output report.html --notices
[+] Parsed 150 components (45 transitive).
[+] Violations: 3 (GPL-2.0 in lodash@1.0.0)
[!] Compliance score: 92/100
[+] Generated notices/ (ATTRIB.txt, LICENSES.txt)
Sample Report (JSON snippet) :
json Copy code
{
"summary": {"total": 150, "allowed": 147, "denied": 3, "score": 92},
"violations": [
{"component": {"name": "lodash", "licenses": ["GPL-2.0"]}, "status": "DENIED", "reason": "Copyleft"}
],
"notices": {"files_generated": ["ATTRIB.txt", "LICENSES.txt"]}
}
API (FastAPI Server)
python Copy code
from licenseguard.api import scan_sbom
result = scan_sbom(sbom_bytes, policy_yaml)
# Returns CheckResult list + notices
Implementation Notes
Tech Stack : Python 3.11+, cyclonedx-python-lib, spdx-tools, PyYAML, Jinja2 (reports), requests (license texts).
Extensibility : Plugin for custom parsers/policies (e.g., via entrypoints).
Performance : <5s for 10k components (cached licenses).
Edge Cases : Unknown licenses → WARNING; Multi-license → All must pass; Embedded binaries.
Security : No exec; Validates inputs; SBOM signatures (future).
Roadmap
GUI dashboard.
IDE plugin (VS Code).
Auto-fix (license swaps).
Integration with OSS Review Toolkit.
Repo : github.com/trailblazer-labs/licenseguard (hypothetical).
This design ensures robust, policy-enforceable scanning with minimal setup. Questions?