The user wants an open-source compliance pipeline.
The key components requested are:
- Scanning (identifying dependencies and licenses).
- Attribution files (generating notices, e.g.,
NOTICE, LICENSE).
- Copyleft triggers (detecting viral licenses like GPL).
- Dual licensing (handling scenarios where code might be under a commercial license vs. open source).
- Approvals (workflow for legal/engineering review).
I need to design a conceptual and practical implementation of this pipeline.
Target Audience: Likely a software engineer, DevOps specialist, or open-source program office (OSPO) manager looking for a concrete architecture or toolset.
Tone: Professional, technical, structured, and actionable.
Key Tools to Consider:
- Scanning: FOSSology, ScanCode, Black Duck (proprietary, but relevant to mention as contrast), OSS Review Toolkit (ORT), Licensee.
- Package Management: SPDX (Software Package Data Exchange) is crucial for standardization.
- CI/CD: GitHub Actions, GitLab CI, Jenkins.
Structure of the Response:
- High-Level Architecture: A diagram (text-based) or flow description.
- Phase 1: Identification & Scanning (The "Input"): How to find the code.
- Phase 2: Analysis & Policy Check (The "Logic"): Copyleft checks, allowlists.
- Phase 3: Attribution & Documentation (The "Output"): Generating files.
- Phase 4: Dual Licensing Handling (The "Edge Case"): How to handle proprietary vs. open.
- Phase 5: Approval Workflow (The "Gate"): Human intervention.
- Example Implementation (The "Code"): A concrete example using a popular open-source tool (like ORT or ScanCode + a script). I'll choose a mix of standard tools (ScanCode + custom logic) or a framework like ORT for a robust solution. ORT is probably the best fit for "building a pipeline" rather than just writing a script. However, a simple Python/Shell script approach is often easier to understand initially. I will provide a modular architecture.
Refining the "Dual Licensing" part:
This is tricky. Dual licensing usually means "If you open source your app, it's free (GPL). If you keep it proprietary, you pay."
The pipeline needs to know: "Is this project open source or proprietary?"
If proprietary -> Check if dependency is GPL. If yes -> Block or Check for commercial license key.
If open source -> GPL is allowed.
Refining the "Approvals" part:
Needs a way to pause the pipeline. GitHub Environments or a JIRA ticket integration.
Drafting the Content:
- Introduction: Define the goal (automated compliance).
- Stack: Recommend SPDX for data format.
- Step-by-Step:
- Scan: Use ScanCode Toolkit or Trivy.
- Parse: Convert scan output to SPDX.
- Policy Engine: The brain. Checks against a
policy.json.
- Artifacts: Generate HTML/Text notices.
- The "Code" Section: I will write a mock Python structure or a GitHub Actions workflow configuration. A GitHub Actions workflow using existing docker containers (like
scancode or ort) is the most practical "build" instruction.
Self-Correction during thought process:
Don't just list tools. The user asked to build one. I should provide a modular design pattern.
I will structure it as a Reference Architecture using OSS Review Toolkit (ORT) as the backbone, because it supports all these features (scanning, rules, curations) out of the box, or I can show how to chain simpler tools together.
Actually, ORT is complex. Maybe a simpler "Do It Yourself" pipeline using scancode-toolkit and a Python script for the logic is better for educational purposes, while mentioning ORT as the "Enterprise" solution.
Let's go with a Modular DIY approach (easier to customize) vs an Integrated approach (ORT). I'll explain the architecture of a custom pipeline using Python + ScanCode.
Key features to implement in the script:
Scanner: Wraps ScanCode.
LicenseMatcher: Checks against SPDX list.
PolicyChecker:
- Allowlist (MIT, Apache).
- Copyleft Triggers (GPL, AGPL).
- Dual License Logic (Check context).
AttributionGenerator: Writes the file.
Handling Dual Licensing:
This usually implies the user's code is dual-licensed, or they are consuming a dual-licensed library.
If consuming: If library is GPL/Commercial, and User project is Proprietary, fail unless a "Commercial Token" is found.
I will add a specific logic block for this.
Final Plan:
- Conceptual Diagram: Inputs -> Scanner -> Policy Engine -> Reporter.
- Tool Selection: ScanCode (best open source scanner), SPDX (standard).
- The Pipeline Script (Python): A mockup of the logic engine.
- CI/CD Integration: YAML example.
- Governance: How to handle the approvals.
Let's write it.
To build a robust Open Source Compliance Pipeline, we need to move beyond simple "scanning" and create a workflow that handles the entire Software Development Lifecycle (SDLC), from dependency ingestion to the final attribution document.
Here is a comprehensive architecture and implementation guide for a pipeline based on the SPDX standard and OSS Review Toolkit (ORT).
Phase 1: Architecture Overview
We will build a pipeline with four distinct stages:
- Discovery: Identify all dependencies (direct & transitive).
- Scanning & Identification: Match code against a license database.
- Policy Evaluation (The "Brain"): Apply rules for Copyleft, Dual-Licensing, and Approvals.
- Artifact Generation: Create Attribution docs and Notices.
The Tech Stack
Phase 2: The Pipeline Configuration
Instead of writing a fragile bash script, we define the compliance rules in a YAML file. This file handles your Attribution, Copyleft Triggers, and Approvals.
Create a file named ort.yml:
# ort.yml - The Rulebook
# 1. DEFINITIONS: How we categorize licenses
license_choices:
# Handle Dual Licensing (e.g., GPL-2.0-only OR Commercial)
# If a package offers a choice, prefer the Commercial license if we have a license key,
# otherwise default to the Open Source option.
- given: "GPL-2.0-only OR LicenseRef-Proprietary"
choice: "LicenseRef-Proprietary"
reason: "COMMERCIAL_LICENSE_ACQUIRED"
# 2. POLICIES: The Compliance Logic
policy:
# A. Approval Mechanism
# Define which licenses are allowed automatically vs. need human approval.
approve_in_license_finding:
- "Apache-2.0"
- "MIT"
- "0BSD"
- "BSD-3-Clause"
# B. The "Stop the Line" Triggers
# These licenses trigger a manual review or pipeline failure.
# Useful for Copyleft (Viral) triggers.
prohibit_in_license_finding:
- id: "GPL-3.0"
message: "Copyleft trigger: GPL-3.0 found. Requires Legal Review."
severity: "ERROR" # Blocks the build
- id: "AGPL-3.0"
message: "Strong Copyleft: AGPL-3.0 found. Network use clause applies."
severity: "ERROR"
# C. Handling Dual Licensing / Commercial exceptions
# If we have a license file for a commercial dependency, treat it as valid.
license_finding_curations:
- path: "libs/commercial-lib/**"
start_line: 1
detected_license: "GPL-2.0"
concluded_license: "LicenseRef-Proprietary"
reason: "CURATION"
# 3. ATTRIBUTION: Generating the Notices
repository:
configurations:
- source:
path: "docs/templates/NOTICE_TEMPLATE.ftl"
target:
path: "distribution/NOTICE.txt"
Phase 3: The Scanning Script
This script acts as the CI/CD job. It downloads your dependencies, scans them, runs the policy logic, and outputs the attribution files.
Prerequisites: Docker installed (to run ORT).
#!/bin/bash
# compliance_pipeline.sh
# 1. SETUP
# Download ORT Docker image (ensure you pin versions in production)
docker pull ghcr.io/oss-review-toolkit/ort:latest
# 2. DEPENDENCY RESOLUTION
# ORT reads package managers (npm, maven, pip, gradle) automatically.
# We assume the project source is in the current directory.
echo "Resolving dependencies..."
docker run --rm \
-v $(pwd):/project \
-v $(pwd)/ort-config:/config \
ghcr.io/oss-review-toolkit/ort \
ort --info analyze -i /project -o /project/ort-results
# 3. SCANNING (The heavy lifting)
# This uses ScanCode internally to find license headers in source files
# and matches them against the SPDX license list.
echo "Scanning source code..."
docker run --rm \
-v $(pwd):/project \
ghcr.io/oss-review-toolkit/ort \
ort --info scan -i /project/ort-results/analyzer-result.yml -o /project/ort-results
# 4. POLICY EVALUATION
# This applies the rules defined in ort.yml (copyleft triggers, approvals).
echo "Evaluating policies..."
docker run --rm \
-v $(pwd):/project \
-v $(pwd)/ort-config:/config \
ghcr.io/oss-review-toolkit/ort \
ort --info evaluate \
-i /project/ort-results/scan-result.yml \
-o /project/ort-results \
--rules-file /config/ort.yml
# 5. REPORTING
# Generate the Attribution file (NOTICE.txt) and HTML reports.
echo "Generating reports..."
docker run --rm \
-v $(pwd):/project \
ghcr.io/oss-review-toolkit/ort \
ort --info report \
-i /project/ort-results/evaluation-result.yml \
-o /project/compliance-output \
-f NoticeTemplate,SpdxDocument,StaticHtml
echo "Pipeline Complete. Check ./compliance-output"
Phase 4: Deep Dive on Features
1. Copyleft Triggers
In the ort.yml configuration above, the prohibit_in_license_finding section handles this.
- Logic: If the scanner finds
GPL-3.0, the evaluate step (Step 4 in the script) will return a non-zero exit code, causing the CI/CD pipeline to fail.
- Workflow: The developer sees the build fail. They must either remove the library, replace it with a permissive alternative, or get a legal exception approved.
2. Dual Licensing Handling
This is handled by license_choices in the config.
- Scenario: A library is
LGPL-2.1 OR Commercial.
- Automation: The pipeline checks if a commercial license file exists. If configured correctly, it automatically chooses the
Commercial path during the evaluation phase, meaning the LGPL obligations are ignored for that specific build because the "Commercial" terms override them.
3. Attribution Files
We generate this in Step 5 using the NoticeTemplate formatter.
- Input: It aggregates all
MIT, Apache, and BSD libraries found.
- Output: A single
NOTICE.txt file containing the copyright statements and license text for all third-party components, which you then bundle with your software release.
Phase 5: The Approval Workflow (Human-in-the-Loop)
For the "Approvals" requirement, you shouldn't just automate everything. You need an exception process.
The Workflow:
- Gatekeeper: The Pipeline fails on a "Forbidden" license (e.g., GPL).
- Intervention: The Developer creates a Pull Request (PR) to add a
resolutions.yml file.
# resolutions.yml
resolutions:
- message: "Using GPL library for internal tooling only, not distributed."
reason: "DYNAMIC_LINKING_EXCEPTION"
type: "RULE"
matches:
- path: "lib/internal-tool"
- Review: The Open Source Program Office (OSPO) reviews the PR.
- Merge: Once merged, the pipeline runs again, picks up the resolution, and passes.
Summary Checklist for your Repo
- Create a
compliance/ folder.
- Add
ort.yml (Your rules).
- Add
resolutions.yml (Your approved exceptions).
- Add
compliance_pipeline.sh (Your runner).
- Add a GitHub Action / GitLab CI step to run the script on every PR.
# .github/workflows/compliance.yml
name: Compliance Check
on: [push]
jobs:
compliance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Compliance Pipeline
run: ./compliance_pipeline.sh
- name: Upload Attribution
uses: actions/upload-artifact@v3
with:
name: attribution-docs
path: compliance-output/