Skip to content

Add provenance metadata command - #244

Merged
andrew merged 5 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/provenance-checking-110
Jul 20, 2026
Merged

andrew merged 5 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/provenance-checking-110

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #110.

Summary

Adds a new git pkgs provenance command for checking resolved dependency versions against registry provenance and attestation metadata.

The command reports:

  • trusted-publishing attestation metadata when exposed by registry APIs
  • npm registry signatures as a weaker integrity signal
  • missing provenance metadata
  • unsupported ecosystems
  • lookup errors

Details

  • Adds --commit, --branch, --ecosystem, --format=json, and --missing
  • Uses an 8-worker lookup pool with a shared 5-minute timeout
  • Keeps unsupported ecosystems explicit instead of treating missing metadata as verified
  • Documents the new command in the README and internals docs
  • Adds focused unit tests for npm provenance/signature parsing, resolved dependency selection and missing-only filtering

Tests

GOCACHE=/tmp/git-pkgs-gocache go test ./cmd -run Provenance
GOCACHE=/tmp/git-pkgs-gocache go test ./...
GOCACHE=/tmp/git-pkgs-gocache GOLANGCI_LINT_CACHE=/tmp/git-pkgs-golangci-cache go tool golangci-lint run ./...
GOCACHE=/tmp/git-pkgs-gocache go build ./...
git diff --check

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new git pkgs provenance command that inspects resolved dependency versions and queries registries for provenance/attestation signals, then reports trusted-publishing attestations, npm signatures, missing provenance, unsupported ecosystems, and lookup errors. This extends the tool’s “extrinsic data” feature set (network-backed checks) and documents the new capability.

Changes:

  • Introduces git pkgs provenance with flags for commit/branch/ecosystem selection, --missing, and --format=json.
  • Implements concurrent registry lookups with a worker pool and overall timeout, plus text/JSON renderers.
  • Documents the command and adds unit tests for npm parsing and filtering behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Documents the new provenance command and adds usage examples.
docs/internals.md Updates internals docs to describe provenance as an extrinsic, registry-backed lookup (non-cached).
cmd/root.go Registers the new provenance subcommand on the root command.
cmd/provenance.go Implements the provenance command, registry lookups, concurrency, and output formatting.
cmd/provenance_test.go Adds unit tests for npm provenance/signature handling and --missing filtering.
cmd/pager_test.go Ensures the new command is included in pager-flag acceptance coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/provenance.go Resolved

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for four issues:

  1. [P1] PyPI provenance is queried through the wrong API. lookupPyPIProvenance requests the legacy /pypi/<project>/<version>/json endpoint and scans it for a provenance key, but PyPI exposes file attestations through the Simple Index and Integrity API. This produces false negatives: PyPI's documented attested example, sampleproject@4.0.0, has no provenance field in that release JSON, so this command reports it as missing. Please use the supported per-file provenance API and account for release files individually. References: https://docs.pypi.org/attestations/consuming-attestations/ and https://docs.pypi.org/api/integrity/

  2. [P1] The RubyGems V2 version endpoint does not expose a per-release attestation or trusted-publishing signal. Scanning its ordinary metadata for generic provenance keys therefore cannot distinguish trusted-published releases and reports them as missing. Please report RubyGems as unsupported until there is a reliable per-release API, or use such an API if one exists. References: https://guides.rubygems.org/rubygems-org-api-v2/ and https://guides.rubygems.org/trusted-publishing/

  3. [P2] runProvenance bypasses the format validation now used on current main. After merging current main, git pkgs provenance --format yaml succeeds and silently emits text. Please use getFormatFlag(cmd, formatText, formatJSON) and add provenance to the unsupported-format regression coverage.

  4. Please separate the registry implementations before merging this command. Keep the Cobra/database orchestration and output in cmd/provenance.go, and move package-neutral types, shared HTTP behavior, dispatch, and ecosystem checkers into a provenance package, with separate files and tests for npm, PyPI, and RubyGems (for example internal/provenance/{types,client,npm,pypi,rubygems}.go). Avoid Cobra and database dependencies in that package so it can be extracted into its own module later without another large rewrite.

