The user wants me to "Design a license compliance scanner."
Key features requested:
- SBOMs (Software Bill of Materials): The input for the scanner.
- Allow/Deny lists: The policy engine to determine compliance.
- Notices: The output mechanism to handle attribution and disclosure requirements.
This is a system design / architecture problem. I need to structure the response to cover the high-level architecture, data flow, core components, data models, and potential challenges.
1. High-Level Architecture:
- Input: SBOMs (SPDX, CycloneDX, etc.) + Policy Definition.
- Processing: Parsing -> Dependency Resolution (maybe) -> License Detection -> Policy Evaluation -> Notice Generation.
- Output: Compliance Report, Attribution Document (Notices.txt), CI/CD blocking/failure status.
2. Component Breakdown:
-
Ingestion Layer:
- Needs to handle different SBOM formats. SPDX and CycloneDX are the standards.
- Needs to handle raw code scans (optional but good for completeness, though the prompt specifically mentioned SBOMs, so I'll focus on SBOM ingestion).
-
License Identification Engine:
- How do we know what license a package has?
- Source A: The SBOM itself (declared license).
- Source B: Lookups against a license database (e.g., ClearlyDefined, internal cache, FOSSA/Snyk APIs - though this is a design question, so I should propose a self-contained architecture or an aggregator pattern).
- Confidence scoring (Declared vs. Concluded).
-
Policy Engine (The "Allow/Deny" part):
- Needs a rule definition format (YAML/JSON).
- Categories: Permissive (MIT, Apache), Weak Copyleft (LGPL), Strong Copyleft (GPL), Proprietary, Unknown.
- Handling exceptions (e.g., "GPL is denied, except for package X which is a build tool").
-
Attribution/Notice Generator:
- Needs templates.
- Needs to aggregate copyright notices.
- Needs to handle file-level copying requirements (e.g., include the full license text).
-
User Interface / API:
- CLI tool (for CI/CD).
- Dashboard (for auditing).
- API (for integration).
3. Detailed Design & Data Models:
- SBOM Model: Package URL (purl), Name, Version, License Expression.
- Policy Model: Rule ID, License ID (SPDX identifier), Action (Allow, Deny, Review), Context (Commercial, Internal).
- Notice Model: Copyright text, License text, Package name.
4. Workflow:
- Developer generates SBOM.
- Scanner ingests SBOM.
- Scanner enriches data (fill in missing licenses).
- Scanner applies Policy rules.
- If Deny -> Fail Build.
- If Allow -> Generate
NOTICE file.
- Store report.
5. Key Technical Challenges:
- Accuracy: Declared licenses are often wrong or missing.
- Conflicts: Transitive dependencies might have incompatible licenses.
- Nuance: "GPL-2.0-only" vs "GPL-2.0-or-later".
- Scale: Large dependency trees.
6. Refining the Response Structure:
- Title: Architecture Design for a License Compliance Scanner.
- System Overview: Diagram description.
- Core Components:
- Ingestion (SBOM Parser).
- License Resolution (The "Knowledge Base").
- Policy Engine (Allow/Deny).
- Reporting & Attribution (Notices).
- Data Models: Define what the Policy and SBOM look like internally.
- The Workflow: Step-by-step execution.
- Edge Cases: Unknown licenses, multi-licensing.
- Tech Stack Recommendation: (Python/Go, Graph DB, etc.).
Self-Correction/Refinement during thought process:
- Initial thought: Should I include code scanning?
- Correction: The prompt specifically says "SBOMs". Stick to SBOMs for the input to keep the scope tight, but mention that the SBOM generator usually does the code scanning.
- Focus: Make sure to explicitly detail the "Allow/Deny" logic and the "Notices" generation, as requested.
Drafting the Content:
- Policy Engine: Needs to support complex logic. Example:
Deny GPL unless approved_by Legal. State management is important here.
- Notices: It's not just a text dump. It needs to follow the specific license requirements (e.g., MIT requires keeping the copyright line, Apache requires listing changes—though hard to automate, standard practice is just including the text).
Let's organize this into a clean, professional design document format.
Structure:
- High-Level Architecture Diagram (ASCII/Mermaid style description).
- Input/Output Specification.
- Component 1: Ingestion & Normalization.
- Component 2: License Resolution (The Enricher).
- Component 3: Policy Engine (The Guardrails).
- Component 4: Notice Generator.
- Data Schema (JSON/YAML examples).
- Integration (CI/CD).
This looks solid. I will write the response following this structure.
Designing a license compliance scanner requires balancing automated accuracy with legal flexibility. The system needs to ingest structured data (SBOMs), apply business logic (Policies), and produce legal artifacts (Notices).
Here is a comprehensive system design for "LicenseGuard," a license compliance scanner.
1. High-Level Architecture
The system consists of four primary stages: Ingestion, Enrichment, Evaluation, and Reporting.
[ SBOM Input ] [ Policy Config ]
| |
v v
[ Normalization ] --> [ Policy Engine ] --> [ Reporting ]
| ^ |
v | v
[ Enrichment Service ]-----+---> [ Notice Generator ]
2. Component Design
A. Ingestion & Normalization Layer
This layer handles the input format chaos. SBOMs come in various formats (SPDX, CycloneDX) and serialization types (JSON, XML).
- Standardization: Convert all inputs into an Internal Dependency Model (IDM).
- IDM Fields:
PackageName, Version, PURL (Package URL), LicenseExpression (SPDX identifier), CopyrightText, DownloadLocation.
- Tree Building: If the SBOM is flat, this layer attempts to reconstruct the dependency tree (using PURLs) to understand transitive dependencies.
B. Enrichment Service (The Resolver)
SBOMs are often incomplete (e.g., they list "UNKNOWN" or generic license names). This service fills the gaps.
- Local Cache: A database mapping
PURL -> LicenseID to speed up repeated scans.
- Federated Lookups: If a license is missing, query external registries:
- ClearlyDefined / FOSSA / Snyk APIs.
- Repo Lookups: If a PURL points to GitHub, fetch
LICENSE, README, and package.json files.
- License Text Matching: If the file content is found but the SPDX ID is missing, calculate the hash of the license text and compare it against a database of known license texts (Text Fuzzy Matching).
C. Policy Engine (The Core Logic)
This is where the Allow/Deny logic lives. Policies are defined in a YAML or JSON file, allowing legal teams to update rules without changing code.
Policy Configuration Structure:
version: 1.0
profiles:
- name: "Commercial-Product-Policy"
default_action: REVIEW
allow_list:
- MIT
- Apache-2.0
- BSD-2-Clause
- ISC
deny_list:
- GPL-3.0 # Strong Copyleft
- AGPL-3.0 # Network Copyleft
- CC-BY-NC # Non-Commercial
exceptions:
# Allow a specific denied package if approved by Legal
- purl: "pkg:maven/com.example/legacy-lib@1.0"
rule_override: ALLOW
reason: "Contractual exemption signed 2023"
# Allow a specific version of an LGPL library
- purl: "pkg:npm/lgpl-component@2.1.0"
rule_override: ALLOW
usage_context: "Isolated dynamic linking"
Evaluation Logic:
- Exact Match: Is the license in the
deny_list? -> FAIL.
- Exception Check: Does the package PURL match an
exception entry? -> PASS (with note).
- Allow Check: Is the license in the
allow_list? -> PASS.
- Unknowns: Is the license
NOASSERTION? -> FAIL (requires review).
D. Notice Generator
Compliance isn't just about blocking; it's about attribution. This component generates the NOTICE file or attribution.txt.
- Templates: Uses Jinja2 or similar templating.
- Aggregation: Groups dependencies by license type to reduce verbosity (e.g., "The following packages are licensed under MIT: [List]").
- File Inclusion: For specific licenses (e.g., Apache 2.0), it copies the full license text into the output directory.
3. Data Models
The Internal Dependency Model (IDM)
{
"purl": "pkg:npm/react@18.2.0",
"name": "React",
"version": "18.2.0",
"licenses": [
{
"spdx_id": "MIT",
"source": "Declared", // or "Detected", "Repository"
"copyright": "Copyright (c) Facebook, Inc."
}
],
"dependencies": ["pkg:nvm/loose-envify@1.4.0"]
}
The Compliance Report
{
"scan_id": "uuid-1234",
"status": "FAILURE",
"summary": {
"total_packages": 142,
"allowed": 130,
"denied": 2,
"review_required": 10
},
"violations": [
{
"purl": "pkg:pypi/gpl-library@1.0",
"reason": "License GPL-3.0 is in the Deny List.",
"severity": "CRITICAL",
"suggestion": "Remove dependency or request exception from Legal."
}
]
}
4. Workflow Example
Scenario: A developer runs the scanner in CI/CD.
- Input: The CI pipeline generates a
bom.json (CycloneDX) and the scanner loads policy.yaml.
- Scan:
- The scanner parses the 150 packages in the SBOM.
- It identifies
pkg:npm/gpl-toolkit@3.0.
- It resolves the license as
GPL-3.0.
- Evaluate:
- Policy Engine checks
GPL-3.0 against the profile.
- Result: DENY.
- Output:
- Console: Prints big red "COMPLIANCE FAILURE" message.
- Exit Code: Returns
1 (breaking the build).
- Artifacts: Generates
compliance-report.json (for auditors) and a partial NOTICE file (for valid packages).
5. Technical Considerations
- Handling "OR" Logic: A package might declare
MIT OR Apache-2.0. The scanner should treat this as passing if either is in the Allow List, but allow the user to pick which one applies for the Notice file.
- Handling "AND" Logic:
MIT AND GPL-3.0. This requires the policy to satisfy both. Usually, this results in a flag because the combination is viral (GPL).
- Conflicts: If the SBOM says "MIT" but the scanner detects "GPL" in the source code file header, this is a High Priority Conflict.
- Scalability: If scanning large monoliths, the enrichment step can be slow. Use async workers (e.g., Python Celery or Go Routines) to fetch license data for hundreds of packages in parallel.
6. CLI Interface Design
# Basic Scan
licenseguard scan --sbom ./sbom.json --policy ./policy.yaml
# Generate Notices only (don't fail)
licenseguard notice --sbom ./sbom.json --output ./dist/NOTICE.txt
# Approve an exception interactively
licenseguard approve --purl "pkg:maven/bad-lib@1.0" --reason "Ticket-1234"