Metadata-Version: 2.4
Name: pinstack
Version: 0.4.1
Summary: Supply-chain dependency pinning enforcement for every ecosystem
Author: Trevor Tonn
License: Apache-2.0
Project-URL: Homepage, https://github.com/a4899e/pinstack
Project-URL: Repository, https://github.com/a4899e/pinstack
Project-URL: Bug Tracker, https://github.com/a4899e/pinstack/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Dynamic: license-file

# pinstack

Supply-chain dependency pinning enforcement for every ecosystem.

pinstack scans a project directory and reports unpinned or loosely-pinned
dependencies across the most common package managers, container formats, and
infrastructure tools. It is designed to drop into any CI pipeline with a single
command and zero setup beyond `pip install pinstack`.

---

## Why This Matters

A version range is a promise someone else can rewrite. `requests>=2.28`,
`FROM python:3.11-slim`, and `uses: actions/checkout@v4` all resolve to
whatever bytes the registry serves at the moment of the build, and that answer
can change without the version string changing at all. A hijacked maintainer
account, a re-pushed tag, a typosquat that wins a resolution race, or a
compromised mirror each produce a build that is green, correct according to the
manifest, and running code nobody reviewed.

Pinning to an exact version narrows that window. Pinning to a *hash* closes it:
a digest names the content itself, so substituted bytes fail the build loudly
instead of shipping silently. That is the difference between a build that is
reproducible and one that merely looks reproducible.

The catch is that every ecosystem spells this differently -- `==` plus `--hash`
in pip, `integrity` in npm, `@sha256:` in Docker, a 40-character commit SHA in
GitHub Actions, `h1:` in Go and Terraform. A real repository uses several at
once, and one unpinned entry reopens the window. pinstack checks all of them in
a single pass, so "is this repository actually pinned?" becomes a question with
a yes-or-no answer you can put in CI.

---

## Project Goals

**1. Broad ecosystem coverage**

pinstack understands as many project and language types as possible. A single
invocation on a monorepo surfaces pinning issues in Python packages, Node
modules, Docker images, Go modules, Rust crates, Ruby gems, Terraform providers,
Helm charts, and more.

**2. Zero dependencies**

pinstack has no runtime dependencies outside the Python standard library. It
runs on any system's `python3` (3.9 or later) without a virtual environment or
any other setup step. This makes it practical to adopt in non-Python projects
where adding a Python dependency tree would be unwelcome.

**3. CLI-only configuration**

There are no config files to maintain. Every behaviour is controlled by flags
passed on the command line. What you see in the command is what it does, making
pinstack easy to audit, reproduce, and reason about in CI logs.

---

## Installation

```
pip install pinstack
```

Because pinstack has zero runtime dependencies, it can also be run directly
from a checkout without installation. Run it from the checkout root:

```
git clone https://github.com/a4899e/pinstack.git
cd pinstack
python3 -m pinstack .
```

To scan a project elsewhere without installing, put the checkout root on
`PYTHONPATH`:

```
PYTHONPATH=/path/to/pinstack python3 -m pinstack /path/to/project
```

---

## Quick Start

Scan the current directory:

```
pinstack .
```

Only check Python and Docker dependency files:

```
pinstack . --check requirements,pyproject,dockerfile
```

Output as SARIF for GitHub Code Scanning integration:

```
pinstack . --format sarif > results.sarif
```

---

## Supported Ecosystems

Sixteen checkers, run in a single pass. Where a manifest and a lock file both
exist, pinstack also cross-references them: a dependency declared in the
manifest but absent from the lock file means the lock file is stale, which
silently defeats the pinning it was supposed to guarantee.

