Merges the list of what is pinned with each one's hash, the two warnings with the untrusted sources, the version comment and the double-check, and the distribution's tools with what is ruled out; every item is kept. Model: opus-5-5
This commit is contained in:
1 parent
4cce747e00
commit
287ffdf43e
1 file changed
+28
-46
+28
-46
@@ -14,17 +14,19 @@ style conventions are in separate documents:
|
|||||||
- [Go HTTP Server Conventions](https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/GO_HTTP_SERVER_CONVENTIONS.md)
|
- [Go HTTP Server Conventions](https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/GO_HTTP_SERVER_CONVENTIONS.md)
|
||||||
- [API Policies](https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/API_POLICIES.md)
|
- [API Policies](https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/API_POLICIES.md)
|
||||||
|
|
||||||
---
|
# Pin external references by hash
|
||||||
|
|
||||||
- **External references must be pinned by cryptographic hash.** This is the
|
- **External references must be pinned by cryptographic hash.** This is the
|
||||||
single most important rule in this document. It covers what we download and
|
single most important rule in this document. It covers what we download and
|
||||||
install ourselves in scripts and Dockerfiles:
|
install ourselves in scripts and Dockerfiles. Reference each by its content
|
||||||
- Docker base images
|
hash:
|
||||||
- Go modules
|
- Docker base images: `@sha256:...`
|
||||||
- Python packages from PyPI
|
- Go modules: the module hash in `go.sum`
|
||||||
- npm packages
|
- Python packages from PyPI: the package hash in `Pipfile.lock`
|
||||||
- GitHub Actions
|
- npm packages: the `checksum` in `yarn.lock`
|
||||||
- release archives fetched with `curl` or `wget`
|
- GitHub Actions: `@<commit-sha>`
|
||||||
|
- release archives fetched with `curl` or `wget`: a hash hardcoded in the
|
||||||
|
Dockerfile or script
|
||||||
|
|
||||||
Packages from the distribution's own package manager are outside this rule.
|
Packages from the distribution's own package manager are outside this rule.
|
||||||
They need no version and no hash, because the distribution is trusted. In a
|
They need no version and no hash, because the distribution is trusted. In a
|
||||||
@@ -39,49 +41,29 @@ style conventions are in separate documents:
|
|||||||
|
|
||||||
A package source that a `Dockerfile` adds itself is not the distribution's
|
A package source that a `Dockerfile` adds itself is not the distribution's
|
||||||
own, so its packages are pinned like any other download.
|
own, so its packages are pinned like any other download.
|
||||||
|
- A version tag such as `@v4`, `@latest` or `:3.21` is server-mutable, and
|
||||||
|
therefore a remote code execution vulnerability.
|
||||||
|
- An unverified install script is arbitrary remote code execution. Never
|
||||||
|
`curl | bash` to install a tool such as rustup. Instead, download a
|
||||||
|
specific release archive from GitHub, verify its hash, and only then
|
||||||
|
install.
|
||||||
|
- Docker Hub, PyPI, the npm registry and `go get` are not trusted, so
|
||||||
|
everything from them stays pinned by hash.
|
||||||
|
- Above each image or package pinned by hash, add a comment with the version
|
||||||
|
and date (YYYY-MM-DD).
|
||||||
|
- Double-check every external reference in every file before committing.
|
||||||
|
|
||||||
A version tag such as `@v4`, `@latest` or `:3.21` is server-mutable, and
|
node, yarn, npm, python, pip and venv come from the distribution wherever
|
||||||
therefore a remote code execution vulnerability. Reference an external
|
possible:
|
||||||
dependency by its content hash:
|
- node means the distribution's newest Node package, such as
|
||||||
- Docker: `@sha256:...`
|
`nodejs-current` on Alpine 3.24.
|
||||||
- Go: the module hash in `go.sum`
|
- pip and venv are the installer tools bundled with python.
|
||||||
- Python: the package hash in `Pipfile.lock`
|
- If the distribution's version is too old, use a newer distribution, never
|
||||||
- npm: the `checksum` in `yarn.lock`
|
a download. That rules out nvm, pyenv, corepack and `npm install -g yarn`.
|
||||||
- GitHub Actions: `@<commit-sha>`
|
|
||||||
|
|
||||||
This also means never `curl | bash` to install a tool such as rustup.
|
|
||||||
Instead, download a specific release archive from GitHub, verify its hash,
|
|
||||||
and only then install. The hash is hardcoded in the Dockerfile or script.
|
|
||||||
Unverified install scripts are arbitrary remote code execution. Double-check
|
|
||||||
every external reference in every file before committing.
|
|
||||||
|
|
||||||
These come from the distribution wherever possible:
|
|
||||||
- node, meaning the distribution's newest Node package, such as
|
|
||||||
`nodejs-current` on Alpine 3.24
|
|
||||||
- yarn
|
|
||||||
- npm
|
|
||||||
- python
|
|
||||||
- pip and venv, the installer tools bundled with python
|
|
||||||
|
|
||||||
If the distribution's version is too old, use a newer distribution, never a
|
|
||||||
download. That rules out all of these:
|
|
||||||
- nvm
|
|
||||||
- pyenv
|
|
||||||
- corepack
|
|
||||||
- `npm install -g yarn`
|
|
||||||
|
|
||||||
yarn's release file is third-party code, and git pins it. `yarn set version`
|
yarn's release file is third-party code, and git pins it. `yarn set version`
|
||||||
writes it to `.yarn/releases/` once, given an exact version.
|
writes it to `.yarn/releases/` once, given an exact version.
|
||||||
|
|
||||||
These are not trusted, so everything from them stays pinned by hash:
|
|
||||||
- Docker Hub
|
|
||||||
- PyPI
|
|
||||||
- the npm registry
|
|
||||||
- `go get`
|
|
||||||
|
|
||||||
- When pinning images or packages by hash, add a comment above the reference
|
|
||||||
with the version and date (YYYY-MM-DD).
|
|
||||||
|
|
||||||
- Never commit secrets. `.env` files, credentials, API keys, and private keys
|
- Never commit secrets. `.env` files, credentials, API keys, and private keys
|
||||||
must be in `.gitignore`. No exceptions.
|
must be in `.gitignore`. No exceptions.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user