pkggate 0.1.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.
Files changed (39) hide show
  1. pkggate-0.1.1/LICENSE +21 -0
  2. pkggate-0.1.1/PKG-INFO +246 -0
  3. pkggate-0.1.1/README.md +218 -0
  4. pkggate-0.1.1/pyproject.toml +58 -0
  5. pkggate-0.1.1/setup.cfg +4 -0
  6. pkggate-0.1.1/src/pkggate/__init__.py +3 -0
  7. pkggate-0.1.1/src/pkggate/__main__.py +29 -0
  8. pkggate-0.1.1/src/pkggate/app.py +142 -0
  9. pkggate-0.1.1/src/pkggate/audit/__init__.py +5 -0
  10. pkggate-0.1.1/src/pkggate/audit/logger.py +61 -0
  11. pkggate-0.1.1/src/pkggate/config.py +47 -0
  12. pkggate-0.1.1/src/pkggate/intel/__init__.py +27 -0
  13. pkggate-0.1.1/src/pkggate/intel/_semver.py +89 -0
  14. pkggate-0.1.1/src/pkggate/intel/composite.py +46 -0
  15. pkggate-0.1.1/src/pkggate/intel/mirror.py +342 -0
  16. pkggate-0.1.1/src/pkggate/intel/osv.py +100 -0
  17. pkggate-0.1.1/src/pkggate/policy/__init__.py +5 -0
  18. pkggate-0.1.1/src/pkggate/policy/engine.py +153 -0
  19. pkggate-0.1.1/src/pkggate/policy/rules.py +138 -0
  20. pkggate-0.1.1/src/pkggate/proxy/__init__.py +6 -0
  21. pkggate-0.1.1/src/pkggate/proxy/integrity.py +90 -0
  22. pkggate-0.1.1/src/pkggate/proxy/npm.py +283 -0
  23. pkggate-0.1.1/src/pkggate/proxy/pypi.py +372 -0
  24. pkggate-0.1.1/src/pkggate/utils.py +42 -0
  25. pkggate-0.1.1/src/pkggate.egg-info/PKG-INFO +246 -0
  26. pkggate-0.1.1/src/pkggate.egg-info/SOURCES.txt +37 -0
  27. pkggate-0.1.1/src/pkggate.egg-info/dependency_links.txt +1 -0
  28. pkggate-0.1.1/src/pkggate.egg-info/entry_points.txt +2 -0
  29. pkggate-0.1.1/src/pkggate.egg-info/requires.txt +18 -0
  30. pkggate-0.1.1/src/pkggate.egg-info/top_level.txt +1 -0
  31. pkggate-0.1.1/tests/test_composite.py +131 -0
  32. pkggate-0.1.1/tests/test_config.py +61 -0
  33. pkggate-0.1.1/tests/test_integrity.py +77 -0
  34. pkggate-0.1.1/tests/test_mirror.py +112 -0
  35. pkggate-0.1.1/tests/test_npm.py +258 -0
  36. pkggate-0.1.1/tests/test_osv.py +81 -0
  37. pkggate-0.1.1/tests/test_policy.py +278 -0
  38. pkggate-0.1.1/tests/test_pypi.py +290 -0
  39. pkggate-0.1.1/tests/test_utils.py +41 -0
pkggate-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 pkggate contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pkggate-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,246 @@
1
+ Metadata-Version: 2.4
2
+ Name: pkggate
3
+ Version: 0.1.1
4
+ Summary: Open-source package firewall proxy for npm and PyPI registries
5
+ Author-email: pkggate contributors <d@bitzer.dev>
6
+ License: MIT
7
+ Requires-Python: >=3.14
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: aiohttp>=3.13.5
11
+ Requires-Dist: pyyaml>=6.0.3
12
+ Requires-Dist: pydantic>=2.13.4
13
+ Requires-Dist: pydantic-settings>=2.14.0
14
+ Requires-Dist: structlog>=25.5.0
15
+ Requires-Dist: cachetools>=7.1.1
16
+ Requires-Dist: packaging>=26.2
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=9.0.3; extra == "dev"
19
+ Requires-Dist: pytest-asyncio>=1.3.0; extra == "dev"
20
+ Requires-Dist: pytest-cov>=7.1.0; extra == "dev"
21
+ Requires-Dist: aioresponses>=0.7.8; extra == "dev"
22
+ Requires-Dist: ruff>=0.15.2; extra == "dev"
23
+ Requires-Dist: mypy>=2.0.0; extra == "dev"
24
+ Requires-Dist: bandit>=1.9.4; extra == "dev"
25
+ Requires-Dist: safety>=3.7.0; extra == "dev"
26
+ Requires-Dist: cyclonedx-bom>=7.3.0; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # pkggate — Open-Source Package Firewall for npm & PyPI
30
+
31
+ > **Block malicious packages before they reach `node_modules` or `site-packages`.**
32
+ > A lightweight, self-hosted supply-chain firewall for small and mid-sized teams — free, open-source, and built on public threat intelligence (OSV.dev).
33
+
34
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#license)
35
+ [![Status: Early Preview](https://img.shields.io/badge/status-early--preview-orange.svg)](#project-status)
36
+ [![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg)](#contributing)
37
+
38
+ **Keywords:** package firewall, supply chain security, npm proxy, pypi proxy, malicious package blocker, OSV mirror, dependency security, software supply chain, self-hosted security, open-source security tooling.
39
+
40
+ ---
41
+
42
+ ## Why pkggate?
43
+
44
+ Software supply-chain attacks against npm and PyPI keep growing — typosquats, account takeovers, and malicious post-install scripts are now everyday threats. Commercial package firewalls exist, but their pricing often locks out small teams, indie developers, and OSS maintainers.
45
+
46
+ **pkggate is a free, self-hosted alternative** designed for organizations that need supply-chain protection without enterprise contracts:
47
+
48
+ - **Zero cost, full control** — runs in your own infrastructure, no vendor lock-in.
49
+ - **Drop-in proxy** — point `npm` and `pip` at pkggate; everything else stays the same.
50
+ - **Offline-capable threat intel** — local OSV mirror means lookups don't leak which packages you install.
51
+ - **Policy-driven** — block by advisory, package age, missing repository links, lifecycle scripts, or explicit allow/deny lists.
52
+ - **Auditable** — every decision lands in a JSON Lines audit log.
53
+
54
+ Inspired by:
55
+ - [Socket Firewall (sfw)](https://github.com/SocketDev/sfw-free)
56
+ - [Datadog supply-chain-firewall](https://github.com/DataDog/supply-chain-firewall)
57
+ - [OSSF Malicious Packages](https://github.com/ossf/malicious-packages)
58
+
59
+ ---
60
+
61
+ ## How it works
62
+
63
+ pkggate acts as a registry to your package manager. Every request is checked against a threat-intel source (OSV.dev) and a policy engine. Hits are blocked with HTTP 403 and recorded in the audit log.
64
+
65
+ ```
66
+ +---------+ +--------+ +---------------------+
67
+ | npm / | ---> | pkggate | ---> | npm / PyPI |
68
+ | pip | | | | upstream registry |
69
+ +---------+ | +----v----+ +---------------------+
70
+ | | OSV API |
71
+ | +---------+
72
+ | +---------+
73
+ | | Policy |
74
+ +---+---------+
75
+ ```
76
+
77
+ Two checkpoints (npm):
78
+
79
+ 1. **Metadata response** (`GET /<pkg>`) — versions with a `MAL-*` advisory are stripped from the `versions` map so the client never tries to resolve them.
80
+ 2. **Tarball request** (`GET /<pkg>/-/<pkg>-<ver>.tgz`) — final check before the file is delivered.
81
+
82
+ ---
83
+
84
+ ## Quick start
85
+
86
+ ### Run with Docker
87
+
88
+ Pull the published image from GitHub Container Registry:
89
+
90
+ ```bash
91
+ docker pull ghcr.io/daneb255/pkggate:latest
92
+ ```
93
+
94
+ Or start everything with Compose (builds locally if no image is present):
95
+
96
+ ```bash
97
+ docker compose up
98
+ ```
99
+
100
+ ### Point npm at pkggate
101
+
102
+ ```bash
103
+ echo "registry=http://localhost:8080/" > ~/.npmrc
104
+
105
+ # Clear the cache once, otherwise npm bypasses the proxy
106
+ npm cache clean --force
107
+
108
+ npm install express
109
+ ```
110
+
111
+ ### Point pip at pkggate
112
+
113
+ ```bash
114
+ pip config set global.index-url http://localhost:8080/simple/
115
+ pip install requests
116
+ ```
117
+
118
+ That's it — installs now flow through pkggate and malicious versions are blocked transparently.
119
+
120
+ ---
121
+
122
+ ## Threat intelligence
123
+
124
+ By default pkggate runs a **local OSV mirror** for both supported ecosystems (npm and PyPI). At startup it downloads each ecosystem's OSV bundle from `storage.googleapis.com/osv-vulnerabilities/<eco>/all.zip`, extracts every `MAL-*` advisory, and indexes them in a local SQLite database partitioned by ecosystem. A background task refreshes each bundle hourly; if one bundle fails the others stay fresh.
125
+
126
+ Per-version lookups during `npm install` / `pip install` hit the local DB — **zero outbound calls on the hot path**, which keeps installs fast and your dependency graph private.
127
+
128
+ To also catch advisories published since the last refresh, enable `PKGGATE_LIVE_FALLBACK_ENABLED=true`. The live API is then queried only for versions the mirror considers clean, batched via OSV's `querybatch` endpoint.
129
+
130
+ ### Configuration
131
+
132
+ | Variable | Default | Purpose |
133
+ | --- | --- | --- |
134
+ | `PKGGATE_MIRROR_ENABLED` | `true` | Enable local OSV mirror |
135
+ | `PKGGATE_MIRROR_DB` | `mirror.db` | SQLite path |
136
+ | `PKGGATE_MIRROR_REFRESH_SECONDS` | `3600` | Refresh interval |
137
+ | `PKGGATE_LIVE_FALLBACK_ENABLED` | `false` | Query OSV API for clean versions |
138
+ | `PKGGATE_OSV_BUNDLE_NPM` | public GCS URL | Override npm bundle source |
139
+ | `PKGGATE_OSV_BUNDLE_PYPI` | public GCS URL | Override PyPI bundle source |
140
+ | `PKGGATE_OSV_API` | `https://api.osv.dev/v1/query` | Live fallback endpoint |
141
+
142
+ ---
143
+
144
+ ## Policy engine
145
+
146
+ Policies live in `config/policy.yaml`. Example rules:
147
+
148
+ - `block_malicious` — hard-block OSV `MAL-*` advisories.
149
+ - `min_package_age_days` — block packages younger than _N_ days (typo-squat mitigation).
150
+ - `require_repository_url` — block packages without a repository link.
151
+ - `deny_postinstall` — block packages that ship lifecycle scripts.
152
+ - `allowlist` / `denylist` — explicit overrides.
153
+
154
+ Tune these to match your organization's risk appetite — small teams typically start with `block_malicious` + `min_package_age_days: 7`.
155
+
156
+ ---
157
+
158
+ ## Audit log
159
+
160
+ Every decision is appended to `./audit.log` as JSON Lines, ready for ingestion by any SIEM, log shipper, or `jq` pipeline:
161
+
162
+ ```json
163
+ {"ts":"2026-04-20T10:12:03Z","action":"block","package":"passports-js","version":"0.0.1-security","rule":"block_malicious","source":"MAL-2024-88"}
164
+ ```
165
+
166
+ ---
167
+
168
+ ## PyPI support
169
+
170
+ pkggate implements the [PEP 691](https://peps.python.org/pep-0691/) Simple Repository JSON API as a two-gate proxy:
171
+
172
+ 1. **Simple index gate** (`GET /simple/<project>/`) — fetches the upstream index, runs intel + policy per version, drops denied files, rewrites surviving file URLs through the proxy, and caches SHA-256 hashes for the second gate.
173
+ 2. **File gate** (`GET /packages/<path>`) — re-evaluates policy (last stop before bytes leave), verifies the SHA-256 hash against the simple-index claim, and serves the file. Lockfile-driven installs that skip the index trigger a one-shot prefetch to populate the hash cache.
174
+
175
+ Configure pip to use pkggate:
176
+
177
+ ```ini
178
+ # pip.conf
179
+ [global]
180
+ index-url = http://127.0.0.1:8080/simple/
181
+ ```
182
+
183
+ | Variable | Default | Description |
184
+ | --- | --- | --- |
185
+ | `PKGGATE_PYPI_ENABLED` | `true` | Enable the PyPI proxy |
186
+ | `PKGGATE_PYPI_UPSTREAM_SIMPLE` | `https://pypi.org/simple/` | Upstream simple index |
187
+ | `PKGGATE_PYPI_UPSTREAM_FILES` | `https://files.pythonhosted.org/` | Upstream file server |
188
+ | `PKGGATE_PYPI_PUBLIC_BASE_URL` | `http://127.0.0.1:8080` | Public URL of this proxy (used for URL rewriting) |
189
+ | `PKGGATE_PYPI_VERIFY_INTEGRITY` | `true` | Verify SHA-256 hash against simple-index claim |
190
+ | `PKGGATE_PYPI_MAX_BUFFER_BYTES` | `209715200` | Maximum file size buffered for verification (200 MiB) |
191
+
192
+ ---
193
+
194
+ ## Project status
195
+
196
+ **pkggate is an early-stage prototype.** It works end-to-end for npm and PyPI, but APIs, configuration keys, and on-disk formats may still change without notice. Production use is at your own risk — please pin versions and review the audit log.
197
+
198
+ Roadmap highlights:
199
+
200
+ - Hardening the policy engine and configuration schema.
201
+ - Cargo and Maven adapters (plugin point already exists at `src/pkggate/proxy/`).
202
+ - A small admin UI for the audit log.
203
+ - Pre-built container images and a Helm chart.
204
+
205
+ ---
206
+
207
+ ## Contributing
208
+
209
+ **Contributions are explicitly welcome.** This project is built for the community — small businesses, OSS maintainers, indie devs, and security teams who want supply-chain protection without an enterprise budget.
210
+
211
+ Helpful ways to contribute:
212
+
213
+ - **Try it in your stack** and open issues for anything that breaks or surprises you.
214
+ - **Add ecosystem adapters** (Cargo, Maven, RubyGems, Go modules).
215
+ - **Improve the policy engine** — new rules, better defaults, clearer error messages.
216
+ - **Documentation, examples, translations** — especially deployment guides for common environments (Kubernetes, Nomad, plain `systemd`).
217
+ - **Threat-intel integrations** beyond OSV.dev.
218
+
219
+ To contribute:
220
+
221
+ 1. Fork the repository and create a feature branch.
222
+ 2. Follow conventional commits where possible.
223
+ 3. Open a pull request describing the change and the motivation.
224
+ 4. Be kind in reviews — see [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).
225
+
226
+ If you're unsure where to start, open a discussion or an issue tagged `question` — we'll help you find a good first task.
227
+
228
+ ---
229
+
230
+ ## Code of Conduct
231
+
232
+ Participation in this project is governed by the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you agree to uphold its terms. Reports can be sent privately to the maintainer email listed in that document.
233
+
234
+ ---
235
+
236
+ ## Security
237
+
238
+ Found a vulnerability in pkggate itself? **Please do not file a public issue.** Email the maintainer (see `CODE_OF_CONDUCT.md`) with details and we will respond as quickly as we can.
239
+
240
+ For malicious-package reports, file them upstream with [OSV.dev](https://osv.dev/) or the [OSSF Malicious Packages](https://github.com/ossf/malicious-packages) project so the whole ecosystem benefits.
241
+
242
+ ---
243
+
244
+ ## License
245
+
246
+ [MIT](LICENSE) — use it, fork it, ship it.
@@ -0,0 +1,218 @@
1
+ # pkggate — Open-Source Package Firewall for npm & PyPI
2
+
3
+ > **Block malicious packages before they reach `node_modules` or `site-packages`.**
4
+ > A lightweight, self-hosted supply-chain firewall for small and mid-sized teams — free, open-source, and built on public threat intelligence (OSV.dev).
5
+
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#license)
7
+ [![Status: Early Preview](https://img.shields.io/badge/status-early--preview-orange.svg)](#project-status)
8
+ [![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg)](#contributing)
9
+
10
+ **Keywords:** package firewall, supply chain security, npm proxy, pypi proxy, malicious package blocker, OSV mirror, dependency security, software supply chain, self-hosted security, open-source security tooling.
11
+
12
+ ---
13
+
14
+ ## Why pkggate?
15
+
16
+ Software supply-chain attacks against npm and PyPI keep growing — typosquats, account takeovers, and malicious post-install scripts are now everyday threats. Commercial package firewalls exist, but their pricing often locks out small teams, indie developers, and OSS maintainers.
17
+
18
+ **pkggate is a free, self-hosted alternative** designed for organizations that need supply-chain protection without enterprise contracts:
19
+
20
+ - **Zero cost, full control** — runs in your own infrastructure, no vendor lock-in.
21
+ - **Drop-in proxy** — point `npm` and `pip` at pkggate; everything else stays the same.
22
+ - **Offline-capable threat intel** — local OSV mirror means lookups don't leak which packages you install.
23
+ - **Policy-driven** — block by advisory, package age, missing repository links, lifecycle scripts, or explicit allow/deny lists.
24
+ - **Auditable** — every decision lands in a JSON Lines audit log.
25
+
26
+ Inspired by:
27
+ - [Socket Firewall (sfw)](https://github.com/SocketDev/sfw-free)
28
+ - [Datadog supply-chain-firewall](https://github.com/DataDog/supply-chain-firewall)
29
+ - [OSSF Malicious Packages](https://github.com/ossf/malicious-packages)
30
+
31
+ ---
32
+
33
+ ## How it works
34
+
35
+ pkggate acts as a registry to your package manager. Every request is checked against a threat-intel source (OSV.dev) and a policy engine. Hits are blocked with HTTP 403 and recorded in the audit log.
36
+
37
+ ```
38
+ +---------+ +--------+ +---------------------+
39
+ | npm / | ---> | pkggate | ---> | npm / PyPI |
40
+ | pip | | | | upstream registry |
41
+ +---------+ | +----v----+ +---------------------+
42
+ | | OSV API |
43
+ | +---------+
44
+ | +---------+
45
+ | | Policy |
46
+ +---+---------+
47
+ ```
48
+
49
+ Two checkpoints (npm):
50
+
51
+ 1. **Metadata response** (`GET /<pkg>`) — versions with a `MAL-*` advisory are stripped from the `versions` map so the client never tries to resolve them.
52
+ 2. **Tarball request** (`GET /<pkg>/-/<pkg>-<ver>.tgz`) — final check before the file is delivered.
53
+
54
+ ---
55
+
56
+ ## Quick start
57
+
58
+ ### Run with Docker
59
+
60
+ Pull the published image from GitHub Container Registry:
61
+
62
+ ```bash
63
+ docker pull ghcr.io/daneb255/pkggate:latest
64
+ ```
65
+
66
+ Or start everything with Compose (builds locally if no image is present):
67
+
68
+ ```bash
69
+ docker compose up
70
+ ```
71
+
72
+ ### Point npm at pkggate
73
+
74
+ ```bash
75
+ echo "registry=http://localhost:8080/" > ~/.npmrc
76
+
77
+ # Clear the cache once, otherwise npm bypasses the proxy
78
+ npm cache clean --force
79
+
80
+ npm install express
81
+ ```
82
+
83
+ ### Point pip at pkggate
84
+
85
+ ```bash
86
+ pip config set global.index-url http://localhost:8080/simple/
87
+ pip install requests
88
+ ```
89
+
90
+ That's it — installs now flow through pkggate and malicious versions are blocked transparently.
91
+
92
+ ---
93
+
94
+ ## Threat intelligence
95
+
96
+ By default pkggate runs a **local OSV mirror** for both supported ecosystems (npm and PyPI). At startup it downloads each ecosystem's OSV bundle from `storage.googleapis.com/osv-vulnerabilities/<eco>/all.zip`, extracts every `MAL-*` advisory, and indexes them in a local SQLite database partitioned by ecosystem. A background task refreshes each bundle hourly; if one bundle fails the others stay fresh.
97
+
98
+ Per-version lookups during `npm install` / `pip install` hit the local DB — **zero outbound calls on the hot path**, which keeps installs fast and your dependency graph private.
99
+
100
+ To also catch advisories published since the last refresh, enable `PKGGATE_LIVE_FALLBACK_ENABLED=true`. The live API is then queried only for versions the mirror considers clean, batched via OSV's `querybatch` endpoint.
101
+
102
+ ### Configuration
103
+
104
+ | Variable | Default | Purpose |
105
+ | --- | --- | --- |
106
+ | `PKGGATE_MIRROR_ENABLED` | `true` | Enable local OSV mirror |
107
+ | `PKGGATE_MIRROR_DB` | `mirror.db` | SQLite path |
108
+ | `PKGGATE_MIRROR_REFRESH_SECONDS` | `3600` | Refresh interval |
109
+ | `PKGGATE_LIVE_FALLBACK_ENABLED` | `false` | Query OSV API for clean versions |
110
+ | `PKGGATE_OSV_BUNDLE_NPM` | public GCS URL | Override npm bundle source |
111
+ | `PKGGATE_OSV_BUNDLE_PYPI` | public GCS URL | Override PyPI bundle source |
112
+ | `PKGGATE_OSV_API` | `https://api.osv.dev/v1/query` | Live fallback endpoint |
113
+
114
+ ---
115
+
116
+ ## Policy engine
117
+
118
+ Policies live in `config/policy.yaml`. Example rules:
119
+
120
+ - `block_malicious` — hard-block OSV `MAL-*` advisories.
121
+ - `min_package_age_days` — block packages younger than _N_ days (typo-squat mitigation).
122
+ - `require_repository_url` — block packages without a repository link.
123
+ - `deny_postinstall` — block packages that ship lifecycle scripts.
124
+ - `allowlist` / `denylist` — explicit overrides.
125
+
126
+ Tune these to match your organization's risk appetite — small teams typically start with `block_malicious` + `min_package_age_days: 7`.
127
+
128
+ ---
129
+
130
+ ## Audit log
131
+
132
+ Every decision is appended to `./audit.log` as JSON Lines, ready for ingestion by any SIEM, log shipper, or `jq` pipeline:
133
+
134
+ ```json
135
+ {"ts":"2026-04-20T10:12:03Z","action":"block","package":"passports-js","version":"0.0.1-security","rule":"block_malicious","source":"MAL-2024-88"}
136
+ ```
137
+
138
+ ---
139
+
140
+ ## PyPI support
141
+
142
+ pkggate implements the [PEP 691](https://peps.python.org/pep-0691/) Simple Repository JSON API as a two-gate proxy:
143
+
144
+ 1. **Simple index gate** (`GET /simple/<project>/`) — fetches the upstream index, runs intel + policy per version, drops denied files, rewrites surviving file URLs through the proxy, and caches SHA-256 hashes for the second gate.
145
+ 2. **File gate** (`GET /packages/<path>`) — re-evaluates policy (last stop before bytes leave), verifies the SHA-256 hash against the simple-index claim, and serves the file. Lockfile-driven installs that skip the index trigger a one-shot prefetch to populate the hash cache.
146
+
147
+ Configure pip to use pkggate:
148
+
149
+ ```ini
150
+ # pip.conf
151
+ [global]
152
+ index-url = http://127.0.0.1:8080/simple/
153
+ ```
154
+
155
+ | Variable | Default | Description |
156
+ | --- | --- | --- |
157
+ | `PKGGATE_PYPI_ENABLED` | `true` | Enable the PyPI proxy |
158
+ | `PKGGATE_PYPI_UPSTREAM_SIMPLE` | `https://pypi.org/simple/` | Upstream simple index |
159
+ | `PKGGATE_PYPI_UPSTREAM_FILES` | `https://files.pythonhosted.org/` | Upstream file server |
160
+ | `PKGGATE_PYPI_PUBLIC_BASE_URL` | `http://127.0.0.1:8080` | Public URL of this proxy (used for URL rewriting) |
161
+ | `PKGGATE_PYPI_VERIFY_INTEGRITY` | `true` | Verify SHA-256 hash against simple-index claim |
162
+ | `PKGGATE_PYPI_MAX_BUFFER_BYTES` | `209715200` | Maximum file size buffered for verification (200 MiB) |
163
+
164
+ ---
165
+
166
+ ## Project status
167
+
168
+ **pkggate is an early-stage prototype.** It works end-to-end for npm and PyPI, but APIs, configuration keys, and on-disk formats may still change without notice. Production use is at your own risk — please pin versions and review the audit log.
169
+
170
+ Roadmap highlights:
171
+
172
+ - Hardening the policy engine and configuration schema.
173
+ - Cargo and Maven adapters (plugin point already exists at `src/pkggate/proxy/`).
174
+ - A small admin UI for the audit log.
175
+ - Pre-built container images and a Helm chart.
176
+
177
+ ---
178
+
179
+ ## Contributing
180
+
181
+ **Contributions are explicitly welcome.** This project is built for the community — small businesses, OSS maintainers, indie devs, and security teams who want supply-chain protection without an enterprise budget.
182
+
183
+ Helpful ways to contribute:
184
+
185
+ - **Try it in your stack** and open issues for anything that breaks or surprises you.
186
+ - **Add ecosystem adapters** (Cargo, Maven, RubyGems, Go modules).
187
+ - **Improve the policy engine** — new rules, better defaults, clearer error messages.
188
+ - **Documentation, examples, translations** — especially deployment guides for common environments (Kubernetes, Nomad, plain `systemd`).
189
+ - **Threat-intel integrations** beyond OSV.dev.
190
+
191
+ To contribute:
192
+
193
+ 1. Fork the repository and create a feature branch.
194
+ 2. Follow conventional commits where possible.
195
+ 3. Open a pull request describing the change and the motivation.
196
+ 4. Be kind in reviews — see [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).
197
+
198
+ If you're unsure where to start, open a discussion or an issue tagged `question` — we'll help you find a good first task.
199
+
200
+ ---
201
+
202
+ ## Code of Conduct
203
+
204
+ Participation in this project is governed by the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you agree to uphold its terms. Reports can be sent privately to the maintainer email listed in that document.
205
+
206
+ ---
207
+
208
+ ## Security
209
+
210
+ Found a vulnerability in pkggate itself? **Please do not file a public issue.** Email the maintainer (see `CODE_OF_CONDUCT.md`) with details and we will respond as quickly as we can.
211
+
212
+ For malicious-package reports, file them upstream with [OSV.dev](https://osv.dev/) or the [OSSF Malicious Packages](https://github.com/ossf/malicious-packages) project so the whole ecosystem benefits.
213
+
214
+ ---
215
+
216
+ ## License
217
+
218
+ [MIT](LICENSE) — use it, fork it, ship it.
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pkggate"
7
+ version = "0.1.1"
8
+ description = "Open-source package firewall proxy for npm and PyPI registries"
9
+ readme = "README.md"
10
+ requires-python = ">=3.14"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "pkggate contributors", email = "d@bitzer.dev" }]
13
+ dependencies = [
14
+ "aiohttp>=3.13.5",
15
+ "pyyaml>=6.0.3",
16
+ "pydantic>=2.13.4",
17
+ "pydantic-settings>=2.14.0",
18
+ "structlog>=25.5.0",
19
+ "cachetools>=7.1.1",
20
+ "packaging>=26.2",
21
+ ]
22
+
23
+ [project.optional-dependencies]
24
+ dev = [
25
+ "pytest>=9.0.3",
26
+ "pytest-asyncio>=1.3.0",
27
+ "pytest-cov>=7.1.0",
28
+ "aioresponses>=0.7.8",
29
+ "ruff>=0.15.2",
30
+ "mypy>=2.0.0",
31
+ "bandit>=1.9.4",
32
+ "safety>=3.7.0",
33
+ "cyclonedx-bom>=7.3.0",
34
+ ]
35
+
36
+ [project.scripts]
37
+ pkggate = "pkggate.__main__:main"
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+
42
+ [tool.pytest.ini_options]
43
+ asyncio_mode = "auto"
44
+ testpaths = ["tests"]
45
+
46
+ [tool.ruff]
47
+ line-length = 100
48
+ target-version = "py314"
49
+
50
+ [tool.ruff.lint]
51
+ select = ["E", "F", "W", "I", "N", "UP", "RUF"]
52
+
53
+ [tool.mypy]
54
+ python_version = "3.14"
55
+ warn_return_any = true
56
+ warn_unused_configs = true
57
+ disallow_untyped_defs = false
58
+ strict_optional = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """Package initialization for pkggate."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,29 @@
1
+ """Entry point for pkggate CLI."""
2
+
3
+ import asyncio
4
+ import logging
5
+ import sys
6
+
7
+ from pkggate.app import run
8
+ from pkggate.config import Settings
9
+
10
+ logging.basicConfig(
11
+ level=logging.INFO,
12
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
13
+ )
14
+
15
+
16
+ def main() -> None:
17
+ """Start pkggate server."""
18
+ try:
19
+ settings = Settings()
20
+ asyncio.run(run(settings))
21
+ except KeyboardInterrupt:
22
+ sys.exit(0)
23
+ except Exception as exc:
24
+ logging.exception("Fatal error: %s", exc)
25
+ sys.exit(1)
26
+
27
+
28
+ if __name__ == "__main__":
29
+ main()