patchstack-audit

module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0

README

PatchStack Audit

PatchStack Audit checks that a set of patches can be applied, in a specified order, to an exact copy of local source code. You provide a source archive, patches and a YAML manifest containing their SHA-256 hashes. The tool verifies those inputs, applies the patches and saves the resulting source tree alongside JSON and Markdown reports.

Use it from the command line or through the Go library at pkg/patchstack. Given the same accepted inputs, it produces identical reports and a matching hash of the final source tree.

A successful audit shows that the declared patches reproduce a particular source tree. Hashes identify the bytes used; they do not establish who supplied them. The audit does not determine whether a vulnerability is fixed, a CVE applies, the software builds or works, or a compliance requirement is met. It uses local inputs and does not download fixes, build software or run the software's tests.

Install the CLI

Release v0.1.2 includes source archives, Linux binaries for amd64 and arm64, and a SHA256SUMS file. The binary archives include a ready-to-run example and do not require Go. See the archive instructions for checksum verification and an example command.

To install with Go on Linux, use Go 1.27.4 and enable network access for this step:

GOTOOLCHAIN=go1.27.4 GOPROXY=https://proxy.golang.org GOSUMDB=sum.golang.org \
  go install github.com/firmdura/patchstack-audit/cmd/patchstack@v0.1.2

Add Go's installation directory for executables to your PATH so you can run patchstack. GNU patch is also required, whichever installation method you use. See the Go API reference for v0.1.2 for the library's exported types and functions.

Build and try the example

The tool runs on Linux. Building from source requires Go 1.27.4; the tested GNU patch version is 2.7.6. Linux must expose /proc/<pid>/fd to the tool and its GNU patch child process. The output filesystem must support an atomic rename that refuses to replace an existing destination. This lets the tool make the complete result visible at once without overwriting other files.

On macOS or Windows, use the local Linux container workflow, which requires Docker and a POSIX shell.

On Linux, first make sure go on your PATH is Go 1.27.4. From the repository root, download the pinned dependency while network access is enabled:

GOTOOLCHAIN=go1.27.4 go mod download

Then build and run the example offline:

export GOTOOLCHAIN=local GOPROXY=off GOSUMDB=off GOFLAGS=-mod=readonly
go build -o bin/patchstack ./cmd/patchstack
work=$(mktemp -d)
go run ./examples/demo --output "$work/inputs"
./bin/patchstack audit \
  --manifest "$work/inputs/stack.yaml" \
  --input-root "$work/inputs" \
  --output "$work/result" \
  --format json > "$work/stdout.json"
cmp "$work/stdout.json" "$work/result/report.json"

The generator creates a tiny C source archive, two patches and a manifest with their actual hashes. All example source and patches are original to this project. Both patches use local:demonstration to describe their origin; the example makes no claim about a real CVE. You do not need a C compiler to run it.

After a successful run, $work/result contains:

source/       the complete patched source tree
report.json   the JSON report
report.md     the Markdown report

The output directory must be new, its parent must already exist, and it must be outside the input directory. Both reports are saved regardless of --format; that flag selects the report also printed to standard output.

Always check the command's exit status:

Status Meaning
0 Input verification, patch application and output publication succeeded.
1 An input hash, patch directory inventory or patch application did not match the declaration. No output was published.
2 A usage or operational error occurred.

If writing to standard output fails after the result has been published, the command returns 2, keeps the complete result and prints its location to standard error. See troubleshooting for other errors and cleanup behavior.

Read more

License

Original code and the original example and test fixtures use Apache-2.0. The YAML dependency retains its third-party notices. Binary archives also include the Go runtime's BSD-3-Clause license and PATENTS grant, copied verbatim from Go 1.27.4. These notices accompany binary distributions. References to upstream patches do not change the licenses of third-party inputs.

Directories

Path Synopsis
cmd
patchstack command
Command patchstack checks and reproduces a declared series of local patches.
Command patchstack checks and reproduces a declared series of local patches.
examples
demo command
Command demo generates inputs for the original two-patch example.
Command demo generates inputs for the original two-patch example.
demo/fixtures
Package fixtures generates repeatable inputs for the local two-patch example.
Package fixtures generates repeatable inputs for the local two-patch example.
internal
cli
Package cli reads command-line arguments and runs audits through the shared API.
Package cli reads command-line arguments and runs audits through the shared API.
contracts
Package contracts defines the shared version 1 types, validation rules and component interfaces.
Package contracts defines the shared version 1 types, validation rules and component interfaces.
executor
Package executor applies a complete verified series to a private prepared workspace using real GNU patch on Linux.
Package executor applies a complete verified series to a private prepared workspace using real GNU patch on Linux.
inputfs
Package inputfs provides the retained, read-only input root used during preparation.
Package inputfs provides the retained, read-only input root used during preparation.
patchinput
Package patchinput verifies a complete patch directory and freezes its declared bytes into private staging.
Package patchinput verifies a complete patch directory and freezes its declared bytes into private staging.
publish
Package publish keeps a completed output package private until one Linux atomic no-replace rename makes it visible at the requested destination.
Package publish keeps a completed output package private until one Linux atomic no-replace rename makes it visible at the requested destination.
source
Package source freezes and verifies a declared source archive before extracting regular files and directories into a caller-owned private empty workspace.
Package source freezes and verifies a declared source archive before extracting regular files and directories into a caller-owned private empty workspace.
treedigest
Package treedigest computes the version 1 canonical source tree inventory and restores intended publication modes only after readable content is hashed.
Package treedigest computes the version 1 canonical source tree inventory and restores intended publication modes only after readable content is hashed.
pkg
patchstack
Package patchstack verifies a local source archive and applies a declared sequence of patches using GNU patch on Linux.
Package patchstack verifies a local source archive and applies a declared sequence of patches using GNU patch on Linux.
scripts
acceptance command
Command acceptance exercises the real CLI with original local fixtures.
Command acceptance exercises the real CLI with original local fixtures.
librarycheck command
This program is copied into a temporary external module by test-library.sh.
This program is copied into a temporary external module by test-library.sh.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL