Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ad3bbd347 | ||
|
|
d4fbcbc83d | ||
|
|
897b43a206 | ||
|
|
1ddc2c747a | ||
|
|
7280ee35f4 | ||
|
|
90596de901 | ||
|
|
d6b87f7502 | ||
|
|
8d1c873bb7 | ||
|
|
f8c796db9b | ||
|
|
7f7fe33cd6 | ||
|
|
dd14677145 | ||
|
|
ace7846d57 | ||
|
|
40e9beea8c | ||
|
|
15ebe24f7b | ||
|
|
64dcc7f42b | ||
|
|
3d90ac87f1 | ||
|
|
e6ddf49acc | ||
|
|
860e590114 | ||
|
|
63575ce827 |
+67
-2
@@ -1,3 +1,68 @@
|
|||||||
.git
|
# .dockerignore does NOT use .gitignore semantics. Docker matches with
|
||||||
.gitea
|
# moby/patternmatcher: filepath.Match plus `**`, so `*` does not cross
|
||||||
|
# `/` and an unprefixed pattern is anchored at the context root. Every
|
||||||
|
# depth-independent pattern therefore needs `**/`, or `config/.env` and
|
||||||
|
# `certs/server.key` still ship while this file reads as solved. Only
|
||||||
|
# genuinely root-anchored entries go unprefixed. Never transplant these
|
||||||
|
# into .gitignore, where `**/` is wrong.
|
||||||
|
#
|
||||||
|
# Matching is case-sensitive, so secrets use character ranges rather
|
||||||
|
# than an ALL-CAPS twin, which would still miss `Server.Key`.
|
||||||
|
#
|
||||||
|
# Extend with this repo's own host-built artifacts, written anchored:
|
||||||
|
# `/myapp`, never `**/myapp`, which also matches `cmd/myapp/` and
|
||||||
|
# deletes the package directory from the context.
|
||||||
|
|
||||||
|
# .git is sent without its config. Without a VERSION build argument the
|
||||||
|
# stage that compiles runs `git describe --tags --always` on .git, which
|
||||||
|
# does not need .git/config; that file can hold a credential, such as a
|
||||||
|
# password in a remote URL or the token the CI checkout step stores there.
|
||||||
|
# Each submodule keeps a config with the same exposure in its git directory
|
||||||
|
# under .git/modules/, nested again for a submodule's own submodules.
|
||||||
|
.git/config
|
||||||
|
.git/modules/**/config
|
||||||
|
|
||||||
|
# Agent scratch: one full checkout of the repo per in-flight agent.
|
||||||
|
# Anchored because it occurs once where agents run at the repo root.
|
||||||
|
# KNOWN GAP: a repo running agents in subdirectories still ships
|
||||||
|
# `services/api/.claude/` and must add its own anchored entry.
|
||||||
|
.claude
|
||||||
|
|
||||||
|
# Environment files. `*.env` covers bare `.env` and the `prod.env`
|
||||||
|
# convention. Re-include a committed template with a negation if the
|
||||||
|
# build needs one: `!docs/example.env`.
|
||||||
|
**/*.[eE][nN][vV]
|
||||||
|
**/.[eE][nN][vV].*
|
||||||
|
**/.[eE][nN][vV][rR][cC]
|
||||||
|
|
||||||
|
# Private keys and the bundles carrying them. Public certificates
|
||||||
|
# (*.crt, *.cer) are deliberately absent: they are legitimate inputs.
|
||||||
|
**/*.[pP][eE][mM]
|
||||||
|
**/*.[kK][eE][yY]
|
||||||
|
**/*.[pP]12
|
||||||
|
**/*.[pP][fF][xX]
|
||||||
|
**/[iI][dD]_[rR][sS][aA]
|
||||||
|
**/[iI][dD]_[dD][sS][aA]
|
||||||
|
**/[iI][dD]_[eE][cC][dD][sS][aA]
|
||||||
|
**/[iI][dD]_[eE][dD]25519
|
||||||
|
|
||||||
|
# Dependencies: restored inside the image, never copied in.
|
||||||
|
**/node_modules
|
||||||
|
|
||||||
|
# OS metadata.
|
||||||
|
**/.DS_Store
|
||||||
|
**/Thumbs.db
|
||||||
|
|
||||||
|
# Editor state: never a build input, and it churns COPY.
|
||||||
|
**/*.swp
|
||||||
|
**/*.swo
|
||||||
|
**/*~
|
||||||
|
**/*.bak
|
||||||
|
**/.idea
|
||||||
|
**/.vscode
|
||||||
|
**/*.sublime-*
|
||||||
|
|
||||||
|
# The binary `make build` writes, and the CI workflow, which is not a
|
||||||
|
# build input.
|
||||||
/keyfunc
|
/keyfunc
|
||||||
|
.gitea
|
||||||
|
|||||||
@@ -6,4 +6,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
# actions/checkout v4.2.2, 2026-02-22
|
# actions/checkout v4.2.2, 2026-02-22
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||||
|
with:
|
||||||
|
# All history and tags, which `git describe --tags` needs.
|
||||||
|
fetch-depth: 0
|
||||||
- run: script/cibuild
|
- run: script/cibuild
|
||||||
|
|||||||
+35
-8
@@ -1,6 +1,3 @@
|
|||||||
# The built binary
|
|
||||||
/keyfunc
|
|
||||||
|
|
||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
@@ -14,8 +11,38 @@ Thumbs.db
|
|||||||
.vscode/
|
.vscode/
|
||||||
*.sublime-*
|
*.sublime-*
|
||||||
|
|
||||||
# Environment / secrets
|
# Agent scratch (worktrees of this repo, created and destroyed by
|
||||||
.env
|
# in-flight tooling). Unanchored: .gitignore patterns already match at
|
||||||
.env.*
|
# every depth, so no prefix is wanted here. This is not a .dockerignore
|
||||||
*.pem
|
# entry and must not be given a `**/` prefix on the way into one.
|
||||||
*.key
|
.claude/
|
||||||
|
|
||||||
|
# Node
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Secrets. Unanchored like every entry above, so each matches at every
|
||||||
|
# depth. Matching is case-sensitive on Linux, so names use character
|
||||||
|
# ranges rather than a lowercase form that misses `Server.Key`.
|
||||||
|
|
||||||
|
# Environment files. `*.env` covers bare `.env` and the `prod.env`
|
||||||
|
# convention. Only the templates `example.env` and `sample.env` are
|
||||||
|
# re-included below. A repository that commits any other template adds
|
||||||
|
# its own negation after these lines, for example `!.env.example`.
|
||||||
|
*.[eE][nN][vV]
|
||||||
|
.[eE][nN][vV].*
|
||||||
|
.[eE][nN][vV][rR][cC]
|
||||||
|
!example.env
|
||||||
|
!sample.env
|
||||||
|
|
||||||
|
# Private keys and the bundles carrying them.
|
||||||
|
*.[pP][eE][mM]
|
||||||
|
*.[kK][eE][yY]
|
||||||
|
*.[pP]12
|
||||||
|
*.[pP][fF][xX]
|
||||||
|
[iI][dD]_[rR][sS][aA]
|
||||||
|
[iI][dD]_[dD][sS][aA]
|
||||||
|
[iI][dD]_[eE][cC][dD][sS][aA]
|
||||||
|
[iI][dD]_[eE][dD]25519
|
||||||
|
|
||||||
|
# The binary `make build` writes.
|
||||||
|
/keyfunc
|
||||||
|
|||||||
+67
-2
@@ -10,14 +10,21 @@ run:
|
|||||||
|
|
||||||
linters:
|
linters:
|
||||||
default: all
|
default: all
|
||||||
|
enable:
|
||||||
|
# Successor to the deprecated gomodguard. Named explicitly, rather than
|
||||||
|
# left to `default: all`, because it carries the module policy below.
|
||||||
|
- gomodguard_v2
|
||||||
disable:
|
disable:
|
||||||
# Genuinely incompatible with project patterns
|
# Genuinely incompatible with project patterns
|
||||||
- exhaustruct # Requires all struct fields
|
- exhaustruct # Requires all struct fields
|
||||||
- depguard # Dependency allow/block lists
|
- exhaustruct_v5 # Requires all struct fields (successor to exhaustruct)
|
||||||
- godot # Requires comments to end with periods
|
- godot # Requires comments to end with periods
|
||||||
- wsl # Deprecated, replaced by wsl_v5
|
|
||||||
- wrapcheck # Too verbose for internal packages
|
- wrapcheck # Too verbose for internal packages
|
||||||
- varnamelen # Short names like db, id are idiomatic Go
|
- varnamelen # Short names like db, id are idiomatic Go
|
||||||
|
# Deprecated: the warning is attached to the old name, so it is
|
||||||
|
# silenced by disabling that name, not by enabling the successor.
|
||||||
|
- wsl # Deprecated, replaced by wsl_v5
|
||||||
|
- gomodguard # Deprecated, replaced by gomodguard_v2
|
||||||
settings:
|
settings:
|
||||||
lll:
|
lll:
|
||||||
line-length: 88
|
line-length: 88
|
||||||
@@ -28,6 +35,64 @@ linters:
|
|||||||
max-complexity: 15
|
max-complexity: 15
|
||||||
dupl:
|
dupl:
|
||||||
threshold: 100
|
threshold: 100
|
||||||
|
depguard:
|
||||||
|
# Test-support code must not be compiled into the shipped binary. A
|
||||||
|
# test-support package exists to hand a test privileges the program
|
||||||
|
# itself must never have, so a file that is not a test must not import
|
||||||
|
# one. Test files, and the files inside a package whose directory name
|
||||||
|
# ends in `test`, are where that code belongs, and are exempt.
|
||||||
|
#
|
||||||
|
# The deny list below is the one part of this file a repository is
|
||||||
|
# expected to extend, and the only part it may. depguard matches an
|
||||||
|
# import path against a list of prefixes, so it cannot be told "any path
|
||||||
|
# whose last segment ends in test"; a repository's own test-support
|
||||||
|
# packages have to be named here one at a time, by full import path,
|
||||||
|
# under a module path that differs from repository to repository. Add
|
||||||
|
# them; change nothing else.
|
||||||
|
rules:
|
||||||
|
test-support:
|
||||||
|
list-mode: lax
|
||||||
|
files:
|
||||||
|
- "$all"
|
||||||
|
- "!$test"
|
||||||
|
- "!**/*test/**"
|
||||||
|
deny:
|
||||||
|
- pkg: net/http/httptest
|
||||||
|
desc: >-
|
||||||
|
Test-support code belongs in test files and in packages whose
|
||||||
|
directory name ends in test, not in the shipped binary.
|
||||||
|
# Only decisions already recorded in the Go package defaults are
|
||||||
|
# listed here. Every entry matches the module path exactly.
|
||||||
|
gomodguard_v2:
|
||||||
|
blocked:
|
||||||
|
- module: github.com/rs/zerolog
|
||||||
|
recommendations:
|
||||||
|
- log/slog
|
||||||
|
reason: "Structured logging is stdlib log/slog."
|
||||||
|
# One entry per pre-fork module path, because the later releases
|
||||||
|
# are separate paths. A prefix match would be shorter but would
|
||||||
|
# also reach github.com/go-redis/redismock, the test double for
|
||||||
|
# the successor these entries recommend.
|
||||||
|
- module: github.com/go-redis/redis
|
||||||
|
recommendations:
|
||||||
|
- github.com/redis/go-redis/v9
|
||||||
|
reason: "Pre-fork module; use the maintained go-redis v9."
|
||||||
|
- module: github.com/go-redis/redis/v7
|
||||||
|
recommendations:
|
||||||
|
- github.com/redis/go-redis/v9
|
||||||
|
reason: "Pre-fork module; use the maintained go-redis v9."
|
||||||
|
- module: github.com/go-redis/redis/v8
|
||||||
|
recommendations:
|
||||||
|
- github.com/redis/go-redis/v9
|
||||||
|
reason: "Pre-fork module; use the maintained go-redis v9."
|
||||||
|
- module: github.com/sergi/go-diff
|
||||||
|
recommendations:
|
||||||
|
- github.com/aymanbagabas/go-udiff
|
||||||
|
reason: "No unified diff output; use go-udiff."
|
||||||
|
- module: github.com/hexops/gotextdiff
|
||||||
|
recommendations:
|
||||||
|
- github.com/aymanbagabas/go-udiff
|
||||||
|
reason: "Unmaintained fork; use go-udiff."
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
max-issues-per-linter: 0
|
max-issues-per-linter: 0
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"tabWidth": 4,
|
||||||
|
"proseWrap": "always"
|
||||||
|
}
|
||||||
+60
-14
@@ -1,11 +1,11 @@
|
|||||||
# The formatting check, the tests and the build. Linting is not here:
|
# The lint phase, the test phase and a development environment.
|
||||||
# it runs in its own pinned image, see Dockerfile.lint and script/lint,
|
# script/lint and script/test each build one phase alone; a plain
|
||||||
# which script/cibuild runs before this file.
|
# `docker build .` builds both, because the last stage copies a file from
|
||||||
|
# each. Formatting is checked on the host by script/fmt-check, not here.
|
||||||
|
|
||||||
# golang:1.26-alpine, 2026-09-07
|
# Lint phase
|
||||||
FROM golang@sha256:ce864e7223ac17b1775e6fd0b4c0db580c2eb50e7953a427916379e4b92a1628 AS builder
|
# golangci/golangci-lint:v2.14.0, 2026-10-04
|
||||||
|
FROM golangci/golangci-lint@sha256:ad862ba6b3798cbe0fd9fd7408d498fd74fbd2623a92406b2fd3898faf0bf98f AS lint
|
||||||
RUN apk add --no-cache make git
|
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
@@ -14,13 +14,59 @@ RUN go mod download
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN make fmt-check
|
RUN golangci-lint run --config .golangci.yml ./...
|
||||||
RUN make test
|
|
||||||
RUN make build
|
|
||||||
|
|
||||||
# alpine:3.23, 2026-09-07
|
# Test phase. -race needs cgo and so a C compiler, which the Debian Go
|
||||||
FROM alpine@sha256:fd791d74b68913cbb027c6546007b3f0d3bc45125f797758156952bc2d6daf40
|
# image ships.
|
||||||
|
# golang:1.26.8-trixie, 2026-10-04. It carries Go 1.26.8, the version
|
||||||
|
# script/bootstrap installs on the host; change both together, and the
|
||||||
|
# same image in the last stage.
|
||||||
|
FROM golang@sha256:eae2aaa6add2936cbf350dd0d2628b363461542f0c4b3c0b558957e0f2997379 AS test
|
||||||
|
|
||||||
COPY --from=builder /src/keyfunc /usr/local/bin/keyfunc
|
WORKDIR /src
|
||||||
|
|
||||||
ENTRYPOINT ["keyfunc"]
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN go test -timeout 90s -race -cover ./... || \
|
||||||
|
{ echo "--- Rerunning with -v for details ---"; \
|
||||||
|
go test -timeout 90s -race -v ./...; exit 1; }
|
||||||
|
|
||||||
|
# Development environment, and the last stage: a plain `docker build .`
|
||||||
|
# builds this one. It holds the source tree in /src, what
|
||||||
|
# script/bootstrap installs, and keyfunc built from that tree on the
|
||||||
|
# PATH. Nothing is wanted from either phase above; the copies are what
|
||||||
|
# make BuildKit build them first, so this stage cannot run unless lint
|
||||||
|
# and test passed.
|
||||||
|
# golang:1.26.8-trixie, 2026-10-04
|
||||||
|
FROM golang@sha256:eae2aaa6add2936cbf350dd0d2628b363461542f0c4b3c0b558957e0f2997379
|
||||||
|
|
||||||
|
COPY --from=lint /src/go.sum /dev/null
|
||||||
|
COPY --from=test /src/go.sum /dev/null
|
||||||
|
|
||||||
|
# A tar-stream context keeps the sender's file owners, which git refuses.
|
||||||
|
RUN git config --system --add safe.directory /src
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
# script/bootstrap needs only script/ and the dependency manifests.
|
||||||
|
COPY script/ script/
|
||||||
|
COPY go.mod go.sum package.json yarn.lock ./
|
||||||
|
RUN script/bootstrap
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# The version stamped into the binary: the VERSION build argument when one
|
||||||
|
# is given, otherwise `git describe --tags --always` of the .git in the
|
||||||
|
# build context. A context that carries .git and still yields no version
|
||||||
|
# fails the build; with neither, as from a source tarball, it is "dev".
|
||||||
|
ARG VERSION
|
||||||
|
RUN version="${VERSION:-$(git describe --tags --always || echo dev)}"; \
|
||||||
|
if [ -e .git ] && { [ -z "$version" ] || [ "$version" = dev ] || \
|
||||||
|
[ "$version" = unknown ]; }; then \
|
||||||
|
echo "no version could be derived although the build context carries .git" >&2; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
make build VERSION="$version" && mv keyfunc /usr/local/bin/keyfunc
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
# The linter, pinned by hash, with this repository linted inside it.
|
|
||||||
# Building this file is how linting happens; see script/lint. Nothing
|
|
||||||
# lints on the host, so the answer is the same everywhere.
|
|
||||||
|
|
||||||
# golangci/golangci-lint:v2.12.2, 2026-09-07
|
|
||||||
FROM golangci/golangci-lint:v2.12.2@sha256:5cceeef04e53efe1470638d4b4b4f5ceefd574955ab3941b2d9a68a8c9ad5240
|
|
||||||
|
|
||||||
WORKDIR /src
|
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
|
||||||
RUN go mod download
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
RUN golangci-lint run --timeout 5m
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 sneak
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -3,7 +3,10 @@
|
|||||||
# which needs the version stamped into the binary.
|
# which needs the version stamped into the binary.
|
||||||
|
|
||||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
||||||
LDFLAGS := -s -w -X 'git.eeqj.de/sneak/keyfunc/internal/cli.Version=$(VERSION)'
|
LDFLAGS := -s -w -X 'sneak.berlin/go/keyfunc/internal/cli.Version=$(VERSION)'
|
||||||
|
|
||||||
|
# Where script/bootstrap installs Go; it cannot put it on our PATH.
|
||||||
|
export PATH := $(HOME)/.local/go/bin:$(PATH)
|
||||||
|
|
||||||
.PHONY: default bootstrap setup build test lint fmt fmt-check check \
|
.PHONY: default bootstrap setup build test lint fmt fmt-check check \
|
||||||
docker cibuild hooks clean
|
docker cibuild hooks clean
|
||||||
|
|||||||
@@ -1,16 +1,79 @@
|
|||||||
# keyfunc
|
# keyfunc
|
||||||
|
|
||||||
`keyfunc` turns a BIP-39 mnemonic into key pairs that can be recreated from
|
`keyfunc` is an MIT-licensed Go command-line tool by
|
||||||
that mnemonic at any time. The same mnemonic, key type and index always give the
|
[@sneak](https://sneak.berlin) that turns a BIP-39 mnemonic into SSH keys, age
|
||||||
same key.
|
identities and child mnemonics, each of which can be recreated from that
|
||||||
|
mnemonic at any time. The same mnemonic, key type and index always give the same
|
||||||
|
key.
|
||||||
|
|
||||||
It uses the BIP-85 entropy deriver from `git.eeqj.de/sneak/secret/pkg/bip85` and
|
It uses the BIP-85 entropy deriver from `git.eeqj.de/sneak/secret/pkg/bip85` and
|
||||||
takes the same steps as that repository's `agehd` package.
|
takes the same steps as that repository's `agehd` package.
|
||||||
|
|
||||||
Commands are grouped by what is derived: `keyfunc ssh ...` for ed25519 SSH
|
Commands are grouped by what is derived: `keyfunc ssh ...` for ed25519 SSH keys,
|
||||||
keys, `keyfunc age ...` for age identities and for encrypting and decrypting
|
`keyfunc age ...` for age identities and for encrypting and decrypting with
|
||||||
with them, and `keyfunc mnemonic ...` for child mnemonics derived from the
|
them, and `keyfunc mnemonic ...` for child mnemonics derived from the main one.
|
||||||
main one.
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Install with Go:
|
||||||
|
|
||||||
|
```
|
||||||
|
go install sneak.berlin/go/keyfunc/cmd/keyfunc@latest
|
||||||
|
```
|
||||||
|
|
||||||
|
Or build from a clone and run the binary:
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone git@git.eeqj.de:sneak/keyfunc.git
|
||||||
|
cd keyfunc
|
||||||
|
make build
|
||||||
|
./keyfunc --version
|
||||||
|
```
|
||||||
|
|
||||||
|
`make build` produces `./keyfunc`. Every deriving command needs a mnemonic; see
|
||||||
|
[Giving it the mnemonic](#giving-it-the-mnemonic) for where it is read from,
|
||||||
|
then for example:
|
||||||
|
|
||||||
|
```
|
||||||
|
./keyfunc ssh pub -n 0 --mnemonic-command 'secret get foo'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Rationale
|
||||||
|
|
||||||
|
A key you can derive again never has to be backed up. One mnemonic, kept safe
|
||||||
|
once, stands behind every key this tool produces: lose a laptop and the SSH key,
|
||||||
|
the age identity and any child mnemonic on it come back from the mnemonic alone,
|
||||||
|
at the same index, byte for byte. Nothing else has to be written down, copied
|
||||||
|
between machines, or stored in a secret manager, because it can always be
|
||||||
|
derived again.
|
||||||
|
|
||||||
|
## Design
|
||||||
|
|
||||||
|
The entry point is a thin `cmd/keyfunc/main.go` (what `make build` builds) that
|
||||||
|
calls into `internal/`. The packages there are:
|
||||||
|
|
||||||
|
- `internal/derive` turns a mnemonic into the 32 bytes a key is made from: it
|
||||||
|
walks BIP-39 seed, BIP-32 master key and BIP-85 entropy, and holds the shared
|
||||||
|
constants (the byte count and the largest key index).
|
||||||
|
- `internal/mnemonic` finds the mnemonic to work from — a command, an
|
||||||
|
environment variable, or a terminal prompt — and refuses one that fails the
|
||||||
|
BIP-39 checksum.
|
||||||
|
- `internal/sshkey` turns the derived bytes into an ed25519 SSH key
|
||||||
|
(`sshkey.go`) and serves that key from an in-process SSH agent on a private
|
||||||
|
unix socket, keeping it out of any file (`agent.go`).
|
||||||
|
- `internal/agekey` turns the derived bytes into an age identity and encrypts
|
||||||
|
and decrypts with it.
|
||||||
|
- `internal/childmnemonic` derives a child mnemonic from the main one using
|
||||||
|
BIP-85's own mnemonic application.
|
||||||
|
- `internal/cli` builds the cobra command tree and runs it. Under it,
|
||||||
|
`cli/options` holds the flags every command shares, and `cli/ssh`, `cli/age`
|
||||||
|
and `cli/mnemonic` are the command groups.
|
||||||
|
|
||||||
|
### Adding a key type
|
||||||
|
|
||||||
|
Adding a key type is one package under `internal/` that turns the 32 derived
|
||||||
|
bytes into that type's key, plus one cobra subcommand under `internal/cli/` that
|
||||||
|
groups its commands.
|
||||||
|
|
||||||
## Derivation
|
## Derivation
|
||||||
|
|
||||||
@@ -42,26 +105,32 @@ The mnemonic itself is never a command-line argument. It is looked for in this
|
|||||||
order; the first one found wins:
|
order; the first one found wins:
|
||||||
|
|
||||||
1. `--mnemonic-command <command>`: a shell command, run with `sh -c`, whose
|
1. `--mnemonic-command <command>`: a shell command, run with `sh -c`, whose
|
||||||
standard output is the mnemonic. Example: `--mnemonic-command 'secret get
|
standard output is the mnemonic. Example:
|
||||||
foo'`. Whitespace around the output is dropped. If the command exits with a
|
`--mnemonic-command 'secret get foo'`. If the command exits with a non-zero
|
||||||
non-zero status, the tool prints its standard error and exits with status 1.
|
status, the tool prints its standard error and exits with status 1.
|
||||||
2. Environment variable `KEYFUNC_MNEMONIC_COMMAND`: the same, as a shell
|
2. Environment variable `KEYFUNC_MNEMONIC_COMMAND`: the same, as a shell command
|
||||||
command held in the environment.
|
held in the environment.
|
||||||
3. Environment variable `KEYFUNC_MNEMONIC`: the mnemonic itself.
|
3. Environment variable `KEYFUNC_MNEMONIC`: the mnemonic itself.
|
||||||
4. A prompt on the terminal with echo turned off.
|
4. A prompt on the terminal with echo turned off.
|
||||||
|
|
||||||
If none of these is available and standard input is not a terminal, the tool
|
If none of these is available and standard input is not a terminal, the tool
|
||||||
refuses and exits with status 1. A mnemonic that fails the BIP-39 checksum is
|
refuses and exits with status 1. A mnemonic that fails the BIP-39 checksum is
|
||||||
refused with a message saying so.
|
refused with a message saying so. Keys are derived from the mnemonic's words
|
||||||
|
joined by single spaces, whatever whitespace is around or between them, so one
|
||||||
|
word per line, tabs or extra spaces give the same keys.
|
||||||
|
|
||||||
|
`KEYFUNC_MNEMONIC` and `KEYFUNC_MNEMONIC_COMMAND` are removed from the
|
||||||
|
environment before the system `ssh` (`keyfunc ssh to`) and `sftp`
|
||||||
|
(`keyfunc ssh install`) are started, so the mnemonic is never handed on to them.
|
||||||
|
|
||||||
Every command takes `--index` / `-n` and `--mnemonic-command`, and has `--help`.
|
Every command takes `--index` / `-n` and `--mnemonic-command`, and has `--help`.
|
||||||
`keyfunc --version` prints the version set at build time.
|
`keyfunc --version` prints the version. `make build` stamps it; a binary
|
||||||
|
installed with `go install` reports the module version instead.
|
||||||
|
|
||||||
## SSH keys: `keyfunc ssh`
|
## SSH keys: `keyfunc ssh`
|
||||||
|
|
||||||
Only ed25519 keys are produced. The application number is `838372`, so the
|
Only ed25519 keys are produced. The application number is `838372`, so the path
|
||||||
path is `m/83696968'/838372'/<n>'`. The 32 bytes from step 4 are the ed25519
|
is `m/83696968'/838372'/<n>'`. The 32 bytes from step 4 are the ed25519 seed.
|
||||||
seed.
|
|
||||||
|
|
||||||
Test vector, mnemonic
|
Test vector, mnemonic
|
||||||
`abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about`:
|
`abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about`:
|
||||||
@@ -91,25 +160,29 @@ same as for `pub`.
|
|||||||
### `keyfunc ssh install <[user@]host> [-- sftp options...]`
|
### `keyfunc ssh install <[user@]host> [-- sftp options...]`
|
||||||
|
|
||||||
Adds the `pub` line to `~/.ssh/authorized_keys` on the host. No command is run
|
Adds the `pub` line to `~/.ssh/authorized_keys` on the host. No command is run
|
||||||
on the host: the file is fetched, changed here, and written back with the
|
on the host: the file is fetched, changed here, and written back with the system
|
||||||
system `sftp` client in batch mode.
|
`sftp` client in batch mode.
|
||||||
|
|
||||||
The first connection fetches `~/.ssh/authorized_keys`. The file reads as empty
|
The first connection lists `~/.ssh`, then `~/.ssh/.`, and then fetches
|
||||||
only when `sftp` reported that file as not being there — the one line naming
|
`~/.ssh/authorized_keys`. The file reads as empty in two cases only: `sftp`
|
||||||
that path. The same wording anywhere else in the session does not count: `ssh`
|
reported `~/.ssh` itself as not being there, or both listings came up and the
|
||||||
writes `No such file or directory` about an `-i` it cannot find, on a session
|
file was not found. Any other outcome of that connection fails the run — a
|
||||||
that then authenticates through the agent. When `sftp` failed for any other
|
`~/.ssh` that is there but cannot be read or entered, an `authorized_keys` that
|
||||||
reason — the file is there and cannot be read, the connection did not come up —
|
is there but cannot be read, or a connection that did not come up — and the tool
|
||||||
the tool prints what `sftp` said and exits with status 1 without writing
|
prints what `sftp` said and exits with status 1 without writing anything, rather
|
||||||
anything, rather than put a file back holding the new key alone. What `sftp`
|
than put a file back holding the new key alone. The listings are what tell a
|
||||||
cannot tell apart is a missing file and one in a directory it cannot enter, so a
|
missing directory from one shut to the user, which `sftp` reports on a fetch the
|
||||||
`~/.ssh` whose mode shuts the user out reads as a host with no file; the second
|
same way: one that cannot be read fails the first listing, and one that can be
|
||||||
connection sets that mode to `0700` and writes, as on a host that has none. If
|
read but not entered fails the second, after which the tool says that `~/.ssh`
|
||||||
an identical line is already in the file, the tool prints
|
cannot be entered. The wording of a missing file elsewhere does not count
|
||||||
`already present` and connects no further. Otherwise the line is added (after a
|
either, since `ssh` writes `No such file or directory` about an `-i` it cannot
|
||||||
newline, if the file did not end with one) and a second connection:
|
find on a session that then authenticates through the agent. If an identical
|
||||||
|
line is already in the file, the tool prints `already present` and connects no
|
||||||
|
further. Otherwise the line is added (after a newline, if the file did not end
|
||||||
|
with one) and a second connection:
|
||||||
|
|
||||||
- creates `~/.ssh` and sets it to mode `0700`;
|
- makes `~/.ssh` and sets it to mode `0700`, but only when the first connection
|
||||||
|
found none; a `~/.ssh` that was already there keeps the mode it had;
|
||||||
- uploads the new file as `~/.ssh/authorized_keys.keyfunc-<random>` and sets it
|
- uploads the new file as `~/.ssh/authorized_keys.keyfunc-<random>` and sets it
|
||||||
to mode `0600`;
|
to mode `0600`;
|
||||||
- renames that file over `~/.ssh/authorized_keys`.
|
- renames that file over `~/.ssh/authorized_keys`.
|
||||||
@@ -117,20 +190,22 @@ newline, if the file did not end with one) and a second connection:
|
|||||||
The tool then prints `added`. So a run that adds a line connects twice. The
|
The tool then prints `added`. So a run that adds a line connects twice. The
|
||||||
rename is the step that either happens or does not: the file on the host is
|
rename is the step that either happens or does not: the file on the host is
|
||||||
never half-written. `sftp` does it in one step against servers that offer
|
never half-written. `sftp` does it in one step against servers that offer
|
||||||
OpenSSH's POSIX rename extension, as OpenSSH's own server does; a server
|
OpenSSH's POSIX rename extension, as OpenSSH's own server does; a server without
|
||||||
without it may refuse to rename onto a file that is already there.
|
it may refuse to rename onto a file that is already there.
|
||||||
|
|
||||||
If a step fails, the tool prints what `sftp` said, removes nothing, and exits
|
If a step fails, the tool prints what `sftp` said, removes nothing, and exits
|
||||||
with status 1. It names the uploaded file only when the step that failed was
|
with status 1. It names the uploaded file only when the step that failed was the
|
||||||
the upload or one after it, which is where a file of that name can be on the
|
upload or one after it, which is where a file of that name can be on the host; a
|
||||||
host; a failure before the upload names none. Everything `sftp`
|
failure before the upload names none. Everything `sftp` writes goes to standard
|
||||||
writes goes to standard error, so the tool's own standard output is only
|
error, so the tool's own standard output is only `added` or `already present`.
|
||||||
`added` or `already present`.
|
|
||||||
|
|
||||||
Anything after `--` is passed to `sftp` unchanged, which is where the port goes
|
Anything after `--` is passed to `sftp` unchanged, which is where the port goes
|
||||||
(`-P 2222`, not `-p`). How the connection authenticates is up to the user's
|
(`-P 2222`, not `-p`). How the connection authenticates is up to the user's
|
||||||
normal `ssh` setup, except that batch mode does not prompt: a key or an agent
|
normal `ssh` setup, except that batch mode does not prompt: a key or an agent
|
||||||
has to do it, not a typed password.
|
has to do it, not a typed password. Nor does it ask whether to trust a host key
|
||||||
|
it has not seen, so the host has to be in `known_hosts` already, or the run
|
||||||
|
fails with `Host key verification failed`. Connect to the host once with `ssh`
|
||||||
|
first, or pass `-o StrictHostKeyChecking=accept-new` after `--`.
|
||||||
|
|
||||||
### `keyfunc ssh to <host> [ssh arguments...]`
|
### `keyfunc ssh to <host> [ssh arguments...]`
|
||||||
|
|
||||||
@@ -138,15 +213,26 @@ Derives the key, serves it from an SSH agent that runs inside the tool on a unix
|
|||||||
socket in a new private `0700` temporary directory, then runs the system `ssh`
|
socket in a new private `0700` temporary directory, then runs the system `ssh`
|
||||||
with `-o IdentityAgent=<that socket>` followed by the host and all remaining
|
with `-o IdentityAgent=<that socket>` followed by the host and all remaining
|
||||||
arguments unchanged. The tool exits with `ssh`'s exit status and removes the
|
arguments unchanged. The tool exits with `ssh`'s exit status and removes the
|
||||||
socket and directory on the way out. The private key is never written to disk.
|
socket and directory on the way out. The private key is never written to disk. A
|
||||||
|
SIGINT, SIGTERM or SIGHUP ends `ssh` and still removes the socket and directory,
|
||||||
|
and the tool then exits with status 1 unless `ssh` reported one of its own.
|
||||||
|
|
||||||
## age identities: `keyfunc age`
|
## age identities: `keyfunc age`
|
||||||
|
|
||||||
The application number is `657169`, path `m/83696968'/657169'/<n>'`. The 32
|
The application number is `657169`, path `m/83696968'/657169'/<n>'`. The 32
|
||||||
bytes from step 4 are clamped as X25519 requires and become an age identity,
|
bytes from step 4 are clamped as X25519 requires and become an age identity, the
|
||||||
the same steps `sneak/secret` takes in its `agehd` package. `secret` derives at
|
same steps `sneak/secret` takes in its `agehd` package. `secret` derives at a
|
||||||
a vendor-specific path today; for its keys to equal this tool's it moves to
|
vendor-specific path today; for its keys to equal this tool's it moves to this
|
||||||
this path, which is a change in `secret`, not here.
|
path, which is a change in `secret`, not here.
|
||||||
|
|
||||||
|
Test vectors, mnemonic
|
||||||
|
`abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about`:
|
||||||
|
|
||||||
|
```
|
||||||
|
recipient index 0: age1xwdy9y6ckyfsgjc8k02e9uhsf3fmjy0ufysewlj68kmx5n67e3nsg2mftq
|
||||||
|
recipient index 1: age1pmm92sxaf5mazjwvjph7dx2zq9r5p8l3rarfgqm7hmakqhvgyy4q5p3w7j
|
||||||
|
identity index 0: AGE-SECRET-KEY-19QKK2P38598XLXMQFFU3P7J9PLDD7527T70JDHGDJ7AMNF3XT44S00JFU5
|
||||||
|
```
|
||||||
|
|
||||||
### `keyfunc age pub`
|
### `keyfunc age pub`
|
||||||
|
|
||||||
@@ -174,39 +260,98 @@ says so and exits with status 1.
|
|||||||
### `keyfunc mnemonic [-n N] [--words 12|18|24]`
|
### `keyfunc mnemonic [-n N] [--words 12|18|24]`
|
||||||
|
|
||||||
Prints a child mnemonic derived from the main one, using BIP-85's own mnemonic
|
Prints a child mnemonic derived from the main one, using BIP-85's own mnemonic
|
||||||
application (number `39`, English, path
|
application (number `39`, English, path `m/83696968'/39'/0'/<words>'/<n>'`,
|
||||||
`m/83696968'/39'/0'/<words>'/<n>'`, entropy taken as the specification says,
|
entropy taken as the specification says, not through step 4). Default 12 words.
|
||||||
not through step 4). Default 12 words. A child mnemonic is a full mnemonic in
|
A child mnemonic is a full mnemonic in its own right: it can seed another
|
||||||
its own right: it can seed another `keyfunc`, another wallet, or `secret`, and
|
`keyfunc`, another wallet, or `secret`, and it never has to be written down,
|
||||||
it never has to be written down, since it can be derived again.
|
since it can be derived again.
|
||||||
|
|
||||||
## Adding a key type
|
Test vector, mnemonic
|
||||||
|
`abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about`:
|
||||||
|
|
||||||
Adding a key type is one package under `internal/` that turns the 32 derived
|
```
|
||||||
bytes into that type's key, plus one cobra subcommand under `internal/cli/` that
|
index 0: prosper short ramp prepare exchange stove life snack client enough purpose fold
|
||||||
groups its commands.
|
```
|
||||||
|
|
||||||
|
The child-mnemonic step is also checked against BIP-85's own published vectors.
|
||||||
|
Those start from the specification's master key
|
||||||
|
`xprv9s21ZrQH143K2LBWUUQRFXhucrQqBpKdRRxNVq2zBqsx8HVqFk2uYo8kmbaLLHRdqtQpUm98uKfu3vca1LqdGhUtyoFnCNkfmXRyPXLjbKb`
|
||||||
|
rather than from a mnemonic, so they cannot be given to `keyfunc`; at key index
|
||||||
|
0 the 12-word English child mnemonic of that key is:
|
||||||
|
|
||||||
|
```
|
||||||
|
girl mad pet galaxy egg matter matrix prison refuse sense ordinary nose
|
||||||
|
```
|
||||||
|
|
||||||
## Errors
|
## Errors
|
||||||
|
|
||||||
Errors go to standard error and the exit status is 1, except for `ssh to`,
|
Errors go to standard error and the exit status is 1, except for `ssh to`, which
|
||||||
which passes through `ssh`'s own exit status.
|
passes through `ssh`'s own exit status.
|
||||||
|
|
||||||
## Building and running
|
## Entrypoints
|
||||||
|
|
||||||
```
|
The repo adheres to the
|
||||||
make build # produces ./keyfunc
|
[Scripts to Rule Them All](https://github.com/github/scripts-to-rule-them-all)
|
||||||
make check # fmt-check, lint (golangci-lint) and tests
|
standard: most Makefile targets are thin shims over an executable in `script/`
|
||||||
```
|
(`build` and `clean` are the exceptions).
|
||||||
|
|
||||||
Examples:
|
- `script/bootstrap` installs, idempotently, everything needed to build and
|
||||||
|
develop apart from Docker, which it only warns about when it is missing, and
|
||||||
|
the linter, which only runs inside Docker. In this order:
|
||||||
|
- git and make from nix, apt, brew or apk, and from there too curl and bash
|
||||||
|
when a later step needs them;
|
||||||
|
- Go at the version the `Dockerfile`'s Go image carries, from the official
|
||||||
|
release archive at go.dev (checked against a sha256 in the script) into
|
||||||
|
`~/.local/go`, unless the `go` first on the `PATH` already is that
|
||||||
|
version; then the Go modules. `script/bootstrap` itself, `script/fmt`,
|
||||||
|
`script/fmt-check`, `script/precommit` and the `Makefile` put
|
||||||
|
`~/.local/go/bin` first on their `PATH`, so they use that Go;
|
||||||
|
- node: an installed one is used as it is, otherwise a pinned one is
|
||||||
|
installed through nvm, which, when it is missing, comes from its release
|
||||||
|
archive, checked against a sha256;
|
||||||
|
- yarn: an installed one is used as it is, otherwise the pinned version
|
||||||
|
through corepack, or through npm where there is no corepack;
|
||||||
|
- the pinned prettier, through yarn.
|
||||||
|
- `script/setup` prepares a fresh clone: it runs `bootstrap`, then installs the
|
||||||
|
git pre-commit hook.
|
||||||
|
- `script/projectname` prints the project name; other scripts call it so they
|
||||||
|
stay identical across repos.
|
||||||
|
- `script/test` builds the `test` phase of the `Dockerfile` alone, uncached: the
|
||||||
|
test suite runs with the race detector inside the build, rerunning verbosely
|
||||||
|
if a test fails.
|
||||||
|
- `script/lint` builds the `lint` phase of the `Dockerfile` alone, uncached: the
|
||||||
|
linter, pinned by hash, runs inside the build, so a complaint fails it and
|
||||||
|
leaves no container behind.
|
||||||
|
- `script/fmt` formats in place: the Go source with `go fmt`, then every
|
||||||
|
Markdown file with prettier (four-space indents, prose wrapped at 80 columns).
|
||||||
|
- `script/fmt-check` checks the same files the same way without writing, failing
|
||||||
|
if anything is unformatted. Both need the node, yarn and prettier that
|
||||||
|
`bootstrap` installs.
|
||||||
|
- `script/check` runs `test`, `lint` and `fmt-check` and changes no files.
|
||||||
|
- `script/docker` builds the Docker image, uncached, tagged with the project
|
||||||
|
name and stamped with the version `git describe` gives on the host. The image
|
||||||
|
cannot be built unless the `lint` and `test` phases pass, so a plain
|
||||||
|
`docker build .` runs them too. The image is a development environment, not a
|
||||||
|
runtime image: the Debian Go image with what `script/bootstrap` installs, the
|
||||||
|
source tree in `/src`, and `keyfunc` built from it on the `PATH`.
|
||||||
|
`docker run --rm -it keyfunc` opens a shell in it.
|
||||||
|
- `script/cibuild` is the CI build the Gitea workflow calls: it runs
|
||||||
|
`bootstrap`, then `check`, then builds the image as `script/docker` does.
|
||||||
|
- `script/precommit` is what the git pre-commit hook runs: `go mod tidy` and
|
||||||
|
`go fmt`, failing if `go.mod` or `go.sum` changed, then `check`.
|
||||||
|
- `script/install-precommit` installs the git pre-commit hook that runs
|
||||||
|
`script/precommit`.
|
||||||
|
|
||||||
```
|
## TODO
|
||||||
keyfunc ssh pub -n 3 --mnemonic-command 'secret get foo'
|
|
||||||
keyfunc ssh priv -n 3 > ~/.ssh/id_bip85_3
|
The open issues that stand between the tree and a 1.0 release:
|
||||||
keyfunc ssh install -n 3 user@example.com
|
|
||||||
keyfunc ssh to -n 3 user@example.com uptime
|
- [#42 go-bip39 no longer exists upstream: keep it, or copy it into the repo?](https://git.eeqj.de/sneak/keyfunc/issues/42)
|
||||||
keyfunc age pub -n 0
|
|
||||||
keyfunc age encrypt -n 0 --armor -o notes.age notes.txt
|
## License
|
||||||
keyfunc age decrypt -n 0 notes.age
|
|
||||||
keyfunc mnemonic -n 1 --words 24
|
MIT. The full text is in [`LICENSE`](LICENSE).
|
||||||
```
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
[@sneak](https://sneak.berlin).
|
||||||
|
|||||||
+301
-79
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Repository Policies
|
title: Repository Policies
|
||||||
last_modified: 2026-08-19
|
last_modified: 2026-10-04
|
||||||
---
|
---
|
||||||
|
|
||||||
This document covers repository structure, tooling, and workflow standards. Code
|
This document covers repository structure, tooling, and workflow standards. Code
|
||||||
@@ -60,17 +60,28 @@ style conventions are in separate documents:
|
|||||||
prerequisite since nvm requires bash. yarn is then pinned via
|
prerequisite since nvm requires bash. yarn is then pinned via
|
||||||
`corepack prepare yarn@<version> --activate`. Never install "latest" or "lts";
|
`corepack prepare yarn@<version> --activate`. Never install "latest" or "lts";
|
||||||
always exact versions. `script/cibuild` runs the CI build: it changes to the
|
always exact versions. `script/cibuild` runs the CI build: it changes to the
|
||||||
repo root and runs `docker build .`; the Gitea workflow calls it. Four further
|
repo root, runs `script/bootstrap`, runs `script/check`, and builds the image
|
||||||
scripts are our own extensions to the standard: `script/check` runs
|
with the version; the Gitea workflow calls it. **`script/cibuild` runs
|
||||||
`script/test`, `script/lint`, and `script/fmt-check`; `script/precommit` is
|
`script/bootstrap` first**, because the workflow checks out the repo and runs
|
||||||
what the git pre-commit hook runs, and it calls `script/check`;
|
nothing else, while `script/fmt-check` runs the formatter on the host: on a
|
||||||
`script/install-precommit` installs the git pre-commit hook (the `make hooks`
|
pristine checkout with nothing installed the run dies there, after the
|
||||||
target shims to it); and `script/projectname` (literally that filename) simply
|
containerised gates have passed. **The bootstrap alone is not enough**:
|
||||||
outputs the project's name. Scripts that need the name call
|
`script/bootstrap` installs node and yarn under nvm and leaves neither on the
|
||||||
`script/projectname` — e.g. `script/docker` assembles its image tag from it —
|
`PATH` of the shell that called it, so a bare `yarn` still exits 127. The host
|
||||||
so those scripts stay byte-identical across all repos. Repo-type-specific
|
entrypoints that need yarn — `script/fmt` and `script/fmt-check` — therefore
|
||||||
pre-commit extras (e.g. `go mod tidy` verification in Go repos) belong in
|
source nvm for the pinned node version before invoking it, exactly as
|
||||||
`script/precommit`, not in the hook itself. Model scripts are at
|
`script/bootstrap`'s own install step does. A runner carrying nothing but
|
||||||
|
docker and git then gets through `script/check`. Four further scripts are our
|
||||||
|
own extensions to the standard: `script/check` runs `script/test`,
|
||||||
|
`script/lint` and `script/fmt-check`; `script/precommit` is what the git
|
||||||
|
pre-commit hook runs, and it calls `script/check`; `script/install-precommit`
|
||||||
|
installs the git pre-commit hook (the `make hooks` target shims to it); and
|
||||||
|
`script/projectname` (literally that filename) simply outputs the project's
|
||||||
|
name. Scripts that need the name call `script/projectname` — e.g.
|
||||||
|
`script/docker` assembles its image tag from it — so those scripts stay
|
||||||
|
byte-identical across all repos. Repo-type-specific pre-commit extras (e.g.
|
||||||
|
`go mod tidy` verification in Go repos) belong in `script/precommit`, not in
|
||||||
|
the hook itself. Model scripts are at
|
||||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/script/<name>`. The README
|
`https://git.eeqj.de/sneak/prompts/raw/branch/main/script/<name>`. The README
|
||||||
must document the provided scripts in an **Entrypoints** section (see the
|
must document the provided scripts in an **Entrypoints** section (see the
|
||||||
README requirements below).
|
README requirements below).
|
||||||
@@ -89,87 +100,171 @@ style conventions are in separate documents:
|
|||||||
contributor should be able to understand the entire development workflow by
|
contributor should be able to understand the entire development workflow by
|
||||||
reading the Makefile.
|
reading the Makefile.
|
||||||
|
|
||||||
- Every repo should have a `Dockerfile`. All Dockerfiles must run `make check`
|
- Every repo should have a `Dockerfile`, and it carries the repo's gates: a
|
||||||
as a build step so the build fails if the branch is not green. For non-server
|
`lint` phase and a `test` phase, with the final stage depending on both so the
|
||||||
repos, the Dockerfile should bring up a development environment and run
|
image cannot be built unless they pass. For non-server repos the final stage
|
||||||
`make check`. For server repos, `make check` should run as an early build
|
brings up a development environment; for server repos it is the runtime image.
|
||||||
stage before the final image is assembled. Dockerfiles install development
|
Dockerfiles install development prerequisites by running `script/bootstrap`
|
||||||
prerequisites by running `script/bootstrap` rather than duplicating installs
|
rather than duplicating installs inline; COPY `script/` and the dependency
|
||||||
inline; COPY `script/` and the dependency manifests (`package.json` +
|
manifests (`package.json` + `yarn.lock`, `go.mod` + `go.sum`, etc.) before
|
||||||
`yarn.lock`, `go.mod` + `go.sum`, etc.) before running it so the bootstrap
|
running it.
|
||||||
layer stays cached until dependencies change.
|
|
||||||
|
|
||||||
- **Dockerfiles must use a separate lint stage for fail-fast feedback.** Go
|
- **Linting and testing run in Docker, as phases of the `Dockerfile`.** There is
|
||||||
repos use a multistage build where linting runs in an independent stage based
|
no separate lint file. `script/lint` and `script/test` each build one phase
|
||||||
on the `golangci/golangci-lint` image (pinned by hash). This stage runs
|
and nothing else:
|
||||||
`make fmt-check` and `make lint` before the full build begins. The build stage
|
|
||||||
then declares an explicit dependency on the lint stage via
|
|
||||||
`COPY --from=lint /src/go.sum /dev/null`, which forces BuildKit to complete
|
|
||||||
linting before proceeding to compilation and tests. This ensures lint failures
|
|
||||||
surface in seconds rather than minutes, without blocking on dependency
|
|
||||||
download or compilation in the build stage.
|
|
||||||
|
|
||||||
The standard pattern for a Go repo Dockerfile is:
|
```sh
|
||||||
|
docker build --no-cache --target lint -t "$(script/projectname)-lint" .
|
||||||
|
docker build --no-cache --target test -t "$(script/projectname)-test" .
|
||||||
|
```
|
||||||
|
|
||||||
|
**A stage that is not the last one in the file is built only when the final
|
||||||
|
stage's chain depends on it, or when `--target` names it.** That is why the
|
||||||
|
two gates are always invoked by name here, and why the final stage carries a
|
||||||
|
`COPY --from=` of a harmless file from each of them: without that edge a
|
||||||
|
plain `docker build .` builds the last stage alone and exits 0 having linted
|
||||||
|
and tested nothing.
|
||||||
|
|
||||||
|
**Every `docker build` in `script/` is tagged**, here and in
|
||||||
|
`script/cibuild` and `script/docker`. An untagged build leaves a dangling
|
||||||
|
image behind on every invocation, on every developer host and every CI
|
||||||
|
runner; a tagged one replaces the previous image.
|
||||||
|
|
||||||
|
Inside a phase the tool is invoked directly — `golangci-lint`, `go test`,
|
||||||
|
`eslint`, `prettier` — never through `make lint` or `script/test`, which are
|
||||||
|
themselves a `docker build` and would recurse into a daemon that does not
|
||||||
|
exist in a build step. Formatting is the exception and stays on the host:
|
||||||
|
`script/fmt` writes the working tree, and `script/fmt-check` is its
|
||||||
|
read-only twin.
|
||||||
|
|
||||||
|
**No lint verdict may come from a host invocation of the linter.** On a
|
||||||
|
shared host golangci-lint reads a result cache keyed on file content rather
|
||||||
|
than location, so a second checkout of the same content is served the first
|
||||||
|
one's findings, and a host-global lock in `$TMPDIR` makes concurrent runs
|
||||||
|
exit non-zero with `parallel golangci-lint is running` — a status a caller
|
||||||
|
cannot tell from real findings. Both have produced wrong verdicts in this
|
||||||
|
org, in both directions. A container has its own cache, its own `TMPDIR` and
|
||||||
|
a digest-pinned binary, so neither is reachable.
|
||||||
|
|
||||||
|
- **Any build that runs checks is built with `--no-cache`.** Docker invalidates
|
||||||
|
a `COPY` layer only when the copied content changes, so on an unchanged tree
|
||||||
|
the check `RUN` is served from cache, nothing executes, and the build still
|
||||||
|
exits 0. Every `docker build` in `script/` therefore passes `--no-cache`:
|
||||||
|
`script/lint`, `script/test`, `script/cibuild` and `script/docker` are the
|
||||||
|
four, and there is no fifth — `script/check` runs the two gate phases and
|
||||||
|
`script/fmt-check`, and builds no image of its own. A bare `docker build .` is
|
||||||
|
not evidence that anything ran: a sub-second build reporting success is a
|
||||||
|
cache hit, not a result. Never invalidate by pruning — `docker builder prune`
|
||||||
|
and friends destroy a build cache shared with every other build on the host.
|
||||||
|
|
||||||
|
- **The gate phases are separate stages, and the build stage depends on both.**
|
||||||
|
The lint phase is based on the `golangci/golangci-lint` image (pinned by
|
||||||
|
hash), so lint failures surface in seconds rather than after a full compile,
|
||||||
|
and the test phase is based on the Debian Go image. The canonical Go repo
|
||||||
|
`Dockerfile`:
|
||||||
|
|
||||||
```dockerfile
|
```dockerfile
|
||||||
# Lint stage — fast feedback on formatting and lint issues
|
# Lint phase
|
||||||
# golangci/golangci-lint:v2.x.x, YYYY-MM-DD
|
# golangci/golangci-lint:v2.x.x, YYYY-MM-DD
|
||||||
FROM golangci/golangci-lint@sha256:... AS lint
|
FROM golangci/golangci-lint@sha256:... AS lint
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN make fmt-check
|
RUN golangci-lint run --config .golangci.yml ./...
|
||||||
RUN make lint
|
|
||||||
|
|
||||||
# Build stage
|
# Test phase. -race needs cgo and so a C compiler, which the Debian Go
|
||||||
# golang:1.x-alpine, YYYY-MM-DD
|
# image ships and the alpine one does not.
|
||||||
FROM golang@sha256:... AS builder
|
# golang:1.x, YYYY-MM-DD
|
||||||
|
FROM golang@sha256:... AS test
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# Force BuildKit to run the lint stage before proceeding
|
|
||||||
COPY --from=lint /src/go.sum /dev/null
|
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN make test
|
RUN go test -timeout 90s -race -cover ./... || \
|
||||||
|
{ echo "--- Rerunning with -v for details ---"; \
|
||||||
|
go test -timeout 90s -race -v ./...; exit 1; }
|
||||||
|
|
||||||
ARG VERSION=dev
|
# Build stage. Nothing is wanted from either phase above; the copies
|
||||||
RUN CGO_ENABLED=0 go build -trimpath \
|
# are what make BuildKit build them first, so this stage cannot run
|
||||||
|
# unless lint and test passed.
|
||||||
|
# golang:1.x-alpine, YYYY-MM-DD
|
||||||
|
FROM golang@sha256:... AS builder
|
||||||
|
COPY --from=lint /src/go.sum /dev/null
|
||||||
|
COPY --from=test /src/go.sum /dev/null
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
# A tar-stream context keeps the sender's file owners, which git refuses.
|
||||||
|
RUN git config --system --add safe.directory /src
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# The VERSION build arg when one is given, otherwise
|
||||||
|
# `git describe --tags --always` on the .git in the build context. With
|
||||||
|
# .git present, a version that is still empty, dev or unknown fails the
|
||||||
|
# build: git is missing or could not read the checkout.
|
||||||
|
ARG VERSION
|
||||||
|
RUN VERSION="${VERSION:-$(git describe --tags --always)}"; \
|
||||||
|
if [ -e .git ]; then \
|
||||||
|
case "$VERSION" in ""|dev|unknown) \
|
||||||
|
echo "version is '$VERSION' although .git is present" >&2; \
|
||||||
|
exit 1 ;; \
|
||||||
|
esac; \
|
||||||
|
fi; \
|
||||||
|
CGO_ENABLED=0 go build -trimpath \
|
||||||
-ldflags="-s -w -X main.Version=${VERSION}" \
|
-ldflags="-s -w -X main.Version=${VERSION}" \
|
||||||
-o /app ./cmd/app/
|
-o /app ./cmd/app/
|
||||||
|
|
||||||
# Runtime stage
|
# Runtime stage, and the last one
|
||||||
FROM alpine@sha256:...
|
FROM alpine@sha256:...
|
||||||
COPY --from=builder /app /usr/local/bin/app
|
COPY --from=builder /app /usr/local/bin/app
|
||||||
ENTRYPOINT ["app"]
|
ENTRYPOINT ["app"]
|
||||||
```
|
```
|
||||||
|
|
||||||
Key points:
|
Key points:
|
||||||
- The lint stage uses the `golangci/golangci-lint` image directly (it
|
- The lint phase uses the `golangci/golangci-lint` image directly (it has
|
||||||
includes both Go and the linter), so there is no need to install the
|
both Go and the linter), so nothing needs installing.
|
||||||
linter separately.
|
- `COPY --from=<phase> /src/go.sum /dev/null` is a no-op copy whose only
|
||||||
- `COPY --from=lint /src/go.sum /dev/null` is a no-op file copy that creates
|
purpose is the ordering edge. BuildKit runs stages in parallel by default,
|
||||||
a stage dependency. BuildKit runs stages in parallel by default; without
|
and a stage nothing depends on is not built at all, so without these two
|
||||||
this line, the build stage would not wait for lint to finish and a lint
|
lines a red gate would not fail the build.
|
||||||
failure might not fail the overall build.
|
- Keep the runtime stage last, and if you add a stage after it, give it the
|
||||||
|
same two copies. A plain `docker build .` builds the last stage's chain
|
||||||
|
and nothing else.
|
||||||
- If the project uses `//go:embed` directives that reference build artifacts
|
- If the project uses `//go:embed` directives that reference build artifacts
|
||||||
(e.g. a web frontend compiled in a separate stage), the lint stage must
|
(e.g. a web frontend compiled in a separate stage), the lint phase must
|
||||||
create placeholder files so the embed directives resolve. Example:
|
create placeholder files so the embed directives resolve. Example:
|
||||||
`RUN mkdir -p web/dist && touch web/dist/index.html web/dist/style.css`.
|
`RUN mkdir -p web/dist && touch web/dist/index.html web/dist/style.css`.
|
||||||
The lint stage should not depend on the actual build output — it exists to
|
|
||||||
fail fast.
|
|
||||||
- If the project requires CGO or system libraries for linting (e.g.
|
- If the project requires CGO or system libraries for linting (e.g.
|
||||||
`vips-dev`), install them in the lint stage with `apk add`.
|
`vips-dev`), install them in the lint phase with `apk add`.
|
||||||
- The build stage runs `make test` after compilation setup. Tests run in the
|
- `.dockerignore` lets `.git` into the build context. It keeps out
|
||||||
build stage, not the lint stage, because they may require compiled
|
`.git/config` and each submodule's `config` under `.git/modules/` at any
|
||||||
artifacts or heavier dependencies.
|
depth (`.git/modules/**/config`), which `git describe` does not need and
|
||||||
|
which can hold a credential: a password in a remote URL, or the token the
|
||||||
|
CI checkout step stores there. The stage that compiles has `git` (the
|
||||||
|
Debian Go image has it; an alpine one needs `apk add --no-cache git`) and
|
||||||
|
takes the version from the `VERSION` build argument when one is given,
|
||||||
|
otherwise from `git describe --tags --always`. That gives the tag on a
|
||||||
|
tagged commit; on a later commit, the tag, the number of commits since it
|
||||||
|
and the short commit (`v1.2.3-4-gabc1234`); and the short commit when no
|
||||||
|
tag is reachable. The stage that compiles also marks its working directory
|
||||||
|
safe for git (`git config --system --add safe.directory /src`): a context
|
||||||
|
sent as a tar stream keeps the sender's file owners, and git refuses a
|
||||||
|
checkout owned by another user, so the version would come out empty.
|
||||||
|
`ARG VERSION` has no default, and the build fails if the context carries
|
||||||
|
`.git` and the version still comes out empty, `dev` or `unknown`. A plain
|
||||||
|
`docker build .` with no build arguments must succeed; a Dockerfile that
|
||||||
|
refuses an empty build argument drops that refusal and keeps the argument.
|
||||||
|
|
||||||
- Every repo should have a Gitea Actions workflow (`.gitea/workflows/`) that
|
- Every repo should have a Gitea Actions workflow (`.gitea/workflows/`) that
|
||||||
runs `script/cibuild` (which runs `docker build .`) on push. Since the
|
runs `script/cibuild` on push, and checks out the repo as its only other step.
|
||||||
Dockerfile already runs `make check`, a successful build implies all checks
|
That script bootstraps, runs the gate phases, and then builds the image, so a
|
||||||
pass.
|
successful run means every check passed; a bare `docker build .` does not
|
||||||
|
carry the same guarantee, because its gate phases may come from the cache. The
|
||||||
|
image build is uncached and so runs the gate phases a second time. That is the
|
||||||
|
price of the rule above, and it is worth paying: the image that ships is built
|
||||||
|
from a run of its own gates rather than from a cache entry.
|
||||||
|
|
||||||
- Use platform-standard formatters: `black` for Python, `prettier` for
|
- Use platform-standard formatters: `black` for Python, `prettier` for
|
||||||
JS/CSS/Markdown/HTML, `go fmt` for Go. Always use default configuration with
|
JS/CSS/Markdown/HTML, `go fmt` for Go. Always use default configuration with
|
||||||
@@ -193,15 +288,17 @@ style conventions are in separate documents:
|
|||||||
suite that exceeds it fails. Under 20 seconds is the target. A suite between
|
suite that exceeds it fails. Under 20 seconds is the target. A suite between
|
||||||
20 and 60 seconds is still green, but the overage must be filed as an
|
20 and 60 seconds is still green, but the overage must be filed as an
|
||||||
improvement bug against that repo. Add a 90-second timeout to the test
|
improvement bug against that repo. Add a 90-second timeout to the test
|
||||||
invocation in the Makefile (`go test -timeout 90s`). The backstop deliberately
|
invocation (`go test -timeout 90s`). The backstop deliberately sits above the
|
||||||
sits above the hard cap so that it catches a genuinely hung test rather than a
|
hard cap so that it catches a genuinely hung test rather than a merely slow
|
||||||
merely slow one.
|
one.
|
||||||
|
|
||||||
- **`make test` should use the conditional verbose rerun pattern.** Run tests
|
- **The test command should use the conditional verbose rerun pattern.** Run
|
||||||
without `-v` (verbose) first. If tests fail, automatically rerun with `-v` to
|
tests without `-v` (verbose) first. If tests fail, automatically rerun with
|
||||||
show full output. This keeps CI logs and `docker build` output clean on
|
`-v` to show full output. This keeps CI logs and `docker build` output clean
|
||||||
success (just package/suite summaries) while providing full diagnostic detail
|
on success (just package/suite summaries) while providing full diagnostic
|
||||||
on failure (every test case, every assertion). The general shell pattern:
|
detail on failure (every test case, every assertion). The command lives in the
|
||||||
|
`test` phase of the `Dockerfile`, since `script/test` builds that phase; the
|
||||||
|
Makefile form below is the same pattern for any repo-local invocation:
|
||||||
|
|
||||||
```makefile
|
```makefile
|
||||||
test:
|
test:
|
||||||
@@ -214,11 +311,26 @@ style conventions are in separate documents:
|
|||||||
|
|
||||||
```makefile
|
```makefile
|
||||||
test:
|
test:
|
||||||
@go test -timeout 90s -race -cover ./... || \
|
@go test -count=1 -timeout 90s -race -cover ./... || \
|
||||||
{ echo "--- Rerunning with -v for details ---"; \
|
{ echo "--- Rerunning with -v for details ---"; \
|
||||||
go test -timeout 90s -race -v ./...; exit 1; }
|
go test -count=1 -timeout 90s -race -v ./...; exit 1; }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`-count=1` is required on both invocations: it defeats Go's test _result_
|
||||||
|
cache, so neither run can report a stored pass in place of running the
|
||||||
|
tests. It leaves the build cache alone, so it costs the runtime of the suite
|
||||||
|
and no recompilation.
|
||||||
|
|
||||||
|
That cache is Go's own, separate from Docker's layer cache. Go stores a
|
||||||
|
passing result in its cache directory (`GOCACHE`), and when the same tests
|
||||||
|
run again on unchanged code it prints that result, marked `(cached)`,
|
||||||
|
without running them. That matters on a developer's machine, where this
|
||||||
|
target runs and the directory lasts from one run to the next. The `test`
|
||||||
|
phase of the `Dockerfile` needs no `-count=1`: its base image holds no
|
||||||
|
result for this repo's tests and nothing before its `go test` step runs a
|
||||||
|
test, so there is nothing to replay. `--no-cache` (above) is what makes that
|
||||||
|
step run on an unchanged tree.
|
||||||
|
|
||||||
Python example:
|
Python example:
|
||||||
|
|
||||||
```makefile
|
```makefile
|
||||||
@@ -244,10 +356,84 @@ style conventions are in separate documents:
|
|||||||
must be in `.gitignore`. No exceptions.
|
must be in `.gitignore`. No exceptions.
|
||||||
|
|
||||||
- `.gitignore` should be comprehensive from the start: OS files (`.DS_Store`),
|
- `.gitignore` should be comprehensive from the start: OS files (`.DS_Store`),
|
||||||
editor files (`.swp`, `*~`), language build artifacts, and `node_modules/`.
|
editor files (`.swp`, `*~`), in-repo agent scratch directories (`.claude/`),
|
||||||
Fetch the standard `.gitignore` from
|
language build artifacts, and `node_modules/`. Fetch the standard `.gitignore`
|
||||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/.gitignore` when setting up
|
from `https://git.eeqj.de/sneak/prompts/raw/branch/main/.gitignore` when
|
||||||
a new repo.
|
setting up a new repo. These patterns are written to `.gitignore`'s own
|
||||||
|
semantics, in which an unanchored pattern already matches at every depth; they
|
||||||
|
are not a `.dockerignore` and must not be transplanted into one unmodified.
|
||||||
|
|
||||||
|
- **`.dockerignore` does not use `.gitignore` semantics, and copying patterns
|
||||||
|
across unmodified leaves secrets in the build context.** Docker matches with
|
||||||
|
`moby/patternmatcher`: `filepath.Match` semantics plus a `**` extension, so
|
||||||
|
`*` does not cross `/` and a pattern without a leading `**/` is anchored at
|
||||||
|
the build-context root. A `.dockerignore` listing `.env`, `*.pem` and `*.key`
|
||||||
|
therefore excludes only the copies at the repository root, while `config/.env`
|
||||||
|
and `certs/server.key` still reach the context and can land in an image layer
|
||||||
|
— which is more dangerous than a short file with no secret patterns at all,
|
||||||
|
because it reads as solved and stops anyone looking. Give every
|
||||||
|
depth-independent pattern the `**/` prefix and leave only genuinely
|
||||||
|
root-anchored entries unprefixed: `.claude`, and the repo's own host-built
|
||||||
|
binary, written `/myapp` and never `**/myapp`, which would also match
|
||||||
|
`cmd/myapp/` and delete the package directory from the context. Matching is
|
||||||
|
case-sensitive, and an ALL-CAPS twin per pattern still misses `Server.Key`, so
|
||||||
|
secret names use character ranges — `**/*.[kK][eE][yY]`, `**/*.[pP][eE][mM]`,
|
||||||
|
and likewise for `.envrc` and the extensionless SSH keys. Where such a pattern
|
||||||
|
also catches something the build needs, re-include it with a negation
|
||||||
|
(`!docs/example.env`); deleting the pattern reopens the exposure for every
|
||||||
|
other file it covers. Fetch the standard `.dockerignore` from
|
||||||
|
`https://git.eeqj.de/sneak/prompts/raw/branch/main/.dockerignore` and extend
|
||||||
|
it with the repo's own artifacts.
|
||||||
|
|
||||||
|
- **In-repo agent scratch belongs in both files, written to each file's own
|
||||||
|
semantics.** `.claude/` holds one worktree per in-flight agent — an entire
|
||||||
|
additional checkout of the repo — so under `COPY . .` the build context
|
||||||
|
inflates by a multiple of the repo and another session's unreviewed work can
|
||||||
|
be copied into an image layer. In `.gitignore` the entry is `.claude/`,
|
||||||
|
unanchored. In `.dockerignore` it is `.claude`, anchored and with **no** `**/`
|
||||||
|
prefix, because the prefixed form would also delete any nested directory of
|
||||||
|
that name from the build. Anchoring carries a known gap that the canonical
|
||||||
|
`.dockerignore` states in its own comment, since consuming repos receive the
|
||||||
|
file and not the tracker: the directory is created in the agent's working
|
||||||
|
directory, so a repo running agents in subdirectories still ships
|
||||||
|
`services/api/.claude/` and must add its own anchored entry there.
|
||||||
|
|
||||||
|
- **A plain `docker build .` of a clone stamps the version that
|
||||||
|
`git describe --tags --always` gives**, derived from the `.git` in the build
|
||||||
|
context as the canonical `Dockerfile` above shows. Without its failure check,
|
||||||
|
a missing `git` or an unreadable checkout would leave `-X main.Version=` empty
|
||||||
|
and the build would still exit 0. `script/docker` and `script/cibuild` pass
|
||||||
|
the version they compute on the host; it takes precedence. They do this
|
||||||
|
byte-identically across repos:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Own line: a failing command substitution inside an argument does not
|
||||||
|
# trip `set -e`, so the inline form degrades to an empty constant.
|
||||||
|
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||||
|
[ -n "$version" ] || version="unknown"
|
||||||
|
docker build --no-cache \
|
||||||
|
--build-arg VERSION="$version" \
|
||||||
|
-t "$(script/projectname)" .
|
||||||
|
```
|
||||||
|
|
||||||
|
`--always` makes an untagged repo yield an abbreviated commit hash rather
|
||||||
|
than failing, and the `[ -n "$version" ]` line is the single place the
|
||||||
|
fallback is applied — a live check that fires on a build from an export with
|
||||||
|
no `.git` and on a repository with no commits yet. Do not fold it into the
|
||||||
|
substitution as `|| echo unknown`, which makes the guard unreachable. The
|
||||||
|
Dockerfile's side is `ARG VERSION` in the stage that compiles, declared
|
||||||
|
there because `ARG` is stage-scoped; passing `VERSION` to a repo whose
|
||||||
|
Dockerfile declares no such `ARG` is ignored and costs nothing, which is why
|
||||||
|
the scripts stay byte-identical. One consequence for CI: the standard
|
||||||
|
checkout action clones shallow and fetches no tags, so a repo that embeds a
|
||||||
|
tag-derived version must set `fetch-depth: 0` on its checkout step.
|
||||||
|
|
||||||
|
- **Verify `.dockerignore` by enumerating the image, not by reading the
|
||||||
|
patterns.** Plant files at the root _and_ at least two directories deep, build
|
||||||
|
a probe image that does `COPY . .`, and list what actually landed
|
||||||
|
(`docker run --rm --entrypoint find IMAGE /app`). The `transferring context`
|
||||||
|
size is not a substitute: a nested secret is a few bytes, and BuildKit
|
||||||
|
transfers only the delta from the previous build.
|
||||||
|
|
||||||
- **No build artifacts in version control.** Code-derived data (compiled
|
- **No build artifacts in version control.** Code-derived data (compiled
|
||||||
bundles, minified output, generated assets) must never be committed to the
|
bundles, minified output, generated assets) must never be committed to the
|
||||||
@@ -269,9 +455,45 @@ style conventions are in separate documents:
|
|||||||
byte-identical, so that no repo can quietly loosen its own linting. Linter
|
byte-identical, so that no repo can quietly loosen its own linting. Linter
|
||||||
configuration changes are made to the canonical copy in the `prompts` repo and
|
configuration changes are made to the canonical copy in the `prompts` repo and
|
||||||
reach consuming repos by re-vendoring; an agent may open a PR against
|
reach consuming repos by re-vendoring; an agent may open a PR against
|
||||||
canonical, which only the user merges. The canonical golangci-lint version is
|
canonical, which only the user merges. One list is exempt from byte-identity,
|
||||||
v2.12.2 (released 2026-05-06), installed commit-pinned via
|
because it cannot be written once for every repo: the `deny` list of the
|
||||||
`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@c0d3ddc9cf3faa61a4e378e879ece580256d76e5`.
|
`test-support` depguard rule, where a repo names its own test-support packages
|
||||||
|
by full import path. A repo adds entries there and changes nothing else, and a
|
||||||
|
re-vendor carries its entries forward. The canonical golangci-lint version is
|
||||||
|
v2.14.0 (released 2026-09-24), pinned as the digest of the lint phase's base
|
||||||
|
image
|
||||||
|
(`golangci/golangci-lint@sha256:ad862ba6b3798cbe0fd9fd7408d498fd74fbd2623a92406b2fd3898faf0bf98f`,
|
||||||
|
which reports `2.14.0 built with go1.27.0 from 114493f9`). A module's `go`
|
||||||
|
directive must not name a newer Go minor version than the one golangci-lint
|
||||||
|
was built with, or golangci-lint refuses to lint it: this release lints
|
||||||
|
`go 1.27.1` but not `go 1.28`. That digest is the only pin, since no repo
|
||||||
|
installs golangci-lint on the host. A repo sets the lint phase digest to the
|
||||||
|
one named here and re-vendors `.golangci.yml` in the same commit, whichever of
|
||||||
|
the two prompted the change: the canonical copy can name linters that an older
|
||||||
|
golangci-lint rejects, and a newer golangci-lint can add linters that
|
||||||
|
`default: all` switches on until the canonical copy disables them.
|
||||||
|
|
||||||
|
- **`script/bootstrap` installs a pinned tool by comparing versions, never by
|
||||||
|
testing presence.** An `if ! command -v <tool>; then install; fi` guard tests
|
||||||
|
`PATH` only, so on an already-provisioned machine the pin is inert and a
|
||||||
|
version bump is a silent no-op — while the Dockerfile, installing into a clean
|
||||||
|
image, gets the pinned version, so a local `make check` and `make docker` can
|
||||||
|
disagree about what the tool even is. The canonical form:
|
||||||
|
- compares the installed version against the pin over the **whole** version
|
||||||
|
token; a parser that stops at the first `-` reports `2.12.2` for a host
|
||||||
|
running `2.12.2-rc1` and skips the install;
|
||||||
|
- treats absent, non-zero, empty or unrecognised `--version` output as a
|
||||||
|
mismatch, so the failure direction is a redundant install and never a
|
||||||
|
skipped one;
|
||||||
|
- after installing, re-resolves the binary the way callers do — `hash -r`,
|
||||||
|
then through `PATH`, not through the directory the installer wrote to —
|
||||||
|
and fails naming the resolved path, since an install that a shadowing
|
||||||
|
binary hides succeeds while changing nothing any caller sees;
|
||||||
|
- is actually called, and prints the version on both success paths: a
|
||||||
|
function defined and never invoked has the same exit status and the same
|
||||||
|
empty output as one that worked.
|
||||||
|
|
||||||
|
Keep it POSIX sh: no arrays, no `[[`, no `grep -P`.
|
||||||
|
|
||||||
- When pinning images or packages by hash, add a comment above the reference
|
- When pinning images or packages by hash, add a comment above the reference
|
||||||
with the version and date (YYYY-MM-DD).
|
with the version and date (YYYY-MM-DD).
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli"
|
"sneak.berlin/go/keyfunc/internal/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
module git.eeqj.de/sneak/keyfunc
|
module sneak.berlin/go/keyfunc
|
||||||
|
|
||||||
go 1.26
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
filippo.io/age v1.2.1
|
filippo.io/age v1.3.2
|
||||||
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd
|
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd
|
||||||
github.com/btcsuite/btcd v0.24.2
|
github.com/btcsuite/btcd v0.25.0
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.6
|
github.com/btcsuite/btcd/btcutil v1.2.0
|
||||||
github.com/spf13/cobra v1.9.1
|
github.com/spf13/cobra v1.10.2
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.12.1
|
||||||
github.com/tyler-smith/go-bip39 v1.1.0
|
github.com/tyler-smith/go-bip39 v1.1.0
|
||||||
golang.org/x/crypto v0.38.0
|
golang.org/x/crypto v0.57.0
|
||||||
golang.org/x/term v0.32.0
|
golang.org/x/term v0.46.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.1.3 // indirect
|
filippo.io/hpke v0.4.0 // indirect
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
|
github.com/btcsuite/btcd/btcec/v2 v2.5.0 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0 // indirect
|
||||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee // indirect
|
||||||
github.com/spf13/pflag v1.0.6 // indirect
|
github.com/spf13/pflag v1.0.9 // indirect
|
||||||
golang.org/x/sys v0.33.0 // indirect
|
go.yaml.in/yaml/v3 v3.0.5 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
golang.org/x/sys v0.48.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,136 +1,50 @@
|
|||||||
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805 h1:u2qwJeEvnypw+OCPUHmoZE3IqwfuN5kgDfo5MLzpNM0=
|
c2sp.org/CCTV/age v0.0.0-20260829155415-4448f2097b2d h1:Blprhc2SbChNZtWcU+BLTM4YdoqYAS9V7cJgOwJKyAs=
|
||||||
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805/go.mod h1:FomMrUJ2Lxt5jCLmZkG3FHa72zUprnhd3v/Z18Snm4w=
|
c2sp.org/CCTV/age v0.0.0-20260829155415-4448f2097b2d/go.mod h1:SrHC2C7r5GkDk8R+NFVzYy/sdj0Ypg9htaPXQq5Cqeo=
|
||||||
filippo.io/age v1.2.1 h1:X0TZjehAZylOIj4DubWYU1vWQxv9bJpo+Uu2/LGhi1o=
|
filippo.io/age v1.3.2 h1:r6RSZLFSMm6rzKepZ7ZAYkKCu14f3/Me8c7uKYh7C8c=
|
||||||
filippo.io/age v1.2.1/go.mod h1:JL9ew2lTN+Pyft4RiNGguFfOpewKwSHm5ayKD/A4004=
|
filippo.io/age v1.3.2/go.mod h1:TH/Yr2sSRhCKbaH4XPxpUV0Us8Gv6txYUpiZQWz8Evk=
|
||||||
|
filippo.io/hpke v0.4.0 h1:p575VVQ6ted4pL+it6M00V/f2qTZITO0zgmdKCkd5+A=
|
||||||
|
filippo.io/hpke v0.4.0/go.mod h1:EmAN849/P3qdeK+PCMkDpDm83vRHM5cDipBJ8xbQLVY=
|
||||||
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd h1:6YFV6horz2wDFPWWhour8qx8gLGyO0qoplwEeOuQ2J4=
|
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd h1:6YFV6horz2wDFPWWhour8qx8gLGyO0qoplwEeOuQ2J4=
|
||||||
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd/go.mod h1:gKCcMZvlBOqusn/BxR8IyFmSJQr6R4vvjJ926iNpOSI=
|
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd/go.mod h1:gKCcMZvlBOqusn/BxR8IyFmSJQr6R4vvjJ926iNpOSI=
|
||||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
github.com/btcsuite/btcd v0.25.0 h1:JPbjwvHGpSywBRuorFFqTjaVP4y6Qw69XJ1nQ6MyWJM=
|
||||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
github.com/btcsuite/btcd v0.25.0/go.mod h1:qbPE+pEiR9643E1s1xu57awsRhlCIm1ZIi6FfeRA4KE=
|
||||||
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
|
github.com/btcsuite/btcd/btcec/v2 v2.5.0 h1:KioMXOWa76b86sTZZOmbzv/ldaQCmB8KFAyn5PbB8E8=
|
||||||
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
|
github.com/btcsuite/btcd/btcec/v2 v2.5.0/go.mod h1:+K/MYXcLBtHEQjRbjHuJChuybk4LCgjdjgRwil+e+Kk=
|
||||||
github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY=
|
github.com/btcsuite/btcd/btcutil v1.2.0 h1:p3+S2g3Q+7G5NOh4Ji+2UrBOrg5Z0Q4ykzShWG1Dhgs=
|
||||||
github.com/btcsuite/btcd v0.24.2/go.mod h1:5C8ChTkl5ejr3WHj8tkQSCmydiMEPB0ZhQhehpq7Dgg=
|
github.com/btcsuite/btcd/btcutil v1.2.0/go.mod h1:/Taflm113pYjUpbWKKQEfa6XOtI/+WS8awxeMZpY75k=
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
|
github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0 h1:yMIg99+4aBvqfl/HzJRKfxTX9rGfikoI9uvFzterhc8=
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.1.3 h1:xM/n3yIhHAhHy04z4i43C8p4ehixJZMsnrVJkgl+MTE=
|
github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0/go.mod h1:Y72Ren9gfhlEvnwnT78BGcSNO2UMphTKLn9AorF+5rg=
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
|
|
||||||
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
|
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
|
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.5/go.mod h1:PSZZ4UitpLBWzxGd5VGOrLnmOjtPP/a6HaFo12zMs00=
|
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.6 h1:zFL2+c3Lb9gEgqKNzowKUPQNb8jV7v5Oaodi/AYFd6c=
|
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.6/go.mod h1:9dFymx8HpuLqBnsPELrImQeTQfKBQqzqGbbV3jK55aE=
|
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
|
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
|
||||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
|
||||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
|
||||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
|
||||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
|
||||||
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
|
|
||||||
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
|
||||||
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
|
||||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
|
||||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
|
||||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
|
||||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
|
|
||||||
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
|
||||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee h1:FPP9HDkBbPyniu+u7FHZg+kKFX1WW0gxOGteJ0h3AJk=
|
||||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee/go.mod h1:N6sz6HwJAenJ6d+/xmSl0ikfV05ZrVGmjt1ryy/WOtE=
|
||||||
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
|
|
||||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
|
||||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
|
||||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
|
||||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
|
||||||
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
|
||||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
|
||||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
|
||||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
||||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
|
||||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
|
||||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
||||||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
|
|
||||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
|
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
|
||||||
|
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
|
golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
|
||||||
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
|
golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
|
||||||
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
|
||||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE=
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc=
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
|
||||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
|
||||||
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
|
|
||||||
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
|
||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
|
||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/agekey"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/agekey"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The recipients the example mnemonic produces at the first two
|
// The recipients the example mnemonic produces at the first two
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"git.eeqj.de/sneak/secret/pkg/bip85"
|
"git.eeqj.de/sneak/secret/pkg/bip85"
|
||||||
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||||
bip39 "github.com/tyler-smith/go-bip39"
|
bip39 "github.com/tyler-smith/go-bip39"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// english is the number BIP-85 gives the English word list.
|
// english is the number BIP-85 gives the English word list.
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/childmnemonic"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
bip39 "github.com/tyler-smith/go-bip39"
|
bip39 "github.com/tyler-smith/go-bip39"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/childmnemonic"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The lengths the tool offers, and one it does not.
|
// The lengths the tool offers, and one it does not.
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/agekey"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli/options"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/agekey"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli/options"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command returns the age command and everything under it.
|
// Command returns the age command and everything under it.
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/agekey"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/mnemonic"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/agekey"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTheAgeCommandsPrintTheKey(t *testing.T) {
|
func TestTheAgeCommandsPrintTheKey(t *testing.T) {
|
||||||
|
|||||||
+47
-10
@@ -2,31 +2,58 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"runtime/debug"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli/age"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli/mnemonic"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli/options"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli/ssh"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli/age"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli/mnemonic"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli/options"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version is what --version prints. The build sets it.
|
// devVersion is what Version holds until a build stamps a real one.
|
||||||
|
const devVersion = "dev"
|
||||||
|
|
||||||
|
// Version is what --version prints. make build stamps it with -ldflags.
|
||||||
//
|
//
|
||||||
//nolint:gochecknoglobals // set at build time with -ldflags
|
//nolint:gochecknoglobals // set at build time with -ldflags
|
||||||
var Version = "dev"
|
var Version = devVersion
|
||||||
|
|
||||||
|
// resolveVersion chooses what --version reports. A value stamped at
|
||||||
|
// build time wins. Otherwise, for a binary from go install, the module
|
||||||
|
// version recorded in the build info is used, unless that is empty or
|
||||||
|
// the "(devel)" of a local build. When neither names a version, the
|
||||||
|
// "dev" fallback stays.
|
||||||
|
func resolveVersion(stamped string, info *debug.BuildInfo) string {
|
||||||
|
if stamped != devVersion {
|
||||||
|
return stamped
|
||||||
|
}
|
||||||
|
|
||||||
|
if info != nil && info.Main.Version != "" &&
|
||||||
|
info.Main.Version != "(devel)" {
|
||||||
|
return info.Main.Version
|
||||||
|
}
|
||||||
|
|
||||||
|
return devVersion
|
||||||
|
}
|
||||||
|
|
||||||
// Root returns the whole command tree.
|
// Root returns the whole command tree.
|
||||||
func Root() *cobra.Command {
|
func Root() *cobra.Command {
|
||||||
|
info, _ := debug.ReadBuildInfo()
|
||||||
|
|
||||||
root := &cobra.Command{
|
root := &cobra.Command{
|
||||||
Use: "keyfunc",
|
Use: "keyfunc",
|
||||||
Short: "derive key pairs from a BIP-39 mnemonic",
|
Short: "derive key pairs from a BIP-39 mnemonic",
|
||||||
Long: "keyfunc turns a BIP-39 mnemonic into key pairs that can " +
|
Long: "keyfunc turns a BIP-39 mnemonic into key pairs that can " +
|
||||||
"be recreated from that mnemonic at any time. The same " +
|
"be recreated from that mnemonic at any time. The same " +
|
||||||
"mnemonic, key type and index always give the same key.",
|
"mnemonic, key type and index always give the same key.",
|
||||||
Version: Version,
|
Version: resolveVersion(Version, info),
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
}
|
}
|
||||||
@@ -42,14 +69,24 @@ func Root() *cobra.Command {
|
|||||||
// status of its own, which "ssh to" uses to hand on the status ssh
|
// status of its own, which "ssh to" uses to hand on the status ssh
|
||||||
// ended with. ssh has already said whatever it had to say in that
|
// ended with. ssh has already said whatever it had to say in that
|
||||||
// case, so nothing more is printed.
|
// case, so nothing more is printed.
|
||||||
|
//
|
||||||
|
// SIGINT, SIGTERM and SIGHUP cancel the command's context instead of
|
||||||
|
// killing the process outright, so the child ssh or sftp ends and the
|
||||||
|
// deferred cleanup that removes the agent socket and the install
|
||||||
|
// working directory still runs.
|
||||||
func Main() int {
|
func Main() int {
|
||||||
err := Root().Execute()
|
ctx, stop := signal.NotifyContext(
|
||||||
|
context.Background(),
|
||||||
|
syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP,
|
||||||
|
)
|
||||||
|
defer stop()
|
||||||
|
|
||||||
|
err := Root().ExecuteContext(ctx)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var passed ssh.StatusError
|
if passed, ok := errors.AsType[ssh.StatusError](err); ok {
|
||||||
if errors.As(err, &passed) {
|
|
||||||
return passed.Status
|
return passed.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/childmnemonic"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/mnemonic"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
bip39 "github.com/tyler-smith/go-bip39"
|
bip39 "github.com/tyler-smith/go-bip39"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/childmnemonic"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The two lines the README says the example mnemonic produces.
|
// The two lines the README says the example mnemonic produces.
|
||||||
@@ -22,6 +22,11 @@ const (
|
|||||||
"0I4FKs+eVUulTPHfk9VtXw1tMF"
|
"0I4FKs+eVUulTPHfk9VtXw1tMF"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The child mnemonic the README says the example mnemonic gives at
|
||||||
|
// index 0.
|
||||||
|
const childZero = "prosper short ramp prepare exchange stove life " +
|
||||||
|
"snack client enough purpose fold"
|
||||||
|
|
||||||
// The two child mnemonic lengths the tests ask for.
|
// The two child mnemonic lengths the tests ask for.
|
||||||
const (
|
const (
|
||||||
twelve = 12
|
twelve = 12
|
||||||
@@ -45,6 +50,28 @@ func TestTheReadmeTestVectors(t *testing.T) {
|
|||||||
vectorOne+" keyfunc/ssh/1",
|
vectorOne+" keyfunc/ssh/1",
|
||||||
strings.TrimSpace(run(t, "ssh", "pub", "-n", "1")),
|
strings.TrimSpace(run(t, "ssh", "pub", "-n", "1")),
|
||||||
)
|
)
|
||||||
|
require.Equal(t,
|
||||||
|
childZero, strings.TrimSpace(run(t, "mnemonic", "-n", "0")),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTheSpacingBetweenTheWordsDoesNotChangeTheKeys(t *testing.T) {
|
||||||
|
words := strings.Fields(example())
|
||||||
|
|
||||||
|
for name, spaced := range map[string]string{
|
||||||
|
"one word per line": strings.Join(words, "\n"),
|
||||||
|
"double spaces": strings.Join(words, " "),
|
||||||
|
"tabs": strings.Join(words, "\t"),
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
t.Setenv(mnemonic.Variable, spaced)
|
||||||
|
|
||||||
|
require.Equal(t,
|
||||||
|
vectorZero+" keyfunc/ssh/0",
|
||||||
|
strings.TrimSpace(run(t, "ssh", "pub", "-n", "0")),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTheCommentCanBeChosen(t *testing.T) {
|
func TestTheCommentCanBeChosen(t *testing.T) {
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ package mnemonic
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/childmnemonic"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli/options"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/childmnemonic"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli/options"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command returns the mnemonic command.
|
// Command returns the mnemonic command.
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ package options
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/mnemonic"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add gives a command the flags that every command has. They are
|
// Add gives a command the flags that every command has. They are
|
||||||
|
|||||||
+102
-22
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -32,6 +33,12 @@ const (
|
|||||||
localMode = 0o600
|
localMode = 0o600
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrCannotEnter is the refusal of a host whose .ssh is there but
|
||||||
|
// cannot be entered, so that nothing in it can be read or written.
|
||||||
|
var ErrCannotEnter = errors.New(
|
||||||
|
"~/.ssh is there on the host but cannot be entered",
|
||||||
|
)
|
||||||
|
|
||||||
// install returns the command that adds the public key to a host.
|
// install returns the command that adds the public key to a host.
|
||||||
func install() *cobra.Command {
|
func install() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@@ -76,7 +83,7 @@ func add(cmd *cobra.Command, host string, options []string, line string) error {
|
|||||||
|
|
||||||
defer func() { _ = os.RemoveAll(work) }()
|
defer func() { _ = os.RemoveAll(work) }()
|
||||||
|
|
||||||
content, err := fetch(cmd, host, options,
|
content, present, err := fetch(cmd, host, options,
|
||||||
filepath.Join(work, "authorized_keys"),
|
filepath.Join(work, "authorized_keys"),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -88,16 +95,18 @@ func add(cmd *cobra.Command, host string, options []string, line string) error {
|
|||||||
return write(cmd, "already present\n")
|
return write(cmd, "already present\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
return upload(cmd, host, options, work, merged)
|
return upload(cmd, host, options, work, merged, present)
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload writes the new file to the host and renames it over
|
// upload writes the new file to the host and renames it over
|
||||||
// authorized_keys, which is the step that either happens or does not.
|
// authorized_keys, which is the step that either happens or does not.
|
||||||
// Nothing is removed when a step fails: the file left behind is named
|
// Nothing is removed when a step fails: the file left behind is named
|
||||||
// so that it can be looked at and cleared away by hand.
|
// so that it can be looked at and cleared away by hand. The directory
|
||||||
|
// is made and set to its mode only when the read found none: an .ssh
|
||||||
|
// that was already there is left with the mode it had.
|
||||||
func upload(
|
func upload(
|
||||||
cmd *cobra.Command, host string, options []string,
|
cmd *cobra.Command, host string, options []string,
|
||||||
work, merged string,
|
work, merged string, present bool,
|
||||||
) error {
|
) error {
|
||||||
local := filepath.Join(work, "authorized_keys.merged")
|
local := filepath.Join(work, "authorized_keys.merged")
|
||||||
|
|
||||||
@@ -111,14 +120,24 @@ func upload(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// The mkdir may fail: the directory is usually there already.
|
var batch []string
|
||||||
said, err := session(cmd, host, options, []string{
|
|
||||||
"-mkdir " + directory,
|
if !present {
|
||||||
"chmod " + directoryMode + " " + directory,
|
// The mkdir is allowed to fail in case the directory appeared
|
||||||
"put " + quoted(local) + " " + sidecar,
|
// between the read and now; the chmod then sets its mode.
|
||||||
"chmod " + fileMode + " " + sidecar,
|
batch = append(batch,
|
||||||
"rename " + sidecar + " " + authorized,
|
"-mkdir "+directory,
|
||||||
})
|
"chmod "+directoryMode+" "+directory,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
batch = append(batch,
|
||||||
|
"put "+quoted(local)+" "+sidecar,
|
||||||
|
"chmod "+fileMode+" "+sidecar,
|
||||||
|
"rename "+sidecar+" "+authorized,
|
||||||
|
)
|
||||||
|
|
||||||
|
said, err := session(cmd, host, options, batch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// sftp echoes each command as it runs it and stops at the
|
// sftp echoes each command as it runs it and stops at the
|
||||||
// first that fails, so the name is in what it said only once
|
// first that fails, so the name is in what it said only once
|
||||||
@@ -154,6 +173,7 @@ func session(
|
|||||||
|
|
||||||
//nolint:gosec // the options are the user's own, meant for sftp
|
//nolint:gosec // the options are the user's own, meant for sftp
|
||||||
command := exec.CommandContext(cmd.Context(), "sftp", argv...)
|
command := exec.CommandContext(cmd.Context(), "sftp", argv...)
|
||||||
|
command.Env = childEnv()
|
||||||
command.Stdin = strings.NewReader(strings.Join(batch, "\n") + "\n")
|
command.Stdin = strings.NewReader(strings.Join(batch, "\n") + "\n")
|
||||||
command.Stdout = &said
|
command.Stdout = &said
|
||||||
command.Stderr = &said
|
command.Stderr = &said
|
||||||
@@ -185,31 +205,91 @@ func merge(content, line string) (string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetch brings the host's authorized_keys into the given path and
|
// fetch brings the host's authorized_keys into the given path and
|
||||||
// returns what is in it. A host that has no such file reads as empty,
|
// returns what is in it, and whether the .ssh directory was already
|
||||||
// but only when that is what sftp said about it: a file that is there
|
// there. The one session lists .ssh, then .ssh/., and then gets the
|
||||||
// and cannot be read fails the run, because writing back over it
|
// file, so the listings settle the state of the directory before the
|
||||||
// would leave the host with the new key and nothing else.
|
// get is read.
|
||||||
|
//
|
||||||
|
// The file reads as empty in just two cases: sftp reported .ssh itself
|
||||||
|
// as not there, or both listings succeeded and the get then reported
|
||||||
|
// the file as not there. Anything else — a listing refused, the file
|
||||||
|
// there but unreadable, the connection down — fails the run and writes
|
||||||
|
// nothing, because writing back over what was not read would leave the
|
||||||
|
// host with the new key and nothing else. sftp cannot tell a missing
|
||||||
|
// file from one in a directory it cannot enter, so the listings do: a
|
||||||
|
// directory that is there but cannot be read fails the first, and one
|
||||||
|
// that can be read but not entered fails the second, because nothing in
|
||||||
|
// it can be looked up, not even ".". The first listing of such a
|
||||||
|
// directory comes up empty, as the server leaves out every name it
|
||||||
|
// cannot look up.
|
||||||
func fetch(
|
func fetch(
|
||||||
cmd *cobra.Command, host string, options []string, into string,
|
cmd *cobra.Command, host string, options []string, into string,
|
||||||
) (string, error) {
|
) (string, bool, error) {
|
||||||
said, err := session(cmd, host, options, []string{
|
said, err := session(cmd, host, options, []string{
|
||||||
|
"ls -1 " + directory,
|
||||||
|
"ls -1 " + directory + "/.",
|
||||||
"get " + authorized + " " + quoted(into),
|
"get " + authorized + " " + quoted(into),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if absent(said) {
|
if listingNotFound(said, directory) {
|
||||||
return "", nil
|
return "", false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", err
|
if listingNotFound(said, directory+"/.") {
|
||||||
|
return "", false, ErrCannotEnter
|
||||||
|
}
|
||||||
|
|
||||||
|
if absent(said) {
|
||||||
|
return "", true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gosec // the path is a temporary file of the tool's own
|
//nolint:gosec // the path is a temporary file of the tool's own
|
||||||
content, err := os.ReadFile(into)
|
content, err := os.ReadFile(into)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("reading the fetched file: %w", err)
|
return "", false, fmt.Errorf("reading the fetched file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(content), nil
|
return string(content), true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// listingNotFound says whether sftp reported the path it was asked to
|
||||||
|
// list as not being there. For .ssh that is the one listing failure
|
||||||
|
// read as a host that has no authorized_keys yet; for .ssh/., once .ssh
|
||||||
|
// itself has been listed, it is a .ssh that is there but cannot be
|
||||||
|
// entered. The reading is taken only from the line in which sftp
|
||||||
|
// reports on that path: any other failure of a listing, in particular a
|
||||||
|
// directory that is there but cannot be read, is left as a failure, so
|
||||||
|
// that no key is written to a host whose keys were never read.
|
||||||
|
func listingNotFound(said, path string) bool {
|
||||||
|
for line := range strings.Lines(said) {
|
||||||
|
named, is := reportedCannotList(strings.TrimSpace(line))
|
||||||
|
if is && (named == path || strings.HasSuffix(named, "/"+path)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// reportedCannotList returns the path an sftp line reports it cannot
|
||||||
|
// list for want of it, and whether the line is such a report. The
|
||||||
|
// client writes this one wording when it cannot look up the path a
|
||||||
|
// listing names, giving the path the server expanded.
|
||||||
|
func reportedCannotList(line string) (string, bool) {
|
||||||
|
const (
|
||||||
|
before = `Can't ls: "`
|
||||||
|
after = `" not found`
|
||||||
|
)
|
||||||
|
|
||||||
|
if !strings.HasPrefix(line, before) ||
|
||||||
|
!strings.HasSuffix(line, after) {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.TrimSuffix(strings.TrimPrefix(line, before), after), true
|
||||||
}
|
}
|
||||||
|
|
||||||
// absent says whether sftp reported the file that was asked for as
|
// absent says whether sftp reported the file that was asked for as
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import "testing"
|
|||||||
const (
|
const (
|
||||||
echoed = `sftp> get .ssh/authorized_keys "/tmp/keyfunc/authorized_keys"
|
echoed = `sftp> get .ssh/authorized_keys "/tmp/keyfunc/authorized_keys"
|
||||||
`
|
`
|
||||||
|
listed = "sftp> ls -1 .ssh\n"
|
||||||
warning = `Warning: Identity file /gone not accessible: ` +
|
warning = `Warning: Identity file /gone not accessible: ` +
|
||||||
"No such file or directory.\n"
|
"No such file or directory.\n"
|
||||||
)
|
)
|
||||||
@@ -76,3 +77,65 @@ func TestAbsenceIsReadOnlyFromWhatSFTPSaidAboutAuthorizedKeys(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestTheDirectoryIsReadAsAbsentOnlyFromTheListingSayingSo holds the
|
||||||
|
// wordings the OpenSSH client was seen to use when a listing fails: a
|
||||||
|
// directory it cannot find is reported one way, and one it cannot read
|
||||||
|
// another, and only the first is read as a host with no .ssh yet. A
|
||||||
|
// .ssh that can be read but not entered lists as empty, and the
|
||||||
|
// listing of .ssh/. that follows reports that path, not .ssh, as not
|
||||||
|
// found.
|
||||||
|
func TestTheDirectoryIsReadAsAbsentOnlyFromTheListingSayingSo(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
listings := map[string]struct {
|
||||||
|
said string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
"the directory is not there": {
|
||||||
|
said: listed + `Can't ls: "/home/someone/.ssh" not found` + "\n",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
"the directory is not there, named as it was asked for": {
|
||||||
|
said: listed + `Can't ls: ".ssh" not found` + "\n",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
"the directory is not there and an identity file is not either": {
|
||||||
|
said: warning + listed +
|
||||||
|
`Can't ls: "/home/someone/.ssh" not found` + "\n",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
"the directory is there and cannot be read": {
|
||||||
|
said: listed +
|
||||||
|
`remote readdir("/home/someone/.ssh/"): Permission denied` + "\n",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
"the directory is there and cannot be entered": {
|
||||||
|
said: listed + "sftp> ls -1 .ssh/.\n" +
|
||||||
|
`Can't ls: "/home/someone/.ssh/." not found` + "\n",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
"some other directory is not there": {
|
||||||
|
said: listed + `Can't ls: "/home/someone/.config" not found` + "\n",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
"the connection did not come up": {
|
||||||
|
said: "ssh: connect to host example.com port 22: " +
|
||||||
|
"Connection refused\nConnection closed\n",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, listing := range listings {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if listingNotFound(listing.said, directory) != listing.want {
|
||||||
|
t.Errorf(
|
||||||
|
"read as absent: %t, wanted %t, from:\n%s",
|
||||||
|
!listing.want, listing.want, listing.said,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+26
-3
@@ -3,11 +3,14 @@ package ssh
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli/options"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/sshkey"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli/options"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/sshkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command returns the ssh command and everything under it.
|
// Command returns the ssh command and everything under it.
|
||||||
@@ -84,6 +87,26 @@ func write(cmd *cobra.Command, text string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// childEnv is the tool's environment with the mnemonic variables taken
|
||||||
|
// out, for the ssh and sftp children it starts. "ssh to" exists so the
|
||||||
|
// private key never leaves the tool; the mnemonic, from either variable,
|
||||||
|
// must not leave it either.
|
||||||
|
func childEnv() []string {
|
||||||
|
environ := os.Environ()
|
||||||
|
kept := make([]string, 0, len(environ))
|
||||||
|
|
||||||
|
for _, entry := range environ {
|
||||||
|
name, _, _ := strings.Cut(entry, "=")
|
||||||
|
if name == mnemonic.Variable || name == mnemonic.CommandVariable {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
kept = append(kept, entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
return kept
|
||||||
|
}
|
||||||
|
|
||||||
// addComment gives a command its comment flag.
|
// addComment gives a command its comment flag.
|
||||||
func addComment(cmd *cobra.Command) {
|
func addComment(cmd *cobra.Command) {
|
||||||
cmd.Flags().String(
|
cmd.Flags().String(
|
||||||
|
|||||||
+10
-2
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"slices"
|
"slices"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -70,17 +71,24 @@ func to() *cobra.Command {
|
|||||||
func connect(ctx context.Context, argv []string) error {
|
func connect(ctx context.Context, argv []string) error {
|
||||||
//nolint:gosec // the arguments are the user's own, meant for ssh
|
//nolint:gosec // the arguments are the user's own, meant for ssh
|
||||||
command := exec.CommandContext(ctx, "ssh", argv...)
|
command := exec.CommandContext(ctx, "ssh", argv...)
|
||||||
|
command.Env = childEnv()
|
||||||
command.Stdin = os.Stdin
|
command.Stdin = os.Stdin
|
||||||
command.Stdout = os.Stdout
|
command.Stdout = os.Stdout
|
||||||
command.Stderr = os.Stderr
|
command.Stderr = os.Stderr
|
||||||
|
|
||||||
|
// A cancelled context means a signal ended the tool. Send ssh a
|
||||||
|
// SIGTERM rather than the default kill, so it puts the terminal
|
||||||
|
// back the way it found it before it goes.
|
||||||
|
command.Cancel = func() error {
|
||||||
|
return command.Process.Signal(syscall.SIGTERM)
|
||||||
|
}
|
||||||
|
|
||||||
err := command.Run()
|
err := command.Run()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var ended *exec.ExitError
|
if ended, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||||
if errors.As(err, &ended) {
|
|
||||||
status := ended.ExitCode()
|
status := ended.ExitCode()
|
||||||
if status < 0 {
|
if status < 0 {
|
||||||
// A signal ended ssh, and a signal has no status of its
|
// A signal ended ssh, and a signal has no status of its
|
||||||
|
|||||||
+356
-36
@@ -3,18 +3,38 @@ package cli_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/cli/ssh"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/mnemonic"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/cli/ssh"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// runAsTool, set in the environment of a re-executed test binary, tells
|
||||||
|
// TestMain to run the tool through Main rather than the suite, so the
|
||||||
|
// signal test can drive the real signal path in a process it can send a
|
||||||
|
// signal to.
|
||||||
|
const runAsTool = "KEYFUNC_TEST_RUN_AS_TOOL"
|
||||||
|
|
||||||
|
// TestMain re-executes the test binary as the tool when runAsTool is
|
||||||
|
// set, and otherwise runs the suite. The signal test starts the tool
|
||||||
|
// this way, as a subprocess it can signal and watch clean up.
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
if os.Getenv(runAsTool) == "1" {
|
||||||
|
os.Exit(cli.Main())
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Exit(m.Run())
|
||||||
|
}
|
||||||
|
|
||||||
// The modes the host is supposed to end up with, and the mode the
|
// The modes the host is supposed to end up with, and the mode the
|
||||||
// stand-ins need so that they can be run at all.
|
// stand-ins need so that they can be run at all.
|
||||||
const (
|
const (
|
||||||
@@ -32,7 +52,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// notADirectory is what a test puts where the .ssh directory belongs
|
// notADirectory is what a test puts where the .ssh directory belongs
|
||||||
// to make a step of the write session fail.
|
// to make a .ssh that is listed but cannot be entered.
|
||||||
const notADirectory = "a file where the directory belongs\n"
|
const notADirectory = "a file where the directory belongs\n"
|
||||||
|
|
||||||
// missingIdentity is a path with no file at it, handed to sftp after
|
// missingIdentity is a path with no file at it, handed to sftp after
|
||||||
@@ -47,6 +67,9 @@ const (
|
|||||||
keptIn = "authorized_keys"
|
keptIn = "authorized_keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// remoteCommand is the command the "to" tests hand ssh after the host.
|
||||||
|
const remoteCommand = "uptime"
|
||||||
|
|
||||||
// The tool's own name, as it stands in the arguments a test hands to
|
// The tool's own name, as it stands in the arguments a test hands to
|
||||||
// Main, the ssh subcommand both commands the tests here drive live
|
// Main, the ssh subcommand both commands the tests here drive live
|
||||||
// under, and the one of those two these tests name most.
|
// under, and the one of those two these tests name most.
|
||||||
@@ -60,22 +83,36 @@ const (
|
|||||||
// an authorized_keys file.
|
// an authorized_keys file.
|
||||||
const keyLine = vectorZero + " keyfunc/ssh/0\n"
|
const keyLine = vectorZero + " keyfunc/ssh/0\n"
|
||||||
|
|
||||||
|
// marker is a variable set beside the mnemonic ones and expected to
|
||||||
|
// reach the stand-in, so a scrubbed environment is told apart from an
|
||||||
|
// empty one.
|
||||||
|
const marker = "KEYFUNC_TEST_MARKER"
|
||||||
|
|
||||||
// installer is a stand-in for the system sftp for the install
|
// installer is a stand-in for the system sftp for the install
|
||||||
// command. It writes down the arguments and every command of the
|
// command. It writes down the arguments and every command of the
|
||||||
// batch it is given, echoes each command as sftp does, and carries
|
// batch it is given, echoes each command as sftp does, writes down its
|
||||||
// the commands out against a directory standing in for the host's
|
// own environment when a test asks for it, and carries the commands out
|
||||||
// home directory, so that what keyfunc sends can be watched doing its
|
// against a directory standing in for the host's home directory, so that
|
||||||
// work. A command that begins with a dash may fail; any other failure
|
// what keyfunc sends can be watched doing its work. A command that
|
||||||
// ends the session, as it does in sftp's own batch mode.
|
// begins with a dash may fail; any other failure ends the session, as it
|
||||||
|
// does in sftp's own batch mode.
|
||||||
//
|
//
|
||||||
// The two ways a get can fail are worded as the OpenSSH client words
|
// The listing and the two ways a get can fail are worded as the
|
||||||
// them, both naming the path the server expanded: a file that is not
|
// OpenSSH client words them, each naming the path the server expanded.
|
||||||
// there, which is the one failure the tool reads as an empty file, and
|
// A listing fails one way when .ssh is not there and another when it is
|
||||||
// a file that is there and cannot be read, which is not. An -i naming
|
// there but shut to the user; the first is the only failure read as a
|
||||||
// a file that is not here draws the warning ssh writes for it, which
|
// host with no file. A get fails one way for a file that is not there,
|
||||||
|
// which after a listing that came up empty is also read as no file, and
|
||||||
|
// another for a file that is there and cannot be read, which is a
|
||||||
|
// failure. A directory shut to the user is stood in for by mode 000,
|
||||||
|
// which the listing reads off the mode itself so that the test does not
|
||||||
|
// turn on the user it runs as, and one the user can enter but not write
|
||||||
|
// to by mode 500, which the put reads off the same way. An -i naming a
|
||||||
|
// file that is not here draws the warning ssh writes for it, which
|
||||||
// carries the wording of a missing file into a session that goes on to
|
// carries the wording of a missing file into a session that goes on to
|
||||||
// authenticate.
|
// authenticate.
|
||||||
const installer = `
|
const installer = `
|
||||||
|
[ -n "$KEYFUNC_TEST_ENVIRONMENT" ] && env > "$KEYFUNC_TEST_ENVIRONMENT"
|
||||||
previous=
|
previous=
|
||||||
for argument in "$@"; do
|
for argument in "$@"; do
|
||||||
printf '%s\n' "$argument" >> "$KEYFUNC_TEST_ARGUMENTS"
|
printf '%s\n' "$argument" >> "$KEYFUNC_TEST_ARGUMENTS"
|
||||||
@@ -99,6 +136,23 @@ while IFS= read -r line; do
|
|||||||
eval "set -- $line"
|
eval "set -- $line"
|
||||||
worked=yes
|
worked=yes
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
ls)
|
||||||
|
dir=$2
|
||||||
|
[ "$dir" = -1 ] && dir=$3
|
||||||
|
if [ ! -e "$home/$dir" ]; then
|
||||||
|
worked=no
|
||||||
|
printf 'Can'\''t ls: "%s" not found\n' "$home/$dir" >&2
|
||||||
|
elif [ -d "$home/$dir" ] && [ "$(stat -c '%a' "$home/$dir")" = 0 ]; then
|
||||||
|
worked=no
|
||||||
|
printf 'remote readdir("%s/"): Permission denied\n' \
|
||||||
|
"$home/$dir" >&2
|
||||||
|
else
|
||||||
|
for entry in "$home/$dir"/*; do
|
||||||
|
[ -e "$entry" ] || continue
|
||||||
|
printf '%s/%s\n' "$dir" "$(basename "$entry")"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
;;
|
||||||
get)
|
get)
|
||||||
if [ ! -e "$home/$2" ]; then
|
if [ ! -e "$home/$2" ]; then
|
||||||
worked=no
|
worked=no
|
||||||
@@ -108,7 +162,13 @@ while IFS= read -r line; do
|
|||||||
printf 'remote open "%s": Permission denied\n' "$home/$2" >&2
|
printf 'remote open "%s": Permission denied\n' "$home/$2" >&2
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
put) cp "$2" "$home/$3" 2>/dev/null || worked=no ;;
|
put)
|
||||||
|
if [ "$(stat -c '%a' "$(dirname "$home/$3")")" = 500 ]; then
|
||||||
|
worked=no
|
||||||
|
else
|
||||||
|
cp "$2" "$home/$3" 2>/dev/null || worked=no
|
||||||
|
fi
|
||||||
|
;;
|
||||||
mkdir) mkdir "$home/$2" 2>/dev/null || worked=no ;;
|
mkdir) mkdir "$home/$2" 2>/dev/null || worked=no ;;
|
||||||
chmod) chmod "$2" "$home/$3" 2>/dev/null || worked=no ;;
|
chmod) chmod "$2" "$home/$3" 2>/dev/null || worked=no ;;
|
||||||
rename) mv "$home/$2" "$home/$3" 2>/dev/null || worked=no ;;
|
rename) mv "$home/$2" "$home/$3" 2>/dev/null || worked=no ;;
|
||||||
@@ -122,9 +182,11 @@ done
|
|||||||
|
|
||||||
// caller is a stand-in for the system ssh for the to command. It
|
// caller is a stand-in for the system ssh for the to command. It
|
||||||
// writes down the arguments it was given, notes the agent socket if
|
// writes down the arguments it was given, notes the agent socket if
|
||||||
// there really is one at the path it was handed, and ends with the
|
// there really is one at the path it was handed, writes down its own
|
||||||
// status the test asked for.
|
// environment when a test asks for it, and ends with the status the
|
||||||
|
// test asked for.
|
||||||
const caller = `
|
const caller = `
|
||||||
|
[ -n "$KEYFUNC_TEST_ENVIRONMENT" ] && env > "$KEYFUNC_TEST_ENVIRONMENT"
|
||||||
for argument in "$@"; do
|
for argument in "$@"; do
|
||||||
printf '%s\n' "$argument" >> "$KEYFUNC_TEST_ARGUMENTS"
|
printf '%s\n' "$argument" >> "$KEYFUNC_TEST_ARGUMENTS"
|
||||||
done
|
done
|
||||||
@@ -135,6 +197,18 @@ fi
|
|||||||
exit "$KEYFUNC_TEST_STATUS"
|
exit "$KEYFUNC_TEST_STATUS"
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// sleeper is a stand-in for the system ssh that notes the agent socket
|
||||||
|
// and then blocks, so a test can cancel the context while it is running
|
||||||
|
// and watch the tool take the agent down. The wait ends on its own only
|
||||||
|
// as a backstop, well after the test has cancelled and looked.
|
||||||
|
const sleeper = `
|
||||||
|
socket=${2#IdentityAgent=}
|
||||||
|
if [ -S "$socket" ]; then
|
||||||
|
printf '%s\n' "$socket" > "$KEYFUNC_TEST_SOCKET"
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
`
|
||||||
|
|
||||||
// pretended is where a stand-in writes down what it was asked to do.
|
// pretended is where a stand-in writes down what it was asked to do.
|
||||||
type pretended struct {
|
type pretended struct {
|
||||||
// home stands in for the home directory on the host.
|
// home stands in for the home directory on the host.
|
||||||
@@ -176,8 +250,8 @@ func TestAKeyThatIsAlreadyThereIsLeftAlone(t *testing.T) {
|
|||||||
require.Equal(t, "already present\n", install(t, host))
|
require.Equal(t, "already present\n", install(t, host))
|
||||||
require.Equal(t, "somebody else\n"+keyLine, read(t, path))
|
require.Equal(t, "somebody else\n"+keyLine, read(t, path))
|
||||||
|
|
||||||
// The fetch and nothing after it: the tool did not connect again.
|
// The read and nothing after it: the tool did not connect again.
|
||||||
require.Len(t, recorded(t, pretend.batch), 1)
|
require.Equal(t, 1, connections(t, pretend))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAnEmptyFileGetsTheKeyAndNoBlankLineBeforeIt(t *testing.T) {
|
func TestAnEmptyFileGetsTheKeyAndNoBlankLineBeforeIt(t *testing.T) {
|
||||||
@@ -218,7 +292,9 @@ func TestTheFileIsUploadedBesideTheOldOneAndThenRenamedOverIt(t *testing.T) {
|
|||||||
strings.HasPrefix(beside, ".ssh/authorized_keys.keyfunc-"),
|
strings.HasPrefix(beside, ".ssh/authorized_keys.keyfunc-"),
|
||||||
)
|
)
|
||||||
|
|
||||||
require.True(t, strings.HasPrefix(sent[0], "get .ssh/authorized_keys "))
|
// The listing fails on a host with no .ssh, so the get never runs;
|
||||||
|
// the write session then makes the directory and puts the file.
|
||||||
|
require.Equal(t, "ls -1 .ssh", sent[0])
|
||||||
require.Equal(t, "-mkdir .ssh", sent[1])
|
require.Equal(t, "-mkdir .ssh", sent[1])
|
||||||
require.Equal(t, "chmod 700 .ssh", sent[2])
|
require.Equal(t, "chmod 700 .ssh", sent[2])
|
||||||
require.Equal(t, "put", strings.Fields(sent[3])[0])
|
require.Equal(t, "put", strings.Fields(sent[3])[0])
|
||||||
@@ -237,12 +313,80 @@ func TestAFileThatCannotBeReadIsNotWrittenOver(t *testing.T) {
|
|||||||
require.Empty(t, printed)
|
require.Empty(t, printed)
|
||||||
require.Contains(t, said, "Permission denied")
|
require.Contains(t, said, "Permission denied")
|
||||||
|
|
||||||
// The fetch and nothing after it, and what was on the host is
|
// The read and nothing after it, and what was on the host is
|
||||||
// still what is on the host.
|
// still what is on the host.
|
||||||
require.Len(t, recorded(t, pretend.batch), 1)
|
require.Equal(t, 1, connections(t, pretend))
|
||||||
require.DirExists(t, unreadable)
|
require.DirExists(t, unreadable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAnUnreadableDirectoryIsNotWrittenInto(t *testing.T) {
|
||||||
|
t.Setenv(mnemonic.Variable, example())
|
||||||
|
|
||||||
|
pretend := pretendHost(t)
|
||||||
|
unlistable(t, pretend)
|
||||||
|
|
||||||
|
// The listing is refused, which is not the same as no directory, so
|
||||||
|
// the tool writes nothing rather than treat a directory it cannot
|
||||||
|
// enter as a host with no file.
|
||||||
|
printed, said, err := attempt(t, host)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Empty(t, printed)
|
||||||
|
require.Contains(t, said, "Permission denied")
|
||||||
|
|
||||||
|
// The read and nothing after it: no second connection wrote a key.
|
||||||
|
require.Equal(t, 1, connections(t, pretend))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestADirectoryThatCannotBeEnteredIsRefusedBeforeAnyUpload(t *testing.T) {
|
||||||
|
t.Setenv(mnemonic.Variable, example())
|
||||||
|
|
||||||
|
pretend := pretendHost(t)
|
||||||
|
|
||||||
|
// A file where .ssh belongs is listed and cannot be entered, which is
|
||||||
|
// how sftp sees a directory that can be read but not entered: the
|
||||||
|
// listing of .ssh comes up and the listing of .ssh/. finds nothing.
|
||||||
|
inTheWay := filepath.Join(pretend.home, keptUnder)
|
||||||
|
require.NoError(t,
|
||||||
|
os.WriteFile(inTheWay, []byte(notADirectory), fileMode),
|
||||||
|
)
|
||||||
|
|
||||||
|
printed, _, err := attempt(t, host)
|
||||||
|
require.ErrorIs(t, err, ssh.ErrCannotEnter)
|
||||||
|
require.Empty(t, printed)
|
||||||
|
|
||||||
|
// The read and nothing after it: no upload was tried, and what was
|
||||||
|
// on the host is still what is on the host.
|
||||||
|
require.Equal(t, 1, connections(t, pretend))
|
||||||
|
require.Equal(t, notADirectory, read(t, inTheWay))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAnExistingDirectoryKeepsItsModeAndIsNotRemade(t *testing.T) {
|
||||||
|
t.Setenv(mnemonic.Variable, example())
|
||||||
|
|
||||||
|
pretend := pretendHost(t)
|
||||||
|
|
||||||
|
// A directory that is there but holds no file yet, made with a mode
|
||||||
|
// of its own so that a stray chmod would show.
|
||||||
|
const ownMode = 0o755
|
||||||
|
|
||||||
|
directory := filepath.Join(pretend.home, keptUnder)
|
||||||
|
require.NoError(t, os.Mkdir(directory, ownMode))
|
||||||
|
|
||||||
|
require.Equal(t, "added\n", install(t, host))
|
||||||
|
|
||||||
|
// The key is added and the directory keeps the mode it had: the
|
||||||
|
// write session neither made it nor set its mode.
|
||||||
|
require.Equal(t, keyLine, read(t, filepath.Join(directory, keptIn)))
|
||||||
|
|
||||||
|
kept, err := os.Stat(directory)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, os.FileMode(ownMode), kept.Mode().Perm())
|
||||||
|
|
||||||
|
sent := recorded(t, pretend.batch)
|
||||||
|
require.NotContains(t, sent, "-mkdir .ssh")
|
||||||
|
require.NotContains(t, sent, "chmod 700 .ssh")
|
||||||
|
}
|
||||||
|
|
||||||
func TestAWarningAboutAnotherFileIsNotTakenForTheOneAskedFor(t *testing.T) {
|
func TestAWarningAboutAnotherFileIsNotTakenForTheOneAskedFor(t *testing.T) {
|
||||||
t.Setenv(mnemonic.Variable, example())
|
t.Setenv(mnemonic.Variable, example())
|
||||||
|
|
||||||
@@ -259,7 +403,7 @@ func TestAWarningAboutAnotherFileIsNotTakenForTheOneAskedFor(t *testing.T) {
|
|||||||
require.Contains(t, said, "No such file or directory")
|
require.Contains(t, said, "No such file or directory")
|
||||||
require.Contains(t, said, "Permission denied")
|
require.Contains(t, said, "Permission denied")
|
||||||
|
|
||||||
require.Len(t, recorded(t, pretend.batch), 1)
|
require.Equal(t, 1, connections(t, pretend))
|
||||||
require.DirExists(t, unreadable)
|
require.DirExists(t, unreadable)
|
||||||
|
|
||||||
// The same run again, this way for the status it ends with.
|
// The same run again, this way for the status it ends with.
|
||||||
@@ -279,27 +423,30 @@ func TestAFailedStepNamesTheUploadedFileAndChangesNothing(t *testing.T) {
|
|||||||
|
|
||||||
pretend := pretendHost(t)
|
pretend := pretendHost(t)
|
||||||
|
|
||||||
// A file where the .ssh directory belongs: nothing is there to
|
// A .ssh that can be listed and entered but not written to: the
|
||||||
// fetch, and then the put has nowhere to put anything, so the
|
// fetch finds no file in it, and then the put has nowhere to put
|
||||||
// write session ends at the put.
|
// anything, so the write session ends at the put.
|
||||||
inTheWay := filepath.Join(pretend.home, keptUnder)
|
const unwritable = 0o500
|
||||||
require.NoError(t,
|
|
||||||
os.WriteFile(inTheWay, []byte(notADirectory), fileMode),
|
directory := filepath.Join(pretend.home, keptUnder)
|
||||||
)
|
require.NoError(t, os.Mkdir(directory, unwritable))
|
||||||
|
|
||||||
printed, said, err := attempt(t, host)
|
printed, said, err := attempt(t, host)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Empty(t, printed)
|
require.Empty(t, printed)
|
||||||
require.Contains(t, said, "put failed")
|
require.Contains(t, said, "put failed")
|
||||||
|
|
||||||
// The put is the last command the session got to, and the file it
|
// The put, after the three commands of the fetch, is the first and
|
||||||
// was uploading is the one the message names.
|
// last command the write session got to, and the file it was
|
||||||
|
// uploading is the one the message names.
|
||||||
sent := recorded(t, pretend.batch)
|
sent := recorded(t, pretend.batch)
|
||||||
require.Len(t, sent, 4)
|
require.Len(t, sent, 4)
|
||||||
require.Equal(t, "put", strings.Fields(sent[3])[0])
|
require.Equal(t, "put", strings.Fields(sent[3])[0])
|
||||||
require.Contains(t, err.Error(), strings.Fields(sent[3])[2])
|
require.Contains(t, err.Error(), strings.Fields(sent[3])[2])
|
||||||
|
|
||||||
require.Equal(t, notADirectory, read(t, inTheWay))
|
left, err := os.ReadDir(directory)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, left)
|
||||||
|
|
||||||
// The same run again, this way for the status it ends with.
|
// The same run again, this way for the status it ends with.
|
||||||
given := os.Args
|
given := os.Args
|
||||||
@@ -343,7 +490,7 @@ func TestSSHIsPointedAtTheAgentAndItsStatusIsHandedOn(t *testing.T) {
|
|||||||
|
|
||||||
arguments, noted := pretendCall(t)
|
arguments, noted := pretendCall(t)
|
||||||
|
|
||||||
_, err := execute(t, subcommand, "to", host, "uptime")
|
_, err := execute(t, subcommand, "to", host, remoteCommand)
|
||||||
|
|
||||||
var passed ssh.StatusError
|
var passed ssh.StatusError
|
||||||
|
|
||||||
@@ -352,7 +499,7 @@ func TestSSHIsPointedAtTheAgentAndItsStatusIsHandedOn(t *testing.T) {
|
|||||||
|
|
||||||
given := recorded(t, arguments)
|
given := recorded(t, arguments)
|
||||||
require.Equal(t, "-o", given[0])
|
require.Equal(t, "-o", given[0])
|
||||||
require.Equal(t, []string{host, "uptime"}, given[2:])
|
require.Equal(t, []string{host, remoteCommand}, given[2:])
|
||||||
|
|
||||||
// The stand-in wrote the path down only because there really was
|
// The stand-in wrote the path down only because there really was
|
||||||
// a socket there while it ran.
|
// a socket there while it ran.
|
||||||
@@ -370,11 +517,130 @@ func TestTheToolEndsWithTheStatusSSHEndedWith(t *testing.T) {
|
|||||||
|
|
||||||
t.Cleanup(func() { os.Args = given })
|
t.Cleanup(func() { os.Args = given })
|
||||||
|
|
||||||
os.Args = []string{tool, subcommand, "to", host, "uptime"}
|
os.Args = []string{tool, subcommand, "to", host, remoteCommand}
|
||||||
|
|
||||||
require.Equal(t, failingStatus, cli.Main())
|
require.Equal(t, failingStatus, cli.Main())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestASignalTakesTheAgentDirectoryDown(t *testing.T) {
|
||||||
|
t.Setenv(mnemonic.Variable, example())
|
||||||
|
|
||||||
|
// The three signals the tool handles, checked one after another.
|
||||||
|
signals := []struct {
|
||||||
|
name string
|
||||||
|
signal os.Signal
|
||||||
|
}{
|
||||||
|
{"SIGTERM", syscall.SIGTERM},
|
||||||
|
{"SIGINT", syscall.SIGINT},
|
||||||
|
{"SIGHUP", syscall.SIGHUP},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ending := range signals {
|
||||||
|
signalEndsTheTool(t, ending.name, ending.signal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// signalEndsTheTool runs the tool as a subprocess against a stand-in
|
||||||
|
// ssh that blocks, waits until the agent is up and ssh is running
|
||||||
|
// against it, sends the tool the signal, and requires the agent socket
|
||||||
|
// and its directory to be gone once the tool has ended. The subprocess
|
||||||
|
// goes through Main and its signal handling, so with that handling
|
||||||
|
// removed the signal kills the tool outright, no deferred cleanup runs,
|
||||||
|
// the directory is left behind, and the check fails.
|
||||||
|
func signalEndsTheTool(t *testing.T, name string, signal os.Signal) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
noted := filepath.Join(t.TempDir(), "socket")
|
||||||
|
t.Setenv("KEYFUNC_TEST_SOCKET", noted)
|
||||||
|
standIn(t, "ssh", sleeper)
|
||||||
|
|
||||||
|
//nolint:gosec // the binary is this test's own, re-run as the tool
|
||||||
|
command := exec.CommandContext(
|
||||||
|
t.Context(), os.Args[0], subcommand, "to", host, remoteCommand,
|
||||||
|
)
|
||||||
|
|
||||||
|
command.Env = append(os.Environ(), runAsTool+"=1")
|
||||||
|
require.NoError(t, command.Start())
|
||||||
|
|
||||||
|
// The stand-in notes the socket only once the agent is up and ssh
|
||||||
|
// is running against it, so this is where the signal lands.
|
||||||
|
socket := waitForSocket(t, noted)
|
||||||
|
|
||||||
|
require.NoError(t, command.Process.Signal(signal))
|
||||||
|
waitForTool(t, name, command)
|
||||||
|
|
||||||
|
// The signal ended the tool, and its deferred cleanup still ran:
|
||||||
|
// the agent socket and its directory are gone.
|
||||||
|
require.NoDirExists(t, filepath.Dir(socket), name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitForTool waits for the subprocess to end, and fails the test if it
|
||||||
|
// does not end in time.
|
||||||
|
func waitForTool(t *testing.T, name string, command *exec.Cmd) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
done := make(chan error, 1)
|
||||||
|
go func() { done <- command.Wait() }()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(10 * time.Second):
|
||||||
|
t.Fatalf("the tool did not end after %s", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitForSocket waits for the stand-in to write down the agent socket
|
||||||
|
// and gives back the path, which means the agent is up and ssh is
|
||||||
|
// running against it.
|
||||||
|
func waitForSocket(t *testing.T, noted string) string {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
var socket string
|
||||||
|
|
||||||
|
require.Eventually(t, func() bool {
|
||||||
|
content, err := os.ReadFile(noted) //nolint:gosec // test path
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
socket = strings.TrimSpace(string(content))
|
||||||
|
|
||||||
|
return socket != ""
|
||||||
|
}, 5*time.Second, 5*time.Millisecond)
|
||||||
|
|
||||||
|
return socket
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTheMnemonicIsNotHandedToSFTP(t *testing.T) {
|
||||||
|
t.Setenv(mnemonic.CommandVariable, "echo "+example())
|
||||||
|
t.Setenv(mnemonic.Variable, example())
|
||||||
|
t.Setenv(marker, "reaches the stand-in")
|
||||||
|
|
||||||
|
pretendHost(t)
|
||||||
|
environment := recordEnvironment(t)
|
||||||
|
|
||||||
|
install(t, host)
|
||||||
|
|
||||||
|
mnemonicWithheld(t, read(t, environment))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTheMnemonicIsNotHandedToSSH(t *testing.T) {
|
||||||
|
t.Setenv(mnemonic.CommandVariable, "echo "+example())
|
||||||
|
t.Setenv(mnemonic.Variable, example())
|
||||||
|
t.Setenv(marker, "reaches the stand-in")
|
||||||
|
|
||||||
|
pretendCall(t)
|
||||||
|
environment := recordEnvironment(t)
|
||||||
|
|
||||||
|
_, err := execute(t, subcommand, "to", host, remoteCommand)
|
||||||
|
|
||||||
|
var passed ssh.StatusError
|
||||||
|
|
||||||
|
require.ErrorAs(t, err, &passed)
|
||||||
|
|
||||||
|
mnemonicWithheld(t, read(t, environment))
|
||||||
|
}
|
||||||
|
|
||||||
// pretendHost puts the install stand-in on the path and gives back the
|
// pretendHost puts the install stand-in on the path and gives back the
|
||||||
// places it writes to.
|
// places it writes to.
|
||||||
func pretendHost(t *testing.T) pretended {
|
func pretendHost(t *testing.T) pretended {
|
||||||
@@ -455,6 +721,38 @@ func unfetchable(t *testing.T, pretend pretended) string {
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unlistable puts a .ssh on the stand-in host that is there but shut to
|
||||||
|
// the user, a directory of mode 000, and gives back its path. Its mode
|
||||||
|
// is put back before the temporary directory is cleared so that it can
|
||||||
|
// be.
|
||||||
|
func unlistable(t *testing.T, pretend pretended) string {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
directory := filepath.Join(pretend.home, keptUnder)
|
||||||
|
require.NoError(t, os.Mkdir(directory, directoryMode))
|
||||||
|
require.NoError(t, os.Chmod(directory, 0))
|
||||||
|
|
||||||
|
t.Cleanup(func() { _ = os.Chmod(directory, directoryMode) })
|
||||||
|
|
||||||
|
return directory
|
||||||
|
}
|
||||||
|
|
||||||
|
// connections returns how many times the tool ran sftp, counted from
|
||||||
|
// the -b that opens each session's arguments.
|
||||||
|
func connections(t *testing.T, pretend pretended) int {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
|
||||||
|
for _, argument := range recorded(t, pretend.arguments) {
|
||||||
|
if argument == "-b" {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
// pretendCall puts the to stand-in on the path and gives back the file
|
// pretendCall puts the to stand-in on the path and gives back the file
|
||||||
// the arguments are written down in and the file the agent socket is
|
// the arguments are written down in and the file the agent socket is
|
||||||
// noted in.
|
// noted in.
|
||||||
@@ -491,6 +789,28 @@ func standIn(t *testing.T, name, body string) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recordEnvironment asks the stand-in to write its environment down and
|
||||||
|
// gives back the file it writes it to.
|
||||||
|
func recordEnvironment(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
path := filepath.Join(t.TempDir(), "environment")
|
||||||
|
t.Setenv("KEYFUNC_TEST_ENVIRONMENT", path)
|
||||||
|
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
// mnemonicWithheld requires that neither mnemonic variable reached the
|
||||||
|
// stand-in and that the marker set beside them did, so an empty
|
||||||
|
// environment does not pass for a scrubbed one.
|
||||||
|
func mnemonicWithheld(t *testing.T, environment string) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
require.NotContains(t, environment, mnemonic.Variable+"=")
|
||||||
|
require.NotContains(t, environment, mnemonic.CommandVariable+"=")
|
||||||
|
require.Contains(t, environment, marker+"=")
|
||||||
|
}
|
||||||
|
|
||||||
// read returns what is in a file.
|
// read returns what is in a file.
|
||||||
func read(t *testing.T, path string) string {
|
func read(t *testing.T, path string) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime/debug"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestResolveVersion(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
release := &debug.BuildInfo{Main: debug.Module{Version: "v1.2.3"}}
|
||||||
|
local := &debug.BuildInfo{Main: debug.Module{Version: "(devel)"}}
|
||||||
|
empty := &debug.BuildInfo{}
|
||||||
|
|
||||||
|
t.Run("stamped value wins over build info", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require.Equal(t, "v0.1.0", resolveVersion("v0.1.0", release))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("go install reports the module version", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require.Equal(t, "v1.2.3", resolveVersion(devVersion, release))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("a local build stays dev", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require.Equal(t, devVersion, resolveVersion(devVersion, local))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("no version anywhere stays dev", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require.Equal(t, devVersion, resolveVersion(devVersion, empty))
|
||||||
|
require.Equal(t, devVersion, resolveVersion(devVersion, nil))
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// application is the number the SSH key type uses.
|
// application is the number the SSH key type uses.
|
||||||
|
|||||||
@@ -104,10 +104,11 @@ func ask() (string, error) {
|
|||||||
return checked(string(typed))
|
return checked(string(typed))
|
||||||
}
|
}
|
||||||
|
|
||||||
// checked drops the surrounding whitespace and refuses a mnemonic that
|
// checked joins the words with single spaces, whatever whitespace
|
||||||
// does not pass the BIP-39 checksum.
|
// separated them, since the seed is computed over the string itself,
|
||||||
|
// and refuses a mnemonic that does not pass the BIP-39 checksum.
|
||||||
func checked(words string) (string, error) {
|
func checked(words string) (string, error) {
|
||||||
words = strings.TrimSpace(words)
|
words = strings.Join(strings.Fields(words), " ")
|
||||||
|
|
||||||
if !bip39.IsMnemonicValid(words) {
|
if !bip39.IsMnemonicValid(words) {
|
||||||
return "", ErrChecksum
|
return "", ErrChecksum
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/mnemonic"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Two more mnemonics that pass the checksum, so a test can tell which
|
// Two more mnemonics that pass the checksum, so a test can tell which
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/derive"
|
|
||||||
"git.eeqj.de/sneak/keyfunc/internal/sshkey"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"golang.org/x/crypto/ssh/agent"
|
"golang.org/x/crypto/ssh/agent"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/derive"
|
||||||
|
"sneak.berlin/go/keyfunc/internal/sshkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
// agentDirectoryMode is what the directory holding the agent socket
|
// agentDirectoryMode is what the directory holding the agent socket
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"devDependencies": {
|
||||||
|
"prettier": "3.8.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
+152
-5
@@ -3,13 +3,35 @@
|
|||||||
# repo. Idempotent: every install is guarded by a check, so tools that
|
# repo. Idempotent: every install is guarded by a check, so tools that
|
||||||
# are already there are left alone. Base tooling comes from nix, apt,
|
# are already there are left alone. Base tooling comes from nix, apt,
|
||||||
# brew, or apk, detected in that order, and nothing is assumed to be
|
# brew, or apk, detected in that order, and nothing is assumed to be
|
||||||
# present. The linter is not installed here: it only ever runs inside
|
# present. Go is installed at the version the Dockerfile's Go image
|
||||||
# the image built from Dockerfile.lint, so Docker is what is needed for
|
# carries, from the official release archive, into ~/.local/go. Node is
|
||||||
# it, and that is checked for rather than installed.
|
# used directly if installed; otherwise it is installed at a pinned
|
||||||
|
# version via nvm (installing nvm itself first, from a hash-verified
|
||||||
|
# release archive, never curl | sh). The linter is not installed here:
|
||||||
|
# linting and testing run only as phases of the Dockerfile, so Docker is
|
||||||
|
# what is needed for them, and that is checked for rather than
|
||||||
|
# installed.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
|
|
||||||
|
# Must match the Go in the Dockerfile's golang image; the sha256 of each
|
||||||
|
# archive is in install_go.
|
||||||
|
GO_VERSION="1.26.8"
|
||||||
|
|
||||||
|
# This script cannot change its caller's PATH, so script/fmt,
|
||||||
|
# script/fmt-check, script/precommit and the Makefile put this directory
|
||||||
|
# first on their own PATH, as is done here.
|
||||||
|
GO_DIR="$HOME/.local/go"
|
||||||
|
PATH="$GO_DIR/bin:$PATH"
|
||||||
|
|
||||||
|
# Pinned versions, 2026-07-06
|
||||||
|
NODE_VERSION="22.17.0"
|
||||||
|
NVM_VERSION="0.40.3"
|
||||||
|
# sha256 of https://github.com/nvm-sh/nvm/archive/refs/tags/v0.40.3.tar.gz
|
||||||
|
NVM_SHA256="5f4d6aaa04a177dc93c985e31dbc411ab6b8c6e1e21d8015dbc1372625fcd1d0"
|
||||||
|
YARN_VERSION="1.22.22"
|
||||||
|
|
||||||
PKGMGR=""
|
PKGMGR=""
|
||||||
SUDO=""
|
SUDO=""
|
||||||
|
|
||||||
@@ -32,6 +54,9 @@ detect_pkgmgr() {
|
|||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
SUDO="sudo"
|
SUDO="sudo"
|
||||||
fi
|
fi
|
||||||
|
# This runs once, before the first install: a fresh host or
|
||||||
|
# runner image has no package lists yet.
|
||||||
|
$SUDO apt-get update
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,17 +75,139 @@ missing() {
|
|||||||
! command -v "$1" >/dev/null 2>&1
|
! command -v "$1" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# verify_sha256 <file> <expected-hash>
|
||||||
|
verify_sha256() {
|
||||||
|
if command -v sha256sum >/dev/null 2>&1; then
|
||||||
|
actual="$(sha256sum "$1" | cut -d' ' -f1)"
|
||||||
|
else
|
||||||
|
actual="$(shasum -a 256 "$1" | cut -d' ' -f1)"
|
||||||
|
fi
|
||||||
|
if [ "$actual" != "$2" ]; then
|
||||||
|
echo "bootstrap: sha256 mismatch for $1" >&2
|
||||||
|
echo " expected: $2" >&2
|
||||||
|
echo " actual: $actual" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# True when the go first on PATH reports exactly GO_VERSION. No go, a go
|
||||||
|
# that fails, or any other output is a mismatch.
|
||||||
|
go_version_matches() {
|
||||||
|
out="$(go version 2>/dev/null)" || return 1
|
||||||
|
case "$out" in
|
||||||
|
"go version go$GO_VERSION "*) return 0 ;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
install_go() {
|
||||||
|
# sha256 of the go1.26.8 archives at https://go.dev/dl/, 2026-10-04
|
||||||
|
case "$(uname -s)-$(uname -m)" in
|
||||||
|
Linux-x86_64)
|
||||||
|
platform="linux-amd64"
|
||||||
|
sha256="d0f743b33e8d8945e6b1f432edd15785c70507121d6e2a723b21285eddf8b57b"
|
||||||
|
;;
|
||||||
|
Linux-aarch64)
|
||||||
|
platform="linux-arm64"
|
||||||
|
sha256="211ffced9dcb9633a55eac6364816ec0ddd951389a740e88fa8b3337971bdda0"
|
||||||
|
;;
|
||||||
|
Darwin-x86_64)
|
||||||
|
platform="darwin-amd64"
|
||||||
|
sha256="186be014105aa6542b767d2c6ed5cca10a0214bdff809ef1724022a8c7894150"
|
||||||
|
;;
|
||||||
|
Darwin-arm64)
|
||||||
|
platform="darwin-arm64"
|
||||||
|
sha256="a012b25b571bd0138a03dcd25375ceba866fe5ca822f426d2c66a4de56fd3f4b"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "bootstrap: no Go archive pinned for $(uname -s) $(uname -m)" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
if missing curl; then pkg_install curl curl curl curl; fi
|
||||||
|
tmp="$(mktemp -d)"
|
||||||
|
curl -fsSL -o "$tmp/go.tar.gz" \
|
||||||
|
"https://go.dev/dl/go${GO_VERSION}.${platform}.tar.gz"
|
||||||
|
verify_sha256 "$tmp/go.tar.gz" "$sha256"
|
||||||
|
# An archive unpacked over an older Go leaves a broken tree.
|
||||||
|
rm -rf "$GO_DIR"
|
||||||
|
mkdir -p "$GO_DIR"
|
||||||
|
tar -xzf "$tmp/go.tar.gz" -C "$GO_DIR" --strip-components=1
|
||||||
|
rm -rf "$tmp"
|
||||||
|
}
|
||||||
|
|
||||||
|
# nvm is a bash script; run a command in a bash with nvm loaded
|
||||||
|
nvm_sh() {
|
||||||
|
bash -c ". \"\$HOME/.nvm/nvm.sh\" && $*"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_nvm() {
|
||||||
|
[ -s "$HOME/.nvm/nvm.sh" ] && return 0
|
||||||
|
# nvm prerequisites; nvm itself requires bash
|
||||||
|
if missing bash; then pkg_install bash bash bash bash; fi
|
||||||
|
if missing curl; then pkg_install curl curl curl curl; fi
|
||||||
|
if missing git; then pkg_install git git git git; fi
|
||||||
|
tmp="$(mktemp -d)"
|
||||||
|
curl -fsSL -o "$tmp/nvm.tar.gz" \
|
||||||
|
"https://github.com/nvm-sh/nvm/archive/refs/tags/v${NVM_VERSION}.tar.gz"
|
||||||
|
verify_sha256 "$tmp/nvm.tar.gz" "$NVM_SHA256"
|
||||||
|
mkdir -p "$HOME/.nvm"
|
||||||
|
tar -xzf "$tmp/nvm.tar.gz" -C "$HOME/.nvm" --strip-components=1
|
||||||
|
rm -rf "$tmp"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_node() {
|
||||||
|
if ! missing node; then return 0; fi
|
||||||
|
ensure_nvm
|
||||||
|
nvm_sh "nvm install $NODE_VERSION"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_yarn() {
|
||||||
|
if ! missing yarn; then return 0; fi
|
||||||
|
if ! missing corepack; then
|
||||||
|
corepack enable
|
||||||
|
corepack prepare "yarn@$YARN_VERSION" --activate
|
||||||
|
elif [ -s "$HOME/.nvm/nvm.sh" ]; then
|
||||||
|
nvm_sh "nvm use $NODE_VERSION >/dev/null && corepack enable && \
|
||||||
|
corepack prepare yarn@$YARN_VERSION --activate"
|
||||||
|
else
|
||||||
|
npm install -g "yarn@$YARN_VERSION"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_js_deps() {
|
||||||
|
if missing yarn && [ -s "$HOME/.nvm/nvm.sh" ]; then
|
||||||
|
nvm_sh "nvm use $NODE_VERSION >/dev/null && cd \"$ROOT\" && \
|
||||||
|
yarn install --frozen-lockfile"
|
||||||
|
else
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
|
|
||||||
if missing git; then pkg_install git git git git; fi
|
if missing git; then pkg_install git git git git; fi
|
||||||
if missing make; then pkg_install gnumake make make make; fi
|
if missing make; then pkg_install gnumake make make make; fi
|
||||||
if missing go; then pkg_install go golang go go; fi
|
|
||||||
|
if ! go_version_matches; then
|
||||||
|
install_go
|
||||||
|
hash -r
|
||||||
|
if ! go_version_matches; then
|
||||||
|
echo "bootstrap: $(command -v go) is not go$GO_VERSION after installing it" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
go version
|
||||||
|
|
||||||
go mod download
|
go mod download
|
||||||
|
|
||||||
|
ensure_node
|
||||||
|
ensure_yarn
|
||||||
|
install_js_deps
|
||||||
|
|
||||||
if missing docker; then
|
if missing docker; then
|
||||||
echo "bootstrap: docker is not installed; make lint needs it" >&2
|
echo "bootstrap: docker is not installed; make lint and make test need it" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "bootstrap complete"
|
echo "bootstrap complete"
|
||||||
|
|||||||
+17
-6
@@ -1,8 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# script/cibuild: run the CI build. The linter needs an image of its
|
# script/cibuild: run the CI build. It bootstraps first: a CI runner
|
||||||
# own, so it runs first; the Dockerfile then runs the formatting check,
|
# checks out and runs this and nothing else, and script/fmt-check runs
|
||||||
# the tests and the build, so a green run here means make check is
|
# the formatter on the host, which a pristine checkout cannot do.
|
||||||
# green.
|
# --no-cache for the same reason as script/docker: the gate phases the
|
||||||
|
# final stage depends on are RUN steps, and a cached one is a check that
|
||||||
|
# did not run.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
@@ -10,8 +12,17 @@ ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
"$SCRIPT_DIR/lint"
|
"$SCRIPT_DIR/bootstrap"
|
||||||
docker build .
|
"$SCRIPT_DIR/check"
|
||||||
|
# Own line: a failing command substitution inside an argument does
|
||||||
|
# not trip `set -e`, so the inline form degrades silently to an
|
||||||
|
# empty constant. The VERSION build argument takes precedence over
|
||||||
|
# the version a build stage derives from the .git in the context.
|
||||||
|
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||||
|
[ -n "$version" ] || version="unknown"
|
||||||
|
docker build --no-cache \
|
||||||
|
--build-arg VERSION="$version" \
|
||||||
|
-t "$("$SCRIPT_DIR/projectname")" .
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
+11
-1
@@ -1,6 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# script/docker: build the Docker image tagged with the project name.
|
# script/docker: build the Docker image tagged with the project name.
|
||||||
# Identical in all repos; the tag comes from script/projectname.
|
# Identical in all repos; the tag comes from script/projectname.
|
||||||
|
# --no-cache because the gate phases the final stage depends on are RUN
|
||||||
|
# steps, and a cached one is a check that did not run.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
@@ -8,7 +10,15 @@ ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
docker build -t "$("$SCRIPT_DIR/projectname")" .
|
# Own line: a failing command substitution inside an argument does
|
||||||
|
# not trip `set -e`, so the inline form degrades silently to an
|
||||||
|
# empty constant. The VERSION build argument takes precedence over
|
||||||
|
# the version a build stage derives from the .git in the context.
|
||||||
|
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||||
|
[ -n "$version" ] || version="unknown"
|
||||||
|
docker build --no-cache \
|
||||||
|
--build-arg VERSION="$version" \
|
||||||
|
-t "$("$SCRIPT_DIR/projectname")" .
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
+25
-1
@@ -1,12 +1,36 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# script/fmt: format all files (writes).
|
# script/fmt: format all files (writes): the Go source with go fmt, then
|
||||||
|
# the Markdown files with prettier.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
|
|
||||||
|
# Where script/bootstrap installs Go; it cannot put it on our PATH.
|
||||||
|
PATH="$HOME/.local/go/bin:$PATH"
|
||||||
|
|
||||||
|
# Must match the pin in script/bootstrap.
|
||||||
|
NODE_VERSION="22.17.0"
|
||||||
|
|
||||||
|
# script/bootstrap installs node and yarn under nvm and leaves neither
|
||||||
|
# on the PATH of the shell that called it, so resolve the pinned
|
||||||
|
# toolchain here the way bootstrap's own install step does. nvm is a
|
||||||
|
# bash script, hence the subshell.
|
||||||
|
run_yarn() {
|
||||||
|
if command -v yarn >/dev/null 2>&1; then
|
||||||
|
exec yarn "$@"
|
||||||
|
fi
|
||||||
|
if [ ! -s "$HOME/.nvm/nvm.sh" ]; then
|
||||||
|
echo "fmt: no yarn; run script/bootstrap first" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exec bash -c '. "$HOME/.nvm/nvm.sh" && nvm use "$1" >/dev/null &&
|
||||||
|
shift && exec yarn "$@"' bash "$NODE_VERSION" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
run_yarn run prettier --write '**/*.md' --tab-width 4 --prose-wrap always
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
@@ -5,6 +5,28 @@ set -eu
|
|||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
|
|
||||||
|
# Where script/bootstrap installs Go; it cannot put it on our PATH.
|
||||||
|
PATH="$HOME/.local/go/bin:$PATH"
|
||||||
|
|
||||||
|
# Must match the pin in script/bootstrap.
|
||||||
|
NODE_VERSION="22.17.0"
|
||||||
|
|
||||||
|
# script/bootstrap installs node and yarn under nvm and leaves neither
|
||||||
|
# on the PATH of the shell that called it, so resolve the pinned
|
||||||
|
# toolchain here the way bootstrap's own install step does. nvm is a
|
||||||
|
# bash script, hence the subshell.
|
||||||
|
run_yarn() {
|
||||||
|
if command -v yarn >/dev/null 2>&1; then
|
||||||
|
exec yarn "$@"
|
||||||
|
fi
|
||||||
|
if [ ! -s "$HOME/.nvm/nvm.sh" ]; then
|
||||||
|
echo "fmt-check: no yarn; run script/bootstrap first" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exec bash -c '. "$HOME/.nvm/nvm.sh" && nvm use "$1" >/dev/null &&
|
||||||
|
shift && exec yarn "$@"' bash "$NODE_VERSION" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
if [ -n "$(gofmt -l .)" ]; then
|
if [ -n "$(gofmt -l .)" ]; then
|
||||||
@@ -12,6 +34,7 @@ main() {
|
|||||||
gofmt -l .
|
gofmt -l .
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
run_yarn run prettier --check '**/*.md' --tab-width 4 --prose-wrap always
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
+11
-6
@@ -1,9 +1,13 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# script/lint: run the linter. Linting only ever happens inside the
|
# script/lint: run the linter. Linting is a phase of the Dockerfile and
|
||||||
# image built from Dockerfile.lint, which pins the linter by hash, so
|
# this builds that phase alone; the linter is never installed or run on
|
||||||
# the answer is the same on every machine and in CI. The linter runs as
|
# a developer host, where a shared result cache and a host-global lock
|
||||||
# a build step of that image, so a complaint fails the build and no
|
# make its answer untrustworthy.
|
||||||
# container is left behind.
|
#
|
||||||
|
# The phase is not the last stage in the file, so it is built only when
|
||||||
|
# --target names it. --no-cache because a cached lint layer is a lint
|
||||||
|
# that did not run. The tag makes each build replace the previous image
|
||||||
|
# instead of leaving a dangling one behind.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
@@ -11,7 +15,8 @@ ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
docker build --progress=plain -f Dockerfile.lint \
|
docker build --no-cache \
|
||||||
|
--target lint \
|
||||||
-t "$("$SCRIPT_DIR/projectname")-lint" .
|
-t "$("$SCRIPT_DIR/projectname")-lint" .
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ set -eu
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||||
|
|
||||||
|
# Where script/bootstrap installs Go; it cannot put it on our PATH.
|
||||||
|
PATH="$HOME/.local/go/bin:$PATH"
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
|||||||
+10
-4
@@ -1,13 +1,19 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# script/test: run the test suite (vet first, verbose rerun on failure).
|
# script/test: run the test suite. Testing is a phase of the Dockerfile
|
||||||
|
# and this builds that phase alone, on the same terms as script/lint:
|
||||||
|
# --target because a phase that is not the last stage is built only when
|
||||||
|
# named, --no-cache because a cached test layer is a test that did not
|
||||||
|
# run, and a tag so each build replaces the previous image.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
|
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
go vet ./...
|
docker build --no-cache \
|
||||||
go test -timeout 90s ./... || go test -timeout 90s -v ./...
|
--target test \
|
||||||
|
-t "$("$SCRIPT_DIR/projectname")-test" .
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||||
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
|
prettier@3.8.1:
|
||||||
|
version "3.8.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.8.1.tgz#edf48977cf991558f4fcbd8a3ba6015ba2a3a173"
|
||||||
|
integrity sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==
|
||||||
Reference in New Issue
Block a user