| Checker | Files Examined | What Is Checked |
|---|---|---|
| `requirements` | `requirements*.txt`, and every file they include with `-r` | `==` pinning and a valid `--hash` (sha256, sha384 or sha512 with the full hex digest) on every requirement and `-e` install. Lines are read as pip reads them. Includes are followed relative to the including file, even outside the `requirements*.txt` glob; one that is missing or unreadable, an `http(s):` URL, outside the scan root, or built from a `${VAR}` is reported. Bare URLs and local paths need a valid `--hash`. The requirement lines of `-c` constraint files install nothing and are not checked, but their `-r` includes are followed |
| `pyproject` | `pyproject.toml`, plus `requirements*.txt`, `poetry.lock`, `pdm.lock`, `uv.lock` | `==` exact pins (no `==2.*` wildcards) in `[project]`, `[project.optional-dependencies]`, `[dependency-groups]`, and `[tool.poetry]`, whether written as sections, inline tables, or dotted keys, and including Poetry's table and multi-constraint forms; a companion lock file must exist and must not be stale. A lock file that parses to no packages is reported. |
| `package_json` | `package.json`, plus `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml` | Every dependency is an exact `x.y.z` version, a local reference (`workspace:`, `file:`, `link:`, a path), an `npm:<name>@x.y.z` alias, or a git source fixed to a full 40-character commit SHA; anything else (`^`, `~`, `*`, `latest`, `1.x`, ranges, tarball URLs, branch or tag refs) is a finding. The same rules apply to `overrides`, `resolutions`, and `pnpm.overrides`. Declared packages must appear in the lock file |
| `package_lock` | `package-lock.json` | `integrity` hashes present on all packages |
| `yarn_lock` | `yarn.lock` | Integrity checksums present |
| `pnpm_lock` | `pnpm-lock.yaml` | `integrity` hashes present |
| `dockerfile` | `Dockerfile*`, `Containerfile*`, `*.dockerfile`, `*.Dockerfile` | `@sha256:` digest on every image the build pulls: the `# syntax=` frontend, `FROM`, `COPY`/`ADD --from`, and `RUN --mount=from=`, including under `ONBUILD`. A bare name such as `alpine` is an image unless declared as a stage with `AS` or as a named context with `--build-context`, and `$VAR` references are reported because `--build-arg` can override them. A digest must be exactly 64 lowercase hex characters |
| `compose` | `docker-compose*.yml`, `docker-compose*.yaml`, `compose*.yml`, `compose*.yaml` | `@sha256:` digest (64 lowercase hex) on every `image:`, in block or flow style, including images set through YAML anchors; `$VAR` interpolation that could replace the digest is reported |
| `github_actions` | `*.yml` and `*.yaml` under `.github/workflows/`; `action.yml` / `action.yaml` anywhere | 40-char commit SHA after `@` in every step and reusable-workflow `uses:` (block or flow style, quoted keys, YAML aliases), including composite actions' steps; `@sha256:` digest on `docker://` actions, job `container` images, service images, and Docker actions' `runs.image` |
| `go` | `go.mod`, `go.sum` | `go.sum` exists alongside `go.mod`; `h1:` hashes present; every `require` appears in `go.sum` |
| `cargo` | `Cargo.lock`, `Cargo.toml` | `checksum` field on each registry `[[package]]`; every `Cargo.toml` dependency appears in `Cargo.lock`; a `Cargo.toml` with dependencies needs a `Cargo.lock` beside it or, for a workspace member, in the workspace root, where its dependencies must also appear |
| `gemfile` | `Gemfile`, `Gemfile.lock` | Lock file exists alongside `Gemfile`; every declared gem appears in it |
| `terraform` | `.terraform.lock.hcl`, `*.tf` | `h1:` hashes present per provider; a root module (a directory whose `.tf` files declare `required_providers` or configure a `provider`, `backend`, or `cloud`, and that no other scanned module calls via a local `source`) needs a `.terraform.lock.hcl` that locks every provider it requires |
| `helm` | `Chart.yaml`, `Chart.lock` | Every `Chart.yaml` dependency has one exact semver version (no `1.x`, `^1.2.0`, `>=1.0` or partial `1.2`; `file://` charts are exempt); `Chart.lock` exists, lists every dependency at an exact version, and carries its `digest:` line. That digest detects drift between `Chart.yaml` and the lock; it is not a hash of chart content, so these findings are not reported as integrity findings |
| `maven` | `pom.xml`, `.mvn/extensions.xml` | Exact `<version>` on every dependency, plugin (including `pluginManagement`, `reporting` and old-style `reportPlugins`), build or core extension, `<parent>`, and the artifacts a plugin resolves from its configuration (`annotationProcessorPaths`, javadoc taglet/doclet artifacts) -- no ranges, `LATEST`/`RELEASE`, `SNAPSHOT`, unresolvable `${property}` references, or missing versions. A plugin or dependency with no version passes only when the same POM's top-level `pluginManagement` / `dependencyManagement` declares it; a version managed by a parent POM is reported as missing. Any POM namespace (4.0.0, 4.1.0) is read; in a 4.1.0 model the `<parent>` and same-build modules may omit versions. Files with a DOCTYPE are reported, not parsed |
| `gradle` | `*.gradle`, `*.gradle.kts`, `gradle.lockfile`, `buildscript-gradle.lockfile`, `*.versions.toml` | Exact versions in every build script (including ones pulled in with `apply from:`) and in version catalogs (`libs.versions.toml`) -- no dynamic (`+`, `latest.*`), range, `SNAPSHOT`, or unresolvable `$variable` versions, including inside `platform(...)`; `build.gradle(.kts)` needs a `gradle.lockfile` that is not stale (buildscript `classpath` entries need a `buildscript-gradle.lockfile` and are cross-referenced against it). `libs.<alias>` references are checked through the catalog, not cross-referenced against the lockfile |

Run `pinstack --list-checkers` to print this list from the installed version.

---

## CLI Reference

```
pinstack [PATH] [OPTIONS]
```

| Option | Description |
|---|---|
| `PATH` | Directory to scan. Defaults to `.` (current directory). |
| `--check NAME,NAME` | Only run these checkers (comma-separated). Mutually exclusive with `--exclude`. |
| `--exclude NAME,NAME` | Skip these checkers (comma-separated). Mutually exclusive with `--check`. |
| `--format FORMAT` | Output format: `text` (default) or `sarif`. |
| `--exit-zero` | Always exit 0, even when findings are present. Useful for advisory-only runs. |
| `--max-depth N` | Maximum directory depth to check. Default: 4 (the scan root is depth 0, so files up to three directories down are checked). Deeper directories are still walked until a dependency file is found there; that file is reported as a `pinstack` finding (`scan incomplete`), so the gate fails rather than passing on a partial scan. Increase for deep monorepos. |
| `--max-files N` | Maximum number of dependency files to check. Default: 384. Directories are indexed whole, so a manifest is never checked without its lock file. Reaching the limit is reported as a `pinstack` finding (`scan incomplete`) on the first file left unchecked. Increase for large monorepos. |
| `--exclude-dir DIR,DIR` | Additional directory names to skip during traversal (comma-separated). |
| `--build-context NAME,NAME` | BuildKit named contexts the build supplies with `docker buildx build --build-context NAME=...`. A Dockerfile may refer to these names in `FROM`, `COPY`/`ADD --from` and `RUN --mount=from=` as it would a stage. Names must be valid stage names (letters, digits, `.`, `_`, `-`), so a tagged image such as `alpine:3.18` cannot be declared. Put the flag next to the build command that supplies the contexts. Comma-separated; may be repeated. |
| `--list-checkers` | Print all available checkers and exit. |
| `--version` | Print the pinstack version and exit. |

### Exit Codes

| Code | Meaning |
|---|---|
| `0` | No findings (or `--exit-zero` was set). |
| `1` | One or more findings reported. This includes a scan that `--max-depth` or `--max-files` left incomplete. |
| `2` | Runtime error. |

---

## Output Formats

### text (default)

Human-readable output suitable for local development and CI logs:

```
FAIL  Dockerfile:1  FROM 'python:3.11-slim' is not pinned with @sha256: digest
FAIL  go.mod  go.mod has no corresponding go.sum; run 'go mod tidy'
FAIL  requirements.txt:1  'requests' is not pinned with ==; use package==version

3 errors in 3 files
```

Findings without a meaningful line number (a missing lock file, for instance)
are reported against the file alone.

### sarif