The exact head and a clean merge with current main both pass go test ./..., but the existing mocked tests do not exercise PyPI or RubyGems.

@abhinavgautam01
abhinavgautam01 force-pushed the feature/provenance-checking-110 branch from 362aad4 to b6c0f74 Compare July 14, 2026 04:01
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Fixed all four items and rebased onto current main.

  1. PyPI now uses the release JSON only to enumerate a version's files, then queries PyPI's supported per-file Integrity API endpoint for each artifact. A release is reported as trusted-published only when every release file has attestation bundles; partial or absent coverage is reported as missing.

  2. RubyGems is now reported as unsupported without calling the V2 version endpoint, since it does not expose reliable per-release provenance signals.

  3. provenance now validates --format through getFormatFlag(cmd, formatText, formatJSON). Added it to the unsupported-format regression coverage.

  4. Extracted shared types, HTTP handling, dispatch, and ecosystem-specific implementations into internal/provenance, with separate npm, PyPI and RubyGems files and tests. The package has no Cobra or database dependency.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewing b6c0f74: the four earlier requests are resolved, and both the exact head and a clean merge with current main pass the full test suite and lint. One blocking correctness issue remains:

  1. [P1] npm attestation metadata is not proof of trusted publishing. internal/provenance/npm.go:21 maps any non-empty dist.attestations (or dist.provenance) to trusted_publishing, but npm supported token-authenticated npm publish --provenance long before OIDC trusted publishing; trusted publishing only makes provenance generation automatic. A concrete false positive is sigstore@1.0.0: it was published on 2023-02-09 and exposes dist.attestations, so this implementation reports it as trusted-published even though npm trusted publishing became generally available on 2025-07-31. This also misses issue #110s requested distinction between OIDC publishing and manual/token uploads. Please either report npm attestations as an attested/provenance signal without claiming trusted publishing, or use a registry signal that actually identifies OIDC authentication if one is available.

References: https://docs.npmjs.com/generating-provenance-statements/ and https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

npm dist.attestations and dist.provenance now produce a distinct attested status instead of trusted_publishing, with trusted_publishing: false. The evidence explains that npm registry metadata does not verify the publishing authentication method, so it cannot distinguish OIDC trusted publishing from manual or token-authenticated uploads.

The command now reports an attested_dependencies summary count, while attested npm releases remain visible with --missing because they do not have a verified trusted-publishing signal. Registry signatures are counted independently. Added regression coverage for the npm attestation classification and updated the README wording.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The npm change is right: dist.attestations now maps to StatusAttested with TrustedPublishing=false, StatusTrustedPublishing is only reachable via PyPI (where PEP 740 requires it), and the summary/evidence make the distinction clear. Tests, tidy, and lint pass on a clean merge with current main.

One remaining UX issue before merge: --missing still only filters StatusTrustedPublishing (cmd/provenance.go:282). Now that npm never returns that status, git pkgs provenance --missing on an npm-only project lists every dependency, attested or not, so the flag stops narrowing anything. The point of --missing is to surface packages that lack provenance metadata so users can chase upstream; attested packages have that metadata, they just cannot prove OIDC authentication.

Please have --missing also skip StatusAttested:

if showMissing && (data.Status == provenanceStatusTrustedPublishing || data.Status == provenanceStatusAttested) {
    continue
}

and update TestBuildProvenanceResultMissingFilter so the attested entry is excluded from result.Dependencies under showMissing=true (expected length drops back to 2). The summary counts already separate attested from without_provenance, so this keeps the flag consistent with the summary buckets.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Thanks...

  • --missing now excludes both trusted_publishing and attested results, so it surfaces only dependencies that lack provenance metadata or have weaker/error/unsupported outcomes.

  • Updated TestBuildProvenanceResultMissingFilter to assert the attested dependency is excluded while the summary still reports it separately through attested_dependencies.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--missing now filters StatusAttested alongside StatusTrustedPublishing, and TestBuildProvenanceResultMissingFilter asserts the attested entry is excluded. Merges cleanly with current main (2a373da); build and tests pass on the merged tree.

@andrew
andrew merged commit 9f0effa into git-pkgs:main Jul 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attestation and provenance checking

3 participants