perquisition 0.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- perquisition-0.7.1/.github/workflows/ci.yml +40 -0
- perquisition-0.7.1/.github/workflows/publish.yml +124 -0
- perquisition-0.7.1/.gitignore +25 -0
- perquisition-0.7.1/AGENTS.md +97 -0
- perquisition-0.7.1/PKG-INFO +403 -0
- perquisition-0.7.1/README.md +394 -0
- perquisition-0.7.1/SPECS.md +427 -0
- perquisition-0.7.1/pyproject.toml +55 -0
- perquisition-0.7.1/src/perquisition/__init__.py +7 -0
- perquisition-0.7.1/src/perquisition/cli.py +376 -0
- perquisition-0.7.1/src/perquisition/data/grype.yaml +16 -0
- perquisition-0.7.1/src/perquisition/db.py +523 -0
- perquisition-0.7.1/src/perquisition/envelope.py +133 -0
- perquisition-0.7.1/src/perquisition/findings.py +1078 -0
- perquisition-0.7.1/src/perquisition/grype.py +208 -0
- perquisition-0.7.1/src/perquisition/sbom.py +426 -0
- perquisition-0.7.1/src/perquisition/schema/envelope.schema.json +182 -0
- perquisition-0.7.1/src/perquisition/semver.py +172 -0
- perquisition-0.7.1/src/perquisition/snapshot.py +99 -0
- perquisition-0.7.1/src/perquisition/view.py +337 -0
- perquisition-0.7.1/tests/conftest.py +215 -0
- perquisition-0.7.1/tests/fixtures/UPSTREAM +3 -0
- perquisition-0.7.1/tests/fixtures/audit-accounts.json +786 -0
- perquisition-0.7.1/tests/fixtures/audit-ip.json +3085 -0
- perquisition-0.7.1/tests/fixtures/audit-offline.json +803 -0
- perquisition-0.7.1/tests/fixtures/audit-supervisors.json +718 -0
- perquisition-0.7.1/tests/fixtures/grype-report-debian12.json +8271 -0
- perquisition-0.7.1/tests/fixtures/regenerate-grype.sh +18 -0
- perquisition-0.7.1/tests/fixtures/root/etc/group +8 -0
- perquisition-0.7.1/tests/fixtures/root/etc/os-release +9 -0
- perquisition-0.7.1/tests/fixtures/root/etc/passwd +8 -0
- perquisition-0.7.1/tests/fixtures/root/etc/shadow +7 -0
- perquisition-0.7.1/tests/fixtures/root/var/lib/dpkg/status +30 -0
- perquisition-0.7.1/tests/fixtures/sanitize.py +60 -0
- perquisition-0.7.1/tests/fixtures/sanitize_grype.py +60 -0
- perquisition-0.7.1/tests/fixtures/sbom-debian12.json +93 -0
- perquisition-0.7.1/tests/test_accounts_fixture.py +133 -0
- perquisition-0.7.1/tests/test_cli.py +77 -0
- perquisition-0.7.1/tests/test_cli_grype.py +275 -0
- perquisition-0.7.1/tests/test_container_inventory.py +266 -0
- perquisition-0.7.1/tests/test_contract_pin.py +170 -0
- perquisition-0.7.1/tests/test_db.py +189 -0
- perquisition-0.7.1/tests/test_envelope.py +148 -0
- perquisition-0.7.1/tests/test_findings.py +628 -0
- perquisition-0.7.1/tests/test_grype_real.py +67 -0
- perquisition-0.7.1/tests/test_grype_runner.py +156 -0
- perquisition-0.7.1/tests/test_grype_store.py +147 -0
- perquisition-0.7.1/tests/test_ip_collector.py +134 -0
- perquisition-0.7.1/tests/test_provenance_coverage.py +43 -0
- perquisition-0.7.1/tests/test_sbom.py +202 -0
- perquisition-0.7.1/tests/test_semver.py +91 -0
- perquisition-0.7.1/tests/test_snapshot.py +116 -0
- perquisition-0.7.1/tests/test_supervisors_fixture.py +153 -0
- perquisition-0.7.1/tests/test_upgrade_tool.py +155 -0
- perquisition-0.7.1/tests/test_view.py +225 -0
- perquisition-0.7.1/tools/refresh-upstream +136 -0
- perquisition-0.7.1/tools/release +209 -0
- perquisition-0.7.1/tools/upgrade-upstream +430 -0
- perquisition-0.7.1/uv.lock +306 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Lint and the suite. Two gates, offline: ruff never needs the network, and
|
|
2
|
+
# neither does pytest — the grype test skips itself where grype is absent.
|
|
3
|
+
name: ci
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
checks:
|
|
14
|
+
name: ruff and the suite
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
# Actions pinned by commit SHA, tags are the comment: a tag can be moved,
|
|
18
|
+
# the job must not change because a third party published a release.
|
|
19
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
20
|
+
# 3.11 is `requires-python`'s floor (SPECS §10.3): the oldest interpreter
|
|
21
|
+
# this library claims to support is the one CI must prove it runs on.
|
|
22
|
+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.11"
|
|
25
|
+
# uv is the only thing pinned outside uv.lock, because uv reads it.
|
|
26
|
+
# Every version ruff, pytest and jsonschema resolve to comes from the
|
|
27
|
+
# lockfile — one source, and `--locked` fails the job when pyproject and
|
|
28
|
+
# uv.lock disagree instead of silently re-resolving them.
|
|
29
|
+
- name: install uv
|
|
30
|
+
run: python -m pip install "uv==0.13.10"
|
|
31
|
+
- name: sync exactly what uv.lock says
|
|
32
|
+
run: uv sync --locked --all-groups
|
|
33
|
+
# ruff itself is a dev dependency, so this is the pinned version, not the
|
|
34
|
+
# runner's: the same `uv run ruff` a developer runs at home.
|
|
35
|
+
- name: ruff check
|
|
36
|
+
run: uv run ruff check .
|
|
37
|
+
- name: ruff format
|
|
38
|
+
run: uv run ruff format --check .
|
|
39
|
+
- name: pytest
|
|
40
|
+
run: uv run pytest
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Publish on a tag: the tag is the release, and the release is what PyPI gets.
|
|
2
|
+
# `v*` is the only push that reaches it — a branch push must never upload.
|
|
3
|
+
#
|
|
4
|
+
# Trusted Publishing, no stored token: PyPI mints a short-lived credential from
|
|
5
|
+
# this job's OIDC identity, so there is no `PYPI_TOKEN` secret to leak, rotate
|
|
6
|
+
# or forget. PyPI must know this workflow before the first upload
|
|
7
|
+
# (https://pypi.org/manage/account/publishing/ — a *pending* publisher while
|
|
8
|
+
# the project does not exist yet):
|
|
9
|
+
#
|
|
10
|
+
# project name: perquisition # free when this file was written
|
|
11
|
+
# owner: athoune
|
|
12
|
+
# repository: perquisition-python
|
|
13
|
+
# workflow: publish.yml
|
|
14
|
+
# environment: pypi # the one named on the job below
|
|
15
|
+
#
|
|
16
|
+
# The manual dispatch is the bootstrap, and nothing else: a tag cut before this
|
|
17
|
+
# file existed (v0.7.0) has no workflow at its commit — GitHub reads the
|
|
18
|
+
# workflow from the tagged tree — so it can only be published by asking for it
|
|
19
|
+
# here, with the same gates and the same version check.
|
|
20
|
+
name: publish
|
|
21
|
+
|
|
22
|
+
on:
|
|
23
|
+
push:
|
|
24
|
+
tags:
|
|
25
|
+
- "v*"
|
|
26
|
+
workflow_dispatch:
|
|
27
|
+
inputs:
|
|
28
|
+
tag:
|
|
29
|
+
description: "Release tag to publish (must already be pushed)"
|
|
30
|
+
required: true
|
|
31
|
+
type: string
|
|
32
|
+
|
|
33
|
+
permissions:
|
|
34
|
+
contents: read
|
|
35
|
+
|
|
36
|
+
jobs:
|
|
37
|
+
publish:
|
|
38
|
+
name: build and publish
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
# The trusted publisher is registered for this repository only: a mirror
|
|
41
|
+
# that copies the tag has nothing to exchange, and should say so early.
|
|
42
|
+
if: github.repository == 'athoune/perquisition-python'
|
|
43
|
+
environment:
|
|
44
|
+
name: pypi
|
|
45
|
+
url: https://pypi.org/p/perquisition
|
|
46
|
+
permissions:
|
|
47
|
+
# The OIDC token PyPI exchanges for a short-lived upload credential.
|
|
48
|
+
id-token: write
|
|
49
|
+
contents: read
|
|
50
|
+
env:
|
|
51
|
+
# A tag push names the tag; the manual dispatch names it in the input.
|
|
52
|
+
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
|
|
53
|
+
steps:
|
|
54
|
+
# Actions pinned by commit SHA, tags are the comment: a tag can be moved,
|
|
55
|
+
# the job must not change because a third party published a release.
|
|
56
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
57
|
+
with:
|
|
58
|
+
ref: ${{ env.RELEASE_TAG }}
|
|
59
|
+
# Same interpreter as ci.yml: `requires-python`'s floor (SPECS §10.3).
|
|
60
|
+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
|
|
61
|
+
with:
|
|
62
|
+
python-version: "3.11"
|
|
63
|
+
# uv pinned where ci.yml pins it, for the same reason: every version the
|
|
64
|
+
# gates resolve comes from uv.lock, uv itself from one declared version.
|
|
65
|
+
- name: install uv
|
|
66
|
+
run: python -m pip install "uv==0.13.10"
|
|
67
|
+
- name: sync exactly what uv.lock says
|
|
68
|
+
run: uv sync --locked --all-groups
|
|
69
|
+
# The gates, re-run on the tagged tree. ci.yml also runs on a tag push,
|
|
70
|
+
# but an upload must not depend on another workflow's result: these are
|
|
71
|
+
# the same four commands, not a second definition.
|
|
72
|
+
- name: ruff check
|
|
73
|
+
run: uv run ruff check .
|
|
74
|
+
- name: ruff format
|
|
75
|
+
run: uv run ruff format --check .
|
|
76
|
+
- name: pytest
|
|
77
|
+
run: uv run pytest
|
|
78
|
+
# One number, three places: pyproject's version, the `__version__` a
|
|
79
|
+
# program reports, the tag a consumer pins. `tools/release` keeps them in
|
|
80
|
+
# step before it tags; this refuses a tag made by hand.
|
|
81
|
+
- name: the tag names this commit's version
|
|
82
|
+
run: |
|
|
83
|
+
set -eu
|
|
84
|
+
tag="${RELEASE_TAG#v}"
|
|
85
|
+
pyproject="$(uv run python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
|
|
86
|
+
reported="$(uv run python -c 'import perquisition; print(perquisition.__version__)')"
|
|
87
|
+
if [ "$pyproject" != "$reported" ]; then
|
|
88
|
+
echo "error: pyproject says $pyproject, __version__ says $reported" >&2
|
|
89
|
+
exit 1
|
|
90
|
+
fi
|
|
91
|
+
if [ "$tag" != "$pyproject" ]; then
|
|
92
|
+
echo "error: tag v$tag, pyproject says $pyproject" >&2
|
|
93
|
+
exit 1
|
|
94
|
+
fi
|
|
95
|
+
echo "publishing $pyproject as v$tag"
|
|
96
|
+
- name: build
|
|
97
|
+
run: uv build
|
|
98
|
+
# What the wheel owes a consumer: validation *is* the vendored schema
|
|
99
|
+
# being executed (README), so a wheel that lost it would install fine and
|
|
100
|
+
# check nothing. The grype configuration is the other packaged file.
|
|
101
|
+
- name: the wheel carries what it promises
|
|
102
|
+
run: |
|
|
103
|
+
set -eu
|
|
104
|
+
python3 - <<'PY'
|
|
105
|
+
import pathlib, tomllib, zipfile
|
|
106
|
+
|
|
107
|
+
version = tomllib.load(open("pyproject.toml", "rb"))["project"]["version"]
|
|
108
|
+
wheel = pathlib.Path("dist") / f"perquisition-{version}-py3-none-any.whl"
|
|
109
|
+
assert wheel.is_file(), f"missing {wheel}"
|
|
110
|
+
names = set(zipfile.ZipFile(wheel).namelist())
|
|
111
|
+
for required in (
|
|
112
|
+
"perquisition/schema/envelope.schema.json",
|
|
113
|
+
"perquisition/data/grype.yaml",
|
|
114
|
+
f"perquisition-{version}.dist-info/METADATA",
|
|
115
|
+
):
|
|
116
|
+
assert required in names, f"{required} is not in {wheel.name}"
|
|
117
|
+
print(f"{wheel.name}: {len(names)} entries, schema and grype.yaml on board")
|
|
118
|
+
PY
|
|
119
|
+
- name: publish to PyPI
|
|
120
|
+
# Attestations (PEP 740) are produced and uploaded by the action
|
|
121
|
+
# itself: build provenance travels with the files, not in a README.
|
|
122
|
+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
|
|
123
|
+
with:
|
|
124
|
+
packages-dir: dist/
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Python working files: the virtualenv and caches are machine-local, the
|
|
2
|
+
# lockfile is not — uv.lock is committed on purpose (it is this project's
|
|
3
|
+
# vendoring).
|
|
4
|
+
.venv/
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.pyc
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
dist/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
|
|
11
|
+
# Databases are derived artifacts: regenerate with `perquisition-analysis load`.
|
|
12
|
+
# `*.db` is the same artifact under whatever name `--db` was given; left
|
|
13
|
+
# untracked it reads as work this repository does not own, which is what trips
|
|
14
|
+
# tools/upgrade-upstream's preflight.
|
|
15
|
+
*.sqlite
|
|
16
|
+
*.sqlite-journal
|
|
17
|
+
*.db
|
|
18
|
+
audit.json
|
|
19
|
+
run.log
|
|
20
|
+
session-*.md
|
|
21
|
+
# So is a scan: `perquisition-analysis grype` writes its SBOM and report beside
|
|
22
|
+
# the database (`<db>-grype/`), regenerable the same way. The probe ignores
|
|
23
|
+
# `/*-grype/` for the same reason — and stray untracked files here would trip
|
|
24
|
+
# tools/upgrade-upstream's preflight, which refuses work it does not own.
|
|
25
|
+
/*-grype/
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Working on perquisition-python
|
|
2
|
+
|
|
3
|
+
This repository is the reference implementation of the `perquisition` probe's
|
|
4
|
+
envelope contract. It parses audits, projects them into SQLite, and defines the
|
|
5
|
+
findings document — it judges nothing, and it collects nothing.
|
|
6
|
+
|
|
7
|
+
It reads exactly two files from the probe, both copied here at a tag:
|
|
8
|
+
`schema/envelope.schema.json` (the contract, and its source of truth) and a
|
|
9
|
+
sanitised fixture. Everything else it knows about an audit comes from the
|
|
10
|
+
**probe's** `SPECS.md` — §3 (the envelope) and §6 (each collector's `data`),
|
|
11
|
+
with the probe's `DATA-CHANGELOG.md` versioning the latter.
|
|
12
|
+
|
|
13
|
+
Two documents are called `SPECS.md` and they share no section numbers. The one
|
|
14
|
+
at this repository's root is the **library's** spec: its §3 is the findings
|
|
15
|
+
document, its §6 the command line. A bare "§N" in code or a test means that
|
|
16
|
+
document; a citation of the probe says so — "probe SPECS §6.18" — because §6.18
|
|
17
|
+
exists nowhere else.
|
|
18
|
+
|
|
19
|
+
The rule that keeps this honest: **never read the probe's Go source to answer a
|
|
20
|
+
question about the envelope.** If the schema and the probe's §6 cannot answer
|
|
21
|
+
it, the contract is incomplete and the fix is a probe change — which this file
|
|
22
|
+
describes. The Go code is one implementation of the contract, never its
|
|
23
|
+
definition.
|
|
24
|
+
|
|
25
|
+
## Where a change belongs
|
|
26
|
+
|
|
27
|
+
| You need | Change it in |
|
|
28
|
+
|---|---|
|
|
29
|
+
| a new or corrected fact | the probe: a collector, or a field in its `data` |
|
|
30
|
+
| a new envelope field, status, or error shape | the probe: `schema/` + Go + its `SPECS.md` §3 |
|
|
31
|
+
| a new accessor, type, or document rule | here, generically, with a test |
|
|
32
|
+
| a severity, a threshold, a waiver | neither: that is a consumer's policy |
|
|
33
|
+
|
|
34
|
+
## Changing the probe
|
|
35
|
+
|
|
36
|
+
1. Work in the probe repository, following **its** `AGENTS.md`: one agent, one
|
|
37
|
+
collector package, one branch. Do not edit the probe's files from here, and
|
|
38
|
+
do not assume the two checkouts sit side by side.
|
|
39
|
+
2. If the envelope *structure* changed, edit `schema/envelope.schema.json` in
|
|
40
|
+
the same change. It is the source of truth, and the schema is closed
|
|
41
|
+
(`additionalProperties: false`): a field emitted without being declared is
|
|
42
|
+
already a failure downstream.
|
|
43
|
+
3. If a collector's `data` shape changed, add a row to the probe's
|
|
44
|
+
`DATA-CHANGELOG.md` and bump `VERSION`. Nothing enforces this. A consumer
|
|
45
|
+
cannot trace a field without that row, so it must treat the field as absent —
|
|
46
|
+
forever.
|
|
47
|
+
4. `make check && make check-schema` in the probe must be green.
|
|
48
|
+
5. Tag the probe: `vX.Y`. **Never move a tag.** Provenance is the product here,
|
|
49
|
+
and a moved tag silently changes what a past report was tested against.
|
|
50
|
+
6. Here: `tools/upgrade-upstream vX.Y.Z` — refresh, row, gates and commit in one
|
|
51
|
+
transaction (`--dry-run` writes nothing). It owns exactly five files
|
|
52
|
+
(`README.md`, `SPECS.md`, `UPSTREAM`, the fixture, the schema), refuses a
|
|
53
|
+
dirty tree outside them, an older series, a tag already vendored with its
|
|
54
|
+
row, and a fixture whose identity is a placeholder; on a failed gate it
|
|
55
|
+
restores those five and commits nothing. It commits *only* those files: when
|
|
56
|
+
a fixture moves something in `tests/`, the gate fails on purpose rather than
|
|
57
|
+
half-committing, and the honest path is the manual one the tool automates —
|
|
58
|
+
`tools/refresh-upstream vX.Y.Z`, migrate the test, run the gates, write the
|
|
59
|
+
row in `README.md` and `SPECS.md` from one string, and commit the refresh
|
|
60
|
+
with the migration it forced: a commit that leaves the suite red for one half
|
|
61
|
+
is the half-refresh in another costume. The refresh refuses a half-refresh
|
|
62
|
+
(schema and fixture disagreeing on the envelope major) because that is the
|
|
63
|
+
one mistake that produces a suite passing for the wrong reason.
|
|
64
|
+
7. Bump this package's version with `tools/release minor` (or `patch`, or an
|
|
65
|
+
explicit `X.Y.Z`): it keeps the distribution version, `__version__` and the
|
|
66
|
+
tag in agreement, and refuses a dirty tree or an existing tag. Vendoring and
|
|
67
|
+
release are separate commits on purpose — the row promises the release that
|
|
68
|
+
ships it — and a tag is never moved. Pushing that tag is the publish:
|
|
69
|
+
`.github/workflows/publish.yml` runs the gates again, refuses a tag that
|
|
70
|
+
disagrees with the package version, and uploads through Trusted Publishing
|
|
71
|
+
(no token stored). Push one tag — `git push origin vX.Y.Z` — never `--tags`:
|
|
72
|
+
the older release tags are local, and each one would upload its own version.
|
|
73
|
+
|
|
74
|
+
The vendored copies are generated. Never edit `src/perquisition/schema/` or
|
|
75
|
+
`tests/fixtures/audit-offline.json` by hand: a hand-edited copy is a test that
|
|
76
|
+
passes against a probe that never existed.
|
|
77
|
+
|
|
78
|
+
## The refresh token (optional since the probe went public)
|
|
79
|
+
|
|
80
|
+
`tools/refresh-upstream` goes through the GitHub contents API. While the probe
|
|
81
|
+
repository was private, that call needed `GITHUB_TOKEN` or `GH_TOKEN` with
|
|
82
|
+
`repo` read scope; it is public now, so the token is optional. Raw URLs are
|
|
83
|
+
still not used on purpose: they carry no `Authorization` header, so a private
|
|
84
|
+
repository answers 404 — the same answer as "this tag has no schema", and a
|
|
85
|
+
tool that cannot tell those apart teaches the wrong lesson. The contents API
|
|
86
|
+
keeps the two distinguishable the day the repository is private again.
|
|
87
|
+
|
|
88
|
+
## Forbidden
|
|
89
|
+
|
|
90
|
+
- reading the probe's Go source to infer a field, a status or an error code;
|
|
91
|
+
- pointing the contract at a branch or a local path (`tag` or nothing);
|
|
92
|
+
- adding a fallback for a field the schema does not declare — declare it
|
|
93
|
+
upstream instead;
|
|
94
|
+
- encoding a client's policy (severity, tolerance, waiver) in this library. It
|
|
95
|
+
gets forked by the next client, and both forks stop being tested;
|
|
96
|
+
- an alias module kept "for compatibility" with a name nobody imports. A second
|
|
97
|
+
name is a second truth with a deprecation clock.
|