SARIF 2.1.0 JSON, consumable by GitHub Code Scanning, GitLab SAST, and other
tools that support the standard.

---

## CI Integration

pinstack is a standalone CLI tool, not a library. It works with any project
regardless of language. Python 3.9+ is the only requirement, and it ships on
virtually every CI runner out of the box.

### GitHub Actions

```yaml
name: Supply Chain Check
on: [push, pull_request]

jobs:
  pinstack:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29

      - name: Set up Python
        uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d
        with:
          python-version: "3.x"

      - name: Install pinstack
        run: pip install pinstack

      - name: Check dependency pinning
        run: pinstack .
```

To upload results to GitHub Code Scanning:

```yaml
      - name: Check dependency pinning (SARIF)
        run: pinstack . --format sarif > pinstack.sarif
        continue-on-error: true

      - name: Upload SARIF
        uses: github/codeql-action/upload-sarif@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d
        with:
          sarif_file: pinstack.sarif
```

### GitLab CI

```yaml
pinstack:
  stage: test
  image: python:3-slim
  before_script:
    - pip install pinstack
  script:
    - pinstack .
```

To integrate with GitLab SAST, output SARIF and use the
[SAST report artifact](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html):

```yaml
pinstack:
  stage: test
  image: python:3-slim
  before_script:
    - pip install pinstack
  script:
    - pinstack . --format sarif > gl-sast-report.json || true
  artifacts:
    reports:
      sast: gl-sast-report.json
```

### Python Projects (Invoke)

Add a task to your `tasks.py`:

```python
from invoke import task


@task
def supply_chain(c):
    """Check dependency pinning."""
    c.run("pinstack .")
```

Then run it with `invoke supply-chain` or include it in your build task:

```python
@task(pre=[lint, typecheck, test, supply_chain])
def build(c):
    """Full build pipeline."""
    pass
```

### Any Project

pinstack runs anywhere Python 3.9+ is available. No virtual environment needed,
no dependencies to install beyond pinstack itself.
CI tests it on Python 3.11, 3.12, 3.13 and 3.14.

**With pip:**

```
pip install pinstack
pinstack .
```

**Without pip (clone and run directly):**

```
git clone https://github.com/a4899e/pinstack.git /tmp/pinstack
PYTHONPATH=/tmp/pinstack python3 -m pinstack .
```

`PYTHONPATH` must point at the checkout root, not at the inner `pinstack/`
package directory.

**Check only specific ecosystems:**

```
# Java project -- only check Maven and Gradle
pinstack . --check maven,gradle

# Node project -- only check JS ecosystem
pinstack . --check package_json,package_lock,yarn_lock,pnpm_lock

# Docker-only check
pinstack . --check dockerfile,compose
```

**Skip directories that contain third-party code:**

```
pinstack . --exclude-dir vendor,third_party,checkouts
```

---

## Contributing

1. Fork the repository at https://github.com/a4899e/pinstack
2. Create a branch from `main`
3. Add tests for any new checker or behaviour
4. Open a pull request against `main`

Development setup (requires Python 3.11+ and [uv](https://docs.astral.sh/uv/)):

```
./scripts/dev-setup.sh
```

> **Note:** pinstack *runs* on Python 3.9+, but *development* requires 3.11+
> because some build-chain tools need it (filelock's security fixes require
> 3.11).

### Running Tests

```
uv run inv test                              # run the full test suite
uv run python -m pytest tests/ -v            # or run pytest directly
uv run python -m pytest tests/test_checker_go.py  # run a single test file
```

### Build Pipeline

The pre-commit hook runs `uv run inv build` before each commit. You can also
run it manually:

```
uv run inv lint          # ruff check + ruff format --check + pyright
uv run inv security      # pinstack self-scan + bandit + pip-audit + detect-secrets
uv run inv test          # pytest
uv run inv build         # clean + lint + security + test (full CI gate)
uv run inv clean         # remove .pyc, caches, build artifacts
```

---

## License

Copyright 2026 Trevor Tonn. Licensed under the Apache License 2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE).

Copyright 2024 Trevor T. <trevort@scantonomous.ai>
