From ff83931bace4e201885174bab1e4119604b1b1ae Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:29:17 -0900 Subject: [PATCH 01/52] Add AGENTS.md as the canonical instructions file of the project AGENTS.md now holds what CLAUDE.md held (commands, rules), with a "Read first" list of pointers, a "Development environment" section (where the Go and linter pins live, what `make bootstrap` and `make doctor` do) and a line on how the whole-suite runs are gated. The authorship rule now says the owner authors the commits made with the project's own tooling, with one exception: an outside pull request keeps its contributor as author and is merged with a merge commit. The one reference that pointed a reader at CLAUDE.md for the acceptance commands (docs/plans/apply-deferred.md) points at AGENTS.md. CLAUDE.md is left as it is; the next commit reduces it to an import. --- AGENTS.md | 43 ++++++++++++++++++++++++++++++++++++ docs/plans/apply-deferred.md | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..90deaf19 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,43 @@ +# tacctl + +Go CLI that manages a TACACS+ (tacquito) and FreeRADIUS server, its users, +groups and scopes, network devices and enrolled Linux hosts. + +## Read first + +- `docs/development/README.md`: working rules, the examples table. +- `docs/plans/backlog.md` §0: roadmap and the plan of the release in progress. +- `CONTRIBUTING.md`: branches, pull requests. +- `docs/releasing.md`: releases. + +## Development environment + +- The Go version is `GO_VERSION` in `bin/tacctl.sh`; the linter pin is `GOLANGCI_LINT_VERSION` in the `Makefile`. +- `make bootstrap` only initialises the bats submodules (`git submodule update --init --recursive`) and installs nothing else; preview it with `make -n bootstrap`. +- `make doctor` checks the checkout and prints one line per item: a line starting `missing`, `fail` or `error` is a problem, a line starting `expected` is a known accepted absence. Run it after pulling and before the gates. +- Agents never install system packages themselves; the doctor prints the install line. +- A new tool the project needs goes into `make doctor` and into this section in the same change. + +## Commands + +- Build: `make build` (binary in `dist/tacctl`) +- Go tests: `LANG=C.UTF-8 go test ./internal/...` + Two tests need the 0.2.2 tag (the rollback build, the 0.2.2 schema); without it they skip and say so, so CI must fetch the tags. +- Gate run of the Go tests: `make gate-go` (`tests/tools/gate-go.sh`). Start it with Bash `run_in_background`, never with a trailing `&`, never wait for it with `pgrep -f`; only its final `GATE-GO PASS` line counts as a pass. `GATE_TMPFS=1 make gate-go` runs the tests' sandboxes on `/dev/shm`, about three times faster. +- CI-equivalent run of the Go tests: `make gate-ci` (`tests/tools/gate-ci.sh`). + `make gate-go` runs neither the race detector nor `-tags testknobs`; CI runs both (the packages but `internal/cli` with `-race`, the two `internal/cli` shards), so run this before a pull request or a release PR. Same rules as `gate-go` (`run_in_background`, no `&`, no `pgrep -f`, `GATE_TMPFS=1`); only its final `GATE-CI PASS` line counts, a `GATE-CI FAIL` line names the failing tests, and it takes several times as long as `gate-go`. +- Lint: `make lint GOLANGCI_LINT=` (includes `tests/tools/no-private.sh`) +- Bats: `make build`, then as an ordinary user, neither root nor one with sudo (`tests/README.md`): `tests/bats/bats-core/bin/bats tests/integration/.bats` +- Diff corpus: `tests/diff/run.sh --all --against ` +- Containers (rootless podman): `tests/containers/run-all.sh` (the whole matrix, with a table) or one of `tests/containers/{hosts,radius,fresh}/run.sh` +- The whole-suite runs are gated as `make lint` and the static checks, then `make gate-go` per feature, and `make gate-ci` per release. + +## Rules + +- No private names (hosts, addresses, users, home paths, domains) in repo files or commit messages. +- Examples are generic and standard: every domain, host, user, address, time zone (`UTC`), location, SNMP value, secret, serial number and pasted device output comes from the table in `docs/development/README.md` (§ Examples), in docs, man page, help, CHANGELOG, tests and commit messages. +- No Claude attribution in commit messages (no `Claude-Session`, `Co-authored-by` or `Generated with` lines). The owner is the author of every commit made with the project's own tooling: reset a member's author when taking a series in (`git rebase --exec 'git commit --amend --no-edit --reset-author'`); `.mailmap` names the owner for the identities of earlier commits. The one exception is an outside pull request: its commits keep the contributor as author and are merged with a merge commit, never rebased or re-authored. Push only to the current feature branch unless told otherwise. +- Never act against the production host. +- Every user-visible change gets a numbered CHANGELOG item. +- Every user-visible change also updates `man/tacctl.1` and the matching page under `docs/` (`README.md` only holds the quick start and the index) in the same change; the man page shows everything and is never tier-filtered (`make lint` runs the man tests, `make lint-man`, which check it against the code, and `groff -k -ww`; `make man` rewrites its generated blocks). +- Plans are pruned once implemented: delete a release's plan, handoff, lab sheet and spike in the release that ships it (`docs/development/README.md`, Working rules). diff --git a/docs/plans/apply-deferred.md b/docs/plans/apply-deferred.md index 665569e7..cfa204fd 100644 --- a/docs/plans/apply-deferred.md +++ b/docs/plans/apply-deferred.md @@ -292,7 +292,7 @@ The work packages of `0.2.5-plan.md` (decisions D77-D92), for a coordinator to h Sizes: S ≈ ½ session, M ≈ 1 session, L ≈ 1½-2. -## Acceptance commands (from `CLAUDE.md`; every package runs the ones that apply) +## Acceptance commands (from `AGENTS.md`; every package runs the ones that apply) ``` make build From 8ec98f1f86ff40f13d933666e0d673b2d571753d Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:29:17 -0900 Subject: [PATCH 02/52] Reduce CLAUDE.md to an import of AGENTS.md CLAUDE.md is the single line `@AGENTS.md`; the instructions live in AGENTS.md. This commit is its own change and can be reverted on its own, which restores the previous CLAUDE.md content (AGENTS.md stays). --- CLAUDE.md | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index d5c979f8..43c994c2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,30 +1 @@ -# tacctl - -Go CLI that manages a TACACS+ (tacquito) and FreeRADIUS server, its users, -groups and scopes, network devices and enrolled Linux hosts. - -Start with `docs/development/README.md` (working rules, examples), then -`docs/plans/backlog.md` §0 (roadmap) and the plan of the release in progress. - -## Commands - -- Build: `make build` (binary in `dist/tacctl`) -- Go tests: `LANG=C.UTF-8 go test ./internal/...` - Two tests need the 0.2.2 tag (the rollback build, the 0.2.2 schema); without it they skip and say so, so CI must fetch the tags. -- Gate run of the Go tests: `make gate-go` (`tests/tools/gate-go.sh`). Start it with Bash `run_in_background`, never with a trailing `&`, never wait for it with `pgrep -f`; only its final `GATE-GO PASS` line counts as a pass. `GATE_TMPFS=1 make gate-go` runs the tests' sandboxes on `/dev/shm`, about three times faster. -- CI-equivalent run of the Go tests: `make gate-ci` (`tests/tools/gate-ci.sh`). - `make gate-go` runs neither the race detector nor `-tags testknobs`; CI runs both (the packages but `internal/cli` with `-race`, the two `internal/cli` shards), so run this before a pull request or a release PR. Same rules as `gate-go` (`run_in_background`, no `&`, no `pgrep -f`, `GATE_TMPFS=1`); only its final `GATE-CI PASS` line counts, a `GATE-CI FAIL` line names the failing tests, and it takes several times as long as `gate-go`. -- Lint: `make lint GOLANGCI_LINT=` (includes `tests/tools/no-private.sh`) -- Bats: `make build`, then as an ordinary user, neither root nor one with sudo (`tests/README.md`): `tests/bats/bats-core/bin/bats tests/integration/.bats` -- Diff corpus: `tests/diff/run.sh --all --against ` -- Containers (rootless podman): `tests/containers/run-all.sh` (the whole matrix, with a table) or one of `tests/containers/{hosts,radius,fresh}/run.sh` - -## Rules - -- No private names (hosts, addresses, users, home paths, domains) in repo files or commit messages. -- Examples are generic and standard: every domain, host, user, address, time zone (`UTC`), location, SNMP value, secret, serial number and pasted device output comes from the table in `docs/development/README.md` (§ Examples), in docs, man page, help, CHANGELOG, tests and commit messages. -- No Claude attribution in commit messages (no `Claude-Session`, `Co-authored-by` or `Generated with` lines). The owner is the author of every commit: reset a member's author when taking a series in (`git rebase --exec 'git commit --amend --no-edit --reset-author'`); `.mailmap` names the owner for the identities of earlier commits. Push only to the current feature branch unless told otherwise. -- Never act against the production host. -- Every user-visible change gets a numbered CHANGELOG item. -- Every user-visible change also updates `man/tacctl.1` and the matching page under `docs/` (`README.md` only holds the quick start and the index) in the same change; the man page shows everything and is never tier-filtered (`make lint` runs the man tests, `make lint-man`, which check it against the code, and `groff -k -ww`; `make man` rewrites its generated blocks). -- Plans are pruned once implemented: delete a release's plan, handoff, lab sheet and spike in the release that ships it (`docs/development/README.md`, Working rules). +@AGENTS.md From 072a794f47c2a41431df9559c6fd437793b755f3 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:29:03 -0900 Subject: [PATCH 03/52] docs: CONTRIBUTING.md for outside pull requests and issues Describes the branches, what a change carries (CHANGELOG item, man page and docs page, examples from the table, no private names or trailers), how authorship is kept for outside pull requests, the checks before a pull request and where releases are described. The commands and rules stay in AGENTS.md. --- CONTRIBUTING.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..42262469 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,43 @@ +# Contributing to tacctl + +tacctl accepts pull requests and issues from anyone. A security problem is not reported in a +public issue: open an issue that only asks for a private channel, without describing the problem, +and the maintainer will answer there. + +`AGENTS.md` holds the commands, the rules and the development environment; this page does not +repeat them. `docs/development/README.md` has the working rules and the examples table. + +## Branches + +- `master` holds the tagged releases. +- `develop` is the integration branch. +- Work happens on `feature/`, cut from `develop` and merged back with `--no-ff`. +- `release/` and `hotfix/` are cut by the maintainer. +- `gh-pages` is the documentation site and is never merged into the others. + +A pull request from a contributor targets `develop`. + +## What a change carries + +- A numbered item in the next release's section of `CHANGELOG.md` (the heading is + `## (unreleased)`). Use the next free number; the maintainer renumbers. +- For a user-visible change, also `man/tacctl.1` and the matching page under `docs/`. +- Examples only from the table in `docs/development/README.md` (§ Examples). +- No private names (hosts, addresses, users, home paths, domains) in files or commit messages. +- No attribution trailers in commit messages. + +## Authorship + +Commits that arrive in an outside pull request keep their author. The maintainer merges the pull +request with a merge commit and does not rebase or re-author it. Commits the maintainer makes with +their own tooling carry the maintainer as author. + +## Before opening a pull request + +Run `make lint` and `GATE_TMPFS=1 make gate-go`; the maintainer runs the longer `make gate-ci` +before a release. `AGENTS.md` ("Commands") lists the rest. CI runs the `test` workflow on every +pull request. + +## Releases + +The maintainer cuts them; the steps are in `docs/releasing.md`. From 419cc9ba56bbe75ae9e728201980eb8dcbb20549 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:29:20 -0900 Subject: [PATCH 04/52] mailmap: say that outside pull requests keep their own author The header said every commit has the owner as author. State the exception: commits of outside pull requests keep their author and are not listed. No mapping line changes. --- .mailmap | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.mailmap b/.mailmap index f3488aeb..4f55a8b4 100644 --- a/.mailmap +++ b/.mailmap @@ -1,5 +1,6 @@ -# One author for every commit: the owner. Git tools that read this file (git log, shortlog, blame) show the -# owner for the identities that were not. GitHub does not read it. +# One author for every commit the maintainer makes: the owner. Git tools that read this file (git log, +# shortlog, blame) show the owner for the identities listed here. Commits of outside pull requests keep +# their own author and are not listed. GitHub does not read it. Everett C. Haimes III qargi Everett C. Haimes III check Everett C. Haimes III Tacctl Docs Writer From 335304a933953fffb07bd8135fa1a06aa0d99a11 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:30:04 -0900 Subject: [PATCH 05/52] tests: doctor.sh checks a checkout for the tools the project needs A read-only, no-network check that prints one line per item (ok, missing with the one-line fix, or expected with why this host may lack it) and exits 1 when anything is missing. It covers the pinned Go (GO_VERSION of bin/tacctl.sh) with gofmt and a C compiler, golangci-lint at the Makefile's pin, the tools whose absence makes tests of internal/cli and internal/console skip silently (the list in test.yml), the bats submodules and the 0.2.2 tag, then the optional tools (GNU parallel, PyYAML, podman, weasyprint) and the host (/dev/shm, root or sudo, the private-pattern file) as expected. The pins are read from where they live, so a bump needs no change here. --- tests/tools/doctor.sh | 195 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100755 tests/tools/doctor.sh diff --git a/tests/tools/doctor.sh b/tests/tools/doctor.sh new file mode 100755 index 00000000..45257716 --- /dev/null +++ b/tests/tools/doctor.sh @@ -0,0 +1,195 @@ +#!/usr/bin/env bash +# doctor.sh +# +# Checks this checkout and this machine for what the project's tooling needs +# ('make doctor'). It only looks: it installs nothing, runs no test, uses no +# network and no sudo, and finishes in a second or two. One line per item, +# in one of three forms: +# +# ok : +# missing : +# expected : +# +# 'missing' is a tool or file that make lint, make gate-go or make build needs, +# or whose absence makes tests skip silently (the list in the comment at the +# top of .github/workflows/test.yml); 'expected' is optional, with what you +# lose without it. The exit status is 1 when any line starts with 'missing', +# else 0. +# +# The pins are read where they live, never copied here: the Go version +# (GO_VERSION) from bin/tacctl.sh, the golangci-lint version +# (GOLANGCI_LINT_VERSION) and the default GO from the Makefile. GO, GOFMT and +# GOLANGCI_LINT in the environment override the Makefile's choice, as they do +# for make; TACCTL_PRIVATE_PATTERNS names the private-name pattern file, as for +# tests/tools/no-private.sh. +set -uo pipefail + +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) || exit 1 +status=0 + +ok() { printf 'ok %s: %s\n' "$1" "$2"; } +expected() { printf 'expected %s: %s\n' "$1" "$2"; } +missing() { + printf 'missing %s: %s\n' "$1" "$2" + status=1 +} + +# first_line : the first line of its output, "" when it fails. +first_line() { "$@" 2> /dev/null | head -n 1; } + +# have_tool : ok with the +# version line (or the path when the command prints none), or missing. +have_tool() { + local item="$1" cmd="$2" hint="$3" path ver + shift 3 + if ! path=$(command -v "$cmd" 2> /dev/null); then + missing "$item" "$hint" + return + fi + ver="" + [[ $# -eq 0 ]] || ver=$(first_line "$@") + ok "$item" "${ver:-$path}" +} + +# --- 1. Go: the Makefile's GO, at exactly the version bin/tacctl.sh pins ------ +go_pin=$(sed -n 's/^GO_VERSION="\([0-9.]*\)"$/\1/p' "$root/bin/tacctl.sh" 2> /dev/null) +GO="${GO:-$(sed -n 's/^GO ?= *//p' "$root/Makefile" 2> /dev/null | head -n 1)}" +GO="${GO:-/usr/local/go/bin/go}" +go_fix="run bin/tacctl.sh as root (it installs the pinned Go ${go_pin:-?} in /usr/local/go; --build only uses it), or set GO=" +if [[ -z "$go_pin" ]]; then + missing go "no GO_VERSION in bin/tacctl.sh, so the pinned Go cannot be known" +elif ! go_path=$(command -v "$GO" 2> /dev/null); then + missing go "$GO does not exist: $go_fix" +else + go_have=$("$go_path" version 2> /dev/null | awk '{print $3}') + go_have="${go_have#go}" + if [[ "$go_have" == "$go_pin" ]]; then + ok go "$go_have ($go_path)" + else + missing go "$go_path is ${go_have:-of an unknown version}, bin/tacctl.sh pins $go_pin: $go_fix" + fi +fi + +# --- 2. gofmt beside that go, and a C compiler (cgo, the race detector) ------- +gofmt="${GOFMT:-$(dirname "$GO")/gofmt}" +if [[ -x "$gofmt" ]]; then + ok gofmt "$gofmt" +else + missing gofmt "$gofmt does not exist; it comes with the Go toolchain (see go)" +fi +if cc_path=$(command -v cc 2> /dev/null || command -v gcc 2> /dev/null); then + ok cc "$(first_line "$cc_path" --version) ($cc_path)" +else + missing cc "install a C compiler for cgo and the race detector (apt install gcc, pacman -S gcc)" +fi + +# --- 3. golangci-lint, found as the lint-go target finds it ------------------- +lint_pin=$(sed -n 's/^GOLANGCI_LINT_VERSION := \(v[0-9.]*\)$/\1/p' "$root/Makefile" 2> /dev/null) +lint_install="GOBIN=\$HOME/.local/bin $GO install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${lint_pin:-?}" +lint="" +if [[ -n "${GOLANGCI_LINT:-}" ]]; then + lint="$GOLANGCI_LINT" +else + lint=$(command -v golangci-lint 2> /dev/null) + for cand in "$HOME/go/bin/golangci-lint" "$HOME/.local/bin/golangci-lint"; do + [[ -n "$lint" || ! -x "$cand" ]] || lint="$cand" + done +fi +if [[ -z "$lint_pin" ]]; then + missing golangci-lint "no GOLANGCI_LINT_VERSION in the Makefile, so the pinned version cannot be known" +elif [[ -z "$lint" ]] || ! lint_path=$(command -v "$lint" 2> /dev/null); then + missing golangci-lint "not found; install $lint_pin for your user (no root): $lint_install" +else + lint_have=$("$lint_path" version --short 2> /dev/null) + if [[ "v${lint_have#v}" == "$lint_pin" ]]; then + ok golangci-lint "$lint_pin ($lint_path)" + else + missing golangci-lint "$lint_path is '${lint_have:-unknown}', the Makefile pins $lint_pin: $lint_install" + fi +fi + +# --- 4. what the tests of internal/cli skip without (test.yml) ---------------- +apt_hint() { echo "apt install $1 (pacman -S $2)"; } +if command -v shellcheck > /dev/null 2>&1; then + ok shellcheck "$(shellcheck --version 2> /dev/null | sed -n 's/^version: //p')" +else + missing shellcheck "$(apt_hint shellcheck shellcheck)" +fi +have_tool groff groff "$(apt_hint groff groff)" groff --version +have_tool less less "$(apt_hint less less)" less --version +have_tool man man "$(apt_hint man-db man-db)" man --version +have_tool setsid setsid "$(apt_hint util-linux util-linux)" setsid --version + +# --- 5. what the tests of internal/console skip without (test.yml) ------------ +# sshd lives in /usr/sbin, which an ordinary user's PATH may not list; the +# tests look there too. +if sshd=$(command -v sshd 2> /dev/null) || { [[ -x /usr/sbin/sshd ]] && sshd=/usr/sbin/sshd; }; then + ok sshd "$sshd" +else + missing sshd "$(apt_hint openssh-server openssh)" +fi +have_tool ssh-keygen ssh-keygen "$(apt_hint openssh-client openssh)" + +# --- 6. the bats submodules --------------------------------------------------- +bats_bad="" +[[ -x "$root/tests/bats/bats-core/bin/bats" ]] || bats_bad=" bats-core/bin/bats" +for d in bats-support bats-assert bats-file; do + [[ -n "$(ls -A "$root/tests/bats/$d" 2> /dev/null)" ]] || bats_bad="$bats_bad $d" +done +if [[ -z "$bats_bad" ]]; then + ok bats "the four submodules under tests/bats are in place" +else + missing bats "not initialised:$bats_bad; run make bootstrap (git submodule update --init --recursive)" +fi + +# --- 7. the 0.2.2 tag: two Go tests skip without it --------------------------- +if git -C "$root" rev-parse -q --verify refs/tags/0.2.2 > /dev/null 2>&1; then + ok tag-0.2.2 "present" +else + missing tag-0.2.2 "two Go tests skip without it (the rollback build, the 0.2.2 schema): git fetch --tags" +fi + +# --- 8. optional tools -------------------------------------------------------- +parallel_ver=$(first_line parallel --version) +if [[ "$parallel_ver" == *"GNU parallel"* ]]; then + ok parallel "$parallel_ver" +else + expected parallel "not GNU parallel, so bats runs serially (apt install parallel)" +fi +if ! command -v python3 > /dev/null 2>&1; then + expected python3 "not installed; the PyYAML corpus check (make test-pyyaml) says so and passes" +elif yaml_ver=$(python3 -c 'import yaml; print(yaml.__version__)' 2> /dev/null); then + ok python3 "PyYAML $yaml_ver" +else + expected python3 "no PyYAML; the corpus check passes without it (apt install python3-yaml)" +fi +if podman_ver=$(first_line podman --version) && [[ -n "$podman_ver" ]]; then + ok podman "$podman_ver" +else + expected podman "the container tests are maintainer-only (tests/containers)" +fi +if weasy_ver=$(first_line weasyprint --version) && [[ -n "$weasy_ver" ]]; then + ok weasyprint "$weasy_ver" +else + expected weasyprint "the tests of the pdf report format skip without it (apt install weasyprint)" +fi + +# --- 9. this host ------------------------------------------------------------- +if [[ -d /dev/shm && -w /dev/shm ]]; then + ok /dev/shm "writable (GATE_TMPFS=1 can use it)" +else + expected /dev/shm "not writable here, so GATE_TMPFS=1 cannot be used" +fi +if [[ $EUID -eq 0 || -n "${SUDO_USER:-}" ]]; then + expected user "running as root or in a sudo session; bats must run as an ordinary user (tests/README.md)" +else + ok user "an ordinary user (uid $EUID), as bats needs (tests/README.md)" +fi +patterns="${TACCTL_PRIVATE_PATTERNS:-$HOME/.config/tacctl/private-patterns}" +if [[ -f "$patterns" ]]; then + ok private-patterns "$patterns" +else + expected private-patterns "$patterns is absent; tests/tools/no-private.sh then checks only its built-in patterns" +fi + +exit "$status" From 273e15d21edbe9bb3fa27c251cb4e07281926e52 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:30:29 -0900 Subject: [PATCH 06/52] Makefile: make doctor runs tests/tools/doctor.sh The target passes the Makefile's GO, GOFMT and GOLANGCI_LINT to the script, so the check looks at the same tools as lint-go and gate-go. --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 70ca7fe1..27d0c714 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: test test-go test-bats test-integration test-e2e test-diff test-pyyaml build \ - coverage gate-go gate-ci lint lint-sh lint-go lint-man lint-private lint-logger lint-short-yes lint-shared-proc man hooks clean bootstrap release-assets release-verify release-reproduce + coverage gate-go gate-ci lint lint-sh lint-go lint-man lint-private lint-logger lint-short-yes lint-shared-proc man hooks clean bootstrap doctor release-assets release-verify release-reproduce BATS := tests/bats/bats-core/bin/bats BATS_FLAGS ?= --print-output-on-failure @@ -234,5 +234,12 @@ lint-go: bootstrap: git submodule update --init --recursive +# What this checkout and machine lack for the targets above: one line per tool +# or file, ok, missing (with the fix) or expected (optional), and exit 1 when +# any is missing. It only looks: no install, no test, no network, no sudo +# (tests/tools/doctor.sh). +doctor: + GO="$(GO)" GOFMT="$(GOFMT)" GOLANGCI_LINT="$(GOLANGCI_LINT)" tests/tools/doctor.sh + clean: rm -rf coverage dist From efc33aa33c7aa217b7acfdc58d88896f1f4dfdff Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:30:41 -0900 Subject: [PATCH 07/52] docs: releasing.md describes the qargi release flow Each release and A hotfix now follow the flow that runs: release verify, start, push and finish, then the after-steps assets, sign, publish, reproducible, site and prune, each with who does it and what proves it. The checks before the first step, the signing step and the host check keep their content; the hand-run git-flow commands move to a last section for a release made without the tooling. --- docs/releasing.md | 297 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 211 insertions(+), 86 deletions(-) diff --git a/docs/releasing.md b/docs/releasing.md index d32eea82..c49a6139 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -2,7 +2,7 @@ A release is a tag on `master` plus four GitHub release assets, built and signed on the release manager's own machine; a workflow then rebuilds them -independently and compares (step 4): +independently and compares (step 8): | Asset | What it is | |---|---| @@ -71,18 +71,23 @@ their own tree lists. The example is 0.2.1 (the release before it 0.2.0); replace it throughout. -The git-flow commands of steps 1 and 4 are written out by hand: qargi's -release tooling will replace them once it supports this project's CHANGELOG -headings and signed assets. +A release runs with qargi, the git-flow release tooling the maintainer +uses. Its commands are plans: each prints what it will do before anything is +applied. The division of labour is fixed. The maintainer's tooling drives the +git-flow steps (verify, start, push, finish) and the after-steps that build, +publish and clean up; the key holder alone signs; and every merge into +`develop` or `master`, every push and every tag is a plan that needs the +maintainer's explicit go-ahead. The hand commands are kept at the end, for a +release made without the tooling. -Before step 1, bring the tacquito fork's `main` up to upstream +Before the first step, bring the tacquito fork's `main` up to upstream (`patches/README.md`, Following upstream) and run the gates on it: a host builds the fork's head, and a host upgrading from a release before 0.2.24 pulls upstream once before the new binary points its clone at the fork, so a fork behind upstream makes that host rebuild tacquito at every upgrade until the fork catches up. -Also before step 1, on `develop`: +Also before the first step, on `develop`: - **The rollback target.** Every release ships `tacctl rollback ` (0.2.17 to 0.2.27 each did). Check that the release before this @@ -100,56 +105,107 @@ Also before step 1, on `develop`: or tag that still holds it (`git show :docs/plans/`). `docs/plans/` keeps the backlog, what is deferred and the plan of the release in progress. - - **The notes.** `tests/tools/release-notes-check.sh ` (qargi runs it as `release.preflight` before `release start` and `release push`) checks that `docs/release-notes-.md` exists and points at the CHANGELOG, that the CHANGELOG section of the version has items numbered 1, 2, 3 ... - without a gap, and that `const rollbackFrom` is the version. + without a gap, and that `const rollbackFrom` is the version. The notes are + committed on `develop` before the release starts. Model them on + `docs/release-notes-0.2.23.md`: a `# tacctl ` title, a paragraph + on what the release does that points to its numbered CHANGELOG section for + everything that differs from the release before, then sections by theme + (`## Devices`, `## Rollback`, `## Upgrading`, ...). The publish step + (step 7) uses them as the release's text. + +The steps, in order. The first four are the git-flow steps; the rest are the +after-steps, each recorded with `qargi release step 0.2.1 ` once its +proof holds. + +| # | Step | Who | What proves it | +|---|---|---|---| +| 1 | verify | the maintainer's tooling | a passing release gate at the head of `develop` | +| 2 | start | the maintainer's tooling, on the maintainer's go-ahead | `release/0.2.1` exists, its first commit dates the release | +| 3 | push | the maintainer's tooling | the checks of the pull request into `master` are green | +| 4 | finish | the maintainer's tooling, on the maintainer's go-ahead | `git describe master` prints `0.2.1`; `master`, `develop` and the tag are pushed | +| 5 | assets | the maintainer's tooling | `dist/release` holds the two binaries and `SHA256SUMS` | +| 6 | sign | the key holder only | `make release-verify` passes | +| 7 | publish | the maintainer's tooling | the GitHub release holds the four files | +| 8 | reproducible | the maintainer's tooling | the `release-reproducible` run of the tag is green | +| 9 | check on a host | the maintainer | `tacctl upgrade` installs the verified binary | +| 10 | site | the maintainer's tooling | the `build` check of the `gh-pages` pull request is green, then it is merged | +| 11 | prune | the maintainer's tooling | no merged branch is left, local or remote | + +### 1. Verify + +```sh +qargi release verify 0.2.1 +``` -### 1. The release branch, the dates, the tag +Runs the release gate: the feature gates first (`make lint`, the static +checks and `make gate-go`), then `GATE_TMPFS=1 make gate-ci` (what the `test` +workflow runs: the race detector and the `-tags testknobs` shards; +`docs/development/README.md`, Working rules). Only a passing run at the head +of `develop` lets a release start; a commit after it needs a new run. The +verdict that counts is the final `GATE-CI PASS` line. + +### 2. Start ```sh -git checkout develop && git pull -git flow release start 0.2.1 -sed -i 's/^## 0\.2\.1 (unreleased)$/## 0.2.1 (YYYY-MM-DD)/' CHANGELOG.md -sed -i 's/^\.TH TACCTL 1 "[^"]*" "tacctl [^"]*"/.TH TACCTL 1 "YYYY-MM-DD" "tacctl 0.2.1"/' \ - man/tacctl.1 -git add docs/release-notes-0.2.1.md # written now: see below -git commit -am "docs: 0.2.1 release date" -git push -u origin release/0.2.1 -gh pr create --base master --head release/0.2.1 --title "0.2.1" --body "Release 0.2.1" -gh pr checks --watch # the Go tests on the release commit; all green before the tag -git flow release finish -m "Release 0.2.1" 0.2.1 -git tag -f -a 0.2.1 -m "Release 0.2.1" master # git-flow writes "Release 0.2.1 0.2.1" -git describe master # 0.2.1 +qargi release start 0.2.1 ``` -The same commit adds the release notes, `docs/release-notes-0.2.1.md`: -`tests/tools/release-preflight.sh` refuses to build assets without them -(step 2), and step 4 publishes them as the release's text. Model them on -`docs/release-notes-0.2.23.md`: a `# tacctl ` title, a paragraph on -what the release does that points to its numbered CHANGELOG section for -everything that differs from the release before, then sections by theme -(`## Devices`, `## Rollback`, `## Upgrading`, ...). +A plan and a token, applied on the maintainer's go-ahead. It runs the stored +preflight (`tests/tools/release-notes-check.sh 0.2.1`, above), creates +`release/0.2.1` from `develop`, and makes the first commit of the branch: the +CHANGELOG heading `## 0.2.1 (unreleased)` becomes `## 0.2.1 (YYYY-MM-DD)` and +the `.TH` line of `man/tacctl.1` takes the same date and `tacctl 0.2.1`. +There is no `VERSION` file: the version is the CHANGELOG heading, the tag and +`const rollbackFrom` in `internal/cli/rollback.go`. -The `sed` of `man/tacctl.1` sets the date and the version of its `.TH` -line, which must match the CHANGELOG heading (step 2). +### 3. Push + +```sh +qargi release push 0.2.1 +``` -The release branch is pushed first so that the `test` workflow runs on the -release commit (the date changes and the notes) before the tag exists; it -runs on a pull request and on a push to `develop`, not on a push to -`master`, whose files are the same as `develop`'s after the finish. The -pull request closes by itself when `master` is pushed (step 4); delete the -remote branch then: `git push origin --delete release/0.2.1`. +Pushes the release branch and opens the pull request into `master`, so that +the `test` workflow runs on the release commit (the date changes and the +notes) before the tag exists; the workflow runs on a pull request and on a +push to `develop`, not on a push to `master`, whose files are the same as +`develop`'s after the finish. Wait for the checks of the pull request: all +green before the finish. -### 2. Build the assets from the tag +### 4. Finish ```sh -git checkout 0.2.1 # a clean checkout of exactly the tag -make release-assets # dist/release/tacctl-0.2.1-linux-{amd64,arm64} and SHA256SUMS +qargi release finish 0.2.1 ``` +A plan, a token and the maintainer's go-ahead. It merges `release/0.2.1` +into `master` without fast-forward, creates the annotated tag `0.2.1`, +merges the release into `develop`, deletes the release branch, and pushes +`master`, `develop` and the tag. The pull request closes by itself when +`master` is pushed. `git describe master` prints `0.2.1`. + +The GitHub repository refuses force pushes and deletion of `master` and +`develop` and any move or deletion of a `0.*` tag: a pushed tag is final, so +a fault found after the finish is fixed in the next release (or a hotfix), +never by moving the tag. That is why the gate of step 1, the preflight of +step 2 and the checks of step 3 come before it. A host that upgrades between +the finish and the publish (step 7) finds no release binary and builds from +source (`could not download SHA256SUMS`). + +### 5. Assets + +```sh +qargi release assets 0.2.1 +``` + +Builds `dist/release/tacctl-0.2.1-linux-amd64`, +`dist/release/tacctl-0.2.1-linux-arm64` and `dist/release/SHA256SUMS` from the +tag, with `make release-assets` (by hand: `git checkout 0.2.1`, a clean +checkout of exactly the tag, then `make release-assets`). + `make release-assets` refuses a tree that is not at a release tag or has local changes, and one whose release metadata is not in place (`tests/tools/release-preflight.sh`, which lists every problem): the tag has @@ -161,7 +217,11 @@ test knobs off, the version and commit stamped from git) and prints `SHA256SUMS`. `RELEASE_TAG=` builds trial assets from any tree and skips the metadata check. -### 3. Sign and verify +### 6. Sign and verify + +Only the key holder signs, on the release manager's own machine, and types +the passphrase; nobody else handles the passphrase or the private key. The +release waits for the key holder here. ```sh ssh-keygen -Y sign -f ~/.ssh/tacctl-release -n tacctl-release dist/release/SHA256SUMS @@ -190,28 +250,49 @@ ssh-keygen -Y sign -f /tmp/trial-key -n tacctl-release dist/release/SHA256SUMS make release-verify ALLOWED_SIGNERS=/tmp/trial-signers ``` -### 4. Push and publish +### 7. Publish -The GitHub repository refuses force pushes and deletion of `master` and -`develop` and any move or deletion of a `0.*` tag, so the tag is made -and checked locally (`git tag -f` above) and pushed once, with the signed -assets already built from it; a pushed tag is final. +```sh +qargi release publish 0.2.1 --notes-file docs/release-notes-0.2.1.md +``` + +Creates the GitHub release of the tag with the four assets (the two +binaries, `SHA256SUMS` and `SHA256SUMS.sig`) in one step, and the release +notes as its text. All four go together: the `release-reproducible` workflow +starts on the publish and needs the signed sums. + +A release's title is always `tacctl ` (`tacctl 0.2.1`), never the bare +tag; the title of a release made another way is fixed with +`gh release edit 0.2.1 --title "tacctl 0.2.1"`. To list the titles that do +not follow the rule: + +```sh +gh release list --limit 100 --json tagName,name \ + --jq '.[] | select(.name != "tacctl " + .tagName) | .tagName' +``` + +For a release that already exists, `gh release upload 0.2.1` with the same +four files adds them (with `--clobber`, replaces them). + +Once, for discoverability, set the repository topics: + +```sh +gh repo edit --add-topic tacacs-plus --add-topic tacacs --add-topic radius --add-topic aaa \ + --add-topic freeradius --add-topic network-automation --add-topic cisco --add-topic junos \ + --add-topic golang +``` + +### 8. Reproducible ```sh -git checkout develop -git push origin develop master 0.2.1 -gh release create 0.2.1 --verify-tag --title "tacctl 0.2.1" \ - --notes-file docs/release-notes-0.2.1.md \ - dist/release/tacctl-0.2.1-linux-amd64 dist/release/tacctl-0.2.1-linux-arm64 \ - dist/release/SHA256SUMS dist/release/SHA256SUMS.sig gh run list --workflow release-reproducible.yml --limit 1 # the job the publish started gh run watch ``` -The `release-reproducible` workflow -(`.github/workflows/release-reproducible.yml`) starts when the release is -published. On a clean runner it checks out the tag, installs the Go version -that tag's `bin/tacctl.sh` names, and runs +Watch the run of the tag and record its URL with the step. The +`release-reproducible` workflow (`.github/workflows/release-reproducible.yml`) +starts when the release is published. On a clean runner it checks out the +tag, installs the Go version that tag's `bin/tacctl.sh` names, and runs `tests/tools/release-reproduce.sh `: 1. downloads the published `SHA256SUMS` and `SHA256SUMS.sig`; @@ -238,29 +319,7 @@ included (it takes the script from the branch it is run on and the build recipe from the tag): `gh workflow run release-reproducible.yml -f tag=0.2.1`. The workflow file must be on the default branch for that. -Once, for discoverability, set the repository topics: - -```sh -gh repo edit --add-topic tacacs-plus --add-topic tacacs --add-topic radius --add-topic aaa \ - --add-topic freeradius --add-topic network-automation --add-topic cisco --add-topic junos \ - --add-topic golang -``` - -A release's title is always `tacctl ` (`tacctl 0.2.1`), never the bare -tag; the title of a release made another way is fixed with -`gh release edit 0.2.1 --title "tacctl 0.2.1"`. To list the titles that do -not follow the rule: - -```sh -gh release list --limit 100 --json tagName,name \ - --jq '.[] | select(.name != "tacctl " + .tagName) | .tagName' -``` - -(For a release that already exists: `gh release upload 0.2.1` with the same -four files.) A host that upgrades between the push and the upload simply -builds from source (`could not download SHA256SUMS`). - -### 5. Check on a host +### 9. Check on a host On a host that follows `master`: @@ -281,7 +340,7 @@ sha256sum -c --ignore-missing SHA256SUMS The fresh-install container check can then run against the published release: `tests/containers/fresh/run.sh --release 0.2.1`. -### 6. The documentation site +### 10. The documentation site The site at https://tacctl.rettware.com/ is built from the orphan `gh-pages` branch, which has no history in common with the code and is never @@ -313,12 +372,78 @@ python3 tools/check_commands.py site Merge the pull request into `gh-pages` only once its `build` check has passed. +### 11. Prune + +```sh +qargi branch prune +``` + +Deletes the branches that are merged (the release's feature and agent +branches, local and remote), as a plan like the others. + ## A hotfix A fix that cannot wait for the next release starts from `master`, not from -`develop`: `git flow hotfix start 0.2.6` (the branch is `hotfix/0.2.6`), the -fix and its CHANGELOG section (`## 0.2.6 (unreleased)`, numbering from 1, the -items that differ from the release it fixes), then `git flow hotfix finish -m -"Release 0.2.6" 0.2.6`, which tags `master` and merges back into `develop`. -Everything else is as for a release: the date and version in `man/tacctl.1` -and the CHANGELOG heading before the finish, and steps 2 to 6 above. +`develop`: + +```sh +qargi release start 0.2.6 --hotfix +# the fix and its CHANGELOG section (## 0.2.6 (unreleased), numbering from 1, +# the items that differ from the release it fixes) and the release notes +qargi release push 0.2.6 +qargi release finish 0.2.6 --hotfix +``` + +`start` makes `hotfix/0.2.6` from `master`; `finish` tags `master` and merges +the fix back into the release branch when one is open, else into `develop`. +Everything else is as for a release: the same plans and go-aheads, the date +and version in `man/tacctl.1` and the CHANGELOG heading before the finish, +and the after-steps 5 to 11 above (assets, sign, publish, reproducible, +check on a host, site, prune). + +## If the release tooling is unavailable (by hand) + +A release can be made without qargi. The git-flow steps 2 to 4 by hand: + +```sh +git checkout develop && git pull +git flow release start 0.2.1 +sed -i 's/^## 0\.2\.1 (unreleased)$/## 0.2.1 (YYYY-MM-DD)/' CHANGELOG.md +sed -i 's/^\.TH TACCTL 1 "[^"]*" "tacctl [^"]*"/.TH TACCTL 1 "YYYY-MM-DD" "tacctl 0.2.1"/' \ + man/tacctl.1 +git add docs/release-notes-0.2.1.md # unless it is committed on develop already +git commit -am "docs: 0.2.1 release date" +git push -u origin release/0.2.1 +gh pr create --base master --head release/0.2.1 --title "0.2.1" --body "Release 0.2.1" +gh pr checks --watch # the Go tests on the release commit; all green before the tag +git flow release finish -m "Release 0.2.1" 0.2.1 +git tag -f -a 0.2.1 -m "Release 0.2.1" master # git-flow writes "Release 0.2.1 0.2.1" +git describe master # 0.2.1 +``` + +The tag is made and checked locally (`git tag -f`) and pushed once, with the +signed assets already built from it, because a pushed tag is final. Build +the assets from the tag and sign them (steps 5 and 6), then push and +publish (step 4's pushes and step 7): + +```sh +git checkout develop +git push origin develop master 0.2.1 +gh release create 0.2.1 --verify-tag --title "tacctl 0.2.1" \ + --notes-file docs/release-notes-0.2.1.md \ + dist/release/tacctl-0.2.1-linux-amd64 dist/release/tacctl-0.2.1-linux-arm64 \ + dist/release/SHA256SUMS dist/release/SHA256SUMS.sig +``` + +The pull request closes by itself when `master` is pushed; delete the +remote branch then: `git push origin --delete release/0.2.1`. Then steps 8 +to 10 as above. A host that upgrades between the push and the upload simply +builds from source (`could not download SHA256SUMS`). + +A hotfix by hand: `git flow hotfix start 0.2.6` (the branch is +`hotfix/0.2.6`), the fix and its CHANGELOG section (`## 0.2.6 +(unreleased)`, numbering from 1, the items that differ from the release it +fixes), then `git flow hotfix finish -m "Release 0.2.6" 0.2.6`, which tags +`master` and merges back into `develop`; the date and version in +`man/tacctl.1` and the CHANGELOG heading come before the finish, and the +rest is as above. From 41edbb0086d3fa4138e1aea31965c0429ec85a74 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:33:13 -0900 Subject: [PATCH 08/52] docs: development page names sftp, AGENTS.md, CONTRIBUTING.md and the declared gates The dependency comment lists github.com/pkg/sftp and kr/fs, which go.mod has; the structure listing and the Working rules name AGENTS.md and CONTRIBUTING.md; the gates rule names the declared gates (make lint and make gate-go per feature, make gate-ci per release); the release rule says when release-reproducible runs. --- docs/development/README.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/development/README.md b/docs/development/README.md index 2e1eb183..fb730b4d 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -14,7 +14,8 @@ tacctl/ vendor/ # vendored Go dependencies (builds need no network) go.mod, go.sum # dependencies: github.com/spf13/cobra (with spf13/pflag and # inconshreveable/mousetrap), golang.org/x/crypto (bcrypt, ssh), - # golang.org/x/sys, golang.org/x/term, gopkg.in/yaml.v3 + # golang.org/x/sys, golang.org/x/term, gopkg.in/yaml.v3, + # github.com/pkg/sftp (with kr/fs; the console's file transfer server) config/ backends/tacacs/ tacquito.yaml # Reference layout of the rendered TACACS+ config @@ -35,6 +36,8 @@ tacctl/ # hosts # verify a release binary), radius-notes.md, release notes, plans/ tests/ # Go and bats suites, containers (tests/README.md) + AGENTS.md # instructions for agents and contributors + CONTRIBUTING.md # branches, pull requests CHANGELOG.md README.md LICENSE @@ -42,6 +45,8 @@ tacctl/ ## Working rules +- Instructions for agents and contributors are in `AGENTS.md`; branches and + pull requests are in `CONTRIBUTING.md`. - Model routing: Opus reviews, Sonnet and Haiku implement, Fable decides important design questions. Subagents never commit; the coordinator reviews, merges, renumbers CHANGELOG items and commits. @@ -80,7 +85,10 @@ tacctl/ descriptions. - No secret, hash, password or community string in any log line, test golden or doc example. -- Gates: build, gofmt, `go vet`, `make lint`, Go tests (`make gate-go`, +- Gates. The declared gates are `make lint` (shellcheck, gofmt, `go vet`, + golangci-lint and the repository's own static checks) and `make gate-go` + for each feature, and `make gate-ci` for each release. The checks are: + build, gofmt, `go vet`, `make lint`, Go tests (`make gate-go`, which runs `internal/cli` under `setsid` with no stdin and ends with one `GATE-GO PASS|FAIL` line: start it with the Bash tool's `run_in_background`, never with a trailing `&` or a `pgrep -f` wait, and @@ -102,9 +110,11 @@ tacctl/ runs on. A test that needs the process environment, the lock wait or a package-wide registry calls `serial(t)` first; the others run in parallel (`hooks_test.go`). -- A release: `docs/releasing.md`. The release branch is pushed and a pull - request opened to `master` so the Go tests run before the tag; - `release-reproducible` runs on the tag by `workflow_dispatch`. +- A release: `docs/releasing.md`. The release gate is `make gate-ci` + (`qargi release verify` runs it after the feature gates); the release + branch is pushed and a pull request opened to `master` so the Go tests run + before the tag; `release-reproducible` runs when the release is published + (and by `workflow_dispatch` for any tag). - Plans are pruned once implemented: a plan, handoff, lab sheet or spike of a released version is deleted in the release that ships it (its decisions are in the CHANGELOG, the docs and git; the code cites them From c777cd8fbc344bf7e0031b53c214683ef6ed36b7 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:39:08 -0900 Subject: [PATCH 09/52] doctor: accept a Go newer than the pin bin/tacctl.sh installs Go only when it is missing or older and never replaces a newer one, so the Go check of make doctor now accepts a Go equal to the pin or newer (compared with sort -V) and says so when it is newer. An older or unknown version is still reported missing. --- tests/tools/doctor.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/tools/doctor.sh b/tests/tools/doctor.sh index 45257716..3eb7b36f 100755 --- a/tests/tools/doctor.sh +++ b/tests/tools/doctor.sh @@ -51,7 +51,7 @@ have_tool() { ok "$item" "${ver:-$path}" } -# --- 1. Go: the Makefile's GO, at exactly the version bin/tacctl.sh pins ------ +# --- 1. Go: the Makefile's GO, at the version bin/tacctl.sh pins or newer ----- go_pin=$(sed -n 's/^GO_VERSION="\([0-9.]*\)"$/\1/p' "$root/bin/tacctl.sh" 2> /dev/null) GO="${GO:-$(sed -n 's/^GO ?= *//p' "$root/Makefile" 2> /dev/null | head -n 1)}" GO="${GO:-/usr/local/go/bin/go}" @@ -63,8 +63,14 @@ elif ! go_path=$(command -v "$GO" 2> /dev/null); then else go_have=$("$go_path" version 2> /dev/null | awk '{print $3}') go_have="${go_have#go}" - if [[ "$go_have" == "$go_pin" ]]; then - ok go "$go_have ($go_path)" + # bin/tacctl.sh installs Go only when it is missing or older and never + # replaces a newer one, so a Go equal to the pin or newer is fine. + if [[ -n "$go_have" && "$(printf '%s\n%s\n' "$go_pin" "$go_have" | sort -V | head -n 1)" == "$go_pin" ]]; then + if [[ "$go_have" == "$go_pin" ]]; then + ok go "$go_have ($go_path)" + else + ok go "$go_have ($go_path; the pin is $go_pin)" + fi else missing go "$go_path is ${go_have:-of an unknown version}, bin/tacctl.sh pins $go_pin: $go_fix" fi From 0d2dd22af74d76246e8f467cda7db94d8b15a99f Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:39:08 -0900 Subject: [PATCH 10/52] CONTRIBUTING: the unreleased heading may not exist yet Right after a release the CHANGELOG has no unreleased section. Say to add the item under the next version's heading and to create that heading above the newest release section when it is missing. --- CONTRIBUTING.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 42262469..e843f389 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,8 +19,9 @@ A pull request from a contributor targets `develop`. ## What a change carries -- A numbered item in the next release's section of `CHANGELOG.md` (the heading is - `## (unreleased)`). Use the next free number; the maintainer renumbers. +- A numbered item in `CHANGELOG.md` under `## (unreleased)`; right after a + release that heading is not there yet, so create it above the newest release section. Use + the next free number; the maintainer renumbers. - For a user-visible change, also `man/tacctl.1` and the matching page under `docs/`. - Examples only from the table in `docs/development/README.md` (§ Examples). - No private names (hosts, addresses, users, home paths, domains) in files or commit messages. From d75d510a70d096ee314c472e650aeb0ffe4b64f6 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:39:19 -0900 Subject: [PATCH 11/52] docs/development: state the gates plainly, document make doctor The Gates rule read awkwardly after an earlier edit. It now says what runs per feature (make lint, the static checks, make gate-go) and per release (make gate-ci), then continues unchanged. The project-structure listing notes that tests/tools/doctor.sh is make doctor. --- docs/development/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/development/README.md b/docs/development/README.md index fb730b4d..b5bdfed1 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -36,6 +36,7 @@ tacctl/ # hosts # verify a release binary), radius-notes.md, release notes, plans/ tests/ # Go and bats suites, containers (tests/README.md) + # tests/tools/doctor.sh is `make doctor` (checks the checkout's tools) AGENTS.md # instructions for agents and contributors CONTRIBUTING.md # branches, pull requests CHANGELOG.md @@ -85,10 +86,12 @@ tacctl/ descriptions. - No secret, hash, password or community string in any log line, test golden or doc example. -- Gates. The declared gates are `make lint` (shellcheck, gofmt, `go vet`, - golangci-lint and the repository's own static checks) and `make gate-go` - for each feature, and `make gate-ci` for each release. The checks are: - build, gofmt, `go vet`, `make lint`, Go tests (`make gate-go`, +- Gates. For each feature: `make lint` (shellcheck, gofmt, `go vet`, + golangci-lint and the repository's own static checks), the static checks + (gofmt, `go vet` with and without `-tags testknobs`, and + `tests/tools/go-test-shard.sh --check 2`) and `make gate-go`. For each + release: `make gate-ci`. The checks are: build, gofmt, `go vet`, + `make lint`, Go tests (`make gate-go`, which runs `internal/cli` under `setsid` with no stdin and ends with one `GATE-GO PASS|FAIL` line: start it with the Bash tool's `run_in_background`, never with a trailing `&` or a `pgrep -f` wait, and From 76e1b449c0e457211e8b1f3800b2629b4a687a61 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:39:19 -0900 Subject: [PATCH 12/52] release-preflight: name the steps of docs/releasing.md that make the metadata The release metadata is made in step 2 (Start) and checked again before the assets in step 5 (Assets); the failure message said step 1. Nothing in tests or docs expects the old text. --- tests/tools/release-preflight.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools/release-preflight.sh b/tests/tools/release-preflight.sh index 6b8bf211..c6948f29 100755 --- a/tests/tools/release-preflight.sh +++ b/tests/tools/release-preflight.sh @@ -67,7 +67,7 @@ fi || fail "docs/release-notes-${tag}.md is missing or empty" if [[ $bad -ne 0 ]]; then - echo "release-preflight: the release metadata of ${tag} is not ready (docs/releasing.md, step 1)" >&2 + echo "release-preflight: the release metadata of ${tag} is not ready (docs/releasing.md, steps 2 and 5)" >&2 exit 1 fi echo "Release metadata of ${tag} in place (CHANGELOG ${date}, man page, release notes)." From 8836bfc0bf4d01df4d4eccb277c011f9cd41c676 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:50:39 -0900 Subject: [PATCH 13/52] releasing: the assets and the signature live in the worktree of release assets The assets verb builds the files in a clean detached worktree of the tag under qargi's state directory and prints its path; it never touches the repository's own dist/release. The sign verb is what the key holder runs in their own terminal: it runs ssh-keygen -Y sign and make release-verify in that worktree and records the result, which the publish verb waits for. Step 5 now says where the files are, and step 6 leads with the sign verb. The raw ssh-keygen and make release-verify lines stay, as what it runs and what to run by hand in a checkout of the tag after make release-assets. --- docs/releasing.md | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/releasing.md b/docs/releasing.md index c49a6139..3fca9c31 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -127,8 +127,8 @@ proof holds. | 2 | start | the maintainer's tooling, on the maintainer's go-ahead | `release/0.2.1` exists, its first commit dates the release | | 3 | push | the maintainer's tooling | the checks of the pull request into `master` are green | | 4 | finish | the maintainer's tooling, on the maintainer's go-ahead | `git describe master` prints `0.2.1`; `master`, `develop` and the tag are pushed | -| 5 | assets | the maintainer's tooling | `dist/release` holds the two binaries and `SHA256SUMS` | -| 6 | sign | the key holder only | `make release-verify` passes | +| 5 | assets | the maintainer's tooling | the worktree that `release assets` prints holds the two binaries and `SHA256SUMS` | +| 6 | sign | the key holder only | `release sign` records that `make release-verify` passed | | 7 | publish | the maintainer's tooling | the GitHub release holds the four files | | 8 | reproducible | the maintainer's tooling | the `release-reproducible` run of the tag is green | | 9 | check on a host | the maintainer | `tacctl upgrade` installs the verified binary | @@ -201,10 +201,14 @@ source (`could not download SHA256SUMS`). qargi release assets 0.2.1 ``` -Builds `dist/release/tacctl-0.2.1-linux-amd64`, -`dist/release/tacctl-0.2.1-linux-arm64` and `dist/release/SHA256SUMS` from the -tag, with `make release-assets` (by hand: `git checkout 0.2.1`, a clean -checkout of exactly the tag, then `make release-assets`). +Builds `tacctl-0.2.1-linux-amd64`, `tacctl-0.2.1-linux-arm64` and +`SHA256SUMS` from the tag, with `make release-assets`, in a clean detached +worktree of the tag under qargi's state directory. It prints the path of that +worktree; the files are in its `dist/release`, not in `dist/release` of the +repository's own checkout, which it never touches. The signing (step 6) and +the publish (step 7) take their files from the same worktree. By hand: +`git checkout 0.2.1`, a clean checkout of exactly the tag, then `make +release-assets`, and the files are in that checkout's `dist/release`. `make release-assets` refuses a tree that is not at a release tag or has local changes, and one whose release metadata is not in place @@ -223,6 +227,21 @@ Only the key holder signs, on the release manager's own machine, and types the passphrase; nobody else handles the passphrase or the private key. The release waits for the key holder here. +```sh +qargi release sign 0.2.1 +``` + +The key holder runs it, in their own terminal; it refuses without a terminal. +In the worktree that `release assets` printed (step 5) it runs the two +commands below: `ssh-keygen -Y sign -f -n tacctl-release ` for +each file to sign, so that the passphrase is typed on the terminal and never +passes through qargi, a log or an agent, and then `make release-verify`. It +records the result, and `release publish` (step 7) waits for that recorded +ok. + +What it runs, and what to run by hand in a checkout of the tag after `make +release-assets`: + ```sh ssh-keygen -Y sign -f ~/.ssh/tacctl-release -n tacctl-release dist/release/SHA256SUMS make release-verify From 29cc8c9c8af1800cd4327b2275ebdd7356fa0bbb Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:51:05 -0900 Subject: [PATCH 14/52] releasing: check the release metadata before the tag is pushed The dated CHANGELOG heading, the .TH date and version and the release notes are checked by tests/tools/release-preflight.sh, which make release-assets runs, but only after the finish has pushed the tag, and a pushed tag is final. The start runs only release-notes-check.sh, which accepts an (unreleased) heading, and neither the gate nor the pull request checks look at the metadata. Step 4 now runs the preflight on the release branch before the finish, and the paragraph that claimed the gate, the start and the checks covered it says what covers it. --- docs/releasing.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/releasing.md b/docs/releasing.md index 3fca9c31..15e4cfbe 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -177,6 +177,24 @@ green before the finish. ### 4. Finish +First, in a checkout of the release branch (`release/0.2.1`, at the commit the +pull request checks ran on), check the release metadata: + +```sh +tests/tools/release-preflight.sh 0.2.1 +``` + +Finish only when it passes. It lists every problem: the dated +`## 0.2.1 (YYYY-MM-DD)` CHANGELOG heading (a real date, and no +`(unreleased)` one), the `.TH` line of `man/tacctl.1` naming `tacctl 0.2.1` +and the same date, and `docs/release-notes-0.2.1.md`. Nothing else before +the finish checks this: `release start` runs only +`tests/tools/release-notes-check.sh`, which accepts an `(unreleased)` +heading, and `make release-assets` runs the preflight only in step 5, after +the finish has pushed the tag, when a fault is no longer fixable in this +release. A second argument names another tree to check instead of this +repository. + ```sh qargi release finish 0.2.1 ``` @@ -190,8 +208,11 @@ merges the release into `develop`, deletes the release branch, and pushes The GitHub repository refuses force pushes and deletion of `master` and `develop` and any move or deletion of a `0.*` tag: a pushed tag is final, so a fault found after the finish is fixed in the next release (or a hotfix), -never by moving the tag. That is why the gate of step 1, the preflight of -step 2 and the checks of step 3 come before it. A host that upgrades between +never by moving the tag. That is why the gate of step 1, the checks of +step 3 and the preflight above come before it; the gate and the checks of +the pull request do not look at the release metadata (the dated heading, the +`.TH` line, the notes), so the preflight above is the only check of it +before the tag. A host that upgrades between the finish and the publish (step 7) finds no release binary and builds from source (`could not download SHA256SUMS`). From 5fd4295547fdfcc159b6145abf28a33ee28c19fa Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:51:24 -0900 Subject: [PATCH 15/52] releasing: the hotfix is cut by hand, the tooling takes over at the push The start verb with --hotfix checks, before changing anything, that the CHANGELOG has content under its unreleased heading and runs the stored preflight (release-notes-check.sh), which wants the release notes, a numbered section of the version and rollbackFrom equal to it. On master none of that exists before the hotfix branch does, so the start is refused. The section said to run it and to date the heading by hand, which also contradicted step 2. It now says the start is refused for this project, cuts hotfix/VERSION by hand, lists what the branch commits (the fix, the dated CHANGELOG section, the notes, rollbackFrom, the .TH line), runs both checks, and uses the push and finish verbs. It also says the route has not been exercised with the tooling yet. --- docs/releasing.md | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/docs/releasing.md b/docs/releasing.md index 15e4cfbe..5261bd11 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -424,22 +424,46 @@ branches, local and remote), as a plan like the others. ## A hotfix A fix that cannot wait for the next release starts from `master`, not from -`develop`: +`develop`. `qargi release start 0.2.6 --hotfix` is the tooling's way to cut +`hotfix/0.2.6` from `master`, but it is refused for this project at present: +before it changes anything it needs content under the CHANGELOG's unreleased +heading and runs the stored preflight +(`tests/tools/release-notes-check.sh 0.2.6`, which wants +`docs/release-notes-0.2.6.md`, a numbered `## 0.2.6 (` section and `const +rollbackFrom` equal to `0.2.6`), and on `master` none of that exists before +the hotfix branch does (`release.preflight failed ... nothing was changed`). +So cut the branch by hand, and use the tooling from the push on: ```sh -qargi release start 0.2.6 --hotfix -# the fix and its CHANGELOG section (## 0.2.6 (unreleased), numbering from 1, -# the items that differ from the release it fixes) and the release notes +git checkout master && git pull +git flow hotfix start 0.2.6 # the branch is hotfix/0.2.6 +``` + +Commit on that branch: + +- the fix; +- its CHANGELOG section, `## 0.2.6 (YYYY-MM-DD)`, dated now because `start` + is not there to date it, numbered from 1, with the items that differ from + the release it fixes; +- `docs/release-notes-0.2.6.md`; +- `const rollbackFrom` in `internal/cli/rollback.go` set to `0.2.6`; +- the `.TH` line of `man/tacctl.1` with the same date and `tacctl 0.2.6` (the + `sed` of the by-hand section below). + +Then check it, push it and finish it with the tooling: + +```sh +tests/tools/release-preflight.sh 0.2.6 +tests/tools/release-notes-check.sh 0.2.6 qargi release push 0.2.6 qargi release finish 0.2.6 --hotfix ``` -`start` makes `hotfix/0.2.6` from `master`; `finish` tags `master` and merges -the fix back into the release branch when one is open, else into `develop`. -Everything else is as for a release: the same plans and go-aheads, the date -and version in `man/tacctl.1` and the CHANGELOG heading before the finish, -and the after-steps 5 to 11 above (assets, sign, publish, reproducible, -check on a host, site, prune). +`finish` tags `master` and merges the fix back into the release branch when +one is open, else into `develop`. Everything else is as for a release: the +same plans and go-aheads, and the after-steps 5 to 11 above (assets, sign, +publish, reproducible, check on a host, site, prune). This route has not +been exercised with the tooling yet, so read each plan before approving it. ## If the release tooling is unavailable (by hand) From c644f0e5926592810e22862fe34433d9defd48d0 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:52:00 -0900 Subject: [PATCH 16/52] releasing: accuracy fixes to the recorded steps, the go-aheads and the by-hand route The text said every after-step is recorded with the step verb, but the check on a host (step 9) is not one of them: the recorded ones are exactly assets, sign, publish, reproducible, site and prune. It now says so. The intro said all of the tooling's commands are plans. Only start, push, finish, publish and prune print one; verify, assets and step print none. Push, publish and prune also need the maintainer's go-ahead (publish and finish take a plan token, push opens the pull request, prune deletes branches); the table and the step texts now say so. The by-hand route starts with the gate and the notes check, runs the preflight before the finish, says the .TH line must carry the same date and version as the CHANGELOG heading (the note of the earlier text), and its tail now runs to step 11 and not 10. --- docs/releasing.md | 62 +++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/docs/releasing.md b/docs/releasing.md index 5261bd11..a6868cd9 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -72,13 +72,17 @@ their own tree lists. The example is 0.2.1 (the release before it 0.2.0); replace it throughout. A release runs with qargi, the git-flow release tooling the maintainer -uses. Its commands are plans: each prints what it will do before anything is -applied. The division of labour is fixed. The maintainer's tooling drives the -git-flow steps (verify, start, push, finish) and the after-steps that build, -publish and clean up; the key holder alone signs; and every merge into -`develop` or `master`, every push and every tag is a plan that needs the -maintainer's explicit go-ahead. The hand commands are kept at the end, for a -release made without the tooling. +uses. The commands that change something (`release start`, `push`, `finish` +and `publish`, and `branch prune`) are plans: each prints what it will do +before anything is applied. `release verify`, `release assets` and `release +step` print no plan. The division of labour is fixed. The maintainer's +tooling drives the git-flow steps (verify, start, push, finish) and the +after-steps that build, publish and clean up; the key holder alone signs; and +every merge into `develop` or `master`, every push, every tag, every publish +and every prune is a plan that needs the maintainer's explicit go-ahead +(`start`, `finish` and `publish` also take a plan token; `push` opens the +pull request; `prune` deletes branches). The hand commands are kept at the end, +for a release made without the tooling. Before the first step, bring the tacquito fork's `main` up to upstream (`patches/README.md`, Following upstream) and run the gates on it: a host @@ -118,22 +122,24 @@ Also before the first step, on `develop`: (step 7) uses them as the release's text. The steps, in order. The first four are the git-flow steps; the rest are the -after-steps, each recorded with `qargi release step 0.2.1 ` once its -proof holds. +after-steps. Six of them are recorded with `qargi release step 0.2.1 ` +once their proof holds, and they are exactly these: `assets`, `sign`, +`publish`, `reproducible`, `site` and `prune`. Step 9, the check on a host, is +not one of them: it is the maintainer's own check, and nothing records it. | # | Step | Who | What proves it | |---|---|---|---| | 1 | verify | the maintainer's tooling | a passing release gate at the head of `develop` | | 2 | start | the maintainer's tooling, on the maintainer's go-ahead | `release/0.2.1` exists, its first commit dates the release | -| 3 | push | the maintainer's tooling | the checks of the pull request into `master` are green | +| 3 | push | the maintainer's tooling, on the maintainer's go-ahead | the checks of the pull request into `master` are green | | 4 | finish | the maintainer's tooling, on the maintainer's go-ahead | `git describe master` prints `0.2.1`; `master`, `develop` and the tag are pushed | | 5 | assets | the maintainer's tooling | the worktree that `release assets` prints holds the two binaries and `SHA256SUMS` | | 6 | sign | the key holder only | `release sign` records that `make release-verify` passed | -| 7 | publish | the maintainer's tooling | the GitHub release holds the four files | +| 7 | publish | the maintainer's tooling, on the maintainer's go-ahead | the GitHub release holds the four files | | 8 | reproducible | the maintainer's tooling | the `release-reproducible` run of the tag is green | -| 9 | check on a host | the maintainer | `tacctl upgrade` installs the verified binary | +| 9 | check on a host | the maintainer, not recorded | `tacctl upgrade` installs the verified binary | | 10 | site | the maintainer's tooling | the `build` check of the `gh-pages` pull request is green, then it is merged | -| 11 | prune | the maintainer's tooling | no merged branch is left, local or remote | +| 11 | prune | the maintainer's tooling, on the maintainer's go-ahead | no merged branch is left, local or remote | ### 1. Verify @@ -168,7 +174,8 @@ There is no `VERSION` file: the version is the CHANGELOG heading, the tag and qargi release push 0.2.1 ``` -Pushes the release branch and opens the pull request into `master`, so that +A plan, on the maintainer's go-ahead. Pushes the release branch and opens the +pull request into `master`, so that the `test` workflow runs on the release commit (the date changes and the notes) before the tag exists; the workflow runs on a pull request and on a push to `develop`, not on a push to `master`, whose files are the same as @@ -296,9 +303,9 @@ make release-verify ALLOWED_SIGNERS=/tmp/trial-signers qargi release publish 0.2.1 --notes-file docs/release-notes-0.2.1.md ``` -Creates the GitHub release of the tag with the four assets (the two -binaries, `SHA256SUMS` and `SHA256SUMS.sig`) in one step, and the release -notes as its text. All four go together: the `release-reproducible` workflow +A plan, a token and the maintainer's go-ahead. Creates the GitHub release of +the tag with the four assets (the two binaries, `SHA256SUMS` and +`SHA256SUMS.sig`) in one step, and the release notes as its text. All four go together: the `release-reproducible` workflow starts on the publish and needs the signed sums. A release's title is always `tacctl ` (`tacctl 0.2.1`), never the bare @@ -418,8 +425,8 @@ passed. qargi branch prune ``` -Deletes the branches that are merged (the release's feature and agent -branches, local and remote), as a plan like the others. +A plan, on the maintainer's go-ahead, since it deletes branches: the ones +that are merged (the release's feature and agent branches, local and remote). ## A hotfix @@ -467,7 +474,15 @@ been exercised with the tooling yet, so read each plan before approving it. ## If the release tooling is unavailable (by hand) -A release can be made without qargi. The git-flow steps 2 to 4 by hand: +A release can be made without qargi. First the gate (step 1) and the notes +check, on `develop`: + +```sh +GATE_TMPFS=1 make gate-ci +tests/tools/release-notes-check.sh 0.2.1 +``` + +Then the git-flow steps 2 to 4 by hand: ```sh git checkout develop && git pull @@ -480,11 +495,16 @@ git commit -am "docs: 0.2.1 release date" git push -u origin release/0.2.1 gh pr create --base master --head release/0.2.1 --title "0.2.1" --body "Release 0.2.1" gh pr checks --watch # the Go tests on the release commit; all green before the tag +tests/tools/release-preflight.sh 0.2.1 # the release metadata (step 4); finish only when it passes git flow release finish -m "Release 0.2.1" 0.2.1 git tag -f -a 0.2.1 -m "Release 0.2.1" master # git-flow writes "Release 0.2.1 0.2.1" git describe master # 0.2.1 ``` +The `sed` of `man/tacctl.1` sets the date and the version of its `.TH` line, +which must carry the same date and version as the CHANGELOG heading +(`tests/tools/release-preflight.sh` checks that they match). + The tag is made and checked locally (`git tag -f`) and pushed once, with the signed assets already built from it, because a pushed tag is final. Build the assets from the tag and sign them (steps 5 and 6), then push and @@ -501,7 +521,7 @@ gh release create 0.2.1 --verify-tag --title "tacctl 0.2.1" \ The pull request closes by itself when `master` is pushed; delete the remote branch then: `git push origin --delete release/0.2.1`. Then steps 8 -to 10 as above. A host that upgrades between the push and the upload simply +to 11 as above. A host that upgrades between the push and the upload simply builds from source (`could not download SHA256SUMS`). A hotfix by hand: `git flow hotfix start 0.2.6` (the branch is From 85daea7ea39274ae8baed380eb07da60f8a6c517 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:50:24 -0900 Subject: [PATCH 17/52] doctor: run go version with GOTOOLCHAIN=local With GOTOOLCHAIN=auto and a go.mod newer than the local Go, go version run from the repository root may download a toolchain. Pin it to the local binary, as tests/tools/release-stamps.sh and bin/tacctl.sh do, so the doctor reports the version of the Go it found and never uses the network. It is the only go call the script makes. --- tests/tools/doctor.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools/doctor.sh b/tests/tools/doctor.sh index 3eb7b36f..66c24f6e 100755 --- a/tests/tools/doctor.sh +++ b/tests/tools/doctor.sh @@ -61,7 +61,7 @@ if [[ -z "$go_pin" ]]; then elif ! go_path=$(command -v "$GO" 2> /dev/null); then missing go "$GO does not exist: $go_fix" else - go_have=$("$go_path" version 2> /dev/null | awk '{print $3}') + go_have=$(GOTOOLCHAIN=local "$go_path" version 2> /dev/null | awk '{print $3}') go_have="${go_have#go}" # bin/tacctl.sh installs Go only when it is missing or older and never # replaces a newer one, so a Go equal to the pin or newer is fine. From 3c960836adfbc94ca49ba3e9cd8174c50e6d9b04 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:50:37 -0900 Subject: [PATCH 18/52] doctor: do not abort when HOME is unset set -u made the script stop with 'HOME: unbound variable' when HOME was unset, at the golangci-lint candidates and at the private-patterns path. Use ${HOME:-}: the two home candidates for golangci-lint are skipped, and the private-patterns item says that no path can be derived. --- tests/tools/doctor.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/tools/doctor.sh b/tests/tools/doctor.sh index 66c24f6e..de08462c 100755 --- a/tests/tools/doctor.sh +++ b/tests/tools/doctor.sh @@ -97,9 +97,12 @@ if [[ -n "${GOLANGCI_LINT:-}" ]]; then lint="$GOLANGCI_LINT" else lint=$(command -v golangci-lint 2> /dev/null) - for cand in "$HOME/go/bin/golangci-lint" "$HOME/.local/bin/golangci-lint"; do - [[ -n "$lint" || ! -x "$cand" ]] || lint="$cand" - done + # The home candidates need HOME; without it they are skipped. + if [[ -n "${HOME:-}" ]]; then + for cand in "$HOME/go/bin/golangci-lint" "$HOME/.local/bin/golangci-lint"; do + [[ -n "$lint" || ! -x "$cand" ]] || lint="$cand" + done + fi fi if [[ -z "$lint_pin" ]]; then missing golangci-lint "no GOLANGCI_LINT_VERSION in the Makefile, so the pinned version cannot be known" @@ -191,8 +194,11 @@ if [[ $EUID -eq 0 || -n "${SUDO_USER:-}" ]]; then else ok user "an ordinary user (uid $EUID), as bats needs (tests/README.md)" fi -patterns="${TACCTL_PRIVATE_PATTERNS:-$HOME/.config/tacctl/private-patterns}" -if [[ -f "$patterns" ]]; then +patterns="${TACCTL_PRIVATE_PATTERNS:-}" +[[ -n "$patterns" || -z "${HOME:-}" ]] || patterns="$HOME/.config/tacctl/private-patterns" +if [[ -z "$patterns" ]]; then + expected private-patterns "HOME is not set and TACCTL_PRIVATE_PATTERNS is empty; tests/tools/no-private.sh then checks only its built-in patterns" +elif [[ -f "$patterns" ]]; then ok private-patterns "$patterns" else expected private-patterns "$patterns is absent; tests/tools/no-private.sh then checks only its built-in patterns" From 332a165a4ba3769ec68c080ce557b310155c988d Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:51:11 -0900 Subject: [PATCH 19/52] doctor: look a gofmt without a slash up in PATH -x "$gofmt" tests a path, so GO=go GOFMT=gofmt was reported missing although make runs gofmt from PATH. A value without a slash is now resolved with command -v; one with a slash is still tested as a path. When GOFMT is unset, the default is the gofmt beside the go the script resolved (go itself was already resolved with command -v). --- tests/tools/doctor.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/tools/doctor.sh b/tests/tools/doctor.sh index de08462c..b86e4343 100755 --- a/tests/tools/doctor.sh +++ b/tests/tools/doctor.sh @@ -77,9 +77,17 @@ else fi # --- 2. gofmt beside that go, and a C compiler (cgo, the race detector) ------- -gofmt="${GOFMT:-$(dirname "$GO")/gofmt}" -if [[ -x "$gofmt" ]]; then - ok gofmt "$gofmt" +# A value with a slash is a path; one without is looked up in PATH, as make +# does when it runs it. +gofmt="${GOFMT:-$(dirname "${go_path:-${GO:-go}}")/gofmt}" +if [[ "$gofmt" == */* ]]; then + gofmt_path="" + [[ ! -x "$gofmt" ]] || gofmt_path="$gofmt" +else + gofmt_path=$(command -v "$gofmt" 2> /dev/null) +fi +if [[ -n "$gofmt_path" ]]; then + ok gofmt "$gofmt_path" else missing gofmt "$gofmt does not exist; it comes with the Go toolchain (see go)" fi From 060d51542969426ae5a18c44e12b96137e1433af Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:51:27 -0900 Subject: [PATCH 20/52] doctor: no hard-coded Go path when the Makefile has none When the GO ?= line of the Makefile could not be parsed, the script fell back to /usr/local/go/bin/go, a copy of a pin it promises to read. Fall back to the go in PATH instead; when there is none, report 'missing go' with the usual fix line. The gofmt default then looks gofmt up in PATH. --- tests/tools/doctor.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/tools/doctor.sh b/tests/tools/doctor.sh index b86e4343..cd053e52 100755 --- a/tests/tools/doctor.sh +++ b/tests/tools/doctor.sh @@ -54,10 +54,12 @@ have_tool() { # --- 1. Go: the Makefile's GO, at the version bin/tacctl.sh pins or newer ----- go_pin=$(sed -n 's/^GO_VERSION="\([0-9.]*\)"$/\1/p' "$root/bin/tacctl.sh" 2> /dev/null) GO="${GO:-$(sed -n 's/^GO ?= *//p' "$root/Makefile" 2> /dev/null | head -n 1)}" -GO="${GO:-/usr/local/go/bin/go}" +GO="${GO:-$(command -v go 2> /dev/null)}" go_fix="run bin/tacctl.sh as root (it installs the pinned Go ${go_pin:-?} in /usr/local/go; --build only uses it), or set GO=" if [[ -z "$go_pin" ]]; then missing go "no GO_VERSION in bin/tacctl.sh, so the pinned Go cannot be known" +elif [[ -z "$GO" ]]; then + missing go "no GO ?= line in the Makefile and no go in PATH: $go_fix" elif ! go_path=$(command -v "$GO" 2> /dev/null); then missing go "$GO does not exist: $go_fix" else @@ -79,7 +81,10 @@ fi # --- 2. gofmt beside that go, and a C compiler (cgo, the race detector) ------- # A value with a slash is a path; one without is looked up in PATH, as make # does when it runs it. -gofmt="${GOFMT:-$(dirname "${go_path:-${GO:-go}}")/gofmt}" +gofmt="${GOFMT:-}" +if [[ -z "$gofmt" ]]; then + if [[ -n "${go_path:-}" ]]; then gofmt="$(dirname "$go_path")/gofmt"; else gofmt=gofmt; fi +fi if [[ "$gofmt" == */* ]]; then gofmt_path="" [[ ! -x "$gofmt" ]] || gofmt_path="$gofmt" From c30b4e0b251f020ea46ed337da37e06b8f4643f4 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:52:03 -0900 Subject: [PATCH 21/52] doctor: check git itself before the tag Without git, or outside a work tree, the tag item said 'missing tag-0.2.2 ... git fetch --tags', a fix that cannot run. Add a git item (ok with the version, missing with the install hint) before it. When git is there but the root is not a work tree, or git is missing, the tag item is 'expected' and says the tag cannot be checked. --- tests/tools/doctor.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/tools/doctor.sh b/tests/tools/doctor.sh index cd053e52..e8f1137e 100755 --- a/tests/tools/doctor.sh +++ b/tests/tools/doctor.sh @@ -164,8 +164,19 @@ else missing bats "not initialised:$bats_bad; run make bootstrap (git submodule update --init --recursive)" fi -# --- 7. the 0.2.2 tag: two Go tests skip without it --------------------------- -if git -C "$root" rev-parse -q --verify refs/tags/0.2.2 > /dev/null 2>&1; then +# --- 7. git, and the 0.2.2 tag: two Go tests skip without it ----------------- +have_git=0 +if command -v git > /dev/null 2>&1; then + ok git "$(first_line git --version)" + have_git=1 +else + missing git "$(apt_hint git git)" +fi +if [[ $have_git -eq 0 ]]; then + expected tag-0.2.2 "git is missing, so the tag cannot be checked" +elif ! git -C "$root" rev-parse --is-inside-work-tree > /dev/null 2>&1; then + expected tag-0.2.2 "not a git checkout, so the tag cannot be checked" +elif git -C "$root" rev-parse -q --verify refs/tags/0.2.2 > /dev/null 2>&1; then ok tag-0.2.2 "present" else missing tag-0.2.2 "two Go tests skip without it (the rollback build, the 0.2.2 schema): git fetch --tags" From 989681786518378bd656c7ee6754cf737f2898c8 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:54:27 -0900 Subject: [PATCH 22/52] doctor: empty bats submodules are expected, not missing lint, gate-go and build do not need the bats submodules, and a member clone has them empty until make bootstrap, so reporting them 'missing' (exit 1) made the doctor fail every such clone although AGENTS.md has agents run it before the gates. The bats item is now 'expected' when they are not initialised ('only the bats suite needs them') and 'ok' when present. The header comment says what 'missing' and 'expected' mean. --- tests/tools/doctor.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/tools/doctor.sh b/tests/tools/doctor.sh index e8f1137e..b0b53b41 100755 --- a/tests/tools/doctor.sh +++ b/tests/tools/doctor.sh @@ -13,8 +13,9 @@ # 'missing' is a tool or file that make lint, make gate-go or make build needs, # or whose absence makes tests skip silently (the list in the comment at the # top of .github/workflows/test.yml); 'expected' is optional, with what you -# lose without it. The exit status is 1 when any line starts with 'missing', -# else 0. +# lose without it (the bats submodules, which only the bats suite needs, and +# so a fresh clone before make bootstrap, are 'expected'). The exit status is +# 1 when any line starts with 'missing', else 0. # # The pins are read where they live, never copied here: the Go version # (GO_VERSION) from bin/tacctl.sh, the golangci-lint version @@ -152,7 +153,7 @@ else fi have_tool ssh-keygen ssh-keygen "$(apt_hint openssh-client openssh)" -# --- 6. the bats submodules --------------------------------------------------- +# --- 6. the bats submodules: only the bats suite needs them ------------------- bats_bad="" [[ -x "$root/tests/bats/bats-core/bin/bats" ]] || bats_bad=" bats-core/bin/bats" for d in bats-support bats-assert bats-file; do @@ -161,7 +162,7 @@ done if [[ -z "$bats_bad" ]]; then ok bats "the four submodules under tests/bats are in place" else - missing bats "not initialised:$bats_bad; run make bootstrap (git submodule update --init --recursive)" + expected bats "not initialised:$bats_bad; only the bats suite needs them (make bootstrap)" fi # --- 7. git, and the 0.2.2 tag: two Go tests skip without it ----------------- From 29676859ad9cf50cb1afb2dddff8171abcfd97c2 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 17:54:40 -0900 Subject: [PATCH 23/52] AGENTS.md: say what the doctor prints, and what the gates are The doctor prints only ok, missing and expected lines and exits 1 when at least one is missing; the bullet named fail and error lines it never prints. Read first points again to two things, as CLAUDE.md did: the roadmap (backlog section 0) and the plan of the release in progress. The last line of Commands named 'the static checks' as if it were a make target; spell out what runs per feature and per release. --- AGENTS.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 90deaf19..c679cca1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,7 +6,8 @@ groups and scopes, network devices and enrolled Linux hosts. ## Read first - `docs/development/README.md`: working rules, the examples table. -- `docs/plans/backlog.md` §0: roadmap and the plan of the release in progress. +- `docs/plans/backlog.md` §0: the roadmap. +- The plan of the release in progress, under `docs/plans/`. - `CONTRIBUTING.md`: branches, pull requests. - `docs/releasing.md`: releases. @@ -14,7 +15,7 @@ groups and scopes, network devices and enrolled Linux hosts. - The Go version is `GO_VERSION` in `bin/tacctl.sh`; the linter pin is `GOLANGCI_LINT_VERSION` in the `Makefile`. - `make bootstrap` only initialises the bats submodules (`git submodule update --init --recursive`) and installs nothing else; preview it with `make -n bootstrap`. -- `make doctor` checks the checkout and prints one line per item: a line starting `missing`, `fail` or `error` is a problem, a line starting `expected` is a known accepted absence. Run it after pulling and before the gates. +- `make doctor` checks the checkout and prints one line per item: it prints only `ok`, `missing` and `expected` lines: `missing` is a problem, `expected` is a known accepted absence, and exit status 1 means at least one `missing`. Run it after pulling and before the gates. - Agents never install system packages themselves; the doctor prints the install line. - A new tool the project needs goes into `make doctor` and into this section in the same change. @@ -30,7 +31,7 @@ groups and scopes, network devices and enrolled Linux hosts. - Bats: `make build`, then as an ordinary user, neither root nor one with sudo (`tests/README.md`): `tests/bats/bats-core/bin/bats tests/integration/.bats` - Diff corpus: `tests/diff/run.sh --all --against ` - Containers (rootless podman): `tests/containers/run-all.sh` (the whole matrix, with a table) or one of `tests/containers/{hosts,radius,fresh}/run.sh` -- The whole-suite runs are gated as `make lint` and the static checks, then `make gate-go` per feature, and `make gate-ci` per release. +- The whole-suite runs are gated per feature with `make lint`, the static checks (`test -z "$(gofmt -l cmd internal)"`, `go vet ./...` and `go vet -tags testknobs ./...`, `tests/tools/go-test-shard.sh --check 2`) and `GATE_TMPFS=1 make gate-go`; per release with `GATE_TMPFS=1 make gate-ci`. ## Rules From 5244115d53240020decad81051862638eee0fad7 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 18:07:23 -0900 Subject: [PATCH 24/52] releasing: the hotfix pushes with --hotfix `qargi release push` takes --hotfix like `start` and `finish`: a hotfix branches from master and finishes into master and the open release branch (or develop). The hotfix block ran `qargi release push 0.2.6` without it. --- docs/releasing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/releasing.md b/docs/releasing.md index a6868cd9..4abb76c1 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -462,7 +462,7 @@ Then check it, push it and finish it with the tooling: ```sh tests/tools/release-preflight.sh 0.2.6 tests/tools/release-notes-check.sh 0.2.6 -qargi release push 0.2.6 +qargi release push 0.2.6 --hotfix qargi release finish 0.2.6 --hotfix ``` From a31e2ee24d456c7916d1ebce71a4eca7e9bb3479 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 18:07:37 -0900 Subject: [PATCH 25/52] releasing: every plan takes a token, the sign step prints none Besides start, finish and publish, `release push` and `branch prune` print a plan and take --plan and --approved. `release verify`, `assets`, `step` and `sign` print no plan; sign is run by the key holder on their own terminal. --- docs/releasing.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/releasing.md b/docs/releasing.md index 4abb76c1..1347be8a 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -74,15 +74,17 @@ The example is 0.2.1 (the release before it 0.2.0); replace it throughout. A release runs with qargi, the git-flow release tooling the maintainer uses. The commands that change something (`release start`, `push`, `finish` and `publish`, and `branch prune`) are plans: each prints what it will do -before anything is applied. `release verify`, `release assets` and `release -step` print no plan. The division of labour is fixed. The maintainer's +before anything is applied. `release verify`, `release assets`, `release +step` and `release sign` print no plan (`sign` is run by the key holder on +their own terminal). The division of labour is fixed. The maintainer's tooling drives the git-flow steps (verify, start, push, finish) and the after-steps that build, publish and clean up; the key holder alone signs; and every merge into `develop` or `master`, every push, every tag, every publish and every prune is a plan that needs the maintainer's explicit go-ahead -(`start`, `finish` and `publish` also take a plan token; `push` opens the -pull request; `prune` deletes branches). The hand commands are kept at the end, -for a release made without the tooling. +(`start`, `push`, `finish`, `publish` and `prune` each print a plan and take +a plan token with `--plan` and the go-ahead with `--approved`; `push` opens +the pull request; `prune` deletes branches). The hand commands are kept at +the end, for a release made without the tooling. Before the first step, bring the tacquito fork's `main` up to upstream (`patches/README.md`, Following upstream) and run the gates on it: a host From 41cab457b2412e96a5eacd272b9037aed42f753d Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 18:07:58 -0900 Subject: [PATCH 26/52] releasing: the prune step says local first, origin with --remote Without --remote the prune deletes only the merged local agent/* and feature/* branches; --remote also deletes them on origin. Step 11 now shows both forms and the step table's proof says the same. --- docs/releasing.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/releasing.md b/docs/releasing.md index 1347be8a..f5691fd7 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -141,7 +141,7 @@ not one of them: it is the maintainer's own check, and nothing records it. | 8 | reproducible | the maintainer's tooling | the `release-reproducible` run of the tag is green | | 9 | check on a host | the maintainer, not recorded | `tacctl upgrade` installs the verified binary | | 10 | site | the maintainer's tooling | the `build` check of the `gh-pages` pull request is green, then it is merged | -| 11 | prune | the maintainer's tooling, on the maintainer's go-ahead | no merged branch is left, local or remote | +| 11 | prune | the maintainer's tooling, on the maintainer's go-ahead | no merged `agent/*` or `feature/*` branch is left locally and, if pruned with `--remote`, on origin | ### 1. Verify @@ -425,10 +425,13 @@ passed. ```sh qargi branch prune +qargi branch prune --remote ``` A plan, on the maintainer's go-ahead, since it deletes branches: the ones -that are merged (the release's feature and agent branches, local and remote). +that are merged (the release's `feature/*` and `agent/*` branches). Without +`--remote` it deletes only the local ones; run the second form, with its own +plan and go-ahead, when the branches on origin are meant to go too. ## A hotfix From 71ce4ebb109cbaa62f2440a4badf7439edc105ca Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 18:08:10 -0900 Subject: [PATCH 27/52] releasing: say which release metadata checks exist before the finish "Nothing else before the finish checks this" overstated it: release start checks that the man page .TH line exists and release finish refuses an empty .TH date or version. Only tests/tools/release-preflight.sh checks the dated heading, that the date and version match, and the notes, so the text says to run it before the finish. --- docs/releasing.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/releasing.md b/docs/releasing.md index f5691fd7..fd112235 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -196,12 +196,14 @@ tests/tools/release-preflight.sh 0.2.1 Finish only when it passes. It lists every problem: the dated `## 0.2.1 (YYYY-MM-DD)` CHANGELOG heading (a real date, and no `(unreleased)` one), the `.TH` line of `man/tacctl.1` naming `tacctl 0.2.1` -and the same date, and `docs/release-notes-0.2.1.md`. Nothing else before -the finish checks this: `release start` runs only -`tests/tools/release-notes-check.sh`, which accepts an `(unreleased)` -heading, and `make release-assets` runs the preflight only in step 5, after -the finish has pushed the tag, when a fault is no longer fixable in this -release. A second argument names another tree to check instead of this +and the same date, and `docs/release-notes-0.2.1.md`. Little else before +the finish checks this: `release start` only checks that the man page's +`.TH` line exists and runs `tests/tools/release-notes-check.sh`, which +accepts an `(unreleased)` heading, and `release finish` refuses an empty +`.TH` date or version. Only the preflight checks the dated heading, that the +date and the version match, and the notes, so run it before the finish. +`make release-assets` runs it only in step 5, after the finish has pushed the +tag, when a fault is no longer fixable in this release. A second argument names another tree to check instead of this repository. ```sh From bcb123f4d13701f210747b19d17d72324417b195 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 18:51:34 -0900 Subject: [PATCH 28/52] sftpd: an upload creates the file with the mode the client asks for The open request of a new upload carries the permissions of the file in the OpenSSH sftp and scp clients (scp of OpenSSH 9 speaks SFTP and sets nothing afterwards), but the console opened every file with 0644, so a script lost its execute bit. The library does not deliver the attribute flags of an open request to the handlers: Request.Flags of an open is the open flags, so AttrFlags and Attributes read the wrong thing. A block of exactly four bytes can only be the permissions, so that is the case that is read; any other length asks for nothing and keeps 0644, as before. The permission bits are masked to 0777 through the same helper that mkdir and setstat use, and the umask of the console (077) still applies: 0755 gives 0700, 0644 gives 0600. A file that exists keeps its mode, and a download changes nothing. Tests send open requests by hand, since the client library never puts attributes in one. docs/cli/console.md, the manual page and the changelog say so. --- CHANGELOG.md | 21 +++ docs/cli/console.md | 2 +- internal/sftpd/file.go | 31 +++- internal/sftpd/handlers.go | 4 +- internal/sftpd/openmode_test.go | 248 ++++++++++++++++++++++++++++++++ man/tacctl.1 | 14 +- 6 files changed, 314 insertions(+), 6 deletions(-) create mode 100644 internal/sftpd/openmode_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 353fc633..ebf6de5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,27 @@ All notable changes to tacctl. The README and the manual page describe only the current behaviour; this file is where history lives. +## 0.2.29 (unreleased) + +1. **A file uploaded through the console keeps the owner's execute bit.** The + console's file transfer gave every new file the mode 0644 and ignored the + mode in the request that opens it, so a script copied with the `scp` of + OpenSSH 9 or later (which speaks SFTP and sends the permissions in that + request, and sets nothing afterwards) lost its execute bit. A new file now + gets the mode the client asks for in the open request when the request + carries the permissions alone, which is what the OpenSSH `sftp` and `scp` + send: the permission bits only (set-user-ID, set-group-ID and sticky are + ignored, as for a new directory), reduced by the umask of the console, 077. + The owner's bits survive and the group and other bits go: a script asked + at 0755 is 0700, a file asked at 0644 is 0600. A request without + permissions still gives 0644, 0600 after the umask. A file that already + exists keeps its mode, and a download changes nothing. A request that + carries other attributes together with the permissions (for example the + times, as with the preserve option of `scp`) is read as carrying none, + because the library does not tell which attributes a request holds; such + a file gets 0644, 0600 after the umask, as before. `docs/cli/console.md` + and the manual page say so. + ## 0.2.28 (2026-11-09) 1. **A support bundle from a Cisco IOS device no longer starts the identity diff --git a/docs/cli/console.md b/docs/cli/console.md index 43b1a220..74ce667f 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -220,7 +220,7 @@ Every form of `console file-transfer` is the superuser's, the reads included (`c **What a user can do.** `sftp alice@tacacs.example.net` and the `scp` of OpenSSH 9 or later (which speaks SFTP unless it is given `-O`) work for an account that has file transfer. `scp -O` (the old protocol), `rsync`, any program and the shell's words are refused, as before, with `the tacctl console does not run programs or shell commands; file transfer is SFTP only (sftp, scp of OpenSSH 9 or later)` (exit 126). For an account that does not have file transfer the subsystem is refused with `file transfer is not enabled for this account; an administrator can switch it on (tacctl console file-transfer)` (exit 126), and so is the subsystem of a user held to a required password change. The console serves the protocol as the logged-in user, with no change of privilege, so the file system's permissions apply as they do in the user's shell. An account that does not have file transfer sees only `Connection closed` from `sftp` and `scp` (sshd does not show the error text of a subsystem; `ssh id`, a command request, does): the reason, `reason=file-transfer` with status 126, is in the console's audit log, and `console show` lists who has file transfer. -**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode the client asks for and a new file 0644, both reduced by the umask of the console, 077 (so a directory is 0700 and a file 0600); the set-user-ID, set-group-ID and sticky bits are ignored, and a client that wants another mode sets it afterwards, which is applied as given. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. +**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode the client asks for. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none); a file that already exists keeps its mode, whatever the open asks. Both are reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is 0700. The set-user-ID, set-group-ID and sticky bits are ignored, and a client that wants another mode sets it afterwards, which is applied as given. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. **The quota and the rate.** The quota is the bytes the home may hold. It counts the sizes of the regular files in it, each inode once (a file with two names counts once): the reports and support bundles tacctl wrote there, `.ssh` and the files the user uploads. Directories, links and inodes do not count, and a sparse file counts its length. A write that would take the home over it is refused whole (`disk quota exceeded`) and audited, and so is a size that would grow a file over it; a smaller size gives the room back. An upload that is refused part way leaves what was written before the refusal in the home (the client does not remove it), and the `sftp` and `scp` of OpenSSH show only `Failure` for it: the reason, `reason=quota`, is in the console's audit log. A file that was deleted while a handle of the session still holds it stays counted until the handle is closed. The home is measured when the session starts and again, when a file is opened for writing, if the last measure is a few seconds old, so the quota is per session: N sessions of one user at once can each use the room that was free when they measured, and bring the home to about N times the quota. A directory in the home that the session cannot read or search (for example one owned by root with mode 0700) makes the home count as full: every upload that grows the home is refused with `disk quota exceeded` until the directory is readable, while reading, deleting and writes that do not grow the home go on. The rate is the bytes a second one session may move, reads and writes together, with a burst of one second; a transfer at its rate waits, it is not refused. Both are read when the session starts. diff --git a/internal/sftpd/file.go b/internal/sftpd/file.go index 835e307f..649e1841 100644 --- a/internal/sftpd/file.go +++ b/internal/sftpd/file.go @@ -1,6 +1,7 @@ package sftpd import ( + "encoding/binary" "os" "sync" "sync/atomic" @@ -34,6 +35,31 @@ type file struct { closed sync.Once } +// defaultFileMode is the mode of a new file when the client's open request +// does not carry one (the umask of the console still applies). +const defaultFileMode = 0o644 + +// permBits is the part of a mode a client may set: the permission bits. The +// set-user-ID, set-group-ID and sticky bits, and any file type bits, are +// dropped. Mkdir, setstat and open all take their mode through it. +func permBits(m uint32) uint32 { return m & 0o777 } + +// openMode is the mode the client asks for in the open request r, and whether +// it asked. The library hands the handlers the attribute block of an open as +// raw bytes and drops the attribute flags that say which fields it holds +// (Request.Flags of an open is the open flags, so AttrFlags and Attributes +// would read the wrong thing). A block of exactly four bytes can only be the +// permissions: it is what the OpenSSH sftp and scp clients send, without a +// size, owner or times. Any other length could be the permissions together +// with a size, an owner or times, in an order that cannot be told apart, so it +// asks for nothing and the new file gets the default mode, as before. +func openMode(r *sftp.Request) (uint32, bool) { + if len(r.Attrs) != 4 { + return 0, false + } + return permBits(binary.BigEndian.Uint32(r.Attrs)), true +} + // openFile opens the file of r. write says the open is for an upload (the // handle can write); otherwise it is a download. func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { @@ -66,7 +92,7 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { s.quota.refresh() } flags := unix.O_NONBLOCK - mode := uint32(0o644) // the attributes of an open are not parsed: the client sets the mode with setstat + mode := uint32(defaultFileMode) if write { flags |= unix.O_WRONLY if pf.Read { @@ -74,6 +100,9 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { } if pf.Creat { flags |= unix.O_CREAT + if m, ok := openMode(r); ok { + mode = m // only a file the open creates gets it; an existing one keeps its mode + } } if pf.Excl { flags |= unix.O_EXCL diff --git a/internal/sftpd/handlers.go b/internal/sftpd/handlers.go index 2e781a42..40a5c2e5 100644 --- a/internal/sftpd/handlers.go +++ b/internal/sftpd/handlers.go @@ -237,7 +237,7 @@ func (s *server) mkdir(r *sftp.Request) (err error) { mode := uint32(0o755) if r.AttrFlags().Permissions { if a := r.Attributes(); a != nil { - mode = a.Mode & 0o777 + mode = permBits(a.Mode) } } return t.pathErr("mkdir", unix.Mkdirat(t.dir, t.name, mode)) @@ -397,7 +397,7 @@ func (s *server) setstat(r *sftp.Request) (err error) { } } if fl.Permissions { - if err := p.chmod(a.Mode & 0o777); err != nil { + if err := p.chmod(permBits(a.Mode)); err != nil { return err } } diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go new file mode 100644 index 00000000..66f72ef5 --- /dev/null +++ b/internal/sftpd/openmode_test.go @@ -0,0 +1,248 @@ +package sftpd + +import ( + "encoding/binary" + "io" + "net" + "os" + "path/filepath" + "syscall" + "testing" +) + +// The SFTP packet types a raw client needs. +const ( + rawInit = 1 + rawOpen = 3 + rawClose = 4 + rawWrite = 6 + rawVersion = 2 + rawStatus = 101 + rawHandle = 102 + + rawFlagRead = 0x1 + rawFlagWrite = 0x2 + rawFlagCreat = 0x8 + rawFlagTrunc = 0x10 + rawFlagExcl = 0x20 + + rawAttrPerm = 0x4 +) + +// rawConn speaks SFTP by hand, so that a test can put attributes in an open +// request, which the client library never does. +type rawConn struct { + t *testing.T + c net.Conn + done chan error + id uint32 +} + +func newRawConn(t *testing.T, home string) *rawConn { + t.Helper() + cs, ss := net.Pipe() + r := &rawConn{t: t, c: cs, done: make(chan error, 1)} + go func() { r.done <- serve(ss, Config{Home: home}, seams{}) }() + t.Cleanup(func() { _ = r.close() }) + r.send(rawInit, binary.BigEndian.AppendUint32(nil, 3)) + if typ, _ := r.recv(); typ != rawVersion { + t.Fatalf("answer to init has type %d", typ) + } + return r +} + +func (r *rawConn) close() error { + if r.c == nil { + return nil + } + _ = r.c.Close() + r.c = nil + return <-r.done +} + +func (r *rawConn) send(typ byte, body []byte) { + r.t.Helper() + b := binary.BigEndian.AppendUint32(nil, uint32(1+len(body))) + b = append(b, typ) + b = append(b, body...) + if _, err := r.c.Write(b); err != nil { + r.t.Fatal(err) + } +} + +func (r *rawConn) recv() (byte, []byte) { + r.t.Helper() + var l [4]byte + if _, err := io.ReadFull(r.c, l[:]); err != nil { + r.t.Fatal(err) + } + b := make([]byte, binary.BigEndian.Uint32(l[:])) + if _, err := io.ReadFull(r.c, b); err != nil { + r.t.Fatal(err) + } + return b[0], b[1:] +} + +func str(b []byte, s string) []byte { + return append(binary.BigEndian.AppendUint32(b, uint32(len(s))), s...) +} + +// request sends a packet that starts with a fresh id and returns the type and +// the body of the answer, without the id. +func (r *rawConn) request(typ byte, body []byte) (byte, []byte) { + r.t.Helper() + r.id++ + r.send(typ, append(binary.BigEndian.AppendUint32(nil, r.id), body...)) + t, b := r.recv() + if got := binary.BigEndian.Uint32(b); got != r.id { + r.t.Fatalf("answer to request %d has id %d", r.id, got) + } + return t, b[4:] +} + +// status is the code of a status answer. +func status(t *testing.T, typ byte, b []byte) uint32 { + t.Helper() + if typ != rawStatus { + t.Fatalf("answer of type %d, want a status", typ) + } + return binary.BigEndian.Uint32(b) +} + +// open sends an open request with the open flags pflags, the attribute flags +// aflags and the attribute block attrs, and returns the handle ("" and the +// status code when it is refused). +func (r *rawConn) open(path string, pflags, aflags uint32, attrs []byte) (string, uint32) { + r.t.Helper() + b := str(nil, path) + b = binary.BigEndian.AppendUint32(b, pflags) + b = binary.BigEndian.AppendUint32(b, aflags) + b = append(b, attrs...) + typ, body := r.request(rawOpen, b) + if typ == rawHandle { + n := binary.BigEndian.Uint32(body) + return string(body[4 : 4+n]), 0 + } + return "", status(r.t, typ, body) +} + +// finish writes data at the start of the open handle h and closes it. +func (r *rawConn) finish(h, data string) { + r.t.Helper() + b := str(nil, h) + b = binary.BigEndian.AppendUint64(b, 0) + b = str(b, data) + typ, body := r.request(rawWrite, b) + if c := status(r.t, typ, body); c != 0 { + r.t.Fatalf("write: status %d", c) + } + typ, body = r.request(rawClose, str(nil, h)) + if c := status(r.t, typ, body); c != 0 { + r.t.Fatalf("close: status %d", c) + } +} + +func permAttrs(mode uint32) []byte { return binary.BigEndian.AppendUint32(nil, mode) } + +// The open request carries the mode of the new file: its permission bits, +// less the umask of the process (the console runs with 077). The attribute +// flags of the request are not delivered to the handlers by the library, so +// only a block of the permissions alone (the four bytes the OpenSSH clients +// send) is read. +func TestOpenModeOfTheRequest(t *testing.T) { + const ( + creatTrunc = rawFlagWrite | rawFlagCreat | rawFlagTrunc + times = 8 // acmodtime attribute flag + ) + twelve := append(permAttrs(0o755), make([]byte, 8)...) // permissions and times + tests := []struct { + name string + umask int + pflags uint32 + aflags uint32 + attrs []byte + existing os.FileMode // 0: the file does not exist + want os.FileMode + }{ + {"0755 under the console umask", 0o077, creatTrunc, rawAttrPerm, permAttrs(0o755), 0, 0o700}, + {"0644 under the console umask", 0o077, creatTrunc, rawAttrPerm, permAttrs(0o644), 0, 0o600}, + {"0755 under umask 022", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o755), 0, 0o755}, + {"0600 under umask 022", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o600), 0, 0o600}, + {"set-user-ID is ignored", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o4755), 0, 0o755}, + {"set-group-ID is ignored", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o2755), 0, 0o755}, + {"sticky is ignored", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o1755), 0, 0o755}, + {"all special bits and the file type are ignored", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o107777), 0, 0o755}, + {"no attributes: 0644 under umask 022", 0o022, creatTrunc, 0, nil, 0, 0o644}, + {"no attributes: 0600 under the console umask", 0o077, creatTrunc, 0, nil, 0, 0o600}, + {"create and exclusive", 0o022, rawFlagWrite | rawFlagCreat | rawFlagExcl, rawAttrPerm, permAttrs(0o755), 0, 0o755}, + {"permissions with times are not read", 0o022, creatTrunc, rawAttrPerm | times, twelve, 0, 0o644}, + {"an existing file keeps its mode", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o755), 0o640, 0o640}, + {"an existing file without create keeps its mode", 0o022, rawFlagWrite, rawAttrPerm, permAttrs(0o755), 0o640, 0o640}, + {"a read-only open changes nothing", 0o022, rawFlagRead, rawAttrPerm, permAttrs(0o755), 0o640, 0o640}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + old := syscall.Umask(tc.umask) + defer syscall.Umask(old) + home := filepath.Join(t.TempDir(), "home") + if err := os.Mkdir(home, 0o755); err != nil { + t.Fatal(err) + } + p := filepath.Join(home, "f") + if tc.existing != 0 { + if err := os.WriteFile(p, []byte("old"), 0o600); err != nil { + t.Fatal(err) + } + if err := os.Chmod(p, tc.existing); err != nil { + t.Fatal(err) + } + } + r := newRawConn(t, home) + h, code := r.open("f", tc.pflags, tc.aflags, tc.attrs) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + if tc.pflags&rawFlagWrite != 0 { + r.finish(h, "new") + } else { + typ, body := r.request(rawClose, str(nil, h)) + if c := status(t, typ, body); c != 0 { + t.Fatalf("close: status %d", c) + } + } + fi, err := os.Stat(p) + if err != nil { + t.Fatal(err) + } + if fi.Mode() != tc.want { + t.Errorf("mode %v, want %v", fi.Mode(), tc.want) + } + }) + } +} + +// A read-only open of a missing file creates nothing, whatever mode the +// request carries. +func TestOpenModeReadOnlyCreatesNothing(t *testing.T) { + home := filepath.Join(t.TempDir(), "home") + if err := os.Mkdir(home, 0o755); err != nil { + t.Fatal(err) + } + r := newRawConn(t, home) + if h, code := r.open("f", rawFlagRead, rawAttrPerm, permAttrs(0o755)); h != "" || code != fxNoSuchFile { + t.Errorf("open = %q, status %d, want status %d", h, code, fxNoSuchFile) + } + if _, err := os.Lstat(filepath.Join(home, "f")); err == nil { + t.Error("the open created the file") + } +} + +// The mode a client asks for in a mkdir, a setstat and an open goes through +// the same mask. +func TestPermBits(t *testing.T) { + for in, want := range map[uint32]uint32{0o755: 0o755, 0o4755: 0o755, 0o2750: 0o750, 0o1777: 0o777, 0o100644: 0o644, 0: 0} { + if got := permBits(in); got != want { + t.Errorf("permBits(%o) = %o, want %o", in, got, want) + } + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index d01a7040..40ba66a3 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -16444,8 +16444,18 @@ can be set (cut, or extended with zeros), which is what .B scp does after an upload to give the file its final size; it counts against the quota like a write. The owner cannot be changed, and a request that asks for it is -refused whole. A new directory gets the mode the client asks for and a new file -0644, both reduced by the umask of the console, 077; the set\-user\-ID, +refused whole. A new directory gets the mode the client asks for. A new file gets +the mode the client asks for in the request that opens it, when that request +carries the permissions alone (which is what the OpenSSH +.B sftp +and +.B scp +send), and 0644 otherwise (a request that carries other attributes with the +permissions is read as carrying none); a file that already exists keeps its +mode, whatever the open asks. Both are reduced by the umask of the console, 077: +the owner's bits survive and the group and other bits go, so a script uploaded +with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is +0700. The set\-user\-ID, set\-group\-ID and sticky bits are ignored, and a client that wants another mode sets it afterwards, which is applied as given. Changing the mode or the times of a file goes through From 0028927f6587505e4baa0181d7026337e1d4ecdf Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 18:59:07 -0900 Subject: [PATCH 29/52] sftpd: pin that a rate-limited session ends when the client leaves A review finding said a rate-limited session lingers after the client leaves. It does not: this change adds the test that shows it, and no behaviour changes. With a rate of one byte per second, requests that are past the point where they take their bytes from the bucket owe hours of sleep. The test (upload and download, one request and more requests than the library has workers) lets them reach the default rate sleep, drops the stream without reading an answer, and Serve returns within a few hundred microseconds: the sleeps end with the stream, requests queued behind them take no sleep of their own, and nothing else holds the library's workers. A sleep that ignores the end of the stream makes the test fail after its 10 s deadline. To see the requests asleep the test needs a hook in the default sleep (seams.sleeping, off unless a test sets it); the raw SFTP client of the mode tests takes the configuration and the seams, and its close no longer waits for a session that does not end. --- internal/sftpd/linger_test.go | 86 +++++++++++++++++++++++++++++++++ internal/sftpd/openmode_test.go | 18 ++++++- internal/sftpd/sftpd.go | 11 ++++- 3 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 internal/sftpd/linger_test.go diff --git a/internal/sftpd/linger_test.go b/internal/sftpd/linger_test.go new file mode 100644 index 00000000..8fc1b09e --- /dev/null +++ b/internal/sftpd/linger_test.go @@ -0,0 +1,86 @@ +package sftpd + +import ( + "encoding/binary" + "os" + "path/filepath" + "testing" + "time" +) + +// A rate-limited session ends as soon as the client leaves. The requests +// that are past the point where they take their bytes from the bucket are +// asleep for the debt (here a rate of one byte per second, so each of them +// owes hours), the client drops the stream without waiting for a reply, and +// Serve must return at once: the sleeps end with the stream, the requests +// that were queued behind them take no sleep of their own, and nothing else +// holds the session. +// +// This test uses the real sleep of the session (the default one, that is +// the code under test) and so waits on a real timer, but only if the code is +// wrong: the debt is hours long and the end of the stream is what must end +// it, so a session that lingers fails the test after a deadline instead of +// hanging. Serve is expected to return in microseconds; the deadline is +// generous for a loaded machine. +func TestRateLimitedSessionEndsWhenTheClientLeaves(t *testing.T) { + const chunk = 32768 + data := bytesOf(chunk) + tests := []struct { + name string + upload bool + requests int // more than the library's workers when it is 20 + }{ + {"upload, one request", true, 1}, + {"upload, more requests than workers", true, 20}, + {"download, one request", false, 1}, + {"download, more requests than workers", false, 20}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + home := filepath.Join(t.TempDir(), "home") + if err := os.Mkdir(home, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(home, "d"), []byte(bytesOf(chunk*tc.requests)), 0o600); err != nil { + t.Fatal(err) + } + asleep := make(chan struct{}, tc.requests) + r := newRawConnCfg(t, Config{Home: home, Rate: 1}, seams{sleeping: func() { asleep <- struct{}{} }}) + var h string + if tc.upload { + h, _ = r.open("u", rawFlagWrite|rawFlagCreat, 0, nil) + } else { + h, _ = r.open("d", rawFlagRead, 0, nil) + } + if h == "" { + t.Fatal("open refused") + } + for i := 0; i < tc.requests; i++ { + r.id++ + b := str(binary.BigEndian.AppendUint32(nil, r.id), h) + b = binary.BigEndian.AppendUint64(b, uint64(i)*chunk) + if tc.upload { + r.send(rawWrite, str(b, data)) + } else { + r.send(rawRead, binary.BigEndian.AppendUint32(b, chunk)) + } + } + // Requests are asleep: as many as the library has workers for, + // at most; the answers are not read, as a client that is gone. + for i := 0; i < min(tc.requests, 8); i++ { + select { + case <-asleep: + case <-time.After(10 * time.Second): + t.Fatalf("only %d requests reached the sleep", i) + } + } + _ = r.c.Close() + r.c = nil + select { + case <-r.done: + case <-time.After(10 * time.Second): + t.Fatal("the session is still running 10 s after the client left") + } + }) + } +} diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go index 66f72ef5..29d2ed4c 100644 --- a/internal/sftpd/openmode_test.go +++ b/internal/sftpd/openmode_test.go @@ -2,12 +2,14 @@ package sftpd import ( "encoding/binary" + "errors" "io" "net" "os" "path/filepath" "syscall" "testing" + "time" ) // The SFTP packet types a raw client needs. @@ -16,6 +18,7 @@ const ( rawOpen = 3 rawClose = 4 rawWrite = 6 + rawRead = 5 rawVersion = 2 rawStatus = 101 rawHandle = 102 @@ -39,10 +42,16 @@ type rawConn struct { } func newRawConn(t *testing.T, home string) *rawConn { + t.Helper() + return newRawConnCfg(t, Config{Home: home}, seams{}) +} + +// newRawConnCfg is newRawConn with the whole configuration and the seams. +func newRawConnCfg(t *testing.T, cfg Config, sm seams) *rawConn { t.Helper() cs, ss := net.Pipe() r := &rawConn{t: t, c: cs, done: make(chan error, 1)} - go func() { r.done <- serve(ss, Config{Home: home}, seams{}) }() + go func() { r.done <- serve(ss, cfg, sm) }() t.Cleanup(func() { _ = r.close() }) r.send(rawInit, binary.BigEndian.AppendUint32(nil, 3)) if typ, _ := r.recv(); typ != rawVersion { @@ -57,7 +66,12 @@ func (r *rawConn) close() error { } _ = r.c.Close() r.c = nil - return <-r.done + select { + case err := <-r.done: + return err + case <-time.After(10 * time.Second): // only if the session does not end + return errors.New("the session did not end") + } } func (r *rawConn) send(typ byte, body []byte) { diff --git a/internal/sftpd/sftpd.go b/internal/sftpd/sftpd.go index d8cae664..4c9ce62f 100644 --- a/internal/sftpd/sftpd.go +++ b/internal/sftpd/sftpd.go @@ -66,6 +66,10 @@ type seams struct { measureDepth int // the depth of the quota walk, 0 for the default maxHandles int // the open handles a session may have, 0 for the default + // sleeping, when set, is called when the default rate sleep begins (a + // test that replaces the sleep does not see it). + sleeping func() + // beforeTruncate, when set, runs in an open that truncates, after the // file is open and judged and before it is cut. beforeTruncate func() @@ -82,7 +86,12 @@ func serve(rw io.ReadWriteCloser, cfg Config, sm seams) error { sm.now = time.Now } if sm.sleep == nil { - sm.sleep = func(d time.Duration) { sleepUntil(n.done, d) } + sm.sleep = func(d time.Duration) { + if sm.sleeping != nil { + sm.sleeping() + } + sleepUntil(n.done, d) + } } h, err := openHome(cfg.Home) if err != nil { From a891469f49aeb3a56b3f91d59692f7b802e83fcf Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 18:55:54 -0900 Subject: [PATCH 30/52] shell tests: TestPtyPaste waits for the prompt before the second paste The test went on as soon as the output of 'echo pasted line end' arrived. That output comes before the shell takes the terminal back: while a command runs the terminal is in its normal mode, and the shell sets it raw and prints the prompt only afterwards. On a loaded runner the echo command was still running when the 4196-character paste was sent, so the terminal's own line discipline took it (echoed as '^[[200~xxxx') and the shell never got the paste and Ctrl-U as the test meant, and the wait for 'STATUS 0' ran out after 60 s. The test now waits for the prompt after the first output, as the other pty tests do. What it asserts is unchanged. Reproduced with the race-enabled test binary under CPU load (24 busy loops, 8 copies at once, GOMAXPROCS=1, 25 runs each): 5 of 200 runs failed before (and 1 of 120 with 16 busy loops and GOMAXPROCS=2), 0 of 200 after. --- internal/shell/pty_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/shell/pty_test.go b/internal/shell/pty_test.go index 21a69620..e87f6ad4 100644 --- a/internal/shell/pty_test.go +++ b/internal/shell/pty_test.go @@ -689,6 +689,13 @@ func TestPtyPaste(t *testing.T) { } p.send("\r") p.output("pasted line end") + // The output of echo comes before the shell takes the terminal back: while + // the command runs the terminal is in its normal (cooked) mode, and a paste + // sent then is echoed as '^[[200~' and handled by the terminal's line + // discipline, not by the editor (on a loaded runner the echo command is + // still running when the test went on). The prompt is the sign that the + // editor reads again. + p.expect(`tacctl> `) // A paste over PasteMax is cut there, and Ctrl-U drops it: the line that // follows is 'exit' alone (with the text left, it would run as a program // and the shell would not end). The editor echoes every character it From 3eb5052f30c991db5cf593bde7caad5103aa7d5c Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 18:58:35 -0900 Subject: [PATCH 31/52] docs: a user is not always given a Linux account on the server The user page and the man page said every user has an account on the tacctl server. Since 0.2.21 every user can log in to the server through the reserved scope tacctl, but a Linux account exists only when the name can be one: a name longer than 32 characters, or one with upper case letters kept from an earlier release, is a user name and not an account name (the reports page was corrected the same way in 0.2.27). 'user add' now says the user gets an account and who has none, with a link to the upgrade page that explains it; the paragraph on a name with a period and the man page say a user is meant to have an account, which is the reason a period is refused. The other mentions in docs/ and the man page are right as they stand (a new user gets an account at once, the sync gives accounts, the reports page already makes the distinction). --- docs/cli/user.md | 16 +++++++++------- man/tacctl.1 | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/cli/user.md b/docs/cli/user.md index 0d1056c0..f6f9aba1 100644 --- a/docs/cli/user.md +++ b/docs/cli/user.md @@ -18,10 +18,12 @@ user add Add a new user; lands in default scope. The name is lower case (`Names are lower case: use 'alice'.`): lower-case letters, digits, `_` and `-`. A period is refused (`Username must contain only letters, numbers, underscores and hyphens (a period cannot be part of a Linux - account name).`): every user has an account on the tacctl server. Reserved names `root` and - `tacquito` are rejected (they collide with OS accounts tacquito resolves locally). A new user - must change the password at the first login to this server (see "A required password - change"). + account name).`): the user gets an account on the tacctl server. A name longer than 32 + characters, or one with upper case letters from an earlier release, is a user name but not an + account name, and that user has none (see [Upgrading](../install/upgrading.md)). Reserved + names `root` and `tacquito` are rejected (they collide with OS accounts tacquito resolves + locally). A new user must change the password at the first login to this server (see "A + required password change"). user add --no-change-required @@ -218,9 +220,9 @@ only when set, so a store without one is unchanged. No mail is sent to it. [Rolling back](../install/upgrading.md#rolling-back)). **A name with a period.** A user name is letters, digits, `_` and `-`. A period cannot be part of a -Linux account name, and every user has an account on the tacctl server, so every `user` verb, `passwd` -and `config linux uid` refuse a name with a period with `Username must contain only letters, numbers, -underscores and hyphens (a period cannot be part of a Linux account name).` 0.2.20 and 0.2.21 allowed +Linux account name, and a user is meant to have an account on the tacctl server, so every `user` +verb, `passwd` and `config linux uid` refuse a name with a period with `Username must contain only +letters, numbers, underscores and hyphens (a period cannot be part of a Linux account name).` 0.2.20 and 0.2.21 allowed periods: `tacctl upgrade` renames each user a store of theirs still holds, replacing every period with `_` (`alice.smith` becomes `alice_smith`), with the user's record, UID line and console settings, after a snapshot it names; it prints `renamed user alice.smith to alice_smith` for each and asks you to diff --git a/man/tacctl.1 b/man/tacctl.1 index d01a7040..a4723407 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -1628,7 +1628,7 @@ a name with upper case is refused with the lower\-case spelling to use, and a user that exists with upper case keeps working as it is .RB ( "tacctl config validate" lists it). A period is refused: it cannot be part of a Linux account name, and -every user has an account on the tacctl server. This holds for every +a user is meant to have an account on the tacctl server. This holds for every .B user verb, for .B passwd From 370119d10cb73956614df867b9784f41fcc06fb0 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:20:15 -0900 Subject: [PATCH 32/52] user add, user rename: a new user name is at most 32 characters A Linux account name is at most 32 characters, but user add took any length, so a longer name became a tacctl user with no account on the tacctl server or on a host. user add and the new name of user rename now refuse a name of more than 32 characters with its length and the limit, change nothing and exit 1. The check is a function of its own, names.RejectLongUsername, run by the two creation paths only. ValidateUsername, which every verb runs, does not have it, so a user that exists with a longer name keeps working: it is shown, changed, renamed away and removed as before, and a restore or an upgrade carries it unchanged. The limit is names.UsernameMax, defined once; a test keeps it equal to what hosts.LinuxName accepts. The comments that said every user has an account are corrected, and so are docs/cli/user.md, docs/install/upgrading.md and the manual page. --- CHANGELOG.md | 15 ++++ docs/cli/user.md | 22 ++++-- docs/install/upgrading.md | 2 +- internal/cli/user.go | 4 ++ internal/cli/user_length_test.go | 113 ++++++++++++++++++++++++++++++ internal/cli/user_no_dots_test.go | 5 +- internal/names/names.go | 28 ++++++-- internal/names/names_test.go | 23 ++++++ man/tacctl.1 | 18 +++-- 9 files changed, 215 insertions(+), 15 deletions(-) create mode 100644 internal/cli/user_length_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 353fc633..b7501d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,21 @@ All notable changes to tacctl. The README and the manual page describe only the current behaviour; this file is where history lives. +## 0.2.29 (unreleased) + +1. **A new user name is at most 32 characters.** A Linux account name is at + most 32 characters, but `user add` took any length, so a longer name became + a tacctl user that has no account on the tacctl server or on a host. + `user add` and the new name of `user rename` now refuse a name of more + than 32 characters, change nothing and exit 1, with + `Username 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is 33 characters; a user name + is at most 32 (the longest a Linux account name can be).` (the name is + given in full). A name of exactly 32 is accepted. Only the creation + paths check it: a user that exists with a longer name keeps working (it is + shown, changed, renamed away to a shorter name and removed as before) and + `backup restore` and `tacctl upgrade` carry it unchanged. `docs/cli/user.md`, `docs/install/upgrading.md` and the + manual page say so; they no longer say that every user has an account. + ## 0.2.28 (2026-11-09) 1. **A support bundle from a Cisco IOS device no longer starts the identity diff --git a/docs/cli/user.md b/docs/cli/user.md index 0d1056c0..27dcc086 100644 --- a/docs/cli/user.md +++ b/docs/cli/user.md @@ -18,7 +18,10 @@ user add Add a new user; lands in default scope. The name is lower case (`Names are lower case: use 'alice'.`): lower-case letters, digits, `_` and `-`. A period is refused (`Username must contain only letters, numbers, underscores and hyphens (a period cannot be part of a Linux - account name).`): every user has an account on the tacctl server. Reserved names `root` and + account name).`). A name is at most 32 characters, the longest a Linux account name can be: a + longer one is refused with its length (`Username '' is 33 characters; a user name is at + most 32 (the longest a Linux account name can be).`; see "A name of more than 32 characters"). + Reserved names `root` and `tacquito` are rejected (they collide with OS accounts tacquito resolves locally). A new user must change the password at the first login to this server (see "A required password change"). @@ -102,7 +105,8 @@ user enable user rename - Rename a user; the new name is lower case and follows the rules of `user add`. The user's + Rename a user; the new name is lower case, at most 32 characters, and follows the rules of + `user add` (the old name can be any name a user has). The user's `console system-shell user` setting and its `console file-transfer` settings (the switch, the quota and the rate) move to the new name, and the command says so. Changing only the spelling (`user rename Alice alice`) fixes a name from before. Devices match the @@ -218,8 +222,8 @@ only when set, so a store without one is unchanged. No mail is sent to it. [Rolling back](../install/upgrading.md#rolling-back)). **A name with a period.** A user name is letters, digits, `_` and `-`. A period cannot be part of a -Linux account name, and every user has an account on the tacctl server, so every `user` verb, `passwd` -and `config linux uid` refuse a name with a period with `Username must contain only letters, numbers, +Linux account name, and a user whose name is not one has no account on the tacctl server, so every +`user` verb, `passwd` and `config linux uid` refuse a name with a period with `Username must contain only letters, numbers, underscores and hyphens (a period cannot be part of a Linux account name).` 0.2.20 and 0.2.21 allowed periods: `tacctl upgrade` renames each user a store of theirs still holds, replacing every period with `_` (`alice.smith` becomes `alice_smith`), with the user's record, UID line and console settings, @@ -231,6 +235,16 @@ and `tacctl user rename` gives another name afterwards (see [Upgrading](../insta upgrade runs, a store that still holds such a name fails every write with `user 'alice.smith': invalid name` and says that `tacctl upgrade` renames it. +**A name of more than 32 characters.** A Linux account name is at most 32 characters, so `user add` +and the new name of `user rename` refuse a longer one, and change nothing, with the length and the +limit: `Username '' is 33 characters; a user name is at most 32 (the longest a Linux account +name can be).` A name of exactly 32 is accepted. Only a new name is checked: an earlier release +took any length, and a user it stored with a longer name keeps working. It is shown, listed, +changed, renamed away to a shorter name and removed as before, and `backup restore` and +`tacctl upgrade` carry it unchanged (neither refuses or drops it), but it has no account on the tacctl +server or on a host, so it gets none at a sync and cannot make a report (see +[Upgrading](../install/upgrading.md)). Rename it with `tacctl user rename `. + **This server's accounts.** `user add`, `remove`, `rename`, `move`, `enable`, `disable`, `scope add|remove|replace|remove --all` and `require-password-change` end by syncing this server's own accounts when the diff --git a/docs/install/upgrading.md b/docs/install/upgrading.md index c0211925..c6791a95 100644 --- a/docs/install/upgrading.md +++ b/docs/install/upgrading.md @@ -26,7 +26,7 @@ The upgrade command: **A user name with a period is renamed.** User names are letters, digits, `_` and `-`, and 0.2.20 and 0.2.21 allowed periods; a period cannot be part of a Linux account name. The upgrade renames every such user, replacing each period with `_` (`alice.smith` becomes `alice_smith`), with everything that follows a user name: the store record (group, scopes, email, flags and limits), the user's line in `linux-uids` and the user's settings in `console.yaml` (the system shell, the password cache and the ignored override of the `users` mapping). It takes a snapshot first and names it (`snapshot holds the state before the rename`; `tacctl backup restore ` undoes the rename), and takes none when no user has a period. One line says each rename (`renamed user alice.smith to alice_smith`; when that name is taken, see below), and a note tells you to have the people log in with the new name: the name typed at a device's login changed, and the old one no longer works. A name with a period never had a Linux account, so no account on this server or on a host is renamed; the new name gets its account at the next sync, unless it cannot be a Linux account name (see below). When `linux-uids` has a line for the new name already, the line of the old name is not moved: the new name keeps its UID, the old line stays in the file as it is, and a warning says so (`'alice_smith' already has UID 80007 in linux-uids, so the line of 'alice.smith' (UID 80001) is not moved: 'alice_smith' keeps UID 80007 and the line of 'alice.smith' stays in the file as it is`). A second upgrade does nothing. -If the new name is taken (a user of that name, a second name that becomes the same, or a break-glass local user of one of the user's scopes), the user gets `_` and four random lowercase letters or digits after it, drawn again until the name is free of every user, every other new name and the break-glass users of the user's scopes: `alice.smith` becomes `alice_smith_k3x9`, and the line says so (`renamed user alice.smith to alice_smith_k3x9 (alice_smith was taken)`). Of two names that meet, the first in the store keeps the name without a suffix, and a name that would be longer than a Linux account name (32 characters) is cut before the suffix. Rename the user again afterwards with `tacctl user rename` if you want another name. The rule for the new name is not changed by what a Linux account may be: a new name with upper case letters (`Alice.Smith` becomes `Alice_Smith`) or longer than 32 characters is a user name but no account name, so that user gets no account at a sync (and `device reports generate` cannot store a report for them). After the renames the upgrade lists each such user with the reason and the fix (`Alice_Smith has upper case letters: tacctl user rename Alice_Smith `), and its closing note says that the other new names get their accounts, or that none can. Only a name that is not a user name even with the periods replaced (one with a space, say) stops the upgrade, before anything is changed: it names the key to edit under `users:` in the store, and you run `tacctl upgrade` again afterwards. When the release you upgrade from has already replaced `tacctl` and the tacquito build, the message says so: the store, the configuration and the services are not changed. An install that cannot read its store is not held up by this step; the warning says so. +If the new name is taken (a user of that name, a second name that becomes the same, or a break-glass local user of one of the user's scopes), the user gets `_` and four random lowercase letters or digits after it, drawn again until the name is free of every user, every other new name and the break-glass users of the user's scopes: `alice.smith` becomes `alice_smith_k3x9`, and the line says so (`renamed user alice.smith to alice_smith_k3x9 (alice_smith was taken)`). Of two names that meet, the first in the store keeps the name without a suffix, and a name that would be longer than a Linux account name (32 characters) is cut before the suffix. Rename the user again afterwards with `tacctl user rename` if you want another name. The rule for the new name is not changed by what a Linux account may be: a new name with upper case letters (`Alice.Smith` becomes `Alice_Smith`) or longer than 32 characters is a user name but no account name (`user add` and `user rename` refuse a new name of more than 32 characters, but the upgrade carries a name it renames and shortens none), so that user gets no account at a sync (and `device reports generate` cannot store a report for them). After the renames the upgrade lists each such user with the reason and the fix (`Alice_Smith has upper case letters: tacctl user rename Alice_Smith `), and its closing note says that the other new names get their accounts, or that none can. Only a name that is not a user name even with the periods replaced (one with a space, say) stops the upgrade, before anything is changed: it names the key to edit under `users:` in the store, and you run `tacctl upgrade` again afterwards. When the release you upgrade from has already replaced `tacctl` and the tacquito build, the message says so: the store, the configuration and the services are not changed. An install that cannot read its store is not held up by this step; the warning says so. The store is renamed before `linux-uids` and `console.yaml` follow, so the upgrade checks both first, before the snapshot and before any write: a `console.yaml` that cannot be read or holds a name the rule refuses (a space, say), or a ledger that cannot be read or locked, stops it with the file and the reason, `No user was renamed.` and `Nothing was changed.`; repair the file and run it again. A key with a period in `console.yaml` that no rename covers (a hand edit, a user who is gone, the `users` mapping) would make the file unreadable, and its settings belong to nobody: the upgrade drops it and says so (`dropped the console settings of 'alice.gone' ...`), also when no user in the store has a period; it is not renamed, because the next user of that name would inherit the system shell or the password cache. If the upgrade stops after the store was written (a crash, a failed write), the renames stay recorded in `upgrade-renames` in the state directory, and the next `tacctl upgrade` finishes the move for those users (`finished the rename of user alice.smith to alice_smith`: the ledger line and the console settings) and removes the file; `tacctl backup restore ` of the snapshot it named is the other way back (a restore forgets the record, since the state it describes is replaced). Until the upgrade has finished the move, `user add`, `user remove` and `user rename` refuse the new name of such a record, and `store import` and the restore of an old-style backup refuse whatever the names, with `The upgrade's rename of user alice.smith to alice_smith is not finished: run 'tacctl upgrade' first. Nothing was changed.`, because the upgrade would otherwise give the ledger line and the console settings of the person it renamed to whoever holds the name by then. The record is emptied before it is removed, so a removal that fails (it says so) does not replay the renames. diff --git a/internal/cli/user.go b/internal/cli/user.go index 1df2e766..b9cbe7b0 100644 --- a/internal/cli/user.go +++ b/internal/cli/user.go @@ -477,6 +477,9 @@ func (inv *invocation) userAdd(args []string) error { if err := names.RequireLower(username); err != nil { return err } + if err := names.RejectLongUsername(username); err != nil { + return err + } if err := inv.groupCheck(group, "Usage: tacctl user add "); err != nil { return err } @@ -1080,6 +1083,7 @@ func (inv *invocation) userRename(args []string) error { func() error { return names.ValidateUsername(newname) }, func() error { return names.RejectReservedUsername(newname) }, func() error { return names.RequireLower(newname) }, + func() error { return names.RejectLongUsername(newname) }, } { if err := check(); err != nil { return err diff --git a/internal/cli/user_length_test.go b/internal/cli/user_length_test.go new file mode 100644 index 00000000..13d4282a --- /dev/null +++ b/internal/cli/user_length_test.go @@ -0,0 +1,113 @@ +package cli + +// A new user name is at most 32 characters, the longest a Linux account name +// can be. The limit is on the creation paths only ('user add' and the new name +// of 'user rename'): a user that exists with a longer name (a store from an +// earlier release) keeps working, is restored as it is, and has no account. + +import ( + "fmt" + "strings" + "testing" + + "github.com/rett/tacctl/internal/hash" + "github.com/rett/tacctl/internal/hosts" + "github.com/rett/tacctl/internal/names" +) + +// longWant is the refusal of a new name of n characters. +func longWant(name string) string { + return fmt.Sprintf("Username '%s' is %d characters; a user name is at most 32 (the longest a Linux account name can be).", name, len(name)) +} + +// The limit of a new user name is the longest a Linux account name can be: +// the two are written apart (internal/hosts, internal/lifecycle), so this +// keeps them equal. +func TestUserNameLimitIsTheLongestLinuxAccountName(t *testing.T) { + if !hosts.LinuxName(strings.Repeat("a", names.UsernameMax)) || hosts.LinuxName(strings.Repeat("a", names.UsernameMax+1)) { + t.Errorf("names.UsernameMax = %d is not the longest hosts.LinuxName accepts", names.UsernameMax) + } +} + +// 32 characters are accepted, 33 are refused, by 'user add' and by the new +// name of 'user rename', and nothing is changed by a refusal. +func TestNewUserNamesAreAtMost32Characters(t *testing.T) { + sb := newSandbox(t, true) + ok, long := strings.Repeat("a", 32), strings.Repeat("a", 33) + + before := sb.store() + sb.run("", []string{"user", "add", long, "operator", "--hash", testHash, "--scopes", "lab"}) + sb.expect(1, "", longWant(long)) + sb.run("", []string{"user", "rename", "bob", long}) + sb.expect(1, "", longWant(long)) + if sb.store() != before { + t.Error("a refusal changed the store") + } + + sb.run("", []string{"user", "add", ok, "operator", "--hash", testHash, "--scopes", "lab"}) + sb.expect(0, "User '"+ok+"' added", "") + renamed := strings.Repeat("b", 32) + sb.run("", []string{"user", "rename", "bob", renamed}) + sb.expect(0, "User renamed: bob -> "+renamed, "") + // The limit is on the new name, whatever the old one is. + sb.run("", []string{"user", "rename", renamed, long}) + sb.expect(1, "", longWant(long)) +} + +// A user from before, with a name over the limit, is shown, changed, renamed +// away to a short name and removed as ever; the limit is not part of the check +// every verb runs. +func TestUserWithAnOverLongNameKeepsWorking(t *testing.T) { + long := strings.Repeat("a", 40) + h, err := hash.Generate("CorrectHorse99", 4) + if err != nil { + t.Fatal(err) + } + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " "+long+":") + + sb.run("", []string{"user", "show", long}) + sb.expect(0, long, "") + sb.run("", []string{"user", "list"}) + sb.expect(0, long, "") + sb.run("", []string{"user", "passwd", long, "--hash", h}) + sb.expect(0, "Password changed for '"+long+"'.", "") + sb.run("CorrectHorse99\n", []string{"user", "verify", long}) + sb.expect(0, "Password is correct.", "") + sb.run("", []string{"user", "disable", long}) + sb.expect(0, "", "") + sb.run("", []string{"user", "enable", long}) + sb.expect(0, "", "") + + // Renamed away to a short name. + sb.run("", []string{"user", "rename", long, "alice"}) + sb.expect(0, "User renamed: "+long+" -> alice", "") + if strings.Contains(sb.store(), long) { + t.Errorf("the store after the rename:\n%s", sb.store()) + } + + // Removed. + sb2 := newSandbox(t, true) + sb2.legacyStoreCase(" alice:", " "+long+":") + sb2.run("y\n", []string{"user", "remove", long}) + sb2.expect(0, "", "") + if strings.Contains(sb2.store(), long) { + t.Errorf("the store after the removal:\n%s", sb2.store()) + } +} + +// The restore of a snapshot with such a user puts the store back as it was +// written: the user is neither refused nor dropped. +func TestBackupRestoreKeepsAnOverLongUser(t *testing.T) { + long := strings.Repeat("a", 40) + sb := renderedSandbox(t) + snap := strings.ReplaceAll(fixture(t, "store.multiscope.yaml"), " alice:", " "+long+":") + sb.mkSnapshot("20200101_000000_001", snap, "") + sb.run("y\n", []string{"backup", "restore", "20200101_000000_001"}) + sb.expect(0, "Restored snapshot 20200101_000000_001.", "") + if sb.read("state/store.yaml") != snap { + t.Errorf("the store is not the snapshot's:\n%s", sb.read("state/store.yaml")) + } + sb.run("", []string{"user", "show", long}) + sb.expect(0, long, "") +} diff --git a/internal/cli/user_no_dots_test.go b/internal/cli/user_no_dots_test.go index 9667f978..a42d71bf 100644 --- a/internal/cli/user_no_dots_test.go +++ b/internal/cli/user_no_dots_test.go @@ -5,8 +5,9 @@ import ( "testing" ) -// A user name is letters, digits, '_' and '-': every user has an account on -// the tacctl server, and a name with a period cannot be a Linux account name. +// A user name is letters, digits, '_' and '-', and a name with a period +// cannot be a Linux account name (a user whose name is not one has no account +// on the tacctl server). // 0.2.20 and 0.2.21 allowed periods; the upgrade renames such a user // (internal/lifecycle/upgrade_dots.go), and no command makes or accepts one. diff --git a/internal/names/names.go b/internal/names/names.go index 2ce1daff..dc983c83 100644 --- a/internal/names/names.go +++ b/internal/names/names.go @@ -122,11 +122,18 @@ func ValidateClassName(value string) error { // '-': it says why a period is not among them. const usernameShape = "Username must contain only letters, numbers, underscores and hyphens (a period cannot be part of a Linux account name)." +// UsernameMax is the most characters a new user name has: the longest a Linux +// account name can be (hosts.LinuxName). A user that exists with a longer name +// (a store from an earlier release) keeps working but has no account. +const UsernameMax = 32 + // ValidateUsername is validate_username: the shape of a user name, letters, -// digits, '_' and '-'. A name with a period is refused whatever the verb: -// every user has an account on the tacctl server and a period cannot be -// part of a Linux account name. See RejectReservedUsername for the -// creation-path check. +// digits, '_' and '-'. A name with a period is refused whatever the verb: a +// period cannot be part of a Linux account name, and a user whose name is not +// one has no account on the tacctl server. The length and the upper case of a +// name from before are not checked here, so every verb still reaches such a +// user. See RejectReservedUsername and RejectLongUsername for the +// creation-path checks. func ValidateUsername(value string) error { if !reUser.MatchString(value) { return fail(usernameShape) @@ -152,6 +159,19 @@ func RejectReservedUsername(value string) error { return nil } +// RejectLongUsername is the length check of the creation paths ('user add' and +// the new name of 'user rename'): a new user name is at most UsernameMax +// characters, the longest a Linux account name can be. It is not part of +// ValidateUsername, which every verb runs: a user that exists with a longer name +// is shown, changed, renamed away and removed as before. The name has passed +// ValidateUsername, so its length in bytes is its length in characters. +func RejectLongUsername(value string) error { + if n := len(value); n > UsernameMax { + return fail(fmt.Sprintf("Username '%s' is %d characters; a user name is at most %d (the longest a Linux account name can be).", value, n, UsernameMax)) + } + return nil +} + // ValidateGroupName is the group-name check of 'group add'. func ValidateGroupName(value string) error { if !reGroup.MatchString(value) { diff --git a/internal/names/names_test.go b/internal/names/names_test.go index d620c5d9..4086719a 100644 --- a/internal/names/names_test.go +++ b/internal/names/names_test.go @@ -2,6 +2,7 @@ package names import ( "errors" + "strconv" "strings" "testing" ) @@ -112,6 +113,28 @@ func TestRejectReservedUsername(t *testing.T) { } } +// --- the length of a new user name --- + +func TestRejectLongUsername(t *testing.T) { + for _, s := range []string{"", "a", "jsmith", strings.Repeat("a", UsernameMax)} { + if err := RejectLongUsername(s); err != nil { + t.Errorf("%q: %v", s, err) + } + } + for _, n := range []int{UsernameMax + 1, 40} { + name := strings.Repeat("a", n) + var e *Error + want := "Username '" + name + "' is " + strconv.Itoa(n) + " characters; a user name is at most 32 (the longest a Linux account name can be)." + if !errors.As(RejectLongUsername(name), &e) || len(e.Lines()) != 1 || e.Lines()[0] != want { + t.Errorf("%d: %v", n, e) + } + } + // ValidateUsername, which every verb runs, takes a user from before. + if err := ValidateUsername(strings.Repeat("a", 40)); err != nil { + t.Errorf("ValidateUsername refuses a long name: %v", err) + } +} + // --- group and scope names --- func TestValidateGroupName(t *testing.T) { diff --git a/man/tacctl.1 b/man/tacctl.1 index d01a7040..cfa3cf43 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -1627,8 +1627,17 @@ Add a user. The name is lower case (lower\-case letters, digits, a name with upper case is refused with the lower\-case spelling to use, and a user that exists with upper case keeps working as it is .RB ( "tacctl config validate" -lists it). A period is refused: it cannot be part of a Linux account name, and -every user has an account on the tacctl server. This holds for every +lists it). A name is at most 32 characters, the longest a Linux account name can +be: a longer one is refused with its length +.RB ( "Username '' is 33 characters; a user name is at most 32 (the longest a Linux account name can be)." ), +and nothing is changed. A user that exists with a longer name (an earlier release +took any length) keeps working as it is, is carried unchanged by +.B "backup restore" +and +.BR "tacctl upgrade" , +and has no Linux account, here or on a host. A period is refused: it +cannot be part of a Linux account name, and a user whose name is not one has no +account on this server. This holds for every .B user verb, for .B passwd @@ -1968,9 +1977,10 @@ Requires: \fBsuperuser\fR. .BI "user rename " "old new" Rename a user. The user's .B "console system\-shell user" -setting moves to the new name, and the command says so. The new name is lower case and follows the rules of +setting moves to the new name, and the command says so. The new name is lower case, at most 32 characters, and follows the rules of .BR "user add" ; -a period is refused in either name. +a period is refused in either name, and the old name can be any name a user has +(also one of more than 32 characters). Changing only the spelling .RB ( "user rename Alice alice" ) is how a name from before is fixed. A device matches the typed login name From cfb761751abeadca6471b799566fa4522bbf0f8d Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:25:02 -0900 Subject: [PATCH 33/52] config validate: warn of a user whose name is longer than 32 characters A user from an earlier release with a name over the limit keeps working but has no Linux account, here or on a host. config validate already lists the users whose name has upper case under Names:, so it lists these too, as a warning (never an error) with the rename that fixes it, in the text and in the json report, the superuser's view only. The finding is separate from the case findings: it carries no kind, so config validate --fix-names, which has no name to propose for it, does not read it. --- CHANGELOG.md | 12 ++++++++++++ docs/cli/config.md | 6 +++++- internal/cli/config_report.go | 7 +++++++ internal/cli/name_case.go | 33 ++++++++++++++++++++++++++++++++ internal/cli/names_lower_test.go | 31 ++++++++++++++++++++++++++++++ man/tacctl.1 | 9 ++++++++- 6 files changed, 96 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7501d60..0792a40b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,18 @@ current behaviour; this file is where history lives. `backup restore` and `tacctl upgrade` carry it unchanged. `docs/cli/user.md`, `docs/install/upgrading.md` and the manual page say so; they no longer say that every user has an account. +2. **`config validate` warns of a user whose name is longer than 32 + characters.** Item 1 keeps such a user (from an earlier release) working, + but it has no Linux account, here or on a host, so it gets none at a + sync. It is a `Names:` warning now, as a name with upper case is, with the + rename that fixes it: `the user 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' has a + name of 33 characters; new user names are at most 32, and this user has no + Linux account, here or on a host (tacctl user rename + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )`. It is a warning, never an + error, and `config validate --json` has it under the section `names`; + `--fix-names` does not offer it, since there is no name to propose. The + superuser's view only. `docs/cli/config.md` and the manual page say so. + ## 0.2.28 (2026-11-09) 1. **A support bundle from a Cisco IOS device no longer starts the identity diff --git a/docs/cli/config.md b/docs/cli/config.md index 95f6ef14..ad79606f 100644 --- a/docs/cli/config.md +++ b/docs/cli/config.md @@ -88,7 +88,11 @@ config validate [--json | --fix-names [--yes]] `host rename`; see cli/host.md). A device, host, user or scope whose name has upper case (the names of new ones are lower case) gets a `Names:` warning that names the rename which fixes it (`tacctl user rename Alice alice`; for a user it adds that devices match the typed login name - exactly, so the rename changes what the person types); the superuser's view only. Exits 1 on + exactly, so the rename changes what the person types); the superuser's view only. A user from + an earlier release whose name is longer than 32 characters (a new name is at most 32, see + cli/user.md) gets a `Names:` warning too: it works but has no Linux account, here or on a + host, and the warning names `tacctl user rename `; `--fix-names` does not + offer that rename, since it has no name to propose. Exits 1 on errors. The verb takes no argument: a word other than its options is refused (`Unknown argument`) and no report is printed. `--json` prints the findings as one JSON object and nothing else on standard output (the schema is below); the exit status is the same. diff --git a/internal/cli/config_report.go b/internal/cli/config_report.go index 51d8b201..9df9becc 100644 --- a/internal/cli/config_report.go +++ b/internal/cli/config_report.go @@ -445,6 +445,13 @@ func (inv *invocation) collectValidate(r *validateReport) { Kind: fnd.Kind, Name: fnd.Name, To: fnd.To, Verb: fnd.Verb}) } + // A user from before with a name longer than a Linux account name: it + // works, but has no account. A warning with the rename that fixes it. + for _, fnd := range inv.lengthFindings() { + r.found(howEchoE, " "+Y+"Names:"+NC+" "+fnd.String(), validateFinding{ + Section: "names", Level: levelWarning, Text: fnd.Text, Fix: fnd.Fix}) + } + // Break-glass local users (D55): a scope without one is a lockout risk // when the server is unreachable, and a name that is also a tacctl user // of its scope is shadowed on the device. Warnings, never errors. diff --git a/internal/cli/name_case.go b/internal/cli/name_case.go index 9a4dfe57..59908852 100644 --- a/internal/cli/name_case.go +++ b/internal/cli/name_case.go @@ -7,6 +7,7 @@ package cli import ( "sort" + "strconv" "strings" "github.com/rett/tacctl/internal/names" @@ -95,3 +96,35 @@ func (inv *invocation) caseFindings() []hostFinding { } return out } + +// lengthFindings are the users whose name is longer than names.UsernameMax, +// a user from an earlier release (new names are checked at 'user add' and +// 'user rename'): each keeps working but has no Linux account, here or on a +// host. They are warnings in 'config validate' with the verb that renames the +// user, sorted by name, the superuser's view only. They carry no Kind, so +// 'config validate --fix-names' (case findings only) does not read them. +func (inv *invocation) lengthFindings() []hostFinding { + if inv.callerScopes().restricted { + return nil + } + m, err := inv.model() + if err != nil { + return nil + } + var long []string + for _, n := range m.UserNames() { + if len(n) > names.UsernameMax { + long = append(long, n) + } + } + sort.Strings(long) + var out []hostFinding + for _, n := range long { + out = append(out, hostFinding{ + Text: "the user '" + n + "' has a name of " + strconv.Itoa(len(n)) + " characters; new user names are at most " + + strconv.Itoa(names.UsernameMax) + ", and this user has no Linux account, here or on a host", + Fix: "tacctl user rename " + n + " ", + }) + } + return out +} diff --git a/internal/cli/names_lower_test.go b/internal/cli/names_lower_test.go index 91ad9e32..29257bea 100644 --- a/internal/cli/names_lower_test.go +++ b/internal/cli/names_lower_test.go @@ -269,6 +269,37 @@ func TestConfigValidateListsNamesWithUpperCase(t *testing.T) { } } +// A user from before with a name of more than 32 characters is a warning +// under Names: with the rename that fixes it (it keeps working but has no +// account); a name of 32 is not listed, and an engineer is told nothing. +func TestConfigValidateListsAUserWithAnOverLongName(t *testing.T) { + long, ok := strings.Repeat("a", 33), strings.Repeat("b", 32) + hs := newHostSandbox(t) + hs.legacyStoreCase(" bob:", " "+long+":") + hs.legacyStoreCase(" carol:", " "+ok+":") + out := plain(hs.run(nil, "config", "validate") + hs.err.String()) + want := "the user '" + long + "' has a name of 33 characters; new user names are at most 32, and this user has no Linux account, here or on a host (tacctl user rename " + long + " )" + if !strings.Contains(out, want) { + t.Errorf("config validate lacks %q:\n%s", want, out) + } + if strings.Contains(out, "'"+ok+"' has a name") { + t.Errorf("a name of 32 characters was listed:\n%s", out) + } + js := hs.run(nil, "config", "validate", "--json") + if !strings.Contains(js, `"section": "names"`) || !strings.Contains(js, `"level": "warning"`) || !strings.Contains(js, `"fix": "tacctl user rename `+long+" ") { + t.Errorf("the json lacks the names finding:\n%s", js) + } + + sb := engineerSandbox(t) + sb.legacyStoreCase(" carol:", " "+long+":") + if got := plain(sb.run("", []string{"config", "validate"}) + sb.err.String()); !strings.Contains(got, long) { + t.Fatalf("the superuser's view lacks the finding:\n%s", got) + } + if got := sb.asEngineer("", "config", "validate") + plain(sb.err.String()); strings.Contains(got, long) { + t.Errorf("an engineer was told of a name:\n%s", got) + } +} + // A host name worked out from a host name is lowercased (host names are not // case-sensitive); one given with --name is refused with upper case; a host // enrolled before under a name with upper case is enrolled again as it is. diff --git a/man/tacctl.1 b/man/tacctl.1 index cfa3cf43..b135a1b3 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -3172,7 +3172,14 @@ case) is a warning under naming the rename that fixes it .RB ( "tacctl user rename Alice alice" , and the like); the one for a user adds that devices match the typed login name -exactly, so the rename changes what the person types at the device. Only the superuser's view has these findings. +exactly, so the rename changes what the person types at the device. A user from +an earlier release whose name is longer than 32 characters (a new name is at +most 32) is a warning under +.B Names: +too: it works but has no Linux account, here or on a host, and the warning names +.BR "tacctl user rename" " name " new\-name ; +.B \-\-fix\-names +does not offer that rename. Only the superuser's view has these findings. .IP Then, for every enabled backend, whether its rendered config is up to date with the store and whether any of its files was edited by hand (drift). With From 0e084799abcc42841f5f3a522975ae08c4528963 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:30:04 -0900 Subject: [PATCH 34/52] docs: a name that starts with a digit or '-' has no account either user add accepts letters, digits, '_' and '-' in any order, but a Linux account name starts with a lower case letter or '_', so a user such as 1alice is created and gets no account. The user page and the manual page said only that a name over 32 characters or with upper case letters has none; they now give the complete list. --- docs/cli/user.md | 6 +++++- man/tacctl.1 | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/cli/user.md b/docs/cli/user.md index 27dcc086..24841328 100644 --- a/docs/cli/user.md +++ b/docs/cli/user.md @@ -21,7 +21,9 @@ user add account name).`). A name is at most 32 characters, the longest a Linux account name can be: a longer one is refused with its length (`Username '' is 33 characters; a user name is at most 32 (the longest a Linux account name can be).`; see "A name of more than 32 characters"). - Reserved names `root` and + A name that starts with a digit or `-` (`1alice`) is still accepted, but a Linux account name + starts with a lower case letter or `_`, so that user has no account on the tacctl server or + on a host. Reserved names `root` and `tacquito` are rejected (they collide with OS accounts tacquito resolves locally). A new user must change the password at the first login to this server (see "A required password change"). @@ -244,6 +246,8 @@ changed, renamed away to a shorter name and removed as before, and `backup resto `tacctl upgrade` carry it unchanged (neither refuses or drops it), but it has no account on the tacctl server or on a host, so it gets none at a sync and cannot make a report (see [Upgrading](../install/upgrading.md)). Rename it with `tacctl user rename `. +The length is not the only reason a user has no account: a name with upper case letters, and a +name that starts with a digit or `-`, which `user add` still accepts, have none either. **This server's accounts.** `user add`, `remove`, `rename`, `move`, `enable`, `disable`, `scope add|remove|replace|remove --all` and diff --git a/man/tacctl.1 b/man/tacctl.1 index b135a1b3..984f94e7 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -1635,7 +1635,16 @@ took any length) keeps working as it is, is carried unchanged by .B "backup restore" and .BR "tacctl upgrade" , -and has no Linux account, here or on a host. A period is refused: it +and has no Linux account, here or on a host. So has a user whose name has upper +case letters or starts with a digit or +.BR \- : +a Linux account name starts with a lower case letter or +.BR _ , +and +.B "user add" +still accepts a name that starts with a digit or +.BR \- . +A period is refused: it cannot be part of a Linux account name, and a user whose name is not one has no account on this server. This holds for every .B user From 38bc42f1055eb97d95b4a824bed361357e6b65cc Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:42:52 -0900 Subject: [PATCH 35/52] rollback: 0.2.28, the release before this one, is a target Every release ships a rollback target for the release before it. 0.2.29 so far changes no stored file 0.2.28 reads strictly (the mode a file uploaded through the console gets, a test and the documentation), so the plan of the target converts nothing: no key and no field is removed, no snapshot is taken, no --yes is needed and every file stays, the console's file transfer settings, the limits of the stored reports, the per-tier sudoers drop-in (0.2.28 and 0.2.29 write the same text), the pull records, the reports in the users' homes and the marker of the offer of the PDF tools included. None of the steps of rollbackAdditions fires for it: they undo changes for the targets older than their release. It is refused only while a device's apply is not settled, as every target is. The command ends with the upgrade and has no closing note. 0.2.28 stops being "not a release to roll back to" in the version refusal and becomes the release before this one; 0.2.27 stops being that and keeps removing the file transfer settings. The usage, the completion, the top-level help and its golden file list it. The lists of "every target but" in the code comments name 0.2.28 beside 0.2.27, the text of the 0.2.27 and 0.2.26 targets says what 0.2.28 and the later releases changed, and the next steps of the 0.2.27 target are those of 0.2.28 plus the snapshot note. rollbackFrom, the release a snapshot's state is of in the note that follows a rollback, is 0.2.29, and the tests that quote the note say so (TestRollbackFromIsTheReleaseOfTheChangelog passes again). Tests: the version check, the plan with and without state (nothing removed, no snapshot, no --yes, console.yaml untouched), --hosts, an unsettled apply, the 0.2.28 tag's console reader and per-tier text (skipped without git or the tag), the command (the dry run, the apply and a second run, the 0.2.27 target told apart, the lockdown, the drop-in, the refusal that names the targets), the completion and the usage golden, and the bats test of the target. --- internal/cli/completion_test.go | 2 +- internal/cli/help_text.go | 2 +- internal/cli/rollback.go | 44 +++-- internal/cli/rollback0216_test.go | 2 +- internal/cli/rollback029_test.go | 2 +- internal/cli/rollback_email_test.go | 4 +- internal/cli/rollback_firewall_test.go | 2 +- internal/cli/rollback_reports_test.go | 4 +- internal/cli/rollback_target0222_test.go | 6 +- internal/cli/rollback_target0225_test.go | 6 +- internal/cli/rollback_target0227_test.go | 14 +- internal/cli/rollback_target0228_test.go | 174 ++++++++++++++++++ internal/cli/rollback_test.go | 4 +- internal/cli/testdata/usage/top.out | 2 +- internal/lifecycle/rollback.go | 46 +++-- internal/lifecycle/rollback0216_test.go | 2 +- internal/lifecycle/rollback0218.go | 2 +- internal/lifecycle/rollback0222.go | 4 +- internal/lifecycle/rollback0223.go | 6 +- internal/lifecycle/rollback0226.go | 6 +- internal/lifecycle/rollback0227.go | 31 ++-- internal/lifecycle/rollback0228.go | 39 ++++ internal/lifecycle/rollback0228_test.go | 167 +++++++++++++++++ internal/lifecycle/rollback_additions.go | 2 +- internal/lifecycle/rollback_email.go | 2 +- internal/lifecycle/rollback_firewall.go | 4 +- internal/lifecycle/rollback_lockdown_hosts.go | 2 +- internal/lifecycle/rollback_snmp_pool.go | 2 +- internal/lifecycle/rollback_staging.go | 2 +- internal/lifecycle/rollback_test.go | 12 +- internal/tier/report_limits_test.go | 22 +++ tests/integration/rollback.bats | 45 ++++- 32 files changed, 565 insertions(+), 99 deletions(-) create mode 100644 internal/cli/rollback_target0228_test.go create mode 100644 internal/lifecycle/rollback0228.go create mode 100644 internal/lifecycle/rollback0228_test.go diff --git a/internal/cli/completion_test.go b/internal/cli/completion_test.go index 661eb3ad..5d9d6b24 100644 --- a/internal/cli/completion_test.go +++ b/internal/cli/completion_test.go @@ -546,7 +546,7 @@ func TestCompleteThisReleasesWords(t *testing.T) { {[]string{"scope", "secret", "lab", "set", "--"}, []string{"--stdin"}, false}, {[]string{"user", "add", "x", "--"}, []string{"--hash"}, false}, {[]string{"user", "passwd", "x", "--"}, []string{"--hash"}, false}, - {[]string{"rollback", ""}, []string{"0.2.27", "0.2.26", "0.2.25", "0.2.24", "0.2.23", "0.2.22", "0.2.21", "0.2.20", "0.2.19", "0.2.18", "0.2.17", "0.2.16", "0.2.9", "0.2.3"}, true}, + {[]string{"rollback", ""}, []string{"0.2.28", "0.2.27", "0.2.26", "0.2.25", "0.2.24", "0.2.23", "0.2.22", "0.2.21", "0.2.20", "0.2.19", "0.2.18", "0.2.17", "0.2.16", "0.2.9", "0.2.3"}, true}, } for _, c := range cases { got, _ := completeWords(t, liveNames, c.words...) diff --git a/internal/cli/help_text.go b/internal/cli/help_text.go index 14ceab72..5e11d258 100644 --- a/internal/cli/help_text.go +++ b/internal/cli/help_text.go @@ -25,7 +25,7 @@ Commands: --yes Answer yes to the confirmations upgrade [--branch ] Pull latest source, rebuild, update scripts and every enabled backend uninstall [--yes] Remove tacctl, its backends' services and all associated files - rollback [options] Prepare the state for the release before this one (0.2.27), for 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 or 0.2.3: a dry run unless --apply + rollback [options] Prepare the state for the release before this one (0.2.28), for 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 or 0.2.3: a dry run unless --apply --apply Take a snapshot, then convert the files the target cannot read (tacctl.yaml, sudoers; for 0.2.3 also console.yaml, devices.yaml) --yes Acknowledge the warnings that --apply refuses to go on without --hosts Accepted; the hosts need nothing for this target (no host is synced) diff --git a/internal/cli/rollback.go b/internal/cli/rollback.go index 5f6123cd..ec3d3e07 100644 --- a/internal/cli/rollback.go +++ b/internal/cli/rollback.go @@ -3,7 +3,7 @@ package cli // 'tacctl rollback [--apply] [--yes] [--hosts]' (docs/plans/ // 0.2.3-plan.md D50, docs/plans/0.2.4-plan.md D73, docs/plans/ // 0.2.9-rollout-plan.md D143, docs/plans/0.2.10-plan.md): prepare tacctl's -// state for the release before this one (0.2.27), for 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, for 0.2.9 or for 0.2.3. The plan and the conversions of +// state for the release before this one (0.2.28), for 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, for 0.2.9 or for 0.2.3. The plan and the conversions of // the files are internal/lifecycle's (rollback.go); this is the command // around them: the arguments, what is printed, the snapshot and the // sudoers installer. @@ -33,7 +33,7 @@ const rollbackUsage = "Usage: tacctl rollback [--apply] [--yes] [--hos var rollbackSpec = Spec{ Flags: []Flag{{Names: []string{"--apply"}}, {Names: []string{"--yes"}}, {Names: []string{"--hosts"}}}, MinArgs: 1, MaxArgs: 1, - Args: []string{lifecycle.RollbackTarget0227 + "|" + lifecycle.RollbackTarget0226 + "|" + lifecycle.RollbackTarget0225 + "|" + lifecycle.RollbackTarget0224 + "|" + lifecycle.RollbackTarget0223 + "|" + lifecycle.RollbackTarget0222 + "|" + lifecycle.RollbackTarget0221 + "|" + lifecycle.RollbackTarget0220 + "|" + lifecycle.RollbackTarget0219 + "|" + lifecycle.RollbackTarget0218 + "|" + lifecycle.RollbackTarget0217 + "|" + lifecycle.RollbackTarget0216 + "|" + lifecycle.RollbackTarget029 + "|" + lifecycle.RollbackTarget}, + Args: []string{lifecycle.RollbackTarget0228 + "|" + lifecycle.RollbackTarget0227 + "|" + lifecycle.RollbackTarget0226 + "|" + lifecycle.RollbackTarget0225 + "|" + lifecycle.RollbackTarget0224 + "|" + lifecycle.RollbackTarget0223 + "|" + lifecycle.RollbackTarget0222 + "|" + lifecycle.RollbackTarget0221 + "|" + lifecycle.RollbackTarget0220 + "|" + lifecycle.RollbackTarget0219 + "|" + lifecycle.RollbackTarget0218 + "|" + lifecycle.RollbackTarget0217 + "|" + lifecycle.RollbackTarget0216 + "|" + lifecycle.RollbackTarget029 + "|" + lifecycle.RollbackTarget}, } func rollbackCmd(inv *invocation) *cobra.Command { @@ -269,6 +269,9 @@ func (inv *invocation) rollbackNextSteps(version string, snapshot, keys, fields defer inv.rollbackReportLimitsNote(version) } switch version { + case lifecycle.RollbackTarget0228: + inv.rollbackNextSteps0228(version) + return case lifecycle.RollbackTarget0227: inv.rollbackNextSteps0227(version, snapshot) return @@ -324,7 +327,7 @@ func (inv *invocation) rollbackNextSteps(version string, snapshot, keys, fields // its snapshot. It moves with each release (docs/releasing.md, The rollback // target); TestRollbackFromIsTheReleaseOfTheChangelog compares it with the // first release heading of CHANGELOG.md. -const rollbackFrom = "0.2.28" +const rollbackFrom = "0.2.29" // rollbackSnapshotNote says where the state before the rollback is, when the // apply took a snapshot (it takes none when no file of tacctl's own is @@ -339,7 +342,7 @@ func (inv *invocation) rollbackSnapshotNote(snapshot bool, tail string) { } // rollbackFirewallNote says, after a rollback that removed the break-glass -// firewall (every target but 0.2.27, 0.2.26, 0.2.25 and 0.2.24): what went and what stays, what a hold that stands +// firewall (every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25 and 0.2.24): what went and what stays, what a hold that stands // gets from the older release, and that the setting command writes the key it // refuses. func (inv *invocation) rollbackFirewallNote(version string, plan *lifecycle.RollbackPlan) { @@ -353,7 +356,7 @@ func (inv *invocation) rollbackFirewallNote(version string, plan *lifecycle.Roll } // rollbackEmailNote says, after a rollback that removed the users' email -// addresses (every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23), where they are and how they come back, and that +// addresses (every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23), where they are and how they come back, and that // the commands that set one write the key again. func (inv *invocation) rollbackEmailNote(version, snapID string, users []string) { n := len(users) @@ -445,31 +448,40 @@ func (inv *invocation) rollbackFileTransferNote(version string) { inv.echo("If one did, run 'tacctl rollback " + version + " --apply' again (it removes them).") } -// rollbackNextSteps0227 is the next steps of the rollback to 0.2.27: the -// upgrade of the tag. 0.2.27 reads every file this release writes but the -// file transfer settings of console.yaml, so the rollback converted nothing -// else and leaves no other command to avoid: the limits of the stored reports -// and the reports in the users' homes (the PDF ones too) stay, 0.2.27 has -// them. snapshot is whether it took the snapshot, which it does only for those -// settings; the note says why 0.2.27 cannot restore it. -func (inv *invocation) rollbackNextSteps0227(version string, snapshot bool) { +// rollbackNextSteps0228 is the next steps of the rollback to 0.2.28: the +// upgrade of the tag. 0.2.28 reads every file this release writes, so the +// rollback converted nothing, took no snapshot and leaves no command to avoid: +// the file transfer settings, the limits of the stored reports and the reports +// in the users' homes (the PDF ones too) stay, 0.2.28 has them. +func (inv *invocation) rollbackNextSteps0228(version string) { inv.echo("") inv.echo(ui.Bold + "Next steps" + ui.NC) inv.echo(" 1. Install " + version + " with the upgrade (see Upgrading in the README), which switches the clone in " + inv.app.Paths.Deploy + " to the tag, builds it and re-executes it:") inv.echo(" tacctl upgrade --branch " + version) inv.echo(" 2. Check it: tacctl status; tacctl config validate") +} + +// rollbackNextSteps0227 is the next steps of the rollback to 0.2.27: those of +// 0.2.28. 0.2.27 reads every file this release writes but the file transfer +// settings of console.yaml, so the rollback converted nothing else and leaves +// no other command to avoid: the limits of the stored reports and the reports +// in the users' homes (the PDF ones too) stay, 0.2.27 has them. snapshot is +// whether it took the snapshot, which it does only for those settings; the +// note says why 0.2.27 cannot restore it. +func (inv *invocation) rollbackNextSteps0227(version string, snapshot bool) { + inv.rollbackNextSteps0228(version) inv.rollbackSnapshotNote(snapshot, "; "+version+"'s restore puts back a console.yaml with a setting it does not know.") } // rollbackNextSteps0226 is the next steps of the rollback to 0.2.26: those of -// 0.2.27, which reads the same files (0.2.26 reads every file 0.2.27 and this -// release write but the file transfer settings). +// 0.2.27, which reads the same files (0.2.26 reads every file 0.2.27, 0.2.28 +// and this release write but the file transfer settings). func (inv *invocation) rollbackNextSteps0226(version string, snapshot bool) { inv.rollbackNextSteps0227(version, snapshot) } // rollbackNextSteps0225 is the next steps of the rollback to 0.2.25: the -// upgrade of the tag. 0.2.25 reads every file 0.2.26, 0.2.27 and this release write but the +// upgrade of the tag. 0.2.25 reads every file 0.2.26 to 0.2.28 and this release write but the // limits of the stored reports (rollbackReportLimitsNote, printed after these // steps, says that the reports stay in the users' homes and what to avoid), so // the rollback converted a file only when a limit was set; snapshot is whether diff --git a/internal/cli/rollback0216_test.go b/internal/cli/rollback0216_test.go index 90fa38d7..d3ca9ede 100644 --- a/internal/cli/rollback0216_test.go +++ b/internal/cli/rollback0216_test.go @@ -67,7 +67,7 @@ func TestRollback0216ApplyRoundTrip(t *testing.T) { hs.expect(0, "Applying.", "") out := hs.all() for _, want := range []string{"removed 1 key", "Next steps", "tacctl upgrade --branch 0.2.16", - "do not add the 'audit' setting (audit.strict)", "holds the 0.2.28 state"} { + "do not add the 'audit' setting (audit.strict)", "holds the 0.2.29 state"} { if !strings.Contains(out, want) { t.Errorf("--apply output lacks %q:\n%s", want, out) } diff --git a/internal/cli/rollback029_test.go b/internal/cli/rollback029_test.go index 75309bc3..9890005f 100644 --- a/internal/cli/rollback029_test.go +++ b/internal/cli/rollback029_test.go @@ -113,7 +113,7 @@ func TestRollback029ApplyRoundTrip(t *testing.T) { out := hs.all() for _, want := range []string{"Config snapshot saved to", "state/tacctl.yaml: removed 4 keys", "state/devices.yaml: removed the NETCONF service setting of 1 device", - "Next steps", "tacctl upgrade --branch 0.2.9", "holds the 0.2.28 state. Restore it with 0.2.28 only"} { + "Next steps", "tacctl upgrade --branch 0.2.9", "holds the 0.2.29 state. Restore it with 0.2.29 only"} { if !strings.Contains(out, want) { t.Errorf("--apply output lacks %q:\n%s", want, out) } diff --git a/internal/cli/rollback_email_test.go b/internal/cli/rollback_email_test.go index 23e4a1b7..65b58b3d 100644 --- a/internal/cli/rollback_email_test.go +++ b/internal/cli/rollback_email_test.go @@ -74,7 +74,7 @@ func TestRollbackWithAnEmailWarnsSnapshotsAndRemovesTheKey(t *testing.T) { for _, want := range []string{ "The email addresses of 2 users (bob, erin) were removed from the store; " + target + " does not know the key.", "They are in snapshot " + id + ", which is kept in " + kept + " (no retention reaches it; " + target + " prunes backups/ by its own):", - "once 0.2.28 is installed again, 'tacctl backup recover " + id + " --only email' puts them back; 'tacctl backup unkeep " + id + "' removes the kept copy after that.", + "once 0.2.29 is installed again, 'tacctl backup recover " + id + " --only email' puts them back; 'tacctl backup unkeep " + id + "' removes the kept copy after that.", "do not run 'tacctl user email' or 'tacctl user add --email'"} { if !strings.Contains(out, want) { t.Errorf("--apply lacks %q:\n%s", want, out) @@ -141,7 +141,7 @@ func TestRollback0222SnapshotFollowsTheAddress(t *testing.T) { hs.run(hs.runner(), "rollback", "0.2.22", "--apply", "--yes") hs.expect(0, "Applying.", "") out := hs.all() - if hs.snapshots() != snaps+1 || strings.Contains(out, "takes no snapshot") || !strings.Contains(out, "holds the 0.2.28 state. Restore it with 0.2.28 only") { + if hs.snapshots() != snaps+1 || strings.Contains(out, "takes no snapshot") || !strings.Contains(out, "holds the 0.2.29 state. Restore it with 0.2.29 only") { t.Errorf("with an address (snapshots %d -> %d):\n%s", snaps, hs.snapshots(), out) } if o := hs.overrides(); strings.Contains(o, "email") { diff --git a/internal/cli/rollback_firewall_test.go b/internal/cli/rollback_firewall_test.go index b3303bab..a1a05b39 100644 --- a/internal/cli/rollback_firewall_test.go +++ b/internal/cli/rollback_firewall_test.go @@ -55,7 +55,7 @@ func TestRollbackRemovesTheFirewall(t *testing.T) { "run no verb that changes the holds, their device or host names, the listeners or the setting ('tacctl breakglass hold|release', 'device address', 'device|host rename', 'device rename --replace', 'backup restore', 'server listen', 'config breakglass-firewall')", "each writes the table, its rules file and the boot unit again, and the setting 0.2.23 refuses", // the key was set: the apply took a snapshot, and the next steps say where the state is - "The snapshot the rollback took first (the newest entry of 'tacctl backup list') holds the 0.2.28 state. Restore it with 0.2.28 only:", + "The snapshot the rollback took first (the newest entry of 'tacctl backup list') holds the 0.2.29 state. Restore it with 0.2.29 only:", "0.2.23's restore refuses a tacctl.yaml with a key it does not know.", } { if !strings.Contains(out, want) { diff --git a/internal/cli/rollback_reports_test.go b/internal/cli/rollback_reports_test.go index 11d1a473..1c5a9114 100644 --- a/internal/cli/rollback_reports_test.go +++ b/internal/cli/rollback_reports_test.go @@ -37,7 +37,7 @@ func TestRollbackRemovesTheReportLimitsOfTheConfig(t *testing.T) { hs.run(hs.runner(), "rollback", target, "--apply") hs.expect(0, "tacctl upgrade --branch "+target, "") out = hs.all() - for _, want := range []string{"holds the 0.2.28 state", "The reports in the users' homes stay", "'tacctl config reports max-size', 'config reports max-count' or 'tacctl user reports-limit'", + for _, want := range []string{"holds the 0.2.29 state", "The reports in the users' homes stay", "'tacctl config reports max-size', 'config reports max-count' or 'tacctl user reports-limit'", target + " has no 'device reports' verbs"} { if !strings.Contains(out, want) { t.Errorf("--apply lacks %q:\n%s", want, out) @@ -108,7 +108,7 @@ func TestRollbackRemovesTheUsersReportLimits(t *testing.T) { "The own limits of the stored reports were removed from the store for 2 users; " + target + " does not know the keys:", " bob: max-size 20 MiB, max-count 50 reports", " erin: max-count no cap", "'tacctl user reports-limit max-size|max-count ' sets them again", - "holds the 0.2.28 state", "The reports in the users' homes stay"} { + "holds the 0.2.29 state", "The reports in the users' homes stay"} { if !strings.Contains(out, want) { t.Errorf("--apply lacks %q:\n%s", want, out) } diff --git a/internal/cli/rollback_target0222_test.go b/internal/cli/rollback_target0222_test.go index cfd2bbb5..d4a85d72 100644 --- a/internal/cli/rollback_target0222_test.go +++ b/internal/cli/rollback_target0222_test.go @@ -94,8 +94,8 @@ func TestRollback0222IsToldApartFromTheOlderTargets(t *testing.T) { if !strings.Contains(hs.all(), "Until the upgrade, do not run 'tacctl device timeout-scale'") { t.Errorf("0.2.21 lacks the note:\n%s", hs.all()) } - hs.run(hs.runner(), "rollback", "0.2.28") - hs.expect(1, "", "prepares the state for 0.2.27 (the release before this one), 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21") + hs.run(hs.runner(), "rollback", "0.2.29") + hs.expect(1, "", "prepares the state for 0.2.28 (the release before this one), 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21") } // The snapshot is announced, and its state named, only when the apply takes @@ -120,7 +120,7 @@ func TestRollbackSnapshotIsSpokenOfOnlyWhenTaken(t *testing.T) { if hs.snapshots() == snaps { t.Error("no snapshot was taken") } - for _, want := range []string{"--apply takes a snapshot of the state first", "holds the 0.2.28 state. Restore it with 0.2.28 only"} { + for _, want := range []string{"--apply takes a snapshot of the state first", "holds the 0.2.29 state. Restore it with 0.2.29 only"} { if !strings.Contains(out, want) { t.Errorf("0.2.21 with a file to convert lacks %q:\n%s", want, out) } diff --git a/internal/cli/rollback_target0225_test.go b/internal/cli/rollback_target0225_test.go index 00b4d8da..1eac0b09 100644 --- a/internal/cli/rollback_target0225_test.go +++ b/internal/cli/rollback_target0225_test.go @@ -64,7 +64,7 @@ func TestRollback0225ConvertsNothingWithoutLimits(t *testing.T) { } // The two settings of the file go after a snapshot and need no --yes; the -// users' own limits are data and need it. The snapshot holds the 0.2.28 state +// users' own limits are data and need it. The snapshot holds the 0.2.29 state // and the note says 0.2.25 cannot restore it; the reports in the homes and the // pull records are not touched. func TestRollback0225RemovesTheLimitsAfterASnapshot(t *testing.T) { @@ -112,7 +112,7 @@ func TestRollback0225RemovesTheLimitsAfterASnapshot(t *testing.T) { hs.expect(0, "Applying.", "") out = hs.all() for _, want := range []string{"tacctl.yaml: removed 2 keys", "store.yaml: removed the report limits of 1 user", " bob: max-count 7 reports", - "holds the 0.2.28 state", "0.2.25's restore refuses a tacctl.yaml with a key it does not know and a store.yaml with a field it does not know.", + "holds the 0.2.29 state", "0.2.25's restore refuses a tacctl.yaml with a key it does not know and a store.yaml with a field it does not know.", "tacctl upgrade --branch 0.2.25", "The reports in the users' homes stay", "0.2.25 has no 'device reports' verbs"} { if !strings.Contains(out, want) { t.Errorf("--apply lacks %q:\n%s", want, out) @@ -178,7 +178,7 @@ func TestRollbackSnapshotNoteNamesWhatTheRestoreRefuses(t *testing.T) { hs.run(hs.runner(), "rollback", c.target, "--apply", "--yes") hs.expect(0, "Applying.", "") out := hs.all() - if !strings.Contains(out, "holds the 0.2.28 state") || !strings.Contains(out, c.target+c.tail) { + if !strings.Contains(out, "holds the 0.2.29 state") || !strings.Contains(out, c.target+c.tail) { t.Errorf("the note lacks %q:\n%s", c.target+c.tail, out) } if c.tail == fieldsTail && strings.Contains(out, "a tacctl.yaml with a key") { diff --git a/internal/cli/rollback_target0227_test.go b/internal/cli/rollback_target0227_test.go index 46460a93..eb6dfacb 100644 --- a/internal/cli/rollback_target0227_test.go +++ b/internal/cli/rollback_target0227_test.go @@ -9,7 +9,7 @@ import ( "github.com/rett/tacctl/internal/tier" ) -// 'tacctl rollback 0.2.27', the release before this one, on the host sandbox +// 'tacctl rollback 0.2.27', the release before 0.2.28, on the host sandbox // with this server enrolled. The plan's own cases are internal/lifecycle's. // rollback0227State is rollback0221State with this release's per-tier sudoers @@ -163,12 +163,12 @@ func TestRollback0227LeavesTheDropIn(t *testing.T) { hs.expect(0, "put back the per-tier sudoers drop-in 0.2.25 writes", "") } -// 0.2.27 is the release before this one; this release is not a target, and -// the refusal names 0.2.27 first. -func TestRollback0227IsTheReleaseBeforeThisOne(t *testing.T) { +// 0.2.27 is the release before 0.2.28; this release is not a target, and the +// refusal names 0.2.28 as the release before this one, and 0.2.27 after it. +func TestRollback0227IsAccepted(t *testing.T) { hs := rollback0227State(t) - hs.run(hs.runner(), "rollback", "0.2.28") - hs.expect(1, "", "prepares the state for 0.2.27 (the release before this one), 0.2.26, 0.2.25, 0.2.24, 0.2.23") + hs.run(hs.runner(), "rollback", "0.2.29") + hs.expect(1, "", "prepares the state for 0.2.28 (the release before this one), 0.2.27, 0.2.26, 0.2.25, 0.2.24") hs.run(hs.runner(), "rollback", "v0.2.27") hs.expect(0, "Roll back to 0.2.27 (dry run)", "") } @@ -209,7 +209,7 @@ func TestRollback0227RemovesTheFileTransferSettings(t *testing.T) { hs.expect(0, "", "") out = hs.all() for _, want := range []string{"console.yaml: removed settings.file_transfer", "tacctl upgrade --branch 0.2.27", - "Restore it with 0.2.28 only", "0.2.27's restore puts back a console.yaml with a setting it does not know", + "Restore it with 0.2.29 only", "0.2.27's restore puts back a console.yaml with a setting it does not know", "Until the upgrade, do not run 'tacctl console file-transfer' with a tier, a user, a quota or a rate to set"} { if !strings.Contains(out, want) { t.Errorf("--apply lacks %q:\n%s", want, out) diff --git a/internal/cli/rollback_target0228_test.go b/internal/cli/rollback_target0228_test.go new file mode 100644 index 00000000..afa06b14 --- /dev/null +++ b/internal/cli/rollback_target0228_test.go @@ -0,0 +1,174 @@ +package cli + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/rett/tacctl/internal/tier" +) + +// 'tacctl rollback 0.2.28', the release before this one, on the host sandbox +// with this server enrolled. The plan's own cases are internal/lifecycle's. + +// This release changed no stored file 0.2.28 reads strictly, so 0.2.28 reads +// everything: the dry run lists nothing to do and --apply converts nothing, +// even with the console's file transfer settings, an email address in the +// store, the break-glass firewall and the limits of the stored reports set, +// takes no snapshot, asks for no --yes and leaves a pull record, a report (a +// PDF one too) and the marker of the offer of the PDF tools byte for byte. A +// second run does the same. +func TestRollback0228ConvertsNothing(t *testing.T) { + hs := rollback0227State(t) + hs.step("", "user", "email", "bob", "bob@example.net") + hs.step("", "server", "name", "core-1") + hs.step("", "config", "reports", "max-size", "20Mi") + hs.step("", "config", "reports", "max-count", "0") + hs.step("", "user", "reports-limit", "bob", "max-count", "7") + hs.step("", "console", "file-transfer", "operator", "enable") + hs.step("", "console", "file-transfer", "quota", "operator", "1G") + hs.step("", "console", "file-transfer", "user", "bob", "disable") + if y := hs.read("state/console.yaml"); !strings.Contains(y, "file_transfer:") { + t.Fatalf("console.yaml:\n%s", y) + } + hs.write("state/tacctl.yaml", hs.read("state/tacctl.yaml")+"breakglass:\n firewall: drop\n", 0o640) + record := `{"version": 1, "devices": {"sw1": {"address": "192.0.2.11", "vendor": "juniper", "serial": "SN000001", + "members": [{"id": "0", "role": "master", "model": "EX4300-48T", "serial": "SN000001", "release": "21.4R3", "status": "present", "priority": 255, "components": []}]}}} +` + hs.write("var-lib/devices-config.json", record, 0o600) + report := filepath.Join(hs.dir, "home", "alice", "reports", "devices", "inventory-20261106.txt") + if err := os.MkdirAll(filepath.Dir(report), 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(report, []byte("sw1 EX4300-48T SN000001\n"), 0o600); err != nil { + t.Fatal(err) + } + pdf := filepath.Join(hs.dir, "home", "alice", "reports", "devices", "inventory-20261107.pdf") + if err := os.WriteFile(pdf, []byte("%PDF-1.7\n"), 0o600); err != nil { + t.Fatal(err) + } + hs.write("var-lib/pdf-tools-offered", "tacctl 0.2.27 offered\n", 0o644) + consoleYAML := hs.read("state/console.yaml") + before := tree(t, hs.dir) + hs.run(hs.runner(), "rollback", "0.2.28", "--hosts") + hs.expect(0, "This was a dry run: nothing was changed.", "") + out := hs.all() + for _, want := range []string{"Roll back to 0.2.28 (dry run)", "nothing to remove (every key of tacctl.yaml is one 0.2.28 knows)", + "--apply converts no file of tacctl's own and takes no snapshot", + "nothing to do for 0.2.28: this release changed nothing on the enrolled hosts", "To convert the state: tacctl rollback 0.2.28 --apply"} { + if !strings.Contains(out, want) { + t.Errorf("the dry run lacks %q:\n%s", want, out) + } + } + for _, not := range []string{"remove email", "remove server", "remove breakglass", "remove reports", "remove settings", "file_transfer", "firewall", "[does]", "add scope", "Warnings", "--yes", "email", "report limits", "Limits of the stored"} { + if strings.Contains(out, not) { + t.Errorf("the dry run says %q:\n%s", not, out) + } + } + if got := changedFiles(before, tree(t, hs.dir)); len(got) != 0 { + t.Errorf("the dry run changed %q", got) + } + snaps := hs.snapshots() + for i := 0; i < 2; i++ { + hs.run(hs.runner(), "rollback", "0.2.28", "--apply") + hs.expect(0, "Nothing to convert: every file is one 0.2.28 can read.", "") + out = hs.all() + if !strings.Contains(out, "tacctl upgrade --branch 0.2.28") { + t.Errorf("--apply lacks the upgrade:\n%s", out) + } + for _, not := range []string{"holds the", "took first", "Until the upgrade", "firewall is removed", "The reports in the users' homes stay", "restore refuses", "restore puts back"} { + if strings.Contains(out, not) { + t.Errorf("--apply (run %d) says %q:\n%s", i+1, not, out) + } + } + if hs.snapshots() != snaps { + t.Errorf("run %d took a snapshot: there is nothing to convert", i+1) + } + if got := changedFiles(before, tree(t, hs.dir)); len(got) != 0 { + t.Errorf("--apply (run %d) changed %q", i+1, got) + } + } + if got := hs.read("state/console.yaml"); got != consoleYAML { + t.Errorf("console.yaml changed:\n%s", got) + } + if got := hs.read("var-lib/devices-config.json"); got != record { + t.Errorf("the pull record changed:\n%s", got) + } + if got, err := os.ReadFile(report); err != nil || string(got) != "sw1 EX4300-48T SN000001\n" { + t.Errorf("the report: %q %v", got, err) + } + if got, err := os.ReadFile(pdf); err != nil || string(got) != "%PDF-1.7\n" { + t.Errorf("the PDF report: %q %v", got, err) + } + if got := hs.read("var-lib/pdf-tools-offered"); got != "tacctl 0.2.27 offered\n" { + t.Errorf("the marker of the PDF offer: %q", got) + } + o, s := hs.overrides(), hs.store() + if !strings.Contains(s, "email:") || !strings.Contains(o, "name: core-1") || !strings.Contains(o, "firewall: drop") || + !strings.Contains(o, "max_size: 20971520") || !strings.Contains(o, "max_count: 0") || !strings.Contains(s, "reports_max_count") { + t.Errorf("a key or a field was lost:\n%s\n%s", o, s) + } +} + +// The 0.2.27 target is told apart from 0.2.28 on the same state: it takes the +// file transfer settings out of console.yaml (0.2.27 refuses the key) after a +// snapshot, which 0.2.28 keeps. An emergency lockdown on the scope the +// enrolled host answers stays in both, and the older targets refuse it. +func TestRollback0228IsToldApartFromTheOlderTargets(t *testing.T) { + hs := rollback0227State(t) + hs.step("", "console", "file-transfer", "operator", "enable") + hs.run(hs.runner(), "rollback", "0.2.27") + hs.expect(0, "remove settings.file_transfer", "") + hs.run(hs.runner(), "rollback", "0.2.28") + hs.expect(0, "nothing to remove (every key of tacctl.yaml is one 0.2.28 knows)", "") + if strings.Contains(hs.all(), "settings.file_transfer") { + t.Errorf("0.2.28 removes a setting it has:\n%s", hs.all()) + } + + hs.write("state/tacctl.yaml", hs.read("state/tacctl.yaml")+"emergency:\n lockdown:\n tacctl:\n groups:\n - operator\n since: '2026-10-25T12:00:00+00:00'\n by: alice\n reason: drill\n", 0o640) + before := tree(t, hs.dir) + hs.run(hs.runner(), "rollback", "0.2.28", "--apply") + hs.expect(0, "Nothing to convert: every file is one 0.2.28 can read.", "") + if o := hs.overrides(); !strings.Contains(o, "lockdown:") || !strings.Contains(o, "reason: drill") { + t.Errorf("tacctl.yaml after --apply:\n%s", o) + } + if y := hs.read("state/console.yaml"); !strings.Contains(y, "file_transfer:") { + t.Errorf("console.yaml lost the settings:\n%s", y) + } + if got := changedFiles(before, tree(t, hs.dir)); len(got) != 0 { + t.Errorf("the rollback to 0.2.28 changed %q", got) + } + for _, v := range []string{"0.2.22", "0.2.21"} { + hs.run(hs.runner(), "rollback", v) + hs.expect(1, "", "Scope tacctl is locked down and has enrolled hosts (authsrv)") + } +} + +// The per-tier drop-in is this release's text and 0.2.28 wrote the same, so +// it is left; the 0.2.25 target puts back its own, without the rows of +// 'device reports'. +func TestRollback0228LeavesTheDropIn(t *testing.T) { + hs := rollback0227State(t) + before := tree(t, hs.dir) + hs.run(hs.runner(), "rollback", "0.2.28", "--apply") + hs.expect(0, "Nothing to convert: every file is one 0.2.28 can read.", "") + if got := hs.read("sudoers.d/tacctl-tiers"); got != tier.Sudoers() { + t.Errorf("the tiers drop-in changed:\n%s", got) + } + if got := changedFiles(before, tree(t, hs.dir)); len(got) != 0 { + t.Errorf("--apply changed %q", got) + } + hs.run(hs.runner(), "rollback", "0.2.25") + hs.expect(0, "put back the per-tier sudoers drop-in 0.2.25 writes", "") +} + +// 0.2.28 is the release before this one; this release is not a target, and +// the refusal names 0.2.28 first. +func TestRollback0228IsTheReleaseBeforeThisOne(t *testing.T) { + hs := rollback0227State(t) + hs.run(hs.runner(), "rollback", "0.2.29") + hs.expect(1, "", "'0.2.29' is not a release to roll back to: 'tacctl rollback' prepares the state for 0.2.28 (the release before this one), 0.2.27, 0.2.26, 0.2.25, 0.2.24") + hs.run(hs.runner(), "rollback", "v0.2.28") + hs.expect(0, "Roll back to 0.2.28 (dry run)", "") +} diff --git a/internal/cli/rollback_test.go b/internal/cli/rollback_test.go index dbe50d6a..c11c04b2 100644 --- a/internal/cli/rollback_test.go +++ b/internal/cli/rollback_test.go @@ -306,7 +306,7 @@ func TestRollbackRoundTrip(t *testing.T) { for _, want := range []string{"Config snapshot saved to", "state/tacctl.yaml: removed 3 keys", "state/console.yaml: removed settings.password_cache", "state/devices.yaml: removed the SNMP settings of 2 devices", "sudoers.d/tacctl-tiers: rewritten with the text 0.2.3 writes", "sudoers.d/tacctl: rewritten with the text 0.2.3 writes", - "Next steps", "tacctl upgrade --branch 0.2.3", "holds the 0.2.28 state. Restore it with 0.2.28 only"} { + "Next steps", "tacctl upgrade --branch 0.2.3", "holds the 0.2.29 state. Restore it with 0.2.29 only"} { if !strings.Contains(out, want) { t.Errorf("--apply output lacks %q:\n%s", want, out) } @@ -717,7 +717,7 @@ func TestRollbackCompletion(t *testing.T) { words []string want []string }{ - {[]string{"rollback", ""}, []string{"0.2.27", "0.2.26", "0.2.25", "0.2.24", "0.2.23", "0.2.22", "0.2.21", "0.2.20", "0.2.19", "0.2.18", "0.2.17", "0.2.16", "0.2.9", "0.2.3"}}, + {[]string{"rollback", ""}, []string{"0.2.28", "0.2.27", "0.2.26", "0.2.25", "0.2.24", "0.2.23", "0.2.22", "0.2.21", "0.2.20", "0.2.19", "0.2.18", "0.2.17", "0.2.16", "0.2.9", "0.2.3"}}, {[]string{"rollback", "0.2.3", ""}, []string{"--apply", "--yes", "--hosts"}}, {[]string{"rollback", "0.2.3", "--apply", ""}, []string{"--yes", "--hosts"}}, {[]string{"rollback", "0.2.3", "--apply", "--yes", "--hosts", ""}, nil}, diff --git a/internal/cli/testdata/usage/top.out b/internal/cli/testdata/usage/top.out index 7a1b18be..d0c78e39 100644 --- a/internal/cli/testdata/usage/top.out +++ b/internal/cli/testdata/usage/top.out @@ -11,7 +11,7 @@ Commands: --yes Answer yes to the confirmations upgrade [--branch ] Pull latest source, rebuild, update scripts and every enabled backend uninstall [--yes] Remove tacctl, its backends' services and all associated files - rollback [options] Prepare the state for the release before this one (0.2.27), for 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 or 0.2.3: a dry run unless --apply + rollback [options] Prepare the state for the release before this one (0.2.28), for 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 or 0.2.3: a dry run unless --apply --apply Take a snapshot, then convert the files the target cannot read (tacctl.yaml, sudoers; for 0.2.3 also console.yaml, devices.yaml) --yes Acknowledge the warnings that --apply refuses to go on without --hosts Accepted; the hosts need nothing for this target (no host is synced) diff --git a/internal/lifecycle/rollback.go b/internal/lifecycle/rollback.go index e0645959..67182f72 100644 --- a/internal/lifecycle/rollback.go +++ b/internal/lifecycle/rollback.go @@ -6,10 +6,11 @@ package lifecycle // one. The command (internal/cli/rollback.go) adds what needs the // invocation: the snapshot and the sudoers installer. // -// The targets are 0.2.27 (the release before this one: RollbackTarget0227; -// rollback0227.go: nothing, this release changed no stored file 0.2.27 reads -// strictly), 0.2.26 (RollbackTarget0226; rollback0226.go: nothing, 0.2.27 and -// this release changed no stored file it reads strictly), 0.2.25 (RollbackTarget0225; rollback0225.go: the limits of the +// The targets are 0.2.28 (the release before this one: RollbackTarget0228; +// rollback0228.go: nothing, this release changed no stored file 0.2.28 reads +// strictly), 0.2.27 (RollbackTarget0227; rollback0227.go: the file transfer +// settings of console.yaml, which 0.2.28 added), 0.2.26 (RollbackTarget0226; +// rollback0226.go: the same, 0.2.27 reads what 0.2.26 reads), 0.2.25 (RollbackTarget0225; rollback0225.go: the limits of the // stored reports, which are keys and fields it refuses, and the per-tier // sudoers drop-in), 0.2.24 // (RollbackTarget0224; rollback0224.go: the same, 0.2.24 and 0.2.25 read the @@ -132,7 +133,7 @@ package lifecycle // // The SNMP credential files (0.2.23, version 2: a pool of v3 users and a // default) are a format every older release refuses, so every target but -// 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 writes them as version 1 again, keeping each level's +// 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 writes them as version 1 again, keeping each level's // default user and dropping the rest, with a warning that names the levels and counts the users, and refuses // a level with several users and no default (rollback_snmp_pool.go, an entry // of rollbackAdditions); 'tacctl backup recover --only snmp-users' puts the @@ -203,7 +204,8 @@ import ( // break-glass firewall, RollbackTarget0224 the one before the limits of the // stored reports (it reads what 0.2.25 reads), RollbackTarget0225 the one // before the limits of the stored reports, RollbackTarget0226 the one before -// the PDF reports and RollbackTarget0227 the release before this one (0.2.10 to 0.2.16 changed no format 0.2.9 reads strictly, so 0.2.9 stays a +// the PDF reports, RollbackTarget0227 the one before the console's file +// transfer settings and RollbackTarget0228 the release before this one (0.2.10 to 0.2.16 changed no format 0.2.9 reads strictly, so 0.2.9 stays a // target; 0.2.18 changed none 0.2.16 or 0.2.17 reads, so 0.2.16 stays one // too). const ( @@ -221,6 +223,7 @@ const ( RollbackTarget0225 = "0.2.25" RollbackTarget0226 = "0.2.26" RollbackTarget0227 = "0.2.27" + RollbackTarget0228 = "0.2.28" ) // RollbackRefusal is a version the command does not take: Lines say why. @@ -304,9 +307,9 @@ func pluralWord(n int, one, many string) string { var reVersion = regexp.MustCompile(`^v?([0-9]+)\.([0-9]+)\.([0-9]+)$`) -const rollbackUsage = "Usage: tacctl rollback " + RollbackTarget0227 + "|" + RollbackTarget0226 + "|" + RollbackTarget0225 + "|" + RollbackTarget0224 + "|" + RollbackTarget0223 + "|" + RollbackTarget0222 + "|" + RollbackTarget0221 + "|" + RollbackTarget0220 + "|" + RollbackTarget0219 + "|" + RollbackTarget0218 + "|" + RollbackTarget0217 + "|" + RollbackTarget0216 + "|" + RollbackTarget029 + "|" + RollbackTarget + " [--apply] [--yes] [--hosts]" +const rollbackUsage = "Usage: tacctl rollback " + RollbackTarget0228 + "|" + RollbackTarget0227 + "|" + RollbackTarget0226 + "|" + RollbackTarget0225 + "|" + RollbackTarget0224 + "|" + RollbackTarget0223 + "|" + RollbackTarget0222 + "|" + RollbackTarget0221 + "|" + RollbackTarget0220 + "|" + RollbackTarget0219 + "|" + RollbackTarget0218 + "|" + RollbackTarget0217 + "|" + RollbackTarget0216 + "|" + RollbackTarget029 + "|" + RollbackTarget + " [--apply] [--yes] [--hosts]" -// CheckRollbackVersion is the version a rollback is asked for ("0.2.27", "0.2.26", "0.2.25", "0.2.24", "0.2.23", "0.2.22", "0.2.21", +// CheckRollbackVersion is the version a rollback is asked for ("0.2.28", "0.2.27", "0.2.26", "0.2.25", "0.2.24", "0.2.23", "0.2.22", "0.2.21", // "0.2.20", "0.2.19", "0.2.18", "0.2.17", "0.2.16", "0.2.9", "0.2.3" or any with a "v"), or a *RollbackRefusal: 0.2.4 // to 0.2.8 and older than 0.2.3 (a release's tool prepares the state for the // releases it knows, so the way back is one release at a time), 0.2.10 to @@ -321,11 +324,11 @@ func CheckRollbackVersion(arg string) (string, error) { rollbackUsage}} } v := strings.TrimPrefix(arg, "v") - if v == RollbackTarget || v == RollbackTarget029 || v == RollbackTarget0216 || v == RollbackTarget0217 || v == RollbackTarget0218 || v == RollbackTarget0219 || v == RollbackTarget0220 || v == RollbackTarget0221 || v == RollbackTarget0222 || v == RollbackTarget0223 || v == RollbackTarget0224 || v == RollbackTarget0225 || v == RollbackTarget0226 || v == RollbackTarget0227 { + if v == RollbackTarget || v == RollbackTarget029 || v == RollbackTarget0216 || v == RollbackTarget0217 || v == RollbackTarget0218 || v == RollbackTarget0219 || v == RollbackTarget0220 || v == RollbackTarget0221 || v == RollbackTarget0222 || v == RollbackTarget0223 || v == RollbackTarget0224 || v == RollbackTarget0225 || v == RollbackTarget0226 || v == RollbackTarget0227 || v == RollbackTarget0228 { return v, nil } n := func(i int) int { x, _ := strconv.Atoi(m[i]); return x } - both := "'tacctl rollback' prepares the state for " + RollbackTarget0227 + " (the release before this one), " + RollbackTarget0226 + ", " + RollbackTarget0225 + ", " + RollbackTarget0224 + ", " + RollbackTarget0223 + ", " + RollbackTarget0222 + ", " + RollbackTarget0221 + ", " + RollbackTarget0220 + ", " + RollbackTarget0219 + ", " + RollbackTarget0218 + ", " + RollbackTarget0217 + ", " + RollbackTarget0216 + ", " + RollbackTarget029 + " and " + RollbackTarget + " only" + both := "'tacctl rollback' prepares the state for " + RollbackTarget0228 + " (the release before this one), " + RollbackTarget0227 + ", " + RollbackTarget0226 + ", " + RollbackTarget0225 + ", " + RollbackTarget0224 + ", " + RollbackTarget0223 + ", " + RollbackTarget0222 + ", " + RollbackTarget0221 + ", " + RollbackTarget0220 + ", " + RollbackTarget0219 + ", " + RollbackTarget0218 + ", " + RollbackTarget0217 + ", " + RollbackTarget0216 + ", " + RollbackTarget029 + " and " + RollbackTarget + " only" fallback := "The fallback that needs no tool is 'tacctl backup restore' of a snapshot of the time (see 'tacctl backup list')." switch { case n(1) == 0 && n(2) == 2 && n(3) > 3 && n(3) < 9: @@ -422,7 +425,7 @@ type RollbackInput struct { HasStore bool // WithHosts: the command was given --hosts. WithHosts bool - // Target is the release rolled back to: RollbackTarget0227, RollbackTarget0226, RollbackTarget0225, RollbackTarget0224, RollbackTarget0219, + // Target is the release rolled back to: RollbackTarget0228, RollbackTarget0227, RollbackTarget0226, RollbackTarget0225, RollbackTarget0224, RollbackTarget0219, // RollbackTarget0218, RollbackTarget0217, RollbackTarget0216, RollbackTarget029 or RollbackTarget (the zero value is 0.2.3, as // before 0.2.9). Target string @@ -630,19 +633,28 @@ func planRollback(in RollbackInput) (*RollbackPlan, error) { if len(pend) > 0 { return nil, PendingRefusal(pend) } - // 0.2.27 reads every file this release writes: it converts nothing - // (rollback0227.go), and has the managed scope of the server's own login, + // 0.2.28 reads every file this release writes: it converts nothing + // (rollback0228.go), and has the managed scope of the server's own login, // so nothing is added to the users. + if in.Target == RollbackTarget0228 { + return planRollback0228(p) + } + // 0.2.27 reads every file this release writes but the file transfer + // settings of console.yaml (an entry of rollbackAdditions, as for every + // older target): it converts nothing else (rollback0227.go), and has the + // managed scope of the server's own login, so nothing is added to the + // users. if in.Target == RollbackTarget0227 { return planRollback0227(p) } - // 0.2.26 reads every file 0.2.27 and this release write: it converts - // nothing (rollback0226.go), and has the managed scope of the server's own - // login, so nothing is added to the users. + // 0.2.26 reads every file 0.2.27, 0.2.28 and this release write but the + // file transfer settings of console.yaml (an entry of rollbackAdditions): it + // converts nothing else (rollback0226.go), and has the managed scope of the + // server's own login, so nothing is added to the users. if in.Target == RollbackTarget0226 { return planRollback0226(p) } - // 0.2.25 reads every file 0.2.26, 0.2.27 and this release write but what a step of + // 0.2.25 reads every file 0.2.26 to 0.2.28 and this release write but what a step of // rollbackAdditions undoes and the key list (rollback0225.go): the limits // of the stored reports, and the per-tier sudoers drop-in; it has the // managed scope of the server's own login, so nothing is added to the diff --git a/internal/lifecycle/rollback0216_test.go b/internal/lifecycle/rollback0216_test.go index ab22c9d0..a13db7e5 100644 --- a/internal/lifecycle/rollback0216_test.go +++ b/internal/lifecycle/rollback0216_test.go @@ -187,7 +187,7 @@ func TestCheckRollbackVersion0216(t *testing.T) { t.Errorf("%s: %q %v", ok, v, err) } } - for _, bad := range []string{"0.2.15", "0.2.10", "0.2.28", "0.2.160", "0.2.170"} { + for _, bad := range []string{"0.2.15", "0.2.10", "0.2.29", "0.2.160", "0.2.170"} { if _, err := CheckRollbackVersion(bad); err == nil { t.Errorf("%s was accepted", bad) } diff --git a/internal/lifecycle/rollback0218.go b/internal/lifecycle/rollback0218.go index 80724641..6767edaa 100644 --- a/internal/lifecycle/rollback0218.go +++ b/internal/lifecycle/rollback0218.go @@ -123,7 +123,7 @@ func (p *RollbackPlan) lockdownKeysStep(target string) RollbackStep { s.Lines = []string{"nothing to remove (no server address, server name or timeout scale is set)"} case RollbackTarget0221: s.Lines = []string{"nothing to remove (no server name or timeout scale is set)"} - case RollbackTarget0222, RollbackTarget0223, RollbackTarget0224, RollbackTarget0225, RollbackTarget0226, RollbackTarget0227: + case RollbackTarget0222, RollbackTarget0223, RollbackTarget0224, RollbackTarget0225, RollbackTarget0226, RollbackTarget0227, RollbackTarget0228: s.Lines = []string{"nothing to remove (every key of tacctl.yaml is one " + target + " knows)"} } return s diff --git a/internal/lifecycle/rollback0222.go b/internal/lifecycle/rollback0222.go index 296c5d3c..83e54b89 100644 --- a/internal/lifecycle/rollback0222.go +++ b/internal/lifecycle/rollback0222.go @@ -1,10 +1,10 @@ package lifecycle // The rollback to 0.2.22, the release before 0.2.23 (rollback0223.go). -// 0.2.22 reads every file 0.2.23 to 0.2.27 and this release write but what a step of +// 0.2.22 reads every file 0.2.23 to 0.2.28 and this release write but what a step of // rollbackAdditions (rollback_additions.go) undoes, so the plan of the target converts nothing // of its own: it leaves every file alone but the per-tier sudoers drop-in -// when it is exactly this release's text (the same as 0.2.27's and 0.2.26's), 0.2.25's or 0.2.23's (it loses the engineer's +// when it is exactly this release's text (the same as 0.2.28's, 0.2.27's and 0.2.26's), 0.2.25's or 0.2.23's (it loses the engineer's // row of 'device clone', tier.Sudoers0222, and the same goes for 0.2.21 and // 0.2.20, which wrote the same text), and a change of this release that // 0.2.22 refuses (the users' email addresses, rollback_email.go) is a step of diff --git a/internal/lifecycle/rollback0223.go b/internal/lifecycle/rollback0223.go index cf0b4a4b..dbb38bd7 100644 --- a/internal/lifecycle/rollback0223.go +++ b/internal/lifecycle/rollback0223.go @@ -3,9 +3,9 @@ package lifecycle // The rollback to 0.2.23, the release before 0.2.24 (rollback0224.go). 0.2.24 // changed no stored file 0.2.23 reads strictly but the break-glass firewall // setting (a step of rollbackAdditions undoes it, rollback_firewall.go), so -// 0.2.23 reads every file 0.2.24 to 0.2.27 and this release write, and the plan of the +// 0.2.23 reads every file 0.2.24 to 0.2.28 and this release write, and the plan of the // target converts nothing but the per-tier sudoers drop-in: when it is -// exactly the text of 0.2.24 and 0.2.25, or the one 0.2.26, 0.2.27 and this release +// exactly the text of 0.2.24 and 0.2.25, or the one 0.2.26 to 0.2.28 and this release // write (with the rows of 'device reports' more), it is rewritten with // 0.2.23's (tier.Sudoers0223, without the operator's 'log failures *', which // 0.2.23 does not know; sudo would accept the row, but 0.2.23's upgrade @@ -50,7 +50,7 @@ func planRollback0223(p *RollbackPlan) (*RollbackPlan, error) { } // tiers0223Step plans the per-tier sudoers drop-in for the target: exactly -// the text of 0.2.24 and 0.2.25, or the one of 0.2.26, 0.2.27 and this release, is rewritten with 0.2.23's (tier.Sudoers0223), which +// the text of 0.2.24 and 0.2.25, or the one of 0.2.26 to 0.2.28 and this release, is rewritten with 0.2.23's (tier.Sudoers0223), which // takes out the operator's row of 'log failures *'. A file that is already // that text, or absent, needs no step; any other text is left and said so. func (p *RollbackPlan) tiers0223Step(target string) []RollbackStep { diff --git a/internal/lifecycle/rollback0226.go b/internal/lifecycle/rollback0226.go index 61f85df5..8a6f61f4 100644 --- a/internal/lifecycle/rollback0226.go +++ b/internal/lifecycle/rollback0226.go @@ -11,9 +11,9 @@ package lifecycle // two notes, and the documentation. The stored state files, the per-tier // sudoers text, the keys of tacctl.yaml, the fields of the store and the // format of the pull records are all as 0.2.26 reads them. So 0.2.26 reads -// every file 0.2.27 and this release write and the plan of the target +// every file 0.2.27, 0.2.28 and this release write and the plan of the target // converts nothing: it leaves every file alone, the per-tier sudoers drop-in -// included (0.2.26, 0.2.27 and this release write the same text), removes no +// included (0.2.26 to 0.2.28 and this release write the same text), removes no // key (the limits of the stored reports, reports.max_size and // reports.max_count in tacctl.yaml and a user's own limits in the store, stay: // 0.2.26 has them) and takes no snapshot but for the file below. The reports in the users' homes @@ -26,7 +26,7 @@ package lifecycle // releases changed, for the targets older than the release that made the // change. // -// What 0.2.27 and this release changed outside the stored files is 0.2.26's to +// What 0.2.27, 0.2.28 and this release changed outside the stored files is 0.2.26's to // undo or keep, and needs no step here: the next 'device config pull' with // 0.2.26 records a stack member with a blank H/W version column as it did // before (the row is not read), and a report made by a user below the diff --git a/internal/lifecycle/rollback0227.go b/internal/lifecycle/rollback0227.go index 9631b82a..f1105ce7 100644 --- a/internal/lifecycle/rollback0227.go +++ b/internal/lifecycle/rollback0227.go @@ -1,7 +1,7 @@ package lifecycle -// The rollback to 0.2.27, the release before this one. This release changed -// one stored file 0.2.27 reads strictly: console.yaml, which gained +// The rollback to 0.2.27, the release before 0.2.28 (rollback0228.go). 0.2.28 +// changed one stored file 0.2.27 reads strictly: console.yaml, which gained // settings.file_transfer (the console's file transfer, off by default, per // tier and per user, with a quota and a rate), a key 0.2.27's reader answers // with "settings: unknown key 'file_transfer'" (the console then falls back to @@ -9,34 +9,37 @@ package lifecycle // when the key is there the plan removes it, after the snapshot --apply takes // first, and keeps every other setting; rollback_filetransfer.go is that step, // an entry of rollbackAdditions that every older target has too. With the -// settings unset the plan converts nothing, as the rest of this release's +// settings unset the plan converts nothing, as the rest of 0.2.28's // changes need no conversion. // -// What else this release changed is the code that reads the answer of a +// What else 0.2.28 changed is the code that reads the answer of a // Cisco IOS device to a long command (the tail of the echo that the device // cuts and redraws is dropped as well, so a support bundle no longer starts -// its identity lines with it), and the documentation. The stored state files, +// its identity lines with it), and the documentation; this release changed +// the mode of a file uploaded through the console, a test and the +// documentation. The stored state files, // the per-tier sudoers text, the keys of tacctl.yaml, the fields of the store, // the format of the pull records and of the reports in the users' homes are -// all as 0.2.27 reads them. So 0.2.27 reads every other file this one writes -// and the plan of the target leaves them alone, the per-tier sudoers drop-in -// included (0.2.27 and this release write the same text), removes no key of +// all as 0.2.27 reads them. So 0.2.27 reads every other file 0.2.28 and this +// release write and the plan of the target leaves them alone, the per-tier +// sudoers drop-in included (0.2.27 to 0.2.28 and this release write the same +// text), removes no key of // tacctl.yaml (the limits of the stored reports, reports.max_size and // reports.max_count in tacctl.yaml and a user's own limits in the store, stay: // 0.2.27 has them) and takes a snapshot only for the file transfer settings. // The reports in the users' homes stay too, the PDF ones included (0.2.27 // reads them), and so does the marker /var/lib/tacctl/pdf-tools-offered, which -// this release and 0.2.27 write alike. No other step of rollbackAdditions +// 0.2.27 and the ones after it write alike. No other step of rollbackAdditions // fires for it either: they undo what 0.2.26 and older releases changed, for // the targets older than the release that made the change. // -// What this release changed outside the stored files is 0.2.27's to undo or -// keep, and needs no step here: the next support bundle of a device with -// 0.2.27 starts the identity lines of an IOS device with the tail of a long -// command's echo again, as it did before. +// What 0.2.28 and this release changed outside the stored files is 0.2.27's +// to undo or keep, and needs no step here: the next support bundle of a device +// with 0.2.27 starts the identity lines of an IOS device with the tail of a +// long command's echo again, as it did before. // planRollback0227 completes p (a plan whose tacctl.yaml was read and whose -// records hold no unsettled apply) for the release before this one. +// records hold no unsettled apply) for 0.2.27. func planRollback0227(p *RollbackPlan) (*RollbackPlan, error) { pt := p.in.Paths p.Steps = append(p.Steps, p.lockdownKeysStep(RollbackTarget0227)) diff --git a/internal/lifecycle/rollback0228.go b/internal/lifecycle/rollback0228.go new file mode 100644 index 00000000..64a1d22b --- /dev/null +++ b/internal/lifecycle/rollback0228.go @@ -0,0 +1,39 @@ +package lifecycle + +// The rollback to 0.2.28, the release before this one. This release changed no +// stored file 0.2.28 reads strictly: what it changed is how the console's file +// transfer sets the mode of a file a client uploads (the owner's execute bit +// of a script copied with scp now survives, a change in the code that serves +// the transfer and not in a file), a test, and the documentation. The stored +// state files, the per-tier sudoers text, the keys of tacctl.yaml (the +// settings.file_transfer of console.yaml is 0.2.28's own), the fields of the +// store, the format of the pull records and of the reports in the users' homes +// are all as 0.2.28 reads them. So 0.2.28 reads every file this release writes +// and the plan of the target converts nothing: it leaves every file alone, the +// per-tier sudoers drop-in included (0.2.28 and this release write the same +// text), removes no key and no field (the limits of the stored reports and the +// file transfer settings stay: 0.2.28 has them) and takes no snapshot. The +// reports in the users' homes stay too, the PDF ones included, and so does the +// marker /var/lib/tacctl/pdf-tools-offered. No step of rollbackAdditions fires +// for it either: they undo what 0.2.28 and older releases changed, for the +// targets older than the release that made the change. +// +// What this release changed outside the stored files is 0.2.28's to undo or +// keep, and needs no step here: with 0.2.28 installed again a file a client +// uploads through the console is created with the mode 0644 (0600 after the +// umask) whatever mode the client asks for, as it was. + +// planRollback0228 completes p (a plan whose tacctl.yaml was read and whose +// records hold no unsettled apply) for the release before this one. +func planRollback0228(p *RollbackPlan) (*RollbackPlan, error) { + pt := p.in.Paths + p.Steps = append(p.Steps, p.lockdownKeysStep(RollbackTarget0228)) + p.Steps = append(p.Steps, RollbackStep{Title: "leave every other file untouched", + Lines: []string{pt.StoreFile + ", " + pt.DevicesFile + ", " + pt.ConsoleFile + ", the per-tier and the group sudoers drop-ins, the SNMP credentials, the pull records, the reports in the users' homes, the blocks, the apply state directory, the host registry and the rendered backend files are in formats " + RollbackTarget0228 + " reads;", + "nothing is re-rendered or restarted, and no device is contacted"}}) + if p.in.WithHosts { + p.Steps = append(p.Steps, RollbackStep{Title: "the enrolled Linux hosts (--hosts)", + Lines: []string{"nothing to do for " + RollbackTarget0228 + ": this release changed nothing on the enrolled hosts; no host is synced"}}) + } + return p, nil +} diff --git a/internal/lifecycle/rollback0228_test.go b/internal/lifecycle/rollback0228_test.go new file mode 100644 index 00000000..8b0f6512 --- /dev/null +++ b/internal/lifecycle/rollback0228_test.go @@ -0,0 +1,167 @@ +package lifecycle + +import ( + "context" + "reflect" + "strings" + "testing" + + "github.com/rett/tacctl/internal/execx" + "github.com/rett/tacctl/internal/tier" +) + +// The rollback to 0.2.28, the release before this one, on the sandbox of +// rollback_test.go: this release changed no stored file 0.2.28 reads strictly +// (it changed the mode of a file uploaded through the console), so the plan +// converts nothing, whatever 0.2.28 itself added to the state (the console's +// file transfer settings included). + +func plan0228(t *testing.T, s *rbSandbox) *RollbackPlan { + t.Helper() + s.in.Target = RollbackTarget0228 + p, err := PlanRollback(s.in) + if err != nil { + t.Fatal(err) + } + return p +} + +// The plan leaves every file, asks for no --yes, takes no snapshot and keeps +// what 0.2.28 has and the older targets drop: the console's file transfer +// settings, the limits of the stored reports, the users' email addresses, a +// pool of SNMPv3 users, a staging entry marked covered, the break-glass +// firewall and the per-tier drop-in, which 0.2.28 and this release write +// alike. It writes nothing. +func TestPlanRollback0228ConvertsNothing(t *testing.T) { + s := poolState(t) + s.write(s.p.TierSudoersFile, tier.Sudoers(), 0o640) + ft := " file_transfer:\n tiers: [operator, superuser]\n users: {bob: 'enable:readonly', carol: disable}\n quota: {operator: 1G}\n" + s.write(s.p.ConsoleFile, strings.Replace(rbConsole, " space_completion: false\n", " space_completion: false\n"+ft, 1), 0o600) + rbStoreLimits(t, s, true) + s.write(s.p.StateDir+"/staging", stagingKept+stagingCovered, 0o600) + s.write(s.p.Overrides, "breakglass:\n firewall: drop\nreports:\n max_size: 20971520\n max_count: 0\n", 0o600) + s.in.Conf.Reload() + s.write(s.p.FirewallRules, "table inet tacctl\n", 0o600) + s.write(s.p.FirewallUnit, "[Unit]\n", 0o644) + if !strings.Contains(string(mustRead(t, s.p.ConsoleFile)), "file_transfer") { + t.Fatal("the fixture lacks the file transfer settings") + } + calls := 0 + s.in.RemoveFirewall = func() ([]string, error) { calls++; return []string{"the nftables table inet tacctl"}, nil } + before := s.snapshotOf() + p := plan0228(t, s) + if p.Target != RollbackTarget0228 { + t.Errorf("target %q", p.Target) + } + st := stepText(p) + for _, w := range []string{s.p.Overrides + ": remove the keys 0.2.28 does not know", "nothing to remove (every key of tacctl.yaml is one 0.2.28 knows)", + "leave every other file untouched", "are in formats 0.2.28 reads", "the pull records, the reports in the users' homes"} { + if !strings.Contains(st, w) { + t.Errorf("steps lack %q:\n%s", w, st) + } + } + for _, not := range []string{"remove device.", "remove server.", "remove breakglass", "remove reports", "remove settings", "file_transfer", "file transfer", "firewall: remove", "email", "v3 user", "staging", "add scope", "0.2.3", "0.2.9", "report limits", "sudoers drop-in 0.2", "take out the settings"} { + if strings.Contains(strings.ToLower(st), not) { + t.Errorf("steps name %q:\n%s", not, st) + } + } + for _, step := range p.Steps { + if step.Todo { + t.Errorf("step %q does something", step.Title) + } + } + if len(p.Keys()) != 0 || p.Pending() || p.PendingFiles() || p.NeedsYes() || len(p.Notes) != 0 || len(p.Warnings) != 0 || p.FirewallTodo() || p.FileTransferRemoved() || + len(p.todoSudoers()) != 0 || len(p.managedUsers) != 0 || len(p.EmailUsers()) != 0 || p.SNMPPoolDropped().Any() || len(p.ReportLimitUsers()) != 0 { + t.Errorf("keys %q pending %v yes %v notes %q warnings %d sudoers %d managed %d email %q", p.Keys(), p.Pending(), p.NeedsYes(), p.Notes, len(p.Warnings), len(p.todoSudoers()), len(p.managedUsers), p.EmailUsers()) + } + if after := s.snapshotOf(); !reflect.DeepEqual(after, before) { + t.Error("the plan wrote a file") + } + if done, err := ApplyRollback(p); err != nil || len(done) != 0 || calls != 0 { + t.Errorf("apply: %q %v (firewall removed %d times)", done, err, calls) + } + if after := s.snapshotOf(); !reflect.DeepEqual(after, before) { + t.Error("the apply wrote a file") + } + if !strings.Contains(string(mustRead(t, s.p.ConsoleFile)), "file_transfer") { + t.Error("console.yaml lost the file transfer settings") + } + if got := string(mustRead(t, s.p.TierSudoersFile)); got != tier.Sudoers() { + t.Error("the per-tier drop-in was rewritten") + } + // the 0.2.27 target, on the same state, does convert (it is told apart): + // it takes the file transfer settings out + s.in.Target = RollbackTarget0227 + q, err := PlanRollback(s.in) + if err != nil { + t.Fatal(err) + } + if !q.FileTransferRemoved() || !q.PendingFiles() || q.NeedsYes() { + t.Errorf("the 0.2.27 target: file transfer removed %v files %v yes %v", q.FileTransferRemoved(), q.PendingFiles(), q.NeedsYes()) + } +} + +// With nothing set, nothing is different: the plan converts nothing and +// asks for nothing, and the second plan after the apply is the first. +func TestPlanRollback0228ConvertsNothingOnAPlainState(t *testing.T) { + s := newRBSandbox(t) + before := s.snapshotOf() + p := plan0228(t, s) + if len(p.Keys()) != 0 || p.PendingFiles() || p.NeedsYes() || len(p.Warnings) != 0 || len(p.ReportLimitUsers()) != 0 { + t.Errorf("keys %q files %v yes %v warnings %d", p.Keys(), p.PendingFiles(), p.NeedsYes(), len(p.Warnings)) + } + if done, err := ApplyRollback(p); err != nil || len(done) != 0 { + t.Errorf("apply: %q %v", done, err) + } + if after := s.snapshotOf(); !reflect.DeepEqual(after, before) { + t.Error("the apply wrote a file") + } + p = plan0228(t, s) + if len(p.Keys()) != 0 || p.PendingFiles() { + t.Error("the second plan has something to do") + } +} + +// --hosts is accepted and says nothing is done. +func TestPlanRollback0228WithHosts(t *testing.T) { + s := newRBSandbox(t) + s.in.WithHosts = true + p := plan0228(t, s) + if st := stepText(p); !strings.Contains(st, "nothing to do for 0.2.28: this release changed nothing on the enrolled hosts") { + t.Errorf("steps:\n%s", st) + } +} + +// A device whose apply is not settled refuses the target, as it does every +// other (the dry run too). +func TestPlanRollback0228RefusesAnUnsettledApply(t *testing.T) { + s := newRBSandbox(t) + s.in.Target = RollbackTarget0228 + s.write(s.p.ConfigRecords, `{"version": 1, "devices": { + "sw1": {"address": "192.0.2.11", "vendor": "juniper", + "applied": {"at": "2026-10-13T10:00:00Z", "until": "2026-10-13T12:10:00Z", "by": "alice", "result": "pending", "id": "tacctl-20261013T100000Z-ab12", "kind": "apply", "via": "netconf"}}}} +`, 0o600) + if _, err := PlanRollback(s.in); err == nil || !strings.Contains(err.Error(), "sw1") { + t.Errorf("an unsettled apply was not refused: %v", err) + } +} + +// What the plan promises of the 0.2.28 reader holds in its source: the +// console.yaml reader knows settings.file_transfer (so nothing is removed). +// Skipped where git or the tag is absent (CI must fetch tags). +func TestRollback0228ReaderKnowsTheFileTransferSettings(t *testing.T) { + r := execx.Real{} + if _, err := r.LookPath("git"); err != nil { + t.Skip("git is not installed, so the 0.2.28 tag cannot be read") + } + if res, err := r.Run(context.Background(), execx.Cmd{Name: "git", Args: []string{"rev-parse", "-q", "--verify", "0.2.28^{commit}"}}); err != nil || res.Code != 0 { + t.Skip("the 0.2.28 tag is not in this repository (CI must fetch tags: git fetch --tags)") + } + res, err := r.Run(context.Background(), execx.Cmd{Name: "git", Args: []string{"show", "0.2.28:internal/console/config.go"}}) + if err != nil || res.Code != 0 { + t.Fatalf("cannot read the 0.2.28 tag's console config: %v %s", err, res.Stderr) + } + if !strings.Contains(string(res.Stdout), `case "file_transfer":`) { + t.Error("0.2.28's console.yaml reader does not know file_transfer: the target would have to remove it") + } +} diff --git a/internal/lifecycle/rollback_additions.go b/internal/lifecycle/rollback_additions.go index fb4ba7da..513ad6fa 100644 --- a/internal/lifecycle/rollback_additions.go +++ b/internal/lifecycle/rollback_additions.go @@ -5,7 +5,7 @@ package lifecycle // // A target's own plan (rollback0222.go, rollback0221.go, ...) says what that // target converts, and several of them return before the generic steps run -// (0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21 and 0.2.20 read most of what this release writes). A change +// (0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21 and 0.2.20 read most of what this release writes). A change // that every older release refuses, such as the timing scale, does not belong // in each of those plans: it is one entry of rollbackAdditions, and // PlanRollback adds its steps, warnings and notes after the target's plan, for diff --git a/internal/lifecycle/rollback_email.go b/internal/lifecycle/rollback_email.go index 979415bf..5167e502 100644 --- a/internal/lifecycle/rollback_email.go +++ b/internal/lifecycle/rollback_email.go @@ -3,7 +3,7 @@ package lifecycle // The email address of a user (0.2.23, users..email in store.yaml) in a // rollback. Every release before 0.2.23 refuses the key ("user '': // unknown field 'email'" on every store command, and 'backup restore' -// refuses a snapshot that has it), so every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 +// refuses a snapshot that has it), so every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 // removes it from the store (store.RollbackEmail), after the snapshot --apply // takes first. Unlike the // files 0.2.22 reads as they are, this makes the 0.2.22 target convert a diff --git a/internal/lifecycle/rollback_firewall.go b/internal/lifecycle/rollback_firewall.go index e2491893..178726c1 100644 --- a/internal/lifecycle/rollback_firewall.go +++ b/internal/lifecycle/rollback_firewall.go @@ -2,10 +2,10 @@ package lifecycle // The break-glass firewall (0.2.24) in a rollback. It is a setting and a set of // files every older release lacks: breakglass.firewall in tacctl.yaml, which -// conf.Added0224 lists so that the key list of every target but 0.2.27, 0.2.26, 0.2.25 and 0.2.24 removes +// conf.Added0224 lists so that the key list of every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25 and 0.2.24 removes // it (a 0.2.23 binary refuses the key), the nftables table inet tacctl in the // kernel, the rules file under the state directory and the boot unit -// tacctl-breakglass-firewall.service. Every target but 0.2.27, 0.2.26, 0.2.25 and 0.2.24 (which have them) +// tacctl-breakglass-firewall.service. Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25 and 0.2.24 (which have them) // removes the last three, through RollbackInput.RemoveFirewall (the command's // seam over the runner; nil lists the step and does nothing), and says so; the nftables package stays, // and so does every hold: an older release that has holds (0.2.5 and later) diff --git a/internal/lifecycle/rollback_lockdown_hosts.go b/internal/lifecycle/rollback_lockdown_hosts.go index 69184047..01e09faf 100644 --- a/internal/lifecycle/rollback_lockdown_hosts.go +++ b/internal/lifecycle/rollback_lockdown_hosts.go @@ -7,7 +7,7 @@ package lifecycle // older schema refuses). A release before 0.2.23 cannot lift a lockdown on a // host: its 'emergency lockdown disable' renders the devices and its 'host // sync' never removes the file, so the host would stay closed with nothing -// that says so. Every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 is therefore refused, in the +// that says so. Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 is therefore refused, in the // dry run and --apply alike, while a lockdown stands on a scope that has an // enrolled host, or a lifted one still waits for a host to drop the file; the // lockdowns of scopes with no host, which the 0.2.19 to 0.2.22 targets take over as they stand, diff --git a/internal/lifecycle/rollback_snmp_pool.go b/internal/lifecycle/rollback_snmp_pool.go index 67fc6906..4ff05f4f 100644 --- a/internal/lifecycle/rollback_snmp_pool.go +++ b/internal/lifecycle/rollback_snmp_pool.go @@ -8,7 +8,7 @@ package lifecycle // without an snmp: entry (snmpcred.Creds.Text chooses; a community and one // default user are saved in version 1). Every release before 0.2.23 reads // version 1 only, with one v3 user, and its strict parser refuses a version 2 -// file ("unsupported version"), so every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 writes +// file ("unsupported version"), so every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 writes // each version 2 file as version 1 again, after the snapshot --apply takes // first (rollback_additions.go). A state with version 1 files only has nothing to // convert: no step, no snapshot, no --yes. diff --git a/internal/lifecycle/rollback_staging.go b/internal/lifecycle/rollback_staging.go index b0e8bfff..f48f4bb4 100644 --- a/internal/lifecycle/rollback_staging.go +++ b/internal/lifecycle/rollback_staging.go @@ -7,7 +7,7 @@ package lifecycle // other staging entry and writes it back without the field, and its sweep // and 'scope staging remove' take the /32 of the entry out of the scope: if // the scope holds that exact /32 as a real prefix, a real prefix goes. So -// every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 drops these lines from the file. The +// every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 drops these lines from the file. The // plan names them, the snapshot --apply takes first holds the file, and // nothing needs an answer: no warning and no --yes. A clone still waiting for its 'device rename // --replace' loses its entry: a re-upgrade cannot write it again, so the plan diff --git a/internal/lifecycle/rollback_test.go b/internal/lifecycle/rollback_test.go index a21c0c9f..2e0643de 100644 --- a/internal/lifecycle/rollback_test.go +++ b/internal/lifecycle/rollback_test.go @@ -17,13 +17,13 @@ import ( ) func TestCheckRollbackVersion(t *testing.T) { - for in, want := range map[string]string{"0.2.3": "0.2.3", "v0.2.3": "0.2.3", "0.2.9": "0.2.9", "v0.2.9": "0.2.9", "0.2.16": "0.2.16", "v0.2.16": "0.2.16", "0.2.17": "0.2.17", "v0.2.17": "0.2.17", "0.2.18": "0.2.18", "0.2.19": "0.2.19", "v0.2.19": "0.2.19", "0.2.20": "0.2.20", "v0.2.20": "0.2.20", "0.2.21": "0.2.21", "v0.2.21": "0.2.21", "0.2.22": "0.2.22", "v0.2.22": "0.2.22", "0.2.23": "0.2.23", "v0.2.23": "0.2.23", "0.2.24": "0.2.24", "v0.2.24": "0.2.24", "0.2.25": "0.2.25", "v0.2.25": "0.2.25", "0.2.26": "0.2.26", "v0.2.26": "0.2.26", "0.2.27": "0.2.27", "v0.2.27": "0.2.27"} { + for in, want := range map[string]string{"0.2.3": "0.2.3", "v0.2.3": "0.2.3", "0.2.9": "0.2.9", "v0.2.9": "0.2.9", "0.2.16": "0.2.16", "v0.2.16": "0.2.16", "0.2.17": "0.2.17", "v0.2.17": "0.2.17", "0.2.18": "0.2.18", "0.2.19": "0.2.19", "v0.2.19": "0.2.19", "0.2.20": "0.2.20", "v0.2.20": "0.2.20", "0.2.21": "0.2.21", "v0.2.21": "0.2.21", "0.2.22": "0.2.22", "v0.2.22": "0.2.22", "0.2.23": "0.2.23", "v0.2.23": "0.2.23", "0.2.24": "0.2.24", "v0.2.24": "0.2.24", "0.2.25": "0.2.25", "v0.2.25": "0.2.25", "0.2.26": "0.2.26", "v0.2.26": "0.2.26", "0.2.27": "0.2.27", "v0.2.27": "0.2.27", "0.2.28": "0.2.28", "v0.2.28": "0.2.28"} { if v, err := CheckRollbackVersion(in); err != nil || v != want { t.Errorf("%q: %q %v", in, v, err) } } for _, c := range []struct{ in, want string }{ - {"0.2.2", "'tacctl rollback' prepares the state for 0.2.27 (the release before this one), 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 and 0.2.3 only (0.2.2 is older)"}, + {"0.2.2", "'tacctl rollback' prepares the state for 0.2.28 (the release before this one), 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 and 0.2.3 only (0.2.2 is older)"}, {"v0.2.2", "is older"}, {"0.2.1", "is older"}, {"0.1.16", "is older"}, @@ -31,10 +31,10 @@ func TestCheckRollbackVersion(t *testing.T) { {"0.2.7", "and 0.2.3 only (0.2.7 is further back)"}, {"v0.2.7", "and 0.2.3 only (0.2.7 is further back)"}, {"0.2.8", "and 0.2.3 only (0.2.8 is further back)"}, - {"0.2.10", "'0.2.10' is not a release to roll back to: 'tacctl rollback' prepares the state for 0.2.27 (the release before this one), 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 and 0.2.3 only"}, + {"0.2.10", "'0.2.10' is not a release to roll back to: 'tacctl rollback' prepares the state for 0.2.28 (the release before this one), 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 and 0.2.3 only"}, {"0.2.15", "'0.2.15' is not a release to roll back to"}, - {"0.2.28", "'0.2.28' is not a release to roll back to"}, - {"0.2.28", "'0.2.28' is not a release to roll back to"}, + {"0.2.29", "'0.2.29' is not a release to roll back to"}, + {"0.2.30", "'0.2.30' is not a release to roll back to"}, {"0.3.0", "and 0.2.3 only"}, {"1.0.0", "and 0.2.3 only"}, {"0.2", "is not a release this tacctl knows"}, @@ -58,7 +58,7 @@ func TestCheckRollbackVersion(t *testing.T) { } // The refusal of 0.2.12 names the targets and promises no route there. _, err212 := CheckRollbackVersion("0.2.12") - if !strings.Contains(err212.Error(), "Usage: tacctl rollback 0.2.27|0.2.26|0.2.25|0.2.24|0.2.23|0.2.22|0.2.21|0.2.20|0.2.19|0.2.18|0.2.17|0.2.16|0.2.9|0.2.3") || strings.Contains(err212.Error(), "one release at a time") || strings.Contains(err212.Error(), "rollback 0.2.16 --apply") { + if !strings.Contains(err212.Error(), "Usage: tacctl rollback 0.2.28|0.2.27|0.2.26|0.2.25|0.2.24|0.2.23|0.2.22|0.2.21|0.2.20|0.2.19|0.2.18|0.2.17|0.2.16|0.2.9|0.2.3") || strings.Contains(err212.Error(), "one release at a time") || strings.Contains(err212.Error(), "rollback 0.2.16 --apply") { t.Errorf("0.2.12 refusal: %v", err212) } // The refusal of 0.2.2 names the two steps and the fallback. diff --git a/internal/tier/report_limits_test.go b/internal/tier/report_limits_test.go index b6be97c8..bf1561a0 100644 --- a/internal/tier/report_limits_test.go +++ b/internal/tier/report_limits_test.go @@ -137,3 +137,25 @@ func TestSudoersIsTheTextOf0227(t *testing.T) { t.Error("the per-tier text differs from the golden file of the 0.2.27 tag: freeze that text for the rollback to 0.2.27 (rollback0227.go leaves the drop-in alone only while they are the same)") } } + +// This release's per-tier text is the one 0.2.28 wrote, which is why the +// rollback to 0.2.28 leaves the drop-in alone. A release that changes a rule +// makes this fail: it freezes the text of the release before it and gives the +// rollback to that release a step for the drop-in. Skipped where git or the +// tag is absent. +func TestSudoersIsTheTextOf0228(t *testing.T) { + r := execx.Real{} + if _, err := r.LookPath("git"); err != nil { + t.Skip("git is not installed, so the 0.2.28 tag cannot be read") + } + if res, err := r.Run(context.Background(), execx.Cmd{Name: "git", Args: []string{"rev-parse", "-q", "--verify", "0.2.28^{commit}"}}); err != nil || res.Code != 0 { + t.Skip("the 0.2.28 tag is not in this repository (CI must fetch tags: git fetch --tags)") + } + res, err := r.Run(context.Background(), execx.Cmd{Name: "git", Args: []string{"show", "0.2.28:internal/tier/testdata/sudoers.tiers"}}) + if err != nil || res.Code != 0 { + t.Fatalf("cannot read the 0.2.28 tag's golden file: %v %s", err, res.Stderr) + } + if string(res.Stdout) != Sudoers() { + t.Error("the per-tier text differs from the golden file of the 0.2.28 tag: freeze that text for the rollback to 0.2.28 (rollback0228.go leaves the drop-in alone only while they are the same)") + } +} diff --git a/tests/integration/rollback.bats b/tests/integration/rollback.bats index d509d06b..051c6390 100644 --- a/tests/integration/rollback.bats +++ b/tests/integration/rollback.bats @@ -455,10 +455,10 @@ JSON assert_output --partial "Roll back to 0.2.19 (dry run)" assert_output --partial "put back the per-tier sudoers drop-in 0.2.19 writes" [[ "$(_sums)" == "$before" ]] - run "$TACCTL_BIN_SCRIPT" rollback 0.2.28 + run "$TACCTL_BIN_SCRIPT" rollback 0.2.29 assert_failure 1 - assert_output --partial "'0.2.28' is not a release to roll back to" - assert_output --partial "prepares the state for 0.2.27 (the release before this one), 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22" + assert_output --partial "'0.2.29' is not a release to roll back to" + assert_output --partial "prepares the state for 0.2.28 (the release before this one), 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23" } @test "rollback 0.2.21: the release before 0.2.22; the dry run writes nothing and --apply takes out the server name and nothing else" { @@ -486,7 +486,44 @@ JSON assert_output --partial "Nothing to convert: every file is one 0.2.21 can read." } -@test "rollback 0.2.27: the release before this one; the dry run writes nothing and --apply converts nothing, the report limits stay" { +@test "rollback 0.2.28: the release before this one; the dry run writes nothing and --apply converts nothing, the report limits stay" { + _state_024 + "$TACCTL_BIN_SCRIPT" server name core-1 > /dev/null + "$TACCTL_BIN_SCRIPT" user add bob engineer --hash "$HASH" --scopes lab > /dev/null + "$TACCTL_BIN_SCRIPT" config reports max-size 20Mi > /dev/null + "$TACCTL_BIN_SCRIPT" user reports-limit bob max-count 7 > /dev/null + mkdir -p "$BATS_TEST_TMPDIR/var-lib" + echo "offered" > "$BATS_TEST_TMPDIR/var-lib/pdf-tools-offered" + before=$(_sums) + n=$(_snapshots) + run "$TACCTL_BIN_SCRIPT" rollback 0.2.28 --hosts + assert_success + assert_output --partial "Roll back to 0.2.28 (dry run)" + assert_output --partial "nothing to remove (every key of tacctl.yaml is one 0.2.28 knows)" + assert_output --partial "nothing to do for 0.2.28: this release changed nothing on the enrolled hosts" + assert_output --partial "--apply converts no file of tacctl's own and takes no snapshot" + refute_output --partial "remove reports.max_size" + refute_output --partial "--yes" + assert_output --partial "This was a dry run: nothing was changed." + [[ "$(_sums)" == "$before" ]] + [[ "$(_snapshots)" == "$n" ]] + run "$TACCTL_BIN_SCRIPT" rollback 0.2.28 --apply + assert_success + assert_output --partial "Nothing to convert: every file is one 0.2.28 can read." + assert_output --partial "tacctl upgrade --branch 0.2.28" + refute_output --partial "The reports in the users' homes stay" + [[ "$(_sums)" == "$before" ]] + [[ "$(_snapshots)" == "$n" ]] + run "$TACCTL_BIN_SCRIPT" config get reports.max_size unset-marker + refute_output "unset-marker" + run "$TACCTL_BIN_SCRIPT" user show bob + assert_output --partial "Report max-count" + run "$TACCTL_BIN_SCRIPT" config get server.name unset-marker + assert_output "core-1" + [[ "$(cat "$BATS_TEST_TMPDIR/var-lib/pdf-tools-offered")" == "offered" ]] +} + +@test "rollback 0.2.27: the release before 0.2.28; the dry run writes nothing and --apply converts nothing, the report limits stay" { _state_024 "$TACCTL_BIN_SCRIPT" server name core-1 > /dev/null "$TACCTL_BIN_SCRIPT" user add bob engineer --hash "$HASH" --scopes lab > /dev/null From cc1115a4897b6f830ae421e661eb732914c3bfbf Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:42:52 -0900 Subject: [PATCH 36/52] docs: the rollback pages and the man page list the 0.2.28 target Rolling back in docs/install/upgrading.md gets a "To 0.2.28" section (nothing is converted, no key or field is removed, no snapshot, no --yes; the file transfer settings, the limits of the stored reports, the reports in the homes, the marker of the offer of the PDF tools and the per-tier drop-in stay) and says fifteen targets. The manual page, docs/cli/conventions.md and docs/releasing.md list 0.2.28 as the release before this one, and the CHANGELOG has item 2 of 0.2.29. The lists of "every target but" for the break-glass firewall, the users' email addresses, the SNMP credential files, the covered staging entries, the server name and timing scale, the scope of the server's own login, the user's required password change and an emergency lockdown with enrolled hosts name 0.2.28 beside 0.2.27. The file transfer paragraph says that every target but 0.2.28 removes the settings, and the limits of the stored reports are said to be kept by 0.2.26 to 0.2.28 (docs/cli/user.md and docs/devices/reports.md say so too). The To 0.2.27, 0.2.26, 0.2.25, 0.2.23 and 0.2.22 sections and the man page entries name 0.2.28 where they say what the target reads. The snapshot note quoted in the pages names 0.2.29. --- CHANGELOG.md | 28 +++++++++++ docs/cli/conventions.md | 7 +-- docs/cli/emergency.md | 2 +- docs/cli/user.md | 6 +-- docs/devices/reports.md | 2 +- docs/install/upgrading.md | 74 ++++++++++++++++------------ docs/releasing.md | 6 +-- man/tacctl.1 | 101 +++++++++++++++++++++++++------------- 8 files changed, 150 insertions(+), 76 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebf6de5d..3f52c3a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,34 @@ current behaviour; this file is where history lives. a file gets 0644, 0600 after the umask, as before. `docs/cli/console.md` and the manual page say so. +2. **`tacctl rollback 0.2.28`, the release before this one, is a target.** + This release changed no stored file 0.2.28 reads strictly (the mode a file + uploaded through the console gets, item 1, a test and the documentation are + all that moved), so 0.2.28 reads everything it writes: the rollback + converts no file, removes no key and no field, takes no snapshot and needs + no `--yes`. The file transfer settings of `console.yaml` + (`settings.file_transfer`) stay, 0.2.28 has them, and so do the limits of + the stored reports (`reports.max_size` and `reports.max_count` in + `tacctl.yaml`, and a user's own `reports_max_size` and `reports_max_count` + in `store.yaml`), the chassis `members` of the pull records and every + report in the users' homes, the PDF ones included, with the marker + `/var/lib/tacctl/pdf-tools-offered` and the packages `weasyprint` and + `fonts-dejavu-core`. The per-tier sudoers drop-in is left too: 0.2.28 and + this release write the same text. The break-glass firewall, the users' + email addresses, the SNMPv3 users, the covered staging entries, the server + name, the timing scale and an emergency lockdown with enrolled hosts, + which the older targets drop or refuse, stay as well. It is refused only + while a device's apply is not settled. The command ends with `tacctl + upgrade --branch 0.2.28` and, having nothing to avoid, has no closing note. + `rollback 0.2.27` and older behave as before (they still remove the file + transfer settings), and the lists of "every target but" in the rollback + pages and the manual page now include 0.2.28. The top-level help, + `docs/cli/conventions.md`, `docs/install/upgrading.md` (Rolling back, To + 0.2.28), `docs/releasing.md`, the manual page and the completion list the + new target, and `tacctl rollback` now takes fifteen targets. The note that + follows a rollback that took a snapshot names this release, 0.2.29, as the + state the snapshot holds ("Restore it with 0.2.29 only"). + ## 0.2.28 (2026-11-09) 1. **A support bundle from a Cisco IOS device no longer starts the identity diff --git a/docs/cli/conventions.md b/docs/cli/conventions.md index 55d53761..60f4e792 100644 --- a/docs/cli/conventions.md +++ b/docs/cli/conventions.md @@ -42,9 +42,10 @@ tacctl uninstall [--yes] tacctl rollback [--apply] [--yes] [--hosts] - Prepare the state for the release before this one (0.2.27), for 0.2.26, 0.2.25, - 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 or for 0.2.3: a - dry run unless --apply; see install/upgrading.md, "Rolling back" + Prepare the state for the release before this one (0.2.28), for 0.2.27, 0.2.26, + 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20, 0.2.19, 0.2.18, 0.2.17, 0.2.16, + 0.2.9 or for 0.2.3: a dry run unless --apply; see install/upgrading.md, + "Rolling back" tacctl status diff --git a/docs/cli/emergency.md b/docs/cli/emergency.md index c7499b02..6a2cb74c 100644 --- a/docs/cli/emergency.md +++ b/docs/cli/emergency.md @@ -132,7 +132,7 @@ takes the group out of every lockdown, and `group edit tier superuser` (or a priv-lvl edit that makes the group a superuser's) is refused while the group is locked, since a superuser group is never locked. A rollback to a release before 0.2.19 is refused while a lockdown stands, and every rollback -but the ones to 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 is while a lockdown has enrolled hosts or a +but the ones to 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 is while a lockdown has enrolled hosts or a lifted one waits for a host (`tacctl rollback`; older releases cannot lift the drop-in). `config validate` warns while a lockdown stands and reports a record that names a scope or group that no diff --git a/docs/cli/user.md b/docs/cli/user.md index f6f9aba1..441da258 100644 --- a/docs/cli/user.md +++ b/docs/cli/user.md @@ -173,7 +173,7 @@ max-count:` line for a user who has an own limit, to every tier that can run `us accounting sink takes none. Setting a limit renders and restarts nothing and takes a snapshot, like any change of the store, and writes the detail line `user reports-limit name= key=max-size|max-count op=set|clear value=`. A release before 0.2.26 refuses the fields, so every `tacctl rollback` target before 0.2.26 -(0.2.25 and older; `rollback 0.2.26` and `rollback 0.2.27` keep them) removes them after a snapshot, needs `--yes` while a user has one and names the users (see +(0.2.25 and older; `rollback 0.2.26`, `rollback 0.2.27` and `rollback 0.2.28` keep them) removes them after a snapshot, needs `--yes` while a user has one and names the users (see [Rolling back](../install/upgrading.md#rolling-back)). ``` @@ -215,7 +215,7 @@ only when set, so a store without one is unchanged. No mail is sent to it. in any other `user` verb, and `…(redacted)` in place of the rest. Like any word on a command line it is in sudo's own log. - *Older releases.* A release before 0.2.23 refuses the key, so every `tacctl - rollback` target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 (which read it) removes it after a + rollback` target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 (which read it) removes it after a snapshot that it keeps, and names the users; `backup recover` puts the addresses back (see [Rolling back](../install/upgrading.md#rolling-back)). @@ -347,7 +347,7 @@ only when set. the reason in `user show`), and one whom devices of a shared scope still accept `flagged, devices in a scope shared with the server still accept the password`; `status` names both groups. - *Older releases.* A release before 0.2.20 refuses the key, so every `tacctl rollback` target - but 0.2.27 to 0.2.20 (which read it) removes it after a snapshot and warns which users get their device access back (see + but 0.2.28 to 0.2.20 (which read it) removes it after a snapshot and warns which users get their device access back (see [Rolling back](../install/upgrading.md#rolling-back)). **A hash kept off the command line.** `--hash -` reads the hash from one line diff --git a/docs/devices/reports.md b/docs/devices/reports.md index 74e0b88c..3293d8a2 100644 --- a/docs/devices/reports.md +++ b/docs/devices/reports.md @@ -250,7 +250,7 @@ A report that is too large can be made smaller (`--scope`, `--vendor`), printed ## Older releases -A release before 0.2.26 has no `device reports` verb. `tacctl rollback` to 0.2.25 or older (see [Rolling back](../install/upgrading.md#rolling-back)) leaves the reports and their metadata files where they are, because they are the users' own files, and says so; it removes the limits of this page (the two settings and the users' own limits, after a snapshot, and `--yes` while a user has one), and puts back the per-tier sudoers drop-in without the `device reports` rows. The `members` of the pull records stay too: an older release ignores them. `tacctl rollback 0.2.26` and `tacctl rollback 0.2.27` convert nothing: both have the verbs, the limits and the reports, and read them as they are (0.2.26 has no PDF format and shows a PDF report as text; 0.2.27 reads it as it is). +A release before 0.2.26 has no `device reports` verb. `tacctl rollback` to 0.2.25 or older (see [Rolling back](../install/upgrading.md#rolling-back)) leaves the reports and their metadata files where they are, because they are the users' own files, and says so; it removes the limits of this page (the two settings and the users' own limits, after a snapshot, and `--yes` while a user has one), and puts back the per-tier sudoers drop-in without the `device reports` rows. The `members` of the pull records stay too: an older release ignores them. `tacctl rollback 0.2.26`, `tacctl rollback 0.2.27` and `tacctl rollback 0.2.28` keep them: all three have the verbs, the limits and the reports, and read them as they are (0.2.26 has no PDF format and shows a PDF report as text; 0.2.27 and 0.2.28 read it as it is). ## Exit status diff --git a/docs/install/upgrading.md b/docs/install/upgrading.md index c0211925..d77d5396 100644 --- a/docs/install/upgrading.md +++ b/docs/install/upgrading.md @@ -110,22 +110,22 @@ Nothing is asked when both packages are installed, on a system without `apt-get` ## Rolling back -`tacctl rollback` takes fourteen targets: `0.2.27`, the release before this -one, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23`, `0.2.22`, `0.2.21`, `0.2.20`, `0.2.19`, `0.2.18`, `0.2.17`, `0.2.16`, `0.2.9` and +`tacctl rollback` takes fifteen targets: `0.2.28`, the release before this +one, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23`, `0.2.22`, `0.2.21`, `0.2.20`, `0.2.19`, `0.2.18`, `0.2.17`, `0.2.16`, `0.2.9` and `0.2.3`. All are the dry run described below until `--apply` is given, all -refuse while an apply is not settled, all but `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, +refuse while an apply is not settled, all but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23`, `0.2.22`, `0.2.21`, `0.2.20` and `0.2.19` while an emergency -lockdown locks a group, all but `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24` and `0.2.23` while an emergency lockdown has enrolled hosts, and each release's tool prepares the state for +lockdown locks a group, all but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24` and `0.2.23` while an emergency lockdown has enrolled hosts, and each release's tool prepares the state for the releases it knows. `0.2.4` to `0.2.8` and `0.2.2` and older are refused with the way there (one release at a time, or `tacctl backup restore` of a snapshot of the time); `0.2.10` to `0.2.15`, this release and any other word are refused with the targets named. -**The break-glass firewall (0.2.24).** Every target but `0.2.27`, `0.2.26`, `0.2.25` and `0.2.24` removes the firewall of the held addresses: `breakglass.firewall` from `tacctl.yaml` (every older release refuses the key, so the key goes after the snapshot like the others they do not know), the nftables table `inet tacctl` with `nft` (the rest of the ruleset is not touched), `/etc/tacctl/breakglass-firewall.nft` and the boot unit `tacctl-breakglass-firewall.service` (disabled first). The `nftables` package stays installed. The dry run lists the step when the file or the unit exists, and the report says what went. A hold that stands stays (0.2.5 and later releases have the record) and is taken over as it is, without the firewall: the older release's server completes the TCP handshake of the held address again, so a device that falls back to its local accounts only when the server is unreachable (WTI `On (Transport Failure)`, Junos `authentication-order [ tacplus password ]`) will not; the plan names the holds in a note. Until the older release is installed, run no verb that changes the holds, their device or host names, the listeners or the setting (`breakglass hold|release`, `device address`, `device|host rename`, `device rename --replace`, `backup restore`, `server listen`, `config breakglass-firewall`): each writes the table, the rules file and the boot unit again, and the setting writes the key the older release refuses. Run the rollback again if one was run. +**The break-glass firewall (0.2.24).** Every target but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25` and `0.2.24` removes the firewall of the held addresses: `breakglass.firewall` from `tacctl.yaml` (every older release refuses the key, so the key goes after the snapshot like the others they do not know), the nftables table `inet tacctl` with `nft` (the rest of the ruleset is not touched), `/etc/tacctl/breakglass-firewall.nft` and the boot unit `tacctl-breakglass-firewall.service` (disabled first). The `nftables` package stays installed. The dry run lists the step when the file or the unit exists, and the report says what went. A hold that stands stays (0.2.5 and later releases have the record) and is taken over as it is, without the firewall: the older release's server completes the TCP handshake of the held address again, so a device that falls back to its local accounts only when the server is unreachable (WTI `On (Transport Failure)`, Junos `authentication-order [ tacplus password ]`) will not; the plan names the holds in a note. Until the older release is installed, run no verb that changes the holds, their device or host names, the listeners or the setting (`breakglass hold|release`, `device address`, `device|host rename`, `device rename --replace`, `backup restore`, `server listen`, `config breakglass-firewall`): each writes the table, the rules file and the boot unit again, and the setting writes the key the older release refuses. Run the rollback again if one was run. -**The limits of the stored reports (0.2.26).** The settings `reports.max_size` and `reports.max_count` of `tacctl.yaml` (`config reports`) and a user's own limits, the fields `reports_max_size` and `reports_max_count` of the user in `store.yaml` (`user reports-limit`), are keys no release before 0.2.26 reads, so every target before 0.2.26 (`0.2.25` and older; `0.2.27` and `0.2.26` have them and keep them) removes them. The settings go with the other keys the target does not know, after the snapshot `--apply` takes first, and need no answer. A user's own limit is data somebody chose for one user, so the dry run names each user with the values in a warning (`remove the report limits of bob (max-size 20 MiB, max-count 50 reports)`), `--apply` refuses without `--yes` while any user has one, the snapshot holds them, and the audit line of the rollback names the users (`limit-users=`, never a value). Once this release is installed again, `tacctl user reports-limit max-size|max-count ` sets them again from the list the rollback prints (`backup recover` does not bring them back). A store that cannot be read refuses every target before 0.2.26: a limit that cannot be seen is not hidden. The reports in the users' homes stay, as the users' own files (an older release has no `device reports` verb to list or remove them), and so do the chassis `members` of the pull records, which an older decoder ignores; the per-tier sudoers drop-in loses the rows of `device reports` (every target before 0.2.26 rewrites it as it did, and 0.2.25 and 0.2.24 with the text they wrote; `0.2.27` and `0.2.26` leave it, they wrote the same text as this release). Until the older release is installed, run none of `config reports max-size`, `config reports max-count` and `user reports-limit`: they write what the older release refuses. If one did, run the rollback again (with `--yes` while a user has a limit of their own). Every target before 0.2.26 ends with a note that says that the reports stay and what to avoid; `0.2.27` and `0.2.26` have none, they have nothing to avoid. +**The limits of the stored reports (0.2.26).** The settings `reports.max_size` and `reports.max_count` of `tacctl.yaml` (`config reports`) and a user's own limits, the fields `reports_max_size` and `reports_max_count` of the user in `store.yaml` (`user reports-limit`), are keys no release before 0.2.26 reads, so every target before 0.2.26 (`0.2.25` and older; `0.2.28`, `0.2.27` and `0.2.26` have them and keep them) removes them. The settings go with the other keys the target does not know, after the snapshot `--apply` takes first, and need no answer. A user's own limit is data somebody chose for one user, so the dry run names each user with the values in a warning (`remove the report limits of bob (max-size 20 MiB, max-count 50 reports)`), `--apply` refuses without `--yes` while any user has one, the snapshot holds them, and the audit line of the rollback names the users (`limit-users=`, never a value). Once this release is installed again, `tacctl user reports-limit max-size|max-count ` sets them again from the list the rollback prints (`backup recover` does not bring them back). A store that cannot be read refuses every target before 0.2.26: a limit that cannot be seen is not hidden. The reports in the users' homes stay, as the users' own files (an older release has no `device reports` verb to list or remove them), and so do the chassis `members` of the pull records, which an older decoder ignores; the per-tier sudoers drop-in loses the rows of `device reports` (every target before 0.2.26 rewrites it as it did, and 0.2.25 and 0.2.24 with the text they wrote; `0.2.28`, `0.2.27` and `0.2.26` leave it, they wrote the same text as this release). Until the older release is installed, run none of `config reports max-size`, `config reports max-count` and `user reports-limit`: they write what the older release refuses. If one did, run the rollback again (with `--yes` while a user has a limit of their own). Every target before 0.2.26 ends with a note that says that the reports stay and what to avoid; `0.2.28`, `0.2.27` and `0.2.26` have none, they have nothing to avoid. -**The console's file transfer settings (0.2.28).** `console.yaml` holds `settings.file_transfer` once something in it is set (`console file-transfer`: the tiers and users that have file transfer, and the quota and the rate of tiers and users). No release before 0.2.28 reads the key, 0.2.27 included: its reader answers `settings: unknown key 'file_transfer'`, the console falls back to its defaults and the commands that write the file fail. So every target removes it: `--apply` takes the snapshot first, removes `settings.file_transfer` and keeps every other setting, and the dry run lists the key as a step of its own with what it held (the tiers, and how many user switches, quotas and rates). It needs no `--yes`. This is the one conversion of `0.2.27` and `0.2.26`, which otherwise convert nothing, and with the settings unset they still take no snapshot. When the key was removed the command ends with a note: until the older release is installed, run no `tacctl console file-transfer` that sets something (it writes the key again; run the rollback again if one was run), and the snapshot holds the 0.2.28 state, which only 0.2.28 restores (the older release would put back a `console.yaml` it cannot read). The settings are not kept anywhere else: set them again after the upgrade. +**The console's file transfer settings (0.2.28).** `console.yaml` holds `settings.file_transfer` once something in it is set (`console file-transfer`: the tiers and users that have file transfer, and the quota and the rate of tiers and users). No release before 0.2.28 reads the key, 0.2.27 included: its reader answers `settings: unknown key 'file_transfer'`, the console falls back to its defaults and the commands that write the file fail. So every target but `0.2.28` (it reads the key, as this release does) removes it: `--apply` takes the snapshot first, removes `settings.file_transfer` and keeps every other setting, and the dry run lists the key as a step of its own with what it held (the tiers, and how many user switches, quotas and rates). It needs no `--yes`. This is the one conversion of `0.2.27` and `0.2.26`, which otherwise convert nothing, and with the settings unset they still take no snapshot. When the key was removed the command ends with a note: until the older release is installed, run no `tacctl console file-transfer` that sets something (it writes the key again; run the rollback again if one was run), and the snapshot holds the 0.2.29 state, which only 0.2.29 restores (the older release would put back a `console.yaml` it cannot read). The settings are not kept anywhere else: set them again after the upgrade. **PDF reports (0.2.27).** No target converts or removes them: a PDF report is a file of the user's home like the others, with a `.meta` file whose `format` is `pdf`, and the marker `/var/lib/tacctl/pdf-tools-offered` (see [PDF reports](#pdf-reports)) is a file no release reads but 0.2.27 and the ones after it. The packages `weasyprint` and `fonts-dejavu-core` stay installed. `0.2.27` has the format and reads the reports as they are. A release before 0.2.27 has no PDF format: 0.2.26 lists such a report and its `show --content` cleans the bytes as text, so fetch it with the `scp` line of `show` instead, and it must not be renamed with `device reports rename` (0.2.26 gives the file the new name without its `.pdf`); remove it or rename it before a rollback to 0.2.26 or older. @@ -145,18 +145,18 @@ systemctl daemon-reload **Every user's login to this server (0.2.21).** This release lets every user log in to the tacctl server and its console, unless disabled or of tier none, without the server's scope in the user's own scopes. Every older release -needs it there (0.2.21 to 0.2.27 have it themselves), so every target but -`0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23`, `0.2.22` and `0.2.21` adds the scope of this server's own login (`tacctl`) to +needs it there (0.2.21 to 0.2.28 have it themselves), so every target but +`0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23`, `0.2.22` and `0.2.21` adds the scope of this server's own login (`tacctl`) to the scopes of each user who logs in to the server and lacks it (the plan counts and names them; a warning, so `--apply` needs `--yes`), after a -snapshot. Every target but `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23` and `0.2.22` removes the server name +snapshot. Every target but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23` and `0.2.22` removes the server name `server.name` (0.2.22, `tacctl server name`) from `tacctl.yaml`, and every -target but `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23`, `0.2.22` and `0.2.21` the server address `server.addresses` too; no older +target but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23`, `0.2.22` and `0.2.21` the server address `server.addresses` too; no older release knows them. The host registry keeps the address in this server's entry, which the older release reads, and the console shows the host name again. -**The timing scale (0.2.22).** Every target but `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23` and `0.2.22` also removes the +**The timing scale (0.2.22).** Every target but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, `0.2.23` and `0.2.22` also removes the timing scale (`tacctl device timeout-scale`, `scope timeout-scale`, `config devices timeout-scale`): `device.timeout_scale` and `timeout_scale_scope.` from `tacctl.yaml`, and the `timeout_scale` of @@ -168,7 +168,7 @@ distant device may not meet. The values stay in the snapshot `--apply` takes first. **Email addresses (0.2.23).** `users..email` (`tacctl user email`, `user -add --email`) is a key no older release reads: every target but `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24` and `0.2.23`, the +add --email`) is a key no older release reads: every target but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24` and `0.2.23`, the ones that return early and `0.2.22` included, removes it from `store.yaml` after a snapshot. The plan names the users who have an address (never the address), in a warning, so `--apply` needs `--yes`; a rollback of a store without an @@ -195,7 +195,7 @@ releases ignore a version 1 file there). A device's file follows its entry: it is saved version 2 while the device has no entry, written version 1 when an entry appears (any setting of the device) and the content fits version 1 (a pool of two stays version 2), and version 2 again when the entry is gone. No -older release reads version 2 ("unsupported version"), so every target but `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24` and `0.2.23` writes +older release reads version 2 ("unsupported version"), so every target but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24` and `0.2.23` writes each version 2 file in version 1 again, after the snapshot `--apply` takes first; a state with version 1 files only has nothing of this to convert. Version 1 holds one v3 user for each level: the default user stays and the @@ -227,7 +227,7 @@ rollback again. clone` at a bench address its scope answers already writes an entry marked `covered` to `state/staging` (no `/32` is added). An older release reads it as a plain entry, and its sweep and `scope staging remove` take that `/32` out of -the scope, a prefix of the scope's own included. So every target but `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24` and `0.2.23` drops these +the scope, a prefix of the scope's own included. So every target but `0.2.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24` and `0.2.23` drops these entries from the file, after the snapshot; the plan names them, and nothing asks (no warning, no `--yes`). A clone that still waits for its `device rename --replace` loses its entry, and after a re-upgrade the verb refuses it as not @@ -243,7 +243,7 @@ rollback again. A record that locks nothing (a hand-edited, partial one) is removed by the rollback, because the older schemas refuse its keys. **An emergency lockdown that has enrolled hosts stops every rollback but the -one to 0.2.27, 0.2.26, 0.2.25, 0.2.24 or 0.2.23**, the ones to 0.2.19 to 0.2.22 included (the dry run too). On a host the lockdown is +one to 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 or 0.2.23**, the ones to 0.2.19 to 0.2.22 included (the dry run too). On a host the lockdown is an sshd drop-in that only this release writes and removes, and the record keeps the hosts it has not reached (a `pending` list that older releases refuse), so an older release could not lift it and the hosts would stay @@ -255,12 +255,12 @@ any more (`emergency lockdown enable ` or `disable` drops the name). A lockdown on a scope with no enrolled host is taken over as before. -**The password cache is the user's choice (0.2.20).** `console password-cache tiers` is now only the permission: a tier that is listed no longer has the cache on for everyone in it. Each user turns it on for themselves with `console password-cache on` (off by default), so a console that had the cache on for a tier has it off for every user until they do; `tacctl shell --password-cache` is unchanged. The choices are stored in `settings.password_cache_users` (written only when a user turned it on). No release before 0.2.20 reads that key: the rollback removes it for every target before 0.2.20 (0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 and 0.2.3; the plan names the users), and the older release then has the cache on for every user of a listed tier, as it always did (0.2.3 has no cache). The targets 0.2.27 to 0.2.20 read the key and leave it. +**The password cache is the user's choice (0.2.20).** `console password-cache tiers` is now only the permission: a tier that is listed no longer has the cache on for everyone in it. Each user turns it on for themselves with `console password-cache on` (off by default), so a console that had the cache on for a tier has it off for every user until they do; `tacctl shell --password-cache` is unchanged. The choices are stored in `settings.password_cache_users` (written only when a user turned it on). No release before 0.2.20 reads that key: the rollback removes it for every target before 0.2.20 (0.2.19, 0.2.18, 0.2.17, 0.2.16, 0.2.9 and 0.2.3; the plan names the users), and the older release then has the cache on for every user of a listed tier, as it always did (0.2.3 has no cache). The targets 0.2.28 to 0.2.20 read the key and leave it. -**The system shell of single users.** `settings.system_shell_users` (`console system-shell user`, written only when a user has a setting) is a key no release before 0.2.20 reads: the rollback to a target before 0.2.20 removes it (the plan names the users and their setting), and the older release has the tiers' list `settings.system_shell_tiers` alone; the targets 0.2.27 to 0.2.20 read the key and leave it. That list always holds `superuser` once this release has written it. +**The system shell of single users.** `settings.system_shell_users` (`console system-shell user`, written only when a user has a setting) is a key no release before 0.2.20 reads: the rollback to a target before 0.2.20 removes it (the plan names the users and their setting), and the older release has the tiers' list `settings.system_shell_tiers` alone; the targets 0.2.28 to 0.2.20 read the key and leave it. That list always holds `superuser` once this release has written it. **The console switches of `console.yaml`.** The `tiers` and `users` mappings that this release -ignores stay in the file, and a release before 0.2.20 (the targets 0.2.19 and older; 0.2.27 to 0.2.20 +ignores stay in the file, and a release before 0.2.20 (the targets 0.2.19 and older; 0.2.28 to 0.2.20 ignore them too, and their rollback says nothing of it) reads them as it always did: a tier or a user switched off there gets a plain shell again at the next `host sync` of that release. A file without the mappings is read there as the console on for every tier. The rollback lists every user @@ -288,7 +288,7 @@ before the upgrade, or expect the errors. Targets 0.2.18, 0.2.17, 0.2.16 and `settings.list_max` of `-1` (`console list-max` with a negative number: never ask). No release before 0.2.20 reads either (it answers `unknown key 'color'` or `settings.list_max must be 1-1000`, the console falls back to its defaults and -its writes fail), so every target before 0.2.20 (0.2.19 and older; 0.2.27 to 0.2.20 read +its writes fail), so every target before 0.2.20 (0.2.19 and older; 0.2.28 to 0.2.20 read both) takes them out: `--apply` removes `settings.color`, writes `list_max: 1000` in place of `-1`, keeps every other setting, and takes the snapshot first. The dry run lists the change as a step @@ -297,7 +297,7 @@ of its own. **A scope's strict management filter mode.** The mode of the Junos management filter (`tacctl scope mgmt-acl mode`, 0.2.20) is stored as `scope_mgmt_acl.mode.` (only `strict` is stored), a key every release -before 0.2.20 refuses. Every target before 0.2.20 (0.2.19 and older; 0.2.27 to 0.2.20 read it +before 0.2.20 refuses. Every target before 0.2.20 (0.2.19 and older; 0.2.28 to 0.2.20 read it and leave it) therefore removes it from `tacctl.yaml` after a snapshot, and the dry run lists the scopes that were strict in a warning that `--apply` refuses without `--yes`. The older release renders and plans the `ssh-only` filter for them, which ends in a `default-accept` term, so its @@ -311,7 +311,7 @@ older release's plans. password before logging in to anything but tacctl (`password_change_required` in `store.yaml`, written only for a flagged user, 0.2.20). Every older release refuses the key (`user '': unknown field -'password_change_required'`), so every target but `0.2.27` to `0.2.20` (which read +'password_change_required'`), so every target but `0.2.28` to `0.2.20` (which read it) removes it from the store after a snapshot, and the dry run lists the flagged users. Those who are not superusers (the flag never binds a superuser) are named in a warning that `--apply` refuses without `--yes`: the older release renders them into every @@ -352,11 +352,23 @@ other line; the dry run lists each file. The files are derived and never in a snapshot; this release, if it stays, reads the two as missing until its next `device config pull`. +### To 0.2.28 + +0.2.28 reads every file this release writes: this release changed no stored file it reads strictly (the mode a file uploaded through the console gets, a test and the documentation are all that moved). So the rollback converts nothing: it removes no key and no field, takes no snapshot, needs no `--yes` and leaves every file alone. The file transfer settings of `console.yaml` (see above) stay, 0.2.28 has them, as do the limits of the stored reports (`reports.max_size` and `reports.max_count` in `tacctl.yaml`, and a user's own limits in `store.yaml`), the chassis `members` of the pull records and every report in the users' homes, the PDF ones included. The marker `/var/lib/tacctl/pdf-tools-offered` stays, and so do the packages `weasyprint` and `fonts-dejavu-core`. The per-tier sudoers drop-in is left too: 0.2.28 and this release write the same text. The break-glass firewall, the users' email addresses, the SNMPv3 users, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (with or without enrolled hosts) all stay. It still refuses while an apply is not settled. `--hosts` is accepted and does nothing. The tacquito checkout in `/opt/tacquito-src` keeps pointing at the project's fork, which is what 0.2.28 pulls from. The command ends with the upgrade and has no closing note, because there is nothing to avoid. + +What this release changed outside the stored files is 0.2.28's to undo or keep. After the `tacctl upgrade --branch 0.2.28` that ends the rollback, a file a client uploads through the console is created with the mode 0644 (0600 after the console's umask) whatever mode the client asks for, as it was in 0.2.28. The files uploaded in between keep the mode they got. + +```bash +tacctl rollback 0.2.28 # the dry run: steps, writes nothing +tacctl rollback 0.2.28 --apply +tacctl upgrade --branch 0.2.28 # install 0.2.28 +``` + ### To 0.2.27 -0.2.27 reads every file this release writes but one setting of `console.yaml`: this release changed no other stored file it reads strictly (how the answer of a Cisco IOS device to a long command is read, and the documentation, are all that moved). So the rollback converts nothing, with one exception: it removes the file transfer settings of `console.yaml` (see above) when they are set, after the snapshot `--apply` takes first, and keeps every other setting. With none set it removes no key and no field, takes no snapshot, needs no `--yes` and leaves every file alone. The limits of the stored reports (`reports.max_size` and `reports.max_count` in `tacctl.yaml`, and a user's own limits in `store.yaml`) stay, 0.2.27 has them, as do the chassis `members` of the pull records and every report in the users' homes, the PDF ones included, which 0.2.27 reads. The marker `/var/lib/tacctl/pdf-tools-offered` stays, and so do the packages `weasyprint` and `fonts-dejavu-core`. The per-tier sudoers drop-in is left too: 0.2.27 and this release write the same text. The break-glass firewall, the users' email addresses, the SNMPv3 users, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (with or without enrolled hosts) all stay. It still refuses while an apply is not settled. `--hosts` is accepted and does nothing. The tacquito checkout in `/opt/tacquito-src` keeps pointing at the project's fork, which is what 0.2.27 pulls from. +0.2.27 reads every file 0.2.28 and this release write but one setting of `console.yaml`: they changed no other stored file it reads strictly (how the answer of a Cisco IOS device to a long command is read, the mode of a file uploaded through the console, and the documentation, are all that moved). So the rollback converts nothing, with one exception: it removes the file transfer settings of `console.yaml` (see above) when they are set, after the snapshot `--apply` takes first, and keeps every other setting. With none set it removes no key and no field, takes no snapshot, needs no `--yes` and leaves every file alone. The limits of the stored reports (`reports.max_size` and `reports.max_count` in `tacctl.yaml`, and a user's own limits in `store.yaml`) stay, 0.2.27 has them, as do the chassis `members` of the pull records and every report in the users' homes, the PDF ones included, which 0.2.27 reads. The marker `/var/lib/tacctl/pdf-tools-offered` stays, and so do the packages `weasyprint` and `fonts-dejavu-core`. The per-tier sudoers drop-in is left too: 0.2.27, 0.2.28 and this release write the same text. The break-glass firewall, the users' email addresses, the SNMPv3 users, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (with or without enrolled hosts) all stay. It still refuses while an apply is not settled. `--hosts` is accepted and does nothing. The tacquito checkout in `/opt/tacquito-src` keeps pointing at the project's fork, which is what 0.2.27 pulls from. -What this release changed outside the stored files is 0.2.27's to undo or keep. After the `tacctl upgrade --branch 0.2.27` that ends the rollback, the support bundle of a Cisco IOS device starts its identity lines with the tail of a long command's echo again, as it did in 0.2.27, when the device cuts its display of the command. The bundles made in between stay as they were made. +What 0.2.28 and this release changed outside the stored files is 0.2.27's to undo or keep. After the `tacctl upgrade --branch 0.2.27` that ends the rollback, the support bundle of a Cisco IOS device starts its identity lines with the tail of a long command's echo again, as it did in 0.2.27, when the device cuts its display of the command. The bundles made in between stay as they were made. ```bash tacctl rollback 0.2.27 # the dry run: steps, writes nothing @@ -366,9 +378,9 @@ tacctl upgrade --branch 0.2.27 # install 0.2.27 ### To 0.2.26 -0.2.26 reads every file 0.2.27 and this release write but one setting of `console.yaml`: they changed no other stored file it reads strictly (what the `show switch` reader accepts, what the reports of a user below the operator tier hold, the audit line of a prune of other users' reports, the PDF format of the reports and the offer of its tools, how the answer of a Cisco IOS device to a long command is read, the wording of two notes and the documentation are all that moved). So the rollback converts nothing but the file transfer settings of `console.yaml` (see above): with none set it removes no key and no field, takes no snapshot, needs no `--yes` and leaves every file alone. The limits of the stored reports (`reports.max_size` and `reports.max_count` in `tacctl.yaml`, and a user's own limits in `store.yaml`) stay, 0.2.26 has them, as do the chassis `members` of the pull records and every report in the users' homes, which 0.2.26 reads. The per-tier sudoers drop-in is left too: 0.2.26, 0.2.27 and this release write the same text. The break-glass firewall, the users' email addresses, the SNMPv3 users, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (with or without enrolled hosts) all stay. It still refuses while an apply is not settled. `--hosts` is accepted and does nothing. The tacquito checkout in `/opt/tacquito-src` keeps pointing at the project's fork, which is what 0.2.26 pulls from. +0.2.26 reads every file 0.2.27, 0.2.28 and this release write but one setting of `console.yaml`: they changed no other stored file it reads strictly (what the `show switch` reader accepts, what the reports of a user below the operator tier hold, the audit line of a prune of other users' reports, the PDF format of the reports and the offer of its tools, how the answer of a Cisco IOS device to a long command is read, the wording of two notes and the documentation are all that moved). So the rollback converts nothing but the file transfer settings of `console.yaml` (see above): with none set it removes no key and no field, takes no snapshot, needs no `--yes` and leaves every file alone. The limits of the stored reports (`reports.max_size` and `reports.max_count` in `tacctl.yaml`, and a user's own limits in `store.yaml`) stay, 0.2.26 has them, as do the chassis `members` of the pull records and every report in the users' homes, which 0.2.26 reads. The per-tier sudoers drop-in is left too: 0.2.26 to 0.2.28 and this release write the same text. The break-glass firewall, the users' email addresses, the SNMPv3 users, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (with or without enrolled hosts) all stay. It still refuses while an apply is not settled. `--hosts` is accepted and does nothing. The tacquito checkout in `/opt/tacquito-src` keeps pointing at the project's fork, which is what 0.2.26 pulls from. -What 0.2.27 and this release changed outside the stored files is 0.2.26's to undo or keep. After the `tacctl upgrade --branch 0.2.26` that ends the rollback, a row of `show switch` whose H/W version column is blank is not read again by the next `device config pull`, as in 0.2.26, and the reports a user below the operator tier makes hold the model, serial number, release and chassis members of a device again, as they did in 0.2.26. The reports made in between stay as they were made. +What 0.2.27, 0.2.28 and this release changed outside the stored files is 0.2.26's to undo or keep. After the `tacctl upgrade --branch 0.2.26` that ends the rollback, a row of `show switch` whose H/W version column is blank is not read again by the next `device config pull`, as in 0.2.26, and the reports a user below the operator tier makes hold the model, serial number, release and chassis members of a device again, as they did in 0.2.26. The reports made in between stay as they were made. ```bash tacctl rollback 0.2.26 # the dry run: steps, writes nothing @@ -378,7 +390,7 @@ tacctl upgrade --branch 0.2.26 # install 0.2.26 ### To 0.2.25 -0.2.25 reads every file 0.2.26, 0.2.27 and this release write but the limits of the stored reports, so the rollback removes those and converts nothing else but the file transfer settings of `console.yaml` (see above): the settings `reports.max_size` and `reports.max_count` from `tacctl.yaml`, and the users' own limits from `store.yaml`. With none of them set it converts nothing, takes no snapshot and does not need `--yes`; with a setting or a limit of a user it takes the snapshot first, and a limit of a user needs `--yes`. When it took a snapshot, the next steps say that it holds the 0.2.28 state and is to be restored with 0.2.28 only, and says what 0.2.25's restore refuses: a `tacctl.yaml` with a key it does not know when a setting was removed, a `store.yaml` with a field it does not know when only a user's own limit was, both when both were. It puts back the per-tier sudoers drop-in that 0.2.25 wrote, this release's without the rows of `device reports`, when the file is exactly this release's text: the dry run shows the step, `--apply` writes it after `visudo -cf` (no snapshot holds a sudoers file), and a file `tacctl` did not write is left. It leaves the `members` of the pull records (0.2.25 ignores the key) and every report in the users' homes, and ends with the note about them and about the three commands that write a limit again. The break-glass firewall, the users' email addresses, the SNMPv3 users, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (with or without enrolled hosts) all stay. It still refuses while an apply is not settled. `--hosts` is accepted and does nothing. The tacquito checkout in `/opt/tacquito-src` keeps pointing at the project's fork, which is what 0.2.25 pulls from. +0.2.25 reads every file 0.2.26 to 0.2.28 and this release write but the limits of the stored reports, so the rollback removes those and converts nothing else but the file transfer settings of `console.yaml` (see above): the settings `reports.max_size` and `reports.max_count` from `tacctl.yaml`, and the users' own limits from `store.yaml`. With none of them set it converts nothing, takes no snapshot and does not need `--yes`; with a setting or a limit of a user it takes the snapshot first, and a limit of a user needs `--yes`. When it took a snapshot, the next steps say that it holds the 0.2.28 state and is to be restored with 0.2.28 only, and says what 0.2.25's restore refuses: a `tacctl.yaml` with a key it does not know when a setting was removed, a `store.yaml` with a field it does not know when only a user's own limit was, both when both were. It puts back the per-tier sudoers drop-in that 0.2.25 wrote, this release's without the rows of `device reports`, when the file is exactly this release's text: the dry run shows the step, `--apply` writes it after `visudo -cf` (no snapshot holds a sudoers file), and a file `tacctl` did not write is left. It leaves the `members` of the pull records (0.2.25 ignores the key) and every report in the users' homes, and ends with the note about them and about the three commands that write a limit again. The break-glass firewall, the users' email addresses, the SNMPv3 users, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (with or without enrolled hosts) all stay. It still refuses while an apply is not settled. `--hosts` is accepted and does nothing. The tacquito checkout in `/opt/tacquito-src` keeps pointing at the project's fork, which is what 0.2.25 pulls from. ```bash tacctl rollback 0.2.25 # the dry run: steps, writes nothing @@ -405,15 +417,15 @@ tacctl upgrade --branch 0.2.24 # install 0.2.24 ### To 0.2.23 -0.2.23 reads every file 0.2.24 to 0.2.27 and this release write but `breakglass.firewall` +0.2.23 reads every file 0.2.24 to 0.2.28 and this release write but `breakglass.firewall` (0.2.24's) and the limits of the stored reports (0.2.26's). The rollback removes the key when it is set, after a snapshot, with the table, the rules file and the boot unit of the break-glass firewall (above), and the limits as above (`--yes` while a user has one of their own). It converts no other file; with the key unset, no firewall file and no limit it takes no snapshot and does not need `--yes`. When it took one, the next steps say that the -snapshot holds the 0.2.28 state and is to be restored with 0.2.28 only: 0.2.23's +snapshot holds the 0.2.29 state and is to be restored with 0.2.29 only: 0.2.23's restore refuses the snapshot's `tacctl.yaml`, which has the key. It puts back 0.2.23's per-tier sudoers drop-in, without the operator's `log failures *` (0.2.23 has no log filters), when the -file is exactly the text 0.2.24 and 0.2.25 wrote, or the one 0.2.26, 0.2.27 and this release write: the dry run shows the step, `--apply` +file is exactly the text 0.2.24 and 0.2.25 wrote, or the one 0.2.26 to 0.2.28 and this release write: the dry run shows the step, `--apply` writes it after `visudo -cf`, and a file `tacctl` did not write is left. Every older target that rewrites the per-tier drop-in recognises this release's text, 0.2.25's and 0.2.23's as `tacctl`'s own and puts back its own. The users' email addresses, the SNMPv3 users, the covered staging entries, the @@ -433,7 +445,7 @@ tacctl upgrade --branch 0.2.23 # install 0.2.23 ### To 0.2.22 -0.2.22 reads every file 0.2.23 to 0.2.27 and this release write but the users' email addresses in +0.2.22 reads every file 0.2.23 to 0.2.28 and this release write but the users' email addresses in `store.yaml`, so the rollback removes those and the limits of the stored reports (above) and converts nothing else but the sudoers drop-in (below): the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (of diff --git a/docs/releasing.md b/docs/releasing.md index fd112235..db7f226f 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -96,9 +96,9 @@ the fork catches up. Also before the first step, on `develop`: - **The rollback target.** Every release ships `tacctl rollback ` (0.2.17 to 0.2.27 each did). Check that the release before this - one is a constant in `internal/lifecycle/rollback.go` (`RollbackTarget0227` - for 0.2.28) and is the one the refusal names "(the release before this + release>` (0.2.17 to 0.2.28 each did). Check that the release before this + one is a constant in `internal/lifecycle/rollback.go` (`RollbackTarget0228` + for 0.2.29) and is the one the refusal names "(the release before this one)" (`internal/lifecycle/rollback_test.go`), that the `rollback` entry of `man/tacctl.1` lists it the same way, that the CHANGELOG has its item, and that `const rollbackFrom` in `internal/cli/rollback.go` is this release (the diff --git a/man/tacctl.1 b/man/tacctl.1 index 2afbf296..e9142211 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -418,8 +418,9 @@ The tacctl repo branch to install or upgrade from (default: the current one). Prepare tacctl's state for the release before this one; run on the newer release, before the older one is installed. A dry run by default: it lists every step and every warning and changes nothing. The versions it takes are -.B 0.2.27 +.B 0.2.28 (the release before this one), +.BR 0.2.27 , .BR 0.2.26 , .BR 0.2.25 , .BR 0.2.24 , @@ -441,12 +442,12 @@ and older are refused, with the way there (one release at a time: this rollback, .BR "tacctl upgrade \-\-branch 0.2.9" , then the rollback of that release), and so is any other word (0.2.10 to -0.2.15 included: the refusal names the targets). Every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20 +0.2.15 included: the refusal names the targets). Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22, 0.2.21, 0.2.20 and 0.2.19 is refused while an emergency lockdown locks a group (the refusal lists each one and .B "emergency lockdown disable" lifts it; a release before 0.2.19 would render the locked users back into the -scope; 0.2.19 has the record and keeps it), every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 is refused while an emergency lockdown stands on a scope that has enrolled hosts, or a lifted one still waits for a host to drop sshd's lockdown drop\-in (older releases cannot lift it on a host; lift it and sync the hosts first), and every target is refused while a device's record says a confirmed commit of +scope; 0.2.19 has the record and keeps it), every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 is refused while an emergency lockdown stands on a scope that has enrolled hosts, or a lifted one still waits for a host to drop sshd's lockdown drop\-in (older releases cannot lift it on a host; lift it and sync the hosts first), and every target is refused while a device's record says a confirmed commit of .B "device config apply" is .B pending @@ -461,7 +462,7 @@ settles it). The and .B users mappings of console.yaml that this release ignores stay in the file, and a -release before 0.2.20 (the targets 0.2.19 and older; 0.2.27 to 0.2.20 ignore +release before 0.2.20 (the targets 0.2.19 and older; 0.2.28 to 0.2.20 ignore them too, and their rollback says nothing of it) reads them as it always did: a user or a tier switched off there gets a plain shell again, and the password cache is on again for every user of a tier that is allowed it, so the plan lists each user who @@ -469,7 +470,7 @@ would gain a system shell or the cache, with the reason, as a warning that .B \-\-apply refuses without .BR \-\-yes . -Every target before 0.2.20 (0.2.19 and older; 0.2.27 to 0.2.20 read them and leave them) also takes out of +Every target before 0.2.20 (0.2.19 and older; 0.2.28 to 0.2.20 read them and leave them) also takes out of .I console.yaml the settings of 0.2.20 that no release before it reads: .BR settings.color , @@ -485,7 +486,7 @@ stay, for the releases that have them) are removed and a of \-1 (never ask) is written as 1000, with every other setting kept and a snapshot first. .IP -Every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22 and 0.2.21, which have it themselves, keeps every user's +Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22 and 0.2.21, which have it themselves, keeps every user's login to this server: an older release answers it only for the users that have the server's scope .RB ( tacctl ) @@ -494,16 +495,16 @@ to the server and lacks it (it counts and names them; a warning, so .B \-\-apply needs .BR \-\-yes ), -after a snapshot. Every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23 and 0.2.22 removes +after a snapshot. Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23 and 0.2.22 removes .B server.name (the name of .BR "server name" ), -and every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22 and 0.2.21 +and every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23, 0.2.22 and 0.2.21 .B server.addresses as well, from .IR tacctl.yaml , which no older release knows; the host registry keeps the address in this -server's entry. Every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23 and 0.2.22 also removes the timing scale: +server's entry. Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24, 0.2.23 and 0.2.22 also removes the timing scale: .B device.timeout_scale and .B timeout_scale_scope.\fIscope\fR @@ -518,7 +519,7 @@ key it does not know). It is a note in the plan, not a warning: the older release connects to every device with its fixed timings again, which a slow or distant device may not meet, and the values stay in the snapshot. .IP -Every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 removes the users' email addresses +Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 removes the users' email addresses .RB ( "user email" , .BR "user add \-\-email" ) from @@ -546,7 +547,7 @@ snapshot and the users. A store that cannot be read refuses every target. Until the older release is installed, the two verbs that set an address write the key again, and the command says so. .IP -Every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 writes the SNMP credential files +Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 writes the SNMP credential files .RI ( snmp.yaml , .IR snmp/ scope .yaml , .IR snmp/devices/ name .yaml ) @@ -575,7 +576,7 @@ the audit line adds and the apply names .BR "tacctl backup recover \-\-only snmp\-users" . .IP -Every target but 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 drops from +Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 drops from .I state/staging the entries marked .B covered @@ -589,7 +590,7 @@ A clone that still waits for its .B "device rename \-\-replace" loses its entry, and after a re-upgrade the verb refuses it as not staged: remove the clone and clone again from the original, or restore the snapshot. Every other entry stays. .IP -Every target but 0.2.27, 0.2.26, 0.2.25 and 0.2.24 removes the break\-glass firewall: the key +Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25 and 0.2.24 removes the break\-glass firewall: the key .B breakglass.firewall (when set; every older release refuses it, so it is removed after the snapshot like the other keys they do not know), the nftables table @@ -635,7 +636,7 @@ and then .BR "systemctl daemon\-reload" . .IP -Every target before 0.2.26 (0.2.25 and older; 0.2.26 and 0.2.27 read the limits and keep them) removes the limits of the stored reports of +Every target before 0.2.26 (0.2.25 and older; 0.2.26 to 0.2.28 read the limits and keep them) removes the limits of the stored reports of .BR "device reports" : the settings .B reports.max_size @@ -685,14 +686,14 @@ again (with .B \-\-yes while a user has a limit of their own). .IP -Every target removes the file transfer settings of the console, +Every target but 0.2.28 removes the file transfer settings of the console, .B settings.file_transfer in .I console.yaml .RB ( "console file\-transfer" ), the target .B 0.2.27 -included: no release before 0.2.28 reads the key (its reader answers +included (0.2.28 reads the key, and so does this release): no release before 0.2.28 reads the key (its reader answers .BR "settings: unknown key" , the console falls back to its defaults and the commands that write the file fail). It goes after the snapshot, with the other settings of the file the @@ -706,13 +707,45 @@ installed, run no that sets something, which writes the key again (run the rollback again if one was run), and the snapshot may be restored with this release only. .IP +.B "rollback 0.2.28" +converts nothing: this release changed no stored file 0.2.28 reads strictly +(the mode a file uploaded through the console gets, a test and the +documentation are all that moved), so 0.2.28 reads every file this release +writes. It removes no key and no field (the file transfer settings of +.IR console.yaml , +.B settings.file_transfer +(0.2.28 has them), the limits of the stored reports, the settings +.B reports.max_size +and +.B reports.max_count +and a user's own limits, stay, and so do the break\-glass firewall and its setting, the +email addresses, the SNMP credential files, the covered staging entries, the +server name, the timing scale, the server address, the users' login to this +server and an emergency lockdown, with or without enrolled hosts), leaves the +per\-tier sudoers drop\-in (0.2.28 and this release write the same text), the +pull records, every report in the users' homes, the PDF ones included, and the marker +.I /var/lib/tacctl/pdf\-tools\-offered +(the packages +.B weasyprint +and +.B fonts\-dejavu\-core +stay installed), takes no snapshot and needs no +.BR \-\-yes . +It is refused only while a device's apply is not settled. +.B \-\-hosts +is accepted and does nothing. The command ends with the next step, +.BR "tacctl upgrade \-\-branch 0.2.28" , +with no note to follow: the settings, the limits and the reports are 0.2.28's own. +After the upgrade a file a client uploads through the console is created with the +mode 0644 (0600 after the umask of the console) whatever mode it asks for, as in 0.2.28. +.IP .B "rollback 0.2.27" converts only the file transfer settings of .IR console.yaml : -this release changed no other stored file 0.2.27 reads strictly (how -the answer of a Cisco IOS device to a long command is read, and the -documentation, are all that moved), so 0.2.27 reads every other file this release -writes. It removes no other key and no field (the limits of the stored reports, the +0.2.28 and this release changed no other stored file 0.2.27 reads strictly (how +the answer of a Cisco IOS device to a long command is read, the mode of a file uploaded +through the console, and the documentation, are all that moved), so 0.2.27 reads every other file +they write. It removes no other key and no field (the limits of the stored reports, the settings .B reports.max_size and @@ -721,7 +754,7 @@ and a user's own limits, stay: 0.2.27 has them, and so do the break\-glass firew email addresses, the SNMP credential files, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown, with or without enrolled hosts), leaves the -per\-tier sudoers drop\-in (0.2.27 and this release write the same text), the +per\-tier sudoers drop\-in (0.2.27, 0.2.28 and this release write the same text), the pull records, every report in the users' homes, the PDF ones included (0.2.27 has the format and reads them), and the marker .I /var/lib/tacctl/pdf\-tools\-offered @@ -743,13 +776,13 @@ limits and the reports are 0.2.27's own. .B "rollback 0.2.26" converts only the file transfer settings of .IR console.yaml : -0.2.27 and this release changed no other stored file 0.2.26 reads strictly (what +0.2.27, 0.2.28 and this release changed no other stored file 0.2.26 reads strictly (what the .B "show switch" reader accepts, what the reports of a user below the operator tier hold, the audit line of a prune of other users' reports, the PDF format of the reports and the offer of its tools, how the answer of a Cisco IOS device to a long command is read, the wording of two notes and the -documentation are all that moved), so 0.2.26 reads every file 0.2.27 and this release +documentation are all that moved), so 0.2.26 reads every file 0.2.27, 0.2.28 and this release write. It removes no other key and no field (the limits of the stored reports, the settings .B reports.max_size @@ -759,7 +792,7 @@ and a user's own limits, stay: 0.2.26 has them, and so do the break\-glass firew email addresses, the SNMP credential files, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown, with or without enrolled hosts), leaves the -per\-tier sudoers drop\-in (0.2.26, 0.2.27 and this release write the same text), the +per\-tier sudoers drop\-in (0.2.26 to 0.2.28 and this release write the same text), the pull records and every report in the users' homes (0.2.26 reads them; a PDF one as text, see Rolling back in the upgrading page), takes the snapshot only when the file transfer settings are set and needs no .BR \-\-yes . @@ -770,8 +803,8 @@ is accepted and does nothing. The command ends with the next step, with no note to follow but the one above when the settings were removed: the limits and the reports are 0.2.26's own. .IP .B "rollback 0.2.25" -removes the limits of the stored reports of 0.2.26, 0.2.27 and this release and converts nothing -else but the file transfer settings of the console: 0.2.25 reads every other file 0.2.26, 0.2.27 and this release write (the break\-glass +removes the limits of the stored reports of 0.2.26 to 0.2.28 and this release and converts nothing +else but the file transfer settings of the console: 0.2.25 reads every other file 0.2.26 to 0.2.28 and this release write (the break\-glass firewall and its setting, the email addresses, the SNMP credential files, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown, with or without @@ -798,7 +831,7 @@ refuses without naming each user and the values (see below). The per\-tier sudoers drop\-in is rewritten, after .BR "visudo \-cf" , -with the text 0.2.25 wrote, the text of 0.2.26, 0.2.27 and this release without the rows of +with the text 0.2.25 wrote, the text of 0.2.26 to 0.2.28 and this release without the rows of .BR "device reports" , when the file is exactly that text (no snapshot holds it; a file tacctl did not write is left). The @@ -807,7 +840,7 @@ of the pull records are left (0.2.25's decoder ignores the key), and so is every report in the users' homes: they are the users' own files, and 0.2.25 has no .B "device reports" verb to list or remove them. When the snapshot was taken, the next steps say -that it holds the 0.2.28 state and is to be restored with 0.2.28 only, and what +that it holds the 0.2.29 state and is to be restored with 0.2.29 only, and what 0.2.25's restore refuses: a tacctl.yaml with a key it does not know when a setting was removed, a store.yaml with a field it does not know when only a user's own limit was, both when both were. The command ends @@ -845,19 +878,19 @@ is accepted and does nothing. The command ends with the next step, .B "rollback 0.2.23" converts no file but the key .B breakglass.firewall -(0.2.24's) and the limits of the stored reports (0.2.26's; when either is set the snapshot is taken): 0.2.24 to 0.2.27 and this release changed no other stored file, so 0.2.23 reads every file they +(0.2.24's) and the limits of the stored reports (0.2.26's; when either is set the snapshot is taken): 0.2.24 to 0.2.28 and this release changed no other stored file, so 0.2.23 reads every file they write (the email addresses, the SNMP credential files, the covered staging entries, the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown, with or without enrolled hosts, all stay), the per\-tier sudoers drop\-in is put back as 0.2.23 wrote it (without the operator's .BR "log failures *" ; -when it is exactly the text of 0.2.24 and 0.2.25, or the one 0.2.26, 0.2.27 and this release write, it is rewritten, after +when it is exactly the text of 0.2.24 and 0.2.25, or the one 0.2.26 to 0.2.28 and this release write, it is rewritten, after .BR "visudo \-cf" , and any other file is left), no snapshot is taken for them and .B \-\-yes is never needed unless a user has an own limit of the stored reports. When the key was set the snapshot was taken, and the next steps -say that it holds the 0.2.28 state and is to be restored with 0.2.28 only +say that it holds the 0.2.29 state and is to be restored with 0.2.29 only (0.2.23's restore refuses its tacctl.yaml, which has the key). It is refused only while a device's apply is not settled. Every older target that rewrites that drop\-in recognises this release's text, 0.2.25's and 0.2.23's as tacctl's own and puts back its own. @@ -890,7 +923,7 @@ converts nothing but the email addresses, the SNMP credential files, the covered with 0.2.22's: the engineer's rule of .B "device clone" is taken out; an edited drop\-in is left): 0.2.22 -reads every other file 0.2.23 to 0.2.27 and this release write, so the server name, the timing +reads every other file 0.2.23 to 0.2.28 and this release write, so the server name, the timing scale, the server address, the users' login to this server and an emergency lockdown (of scopes with no enrolled host) stay. With no address in the store, no SNMP @@ -1015,7 +1048,7 @@ An older release lints such a block as an error and plans nothing for the devices it reaches. The block files are not rewritten; take the statements out before the upgrade. .IP -Every target before 0.2.20 (0.2.19 and older; 0.2.27 to 0.2.20 read it and leave it) removes the management filter mode of the scopes +Every target before 0.2.20 (0.2.19 and older; 0.2.28 to 0.2.20 read it and leave it) removes the management filter mode of the scopes .RB ( scope_mgmt_acl.mode.\fIscope\fR , only .B strict @@ -1037,7 +1070,7 @@ or would put that filter back on a device that holds the strict one, without saying so. The rollback is not refused, and no device is contacted. .IP -Every target but 0.2.27 to 0.2.20 (which read it) removes the required password change +Every target but 0.2.28 to 0.2.20 (which read it) removes the required password change .RB ( password_change_required of a user in .IR store.yaml , From 886a2eb0ad64cc8aa3a3ff1358ddff3a62ffc3b3 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:42:52 -0900 Subject: [PATCH 37/52] tacctl ssh: --login logs in as a local account of the device In the console the words after -- are the remote command, so ssh's own -l admin is refused, and while break-glass is held on a device only its local accounts work. 'tacctl ssh --login ' (and 'device ssh', the same code path) runs ssh as the caller with -l in place of the caller's name. Registered devices of any vendor only: an enrolled host is refused in one sentence and nothing is started. The device must have a pinned host key (refused with the device hostkey command otherwise); ssh then checks it strictly against the pin as for a plain session. The tier is the engineer's and up, through deviceVerbAllowed like the other --login verbs; the device must be in one of the caller's scopes (sshAdmit, as for every ssh). The account name goes through localAccountOf. The device asks for the password at its own prompt. The password cache is never used for such a line: the shell leaves it shut (askpassWords), the invocation drops the variable unread and makes no client, so nothing is asked, stored or forgotten, not even on status 255. The session start and end audit lines end with login= (no password field); a plain session's lines are unchanged. The held-device warning says the local account is what is used. The usage, the explain text, the completion spec (a --login value flag with no candidates) and the generated blocks of the man page come with it. Tests use the fake runner and a real cache agent to check that the cache is untouched. The documentation pages and the CHANGELOG item are in the next commit. --- internal/cli/device.go | 2 +- internal/cli/password_cache.go | 18 +- internal/cli/password_cache_test.go | 5 + internal/cli/shell_test.go | 2 +- internal/cli/ssh.go | 105 +++++++- internal/cli/ssh_login_test.go | 386 ++++++++++++++++++++++++++++ internal/cli/ssh_test.go | 2 +- man/tacctl.1 | 49 +++- 8 files changed, 550 insertions(+), 19 deletions(-) create mode 100644 internal/cli/ssh_login_test.go diff --git a/internal/cli/device.go b/internal/cli/device.go index f5018da5..bcab7ad3 100644 --- a/internal/cli/device.go +++ b/internal/cli/device.go @@ -225,7 +225,7 @@ var deviceVerbs = [][2]string{ {"snmp v3-user add|remove|default|list []", "The device's v3 user pool: add, remove, default (any pool it sees), list"}, {"snmp clear", "Remove everything the device sets of its own: its scope's settings apply again"}, {deviceBlockUse, "A device's own configuration blocks (snmp and system, for Junos and IOS) over its scope's: list, show, check, set, remove, edit, adopt"}, - {"ssh [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ]", "Alias of 'tacctl ssh': a session to the device, as you"}, + {"ssh [--login ] [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ]", "Alias of 'tacctl ssh': a session to a device, as you or a local account"}, {"client-config", "Print an ssh_config Include for your devices (Host blocks, pinned keys)"}, {"scan [--full] [--since ] [--backend ] [--sources]", "Read the logs for the devices seen; re-scan pinned host keys"}, {"discover [--all] [--snmp] [--backend ]", "Scan, then list the addresses that authenticated unregistered (--snmp: read each one's name and vendor by SNMP for the add lines)"}, diff --git a/internal/cli/password_cache.go b/internal/cli/password_cache.go index a4d91f4a..15359d81 100644 --- a/internal/cli/password_cache.go +++ b/internal/cli/password_cache.go @@ -261,10 +261,12 @@ func askpassWords(words []string) bool { switch { case len(words) == 0: return false + // a session as a device's local account (--login) never asks the cache: + // the device asks the password, and the line leaves the cache shut case words[0] == "ssh": - return true + return !localLoginLine(words[1:]) case words[0] == "device" && len(words) > 1 && words[1] == "ssh": - return true + return !localLoginLine(words[2:]) // a read as a device's local account (--login, 0.2.9 D136) never asks // the cache: its line leaves it shut case words[0] == "device" && len(words) > 2 && words[1] == "config" && localLoginLine(words[3:]): @@ -406,3 +408,15 @@ func (inv *invocation) takeAskpass() *askpass.Client { c.ExpectUID = uid return c } + +// dropAskpass discards the cache's value for this process unread, for a line +// that must not use the cache (a local account's login): no client is made +// from it, the value kept by captureAskpass is cleared, and the process +// environment is cleared of it as askpassValue does. +func (inv *invocation) dropAskpass() { + if inv.hooks != nil && inv.hooks.askpassFromApp { + return // a test: the app's environment only, no process state touched + } + processAskpass = "" + _ = os.Unsetenv(askpass.EnvVar) //nolint:forbidigo // removing the token, not reading the environment +} diff --git a/internal/cli/password_cache_test.go b/internal/cli/password_cache_test.go index 849b0291..995d4120 100644 --- a/internal/cli/password_cache_test.go +++ b/internal/cli/password_cache_test.go @@ -618,6 +618,11 @@ func TestAskpassWords(t *testing.T) { "device collect 192.0.2.1": true, "device collect --discovered --register": true, "device collect 192.0.2.1 --login admin": false, "device collect --discovered --login=root": false, "device sync x": false, "device sync --all --apply": false, + // a session as a device's local account asks the device, never the + // cache; after '--' the word is the remote command's + "ssh core-sw1 --login admin": false, "device ssh core-sw1 --login=admin -p 22": false, "ssh --login admin core-sw1": false, + "device ssh core-sw1 -L 8443:localhost:443 --login admin": false, "ssh core-sw1 -- show --login": true, + "device ssh core-sw1 -p 22 -- --login admin": true, // 'enroll' pulls and may apply as the caller (0.2.17) "device enroll 192.0.2.1": true, "device enroll --discovered": true, "ssh": true, "device": false, "device config": false, "ssh core-sw1 -- show version": true, "device ssh core-sw1 -- -v": true, diff --git a/internal/cli/shell_test.go b/internal/cli/shell_test.go index 49e54bc7..a86fb322 100644 --- a/internal/cli/shell_test.go +++ b/internal/cli/shell_test.go @@ -713,7 +713,7 @@ func TestShellExplain(t *testing.T) { {[]string{"user", "add", "bob"}, []string{"Next: \n"}}, {[]string{"user", "add", "bob", "ops"}, []string{"Next: to run\n"}}, {[]string{"ssh", "core1"}, []string{ - "Usage:\n ssh [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ] Open an ssh session", + "Usage:\n ssh [--login ] [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ] Open an ssh session", "\n -p ", "Connect to this port", "Next: to run\n", }}, diff --git a/internal/cli/ssh.go b/internal/cli/ssh.go index 351e2f1e..8fa89eb8 100644 --- a/internal/cli/ssh.go +++ b/internal/cli/ssh.go @@ -33,6 +33,13 @@ package cli // line, in its environment and nowhere else. The cache forgets the password // when ssh ends with status 255 (a refusal cannot be told from other failures // of the connection). +// +// With '--login ' (a registered device only, the engineer's tier +// and up, a pinned host key) ssh logs in as that local account of the device +// instead of the caller: '-l ', the password asked by the device +// itself. The password cache is not used for such a line (never read, never +// asked, never told to forget; the shell leaves it shut, askpassWords), and +// the log lines carry login=. import ( "context" @@ -55,6 +62,7 @@ import ( "github.com/rett/tacctl/internal/devreg" "github.com/rett/tacctl/internal/execx" "github.com/rett/tacctl/internal/hosts" + "github.com/rett/tacctl/internal/tier" "github.com/rett/tacctl/internal/ui" ) @@ -67,6 +75,9 @@ func init() { // handed to ssh as it is). var sshSpec = Spec{MaxArgs: 1, Args: []string{KindDevices}, Flags: []Flag{ {Names: []string{"-p"}, Value: true}, + {Names: []string{"--login"}, Value: true, Arg: "", + Desc: "Log in as this local account of the device, not as you", + Long: "Log in as this local account of the device (a break-glass one, or any other) instead of as you; the account's password is asked by the device itself, never by tacctl, and is not cached or stored. For registered devices of any vendor with a pinned host key, not enrolled hosts; the engineer tier and up, for a device in one of your scopes"}, {Names: []string{"-X"}}, {Names: []string{"-Y"}}, {Names: []string{"-g"}}, {Names: []string{"-L"}, Value: true, Repeat: true}, {Names: []string{"-R"}, Value: true, Repeat: true}, @@ -78,8 +89,8 @@ var sshSpec = Spec{MaxArgs: 1, Args: []string{KindDevices}, Flags: []Flag{ var reForwardSpec = regexp.MustCompile(`^[A-Za-z0-9.:/\[\]_*-]+$`) const ( - sshUse = "ssh [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ]" - sshShort = "Session to a registered device or enrolled host, as you (never root)" + sshUse = "ssh [--login ] [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ]" + sshShort = "Session to a device or host as you, or a device's local account" ) func sshCmd(inv *invocation) *cobra.Command { @@ -105,6 +116,15 @@ password-cache'), the first ssh to a device with a pinned host key asks for your password itself, before it connects, and keeps it for the session: the next ssh asks nothing. A refused password is forgotten. +--login logs in as that local account of the device instead (a +break-glass account, or any other; ssh's own -l is not available after --). +It is for registered devices of any vendor, not enrolled hosts, with a pinned +host key, and for engineers and up (the device must be in one of your scopes, +as for every ssh). The device asks for the account's password itself: tacctl +never asks for it, caches it or stores it, and the password cache is not used +for the line. + + --login Log in as this local account of the device, not as you -p Connect to this port (default: the device's port, else 22) -X, -Y Forward X11 (untrusted, trusted) to this server's display -L Forward a local port, as ssh -L (repeatable) @@ -127,6 +147,7 @@ Examples: tacctl ssh 10.99.0.1 -p 2222 tacctl ssh core-sw1 -- show version tacctl ssh core-sw1 -L 8443:localhost:443 + tacctl ssh core-sw1 --login admin ` } @@ -155,13 +176,20 @@ func (inv *invocation) ssh(args []string) error { inv.write(sshUsage()) return nil } - // The password cache's variable is read once and taken out of the - // environment before anything else runs. - cacheClient := inv.takeAskpass() var extra []string if i := slices.Index(args, "--"); i >= 0 { args, extra = args[:i], args[i+1:] } + // The password cache's variable is read once and taken out of the + // environment before anything else runs. A line with --login is a local + // account's, whose password the device asks and the cache never sees: the + // variable is dropped unread, with no client made from it. + var cacheClient *askpass.Client + if localLoginLine(args) { + inv.dropAskpass() + } else { + cacheClient = inv.takeAskpass() + } usage := "Usage: tacctl " + sshUse p, err := Parse(sshSpec, args) if err != nil { @@ -192,11 +220,22 @@ func (inv *invocation) ssh(args []string) error { if inv.sshConsole() && len(extra) > 0 && strings.HasPrefix(extra[0], "-") { return inv.usageErr("In the tacctl console the words after -- are the remote command; ssh's own options are not available.") } + login := "" + if p.Has("--login") { + if login, err = inv.localAccountOf(p.Value("--login"), usage); err != nil { + return err + } + // the engineer's, as the other --login verbs (a plain session is + // every tier's) + if err := inv.deviceVerbAllowed("device", "ssh --login", tier.Engineer); err != nil { + return err + } + } fwd, kinds, err := inv.sshForwarding(p, caller) if err != nil { return err } - plan, err := inv.sshResolve(p, caller, extra, fwd) + plan, err := inv.sshResolve(p, caller, login, extra, fwd) if err != nil { return err } @@ -220,6 +259,7 @@ func (inv *invocation) ssh(args []string) error { cmd := plan.cmd.Cmd(plan.args...) cacheNote := "" var cachedCmd execx.Cmd + // (a --login line has no client: cacheClient is nil) if cacheClient != nil && devreg.Pinned(e) && !optionAfterTarget { if have, err := cacheClient.Have(inv.ctx); err == nil { // Started as the user directly, not through sudo, so that the @@ -239,7 +279,11 @@ func (inv *invocation) ssh(args []string) error { switch e.Source { case devreg.SourceDevice: if _, held := inv.holdOf(e.Name, e.Address); held { - a.Out.Warn("break-glass is held on " + e.Name + ": it takes local accounts only") + if login != "" { + a.Out.Warn("break-glass is held on " + e.Name + ": you log in as its local account '" + login + "'") + } else { + a.Out.Warn("break-glass is held on " + e.Name + ": it takes local accounts only") + } } case devreg.SourceHost: if reg, err := inv.registry(); err == nil { @@ -261,7 +305,13 @@ func (inv *invocation) ssh(args []string) error { cmd, cached, cacheNote = cachedCmd, true, " password=asked" } } - a.Audit().Raw("auth.info", "ssh user="+caller+" device="+e.Name+" addr="+addr+forward+cacheNote+inv.originFields()) + // The local account of a --login line, in the start and end lines; no + // password field: the device asks it, tacctl never has it. + loginNote := "" + if login != "" { + loginNote = " login=" + login + } + a.Audit().Raw("auth.info", "ssh user="+caller+" device="+e.Name+" addr="+addr+forward+cacheNote+loginNote+inv.originFields()) start := a.Knobs.Now() code, _, startErr := hosts.Attached(inv.ctx, a.Runner, cmd, a.Stdin, a.Out) if cached && code == 255 { @@ -273,7 +323,7 @@ func (inv *invocation) ssh(args []string) error { code = 127 } a.Audit().Raw("auth.info", "ssh end user="+caller+" device="+e.Name+" status="+strconv.Itoa(code)+ - " duration="+console.Seconds(a.Knobs.Now().Sub(start))+inv.originFields()) + " duration="+console.Seconds(a.Knobs.Now().Sub(start))+loginNote+inv.originFields()) if startErr != nil { a.Out.Error("ssh could not be run (" + startErr.Error() + "); it comes with the openssh-client package.") return exit(code) @@ -330,7 +380,9 @@ func (inv *invocation) sshAskAndStore(c *askpass.Client, caller string) (stored // the profile, the pinning options of a pinned entry (whose known_hosts is // brought up to date first), then -p, '-l ', the target and the // extra arguments (after the target: ssh takes them as the remote command). -func (inv *invocation) sshResolve(p Parsed, caller string, extra, fwd []string) (sshPlan, error) { +// A --login line gets '-l ' in place of '-l ' (sshLoginEntry +// refuses first what it may not reach). +func (inv *invocation) sshResolve(p Parsed, caller, login string, extra, fwd []string) (sshPlan, error) { a := inv.app key := p.Args[0] _, res, err := inv.deviceLoad() @@ -348,6 +400,11 @@ func (inv *invocation) sshResolve(p Parsed, caller string, extra, fwd []string) if err := inv.sshAdmit(caller, e); err != nil { return sshPlan{}, err } + if login != "" { + if err := inv.sshLoginEntry(caller, login, e); err != nil { + return sshPlan{}, err + } + } target, ok := devreg.SSHTarget(e) if !ok { return sshPlan{}, inv.usageErr("'" + e.Name + "' is this server (enrolled with --local); there is no ssh session to open.") @@ -376,7 +433,12 @@ func (inv *invocation) sshResolve(p Parsed, caller string, extra, fwd []string) // No agent socket and no identity (an enrolled host's is the // provisioning account's): the session is the caller's, by password. opts := devreg.OptionArgs(devreg.SSHOptionsScaled(e, a.Paths.KnownHosts, inv.scaleOfEntry(e))) - plan.args = append(append(plan.args, fwd...), "-l", caller) + // the login is the caller's, or the local account of a --login line + user := caller + if login != "" { + user = login + } + plan.args = append(append(plan.args, fwd...), "-l", user) if inConsole { opts = append(sshConsoleOptions(inv.sshEscape(), len(fwd) > 0), opts...) plan.args = append(plan.args, "--") @@ -389,6 +451,27 @@ func (inv *invocation) sshResolve(p Parsed, caller string, extra, fwd []string) return plan, nil } +// sshLoginEntry is the refusal of an entry a --login line may not reach: +// only a registered device (an enrolled host is reached as the caller) with a +// pinned host key, since the local password is typed at a device whose key +// was verified. The scope of the entry is sshAdmit's, the same as for a plain +// session. A refusal is logged ('ssh DENY ... reason=login-host|login-unpinned +// login=') and nothing is started. +func (inv *invocation) sshLoginEntry(caller, login string, e devreg.Entry) error { + deny := func(reason, msg string, hint ...string) error { + inv.app.Audit().Raw("auth.warning", "ssh DENY user="+caller+" device="+e.Name+" scope="+dash(e.Scope)+" reason="+reason+" login="+login+inv.originFields()) + return inv.usageErr(append([]string{msg}, hint...)...) + } + switch { + case e.Source == devreg.SourceHost: + return deny("login-host", "--login is for registered devices: '"+e.Name+"' is an enrolled Linux host, and hosts are reached as you. Nothing was started.") + case !devreg.Pinned(e): + return deny("login-unpinned", "'"+e.Name+"' has no pinned host key, and a local password goes only to a device whose key was verified. Nothing was started.", + "Pin it after comparing it with the device console: tacctl device hostkey "+e.Name+" accept") + } + return nil +} + // sshCachedOptions are the options ssh gets besides the plan's when it // asks the password cache: one password prompt (a refused password is not // offered again), and the same closed set a console session has when the diff --git a/internal/cli/ssh_login_test.go b/internal/cli/ssh_login_test.go new file mode 100644 index 00000000..c3211d47 --- /dev/null +++ b/internal/cli/ssh_login_test.go @@ -0,0 +1,386 @@ +package cli + +import ( + "context" + "slices" + "strconv" + "strings" + "testing" + + "github.com/rett/tacctl/internal/askpass" + "github.com/rett/tacctl/internal/execx" + "github.com/rett/tacctl/internal/execx/fake" +) + +// 'tacctl ssh --login ' in-process (ssh.go, sshLoginEntry): +// the session logs in as a local account of the device. The argv is the +// plain session's with '-l '; a host, an unpinned device, a tier +// below the engineer's and a device outside the caller's scopes are refused +// before anything is started; the password cache is never used; the log +// lines carry login=. ssh runs through the fake runner; nothing reaches a +// host. + +// loginTier is the fake 'id -nG' of a user of the sandbox in the tier group. +func loginTier(user, group string) func(*fake.Runner) { + return func(r *fake.Runner) { + r.On([]string{"id", "-nG", "--", user}, execx.Result{Stdout: []byte(user + " tac-users " + group + "\n")}) + } +} + +// setEngineer makes the sandbox's operators engineers (the tier setting +// engineerSandbox writes) or, with false, puts the default back. +func setEngineer(sb *sandbox, on bool) { + sb.t.Helper() + text := "" + if on { + text = "tier:\n operator: engineer\n" + } + sb.write("state/tacctl.yaml", text, 0o600) +} + +// loginOpts are the ssh options every pinned session to lab-rtr2 has. +func loginOpts(sb *sandbox) string { + return "-o ConnectTimeout=10 -o PubkeyAuthentication=no -o PreferredAuthentications=keyboard-interactive,password " + + "-o UserKnownHostsFile=" + sb.path("var-lib", "ssh", "known_hosts") + + " -o GlobalKnownHostsFile=none -o StrictHostKeyChecking=yes -o HostKeyAlias=lab-rtr2 -o UpdateHostKeys=no" +} + +// The argv of a session as a local account: the caller's sudo, the device's +// options and pin, '-l ' in place of '-l ', the port and +// the forwardings as for a plain session, the words after '--' after the +// target, and no askpass of any kind. +func TestSSHLoginArgv(t *testing.T) { + sb, _, _ := sshSandbox(t) + setEngineer(sb, true) + opts := loginOpts(sb) + kh := sb.path("var-lib", "ssh", "known_hosts") + legacy := "-o KexAlgorithms=+diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 -o Ciphers=+aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa" + coreOpts := "-o ConnectTimeout=10 -o PubkeyAuthentication=no -o PreferredAuthentications=keyboard-interactive,password " + legacy + + " -o UserKnownHostsFile=" + kh + " -o GlobalKnownHostsFile=none -o StrictHostKeyChecking=yes -o HostKeyAlias=core-sw1 -o UpdateHostKeys=no" + for _, c := range []struct { + user string + script func(*fake.Runner) + args []string + want string + }{ + // an engineer, a superuser; ssh and device ssh + {"bob", loginTier("bob", "tac-engineer"), []string{"ssh", "lab-rtr2", "--login", "admin"}, + "sudo -u bob -H ssh " + opts + " -l admin 192.168.5.1"}, + {"bob", loginTier("bob", "tac-engineer"), []string{"device", "ssh", "192.168.5.1", "--login=admin"}, + "sudo -u bob -H ssh " + opts + " -l admin 192.168.5.1"}, + {"alice", nil, []string{"device", "ssh", "core-sw1", "--login", "bg-admin.1"}, + "sudo -u alice -H ssh " + coreOpts + " -l bg-admin.1 10.99.0.1"}, + // the option may come before the name + {"alice", nil, []string{"ssh", "--login", "root", "lab-rtr2"}, + "sudo -u alice -H ssh " + opts + " -l root 192.168.5.1"}, + // the port, every forwarding and the words after '--' as for a plain session + {"bob", loginTier("bob", "tac-engineer"), + []string{"ssh", "lab-rtr2", "--login", "admin", "-p", "2200", "-g", "-L", "8443:localhost:443", "-R", "8080:localhost:80", "-D", "1080", "--", "show", "version"}, + "sudo -u bob -H ssh " + opts + " -p 2200 -g -L 8443:localhost:443 -R 8080:localhost:80 -D 1080 -l admin 192.168.5.1 show version"}, + // ssh's own options after '--' are still handled as they are today + {"alice", nil, []string{"ssh", "lab-rtr2", "--login", "admin", "--", "-v", "show", "version"}, + "sudo -u alice -H ssh " + opts + " -l admin 192.168.5.1 -v show version"}, + } { + sb.sshRun(c.user, c.script, c.args...) + if sb.code != 0 { + t.Errorf("%s %v: exit %d %q", c.user, c.args, sb.code, sb.stderr()) + } + if got := sb.sshArgv(); got != c.want { + t.Errorf("%s %v:\n got %s\nwant %s", c.user, c.args, got, c.want) + } + if strings.Contains(sb.sshArgv(), "-l "+c.user+" ") { + t.Errorf("%v: the caller's name is a login on argv: %s", c.args, sb.sshArgv()) + } + } + // X11 goes to ssh through env(1) as for a plain session. + sb.cfgRun("", []string{"ssh", "lab-rtr2", "--login", "admin", "-Y"}, nil, "SUDO_USER=alice", "SUDO_UID="+uidOf("alice"), "DISPLAY=localhost:10.0") + if sb.code != 0 || !strings.HasPrefix(sb.sshArgv(), "sudo -u alice -H env DISPLAY=localhost:10.0 ssh ") || + !strings.HasSuffix(sb.sshArgv(), " -Y -l admin 192.168.5.1") { + t.Errorf("-Y (%d %q): %s", sb.code, sb.stderr(), sb.sshArgv()) + } +} + +// A session as a local account of the device is for registered devices +// only: an enrolled host (a --local one too) is refused with the reason, a +// device with no pinned host key is refused with the way to pin it, the name +// is checked, an address nobody registered is refused as ever, and a tier +// below the engineer's, or a device out of the caller's scopes, is refused as +// for the other --login verbs and for a plain session. Nothing is started. +func TestSSHLoginRefusals(t *testing.T) { + sb, _, _ := sshSandbox(t) + setEngineer(sb, true) + engineer := loginTier("bob", "tac-engineer") + for _, c := range []struct { + user string + script func(*fake.Runner) + args []string + err string + }{ + {"bob", engineer, []string{"ssh", "web1", "--login", "admin"}, + "--login is for registered devices: 'web1' is an enrolled Linux host, and hosts are reached as you. Nothing was started."}, + {"alice", nil, []string{"device", "ssh", "authsrv", "--login", "admin"}, + "'authsrv' is an enrolled Linux host, and hosts are reached as you. Nothing was started."}, + {"alice", nil, []string{"ssh", "oob-con1", "--login", "admin"}, + "'oob-con1' has no pinned host key, and a local password goes only to a device whose key was verified. Nothing was started."}, + {"alice", nil, []string{"ssh", "oob-con1", "--login", "admin"}, "tacctl device hostkey oob-con1 accept"}, + {"alice", nil, []string{"ssh", "lab-rtr2", "--login", "bad name"}, "--login takes the name of one of the device's local accounts (letters, digits, '.', '_' and '-'): 'bad name'"}, + {"alice", nil, []string{"ssh", "lab-rtr2", "--login", "-oProxyCommand=x"}, "--login takes the name of one of the device's local accounts"}, + {"alice", nil, []string{"ssh", "lab-rtr2", "--login"}, "--login"}, + {"alice", nil, []string{"ssh", "10.1.2.3", "--login", "admin"}, "'10.1.2.3' is not a registered device; register it: tacctl device add 10.1.2.3"}, + {"alice", nil, []string{"ssh", "nosuch", "--login", "admin"}, "Device 'nosuch' not found. List them with: tacctl device list"}, + // below the engineer's tier, with the wording of the other --login verbs + {"carol", loginTier("carol", "tac-readonly"), []string{"ssh", "lab-rtr2", "--login", "admin"}, "'tacctl device ssh --login' is not permitted for the readonly tier."}, + // a device outside the caller's scopes, at any tier + {"bob", engineer, []string{"ssh", "core-sw1", "--login", "admin"}, "'bob' has no access to scope 'prod' (device core-sw1)"}, + {"alice", nil, []string{"ssh", "edge-fw", "--login", "admin"}, "'alice' has no access to scope 'dmz' (device edge-fw)"}, + } { + sb.sshRun(c.user, c.script, c.args...) + if sb.code == 0 || !strings.Contains(sb.stderr(), c.err) { + t.Errorf("%s %v: %d %q, want %q", c.user, c.args, sb.code, sb.stderr(), c.err) + } + if a := sb.sshArgv(); a != "" { + t.Errorf("%s %v ran ssh: %s", c.user, c.args, a) + } + if sb.runner.Called("ssh-keyscan") { + t.Errorf("%s %v: scanned a device: %q", c.user, c.args, sb.runner.Argvs()) + } + if hasAuditPrefix(sb.runner, "auth.info", "ssh user=") { + t.Errorf("%s %v: a session was logged: %q", c.user, c.args, sb.runner.Argvs()) + } + } + // An operator (the default tier of bob) is below the engineer's. + setEngineer(sb, false) + sb.sshRun("bob", loginTier("bob", "tac-operator"), "device", "ssh", "lab-rtr2", "--login", "admin") + if sb.code == 0 || !strings.Contains(sb.stderr(), "'tacctl device ssh --login' is not permitted for the operator tier.") || sb.sshArgv() != "" { + t.Errorf("operator: %d %q %s", sb.code, sb.stderr(), sb.sshArgv()) + } + sb.sshRun("bob", loginTier("bob", "tac-operator"), "ssh", "lab-rtr2") + if sb.code != 0 { + t.Errorf("operator, plain: %d %q", sb.code, sb.stderr()) + } + setEngineer(sb, true) + // A refusal for the entry is logged with the account; the tier denial as + // every tier denial; no unpinned notice reaches the person first. + sb.sshRun("bob", engineer, "ssh", "web1", "--login", "admin") + if !hasAudit(sb.runner, "auth.warning", "ssh DENY user=bob device=web1 scope=lab reason=login-host login=admin") { + t.Errorf("no deny line for the host: %q", sb.runner.Argvs()) + } + sb.sshRun("alice", nil, "ssh", "oob-con1", "--login", "admin") + if !hasAudit(sb.runner, "auth.warning", "ssh DENY user=alice device=oob-con1 scope=prod reason=login-unpinned login=admin") || + strings.Contains(sb.stderr(), "hostkey-unpinned") { + t.Errorf("unpinned: %q %q", sb.stderr(), sb.runner.Argvs()) + } + sb.sshRun("carol", loginTier("carol", "tac-readonly"), "ssh", "lab-rtr2", "--login", "admin") + if !hasAudit(sb.runner, "auth.warning", "tier DENY user=carol tier=readonly cmd=device ssh --login") { + t.Errorf("no tier deny line: %q", sb.runner.Argvs()) + } + sb.sshRun("bob", engineer, "ssh", "core-sw1", "--login", "admin") + if !hasAudit(sb.runner, "auth.warning", "ssh DENY user=bob device=core-sw1 scope=prod reason=scope") { + t.Errorf("no scope deny line: %q", sb.runner.Argvs()) + } + // Without --login the same readonly user still reaches the device: the + // gate of the flag does not touch the plain session. + sb.sshRun("carol", loginTier("carol", "tac-readonly"), "ssh", "lab-rtr2") + if sb.code != 0 || !strings.HasSuffix(sb.sshArgv(), " -l carol 192.168.5.1") { + t.Errorf("plain readonly: %d %q %s", sb.code, sb.stderr(), sb.sshArgv()) + } +} + +// The session start and end lines carry login= and no password +// field; a plain session's lines are exactly what they were (no login field, +// the same bytes) whether or not the line before had one. +func TestSSHLoginAudit(t *testing.T) { + sb, _, _ := sshSandbox(t) + sb.sshRun("alice", nil, "ssh", "lab-rtr2", "--login", "admin", "-L", "8443:localhost:443") + if sb.code != 0 { + t.Fatalf("exit %d %q", sb.code, sb.stderr()) + } + if !hasAudit(sb.runner, "auth.info", "ssh user=alice device=lab-rtr2 addr=192.168.5.1 forward=local login=admin") || + !hasAuditMatch(sb.runner, "auth.info", `^ssh end user=alice device=lab-rtr2 status=0 duration=\d+ login=admin$`) { + t.Errorf("login lines: %q", sb.runner.Argvs()) + } + for _, c := range auditCalls(sb.runner) { + if strings.Contains(c.Line, "password=") { + t.Errorf("a password field: %s", c.Line) + } + } + // A plain session, with and without forwarding, status 4. + sb.sshRun("alice", func(r *fake.Runner) { r.On([]string{"sudo", "-u", "alice"}, execx.Result{Code: 4}) }, "ssh", "lab-rtr2") + if !hasAudit(sb.runner, "auth.info", "ssh user=alice device=lab-rtr2 addr=192.168.5.1") || + !hasAuditMatch(sb.runner, "auth.info", `^ssh end user=alice device=lab-rtr2 status=4 duration=\d+$`) { + t.Errorf("plain lines: %q", sb.runner.Argvs()) + } + sb.sshRun("alice", nil, "device", "ssh", "core-sw1", "-D", "1080") + if !hasAudit(sb.runner, "auth.info", "ssh user=alice device=core-sw1 addr=10.99.0.1 forward=dynamic") { + t.Errorf("plain forward line: %q", sb.runner.Argvs()) + } + for _, args := range [][]string{{"ssh", "lab-rtr2"}, {"ssh", "web1"}, {"ssh", "oob-con1", "--", "uptime"}} { + sb.sshRun("alice", nil, args...) + for _, c := range auditCalls(sb.runner) { + if strings.Contains(c.Line, "login") { + t.Errorf("%v: a plain line mentions a login: %s", args, c.Line) + } + } + } +} + +// From a console session the words after '--' stay the remote command and an +// option among them is refused; the target follows '--'; an unpinned device +// is refused; the lines end with the account and the session. +func TestSSHLoginConsole(t *testing.T) { + sb, _, _ := sshSandbox(t) + opts := loginOpts(sb) + hard := "-F /dev/null -o PermitLocalCommand=no -o ControlMaster=no -o ClearAllForwardings=yes -o ForwardAgent=no -o EscapeChar=none" + session := "TACCTL_CONSOLE=0123456789ab" + run := func(args ...string) { + t.Helper() + sb.cfgRun("", args, nil, "SUDO_USER=alice", "SUDO_UID="+uidOf("alice"), session) + } + run("ssh", "lab-rtr2", "--login", "admin", "-p", "2200", "--", "show", "version") + want := "sudo -u alice -H ssh " + hard + " " + opts + " -p 2200 -l admin -- 192.168.5.1 show version" + if sb.code != 0 || sb.sshArgv() != want { + t.Errorf("console argv (%d %q):\n got %s\nwant %s", sb.code, sb.stderr(), sb.sshArgv(), want) + } + if !hasAudit(sb.runner, "auth.info", "ssh user=alice device=lab-rtr2 addr=192.168.5.1 login=admin console=0123456789ab") || + !hasAuditMatch(sb.runner, "auth.info", `^ssh end user=alice device=lab-rtr2 status=0 duration=\d+ login=admin console=0123456789ab$`) { + t.Errorf("console log: %q", sb.runner.Argvs()) + } + run("ssh", "lab-rtr2", "--login", "admin", "--", "-o", "ProxyCommand=sh") + if sb.code != 1 || sb.sshArgv() != "" || !strings.Contains(sb.stderr(), "In the tacctl console the words after -- are the remote command; ssh's own options are not available.") { + t.Errorf("option after --: %d %q", sb.code, sb.stderr()) + } + // -l is no option of the console line either way + run("ssh", "lab-rtr2", "--login", "admin", "-l", "root") + if sb.code != 1 || sb.sshArgv() != "" || !strings.Contains(sb.stderr(), "Unknown option: '-l'") { + t.Errorf("-l: %d %q", sb.code, sb.stderr()) + } + run("ssh", "oob-con1", "--login", "admin") + if sb.code != 1 || sb.sshArgv() != "" || !strings.Contains(sb.stderr(), "has no pinned host key") { + t.Errorf("unpinned: %d %q", sb.code, sb.stderr()) + } +} + +// A hold on the device is no reason to stop: the session goes on as the +// account, and the warning says that is what is used. The plain session's +// warning is unchanged. +func TestSSHLoginHeldDevice(t *testing.T) { + sb, _, _ := sshSandbox(t) + sb.write("state/tacctl.yaml", sb.overrides()+"breakglass_hold:\n lab-rtr2:\n address: 192.168.5.1\n since: '2026-10-13T00:00:00Z'\n by: alice\n reason: console recovery\n", 0o600) + out := sb.sshRun("alice", nil, "ssh", "lab-rtr2", "--login", "bgadmin") + if sb.code != 0 || !strings.HasSuffix(sb.sshArgv(), " -l bgadmin 192.168.5.1") { + t.Fatalf("held, login: %d %q %s", sb.code, sb.stderr(), sb.sshArgv()) + } + if e := out; !strings.Contains(e, "break-glass is held on lab-rtr2: you log in as its local account 'bgadmin'") || strings.Contains(e, "takes local accounts only") { + t.Errorf("warning: %q", e) + } + out = sb.sshRun("alice", nil, "ssh", "lab-rtr2") + if sb.code != 0 || !strings.Contains(out, "break-glass is held on lab-rtr2: it takes local accounts only") { + t.Errorf("plain warning: %d %q", sb.code, out) + } + out = sb.sshRun("alice", nil, "ssh", "core-sw1", "--login", "admin") + if sb.code != 0 || strings.Contains(out, "break-glass") { + t.Errorf("not held: %d %q", sb.code, out) + } +} + +// The password cache is out of a session as a local account: with a client +// in the environment and a password cached, nothing is asked, taken, stored +// or forgotten (not even when ssh ends with 255), ssh is started through sudo +// with no askpass and none of the cache's variables, and the line's token is +// unspent. +func TestSSHLoginNeverUsesThePasswordCache(t *testing.T) { + b := newAskedBox(t) + const cached = "secret-pw-17" + if err := b.c.ag.Store([]byte(cached)); err != nil { + t.Fatal(err) + } + before := b.c.stored() + for _, args := range [][]string{ + {"ssh", "core-sw1", "--login", "admin"}, + {"device", "ssh", "core-sw1", "--login=admin"}, + {"ssh", "core-sw1", "-p", "22", "--login", "admin", "--", "show", "version"}, + } { + b.c.begin(t) + b.sb.cfgRun("", args, func(r *fake.Runner) { + r.On([]string{"sudo", "-u", "alice"}, execx.Result{Code: 255}) + r.On([]string{"ssh-keyscan"}, execx.Result{Stdout: keyscanOut("x", b.rsa)}) + }, "SUDO_USER=alice", "SUDO_UID="+strconv.Itoa(b.c.uid), "TERM=xterm", askpass.EnvVar+"="+b.c.ag.Env()) + if b.sb.code != 255 { + t.Fatalf("%v: exit %d %q", args, b.sb.code, b.sb.stderr()) + } + if len(b.prompts) != 0 || b.dumpOff != 0 { + t.Errorf("%v: asked for a password (%q, %d not-dumpable marks)", args, b.prompts, b.dumpOff) + } + call, ok := b.call() + if !ok { + t.Fatalf("%v: no ssh call: %q", args, b.sb.runner.Argvs()) + } + got := strings.Join(call.Argv(), " ") + if b.cachedPath(t) || !strings.HasPrefix(got, "sudo -u alice -H ssh ") || !strings.Contains(got, " -l admin ") || + call.Credential != nil || countPrefix(call.Env, askpass.EnvVar+"=") != 0 { + t.Errorf("%v: the cached path was taken: %s", args, got) + } + for _, bad := range []string{"SSH_ASKPASS", "NumberOfPasswordPrompts", "password=", cached} { + if strings.Contains(got, bad) || slices.ContainsFunc(call.Env, func(kv string) bool { return strings.Contains(kv, bad) }) { + t.Errorf("%v: %q on the ssh command: %s %q", args, bad, got, call.Env) + } + } + for _, c := range auditCalls(b.sb.runner) { + if strings.Contains(c.Line, "password=") { + t.Errorf("%v: audit line %q", args, c.Line) + } + } + // the token of the line was never spent: its one get still answers + pw, err := b.c.cl.Get(context.Background()) + if err != nil || string(pw) != cached { + t.Errorf("%v: the cache was used: %q %v", args, pw, err) + } + askpass.Zero(pw) + } + if got := b.c.stored(); got != before { + t.Errorf("stored into the cache: %d events, %d before", got, before) + } + b.c.mu.Lock() + for _, e := range b.c.events { + if e.Kind == askpass.EventForgotten { + t.Error("the cache was told to forget (ssh ended with 255)") + } + } + b.c.mu.Unlock() + if !b.c.ag.Cached() { + t.Error("the cached password is gone") + } + // An unusable client in the environment changes nothing either. + b.c.begin(t) + b.sb.cfgRun("", []string{"ssh", "core-sw1", "--login", "admin"}, nil, "SUDO_USER=alice", "SUDO_UID="+strconv.Itoa(b.c.uid), askpass.EnvVar+"=not-a-token") + if b.sb.code != 0 || !strings.Contains(b.sb.sshArgv(), " -l admin 10.99.0.1") { + t.Errorf("bad variable: %d %q %s", b.sb.code, b.sb.stderr(), b.sb.sshArgv()) + } +} + +// Without --login the cache is used as before: a second line over the same +// sandbox asks (the first ssh to a pinned device with the cache on and +// empty), so the flag's exclusion above is the flag's, not the sandbox's. +func TestSSHPlainStillUsesThePasswordCache(t *testing.T) { + b := newAskedBox(t) + b.ssh(0, true, "ssh", "core-sw1") + if b.sb.code != 0 || len(b.prompts) != 1 || !b.cachedPath(t) { + t.Errorf("plain: exit %d, %d prompts, cached path %v", b.sb.code, len(b.prompts), b.cachedPath(t)) + } + if !hasAudit(b.sb.runner, "auth.info", "ssh user=alice device=core-sw1 addr=10.99.0.1 password=asked") { + t.Errorf("no password=asked line: %q", b.sb.runner.Argvs()) + } +} + +// The line's variable is dropped, unread, for a --login line. +func TestDropAskpassClearsTheProcessValue(t *testing.T) { + serial(t) // processAskpass is process state + old := processAskpass + t.Cleanup(func() { processAskpass = old }) + processAskpass = "sock:token" + inv := &invocation{hooks: &hooks{}} + inv.dropAskpass() + if processAskpass != "" { + t.Errorf("kept %q", processAskpass) + } +} diff --git a/internal/cli/ssh_test.go b/internal/cli/ssh_test.go index 7ea35f75..70cd08e8 100644 --- a/internal/cli/ssh_test.go +++ b/internal/cli/ssh_test.go @@ -233,7 +233,7 @@ func TestSSHRefusals(t *testing.T) { } // No name: the usage, exit 0. out := sb.sshRun("alice", nil, "ssh") - if sb.code != 0 || !strings.Contains(out, "Usage: tacctl ssh [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ]") { + if sb.code != 0 || !strings.Contains(out, "Usage: tacctl ssh [--login ] [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ]") { t.Errorf("usage: %d %q", sb.code, out) } } diff --git a/man/tacctl.1 b/man/tacctl.1 index d01a7040..4b955522 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -11476,7 +11476,7 @@ Options: .RE .\" END GENERATED: command device hostkey .TP -.BI "device ssh " name|address " [ \-p " port " ] [ \-\- " "ssh args" " ]" +.BI "device ssh " name|address " [ \-\-login " local\-user " ] [ \-p " port " ] [ \-\- " "ssh args" " ]" The same as .BR "tacctl ssh" , below. @@ -11490,6 +11490,9 @@ Options: \fB\-p\fR \fI\fR Connect to this port (default: the device's port, else 22). .TP +\fB\-\-login\fR \fI\fR +Log in as this local account of the device (a break\-glass one, or any other) instead of as you; the account's password is asked by the device itself, never by tacctl, and is not cached or stored. For registered devices of any vendor with a pinned host key, not enrolled hosts; the engineer tier and up, for a device in one of your scopes. +.TP \fB\-X\fR Forward X11 to this server's display (untrusted, as ssh \-X). .TP @@ -14628,7 +14631,7 @@ Do not ask for confirmation. .\" END GENERATED: command device reports prune .SS SSH to a device \fB(tacctl ssh)\fR .TP -.BI "ssh " name|address " [ \-p " port " ] [ \-X | \-Y ] [ \-g ] [ { \-L | \-R | \-D } " spec " ]... [ \-\- " "ssh args" " ]" +.BI "ssh " name|address " [ \-\-login " local\-user " ] [ \-p " port " ] [ \-X | \-Y ] [ \-g ] [ { \-L | \-R | \-D } " spec " ]... [ \-\- " "ssh args" " ]" Open an ssh session to a registered device or an enrolled host, named by its name or its registered address. tacctl resolves the name as root and admits only an active tacctl user (in the store, not disabled, with a password) whose @@ -14811,6 +14814,41 @@ Words after that start with a dash, an unpinned device, and an account that is not in the local account database keep the prompt. An ssh that ends with status 255 makes the cache forget the password. +.IP +.BI \-\-login " local\-user" +logs in as that local account of the device instead of as the invoking user +(ssh's +.B \-l +is not available after +.BR \-\- , +in the console the words there are the remote command): the way in to a device +whose break-glass is held, which takes local accounts only. The name is +letters, digits, +.BR . , +.B _ +and +.BR \- . +It is for registered devices of any vendor, not for an enrolled host +.RI ( "\-\-login is for registered devices" ; +hosts are reached as the user), and only for a device with a pinned host key +.RI ( "has no pinned host key, and a local password goes only to a device whose key was verified" ; +the key is checked strictly against the pin, as for a plain session), for the +engineer tier and up +.RI ( "'tacctl device ssh \-\-login' is not permitted for the tier tier" ), +and for a device in one of the caller's scopes, as for every ssh. A refusal of the +entry is logged +.RB ( "ssh DENY ... reason=login\-host" " or " "reason=login\-unpinned" ). +The device asks for the account's password at its own prompt: tacctl never +asks for it, caches it or stores it, it is the engineer's, and the password +cache is neither asked, filled nor told to forget for the line (the shell +leaves it shut). The two log lines end with +.BI login= local\-user +(before +.BR console= ), +and have no +.B password= +field. The warning for a held device then says the local account is what is +used. .\" BEGIN GENERATED: command ssh .RS .PP @@ -14821,6 +14859,9 @@ Options: \fB\-p\fR \fI\fR Connect to this port (default: the device's port, else 22). .TP +\fB\-\-login\fR \fI\fR +Log in as this local account of the device (a break\-glass one, or any other) instead of as you; the account's password is asked by the device itself, never by tacctl, and is not cached or stored. For registered devices of any vendor with a pinned host key, not enrolled hosts; the engineer tier and up, for a device in one of your scopes. +.TP \fB\-X\fR Forward X11 to this server's display (untrusted, as ssh \-X). .TP @@ -14916,7 +14957,9 @@ has a .B Break\-glass section, and .B "tacctl ssh" -warns and connects. +warns and connects +.RB ( "tacctl ssh " device " \-\-login " account +logs in as one of its local accounts). .PP The record is .B breakglass_hold..address|since|by|reason From 00590de4c53316ca40c302f6e709985a1c9986ca Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:42:52 -0900 Subject: [PATCH 38/52] docs: tacctl ssh --login, in the pages and the CHANGELOG Describes the --login flag of 'tacctl ssh' and 'device ssh' (previous commit): docs/cli/device.md (the entry), docs/cli/shell.md and docs/cli/console.md (a --login line leaves the password cache shut), docs/cli/conventions.md (the usage list), docs/devices/connecting.md, docs/devices/walkthroughs.md (the log lines end with login=, the DENY reasons) and docs/devices/break-glass.md (the way in while a hold stands). Says that the password is asked by the device and is never cached or stored by tacctl, and that it is the engineer's. CHANGELOG item 1 under 0.2.29 (unreleased). --- CHANGELOG.md | 33 +++++++++++++++++++++++++++++++++ docs/cli/console.md | 3 ++- docs/cli/conventions.md | 6 ++++-- docs/cli/device.md | 15 +++++++++++++-- docs/cli/shell.md | 2 +- docs/devices/break-glass.md | 2 +- docs/devices/connecting.md | 2 ++ docs/devices/walkthroughs.md | 2 +- 8 files changed, 57 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 353fc633..9971906d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,39 @@ All notable changes to tacctl. The README and the manual page describe only the current behaviour; this file is where history lives. +## 0.2.29 (unreleased) + +1. **`tacctl ssh --login ` logs in as one of the device's + own accounts.** In the tacctl console the words after `--` are the remote + command and ssh's `-l admin` is refused, and while break-glass is held on a + device only its local accounts work, so a person had no way to open a + session as `admin` from the console. `tacctl ssh --login + [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ]` + (and `tacctl device ssh`, the same command) now runs ssh as you, as + before, with `-l ` in place of your name. It is for + registered devices of any vendor; an enrolled host is refused in one + sentence (hosts are reached as you) and nothing is started. The device must + have a pinned host key: without one the line is refused and names + `tacctl device hostkey accept`, because a local password goes only + to a device whose key was verified; with one, ssh checks the key strictly + against the pin, exactly as for a plain session. It needs the engineer tier + or above, as the other `--login` verbs do (a lower tier gets + `'tacctl device ssh --login' is not permitted for the tier.`), and + the device must be in one of your scopes, as for every ssh. The name is + letters, digits, `.`, `_` and `-`. The device asks for the account's + password at its own prompt: tacctl never asks for it, caches it or stores + it, and the password cache of the shell and the console is not used for the + line (it is not asked, filled or told to forget, not even when ssh ends with + status 255, and the shell gives the line no token). The session's + `ssh user= device= addr=` and `ssh end` lines end with `login=` + (and have no `password=` field); a plain session's lines are unchanged. The + warning for a device with break-glass held says `you log in as its local + account ''` and the session goes on. Help (`tacctl ssh -h`, + `help device`), the completion (a `--login` flag with no candidates, as for + the other `--login` verbs), the manual page, `docs/cli/device.md`, + `docs/cli/shell.md`, `docs/devices/connecting.md`, + `docs/devices/walkthroughs.md` and `docs/devices/break-glass.md` describe it. + ## 0.2.28 (2026-11-09) 1. **A support bundle from a Cisco IOS device no longer starts the identity diff --git a/docs/cli/console.md b/docs/cli/console.md index 43b1a220..f559a334 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -105,7 +105,8 @@ console password-cache [on|off] before they connect, and keep it; the logins tacctl makes itself (device config pull, diff --pull, plan --pull, block ... adopt, device config apply, device onboard, device collect, device enroll) keep the password a device accepted, and every one of these lines - uses a cached password (details: shell.md, Password cache) + uses a cached password, except a line with --login (a local account's password never + comes from or goes into the cache; details: shell.md, Password cache) console password-cache tiers [|none] diff --git a/docs/cli/conventions.md b/docs/cli/conventions.md index 55d53761..d0e71af2 100644 --- a/docs/cli/conventions.md +++ b/docs/cli/conventions.md @@ -87,9 +87,11 @@ tacctl server This server's settings (show, name, addresses, listen, metrics); see server.md -tacctl ssh [-p port] [-X|-Y] [-g] [-L|-R|-D spec]... [-- ssh args] +tacctl ssh [--login local-user] [-p port] [-X|-Y] [-g] + [-L|-R|-D spec]... [-- ssh args] - ssh session to a registered device or enrolled host, as you, by password (never root) + ssh session to a registered device or enrolled host, as you, by password (never root), + or as a local account of a device with --login tacctl console diff --git a/docs/cli/device.md b/docs/cli/device.md index e6ddcd36..ca4c2dce 100644 --- a/docs/cli/device.md +++ b/docs/cli/device.md @@ -384,9 +384,20 @@ device hostkey set SHA256: time to greet) and the same two ways to accept a key. Nothing is written; `--no-host-key` registers the device unpinned. -device ssh [-p ] [-X|-Y] [-g] [-L|-R|-D ]... [-- ] +device ssh [--login ] [-p ] [-X|-Y] [-g] + [-L|-R|-D ]... [-- ] Same as tacctl ssh + --login + Log in as this local account of the device instead of as you (a break-glass account, or any + other): ssh runs with `-l `. Registered devices only, of any vendor (an enrolled + host is refused: hosts are reached as you), and only a device with a pinned host key (the + key is checked strictly against the pin, as for a plain session); the engineer tier and + up, for a device in one of your scopes. The device asks for the account's password + itself: tacctl never asks for it, caches it or stores it, and the password cache is not + used for the line. The session's log lines end with `login=` (no password + field). A hold on the device only warns: it is what the account is for. The words after + `--` stay the remote command in the console. device client-config @@ -824,7 +835,7 @@ export. A name that exists with upper case keeps working, is found in any case, and is listed by `tacctl config validate` with the `device rename` that fixes it. -A device is found by name (any case) or by its registered address; an unregistered address is not found, even when a scope covers it. An address is registered once. A device name is letters, digits, `.`, `_` and `-`, starting with a letter or digit, at most 253 characters with each dotted part at most 63, so a fully qualified host name (`sw1.site-a.example`) is one. An enrolled host's name is the same, starting with a letter; `host enroll` borrows the short name from the target (`alice@sw1.example.net` is `sw1`), and a fully qualified name is given with `--name` or `host rename`. Enrolled Linux hosts share the namespace and `show` (and the other verbs that take a device, which do not change a host) takes one by name, as a `linux` entry, read-only; `list` shows devices only, and `host list` the hosts. `list`, `show`, `notice list`, `client-config` and `tacctl ssh` are open to the read-only and operator tiers, limited to the entries of their own scopes (`tacctl ssh` is limited so for every tier); `export` is operator-level, filtered the same way. `device reports` is open to every tier for its own reports (made from stored data and limited to the user's own scopes); `generate --pull` is the engineer's, and another user's reports (`--user`, `--all-users`, `/`) the superuser's (see [Device reports](../devices/reports.md)). +A device is found by name (any case) or by its registered address; an unregistered address is not found, even when a scope covers it. An address is registered once. A device name is letters, digits, `.`, `_` and `-`, starting with a letter or digit, at most 253 characters with each dotted part at most 63, so a fully qualified host name (`sw1.site-a.example`) is one. An enrolled host's name is the same, starting with a letter; `host enroll` borrows the short name from the target (`alice@sw1.example.net` is `sw1`), and a fully qualified name is given with `--name` or `host rename`. Enrolled Linux hosts share the namespace and `show` (and the other verbs that take a device, which do not change a host) takes one by name, as a `linux` entry, read-only; `list` shows devices only, and `host list` the hosts. `list`, `show`, `notice list`, `client-config` and `tacctl ssh` are open to the read-only and operator tiers, limited to the entries of their own scopes (`tacctl ssh` is limited so for every tier; its `--login` is the engineer's); `export` is operator-level, filtered the same way. `device reports` is open to every tier for its own reports (made from stored data and limited to the user's own scopes); `generate --pull` is the engineer's, and another user's reports (`--user`, `--all-users`, `/`) the superuser's (see [Device reports](../devices/reports.md)). A name that is a factory or image default is refused with the command that names the device on the device itself (`hostname`, `set system host-name`, ...); a host already enrolled under such a name is not refused and carries a `generic-name` notice. `host enroll --name` follows the same rules. Add your own patterns with `generic_names:` (regular expressions, whole-name, case-insensitive) in `devices.yaml`. diff --git a/docs/cli/shell.md b/docs/cli/shell.md index 1a805496..2f8693f3 100644 --- a/docs/cli/shell.md +++ b/docs/cli/shell.md @@ -104,6 +104,6 @@ console forget `console password-cache tiers` is the **permission**: it names the tiers that may use the cache, and nothing changes for a tier that is not listed. For a tier that is listed the cache is not automatic: it is on in a session when your tier is allowed **and you have turned it on for yourself**, which is off until you do. Type `console password-cache on` at the prompt of the console (or of `tacctl shell`): it saves your choice for every later session and starts the cache in the running one at once (the first device login that asks for your password keeps it: the logins `tacctl` makes itself store the password after a device accepts it, and `ssh` and `device ssh` ask for it themselves the first time, before they connect, see below). `console password-cache off` saves that, forgets a cached password at once (`password forgotten (console password-cache off)`) and stops caching. With no argument the word prints the permission and limits (`tiers`, `idle`, `max`, `your tier (operator): allowed`, `your setting: on|off`) and whether a password is cached in this session now. When your tier is not allowed, `on` is refused in one sentence naming the fix (a superuser runs `console password-cache tiers ...`) and saves nothing. Each user sets only their own choice (the word takes no name, and the root side takes the user from the one `sudo` was run by); a superuser sees who turned it on with `console password-cache user` and switches a user's choice off with `console password-cache user clear` (a session the user has open keeps its cache until it ends or they turn it off). A user who is renamed keeps the choice, and a removed user's is dropped. A plain `tacctl shell --password-cache` is an explicit request and stays as it was: it needs only the tier's permission (a caller outside `tac-users` asks for it themselves). It is for the interactive session only: `-c` and batch lines keep no process to hold it, and the plain CLI from bash asks per run. -How it works: the shell process itself holds the password, in a page it locked in memory (`mlock`; when memory cannot be locked, a debugger is attached, or no private directory is available for the socket, there is no cache and one line says `password cache unavailable: `: `cannot lock memory`, `this process is being traced` or `no private directory for its socket`), in a process marked not dumpable, zeroed when it is forgotten. It is never written to a file, a log, an argument or the environment. The shell listens on a socket in a private directory (`$XDG_RUNTIME_DIR/tacctl`, else `/run/user//tacctl`, else `~/.local/state/tacctl/run`, mode 0700) and is shut between lines. For a line that runs `device config pull`, `device config diff --pull`, `device config plan --pull`, `ssh`, `device ssh`, `block ... adopt`, `device config apply`, `device onboard` (for your own password after its review), `device collect` or `device enroll`, and for no other line (a `diff` without `--pull` logs in to nothing, and a line with `--login ` logs in as a device's local account, whose password never comes from or goes into the cache, so their lines leave it shut), it mints a token and puts `TACCTL_ASKPASS=:` in the environment of that line's `sudo` process, never on sudo's command line; the tiers drop-ins keep that one variable for those command lines only. The token exists only for that line: the agent answers only while the line runs, only to your own user or root (`SO_PEERCRED`), only with that token, and gives the password once; after that single `get` the token is good for nothing but `forget`, and when the line ends it is dead (a value read from an earlier line is refused). A second ask on the same line is a refusal and forgets the password. What remains is the usual one for a secret handed through an environment: a process of your own user that reads the pull's or ssh's environment during the line, and gets to the socket before the single `get` of that line, is answered as the line would be. Which lines use and which store: every line named above uses a cached password. The logins `tacctl` makes itself (`device config pull`, `diff --pull`, `plan --pull`, `block ... adopt`, `device config apply`, `device onboard`, `device collect` and `device enroll`) ask the cache, and when nothing is cached they prompt on the terminal; after the first device **accepts** a password they prompted for it is stored (a password that came from the cache is never stored again, so the maximum lifetime cannot be extended by use). A device that refuses the password makes the cache forget it at once and the run stops starting new devices. `ssh` and `device ssh` ask for your password themselves the first time, before they connect, and keep it: with the cache on and empty, for a device with pinned host keys and no option of ssh's own after `--`, they prompt `Password for (device login):` on the terminal (no echo; Ctrl-C ends the line with status 130 and starts nothing, an empty answer stores nothing), store the answer in the cache and then connect by the path below, so the password is typed once, before the device banner, and the next `ssh` to any device asks nothing. Their audit line ends `password=asked` for the line that prompted and `password=cached` for the lines that used the cache. The password is stored before the device has seen it, so a wrong one stays only until the first ssh that ends with status 255 (an authentication or connection failure), which forgets it: a typo costs one more typing, as with ssh itself. Only the password `ssh` asked for itself is stored, never a word a device asks for later, so a device cannot make the session keep anything. Without a terminal to prompt on, for a device with no pinned host key, with an option of ssh's own after `--`, or when the account is not in the local account database, ssh asks for the password itself, as it always did, and nothing is cached. `tacctl ssh` uses a cached password only for a device with pinned host keys: ssh is then started as you directly, without sudo (your uid, gid and groups; an explicit environment of `HOME`, `USER`, `LOGNAME`, `PATH`, the terminal and locale, and the display), so the token is never a `sudo` variable or argument and reaches no log. It asks the shell's agent for the password through `SSH_ASKPASS` (this binary, which answers a password prompt and nothing else), `SSH_ASKPASS_REQUIRE=force`, one prompt (`NumberOfPasswordPrompts=1`), no configuration file and `StrictHostKeyChecking=yes` against the pinned keys; an ssh that ends with status 255 forgets the password. An account that is not in the local account database keeps the prompt. +How it works: the shell process itself holds the password, in a page it locked in memory (`mlock`; when memory cannot be locked, a debugger is attached, or no private directory is available for the socket, there is no cache and one line says `password cache unavailable: `: `cannot lock memory`, `this process is being traced` or `no private directory for its socket`), in a process marked not dumpable, zeroed when it is forgotten. It is never written to a file, a log, an argument or the environment. The shell listens on a socket in a private directory (`$XDG_RUNTIME_DIR/tacctl`, else `/run/user//tacctl`, else `~/.local/state/tacctl/run`, mode 0700) and is shut between lines. For a line that runs `device config pull`, `device config diff --pull`, `device config plan --pull`, `ssh`, `device ssh`, `block ... adopt`, `device config apply`, `device onboard` (for your own password after its review), `device collect` or `device enroll`, and for no other line (a `diff` without `--pull` logs in to nothing, and a line with `--login `, `ssh` and `device ssh` included, logs in as a device's local account, whose password never comes from or goes into the cache, so their lines leave it shut), it mints a token and puts `TACCTL_ASKPASS=:` in the environment of that line's `sudo` process, never on sudo's command line; the tiers drop-ins keep that one variable for those command lines only. The token exists only for that line: the agent answers only while the line runs, only to your own user or root (`SO_PEERCRED`), only with that token, and gives the password once; after that single `get` the token is good for nothing but `forget`, and when the line ends it is dead (a value read from an earlier line is refused). A second ask on the same line is a refusal and forgets the password. What remains is the usual one for a secret handed through an environment: a process of your own user that reads the pull's or ssh's environment during the line, and gets to the socket before the single `get` of that line, is answered as the line would be. Which lines use and which store: every line named above uses a cached password. The logins `tacctl` makes itself (`device config pull`, `diff --pull`, `plan --pull`, `block ... adopt`, `device config apply`, `device onboard`, `device collect` and `device enroll`) ask the cache, and when nothing is cached they prompt on the terminal; after the first device **accepts** a password they prompted for it is stored (a password that came from the cache is never stored again, so the maximum lifetime cannot be extended by use). A device that refuses the password makes the cache forget it at once and the run stops starting new devices. `ssh` and `device ssh` ask for your password themselves the first time, before they connect, and keep it: with the cache on and empty, for a device with pinned host keys and no option of ssh's own after `--`, they prompt `Password for (device login):` on the terminal (no echo; Ctrl-C ends the line with status 130 and starts nothing, an empty answer stores nothing), store the answer in the cache and then connect by the path below, so the password is typed once, before the device banner, and the next `ssh` to any device asks nothing. Their audit line ends `password=asked` for the line that prompted and `password=cached` for the lines that used the cache. The password is stored before the device has seen it, so a wrong one stays only until the first ssh that ends with status 255 (an authentication or connection failure), which forgets it: a typo costs one more typing, as with ssh itself. Only the password `ssh` asked for itself is stored, never a word a device asks for later, so a device cannot make the session keep anything. Without a terminal to prompt on, for a device with no pinned host key, with an option of ssh's own after `--`, or when the account is not in the local account database, ssh asks for the password itself, as it always did, and nothing is cached. `tacctl ssh` uses a cached password only for a device with pinned host keys: ssh is then started as you directly, without sudo (your uid, gid and groups; an explicit environment of `HOME`, `USER`, `LOGNAME`, `PATH`, the terminal and locale, and the display), so the token is never a `sudo` variable or argument and reaches no log. It asks the shell's agent for the password through `SSH_ASKPASS` (this binary, which answers a password prompt and nothing else), `SSH_ASKPASS_REQUIRE=force`, one prompt (`NumberOfPasswordPrompts=1`), no configuration file and `StrictHostKeyChecking=yes` against the pinned keys; an ssh that ends with status 255 forgets the password. An account that is not in the local account database keeps the prompt. `ssh --login ` is outside all of this: the line gets no token, the cache is not asked, filled or told to forget (not even by a status of 255), and the device asks for the local account's password itself. It is forgotten when the session ends, after the idle time, after the maximum lifetime, when you change your password (`passwd`, `user passwd`), when a device refuses it, when the clock goes backwards, and by `console forget`; the shell says `password cached for this session (console password-cache)` when it keeps one and `password forgotten ()` when it lets go. The cache protects the password against other users and against its landing in files, logs, arguments or the environment; root can read any process, and hibernation can write the locked page to disk. diff --git a/docs/devices/break-glass.md b/docs/devices/break-glass.md index 6ad78687..2c4c2e63 100644 --- a/docs/devices/break-glass.md +++ b/docs/devices/break-glass.md @@ -100,7 +100,7 @@ The local accounts of [Break-glass local users](#break-glass-local-users) (`root rendered files name a held host in their comment block as `(host )` and a held device as `(device )`. - **The way in, by vendor.** *Cisco IOS:* ssh as a local account (the device waits for the server a few seconds, then takes the local password; the account lands at the level of its `username ... privilege` line); on the console, log in as the local account (the `CONSOLE` list is local), then `enable` with the local enable secret (that works with the server up, held or not). Logins by your TACACS+ name fail on that device until you release it. *Junos:* ssh or console as a local user (`system login user`), or as `root` when the scope records it ([Junos root](#junos-root): ssh needs `root-login allow`); the switch waits out its tacplus-server timeout, then checks the local password (`authentication-order [ tacplus password ]`); root on the console is local always. *WTI:* the unit takes its local accounts only if its TACACS+ Fallback Local is `On (Transport Failure)` or `On (All Failures)` (the walkthrough sets it from the scope's `aaa-order`); with `Off`, nobody logs in until you release it. Nothing a held device does is accounted here: its accounting goes to a server that does not answer it, and what the technician typed is in the device's own log only. -- **While it stands.** There is no timer and no automatic release: a hold ends only with `tacctl breakglass release `, and is shown until then: `breakglass list`, `status` (a red line per hold), `device show` (`Break-glass: HELD since ... by ...: ; the server does not answer
`), `device list` (`BREAK-GLASS` in the STATE column and a footer), `device check` (the Scope row and `breakglass` in `--json`), `device scan` (a refusal of the address reads `(break-glass held)`), `scope routing|show|list|lookup` and `config validate` (a warning per hold). `device remove` of a held device is refused (`break-glass is held on : release it first`); `device address` moves the hold with the device (see below), and `device rename` (for a host, `host rename`) moves the record with it. `device config pull|diff|plan --pull` of a held device is refused up front, and a batch skips it with that line, because the device does not authenticate your login; `device config plan` of the last pull works and says `BREAK-GLASS HELD on this device` before its items, and the cover page marks the device. `tacctl ssh` of a held device or host warns and connects. `backup restore` is a render like any other: a hold comes back with a snapshot of a `tacctl.yaml` that has it and goes with one that lacks it, and the restore names the devices held now and after it when that set changes. +- **While it stands.** There is no timer and no automatic release: a hold ends only with `tacctl breakglass release `, and is shown until then: `breakglass list`, `status` (a red line per hold), `device show` (`Break-glass: HELD since ... by ...: ; the server does not answer
`), `device list` (`BREAK-GLASS` in the STATE column and a footer), `device check` (the Scope row and `breakglass` in `--json`), `device scan` (a refusal of the address reads `(break-glass held)`), `scope routing|show|list|lookup` and `config validate` (a warning per hold). `device remove` of a held device is refused (`break-glass is held on : release it first`); `device address` moves the hold with the device (see below), and `device rename` (for a host, `host rename`) moves the record with it. `device config pull|diff|plan --pull` of a held device is refused up front, and a batch skips it with that line, because the device does not authenticate your login; `device config plan` of the last pull works and says `BREAK-GLASS HELD on this device` before its items, and the cover page marks the device. `tacctl ssh` of a held device or host warns and connects; `tacctl ssh --login ` (engineers and up, a device with a pinned host key) logs in as one of the device's local accounts, the way in while the hold stands, and the device asks for that account's password itself (tacctl never asks for it or keeps it). `backup restore` is a render like any other: a hold comes back with a snapshot of a `tacctl.yaml` that has it and goes with one that lacks it, and the restore names the devices held now and after it when that set changes. - **A record that holds no device.** A record holds a device only while the device is registered at the record's address (a host: while a host of the name is enrolled and its recorded address is the record's). When the device was removed from `devices.yaml` by hand, or another was registered under the name at another address, the record is an *orphan*: `breakglass list` shows ` (orphan)` and says why (`--json` has `"orphan": true`), `status` and `config validate` name it, the address it carved stays carved, the device is not shown as held and none of the held-device refusals applies to it, and `breakglass hold ` is refused until `tacctl breakglass release ` removes the record. A hand-written key with a dot in it (`breakglass_hold: {sw.lab: ...}`) is read and released like any other; `config validate` names it, and names an entry with no address, an address that is not one IPv4 or IPv6 address, or that is not a record: those carve nothing, and `release ` removes them. - **When the device moves.** `tacctl device address
[--yes]` on a held device moves the hold to the new address (superuser; an engineer is refused; releasing first would answer the old address again). The new address passes the checks of a new hold: not a loopback address, not an address a listener of either backend binds, not the address of an enrolled host, not held by another record, covered by a scope. One line names both addresses and asks to confirm (`Confirm moving the hold from to ? [y/N]`; `--yes` skips it); the registry and the record are written together, rendered once and each backend whose file changed is restarted once. The report names the hold's original reason and time, the rendered carve, that the old address is answered again and what the firewall table did (`Firewall: refused on tcp/49 (reject); accepted again`). A refused address changes nothing (`Nothing was changed.`). A restart that fails is reported as `NOT restarted` and the command exits 1, with the registry and the record on the new address. `--apply` is refused for a held device (it does not authenticate your login). `auth.info` line: `breakglass hold-move device= from= to= by= firewall=`. - **When a restart fails.** The report says `tacacs NOT restarted: the running server still answers
until it is restarted (run: sudo systemctl restart tacquito)` (for a release, `still does not answer`), the command exits 1, and nothing is undone: the record and the rendered files stay, and are what the next restart serves. Two superusers who hold one device at the same moment cannot both succeed: the second is refused as already held and the first record is left as it was. diff --git a/docs/devices/connecting.md b/docs/devices/connecting.md index e4c9cc0a..4997dd25 100644 --- a/docs/devices/connecting.md +++ b/docs/devices/connecting.md @@ -15,6 +15,7 @@ tacctl device config show core-sw1 # the device's data, then the walkthrough fo # scope tacctl ssh core-sw1 # a session, as you tacctl ssh core-sw1 -- show version # one remote command +tacctl ssh core-sw1 --login admin # as the device's local account admin ``` 1. **Register.** A device whose address a scope's prefixes cover is `configured` in that scope (`tacctl device list`); one that no scope covers registers as `unconfigured`, and no one may connect to it. `--legacy-ssh` is for a device that offers only SHA-1 key exchange, CBC ciphers and `ssh-rsa`, and is the ssh algorithms and nothing else (the configuration syntax is `--ios-syntax`); `--vendor wti` selects the password-only method order. `device add` pins the host keys the device offers: **compare the printed fingerprints with the device's console** (Cisco `show ip ssh`, Junos `file show /etc/ssh/ssh_host_ed25519_key.pub` from the CLI, or `ssh-keygen -lf` on the same file from `start shell`, Linux `ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub`). Names that are factory defaults (`switch`, `router`) are refused; name the device on the device too. Devices that already authenticate but are not registered are listed by `tacctl device discover`, each with a ready `device add` line; `tacctl device collect --discovered` logs in to them once and shows what each is, and `--register` registers them (see [Collecting from addresses nobody registered](planning.md#collecting-from-addresses-nobody-registered)). See [Host keys of devices and hosts (pinning)](../security/host-key-pinning.md#host-key-pinning). @@ -23,6 +24,7 @@ tacctl ssh core-sw1 -- show version # one remote command **The device's own name.** With SNMP set up (`tacctl config snmp`), `device add` also reads the device's `sysName.0` (and its `sysLocation.0`, which it stores as the device's location) and says what the device calls itself; a name that is not the one given (or its `--hostname`, or the first label of either) is a warning with the fixes, and the add goes ahead. `tacctl device add
` with no name offers the sysName, lowercased, at a terminal. See [The SNMP name hint](snmp-name-hint.md#the-snmp-name-hint). 2. **Who may connect.** An active tacctl user (in the store, not disabled) whose scopes include the device's scope, at every tier, superusers included. A local account that is not a tacctl user, a disabled user and a device in no configured scope are refused, and each refusal is logged to syslog (`ssh DENY`). A read-only or operator user (a member of `tac-users` with the [tiers file](../security/tiers.md#tiered-access) installed) may run `tacctl ssh` and sees only the devices of its own scopes. 3. **How it logs in.** ssh runs as you, never as root, and logs in with your own username and your tacctl password (which the device checks against this server): no agent, no key, no other login. Run it from your own account; as root it refuses. It needs a terminal. + **As a local account of the device.** `--login ` logs in as one of the device's own accounts instead of as you (`ssh -l `): the way in to a device whose break-glass is [held](break-glass.md), which takes local accounts only, and the way to log in as another account in the console, where the words after `--` are the remote command and ssh's own `-l` is refused. It is for registered devices of any vendor (an enrolled host is refused, since hosts are reached as you) with a pinned host key (without one it is refused with the `device hostkey` command that pins it: a local password goes only to a device whose key was verified), for engineers and up, and only for a device in one of your scopes, as for every ssh. The device asks for the account's password at its own prompt: tacctl never asks for it, caches it or stores it, it is the engineer's, and the [password cache](../cli/shell.md#password-cache) is not used for the line. The session's log lines end with `login=`. 4. **Plain `ssh`.** `tacctl device client-config > ~/.ssh/tacctl.conf` and `Include ~/.ssh/tacctl.conf` at the top of `~/.ssh/config` give a plain `ssh core-sw1` (and `scp`) the same options and the same pin. The fragment has one `Host` block per device you may see and no `User` line, so ssh logs in with your local username: a tacctl user whose local account has another name adds `User ` to its own `~/.ssh/config`. Re-run it after the registry changes. 5. **A key that changed.** When a device was replaced or reset, ssh is refused and tacctl prints the pinned and offered fingerprints and the console command that shows the key. After verifying on the console, an administrator re-pins with `tacctl device hostkey core-sw1 accept` (or `set SHA256:`). diff --git a/docs/devices/walkthroughs.md b/docs/devices/walkthroughs.md index b66ba6bc..7b41d48e 100644 --- a/docs/devices/walkthroughs.md +++ b/docs/devices/walkthroughs.md @@ -31,7 +31,7 @@ | pinned keys | `-o UserKnownHostsFile=/var/lib/tacctl/ssh/known_hosts -o GlobalKnownHostsFile=none -o StrictHostKeyChecking=yes -o HostKeyAlias= -o UpdateHostKeys=no` | | enrolled host | its target's host and its port | -An unpinned device is checked against your own known_hosts, after its `hostkey-unpinned` notice. Arguments after `--` follow the target, so ssh takes them as the remote command (`tacctl ssh core-sw1 -- show version`); they cannot replace an option. Each session is logged when it starts (`ssh user= device= addr=`) and when it ends (`ssh end user= device= status= duration=`). +An unpinned device is checked against your own known_hosts, after its `hostkey-unpinned` notice. Arguments after `--` follow the target, so ssh takes them as the remote command (`tacctl ssh core-sw1 -- show version`); they cannot replace an option. Each session is logged when it starts (`ssh user= device= addr=`) and when it ends (`ssh end user= device= status= duration=`). With `--login ` ssh logs in as that local account of the device (`-l `, the password asked by the device, never by tacctl and never cached) and both lines end with `login=` (before `console=`); a registered device with a pinned host key, the engineer tier and up (see [Connecting to devices by name](connecting.md)); a refusal of the entry is logged as `ssh DENY … reason=login-host` or `reason=login-unpinned`. From a login console session (each of its lines carries `TACCTL_CONSOLE=`), `tacctl ssh` reads no ssh configuration file and opens nothing but the session: it adds `-F /dev/null -o PermitLocalCommand=no -o ControlMaster=no -o ClearAllForwardings=yes -o ForwardAgent=no`, `-o EscapeChar=none` unless `tacctl console ssh-escape enable`, and puts the target after `--`, so the words after the name's `--` are only ever the remote command (a first word starting with `-` is refused). A device or host with no pinned host key is refused: `'' has no pinned host key, so the console does not connect to it; an administrator pins it: tacctl device hostkey accept`. Its log lines end with `console=`. When ssh fails with 255 on a pinned device whose key changed, tacctl prints the pinned and offered fingerprints, the console command that shows the key, and `tacctl device hostkey accept|set`. From e31c62a5f1f7bdee9e1751dac95ef2a5e282c4bd Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:52:58 -0900 Subject: [PATCH 39/52] sftpd: a new file asked at a read-only mode is made writable until the close A file uploaded with a mode that lacks the owner's write bit (0444 or 0555 from a read-only source, 0400 or 0500 after the umask of the console) was created with that mode, and the size step that the OpenSSH scp ends an upload with (an fsetstat of the size, which the library turns into a setstat of the path, a truncate by path) failed with permission denied: truncate(2) needs write permission, and the owner had none. openFile now creates such a file with the owner's write bit added, reads the mode the kernel made from the descriptor (so the umask that applied is the one that applied, without calling umask(2), which is process-wide), and sets that mode without the owner's write bit on the descriptor when the handle closes, before it is closed. The result is what open(2) would have made: 0444 under 077 is 0400. An existing file is never touched: the create is tried with O_EXCL first (the client's O_EXCL alone when it asked for it) and an existing file is opened again without O_CREAT, so that the kernel's answer says whether this open made the file. A setstat that sets the permissions of the file takes it off the list of files waiting for their mode, so what the client sets between the data and the close stays. A session that ends with the handle open closes it through the library, which restores the mode too; only a process that is killed leaves the file owner-writable, and it is the owner's own file. The test fails without the change (the size step answers status 3). The console page, the manual page and item 1 of 0.2.29 say it. --- CHANGELOG.md | 8 +- docs/cli/console.md | 2 +- internal/sftpd/file.go | 118 ++++++++++++++- internal/sftpd/handlers.go | 2 + internal/sftpd/openmode_test.go | 260 +++++++++++++++++++++++++++++++- man/tacctl.1 | 9 +- 6 files changed, 386 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f52c3a7..76b6bcb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,13 @@ current behaviour; this file is where history lives. The owner's bits survive and the group and other bits go: a script asked at 0755 is 0700, a file asked at 0644 is 0600. A request without permissions still gives 0644, 0600 after the umask. A file that already - exists keeps its mode, and a download changes nothing. A request that + exists keeps its mode, and a download changes nothing. A file asked at a + mode without the owner's write bit (0444, or 0555, which `scp` sends for a + read-only source) is created writable by its owner and gets the mode asked + for, reduced by the umask, when the client closes the handle: `scp` ends an + upload by setting the size of the file, which the kernel refuses on a file + its owner cannot write, so the mode comes last. A client that sets the + permissions itself before it closes the handle keeps what it set. A request that carries other attributes together with the permissions (for example the times, as with the preserve option of `scp`) is read as carrying none, because the library does not tell which attributes a request holds; such diff --git a/docs/cli/console.md b/docs/cli/console.md index 74ce667f..3c86f2c7 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -220,7 +220,7 @@ Every form of `console file-transfer` is the superuser's, the reads included (`c **What a user can do.** `sftp alice@tacacs.example.net` and the `scp` of OpenSSH 9 or later (which speaks SFTP unless it is given `-O`) work for an account that has file transfer. `scp -O` (the old protocol), `rsync`, any program and the shell's words are refused, as before, with `the tacctl console does not run programs or shell commands; file transfer is SFTP only (sftp, scp of OpenSSH 9 or later)` (exit 126). For an account that does not have file transfer the subsystem is refused with `file transfer is not enabled for this account; an administrator can switch it on (tacctl console file-transfer)` (exit 126), and so is the subsystem of a user held to a required password change. The console serves the protocol as the logged-in user, with no change of privilege, so the file system's permissions apply as they do in the user's shell. An account that does not have file transfer sees only `Connection closed` from `sftp` and `scp` (sshd does not show the error text of a subsystem; `ssh id`, a command request, does): the reason, `reason=file-transfer` with status 126, is in the console's audit log, and `console show` lists who has file transfer. -**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode the client asks for. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none); a file that already exists keeps its mode, whatever the open asks. Both are reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is 0700. The set-user-ID, set-group-ID and sticky bits are ignored, and a client that wants another mode sets it afterwards, which is applied as given. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. +**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode the client asks for. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle open closes it. Both are reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is 0700. The set-user-ID, set-group-ID and sticky bits are ignored, and a client that wants another mode sets it afterwards, which is applied as given. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. **The quota and the rate.** The quota is the bytes the home may hold. It counts the sizes of the regular files in it, each inode once (a file with two names counts once): the reports and support bundles tacctl wrote there, `.ssh` and the files the user uploads. Directories, links and inodes do not count, and a sparse file counts its length. A write that would take the home over it is refused whole (`disk quota exceeded`) and audited, and so is a size that would grow a file over it; a smaller size gives the room back. An upload that is refused part way leaves what was written before the refusal in the home (the client does not remove it), and the `sftp` and `scp` of OpenSSH show only `Failure` for it: the reason, `reason=quota`, is in the console's audit log. A file that was deleted while a handle of the session still holds it stays counted until the handle is closed. The home is measured when the session starts and again, when a file is opened for writing, if the last measure is a few seconds old, so the quota is per session: N sessions of one user at once can each use the room that was free when they measured, and bring the home to about N times the quota. A directory in the home that the session cannot read or search (for example one owned by root with mode 0700) makes the home count as full: every upload that grows the home is refused with `disk quota exceeded` until the directory is readable, while reading, deleting and writes that do not grow the home go on. The rate is the bytes a second one session may move, reads and writes together, with a burst of one second; a transfer at its rate waits, it is not refused. Both are read when the session starts. diff --git a/internal/sftpd/file.go b/internal/sftpd/file.go index 649e1841..1050e1d6 100644 --- a/internal/sftpd/file.go +++ b/internal/sftpd/file.go @@ -2,6 +2,7 @@ package sftpd import ( "encoding/binary" + "errors" "os" "sync" "sync/atomic" @@ -30,18 +31,62 @@ type file struct { read, written atomic.Int64 + // restore, with restoring, is the mode the file gets when the handle + // closes: the open created it, for a mode without the owner's write bit, + // owner-writable (see openNew). Set before the handle is handed out, and + // not changed. + restore uint32 + restoring bool + mu sync.Mutex xferr error // the error that ended the session with the handle open closed sync.Once } +// freshModes is the files of the session that the open created owner-writable +// and that wait for their mode to be set when the handle closes. A setstat of +// the permissions of such a file takes it out: the client has said what it +// wants, and that is not undone at the close. +type freshModes struct { + mu sync.Mutex + m map[inode]*file +} + +func (b *freshModes) add(f *file) { + b.mu.Lock() + defer b.mu.Unlock() + if b.m == nil { + b.m = map[inode]*file{} + } + b.m[f.key] = f +} + +// take reports whether f is still waiting, and stops it from waiting. +func (b *freshModes) take(f *file) bool { + b.mu.Lock() + defer b.mu.Unlock() + if b.m[f.key] != f { + return false + } + delete(b.m, f.key) + return true +} + +// forget drops the file on disk k: its permissions were set by the client. +func (b *freshModes) forget(k inode) { + b.mu.Lock() + defer b.mu.Unlock() + delete(b.m, k) +} + // defaultFileMode is the mode of a new file when the client's open request // does not carry one (the umask of the console still applies). const defaultFileMode = 0o644 // permBits is the part of a mode a client may set: the permission bits. The // set-user-ID, set-group-ID and sticky bits, and any file type bits, are -// dropped. Mkdir, setstat and open all take their mode through it. +// dropped. Setstat and open take their mode through it (a mkdir takes none: +// see mkdir). func permBits(m uint32) uint32 { return m & 0o777 } // openMode is the mode the client asks for in the open request r, and whether @@ -93,6 +138,7 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { } flags := unix.O_NONBLOCK mode := uint32(defaultFileMode) + readOnlyNew := false // a create for a mode without the owner's write bit if write { flags |= unix.O_WRONLY if pf.Read { @@ -102,6 +148,7 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { flags |= unix.O_CREAT if m, ok := openMode(r); ok { mode = m // only a file the open creates gets it; an existing one keeps its mode + readOnlyNew = m&0o200 == 0 } } if pf.Excl { @@ -113,7 +160,13 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { } else { flags |= unix.O_RDONLY } - fd, err := t.open(flags, mode) + var fd int + created := false + if readOnlyNew { + fd, created, err = t.openNew(flags, mode|0o200) + } else { + fd, err = t.open(flags, mode) + } if err != nil { return nil, err } @@ -161,6 +214,17 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { quota: s.quota, rate: s.rate, } + if created { + // st.Mode is what the kernel made of the mode and the umask, with the + // owner's write bit that openNew added; the mode the client asked for + // is that without it, exactly what open(2) would have made, whatever + // the umask is. (A umask that clears the owner's write bit leaves the + // file as the kernel made it, and nothing is restored.) + if st.Mode&0o200 != 0 { + f.restore, f.restoring = st.Mode&0o777&^0o200, true + s.fresh.add(f) + } + } if f.quota != nil { f.quota.hold(f) } @@ -168,6 +232,47 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { return f, nil } +// openNew is the open of a file that may be created, for a client that asked +// for a mode without the owner's write bit (0444 for a read-only source file). +// The file is created with mode, which the caller gives the owner's write bit: +// the client's next steps on the handle are its own (an upload ends with a +// size step, a truncate by path, which the kernel refuses on a file its owner +// cannot write), and the mode it asked for is set when the handle closes (see +// Close). A client that never closes the handle cleanly leaves the file +// owner-writable; it is the owner's own file, and the session ending closes +// the handles it left open. +// +// An existing file is never touched: only a file this open creates is changed +// at the close, and the open that creates it is the one whose O_CREAT|O_EXCL +// succeeds. When the client did not ask for O_EXCL, the create is tried with it +// first, and an existing file is then opened without O_CREAT (it can be +// removed between the two calls: the create is tried again, a few times). +// Whether the file was created is the kernel's answer, not a look at the file +// afterwards. +func (t *target) openNew(flags int, mode uint32) (fd int, created bool, err error) { + if flags&unix.O_EXCL != 0 { + fd, err = t.open(flags, mode) + return fd, err == nil, err + } + for range 3 { + fd, err = t.open(flags|unix.O_EXCL, mode) + if err == nil { + return fd, true, nil + } + if !errors.Is(err, unix.EEXIST) { + return -1, false, err + } + fd, err = t.open(flags&^unix.O_CREAT, 0) + if err == nil { + return fd, false, nil + } + if !errors.Is(err, unix.ENOENT) { + return -1, false, err + } + } + return -1, false, err +} + // truncate empties the open file fd and takes the size it had off the usage. // With a quota the size is read, the file cut and the usage lowered as one step // under the quota's lock, like a write: a write on another handle of the same @@ -267,7 +372,16 @@ func (f *file) Close() error { if f.quota != nil { f.quota.unhold(f) // while the descriptor is still open } + var merr error + if f.restoring && f.s.fresh.take(f) { + // The mode the client asked for, on the descriptor (the name may + // have gone elsewhere), before it is closed. + merr = f.f.Chmod(os.FileMode(f.restore)) + } cerr = f.f.Close() + if cerr == nil { + cerr = merr + } f.s.handles.release() f.mu.Lock() err := f.xferr diff --git a/internal/sftpd/handlers.go b/internal/sftpd/handlers.go index 40a5c2e5..051a4216 100644 --- a/internal/sftpd/handlers.go +++ b/internal/sftpd/handlers.go @@ -21,6 +21,7 @@ type server struct { rate *bucket // nil when the session has no rate limit handles handleCount // the open files and directory listings + fresh freshModes // the files created owner-writable, waiting for their mode beforeTruncate func() // a test's hooks, see seams afterPin func() @@ -400,6 +401,7 @@ func (s *server) setstat(r *sftp.Request) (err error) { if err := p.chmod(permBits(a.Mode)); err != nil { return err } + s.fresh.forget(inode{u64(p.st.Dev), u64(p.st.Ino)}) // what the client set stays } if fl.Acmodtime { if err := p.utimes(a.Atime, a.Mtime); err != nil { diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go index 29d2ed4c..f6f2c33d 100644 --- a/internal/sftpd/openmode_test.go +++ b/internal/sftpd/openmode_test.go @@ -7,6 +7,7 @@ import ( "net" "os" "path/filepath" + "sync" "syscall" "testing" "time" @@ -14,14 +15,17 @@ import ( // The SFTP packet types a raw client needs. const ( - rawInit = 1 - rawOpen = 3 - rawClose = 4 - rawWrite = 6 - rawRead = 5 - rawVersion = 2 - rawStatus = 101 - rawHandle = 102 + rawInit = 1 + rawOpen = 3 + rawClose = 4 + rawSetstat = 9 + rawFsetstat = 10 + rawMkdir = 14 + rawWrite = 6 + rawRead = 5 + rawVersion = 2 + rawStatus = 101 + rawHandle = 102 rawFlagRead = 0x1 rawFlagWrite = 0x2 @@ -29,6 +33,7 @@ const ( rawFlagTrunc = 0x10 rawFlagExcl = 0x20 + rawAttrSize = 0x1 rawAttrPerm = 0x4 ) @@ -156,6 +161,28 @@ func (r *rawConn) finish(h, data string) { } } +// fsetstat sends an fsetstat request for the handle h with the attribute flags +// aflags and the block attrs, and returns the status code. +func (r *rawConn) fsetstat(h string, aflags uint32, attrs []byte) uint32 { + r.t.Helper() + b := str(nil, h) + b = binary.BigEndian.AppendUint32(b, aflags) + b = append(b, attrs...) + typ, body := r.request(rawFsetstat, b) + return status(r.t, typ, body) +} + +// closeHandle closes the handle h. +func (r *rawConn) closeHandle(h string) { + r.t.Helper() + typ, body := r.request(rawClose, str(nil, h)) + if c := status(r.t, typ, body); c != 0 { + r.t.Fatalf("close: status %d", c) + } +} + +func sizeAttrs(size uint64) []byte { return binary.BigEndian.AppendUint64(nil, size) } + func permAttrs(mode uint32) []byte { return binary.BigEndian.AppendUint32(nil, mode) } // The open request carries the mode of the new file: its permission bits, @@ -260,3 +287,220 @@ func TestPermBits(t *testing.T) { } } } + +// An upload of a file whose mode lacks the owner's write bit (scp without -p +// sends 0444 or 0555 for a read-only source) ends with a size step: the client +// sets the size of the handle it wrote, which the library turns into a setstat +// of the path, a truncate that needs write permission. The file must be +// writable by its owner until the handle is closed, and have the mode the +// client asked for after it. +func TestOpenModeWithoutOwnerWrite(t *testing.T) { + const creatTrunc = rawFlagWrite | rawFlagCreat | rawFlagTrunc + tests := []struct { + name string + umask int + mode uint32 + pflags uint32 + want os.FileMode + }{ + {"0400 under the console umask", 0o077, 0o400, creatTrunc, 0o400}, + {"0444 under the console umask", 0o077, 0o444, creatTrunc, 0o400}, + {"0500 under the console umask", 0o077, 0o500, creatTrunc, 0o500}, + {"0555 under the console umask", 0o077, 0o555, creatTrunc, 0o500}, + {"0444 under umask 022", 0o022, 0o444, creatTrunc, 0o444}, + {"0555 under umask 022", 0o022, 0o555, creatTrunc, 0o555}, + {"0444 and exclusive", 0o022, 0o444, rawFlagWrite | rawFlagCreat | rawFlagExcl, 0o444}, + {"0444 for reading and writing", 0o022, 0o444, rawFlagRead | creatTrunc, 0o444}, + {"the special bits are dropped", 0o022, 0o4444, creatTrunc, 0o444}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + old := syscall.Umask(tc.umask) + defer syscall.Umask(old) + home := filepath.Join(t.TempDir(), "home") + if err := os.Mkdir(home, 0o755); err != nil { + t.Fatal(err) + } + p := filepath.Join(home, "f") + r := newRawConn(t, home) + h, code := r.open("f", tc.pflags, rawAttrPerm, permAttrs(tc.mode)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + b := str(nil, h) + b = binary.BigEndian.AppendUint64(b, 0) + b = str(b, "newdata") + typ, body := r.request(rawWrite, b) + if c := status(t, typ, body); c != 0 { + t.Fatalf("write: status %d", c) + } + // What scp does after the data: the size of the handle. + if c := r.fsetstat(h, rawAttrSize, sizeAttrs(7)); c != 0 { + t.Errorf("fsetstat of the size: status %d, want 0", c) + } + r.closeHandle(h) + fi, err := os.Stat(p) + if err != nil { + t.Fatal(err) + } + if fi.Mode() != tc.want { + t.Errorf("mode %v, want %v", fi.Mode(), tc.want) + } + if fi.Size() != 7 { + t.Errorf("size %d, want 7", fi.Size()) + } + }) + } +} + +// writeAt writes data at offset 0 of the handle h. +func (r *rawConn) writeAt(h, data string) { + r.t.Helper() + b := binary.BigEndian.AppendUint64(str(nil, h), 0) + typ, body := r.request(rawWrite, str(b, data)) + if c := status(r.t, typ, body); c != 0 { + r.t.Fatalf("write: status %d", c) + } +} + +func newHome(t *testing.T) string { + t.Helper() + home := filepath.Join(t.TempDir(), "home") + if err := os.Mkdir(home, 0o755); err != nil { + t.Fatal(err) + } + return home +} + +func modeOfFile(t *testing.T, p string) os.FileMode { + t.Helper() + fi, err := os.Stat(p) + if err != nil { + t.Fatal(err) + } + return fi.Mode() +} + +// A file that exists is not touched by an open that asks for a mode without +// the owner's write bit, with or without truncation: it keeps its mode, and +// the client's size step works on it as on any file its owner can write. +func TestOpenModeWithoutOwnerWriteExistingFile(t *testing.T) { + for _, pflags := range []uint32{ + rawFlagWrite | rawFlagCreat | rawFlagTrunc, + rawFlagWrite | rawFlagCreat, + rawFlagRead | rawFlagWrite | rawFlagCreat, + } { + old := syscall.Umask(0o077) + home := newHome(t) + p := filepath.Join(home, "f") + if err := os.WriteFile(p, []byte("old data"), 0o600); err != nil { + t.Fatal(err) + } + if err := os.Chmod(p, 0o640); err != nil { + t.Fatal(err) + } + r := newRawConn(t, home) + h, code := r.open("f", pflags, rawAttrPerm, permAttrs(0o400)) + if h == "" { + t.Fatalf("pflags %#x: open refused: status %d", pflags, code) + } + r.writeAt(h, "new") + if c := r.fsetstat(h, rawAttrSize, sizeAttrs(3)); c != 0 { + t.Errorf("pflags %#x: fsetstat of the size: status %d", pflags, c) + } + r.closeHandle(h) + syscall.Umask(old) + if got := modeOfFile(t, p); got != 0o640 { + t.Errorf("pflags %#x: mode %v, want -rw-r-----", pflags, got) + } + } +} + +// A client that sets the permissions of the file between the data and the +// close gets what it set: the close does not put the mode of the open back. +func TestOpenModeWithoutOwnerWriteSetstatWins(t *testing.T) { + old := syscall.Umask(0o077) + defer syscall.Umask(old) + home := newHome(t) + p := filepath.Join(home, "f") + r := newRawConn(t, home) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm, permAttrs(0o400)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + r.writeAt(h, "data") + if c := r.fsetstat(h, rawAttrSize, sizeAttrs(4)); c != 0 { + t.Fatalf("fsetstat of the size: status %d", c) + } + if c := r.fsetstat(h, rawAttrPerm, permAttrs(0o755)); c != 0 { + t.Fatalf("fsetstat of the permissions: status %d", c) + } + r.closeHandle(h) + if got := modeOfFile(t, p); got != 0o755 { + t.Errorf("mode %v, want -rwxr-xr-x", got) + } +} + +// A session that ends with the handle open still gives the file the mode the +// client asked for: the library closes the handles it holds. +func TestOpenModeWithoutOwnerWriteSessionEnds(t *testing.T) { + old := syscall.Umask(0o077) + defer syscall.Umask(old) + home := newHome(t) + p := filepath.Join(home, "f") + r := newRawConn(t, home) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm, permAttrs(0o444)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + r.writeAt(h, "data") + _ = r.close() // the client leaves with the handle open + if got := modeOfFile(t, p); got != 0o400 { + t.Errorf("mode %v, want -r--------", got) + } +} + +// With a quota the size step of the upload is measured as always, and with an +// audit the upload is one event. +func TestOpenModeWithoutOwnerWriteQuotaAndAudit(t *testing.T) { + old := syscall.Umask(0o077) + defer syscall.Umask(old) + home := newHome(t) + var events []Event + var mu sync.Mutex + cfg := Config{Home: home, Quota: 10, Audit: func(e Event) { + mu.Lock() + events = append(events, e) + mu.Unlock() + }} + r := newRawConnCfg(t, cfg, seams{}) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm, permAttrs(0o444)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + r.writeAt(h, "12345") + if c := r.fsetstat(h, rawAttrSize, sizeAttrs(100)); c != fxFailure && c != fxPermissionDenied && c == 0 { + t.Errorf("a size over the quota: status %d, want a refusal", c) + } + if c := r.fsetstat(h, rawAttrSize, sizeAttrs(5)); c != 0 { + t.Errorf("fsetstat of the size: status %d", c) + } + r.closeHandle(h) + if got := modeOfFile(t, filepath.Join(home, "f")); got != 0o400 { + t.Errorf("mode %v, want -r--------", got) + } + mu.Lock() + defer mu.Unlock() + var up int + for _, e := range events { + if e.Op == "upload" { + up++ + if e.Err != nil || e.Bytes != 5 { + t.Errorf("upload event %+v", e) + } + } + } + if up != 1 { + t.Errorf("%d upload events, want 1: %+v", up, events) + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index e9142211..9e9aebce 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -16485,7 +16485,14 @@ and .B scp send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none); a file that already exists keeps its -mode, whatever the open asks. Both are reduced by the umask of the console, 077: +mode, whatever the open asks. A new file asked at a mode without the owner's +write bit (0444, which +.B scp +sends for a read\-only source) is created writable by its owner and gets the +mode asked for, reduced the same way, when the client closes the handle, so that +the size step an upload ends with works; a client that sets the permissions +itself in between keeps what it set, and a session that ends with the handle +open closes it. Both are reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is 0700. The set\-user\-ID, From e98bee44a78d3b8d8146725aeb737ca8469b337f Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:54:45 -0900 Subject: [PATCH 40/52] sftpd: an open that asks for the mode 0 asks for nothing A version 3 attribute block with only the extended flag and a count of none is four bytes of zero, as long as the permissions block the OpenSSH clients send, and openMode read it as the mode 0000: the new file got no permission bits. A four byte block with the value 0 now asks for nothing, so the file gets the default mode (0644, 0600 after the umask of the console), and a client that really wants 0000 sets it afterwards. The comment of openMode and item 1 of 0.2.29 said that four bytes can only be the permissions, which is not so; they now say that it is read as such and what the exception is. The console page and the manual page name the mode 0. The test covers the mode 0 and the extended flag with no attributes, under both umasks, and fails without the change (the file is created with no mode). --- CHANGELOG.md | 16 ++++++++++------ docs/cli/console.md | 2 +- internal/sftpd/file.go | 19 ++++++++++++++----- internal/sftpd/openmode_test.go | 9 +++++++-- man/tacctl.1 | 4 +++- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76b6bcb3..f005d4ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,16 @@ current behaviour; this file is where history lives. OpenSSH 9 or later (which speaks SFTP and sends the permissions in that request, and sets nothing afterwards) lost its execute bit. A new file now gets the mode the client asks for in the open request when the request - carries the permissions alone, which is what the OpenSSH `sftp` and `scp` - send: the permission bits only (set-user-ID, set-group-ID and sticky are - ignored, as for a new directory), reduced by the umask of the console, 077. - The owner's bits survive and the group and other bits go: a script asked - at 0755 is 0700, a file asked at 0644 is 0600. A request without - permissions still gives 0644, 0600 after the umask. A file that already + carries a block of four bytes, read as the permissions alone (the library + does not say which attributes a request holds; four bytes is what the + OpenSSH `sftp` and `scp` send): the permission bits only (set-user-ID, + set-group-ID and sticky are ignored, as for a new directory), reduced by + the umask of the console, 077. The + owner's bits survive and the group and other bits go: a script asked at + 0755 is 0700, a file asked at 0644 is 0600. A request without permissions, + or that asks for the mode 0 (a block of four bytes of zero is also what a + request with no attributes but the extended ones looks like), still gives + 0644, 0600 after the umask. A file that already exists keeps its mode, and a download changes nothing. A file asked at a mode without the owner's write bit (0444, or 0555, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked diff --git a/docs/cli/console.md b/docs/cli/console.md index 3c86f2c7..41858805 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -220,7 +220,7 @@ Every form of `console file-transfer` is the superuser's, the reads included (`c **What a user can do.** `sftp alice@tacacs.example.net` and the `scp` of OpenSSH 9 or later (which speaks SFTP unless it is given `-O`) work for an account that has file transfer. `scp -O` (the old protocol), `rsync`, any program and the shell's words are refused, as before, with `the tacctl console does not run programs or shell commands; file transfer is SFTP only (sftp, scp of OpenSSH 9 or later)` (exit 126). For an account that does not have file transfer the subsystem is refused with `file transfer is not enabled for this account; an administrator can switch it on (tacctl console file-transfer)` (exit 126), and so is the subsystem of a user held to a required password change. The console serves the protocol as the logged-in user, with no change of privilege, so the file system's permissions apply as they do in the user's shell. An account that does not have file transfer sees only `Connection closed` from `sftp` and `scp` (sshd does not show the error text of a subsystem; `ssh id`, a command request, does): the reason, `reason=file-transfer` with status 126, is in the console's audit log, and `console show` lists who has file transfer. -**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode the client asks for. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle open closes it. Both are reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is 0700. The set-user-ID, set-group-ID and sticky bits are ignored, and a client that wants another mode sets it afterwards, which is applied as given. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. +**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode the client asks for. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for the mode 0, which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle open closes it. Both are reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is 0700. The set-user-ID, set-group-ID and sticky bits are ignored, and a client that wants another mode sets it afterwards, which is applied as given. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. **The quota and the rate.** The quota is the bytes the home may hold. It counts the sizes of the regular files in it, each inode once (a file with two names counts once): the reports and support bundles tacctl wrote there, `.ssh` and the files the user uploads. Directories, links and inodes do not count, and a sparse file counts its length. A write that would take the home over it is refused whole (`disk quota exceeded`) and audited, and so is a size that would grow a file over it; a smaller size gives the room back. An upload that is refused part way leaves what was written before the refusal in the home (the client does not remove it), and the `sftp` and `scp` of OpenSSH show only `Failure` for it: the reason, `reason=quota`, is in the console's audit log. A file that was deleted while a handle of the session still holds it stays counted until the handle is closed. The home is measured when the session starts and again, when a file is opened for writing, if the last measure is a few seconds old, so the quota is per session: N sessions of one user at once can each use the room that was free when they measured, and bring the home to about N times the quota. A directory in the home that the session cannot read or search (for example one owned by root with mode 0700) makes the home count as full: every upload that grows the home is refused with `disk quota exceeded` until the directory is readable, while reading, deleting and writes that do not grow the home go on. The rate is the bytes a second one session may move, reads and writes together, with a burst of one second; a transfer at its rate waits, it is not refused. Both are read when the session starts. diff --git a/internal/sftpd/file.go b/internal/sftpd/file.go index 1050e1d6..9c459225 100644 --- a/internal/sftpd/file.go +++ b/internal/sftpd/file.go @@ -93,16 +93,25 @@ func permBits(m uint32) uint32 { return m & 0o777 } // it asked. The library hands the handlers the attribute block of an open as // raw bytes and drops the attribute flags that say which fields it holds // (Request.Flags of an open is the open flags, so AttrFlags and Attributes -// would read the wrong thing). A block of exactly four bytes can only be the +// would read the wrong thing). A block of exactly four bytes is read as the // permissions: it is what the OpenSSH sftp and scp clients send, without a -// size, owner or times. Any other length could be the permissions together -// with a size, an owner or times, in an order that cannot be told apart, so it -// asks for nothing and the new file gets the default mode, as before. +// size, owner or times. It is not always so: a version 3 block that holds only +// the flag of the extended attributes and a count of none is four bytes of +// zero too, and would read as the mode 0000. A value of zero is therefore +// read as asking for nothing (a client that really asks for 0000 gets the +// default, and can set the mode afterwards). Any other length could be the +// permissions together with a size, an owner or times, in an order that +// cannot be told apart, so it asks for nothing and the new file gets the +// default mode, as before. func openMode(r *sftp.Request) (uint32, bool) { if len(r.Attrs) != 4 { return 0, false } - return permBits(binary.BigEndian.Uint32(r.Attrs)), true + v := binary.BigEndian.Uint32(r.Attrs) + if v == 0 { + return 0, false + } + return permBits(v), true } // openFile opens the file of r. write says the open is for an upload (the diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go index f6f2c33d..73753cec 100644 --- a/internal/sftpd/openmode_test.go +++ b/internal/sftpd/openmode_test.go @@ -33,8 +33,9 @@ const ( rawFlagTrunc = 0x10 rawFlagExcl = 0x20 - rawAttrSize = 0x1 - rawAttrPerm = 0x4 + rawAttrSize = 0x1 + rawAttrExtended = 0x80000000 + rawAttrPerm = 0x4 ) // rawConn speaks SFTP by hand, so that a test can put attributes in an open @@ -216,6 +217,10 @@ func TestOpenModeOfTheRequest(t *testing.T) { {"no attributes: 0644 under umask 022", 0o022, creatTrunc, 0, nil, 0, 0o644}, {"no attributes: 0600 under the console umask", 0o077, creatTrunc, 0, nil, 0, 0o600}, {"create and exclusive", 0o022, rawFlagWrite | rawFlagCreat | rawFlagExcl, rawAttrPerm, permAttrs(0o755), 0, 0o755}, + {"mode 0 asks for nothing: 0644 under umask 022", 0o022, creatTrunc, rawAttrPerm, permAttrs(0), 0, 0o644}, + {"mode 0 asks for nothing: 0600 under the console umask", 0o077, creatTrunc, rawAttrPerm, permAttrs(0), 0, 0o600}, + {"extended attributes without any: 0644 under umask 022", 0o022, creatTrunc, rawAttrExtended, permAttrs(0), 0, 0o644}, + {"extended attributes without any: 0600 under the console umask", 0o077, creatTrunc, rawAttrExtended, permAttrs(0), 0, 0o600}, {"permissions with times are not read", 0o022, creatTrunc, rawAttrPerm | times, twelve, 0, 0o644}, {"an existing file keeps its mode", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o755), 0o640, 0o640}, {"an existing file without create keeps its mode", 0o022, rawFlagWrite, rawAttrPerm, permAttrs(0o755), 0o640, 0o640}, diff --git a/man/tacctl.1 b/man/tacctl.1 index 9e9aebce..6df1c553 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -16484,7 +16484,9 @@ carries the permissions alone (which is what the OpenSSH and .B scp send), and 0644 otherwise (a request that carries other attributes with the -permissions is read as carrying none); a file that already exists keeps its +permissions is read as carrying none, and so is one that asks for the mode 0, +which cannot be told from a request with no attributes but the extended ones); +a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which .B scp From ddce7fc0c6b0caede943cb5223776ee35d0fb049 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:57:58 -0900 Subject: [PATCH 41/52] docs: a new directory is 0755, and what scp -p and scp without -p do The pages said that a new directory gets the mode the client asks for. It never did: the library reads only the attribute flags of a mkdir packet (sshFxpMkdirPacket.UnmarshalBinary) and sets no flags in the request for it, so the handler never sees the permissions and every new directory is 0755, 0700 after the umask of the console. The console page, the manual page and item 1 of 0.2.29 now say that, and that a client that wants another mode sets it afterwards. The comment of permBits no longer says that mkdir takes its mode through it, and mkdir says why its branch is not reached. The new test makes a directory with the mode 0500 and 0777 under both umasks and fails if a library upgrade starts to deliver the permissions. The pages and the item said that scp sets nothing after an upload and that scp -p only gets the open's mode. Without -p scp sets the size afterwards (the previous change); with -p the open carries the permissions and the times (twelve bytes, read as asking for nothing, so the file is created 0644, 0600 after the umask) and an fsetstat then sets the permissions and times, which setstat applies as given, with no umask: a script ends with its source's mode, 0755. A new test sends that sequence and checks the mode and the time. --- CHANGELOG.md | 48 ++++++++++--------- docs/cli/console.md | 2 +- internal/sftpd/handlers.go | 5 ++ internal/sftpd/openmode_test.go | 84 +++++++++++++++++++++++++++++++++ man/tacctl.1 | 31 +++++++++--- 5 files changed, 140 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f005d4ef..48efac08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,30 +9,34 @@ current behaviour; this file is where history lives. console's file transfer gave every new file the mode 0644 and ignored the mode in the request that opens it, so a script copied with the `scp` of OpenSSH 9 or later (which speaks SFTP and sends the permissions in that - request, and sets nothing afterwards) lost its execute bit. A new file now - gets the mode the client asks for in the open request when the request - carries a block of four bytes, read as the permissions alone (the library - does not say which attributes a request holds; four bytes is what the - OpenSSH `sftp` and `scp` send): the permission bits only (set-user-ID, - set-group-ID and sticky are ignored, as for a new directory), reduced by - the umask of the console, 077. The + request) lost its execute bit. A new file now gets the mode the client + asks for in the open request when the request carries a block of four + bytes, read as the permissions alone (the library does not say which + attributes a request holds; four bytes is what the OpenSSH `sftp` and + `scp` send): the permission bits only (set-user-ID, set-group-ID and + sticky are ignored), reduced by the umask of the console, 077. The owner's bits survive and the group and other bits go: a script asked at - 0755 is 0700, a file asked at 0644 is 0600. A request without permissions, - or that asks for the mode 0 (a block of four bytes of zero is also what a - request with no attributes but the extended ones looks like), still gives - 0644, 0600 after the umask. A file that already + 0755 is 0700, a file asked at 0644 is 0600. A request without + permissions, or that asks for the mode 0 (a block of four bytes of zero + is also what a request with no attributes but the extended ones looks + like), still gives 0644, 0600 after the umask. A file that already exists keeps its mode, and a download changes nothing. A file asked at a - mode without the owner's write bit (0444, or 0555, which `scp` sends for a - read-only source) is created writable by its owner and gets the mode asked - for, reduced by the umask, when the client closes the handle: `scp` ends an - upload by setting the size of the file, which the kernel refuses on a file - its owner cannot write, so the mode comes last. A client that sets the - permissions itself before it closes the handle keeps what it set. A request that - carries other attributes together with the permissions (for example the - times, as with the preserve option of `scp`) is read as carrying none, - because the library does not tell which attributes a request holds; such - a file gets 0644, 0600 after the umask, as before. `docs/cli/console.md` - and the manual page say so. + mode without the owner's write bit (0444, or 0555, which `scp` sends for + a read-only source) is created writable by its owner and gets the mode + asked for, reduced by the umask, when the client closes the handle: + without `-p`, `scp` ends an upload by setting the size of the file, which + the kernel refuses on a file its owner cannot write, so the mode comes + last. A client that sets the permissions itself before it closes the + handle keeps what it set. A request that carries other attributes + together with the permissions (the times that `scp -p` sends) is read as + carrying none, and such a file gets 0644, 0600 after the umask, as before; + `scp -p` then sets the permissions and the times of the file after the + upload, which are applied as given, with no umask, so a script ends with + the mode of its source, 0755. A new directory is not affected: the + library does not deliver the mode of a request to make a directory, so it + is 0755, 0700 after the umask, whatever the client asks, and a client + that wants another mode sets it afterwards. `docs/cli/console.md` and the + manual page say so. 2. **`tacctl rollback 0.2.28`, the release before this one, is a target.** This release changed no stored file 0.2.28 reads strictly (the mode a file diff --git a/docs/cli/console.md b/docs/cli/console.md index 41858805..1eefb268 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -220,7 +220,7 @@ Every form of `console file-transfer` is the superuser's, the reads included (`c **What a user can do.** `sftp alice@tacacs.example.net` and the `scp` of OpenSSH 9 or later (which speaks SFTP unless it is given `-O`) work for an account that has file transfer. `scp -O` (the old protocol), `rsync`, any program and the shell's words are refused, as before, with `the tacctl console does not run programs or shell commands; file transfer is SFTP only (sftp, scp of OpenSSH 9 or later)` (exit 126). For an account that does not have file transfer the subsystem is refused with `file transfer is not enabled for this account; an administrator can switch it on (tacctl console file-transfer)` (exit 126), and so is the subsystem of a user held to a required password change. The console serves the protocol as the logged-in user, with no change of privilege, so the file system's permissions apply as they do in the user's shell. An account that does not have file transfer sees only `Connection closed` from `sftp` and `scp` (sshd does not show the error text of a subsystem; `ssh id`, a command request, does): the reason, `reason=file-transfer` with status 126, is in the console's audit log, and `console show` lists who has file transfer. -**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode the client asks for. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for the mode 0, which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle open closes it. Both are reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is 0700. The set-user-ID, set-group-ID and sticky bits are ignored, and a client that wants another mode sets it afterwards, which is applied as given. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. +**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode 0755, which is 0700 after the umask of the console, whatever the client asks (the library does not hand the server the attributes of a request to make a directory); a client that wants another mode sets it afterwards. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for the mode 0, which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle open closes it. The mode of a new file is reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set-user-ID, set-group-ID and sticky bits are ignored. A mode that a client sets afterwards (a `chmod` in `sftp`, or the permissions sent for a handle) is applied as given, with no umask. Without `-p`, `scp` sets nothing but the size of the file after an upload, so the mode is the one of the open. With `-p` (preserve) it sends the times together with the permissions in the open request, which is read as carrying none, so the file is created with 0644 (0600 after the umask), and then sets the permissions and the times of the handle after the upload, which are applied as given: a script ends with the mode of its source, 0755. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. **The quota and the rate.** The quota is the bytes the home may hold. It counts the sizes of the regular files in it, each inode once (a file with two names counts once): the reports and support bundles tacctl wrote there, `.ssh` and the files the user uploads. Directories, links and inodes do not count, and a sparse file counts its length. A write that would take the home over it is refused whole (`disk quota exceeded`) and audited, and so is a size that would grow a file over it; a smaller size gives the room back. An upload that is refused part way leaves what was written before the refusal in the home (the client does not remove it), and the `sftp` and `scp` of OpenSSH show only `Failure` for it: the reason, `reason=quota`, is in the console's audit log. A file that was deleted while a handle of the session still holds it stays counted until the handle is closed. The home is measured when the session starts and again, when a file is opened for writing, if the last measure is a few seconds old, so the quota is per session: N sessions of one user at once can each use the room that was free when they measured, and bring the home to about N times the quota. A directory in the home that the session cannot read or search (for example one owned by root with mode 0700) makes the home count as full: every upload that grows the home is refused with `disk quota exceeded` until the directory is readable, while reading, deleting and writes that do not grow the home go on. The rate is the bytes a second one session may move, reads and writes together, with a burst of one second; a transfer at its rate waits, it is not refused. Both are read when the session starts. diff --git a/internal/sftpd/handlers.go b/internal/sftpd/handlers.go index 051a4216..e9d9a3a3 100644 --- a/internal/sftpd/handlers.go +++ b/internal/sftpd/handlers.go @@ -235,6 +235,11 @@ func (s *server) mkdir(r *sftp.Request) (err error) { return err } defer t.close() + // The library reads only the attribute flags of a mkdir packet and sets no + // flags in the request, so the permissions are never delivered and a new + // directory is 0755 less the umask whatever the client asks (the docs say + // so; TestMkdirIgnoresTheModeOfTheRequest holds it). The branch is for a + // library that delivers them. mode := uint32(0o755) if r.AttrFlags().Permissions { if a := r.Attributes(); a != nil { diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go index 73753cec..ee42ae41 100644 --- a/internal/sftpd/openmode_test.go +++ b/internal/sftpd/openmode_test.go @@ -36,6 +36,7 @@ const ( rawAttrSize = 0x1 rawAttrExtended = 0x80000000 rawAttrPerm = 0x4 + rawAttrTimes = 0x8 ) // rawConn speaks SFTP by hand, so that a test can put attributes in an open @@ -509,3 +510,86 @@ func TestOpenModeWithoutOwnerWriteQuotaAndAudit(t *testing.T) { t.Errorf("%d upload events, want 1: %+v", up, events) } } + +// mkdir sends a mkdir request with the attribute flags aflags and the block +// attrs, and returns the status code. +func (r *rawConn) mkdir(path string, aflags uint32, attrs []byte) uint32 { + r.t.Helper() + b := binary.BigEndian.AppendUint32(str(nil, path), aflags) + typ, body := r.request(rawMkdir, append(b, attrs...)) + return status(r.t, typ, body) +} + +// A new directory is 0755 less the umask whatever the request asks: the library +// reads only the attribute flags of a mkdir packet (vendor/github.com/pkg/sftp, +// sshFxpMkdirPacket.UnmarshalBinary) and sets no Request.Flags for it, so the +// handler is never told the permissions. The docs say so; this test fails if a +// library upgrade starts to deliver them (and the docs and the handler are then +// to be looked at together). +func TestMkdirIgnoresTheModeOfTheRequest(t *testing.T) { + tests := []struct { + name string + umask int + mode uint32 + want os.FileMode + }{ + {"0500 under the console umask", 0o077, 0o500, 0o700}, + {"0777 under the console umask", 0o077, 0o777, 0o700}, + {"0500 under umask 022", 0o022, 0o500, 0o755}, + {"0700 under umask 022", 0o022, 0o700, 0o755}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + home := newHome(t) + old := syscall.Umask(tc.umask) + defer syscall.Umask(old) + r := newRawConn(t, home) + if c := r.mkdir("d", rawAttrPerm, permAttrs(tc.mode)); c != 0 { + t.Fatalf("mkdir: status %d", c) + } + fi, err := os.Stat(filepath.Join(home, "d")) + if err != nil { + t.Fatal(err) + } + if fi.Mode() != tc.want|os.ModeDir { + t.Errorf("mode %v, want %v", fi.Mode(), tc.want|os.ModeDir) + } + }) + } +} + +// What scp -p does: the open carries the permissions and the times (twelve +// bytes, read as asking for nothing, so the file is created 0644 less the +// umask), and after the data an fsetstat sets the same permissions and times, +// which are applied as given: the umask of the console does not reduce them. +func TestOpenModeWithTimesThenSetstat(t *testing.T) { + old := syscall.Umask(0o077) + defer syscall.Umask(old) + home := newHome(t) + p := filepath.Join(home, "f") + const mtime = 1_700_000_000 + times := binary.BigEndian.AppendUint32(binary.BigEndian.AppendUint32(nil, mtime), mtime) + r := newRawConn(t, home) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm|rawAttrTimes, append(permAttrs(0o755), times...)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + if got := modeOfFile(t, p); got != 0o600 { + t.Errorf("mode after the open %v, want -rw-------", got) + } + r.writeAt(h, "#!/bin/sh\n") + if c := r.fsetstat(h, rawAttrPerm|rawAttrTimes, append(permAttrs(0o755), times...)); c != 0 { + t.Fatalf("fsetstat: status %d", c) + } + r.closeHandle(h) + fi, err := os.Stat(p) + if err != nil { + t.Fatal(err) + } + if fi.Mode() != 0o755 { + t.Errorf("mode %v, want -rwxr-xr-x", fi.Mode()) + } + if fi.ModTime().Unix() != mtime { + t.Errorf("mtime %d, want %d", fi.ModTime().Unix(), mtime) + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index 6df1c553..fe173a24 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -16477,7 +16477,10 @@ can be set (cut, or extended with zeros), which is what .B scp does after an upload to give the file its final size; it counts against the quota like a write. The owner cannot be changed, and a request that asks for it is -refused whole. A new directory gets the mode the client asks for. A new file gets +refused whole. A new directory gets the mode 0755, which is 0700 after the umask +of the console, whatever the client asks (the library does not hand the server +the attributes of a request to make a directory); a client that wants another +mode sets it afterwards. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the OpenSSH .B sftp @@ -16494,12 +16497,26 @@ sends for a read\-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle -open closes it. Both are reduced by the umask of the console, 077: -the owner's bits survive and the group and other bits go, so a script uploaded -with mode 0755 is 0700, one with 0644 is 0600, and a directory asked 0755 is -0700. The set\-user\-ID, -set\-group\-ID and sticky bits are ignored, and a client that wants another mode -sets it afterwards, which is applied as given. Changing the mode or the times of +open closes it. The mode of a new file is reduced by the umask of the console, +077: the owner's bits survive and the group and other bits go, so a script +uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set\-user\-ID, +set\-group\-ID and sticky bits are ignored. A mode that a client sets afterwards +(a +.B chmod +in +.BR sftp , +or the permissions sent for a handle) is applied as given, with no umask. +Without +.BR \-p , +.B scp +sets nothing but the size of the file after an upload, so the mode is the one of +the open. With +.B \-p +(preserve) it sends the times together with the permissions in the open request, +which is read as carrying none, so the file is created with 0644 (0600 after the +umask), and then sets the permissions and the times of the handle after the +upload, which are applied as given: a script ends with the mode of its source, +0755. Changing the mode or the times of a file goes through .BR /proc/self/fd , so file transfer needs From 439b87b83ddf01bc8bda80fd096c3be4f9d09d27 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:58:18 -0900 Subject: [PATCH 42/52] plans: the 0.2.28 row no longer lists the upload mode and the lingering session The mode a client asks for on an upload is honoured by this release (item 1 of 0.2.29). The rate-limited session that could stay a moment after the client leaves was investigated and does not linger, so it is no longer open. The rest of the row stays. --- docs/plans/backlog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plans/backlog.md b/docs/plans/backlog.md index 99b706bc..3ddc731a 100644 --- a/docs/plans/backlog.md +++ b/docs/plans/backlog.md @@ -33,7 +33,7 @@ Planned 2026-10-08; **solidified 2026-10-09 with the 0.2.4 plan** (`0.2.4-plan.m | **0.2.23 (released 2026-10-31; CHANGELOG `## 0.2.23`, items 1-20)** | **Stored-file changes with a `rollback 0.2.22`:** an optional email on users; the SNMPv3 user pool (one default per level, protocols per level); `device clone` and `device rename --replace` with the scope staging address (and `rename` carrying the staging line); lockdown on enrolled hosts (a static sshd `Match Group` drop-in, applied by `host sync`, pending list); carry-overs of 0.2.22; device-own AAA settings and the AAA source check (`device check|scan --sources`); an immediate sync of this server on user changes with an offer for the other hosts; `backup keep` and `backup recover`. Not in the release: naming a device from its configuration (section 3j). | | **0.2.24 (released 2026-11-05; CHANGELOG `## 0.2.24`, items 1-11)** | **Logs, forwarding and the tacquito source, with a `rollback 0.2.23` that converts nothing:** each accounting record names the device that sent it (`"Device"`, tacquito patch 0006; `log accounting` shows the device's name) and keeps `<`, `>` and `&` as they are; `--since`, `--until`, `--user`, `--device`, `--type` and `--json` on `log tail|search|failures|accounting`, with the operator's sudo rule `log failures *`; a user held to a password change forwards no port through the server in any tier (a `Match User` block ahead of the tier blocks of the console's sshd drop-in, checked by `console check`); the walkthroughs no longer set `single-connection` and `device config plan|apply` delete it from tacctl's server; tacquito built from the project's fork `rett/tacquito`, its pull a fetch and a fast-forward with a reset when it cannot; the git clones, fetches and pulls of `install`, `upgrade`, `config branch` and `config linux build` ask for nothing and drop a stalled transfer (an ssh remote needs its host key in `known_hosts`); a break-glass hold also loads an nftables table that refuses the held address's TCP connections to tacquito, so a device that falls back to its local accounts when the server is unreachable (WTI, Junos) does (`config breakglass-firewall reject|drop|off`, a boot unit, the `nftables` package, removed by `rollback`); `tacctl man` on groff 1.24; `make lint` in CI and the skipped tests counted by the gates. | | **0.2.25 (2026-11-05; CHANGELOG `## 0.2.25`, items 1-10)** | **Junos fixes from a live network, the shapes list and the apply explanation, with a `rollback 0.2.24` that converts nothing:** `device config shapes` keeps its table narrow (a count in `NOW`, the devices below it wrapped at 80 columns); "Applying a plan" opens with a rollout in five steps and explains shape, canary and confirmed; a Junos NETCONF hello that names its capabilities with the XML namespace's prefix is read as `hello ok`, the hello is read as the device prints it, and a failed hello says why; a slow device's late answer in front of a command's echo no longer fails a pull or an apply; a Junos virtual chassis of two members whose master prints its own label is applied to, and a refused commit answer shows up to 40 lines; text a device sends is shown with C1 controls, formatting characters and line separators replaced; `rollback 0.2.24`; small accuracy fixes (the snapshot note of `rollback 0.2.23`, "1 line differs", the `config apply` usage row, which targets remove the 0.2.20 keys). **Open:** a virtual chassis of three or more members that all print a label has no capture and is read one line per label. | -| **0.2.28 (CHANGELOG `## 0.2.28`, items 1-4)** | **File transfer through the console, with a `rollback 0.2.27` that converts only its settings:** the console serves SFTP (`sftp` and the `scp` of OpenSSH 9 or later) to the accounts that have it, as the user, rooted in the home with `.ssh` out of reach and no link followed; `console file-transfer` sets it per tier and per user (off by default, superusers always, engineers allowed) with a quota on the home (256M, none for superusers) and an optional rate; the support bundle of a Cisco IOS device drops the tail of a long command's echo. **Open:** honouring the mode a client asks for on an upload (a new file is 0644 under the umask 077, so `scp` keeps no executable bit); a rate-limited session that can stay a moment after the client leaves; chassis components (power supplies, fans, line cards, optics) of a member, a dual-RE or SRX-cluster capture and a standalone Catalyst capture. | +| **0.2.28 (CHANGELOG `## 0.2.28`, items 1-4)** | **File transfer through the console, with a `rollback 0.2.27` that converts only its settings:** the console serves SFTP (`sftp` and the `scp` of OpenSSH 9 or later) to the accounts that have it, as the user, rooted in the home with `.ssh` out of reach and no link followed; `console file-transfer` sets it per tier and per user (off by default, superusers always, engineers allowed) with a quota on the home (256M, none for superusers) and an optional rate; the support bundle of a Cisco IOS device drops the tail of a long command's echo. **Open:** chassis components (power supplies, fans, line cards, optics) of a member, a dual-RE or SRX-cluster capture and a standalone Catalyst capture. | | **0.2.27 (CHANGELOG `## 0.2.27`, items 1-9)** | **PDF reports, a corrected support-bundle scrubber and home-only output paths, with a `rollback 0.2.26` that converts nothing:** `device reports generate --format pdf` (weasyprint, the upgrade offers `weasyprint` and `fonts-dejavu-core`); the scrubber keeps model names, object identifiers, column widths and vendors' public names and replaces serials by field, from the captures of real devices; every option that names a file to write is a path inside the caller's home (`device support-bundle --out` is a name); small report and rollback fixes. **Open:** chassis components (power supplies, fans, line cards, optics) of a member, a dual-RE or SRX-cluster capture and a standalone Catalyst capture. | | **0.2.26 (released 2026-11-06; CHANGELOG `## 0.2.26`, items 1-9)** | **Device reports with serial numbers and chassis members:** a good pull also stores the members of a Junos virtual chassis or Cisco stack (id, role, model, serial, release, status, priority); `device reports generate|list|show|export|rename|remove|prune` makes inventory, members, software and config reports as text, CSV or JSON in the user's own `~/reports/devices/`, from the stored records with no login (`--pull` reads first, engineer tier); superusers reach other users' reports with an audit line; `rollback 0.2.25`. **Out:** chassis components (0.2.27), PDF, `generate --as`. | | **0.2.10 (released 2026-10-15; `0.2.10-plan.md`, `0.2.10-lab.md`)** | **Apply over NETCONF as the second transport (pulled into 0.2.10 by the user, 2026-10-14; NETCONF is opt-in, the command line stays the default, `device config rollback` stays deferred) and the NETCONF service setting below; the account, break-glass and drift-detection items that follow are dropped (2026-10-15, `0.2.12-plan.md` section 2).** **A NETCONF service setting for Junos (decided with the user, 2026-10-14).** Three states, default `leave`: `enable` renders and plans `set system services netconf ssh` (with the optional connection-limit and rate-limit), `disable` plans `delete system services netconf`, `leave` plans and compares nothing (today's behaviour). Per scope with a per-device override, layered as SNMP and the blocks are: `scope netconf enable|disable|leave`, `device netconf enable|disable|leave`. The apply allow-list admits only those exact `system services netconf` statements; everything else under `system services` stays on the never-list (D133). Built, reviewed and run on the lab switch (`0.2.10-lab.md`). It supersedes `device config enable-netconf` (D93 of `apply-deferred.md`). **Provisioning/break-glass account rotation on devices** (new local user, proven by a fresh login, target switched, old one optionally removed last; new passwords generated and shown once unless decided otherwise); the rest of the per-user password handling, if any is left after 0.2.4. **From 0.2.4:** unattended drift detection (a timer running `device config pull --stale`) needs a credential no person types, which the never-stored rule forbids for users' passwords; it is designed here as a read-only service account on the devices (an ssh key held by the tacctl server, proved and rotated like the provisioning accounts), not before. **Break-glass users as a configuration block (filed 2026-10-12; open question, decide with the rotation design):** a vendor-native `login` block could carry a scope's break-glass accounts (Junos `system login user class authentication encrypted-password`, Cisco `username privilege secret 9 `), so every device of a scope gets the same account with compare, plan, back-out and the existing secret elision. *Gain:* consistent accounts, central rotation. *Cost:* it reverses the never-stored rule for a credential hash (at rest under `/etc/tacctl/blocks` and in every backup), makes one shared local-admin password per scope the easy path where a unique one per device is the usual practice, and a bad hash pasted fleet-wide breaks the one account meant for recovery (the helper's region check refuses login-user authentication today, and plans never emit the `breakglass` section, both on purpose). *Decide first:* store the hash (opt-in per scope, in a block, read-protected like an SNMP community) or keep it generated and shown once, which the rotation design above assumes; the two do not fit together. Until then: `scope breakglass` names and roles plus the walkthrough placeholder. Needs 0.2.9's apply to push a rotated account. | From f71dcad368319e6907e2fd34a2da550a6719f0f4 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 20:11:31 -0900 Subject: [PATCH 43/52] sftpd: an existing file is reopened with the client's own flags, and a failed create gives the mode back openNew opened an existing file without O_CREAT after the exclusive create answered EEXIST. The kernel answers EEXIST for O_CREAT|O_EXCL before it runs the sticky-directory checks of fs.protected_regular and fs.protected_fifos, and an open without O_CREAT never runs them, so a file that the single O_CREAT open of before would have refused (a file of another user in a world-writable sticky directory) was opened and written. After EEXIST the file is now opened again with the flags the client asked for, O_CREAT included, so the kernel's checks apply as they did; that also removes the retry loop and the ENOENT an O_CREAT open could end in after three lost rounds. The comment of openNew said a client that does not close the handle leaves the file owner-writable: the session ending closes every handle (TestOpenModeWithoutOwnerWriteSessionEnds shows it), only a killed server process leaves it. It now says so, and that a second handle on a file that still waits for its mode loses its size step when the creating handle closes first. The errors of openFile after a create and before the file is registered (a second name, a descriptor that cannot be made blocking, a failed truncation) left the file at the mode asked for plus the owner's write bit for good. They now go through one function that sets the asked mode on the descriptor before closing it. The new afterOpen seam lets a test give the file a second name between the open and the check. The documentation and the changelog say that an interrupted upload of a read-only source ends read-only, and that resuming it is refused. --- CHANGELOG.md | 5 +- docs/cli/console.md | 2 +- internal/sftpd/file.go | 101 ++++++++++++++++++-------------- internal/sftpd/handlers.go | 3 +- internal/sftpd/openmode_test.go | 66 +++++++++++++++++++++ internal/sftpd/sftpd.go | 5 +- man/tacctl.1 | 7 ++- 7 files changed, 141 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48efac08..520031c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,10 @@ current behaviour; this file is where history lives. without `-p`, `scp` ends an upload by setting the size of the file, which the kernel refuses on a file its owner cannot write, so the mode comes last. A client that sets the permissions itself before it closes the - handle keeps what it set. A request that carries other attributes + handle keeps what it set. An upload of a read-only source that is + interrupted ends read-only (0400, say), since the session ends by closing + the handle, and resuming it with `put -a` or `reput` is refused with + permission denied, as it is by the OpenSSH server. A request that carries other attributes together with the permissions (the times that `scp -p` sends) is read as carrying none, and such a file gets 0644, 0600 after the umask, as before; `scp -p` then sets the permissions and the times of the file after the diff --git a/docs/cli/console.md b/docs/cli/console.md index 1eefb268..3c973ae8 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -220,7 +220,7 @@ Every form of `console file-transfer` is the superuser's, the reads included (`c **What a user can do.** `sftp alice@tacacs.example.net` and the `scp` of OpenSSH 9 or later (which speaks SFTP unless it is given `-O`) work for an account that has file transfer. `scp -O` (the old protocol), `rsync`, any program and the shell's words are refused, as before, with `the tacctl console does not run programs or shell commands; file transfer is SFTP only (sftp, scp of OpenSSH 9 or later)` (exit 126). For an account that does not have file transfer the subsystem is refused with `file transfer is not enabled for this account; an administrator can switch it on (tacctl console file-transfer)` (exit 126), and so is the subsystem of a user held to a required password change. The console serves the protocol as the logged-in user, with no change of privilege, so the file system's permissions apply as they do in the user's shell. An account that does not have file transfer sees only `Connection closed` from `sftp` and `scp` (sshd does not show the error text of a subsystem; `ssh id`, a command request, does): the reason, `reason=file-transfer` with status 126, is in the console's audit log, and `console show` lists who has file transfer. -**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode 0755, which is 0700 after the umask of the console, whatever the client asks (the library does not hand the server the attributes of a request to make a directory); a client that wants another mode sets it afterwards. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for the mode 0, which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle open closes it. The mode of a new file is reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set-user-ID, set-group-ID and sticky bits are ignored. A mode that a client sets afterwards (a `chmod` in `sftp`, or the permissions sent for a handle) is applied as given, with no umask. Without `-p`, `scp` sets nothing but the size of the file after an upload, so the mode is the one of the open. With `-p` (preserve) it sends the times together with the permissions in the open request, which is read as carrying none, so the file is created with 0644 (0600 after the umask), and then sets the permissions and the times of the handle after the upload, which are applied as given: a script ends with the mode of its source, 0755. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. +**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode 0755, which is 0700 after the umask of the console, whatever the client asks (the library does not hand the server the attributes of a request to make a directory); a client that wants another mode sets it afterwards. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for the mode 0, which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle open closes it, so an upload of a read-only source that is interrupted ends read-only (0400, say) and resuming it with `put -a` or `reput` is refused with permission denied, as it is by the OpenSSH server. The mode of a new file is reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set-user-ID, set-group-ID and sticky bits are ignored. A mode that a client sets afterwards (a `chmod` in `sftp`, or the permissions sent for a handle) is applied as given, with no umask. Without `-p`, `scp` sets nothing but the size of the file after an upload, so the mode is the one of the open. With `-p` (preserve) it sends the times together with the permissions in the open request, which is read as carrying none, so the file is created with 0644 (0600 after the umask), and then sets the permissions and the times of the handle after the upload, which are applied as given: a script ends with the mode of its source, 0755. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. **The quota and the rate.** The quota is the bytes the home may hold. It counts the sizes of the regular files in it, each inode once (a file with two names counts once): the reports and support bundles tacctl wrote there, `.ssh` and the files the user uploads. Directories, links and inodes do not count, and a sparse file counts its length. A write that would take the home over it is refused whole (`disk quota exceeded`) and audited, and so is a size that would grow a file over it; a smaller size gives the room back. An upload that is refused part way leaves what was written before the refusal in the home (the client does not remove it), and the `sftp` and `scp` of OpenSSH show only `Failure` for it: the reason, `reason=quota`, is in the console's audit log. A file that was deleted while a handle of the session still holds it stays counted until the handle is closed. The home is measured when the session starts and again, when a file is opened for writing, if the last measure is a few seconds old, so the quota is per session: N sessions of one user at once can each use the room that was free when they measured, and bring the home to about N times the quota. A directory in the home that the session cannot read or search (for example one owned by root with mode 0700) makes the home count as full: every upload that grows the home is refused with `disk quota exceeded` until the directory is readable, while reading, deleting and writes that do not grow the home go on. The rate is the bytes a second one session may move, reads and writes together, with a burst of one second; a transfer at its rate waits, it is not refused. Both are read when the session starts. diff --git a/internal/sftpd/file.go b/internal/sftpd/file.go index 9c459225..db69ee73 100644 --- a/internal/sftpd/file.go +++ b/internal/sftpd/file.go @@ -179,37 +179,52 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { if err != nil { return nil, err } + if s.afterOpen != nil { + s.afterOpen() + } var st unix.Stat_t if err := unix.Fstat(fd, &st); err != nil { _ = unix.Close(fd) return nil, t.pathErr("stat", err) } + // st.Mode is what the kernel made of the mode and the umask, with the + // owner's write bit that openNew added; the mode the client asked for is + // that without it, exactly what open(2) would have made, whatever the + // umask is. (A umask that clears the owner's write bit leaves the file as + // the kernel made it, and nothing is restored.) + restoring := created && st.Mode&0o200 != 0 + asked := st.Mode & 0o777 &^ 0o200 + // fail ends an open that created the file and does not hand out the + // handle: the file stays, with the mode the client asked for and not with + // the owner's write bit the open added. + fail := func(err error) (*file, error) { + if restoring { + _ = unix.Fchmod(fd, asked) + } + _ = unix.Close(fd) + return nil, err + } switch st.Mode & unix.S_IFMT { case unix.S_IFREG: // Judged on the open file, so that nothing between a look and the // open can change what it is. Nothing has been truncated yet. if st.Nlink > 1 { - _ = unix.Close(fd) - return nil, errLink() + return fail(errLink()) } case unix.S_IFDIR: - _ = unix.Close(fd) - return nil, &os.PathError{Op: "open", Path: v.String(), Err: unix.EISDIR} + return fail(&os.PathError{Op: "open", Path: v.String(), Err: unix.EISDIR}) default: - _ = unix.Close(fd) - return nil, &statusError{reason: reasonUnsupported, code: sftp.ErrSSHFxOpUnsupported, msg: "not a regular file"} + return fail(&statusError{reason: reasonUnsupported, code: sftp.ErrSSHFxOpUnsupported, msg: "not a regular file"}) } if err := unix.SetNonblock(fd, false); err != nil { - _ = unix.Close(fd) - return nil, t.pathErr("open", err) + return fail(t.pathErr("open", err)) } if write && pf.Trunc { if s.beforeTruncate != nil { s.beforeTruncate() } if err := s.truncate(fd, t); err != nil { - _ = unix.Close(fd) - return nil, err + return fail(err) } } f := &file{ @@ -223,16 +238,9 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { quota: s.quota, rate: s.rate, } - if created { - // st.Mode is what the kernel made of the mode and the umask, with the - // owner's write bit that openNew added; the mode the client asked for - // is that without it, exactly what open(2) would have made, whatever - // the umask is. (A umask that clears the owner's write bit leaves the - // file as the kernel made it, and nothing is restored.) - if st.Mode&0o200 != 0 { - f.restore, f.restoring = st.Mode&0o777&^0o200, true - s.fresh.add(f) - } + if restoring { + f.restore, f.restoring = asked, true + s.fresh.add(f) } if f.quota != nil { f.quota.hold(f) @@ -247,39 +255,46 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { // the client's next steps on the handle are its own (an upload ends with a // size step, a truncate by path, which the kernel refuses on a file its owner // cannot write), and the mode it asked for is set when the handle closes (see -// Close). A client that never closes the handle cleanly leaves the file -// owner-writable; it is the owner's own file, and the session ending closes -// the handles it left open. +// Close). A client that never closes the handle leaves nothing behind: the +// session ending closes the handles it left open (Serve does, see +// TestOpenModeWithoutOwnerWriteSessionEnds). Only a server process that is +// killed leaves the file owner-writable, and it is the owner's own file. // // An existing file is never touched: only a file this open creates is changed // at the close, and the open that creates it is the one whose O_CREAT|O_EXCL // succeeds. When the client did not ask for O_EXCL, the create is tried with it -// first, and an existing file is then opened without O_CREAT (it can be -// removed between the two calls: the create is tried again, a few times). -// Whether the file was created is the kernel's answer, not a look at the file -// afterwards. +// first. If the name exists (EEXIST), the file is opened again with the flags +// and the mode the caller gave, O_CREAT included, which is the open the client +// asked for: the kernel's checks of an open that may create (the sticky +// directory rules of fs.protected_regular and fs.protected_fifos) then apply +// to the existing file as they would without the first call, which an open +// without O_CREAT would skip, and there is no loop to lose a race in. The +// answer of that second call is the answer of the open, and it is "not +// created": whether the file was created is the kernel's answer to the first +// call, not a look at the file afterwards. If the file is created by someone +// else between the two calls, the second call opens it, with nothing to give +// back, and when the second call is the one that creates it (the name was +// removed in the window) the file stays owner-writable, unregistered: the +// client sets its mode itself, as it would for any file. +// +// A second handle on a file that is still waiting for its mode does not keep +// it waiting: when the handle that created the file closes first, the mode the +// client asked for is set and the size step of the other handle is refused. +// The OpenSSH clients do not open a file twice in one upload. func (t *target) openNew(flags int, mode uint32) (fd int, created bool, err error) { if flags&unix.O_EXCL != 0 { fd, err = t.open(flags, mode) return fd, err == nil, err } - for range 3 { - fd, err = t.open(flags|unix.O_EXCL, mode) - if err == nil { - return fd, true, nil - } - if !errors.Is(err, unix.EEXIST) { - return -1, false, err - } - fd, err = t.open(flags&^unix.O_CREAT, 0) - if err == nil { - return fd, false, nil - } - if !errors.Is(err, unix.ENOENT) { - return -1, false, err - } + fd, err = t.open(flags|unix.O_EXCL, mode) + if err == nil { + return fd, true, nil + } + if !errors.Is(err, unix.EEXIST) { + return -1, false, err } - return -1, false, err + fd, err = t.open(flags, mode) + return fd, false, err } // truncate empties the open file fd and takes the size it had off the usage. diff --git a/internal/sftpd/handlers.go b/internal/sftpd/handlers.go index e9d9a3a3..9d6e8888 100644 --- a/internal/sftpd/handlers.go +++ b/internal/sftpd/handlers.go @@ -23,7 +23,8 @@ type server struct { handles handleCount // the open files and directory listings fresh freshModes // the files created owner-writable, waiting for their mode - beforeTruncate func() // a test's hooks, see seams + afterOpen func() // a test's hooks, see seams + beforeTruncate func() afterPin func() } diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go index ee42ae41..38deb3dc 100644 --- a/internal/sftpd/openmode_test.go +++ b/internal/sftpd/openmode_test.go @@ -593,3 +593,69 @@ func TestOpenModeWithTimesThenSetstat(t *testing.T) { t.Errorf("mtime %d, want %d", fi.ModTime().Unix(), mtime) } } + +// setUmask sets the umask of the process for the test and puts it back when +// the test ends, whatever way it ends. +func setUmask(t *testing.T, m int) { + t.Helper() + old := syscall.Umask(m) + t.Cleanup(func() { syscall.Umask(old) }) +} + +// A client that asks for O_EXCL on a name that exists is told so, as it is for +// any file, and the file is not touched, whatever mode the request asks. +func TestOpenModeWithoutOwnerWriteExclOnExistingFile(t *testing.T) { + setUmask(t, 0o022) + home := newHome(t) + p := filepath.Join(home, "f") + if err := os.WriteFile(p, []byte("old data"), 0o640); err != nil { + t.Fatal(err) + } + if err := os.Chmod(p, 0o640); err != nil { + t.Fatal(err) + } + r := newRawConn(t, home) + const pflags = rawFlagWrite | rawFlagCreat | rawFlagExcl + _, want := r.open("f", pflags, 0, nil) + if want == 0 { + t.Fatal("an exclusive create of an existing file succeeded") + } + for _, mode := range []uint32{0o400, 0o444} { + if h, code := r.open("f", pflags, rawAttrPerm, permAttrs(mode)); h != "" || code != want { + t.Errorf("mode %o: open = %q, status %d, want status %d", mode, h, code, want) + } + } + if got := modeOfFile(t, p); got != 0o640 { + t.Errorf("mode %v, want -rw-r-----", got) + } + if b, err := os.ReadFile(p); err != nil || string(b) != "old data" { + t.Errorf("content %q, %v; want the old data", b, err) + } +} + +// An error after the file was created, before the handle is given out (here a +// file that gained a second name between the open and the check), leaves the +// file with the mode the client asked for, not with the owner's write bit the +// open added. The other such errors (the descriptor that cannot be made +// blocking, the truncation that fails) share the code and cannot be provoked +// from a test. +func TestOpenModeWithoutOwnerWriteFailedOpenRestoresTheMode(t *testing.T) { + setUmask(t, 0o022) + home := newHome(t) + p := filepath.Join(home, "f") + var once sync.Once + var linkErr error + r := newRawConnCfg(t, Config{Home: home}, seams{afterOpen: func() { + once.Do(func() { linkErr = os.Link(p, filepath.Join(home, "g")) }) + }}) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm, permAttrs(0o444)) + if linkErr != nil { + t.Fatal(linkErr) + } + if h != "" || code != fxPermissionDenied { + t.Fatalf("open = %q, status %d, want status %d", h, code, fxPermissionDenied) + } + if got := modeOfFile(t, p); got != 0o444 { + t.Errorf("mode %v, want -r--r--r--", got) + } +} diff --git a/internal/sftpd/sftpd.go b/internal/sftpd/sftpd.go index 4c9ce62f..7c017fb8 100644 --- a/internal/sftpd/sftpd.go +++ b/internal/sftpd/sftpd.go @@ -70,6 +70,9 @@ type seams struct { // test that replaces the sleep does not see it). sleeping func() + // afterOpen, when set, runs in an open after the file is open and before + // it is judged. + afterOpen func() // beforeTruncate, when set, runs in an open that truncates, after the // file is open and judged and before it is cut. beforeTruncate func() @@ -110,7 +113,7 @@ func serve(rw io.ReadWriteCloser, cfg Config, sm seams) error { // newServer builds the state of one session. The home is measured here when // there is a quota, and not at all when there is none. func newServer(h *home, cfg Config, sm seams) *server { - s := &server{home: h, cfg: cfg, handles: handleCount{max: cmp.Or(sm.maxHandles, maxHandles)}, beforeTruncate: sm.beforeTruncate, afterPin: sm.afterPin} + s := &server{home: h, cfg: cfg, handles: handleCount{max: cmp.Or(sm.maxHandles, maxHandles)}, afterOpen: sm.afterOpen, beforeTruncate: sm.beforeTruncate, afterPin: sm.afterPin} if cfg.Quota > 0 { s.quota = newQuota(h, cfg.Quota, sm.now, sm.measureDepth) } diff --git a/man/tacctl.1 b/man/tacctl.1 index fe173a24..9fb57607 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -16497,7 +16497,12 @@ sends for a read\-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle -open closes it. The mode of a new file is reduced by the umask of the console, +open closes it, so an upload of a read\-only source that is interrupted ends +read\-only (0400, say) and resuming it with +.B put \-a +or +.B reput +is refused with permission denied, as it is by the OpenSSH server. The mode of a new file is reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set\-user\-ID, set\-group\-ID and sticky bits are ignored. A mode that a client sets afterwards From 7aa893a6a737ef5804dac8cee0a1411ea1cfac7d Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 20:12:16 -0900 Subject: [PATCH 44/52] sftpd: a chmod made outside the session before the close is kept The close of a file this open created owner-writable put the mode the client asked for back whatever the file had by then, so a chmod made by another session or by the user's shell between the data and the close was overwritten; only a setstat of the same session was remembered. The open now keeps the mode the kernel gave the new file, and the close looks at the descriptor and gives the asked mode only to a file that still has exactly that mode. The setstat of the permissions in the same session still takes the file out of the wait, which also covers one that sets the very mode the file had. The check and the change are two calls, so a chmod between them is lost; the comment says so. The documentation and the changelog say that any change of the permissions before the close is kept. --- CHANGELOG.md | 12 +++++++----- docs/cli/console.md | 2 +- internal/sftpd/file.go | 32 +++++++++++++++++++++++++------- internal/sftpd/openmode_test.go | 22 ++++++++++++++++++++++ man/tacctl.1 | 6 ++++-- 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 520031c0..321f8584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,11 +26,13 @@ current behaviour; this file is where history lives. asked for, reduced by the umask, when the client closes the handle: without `-p`, `scp` ends an upload by setting the size of the file, which the kernel refuses on a file its owner cannot write, so the mode comes - last. A client that sets the permissions itself before it closes the - handle keeps what it set. An upload of a read-only source that is - interrupted ends read-only (0400, say), since the session ends by closing - the handle, and resuming it with `put -a` or `reput` is refused with - permission denied, as it is by the OpenSSH server. A request that carries other attributes + last. A change of the permissions before the close, by the client or by + anything else (a `chmod` in a shell, another session), is kept: the close + gives the mode back only to a file that still has the mode the open gave + it. An upload of a read-only source that is interrupted ends read-only + (0400, say), since the session ends by closing the handle, and resuming it + with `put -a` or `reput` is refused with permission denied, as it is by + the OpenSSH server. A request that carries other attributes together with the permissions (the times that `scp -p` sends) is read as carrying none, and such a file gets 0644, 0600 after the umask, as before; `scp -p` then sets the permissions and the times of the file after the diff --git a/docs/cli/console.md b/docs/cli/console.md index 3c973ae8..9c1f6bed 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -220,7 +220,7 @@ Every form of `console file-transfer` is the superuser's, the reads included (`c **What a user can do.** `sftp alice@tacacs.example.net` and the `scp` of OpenSSH 9 or later (which speaks SFTP unless it is given `-O`) work for an account that has file transfer. `scp -O` (the old protocol), `rsync`, any program and the shell's words are refused, as before, with `the tacctl console does not run programs or shell commands; file transfer is SFTP only (sftp, scp of OpenSSH 9 or later)` (exit 126). For an account that does not have file transfer the subsystem is refused with `file transfer is not enabled for this account; an administrator can switch it on (tacctl console file-transfer)` (exit 126), and so is the subsystem of a user held to a required password change. The console serves the protocol as the logged-in user, with no change of privilege, so the file system's permissions apply as they do in the user's shell. An account that does not have file transfer sees only `Connection closed` from `sftp` and `scp` (sshd does not show the error text of a subsystem; `ssh id`, a command request, does): the reason, `reason=file-transfer` with status 126, is in the console's audit log, and `console show` lists who has file transfer. -**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode 0755, which is 0700 after the umask of the console, whatever the client asks (the library does not hand the server the attributes of a request to make a directory); a client that wants another mode sets it afterwards. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for the mode 0, which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a client that sets the permissions itself in between keeps what it set, and a session that ends with the handle open closes it, so an upload of a read-only source that is interrupted ends read-only (0400, say) and resuming it with `put -a` or `reput` is refused with permission denied, as it is by the OpenSSH server. The mode of a new file is reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set-user-ID, set-group-ID and sticky bits are ignored. A mode that a client sets afterwards (a `chmod` in `sftp`, or the permissions sent for a handle) is applied as given, with no umask. Without `-p`, `scp` sets nothing but the size of the file after an upload, so the mode is the one of the open. With `-p` (preserve) it sends the times together with the permissions in the open request, which is read as carrying none, so the file is created with 0644 (0600 after the umask), and then sets the permissions and the times of the handle after the upload, which are applied as given: a script ends with the mode of its source, 0755. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. +**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode 0755, which is 0700 after the umask of the console, whatever the client asks (the library does not hand the server the attributes of a request to make a directory); a client that wants another mode sets it afterwards. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for the mode 0, which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a change of the permissions before the close, by the client or by anything else (a `chmod` in a shell, another session), is kept, and a session that ends with the handle open closes it, so an upload of a read-only source that is interrupted ends read-only (0400, say) and resuming it with `put -a` or `reput` is refused with permission denied, as it is by the OpenSSH server. The mode of a new file is reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set-user-ID, set-group-ID and sticky bits are ignored. A mode that a client sets afterwards (a `chmod` in `sftp`, or the permissions sent for a handle) is applied as given, with no umask. Without `-p`, `scp` sets nothing but the size of the file after an upload, so the mode is the one of the open. With `-p` (preserve) it sends the times together with the permissions in the open request, which is read as carrying none, so the file is created with 0644 (0600 after the umask), and then sets the permissions and the times of the handle after the upload, which are applied as given: a script ends with the mode of its source, 0755. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. **The quota and the rate.** The quota is the bytes the home may hold. It counts the sizes of the regular files in it, each inode once (a file with two names counts once): the reports and support bundles tacctl wrote there, `.ssh` and the files the user uploads. Directories, links and inodes do not count, and a sparse file counts its length. A write that would take the home over it is refused whole (`disk quota exceeded`) and audited, and so is a size that would grow a file over it; a smaller size gives the room back. An upload that is refused part way leaves what was written before the refusal in the home (the client does not remove it), and the `sftp` and `scp` of OpenSSH show only `Failure` for it: the reason, `reason=quota`, is in the console's audit log. A file that was deleted while a handle of the session still holds it stays counted until the handle is closed. The home is measured when the session starts and again, when a file is opened for writing, if the last measure is a few seconds old, so the quota is per session: N sessions of one user at once can each use the room that was free when they measured, and bring the home to about N times the quota. A directory in the home that the session cannot read or search (for example one owned by root with mode 0700) makes the home count as full: every upload that grows the home is refused with `disk quota exceeded` until the directory is readable, while reading, deleting and writes that do not grow the home go on. The rate is the bytes a second one session may move, reads and writes together, with a burst of one second; a transfer at its rate waits, it is not refused. Both are read when the session starts. diff --git a/internal/sftpd/file.go b/internal/sftpd/file.go index db69ee73..2aa2076d 100644 --- a/internal/sftpd/file.go +++ b/internal/sftpd/file.go @@ -33,9 +33,11 @@ type file struct { // restore, with restoring, is the mode the file gets when the handle // closes: the open created it, for a mode without the owner's write bit, - // owner-writable (see openNew). Set before the handle is handed out, and - // not changed. + // owner-writable (see openNew). made is the mode the kernel gave it then: + // the file gets restore only while it still has made (see Close). Set + // before the handle is handed out, and not changed. restore uint32 + made uint32 restoring bool mu sync.Mutex @@ -46,7 +48,8 @@ type file struct { // freshModes is the files of the session that the open created owner-writable // and that wait for their mode to be set when the handle closes. A setstat of // the permissions of such a file takes it out: the client has said what it -// wants, and that is not undone at the close. +// wants, and that is not undone at the close. (A change of the permissions +// from elsewhere is told apart at the close, by the mode the file has then.) type freshModes struct { mu sync.Mutex m map[inode]*file @@ -239,7 +242,7 @@ func (s *server) openFile(r *sftp.Request, write bool) (*file, error) { rate: s.rate, } if restoring { - f.restore, f.restoring = asked, true + f.restore, f.made, f.restoring = asked, st.Mode&0o777, true s.fresh.add(f) } if f.quota != nil { @@ -387,6 +390,23 @@ func (f *file) TransferError(err error) { f.mu.Unlock() } +// giveRestoredMode sets the mode the client asked for, on the descriptor (the +// name may have gone elsewhere), if the file still has the mode the open gave +// it. A file whose mode is another was changed by someone else (a chmod of +// another session or of the user's shell) after the open, and that is kept: the +// check and the change are two calls, so a chmod between them is lost, which +// is as narrow as it can be made. +func (f *file) giveRestoredMode() error { + fi, err := f.f.Stat() + if err != nil { + return err + } + if fi.Mode() != os.FileMode(f.made) { + return nil + } + return f.f.Chmod(os.FileMode(f.restore)) +} + // Close closes the file and audits the transfer: an upload for a handle // opened to write (with the bytes written), a download for one that was // read from (with the bytes read). It is safe to call twice. @@ -398,9 +418,7 @@ func (f *file) Close() error { } var merr error if f.restoring && f.s.fresh.take(f) { - // The mode the client asked for, on the descriptor (the name may - // have gone elsewhere), before it is closed. - merr = f.f.Chmod(os.FileMode(f.restore)) + merr = f.giveRestoredMode() } cerr = f.f.Close() if cerr == nil { diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go index 38deb3dc..3c1f8b8c 100644 --- a/internal/sftpd/openmode_test.go +++ b/internal/sftpd/openmode_test.go @@ -659,3 +659,25 @@ func TestOpenModeWithoutOwnerWriteFailedOpenRestoresTheMode(t *testing.T) { t.Errorf("mode %v, want -r--r--r--", got) } } + +// A change of the permissions made outside the handle (another session, the +// user's shell) between the data and the close is kept: the close puts the mode +// asked for back only on a file that still has the mode the open gave it. +func TestOpenModeWithoutOwnerWriteChmodElsewhereWins(t *testing.T) { + setUmask(t, 0o077) + home := newHome(t) + p := filepath.Join(home, "f") + r := newRawConn(t, home) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm, permAttrs(0o444)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + r.writeAt(h, "data") + if err := os.Chmod(p, 0o640); err != nil { + t.Fatal(err) + } + r.closeHandle(h) + if got := modeOfFile(t, p); got != 0o640 { + t.Errorf("mode %v, want -rw-r-----", got) + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index 9fb57607..e2ba897a 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -16495,8 +16495,10 @@ write bit (0444, which .B scp sends for a read\-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that -the size step an upload ends with works; a client that sets the permissions -itself in between keeps what it set, and a session that ends with the handle +the size step an upload ends with works; a change of the permissions before the +close, by the client or by anything else (a +.B chmod +in a shell, another session), is kept, and a session that ends with the handle open closes it, so an upload of a read\-only source that is interrupted ends read\-only (0400, say) and resuming it with .B put \-a From 82d5f6c7350a2677132f9c21ec9fe18274942b0a Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 20:16:09 -0900 Subject: [PATCH 45/52] sftpd: a request with only file type bits asks for no mode, and tests for the gaps of the open mode openMode tested the raw value against zero, so a value that holds only file type bits (0100000) counted as asking for the mode 0000: the file was created 0200 and ended 0000. The permission bits are now tested, so such a value, like a value of zero, asks for nothing and the new file gets the default mode. The documentation and the changelog say "no permission bits". Tests: the table of the request mode has the cases of file type bits and of special bits only (they fail without the change). TestOpenModeWithoutOwnerWriteExistingFile set the umask in a loop and put it back without defer, so a failure left the process at 077; it uses a subtest per case and a helper that restores the umask when the test ends. A check of the quota test that reduced to "status is 0" says so. New tests: a directory, a symbolic link and a FIFO at the name are refused as with any other mode and left as they were; a umask that clears the owner's write bit makes the file and the close changes nothing; an fsetstat of the times alone does not cancel the restore; a file renamed before the close gets the mode, and the old name stays empty. --- CHANGELOG.md | 8 +- docs/cli/console.md | 2 +- internal/sftpd/file.go | 13 +- internal/sftpd/openmode_test.go | 204 ++++++++++++++++++++++++++++---- man/tacctl.1 | 5 +- 5 files changed, 195 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 321f8584..ffbc477b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,10 +17,10 @@ current behaviour; this file is where history lives. sticky are ignored), reduced by the umask of the console, 077. The owner's bits survive and the group and other bits go: a script asked at 0755 is 0700, a file asked at 0644 is 0600. A request without - permissions, or that asks for the mode 0 (a block of four bytes of zero - is also what a request with no attributes but the extended ones looks - like), still gives 0644, 0600 after the umask. A file that already - exists keeps its mode, and a download changes nothing. A file asked at a + permissions, or that asks for no permission bits (the mode 0, with or + without file type bits; a block of four bytes of zero is also what a + request with no attributes but the extended ones looks like), still gives + 0644, 0600 after the umask. A file that already exists keeps its mode, and a download changes nothing. A file asked at a mode without the owner's write bit (0444, or 0555, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced by the umask, when the client closes the handle: diff --git a/docs/cli/console.md b/docs/cli/console.md index 9c1f6bed..cb8a5367 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -220,7 +220,7 @@ Every form of `console file-transfer` is the superuser's, the reads included (`c **What a user can do.** `sftp alice@tacacs.example.net` and the `scp` of OpenSSH 9 or later (which speaks SFTP unless it is given `-O`) work for an account that has file transfer. `scp -O` (the old protocol), `rsync`, any program and the shell's words are refused, as before, with `the tacctl console does not run programs or shell commands; file transfer is SFTP only (sftp, scp of OpenSSH 9 or later)` (exit 126). For an account that does not have file transfer the subsystem is refused with `file transfer is not enabled for this account; an administrator can switch it on (tacctl console file-transfer)` (exit 126), and so is the subsystem of a user held to a required password change. The console serves the protocol as the logged-in user, with no change of privilege, so the file system's permissions apply as they do in the user's shell. An account that does not have file transfer sees only `Connection closed` from `sftp` and `scp` (sshd does not show the error text of a subsystem; `ssh id`, a command request, does): the reason, `reason=file-transfer` with status 126, is in the console's audit log, and `console show` lists who has file transfer. -**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode 0755, which is 0700 after the umask of the console, whatever the client asks (the library does not hand the server the attributes of a request to make a directory); a client that wants another mode sets it afterwards. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for the mode 0, which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a change of the permissions before the close, by the client or by anything else (a `chmod` in a shell, another session), is kept, and a session that ends with the handle open closes it, so an upload of a read-only source that is interrupted ends read-only (0400, say) and resuming it with `put -a` or `reput` is refused with permission denied, as it is by the OpenSSH server. The mode of a new file is reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set-user-ID, set-group-ID and sticky bits are ignored. A mode that a client sets afterwards (a `chmod` in `sftp`, or the permissions sent for a handle) is applied as given, with no umask. Without `-p`, `scp` sets nothing but the size of the file after an upload, so the mode is the one of the open. With `-p` (preserve) it sends the times together with the permissions in the open request, which is read as carrying none, so the file is created with 0644 (0600 after the umask), and then sets the permissions and the times of the handle after the upload, which are applied as given: a script ends with the mode of its source, 0755. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. +**The root is the home.** The user's home directory, as the account database names it and never `$HOME`, is `/` for the client: a relative path starts there, and `..` does not climb out of it. `.ssh` is invisible (a listing does not show it) and every request for it, by any spelling, is refused; so is the request that would change the home directory itself. A symbolic link is never followed, and neither a symbolic link nor a hard link can be created through the console (the request is refused). A file that already has more than one name (a hard link made outside SFTP, for example in a shell with `ln`) cannot be opened, downloaded or written, and its mode and times cannot be changed (refused, reason `link`); it can still be listed, renamed and removed, since that acts on the name and not on the data. Setting the mode of a directory without the owner's read and search bits is refused too. The size of a regular file can be set (cut, or extended with zeros), which is what `scp` does after an upload to give the file its final size; it counts against the quota like a write (see below). The owner cannot be changed, and a request that asks for it is refused whole. A new directory gets the mode 0755, which is 0700 after the umask of the console, whatever the client asks (the library does not hand the server the attributes of a request to make a directory); a client that wants another mode sets it afterwards. A new file gets the mode the client asks for in the request that opens it, when that request carries the permissions alone (which is what the `sftp` and the `scp` of OpenSSH send), and 0644 otherwise (a request that carries other attributes with the permissions is read as carrying none, and so is one that asks for no permission bits (the mode 0, with or without file type bits), which cannot be told from a request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which `scp` sends for a read-only source) is created writable by its owner and gets the mode asked for, reduced the same way, when the client closes the handle, so that the size step an upload ends with works; a change of the permissions before the close, by the client or by anything else (a `chmod` in a shell, another session), is kept, and a session that ends with the handle open closes it, so an upload of a read-only source that is interrupted ends read-only (0400, say) and resuming it with `put -a` or `reput` is refused with permission denied, as it is by the OpenSSH server. The mode of a new file is reduced by the umask of the console, 077: the owner's bits survive and the group and other bits go, so a script uploaded with mode 0755 is 0700 and one with 0644 is 0600. The set-user-ID, set-group-ID and sticky bits are ignored. A mode that a client sets afterwards (a `chmod` in `sftp`, or the permissions sent for a handle) is applied as given, with no umask. Without `-p`, `scp` sets nothing but the size of the file after an upload, so the mode is the one of the open. With `-p` (preserve) it sends the times together with the permissions in the open request, which is read as carrying none, so the file is created with 0644 (0600 after the umask), and then sets the permissions and the times of the handle after the upload, which are applied as given: a script ends with the mode of its source, 0755. Changing the mode or the times of a file goes through `/proc/self/fd`, so file transfer needs `/proc` mounted on the server. A listing comes in the order of the file system, not sorted (the `sftp` client of OpenSSH sorts what its `ls` prints itself). A session has at most 256 files and directory listings open at once; an open past that fails and is audited (reason `too-many-open-files`). The reports (`device reports`) and the support bundles of the user are in the home, so a user can fetch them with `scp alice@tacacs.example.net:reports/devices/inventory-20261106.csv .`. **The quota and the rate.** The quota is the bytes the home may hold. It counts the sizes of the regular files in it, each inode once (a file with two names counts once): the reports and support bundles tacctl wrote there, `.ssh` and the files the user uploads. Directories, links and inodes do not count, and a sparse file counts its length. A write that would take the home over it is refused whole (`disk quota exceeded`) and audited, and so is a size that would grow a file over it; a smaller size gives the room back. An upload that is refused part way leaves what was written before the refusal in the home (the client does not remove it), and the `sftp` and `scp` of OpenSSH show only `Failure` for it: the reason, `reason=quota`, is in the console's audit log. A file that was deleted while a handle of the session still holds it stays counted until the handle is closed. The home is measured when the session starts and again, when a file is opened for writing, if the last measure is a few seconds old, so the quota is per session: N sessions of one user at once can each use the room that was free when they measured, and bring the home to about N times the quota. A directory in the home that the session cannot read or search (for example one owned by root with mode 0700) makes the home count as full: every upload that grows the home is refused with `disk quota exceeded` until the directory is readable, while reading, deleting and writes that do not grow the home go on. The rate is the bytes a second one session may move, reads and writes together, with a burst of one second; a transfer at its rate waits, it is not refused. Both are read when the session starts. diff --git a/internal/sftpd/file.go b/internal/sftpd/file.go index 2aa2076d..aadec841 100644 --- a/internal/sftpd/file.go +++ b/internal/sftpd/file.go @@ -100,9 +100,10 @@ func permBits(m uint32) uint32 { return m & 0o777 } // permissions: it is what the OpenSSH sftp and scp clients send, without a // size, owner or times. It is not always so: a version 3 block that holds only // the flag of the extended attributes and a count of none is four bytes of -// zero too, and would read as the mode 0000. A value of zero is therefore -// read as asking for nothing (a client that really asks for 0000 gets the -// default, and can set the mode afterwards). Any other length could be the +// zero too, and would read as the mode 0000. A value without any permission +// bit (zero, or only file type bits, which permBits drops) is therefore read +// as asking for nothing (a client that really asks for 0000 gets the default, +// and can set the mode afterwards). Any other length could be the // permissions together with a size, an owner or times, in an order that // cannot be told apart, so it asks for nothing and the new file gets the // default mode, as before. @@ -110,11 +111,11 @@ func openMode(r *sftp.Request) (uint32, bool) { if len(r.Attrs) != 4 { return 0, false } - v := binary.BigEndian.Uint32(r.Attrs) - if v == 0 { + m := permBits(binary.BigEndian.Uint32(r.Attrs)) + if m == 0 { return 0, false } - return permBits(v), true + return m, true } // openFile opens the file of r. write says the open is for an upload (the diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go index 3c1f8b8c..bf4f3aa3 100644 --- a/internal/sftpd/openmode_test.go +++ b/internal/sftpd/openmode_test.go @@ -3,6 +3,7 @@ package sftpd import ( "encoding/binary" "errors" + "fmt" "io" "net" "os" @@ -220,6 +221,11 @@ func TestOpenModeOfTheRequest(t *testing.T) { {"create and exclusive", 0o022, rawFlagWrite | rawFlagCreat | rawFlagExcl, rawAttrPerm, permAttrs(0o755), 0, 0o755}, {"mode 0 asks for nothing: 0644 under umask 022", 0o022, creatTrunc, rawAttrPerm, permAttrs(0), 0, 0o644}, {"mode 0 asks for nothing: 0600 under the console umask", 0o077, creatTrunc, rawAttrPerm, permAttrs(0), 0, 0o600}, + {"only file type bits ask for nothing: 0644 under umask 022", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o100000), 0, 0o644}, + {"only file type bits ask for nothing: 0600 under the console umask", 0o077, creatTrunc, rawAttrPerm, permAttrs(0o100000), 0, 0o600}, + {"all file type bits ask for nothing: 0644 under umask 022", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o170000), 0, 0o644}, + {"all file type bits ask for nothing: 0600 under the console umask", 0o077, creatTrunc, rawAttrPerm, permAttrs(0o170000), 0, 0o600}, + {"only special bits ask for nothing: 0644 under umask 022", 0o022, creatTrunc, rawAttrPerm, permAttrs(0o7000), 0, 0o644}, {"extended attributes without any: 0644 under umask 022", 0o022, creatTrunc, rawAttrExtended, permAttrs(0), 0, 0o644}, {"extended attributes without any: 0600 under the console umask", 0o077, creatTrunc, rawAttrExtended, permAttrs(0), 0, 0o600}, {"permissions with times are not read", 0o022, creatTrunc, rawAttrPerm | times, twelve, 0, 0o644}, @@ -396,29 +402,30 @@ func TestOpenModeWithoutOwnerWriteExistingFile(t *testing.T) { rawFlagWrite | rawFlagCreat, rawFlagRead | rawFlagWrite | rawFlagCreat, } { - old := syscall.Umask(0o077) - home := newHome(t) - p := filepath.Join(home, "f") - if err := os.WriteFile(p, []byte("old data"), 0o600); err != nil { - t.Fatal(err) - } - if err := os.Chmod(p, 0o640); err != nil { - t.Fatal(err) - } - r := newRawConn(t, home) - h, code := r.open("f", pflags, rawAttrPerm, permAttrs(0o400)) - if h == "" { - t.Fatalf("pflags %#x: open refused: status %d", pflags, code) - } - r.writeAt(h, "new") - if c := r.fsetstat(h, rawAttrSize, sizeAttrs(3)); c != 0 { - t.Errorf("pflags %#x: fsetstat of the size: status %d", pflags, c) - } - r.closeHandle(h) - syscall.Umask(old) - if got := modeOfFile(t, p); got != 0o640 { - t.Errorf("pflags %#x: mode %v, want -rw-r-----", pflags, got) - } + t.Run(fmt.Sprintf("pflags %#x", pflags), func(t *testing.T) { + setUmask(t, 0o077) + home := newHome(t) + p := filepath.Join(home, "f") + if err := os.WriteFile(p, []byte("old data"), 0o600); err != nil { + t.Fatal(err) + } + if err := os.Chmod(p, 0o640); err != nil { + t.Fatal(err) + } + r := newRawConn(t, home) + h, code := r.open("f", pflags, rawAttrPerm, permAttrs(0o400)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + r.writeAt(h, "new") + if c := r.fsetstat(h, rawAttrSize, sizeAttrs(3)); c != 0 { + t.Errorf("fsetstat of the size: status %d", c) + } + r.closeHandle(h) + if got := modeOfFile(t, p); got != 0o640 { + t.Errorf("mode %v, want -rw-r-----", got) + } + }) } } @@ -485,7 +492,7 @@ func TestOpenModeWithoutOwnerWriteQuotaAndAudit(t *testing.T) { t.Fatalf("open refused: status %d", code) } r.writeAt(h, "12345") - if c := r.fsetstat(h, rawAttrSize, sizeAttrs(100)); c != fxFailure && c != fxPermissionDenied && c == 0 { + if c := r.fsetstat(h, rawAttrSize, sizeAttrs(100)); c == 0 { t.Errorf("a size over the quota: status %d, want a refusal", c) } if c := r.fsetstat(h, rawAttrSize, sizeAttrs(5)); c != 0 { @@ -681,3 +688,152 @@ func TestOpenModeWithoutOwnerWriteChmodElsewhereWins(t *testing.T) { t.Errorf("mode %v, want -rw-r-----", got) } } + +// A name that is a directory, a symbolic link or a FIFO is refused with a +// mode without the owner's write bit exactly as with any other mode, and what +// is at the name is not changed. +func TestOpenModeWithoutOwnerWriteNotARegularFile(t *testing.T) { + setUmask(t, 0o022) + tests := []struct { + name string + make func(t *testing.T, home string) + check func(t *testing.T, p string) + }{ + {"directory", func(t *testing.T, home string) { + if err := os.Mkdir(filepath.Join(home, "f"), 0o750); err != nil { + t.Fatal(err) + } + }, func(t *testing.T, p string) { + if got := modeOfFile(t, p); got != 0o750|os.ModeDir { + t.Errorf("mode %v, want drwxr-x---", got) + } + }}, + {"symbolic link", func(t *testing.T, home string) { + if err := os.WriteFile(filepath.Join(home, "target"), []byte("old"), 0o640); err != nil { + t.Fatal(err) + } + if err := os.Chmod(filepath.Join(home, "target"), 0o640); err != nil { + t.Fatal(err) + } + if err := os.Symlink("target", filepath.Join(home, "f")); err != nil { + t.Fatal(err) + } + }, func(t *testing.T, p string) { + if got := modeOfFile(t, filepath.Join(filepath.Dir(p), "target")); got != 0o640 { + t.Errorf("mode of the target %v, want -rw-r-----", got) + } + if fi, err := os.Lstat(p); err != nil || fi.Mode()&os.ModeSymlink == 0 { + t.Errorf("the link is gone or changed: %v, %v", fi, err) + } + }}, + {"FIFO", func(t *testing.T, home string) { + if err := syscall.Mkfifo(filepath.Join(home, "f"), 0o640); err != nil { + t.Fatal(err) + } + if err := os.Chmod(filepath.Join(home, "f"), 0o640); err != nil { + t.Fatal(err) + } + }, func(t *testing.T, p string) { + if got := modeOfFile(t, p); got != 0o640|os.ModeNamedPipe { + t.Errorf("mode %v, want prw-r-----", got) + } + }}, + } + for _, tc := range tests { + for _, pflags := range []uint32{rawFlagWrite | rawFlagCreat | rawFlagTrunc, rawFlagRead | rawFlagWrite | rawFlagCreat} { + t.Run(fmt.Sprintf("%s %#x", tc.name, pflags), func(t *testing.T) { + home := newHome(t) + tc.make(t, home) + r := newRawConn(t, home) + _, want := r.open("f", pflags, 0, nil) // the answer without a mode in the request + if want == 0 { + t.Fatal("the open without a mode succeeded") + } + for _, mode := range []uint32{0o400, 0o444} { + if h, code := r.open("f", pflags, rawAttrPerm, permAttrs(mode)); h != "" || code != want { + t.Errorf("mode %o: open = %q, status %d, want status %d", mode, h, code, want) + } + } + tc.check(t, filepath.Join(home, "f")) + }) + } + } +} + +// A umask that clears the owner's write bit leaves the new file as the kernel +// made it: the file is created, and the close changes nothing. +func TestOpenModeWithoutOwnerWriteUmaskClearsOwnerWrite(t *testing.T) { + home := newHome(t) // before the umask: the test's directories need the owner's write bit + setUmask(t, 0o277) + p := filepath.Join(home, "f") + r := newRawConn(t, home) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm, permAttrs(0o444)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + if got := modeOfFile(t, p); got != 0o400 { + t.Errorf("mode after the open %v, want -r--------", got) + } + r.writeAt(h, "data") + r.closeHandle(h) + if got := modeOfFile(t, p); got != 0o400 { + t.Errorf("mode after the close %v, want -r--------", got) + } + if b, err := os.ReadFile(p); err != nil || string(b) != "data" { + t.Errorf("content %q, %v; want data", b, err) + } +} + +// An fsetstat of the times alone does not say anything about the permissions: +// the close still gives the mode asked for. +func TestOpenModeWithoutOwnerWriteTimesOnlyKeepsTheRestore(t *testing.T) { + setUmask(t, 0o022) + home := newHome(t) + p := filepath.Join(home, "f") + const mtime = 1_700_000_000 + times := binary.BigEndian.AppendUint32(binary.BigEndian.AppendUint32(nil, mtime), mtime) + r := newRawConn(t, home) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm, permAttrs(0o444)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + r.writeAt(h, "data") + if c := r.fsetstat(h, rawAttrTimes, times); c != 0 { + t.Fatalf("fsetstat of the times: status %d", c) + } + r.closeHandle(h) + fi, err := os.Stat(p) + if err != nil { + t.Fatal(err) + } + if fi.Mode() != 0o444 { + t.Errorf("mode %v, want -r--r--r--", fi.Mode()) + } + if fi.ModTime().Unix() != mtime { + t.Errorf("mtime %d, want %d", fi.ModTime().Unix(), mtime) + } +} + +// The mode is given to the descriptor, not to the name: a file renamed before +// the close gets it, and nothing is left at the old name. +func TestOpenModeWithoutOwnerWriteRenamedBeforeClose(t *testing.T) { + setUmask(t, 0o022) + home := newHome(t) + p, moved := filepath.Join(home, "f"), filepath.Join(home, "g") + r := newRawConn(t, home) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm, permAttrs(0o444)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + r.writeAt(h, "data") + if err := os.Rename(p, moved); err != nil { + t.Fatal(err) + } + r.closeHandle(h) + if got := modeOfFile(t, moved); got != 0o444 { + t.Errorf("mode of the renamed file %v, want -r--r--r--", got) + } + if _, err := os.Lstat(p); err == nil { + t.Error("a file is at the old name") + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index e2ba897a..6b7da46e 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -16487,8 +16487,9 @@ carries the permissions alone (which is what the OpenSSH and .B scp send), and 0644 otherwise (a request that carries other attributes with the -permissions is read as carrying none, and so is one that asks for the mode 0, -which cannot be told from a request with no attributes but the extended ones); +permissions is read as carrying none, and so is one that asks for no permission +bits (the mode 0, with or without file type bits), which cannot be told from a +request with no attributes but the extended ones); a file that already exists keeps its mode, whatever the open asks. A new file asked at a mode without the owner's write bit (0444, which From 6299f4df9829bcfedcf9516e49fe8df228974a04 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 19:25:14 -0900 Subject: [PATCH 46/52] diff runner: make the bcrypt salt deterministic with bcrypt 5.x The runner's sitecustomize makes Python's bcrypt salt deterministic by replacing os.urandom. bcrypt 5.x makes the salt inside its Rust module and no longer calls os.urandom, so the shim did nothing there and the self-test failed ("bash against bash reports a difference") on a host with bcrypt 5.0. The sitecustomize now also replaces bcrypt.gensalt by a function that builds the salt from the shimmed os.urandom(16) the way bcrypt 4.x did (prefix, two-digit rounds, the 16 bytes in bcrypt's base64 without padding), so the bytes-to-salt result is unchanged for the old kind. The replacement is installed by an import hook on the first import of bcrypt: a python3 that never uses bcrypt, or a host without it, pays nothing and cannot fail on it. --- tests/diff/run.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/diff/run.sh b/tests/diff/run.sh index 3d6a4a3c..1d2d8467 100755 --- a/tests/diff/run.sh +++ b/tests/diff/run.sh @@ -194,6 +194,12 @@ test_hash="243262243130246161616161616161616161616161616161616161616161616161616 # first byte in every process: the same rule as the Go knob (each Rand() of # app.Knobs starts at the first byte), so a generated hash is the same on # both sides when the Go code takes its salt from the knob's source. +# bcrypt 4.x and older call os.urandom(16) in gensalt; 5.x makes the salt +# inside its Rust module and never calls it, so the same sitecustomize also +# replaces bcrypt.gensalt by a function that builds the salt from +# os.urandom(16) the way the old one did. It does so from an import hook, on +# the first import of bcrypt, so a python3 that never uses bcrypt (and a host +# without it) pays nothing. mkdir -p "${work}/pysite" cat > "${work}/pysite/sitecustomize.py" <<'PY' import os @@ -212,6 +218,58 @@ def _urandom(n): os.urandom = _urandom + +# gensalt of bcrypt before 5.0: "$" prefix "$" two-digit rounds "$" and the 16 +# bytes in bcrypt's base64 (22 characters, no padding). +_B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" +_BCRYPT64 = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + + +def _gensalt(rounds=12, prefix=b"2b"): + import base64 + + if prefix not in (b"2a", b"2b"): + raise ValueError("Invalid prefix") + if not 4 <= rounds <= 31: + raise ValueError("Invalid rounds") + enc = base64.b64encode(os.urandom(16)).decode("ascii").rstrip("=") + enc = enc.translate(str.maketrans(_B64, _BCRYPT64)) + return b"$" + prefix + b"$" + ("%02d" % rounds).encode("ascii") + b"$" + enc.encode("ascii") + + +def _patch(module): + module.gensalt = _gensalt + + +class _BcryptHook: + # Wraps the loader of the first "import bcrypt" so that the module is + # patched right after it runs; never fails the import itself. + def find_spec(self, name, path=None, target=None): + if name != "bcrypt": + return None + import sys + + try: + sys.meta_path.remove(self) + import importlib.util + + spec = importlib.util.find_spec(name) + if spec is not None and spec.loader is not None: + run = spec.loader.exec_module + + def exec_module(module): + run(module) + _patch(module) + + spec.loader.exec_module = exec_module + return spec + except Exception: + return None + + +import sys + +sys.meta_path.insert(0, _BcryptHook()) PY # --- stubs ----------------------------------------------------------------------- From 572e968baabfc34ab3bcb4d4659259261fbe6bb5 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 21:02:40 -0900 Subject: [PATCH 47/52] config validate: a user with upper case and over 32 characters gets one finding The case finding proposed the lower-case spelling for every user with upper case, also for one whose name is over 32 characters. That spelling is over the limit too, so 'user rename' refuses it: config validate printed two Names: warnings with contradicting fixes, and --fix-names offered the refused rename and failed every run (exit 1). caseFindings now leaves a user over names.UsernameMax to lengthFindings, whose warning names the rename and says when the name also has upper case letters. --fix-names offers nothing for the user, counts nothing as failed and exits as for a store with no fixable names. Tests: a user that is both, through config validate text, --json and --fix-names. The config page, the man page and the CHANGELOG item say so. --- CHANGELOG.md | 10 +++++-- docs/cli/config.md | 8 +++++- internal/cli/name_case.go | 21 +++++++++++--- internal/cli/user_length_test.go | 48 ++++++++++++++++++++++++++++++++ man/tacctl.1 | 4 ++- 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75c5a61b..caba2b0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,8 +93,14 @@ current behaviour; this file is where history lives. Linux account, here or on a host (tacctl user rename aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )`. It is a warning, never an error, and `config validate --json` has it under the section `names`; - `--fix-names` does not offer it, since there is no name to propose. The - superuser's view only. `docs/cli/config.md` and the manual page say so. + `--fix-names` does not offer it, since there is no name to propose. A + user whose name is also in upper case gets this one warning, not a second + one that proposes the lower-case spelling (also over 32 characters, so + `user rename` would refuse it): it reads `has a name of 40 characters and + has upper case letters; new user names are at most 32 and lower case, and + this user has no Linux account, here or on a host`, and `--fix-names` + offers nothing for the user and exits as for a store with no fixable + names. The superuser's view only. `docs/cli/config.md` and the manual page say so. 5. **`tacctl ssh --login ` logs in as one of the device's own accounts.** In the tacctl console the words after `--` are the remote diff --git a/docs/cli/config.md b/docs/cli/config.md index ad79606f..42d46a80 100644 --- a/docs/cli/config.md +++ b/docs/cli/config.md @@ -92,7 +92,9 @@ config validate [--json | --fix-names [--yes]] an earlier release whose name is longer than 32 characters (a new name is at most 32, see cli/user.md) gets a `Names:` warning too: it works but has no Linux account, here or on a host, and the warning names `tacctl user rename `; `--fix-names` does not - offer that rename, since it has no name to propose. Exits 1 on + offer that rename, since it has no name to propose. A user whose name is both longer than 32 + characters and has upper case gets that one warning only, which says so (the lower-case + spelling is longer than 32 characters too, and `user rename` refuses it). Exits 1 on errors. The verb takes no argument: a word other than its options is refused (`Unknown argument`) and no report is printed. `--json` prints the findings as one JSON object and nothing else on standard output (the schema is below); the exit status is the same. @@ -371,6 +373,10 @@ leftover under the new name, the scope) after this one. The findings are read again after each rename, so a scope that a host rename carried is not offered twice. +A user whose name is longer than 32 characters is not offered, whatever its case: +its lower-case spelling would be refused by `user rename` too, and the `Names:` warning for +its length names the rename (it is counted neither as not offered nor as failed). + A name whose lower-case spelling is another name's (`Alice` beside `alice`, two hosts equal ignoring case, a device and a host that are one name) is not offered. One line says so: diff --git a/internal/cli/name_case.go b/internal/cli/name_case.go index 59908852..c90d4244 100644 --- a/internal/cli/name_case.go +++ b/internal/cli/name_case.go @@ -14,7 +14,8 @@ import ( ) // caseFindings are the names of devices, hosts, users and scopes with upper -// case, each with its fix, in that order and sorted within a kind. Only the +// case, each with its fix, in that order and sorted within a kind (a user over +// names.UsernameMax is left to lengthFindings). Only the // superuser's view has them (a restricted caller is told nothing: what they // would name is not theirs). A fix names the lower-case spelling, or // when another name of the namespace is equal to it ignoring case. @@ -84,6 +85,12 @@ func (inv *invocation) caseFindings() []hostFinding { lowers[strings.ToLower(n)]++ } for _, n := range set.all { + // A user over names.UsernameMax is not offered the lower-case + // spelling, which is over the limit too and which 'user + // rename' refuses: lengthFindings names the rename for it. + if set.kind == "user" && len(n) > names.UsernameMax { + continue + } if names.HasUpper(n) { out = append(out, hostFinding{ Text: "the " + set.kind + " '" + n + "' has upper case in its name; new names are lower case" + set.note, @@ -102,7 +109,9 @@ func (inv *invocation) caseFindings() []hostFinding { // 'user rename'): each keeps working but has no Linux account, here or on a // host. They are warnings in 'config validate' with the verb that renames the // user, sorted by name, the superuser's view only. They carry no Kind, so -// 'config validate --fix-names' (case findings only) does not read them. +// 'config validate --fix-names' (case findings only) does not read them. A user +// that also has upper case gets this one finding, which says so: the rename it +// names is the one that fixes both. func (inv *invocation) lengthFindings() []hostFinding { if inv.callerScopes().restricted { return nil @@ -120,9 +129,13 @@ func (inv *invocation) lengthFindings() []hostFinding { sort.Strings(long) var out []hostFinding for _, n := range long { + also, andLower := "", "" + if names.HasUpper(n) { + also, andLower = " and has upper case letters", " and lower case" + } out = append(out, hostFinding{ - Text: "the user '" + n + "' has a name of " + strconv.Itoa(len(n)) + " characters; new user names are at most " + - strconv.Itoa(names.UsernameMax) + ", and this user has no Linux account, here or on a host", + Text: "the user '" + n + "' has a name of " + strconv.Itoa(len(n)) + " characters" + also + "; new user names are at most " + + strconv.Itoa(names.UsernameMax) + andLower + ", and this user has no Linux account, here or on a host", Fix: "tacctl user rename " + n + " ", }) } diff --git a/internal/cli/user_length_test.go b/internal/cli/user_length_test.go index 13d4282a..f71fb277 100644 --- a/internal/cli/user_length_test.go +++ b/internal/cli/user_length_test.go @@ -111,3 +111,51 @@ func TestBackupRestoreKeepsAnOverLongUser(t *testing.T) { sb.run("", []string{"user", "show", long}) sb.expect(0, long, "") } + +// A user whose name has upper case and is over the limit gets one finding, the +// rename that fixes the length (the lower-case spelling would be over the +// limit too, and 'user rename' refuses it), and it says the name also has +// upper case. 'config validate --fix-names' offers nothing for it and ends as +// for a store with no fixable names. +func TestOverLongNameWithUpperCaseIsOneFinding(t *testing.T) { + long := "A" + strings.Repeat("a", 39) + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " "+long+":") + sb.run("", []string{"config", "render"}) + sb.expect(0, "", "") + + sb.run("", []string{"config", "validate"}) + out := plain(sb.out.String()) + if n := strings.Count(out, "'"+long+"'"); n != 1 { + t.Errorf("%d findings name the user, want 1:\n%s", n, out) + } + if strings.Contains(out, "has upper case in its name") || strings.Contains(out, "rename "+long+" "+strings.ToLower(long)) { + t.Errorf("the lower-case rename is proposed:\n%s", out) + } + want := "the user '" + long + "' has a name of 40 characters and has upper case letters; new user names are at most 32 and lower case, and this user has no Linux account, here or on a host (tacctl user rename " + long + " )" + if !strings.Contains(out, want) { + t.Errorf("config validate lacks %q:\n%s", want, out) + } + + v := validateJSONOf(t, sb.run("", []string{"config", "validate", "--json"})) + var names []validateFinding + for _, f := range v.Findings { + if f.Section == "names" { + names = append(names, f) + } + } + if len(names) != 1 || names[0].Fix != "tacctl user rename "+long+" " || names[0].Kind != "" { + t.Errorf("the json names findings: %+v", names) + } + + before := sb.store() + snaps := len(sb.snapshotDirs()) + sb.run("", []string{"config", "validate", "--fix-names", "--yes"}) + sb.expect(0, "Names: renamed 0, declined 0, not offered 0, failed 0.", "") + if sb.store() != before || len(sb.snapshotDirs()) != snaps { + t.Error("--fix-names changed something") + } + if strings.Contains(sb.printed(), "Rename user") { + t.Errorf("a rename was offered:\n%s", sb.printed()) + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index 0a943da6..3e354e0c 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -3221,7 +3221,9 @@ most 32) is a warning under too: it works but has no Linux account, here or on a host, and the warning names .BR "tacctl user rename" " name " new\-name ; .B \-\-fix\-names -does not offer that rename. Only the superuser's view has these findings. +does not offer that rename. A user whose name is both longer than 32 characters +and has upper case gets that one warning only, which says so. Only the +superuser's view has these findings. .IP Then, for every enabled backend, whether its rendered config is up to date with the store and whether any of its files was edited by hand (drift). With From 06c839db836f5fa75e625bcff90489da0d82b538 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 21:06:09 -0900 Subject: [PATCH 48/52] docs: a session can log in as a device's local account, and login= is not the last field The pages and comments that say a session logs in as you and never as another login now add 'or, with --login, the device's local account': the session section of the man page, connecting.md, walkthroughs.md, host-key-pinning.md and the package comment of the session code. The two session log lines were said to end with login=, but from= and console= follow it. The man page, connecting.md, walkthroughs.md, device.md and CHANGELOG item 5 now say that the lines carry it after the device and address fields, with from= and console= after. The man page writes the tier of the refusal as , as the CHANGELOG does, and CHANGELOG item 5 lists console.md and conventions.md among the pages it changed. --- CHANGELOG.md | 8 +++++--- docs/cli/device.md | 7 ++++--- docs/devices/connecting.md | 4 ++-- docs/devices/walkthroughs.md | 4 ++-- docs/security/host-key-pinning.md | 2 +- internal/cli/ssh.go | 5 +++-- man/tacctl.1 | 18 +++++++++++------- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index caba2b0d..834c5486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -124,12 +124,14 @@ current behaviour; this file is where history lives. it, and the password cache of the shell and the console is not used for the line (it is not asked, filled or told to forget, not even when ssh ends with status 255, and the shell gives the line no token). The session's - `ssh user= device= addr=` and `ssh end` lines end with `login=` - (and have no `password=` field); a plain session's lines are unchanged. The + `ssh user= device= addr=` and `ssh end` lines carry `login=` + (after the device and address fields; `from=` and `console=` follow) and + have no `password=` field; a plain session's lines are unchanged. The warning for a device with break-glass held says `you log in as its local account ''` and the session goes on. Help (`tacctl ssh -h`, `help device`), the completion (a `--login` flag with no candidates, as for - the other `--login` verbs), the manual page, `docs/cli/device.md`, + the other `--login` verbs), the manual page, `docs/cli/console.md`, + `docs/cli/conventions.md`, `docs/cli/device.md`, `docs/cli/shell.md`, `docs/devices/connecting.md`, `docs/devices/walkthroughs.md` and `docs/devices/break-glass.md` describe it. diff --git a/docs/cli/device.md b/docs/cli/device.md index ca4c2dce..a5409d8e 100644 --- a/docs/cli/device.md +++ b/docs/cli/device.md @@ -395,9 +395,10 @@ device ssh [--login ] [-p ] [-X|-Y] [-g] key is checked strictly against the pin, as for a plain session); the engineer tier and up, for a device in one of your scopes. The device asks for the account's password itself: tacctl never asks for it, caches it or stores it, and the password cache is not - used for the line. The session's log lines end with `login=` (no password - field). A hold on the device only warns: it is what the account is for. The words after - `--` stay the remote command in the console. + used for the line. The session's log lines carry `login=` (after the device + and address fields; `from=` and `console=` follow; no password field). A hold on the + device only warns: it is what the account is for. The words after `--` stay the remote + command in the console. device client-config diff --git a/docs/devices/connecting.md b/docs/devices/connecting.md index 4997dd25..f8723a53 100644 --- a/docs/devices/connecting.md +++ b/docs/devices/connecting.md @@ -23,8 +23,8 @@ tacctl ssh core-sw1 --login admin # as the device's local account admin **The configuration syntax.** A Cisco device is walked through and compared in one of two syntaxes: `modern` (`tacacs server NAME` / `address ipv4`, IOS 15.2 and later, 16.x, 17.x and IOS-XE) or `ios12` (`tacacs-server host`, the IOS 12.x template). It is independent of the ssh algorithms: a router of IOS 15.6 or IOS-XE 16.7 may need `--legacy-ssh` and still speak the modern syntax. `tacctl device ios-syntax [auto|ios12|modern]` sets it (no word prints it; `device add --ios-syntax` sets it on registering; `auto`, the default, is not written to the file). With `auto` the syntax comes from the version line the last `device config pull` read (`show version | include Version`: `Version 12.` is `ios12`; `Version 15.2` to `15.9`, `16.`, `17.` and `IOS-XE` are `modern`; any other line, such as IOS 11.x, IOS 15.0 and 15.1, an ASA registered as cisco or IOS XR, is **unknown, never guessed**: the pull is refused with the command to set `ios12` or `modern`, so a setting is how those devices are compared); a device not pulled yet is walked through in the modern syntax with a line that says so, and `device config list` calls it `pull` (`needs pull (syntax unknown)`) until it is pulled once. A setting that contradicts the image the last pull read (`modern` on a device that says IOS 12.4: the lock-out direction) is **not refused, the setting wins, and it is shown**: `device config pull` (text and `--json`: `syntax_conflict`), `device show`, `device config list` and the walkthrough each say it. A pull refused because its version was not read or is not mapped is not recorded, so `device config list` is unchanged; the pull's output says why. See [Device configuration](configuration.md#device-configuration). **The device's own name.** With SNMP set up (`tacctl config snmp`), `device add` also reads the device's `sysName.0` (and its `sysLocation.0`, which it stores as the device's location) and says what the device calls itself; a name that is not the one given (or its `--hostname`, or the first label of either) is a warning with the fixes, and the add goes ahead. `tacctl device add
` with no name offers the sysName, lowercased, at a terminal. See [The SNMP name hint](snmp-name-hint.md#the-snmp-name-hint). 2. **Who may connect.** An active tacctl user (in the store, not disabled) whose scopes include the device's scope, at every tier, superusers included. A local account that is not a tacctl user, a disabled user and a device in no configured scope are refused, and each refusal is logged to syslog (`ssh DENY`). A read-only or operator user (a member of `tac-users` with the [tiers file](../security/tiers.md#tiered-access) installed) may run `tacctl ssh` and sees only the devices of its own scopes. -3. **How it logs in.** ssh runs as you, never as root, and logs in with your own username and your tacctl password (which the device checks against this server): no agent, no key, no other login. Run it from your own account; as root it refuses. It needs a terminal. - **As a local account of the device.** `--login ` logs in as one of the device's own accounts instead of as you (`ssh -l `): the way in to a device whose break-glass is [held](break-glass.md), which takes local accounts only, and the way to log in as another account in the console, where the words after `--` are the remote command and ssh's own `-l` is refused. It is for registered devices of any vendor (an enrolled host is refused, since hosts are reached as you) with a pinned host key (without one it is refused with the `device hostkey` command that pins it: a local password goes only to a device whose key was verified), for engineers and up, and only for a device in one of your scopes, as for every ssh. The device asks for the account's password at its own prompt: tacctl never asks for it, caches it or stores it, it is the engineer's, and the [password cache](../cli/shell.md#password-cache) is not used for the line. The session's log lines end with `login=`. +3. **How it logs in.** ssh runs as you, never as root, and logs in with your own username (or, with `--login`, the device's local account, below) and your tacctl password (which the device checks against this server): no agent, no key, no other login. Run it from your own account; as root it refuses. It needs a terminal. + **As a local account of the device.** `--login ` logs in as one of the device's own accounts instead of as you (`ssh -l `): the way in to a device whose break-glass is [held](break-glass.md), which takes local accounts only, and the way to log in as another account in the console, where the words after `--` are the remote command and ssh's own `-l` is refused. It is for registered devices of any vendor (an enrolled host is refused, since hosts are reached as you) with a pinned host key (without one it is refused with the `device hostkey` command that pins it: a local password goes only to a device whose key was verified), for engineers and up, and only for a device in one of your scopes, as for every ssh. The device asks for the account's password at its own prompt: tacctl never asks for it, caches it or stores it, it is the engineer's, and the [password cache](../cli/shell.md#password-cache) is not used for the line. The session's log lines carry `login=` (after the device and address fields; `from=` and `console=` follow). 4. **Plain `ssh`.** `tacctl device client-config > ~/.ssh/tacctl.conf` and `Include ~/.ssh/tacctl.conf` at the top of `~/.ssh/config` give a plain `ssh core-sw1` (and `scp`) the same options and the same pin. The fragment has one `Host` block per device you may see and no `User` line, so ssh logs in with your local username: a tacctl user whose local account has another name adds `User ` to its own `~/.ssh/config`. Re-run it after the registry changes. 5. **A key that changed.** When a device was replaced or reset, ssh is refused and tacctl prints the pinned and offered fingerprints and the console command that shows the key. After verifying on the console, an administrator re-pins with `tacctl device hostkey core-sw1 accept` (or `set SHA256:`). diff --git a/docs/devices/walkthroughs.md b/docs/devices/walkthroughs.md index 7b41d48e..f0269829 100644 --- a/docs/devices/walkthroughs.md +++ b/docs/devices/walkthroughs.md @@ -21,7 +21,7 @@ **Host keys.** `device add` reads the keys the device offers (`ssh-keyscan -T 5 -p -t ed25519,ecdsa,rsa
`, as root; `legacy-ssh` devices are asked for `ssh-rsa` by name too; a device that accepts the connection but gives no key to that, because it limits the simultaneous connections `ssh-keyscan` opens per key type or drops its long offer, is asked again one key type at a time, `-t ed25519`, then `ecdsa`, `rsa` (and `ssh-rsa`), each with `-T 3`, and every key that answers is pinned; a device whose name `ssh-keyscan` reports as not resolving is not asked again; `ssh-keyscan` cannot do the SHA-1 key exchange and CBC ciphers a `legacy-ssh` device needs, so for a `legacy-ssh` device that it reads nothing from, for any device that accepted the connection but gave no key even one type at a time, and for a device it reads nothing from and prints nothing about (a server slow to greet, which plain `ssh` waits longer for, or a refused or filtered address; no one-type retry then, and a 3-second connect), tacctl's built-in ssh client reads the keys instead, stopping at the host key, before authentication, so no password is sent; it starts with ed25519 alone and the library's short algorithm offer, the legacy algorithms only when that reads nothing), pins them in `devices.yaml` and prints each `SHA256:` fingerprint with the command that shows it on the device console (Cisco `show ip ssh`, Junos `file show /etc/ssh/ssh_host_ed25519_key.pub` from the CLI, or `ssh-keygen -lf` on the same file from `start shell`, Linux `ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub`); compare them before connecting (`tacctl device hostkey show` prints each pinned key as an `ssh-ed25519 AAAA…` line as well, so a `file show` output can be compared by eye). A device that does not answer either read is refused unless `--no-host-key` is given. `host enroll` and `host sync` pin an enrolled host's keys the first time from two independent reads: the host's own public key files (`cat /etc/ssh/ssh_host_*_key.pub`, read-only, over the enrolment's ssh connection, which your own ssh checked against your known_hosts) and an `ssh-keyscan` of the target. Only keys both reads hold are pinned; a key type they disagree on refuses the pin (both sets are shown and `host hostkey-mismatch` is logged), a type only one of them has is reported and not pinned, and key files that cannot be read pin nothing. The enrolment or sync succeeds either way. A sync of a pinned host compares the session's keys with the pin, reports a difference and keeps the pin. The same connection gives the host's address: enroll and sync record the address the connection reached (the host's side of `SSH_CONNECTION`; `--local` records 127.0.0.1) in `devices.yaml`'s `hosts:` section, and warn when it differs from what the target's name resolves to. `device add` and `device address` refuse that address, `device show
` finds the host, sightings from it are the host's, and `device discover` does not list it; a sync that finds another address records it and raises `address-changed`. Only `device hostkey accept|set` changes a pin. Every registry write regenerates `/var/lib/tacctl/ssh/known_hosts` (0644), one ` ` line per pinned key, for `ssh -o UserKnownHostsFile=/var/lib/tacctl/ssh/known_hosts -o GlobalKnownHostsFile=none -o HostKeyAlias= -o StrictHostKeyChecking=yes`. -**`tacctl ssh `** opens an ssh session to a registered device or an enrolled host, as you: the name is resolved as root (the registry is root's), and only an active tacctl user (in the store, not disabled) whose scopes include the entry's may connect, at every tier, superusers included (`'jdoe' has no access to scope 'prod' (device core-sw1)`; a local account that is not a tacctl user, and an entry in no configured scope, are refused to everyone; each refusal is logged as `ssh DENY … reason=`). The session is logged (`ssh user= device= addr=
from=`, syslog auth.info; `from=` is omitted when it cannot be told), and ssh runs as the invoking user (`sudo -u -H ssh …`), logging in as you by password: your tacctl password, checked by the device against this server; no agent, no key, no other login. An enrolled host's enrolment account and identity are never used. Its exit status is passed back. `-X`/`-Y` forward X11 to this server's display (the `DISPLAY` of an `ssh -X` login here, which sudo keeps for tacctl), and `-L`, `-R` and `-D` (repeatable) are ssh's port forwardings; the log line then carries `forward=x11,local,…`. In the login console they are for the tiers of `console forwarding tiers` only (default superuser; others get `ssh DENY … reason=forward`), and `-L` and `-D` listen on loopback only: `-g` and a bind address other than loopback (`0.0.0.0:8443:localhost:443`, `*:1080`, or an empty one, which ssh binds on every address even without `-g`) are refused (`ssh DENY … reason=gateway`) unless `console forwarding gateway-ports` is enabled. Run as root itself it refuses (`tacctl ssh runs ssh as the user who invoked it; run it from your own account, not as root`); it needs a terminal. An unregistered address is refused with the `device add` command that registers it. The options per device: +**`tacctl ssh `** opens an ssh session to a registered device or an enrolled host, as you: the name is resolved as root (the registry is root's), and only an active tacctl user (in the store, not disabled) whose scopes include the entry's may connect, at every tier, superusers included (`'jdoe' has no access to scope 'prod' (device core-sw1)`; a local account that is not a tacctl user, and an entry in no configured scope, are refused to everyone; each refusal is logged as `ssh DENY … reason=`). The session is logged (`ssh user= device= addr=
from=`, syslog auth.info; `from=` is omitted when it cannot be told), and ssh runs as the invoking user (`sudo -u -H ssh …`), logging in as you (or, with `--login`, as the device's local account) by password: your tacctl password, checked by the device against this server; no agent, no key, no other login. An enrolled host's enrolment account and identity are never used. Its exit status is passed back. `-X`/`-Y` forward X11 to this server's display (the `DISPLAY` of an `ssh -X` login here, which sudo keeps for tacctl), and `-L`, `-R` and `-D` (repeatable) are ssh's port forwardings; the log line then carries `forward=x11,local,…`. In the login console they are for the tiers of `console forwarding tiers` only (default superuser; others get `ssh DENY … reason=forward`), and `-L` and `-D` listen on loopback only: `-g` and a bind address other than loopback (`0.0.0.0:8443:localhost:443`, `*:1080`, or an empty one, which ssh binds on every address even without `-g`) are refused (`ssh DENY … reason=gateway`) unless `console forwarding gateway-ports` is enabled. Run as root itself it refuses (`tacctl ssh runs ssh as the user who invoked it; run it from your own account, not as root`); it needs a terminal. An unregistered address is refused with the `device add` command that registers it. The options per device: | Device | ssh options | |---|---| @@ -31,7 +31,7 @@ | pinned keys | `-o UserKnownHostsFile=/var/lib/tacctl/ssh/known_hosts -o GlobalKnownHostsFile=none -o StrictHostKeyChecking=yes -o HostKeyAlias= -o UpdateHostKeys=no` | | enrolled host | its target's host and its port | -An unpinned device is checked against your own known_hosts, after its `hostkey-unpinned` notice. Arguments after `--` follow the target, so ssh takes them as the remote command (`tacctl ssh core-sw1 -- show version`); they cannot replace an option. Each session is logged when it starts (`ssh user= device= addr=`) and when it ends (`ssh end user= device= status= duration=`). With `--login ` ssh logs in as that local account of the device (`-l `, the password asked by the device, never by tacctl and never cached) and both lines end with `login=` (before `console=`); a registered device with a pinned host key, the engineer tier and up (see [Connecting to devices by name](connecting.md)); a refusal of the entry is logged as `ssh DENY … reason=login-host` or `reason=login-unpinned`. +An unpinned device is checked against your own known_hosts, after its `hostkey-unpinned` notice. Arguments after `--` follow the target, so ssh takes them as the remote command (`tacctl ssh core-sw1 -- show version`); they cannot replace an option. Each session is logged when it starts (`ssh user= device= addr=`) and when it ends (`ssh end user= device= status= duration=`). With `--login ` ssh logs in as that local account of the device (`-l `, the password asked by the device, never by tacctl and never cached) and both lines carry `login=` (after the device and address fields; `from=` and `console=` follow); a registered device with a pinned host key, the engineer tier and up (see [Connecting to devices by name](connecting.md)); a refusal of the entry is logged as `ssh DENY … reason=login-host` or `reason=login-unpinned`. From a login console session (each of its lines carries `TACCTL_CONSOLE=`), `tacctl ssh` reads no ssh configuration file and opens nothing but the session: it adds `-F /dev/null -o PermitLocalCommand=no -o ControlMaster=no -o ClearAllForwardings=yes -o ForwardAgent=no`, `-o EscapeChar=none` unless `tacctl console ssh-escape enable`, and puts the target after `--`, so the words after the name's `--` are only ever the remote command (a first word starting with `-` is refused). A device or host with no pinned host key is refused: `'' has no pinned host key, so the console does not connect to it; an administrator pins it: tacctl device hostkey accept`. Its log lines end with `console=`. When ssh fails with 255 on a pinned device whose key changed, tacctl prints the pinned and offered fingerprints, the console command that shows the key, and `tacctl device hostkey accept|set`. diff --git a/docs/security/host-key-pinning.md b/docs/security/host-key-pinning.md index c21ab975..b89c2a43 100644 --- a/docs/security/host-key-pinning.md +++ b/docs/security/host-key-pinning.md @@ -9,4 +9,4 @@ - **Enrolled hosts** are not pinned from a scan alone: `host enroll` and `host sync` read the host's own `/etc/ssh/ssh_host_*_key.pub` over the enrolment's authenticated ssh connection and pin only the keys an `ssh-keyscan` of the target holds too (asked one key type at a time when the combined scan gives no key, as for a device; a host that still gives none is named in the warning with the reads that were made). A key type on which the two reads disagree pins nothing and is logged (`host hostkey-mismatch`). - **No silent change.** Only `tacctl device hostkey accept|set` (administrators, after verifying on the console) changes a pin; it is logged to syslog. A scan that finds a different key raises a `hostkey-changed` notice that cannot be acknowledged away, and ssh refuses the connection to that device, after which `tacctl ssh` prints the pinned and offered fingerprints. - **How it reaches ssh.** tacctl writes `/var/lib/tacctl/ssh/known_hosts` (0644, root-owned, in a 0755 directory: the registry itself is root's alone) from the pins on every registry write, and runs ssh with `UserKnownHostsFile` on it, `GlobalKnownHostsFile=none`, `StrictHostKeyChecking=yes`, `HostKeyAlias=` and `UpdateHostKeys=no`. User-supplied ssh arguments come after those options and cannot replace them. `tacctl device client-config` gives plain `ssh` the same options. -- **Passwords only.** Sessions never use an agent, a key or another login: `PubkeyAuthentication=no`, the login is the caller's own name, and only an active tacctl user with a scope that includes the device's may connect, whatever the tier. +- **Passwords only.** Sessions never use an agent, a key or another login: `PubkeyAuthentication=no`, the login is the caller's own name (or, with `tacctl ssh --login`, the device's local account), and only an active tacctl user with a scope that includes the device's may connect, whatever the tier. diff --git a/internal/cli/ssh.go b/internal/cli/ssh.go index 8fa89eb8..9a67d3b1 100644 --- a/internal/cli/ssh.go +++ b/internal/cli/ssh.go @@ -7,7 +7,8 @@ package cli // resolves the name, admits only an active tacctl user whose scopes hold // the entry's (every tier, superusers included), logs the session, and runs // ssh as SUDO_USER with the terminal, logging in as SUDO_USER by password -// (no agent, no key, no other login), returning ssh's exit status. The +// (no agent, no key, no other login; or, with --login, the device's local +// account), returning ssh's exit status. The // shell and the console run the same line ('sudo -n tacctl ssh '), so // there is one path to audit. 'device ssh' is the same command. // @@ -39,7 +40,7 @@ package cli // instead of the caller: '-l ', the password asked by the device // itself. The password cache is not used for such a line (never read, never // asked, never told to forget; the shell leaves it shut, askpassWords), and -// the log lines carry login=. +// the log lines carry login= (before from= and console=). import ( "context" diff --git a/man/tacctl.1 b/man/tacctl.1 index 3e354e0c..71cb3ff1 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -14715,8 +14715,10 @@ or the host of the terminal's login record) and, when ssh ends, as runs as the invoking user .RB ( "sudo \-u " "\fIuser\fR " \-H ), with the terminal, returning its exit status. The login is always the invoking -user's own name and the session authenticates by password only: no agent, no -key, no other login; an enrolled host's enrolment account and identity are +user's own name (or, with +.BR \-\-login , +the device's local account named there) and the session authenticates by +password only: no agent, no key, no other login; an enrolled host's enrolment account and identity are never used. It never runs ssh as root: run by root itself (no .BR SUDO_USER , or @@ -14895,18 +14897,20 @@ hosts are reached as the user), and only for a device with a pinned host key .RI ( "has no pinned host key, and a local password goes only to a device whose key was verified" ; the key is checked strictly against the pin, as for a plain session), for the engineer tier and up -.RI ( "'tacctl device ssh \-\-login' is not permitted for the tier tier" ), +.RI ( "'tacctl device ssh \-\-login' is not permitted for the tier" ), and for a device in one of the caller's scopes, as for every ssh. A refusal of the entry is logged .RB ( "ssh DENY ... reason=login\-host" " or " "reason=login\-unpinned" ). The device asks for the account's password at its own prompt: tacctl never asks for it, caches it or stores it, it is the engineer's, and the password cache is neither asked, filled nor told to forget for the line (the shell -leaves it shut). The two log lines end with +leaves it shut). The two log lines carry .BI login= local\-user -(before -.BR console= ), -and have no +(after the device and address fields; +.B from= +and +.B console= +follow), and have no .B password= field. The warning for a held device then says the local account is what is used. From 3cf97dd2511ae2937135a455d7d609d355636078 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 21:19:05 -0900 Subject: [PATCH 49/52] device usage and man page: --login of the ssh verbs is listed and its tier is told 'tacctl device' and 'help device' listed every option of the ssh row but --login. The row is there now, with an '(ssh)' opening: a bare text would be picked by the help of 'device collect --login' (which has no option line of its own and takes the shared line of onboard), since the line of onboard names two verbs and loses to a line that names none. A test pins both the row and the unchanged text of collect's flag. The Requires lines of the manual page for ssh and device ssh said only readonly, but --login needs the engineer tier. The gate sees both as readonly rows (ssh is an AnySub row, whose note key has no sub-verb), so the sentence is added to the notes the cli reads (tierNotes), which the generated Requires lines, the TIERS list and the help of the device family use; the generator trims the key of an AnySub row. The sentence belongs on the rows of tier.Rules, as every other note does. The help of ssh spells the value of --login as , as the flag does, and the comment of localLoginLine says the check also serves ssh, device ssh and device collect. --- CHANGELOG.md | 5 +++- internal/cli/device.go | 1 + internal/cli/man_gen_test.go | 7 +++-- internal/cli/password_cache.go | 5 ++-- internal/cli/shell_view.go | 17 ++++++++++-- internal/cli/ssh.go | 16 +++++------ internal/cli/ssh_login_test.go | 50 ++++++++++++++++++++++++++++++++++ man/tacctl.1 | 10 +++++-- 8 files changed, 93 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 834c5486..8b8b0d05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,7 +129,10 @@ current behaviour; this file is where history lives. have no `password=` field; a plain session's lines are unchanged. The warning for a device with break-glass held says `you log in as its local account ''` and the session goes on. Help (`tacctl ssh -h`, - `help device`), the completion (a `--login` flag with no candidates, as for + `tacctl device` and `help device`, which now list `--login ` + under `ssh` as they list its other options), the tier lines of `ssh` and + `device ssh` in the manual page (a session as you is every tier's, + `--login` needs the engineer tier), the completion (a `--login` flag with no candidates, as for the other `--login` verbs), the manual page, `docs/cli/console.md`, `docs/cli/conventions.md`, `docs/cli/device.md`, `docs/cli/shell.md`, `docs/devices/connecting.md`, diff --git a/internal/cli/device.go b/internal/cli/device.go index bcab7ad3..63e39a99 100644 --- a/internal/cli/device.go +++ b/internal/cli/device.go @@ -328,6 +328,7 @@ var deviceOptions = map[string][][2]string{ {"--against", "(block check) Plan the device with the text in force and print its section's statements"}, }, "ssh": { + {"--login ", "(ssh) Log in as this local account of the device, not as you (engineer and up)"}, {"-p ", "Connect to this port (default: the device's port, else 22)"}, {"-X, -Y", "Forward X11 (untrusted, trusted) to this server's display"}, {"-L ", "Forward a local port, as ssh -L (repeatable)"}, diff --git a/internal/cli/man_gen_test.go b/internal/cli/man_gen_test.go index 73202bd7..fed6fab1 100644 --- a/internal/cli/man_gen_test.go +++ b/internal/cli/man_gen_test.go @@ -116,8 +116,9 @@ func manTiersBlock() manBlock { l = append(l, ".PP", "The gate sees two words, so a verb that the code splits further is listed at its", "two\\-word level and then limited by the code:") for _, k := range slices.Sorted(maps.Keys(tierNotes)) { - note := strings.TrimPrefix(tierNotes[k], k+": ") - l = append(l, ".TP", ".B "+roff(k), roff(upperFirst(note))) + name := strings.TrimSpace(k) // the key of an AnySub row ends with a space + note := strings.TrimPrefix(tierNotes[k], name+": ") + l = append(l, ".TP", ".B "+roff(name), roff(upperFirst(note))) } return manBlock{name: "tiers", lines: l} } @@ -172,7 +173,7 @@ func manCommandBlocks(t *testing.T) []manBlock { l := []string{".RS", ".PP"} req := `Requires: \fB` + string(lowestTier(p[0], sub)) + `\fR.` if note, ok := tierNotes[p[0]+" "+sub]; ok { - req += " " + roff(upperFirst(strings.TrimPrefix(note, p[0]+" "+sub+": "))) + req += " " + roff(upperFirst(strings.TrimPrefix(note, strings.TrimSpace(p[0]+" "+sub)+": "))) } // The gate sees 'device config'; each of its verbs holds its own tier. if need, ok := deviceConfigNeeds[strings.TrimPrefix(words, "device config ")]; ok && len(p) == 3 && p[0] == "device" && p[1] == "config" { diff --git a/internal/cli/password_cache.go b/internal/cli/password_cache.go index 15359d81..606866ea 100644 --- a/internal/cli/password_cache.go +++ b/internal/cli/password_cache.go @@ -313,8 +313,9 @@ func askpassWords(words []string) bool { return false } -// localLoginLine reports whether the words of a 'device config' verb give -// --login before any '--'. +// localLoginLine reports whether the words of a verb that logs in to a device +// (a 'device config' verb, 'ssh' and 'device ssh', 'device collect') give +// --login before any '--': the account is the device's own, not the caller's. func localLoginLine(words []string) bool { for _, w := range words { switch { diff --git a/internal/cli/shell_view.go b/internal/cli/shell_view.go index f6deb5ec..341ca5b5 100644 --- a/internal/cli/shell_view.go +++ b/internal/cli/shell_view.go @@ -187,8 +187,21 @@ func familyTier(root *cobra.Command, path []string) tier.Tier { // tierNotes are the verbs whose sub-verbs the gate cannot tell apart (it // sees two words); the family's help says what the code decides. They are // the Note field of the rows of tier.Rules, so a row and its sentence are -// edited in one place. -var tierNotes = tier.Notes() +// edited in one place. The two ssh rows are the exception for now: --login +// makes their verb two-tiered ("ssh" is an AnySub row, whose key has no +// sub-verb, "ssh "), and their sentences are added here, with the generated +// man page and the family's help reading them as any other note. +var tierNotes = withSSHNotes(tier.Notes()) + +// sshLoginNote is what the gate cannot tell of 'ssh' and 'device ssh': the +// session as you is every tier's, --login needs the engineer tier. +const sshLoginNote = ": a session as you is every tier's; --login (a session as a local account of the device) needs the engineer tier." + +func withSSHNotes(n map[string]string) map[string]string { + n["ssh "] = "ssh" + sshLoginNote + n["device ssh"] = "device ssh" + sshLoginNote + return n +} // tierSection is the part of a family's help that names the tier each of // its verbs needs: the lowest tier whose rows run it, grouped by tier, with diff --git a/internal/cli/ssh.go b/internal/cli/ssh.go index 9a67d3b1..98d0d6d8 100644 --- a/internal/cli/ssh.go +++ b/internal/cli/ssh.go @@ -125,14 +125,14 @@ as for every ssh). The device asks for the account's password itself: tacctl never asks for it, caches it or stores it, and the password cache is not used for the line. - --login Log in as this local account of the device, not as you - -p Connect to this port (default: the device's port, else 22) - -X, -Y Forward X11 (untrusted, trusted) to this server's display - -L Forward a local port, as ssh -L (repeatable) - -R Forward a remote port, as ssh -R (repeatable) - -D Open a SOCKS proxy, as ssh -D (repeatable) - -g Let -L and -D ports listen on every address, as ssh -g - -- Pass the rest to ssh for this session (a remote command) + --login Log in as this local account of the device, not as you + -p Connect to this port (default: the device's port, else 22) + -X, -Y Forward X11 (untrusted, trusted) to this server's display + -L Forward a local port, as ssh -L (repeatable) + -R Forward a remote port, as ssh -R (repeatable) + -D Open a SOCKS proxy, as ssh -D (repeatable) + -g Let -L and -D ports listen on every address, as ssh -g + -- Pass the rest to ssh for this session (a remote command) Only active tacctl users reach a device, and only one in a scope of their own, whatever their tier; a device no scope covers is reached by no one. Every diff --git a/internal/cli/ssh_login_test.go b/internal/cli/ssh_login_test.go index c3211d47..d612eaed 100644 --- a/internal/cli/ssh_login_test.go +++ b/internal/cli/ssh_login_test.go @@ -2,6 +2,8 @@ package cli import ( "context" + "os" + "path/filepath" "slices" "strconv" "strings" @@ -384,3 +386,51 @@ func TestDropAskpassClearsTheProcessValue(t *testing.T) { t.Errorf("kept %q", processAskpass) } } + +// 'tacctl device' lists --login under the ssh row as it lists the other ssh +// options, and the row does not change what '?' says of the --login of +// another verb that has no option line of its own ('device collect --login' +// is described by the shared line of onboard, not by ssh's). +func TestDeviceUsageListsTheSSHLoginOption(t *testing.T) { + sb := newSandbox(t, true) + out := plain(sb.run("", []string{"device"})) + i := strings.Index(out, "\n ssh ") + if i < 0 { + t.Fatalf("no ssh row in the usage:\n%s", out) + } + rest := out[i+1:] + if j := strings.Index(rest, "\n scan"); j > 0 { + rest = rest[:j] + } + if !strings.Contains(rest, "--login ") || !strings.Contains(rest, "(engineer and up)") { + t.Errorf("the ssh row lacks the --login option line:\n%s", rest) + } + + texts := flagTexts(t) + if got := texts["device collect --login"]; !strings.HasPrefix(got, "(onboard, collect;") { + t.Errorf("device collect --login is described as %q", got) + } +} + +// The gate sees 'ssh' and 'device ssh' as readonly rows and --login is the +// engineer's: both verbs carry a tier note, which the manual page's +// Requires line and the TIERS list read; and the help of 'ssh' spells the +// value of --login as the flag's Spec does. +func TestSSHLoginTierNoteAndHelpValue(t *testing.T) { + for _, k := range []string{"ssh ", "device ssh"} { + if n := tierNotes[k]; !strings.Contains(n, "--login") || !strings.Contains(n, "engineer tier") { + t.Errorf("tierNotes[%q] = %q", k, n) + } + } + page, err := os.ReadFile(filepath.Join("..", "..", "man", "tacctl.1")) + if err != nil { + t.Fatal(err) + } + if n := strings.Count(string(page), `Requires: \fBreadonly\fR. A session as you is every tier's; \-\-login`); n != 2 { + t.Errorf("%d Requires lines of the man page name the engineer tier of --login, want 2 (ssh, device ssh)", n) + } + flag := sshSpec.Flags[1] + if flag.Names[0] != "--login" || !strings.Contains(sshUsage(), "--login "+flag.Arg+" ") { + t.Errorf("the help of ssh does not spell the value of --login as %s", flag.Arg) + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index 71cb3ff1..a0117d98 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -11544,7 +11544,7 @@ below. .\" BEGIN GENERATED: command device ssh .RS .PP -Requires: \fBreadonly\fR. +Requires: \fBreadonly\fR. A session as you is every tier's; \-\-login (a session as a local account of the device) needs the engineer tier. .PP Options: .TP @@ -14917,7 +14917,7 @@ used. .\" BEGIN GENERATED: command ssh .RS .PP -Requires: \fBreadonly\fR. +Requires: \fBreadonly\fR. A session as you is every tier's; \-\-login (a session as a local account of the device) needs the engineer tier. .PP Options: .TP @@ -16972,6 +16972,9 @@ The Configuration, Release, Model and Serial rows, the Chassis members table (an .B device snmp An engineer may read the settings of a device of their own scope (show [\-\-reveal []], version, port, timeout, v3\-user list|default, clients list); every setter and clear needs the superuser tier. .TP +.B device ssh +A session as you is every tier's; \-\-login (a session as a local account of the device) needs the engineer tier. +.TP .B host show An engineer reads what tacctl recorded of a host; \-\-check logs in to it and needs the superuser tier. .TP @@ -16989,6 +16992,9 @@ An engineer may read the settings of a scope of their own (show [\-\-reveal [ Date: Mon, 9 Nov 2026 21:22:30 -0900 Subject: [PATCH 50/52] store import notes users over 32 characters; the rollback and upgrade wording is made true store import loaded a legacy user whose name is over 32 characters without a word, while it says so for names with upper case. It now says in one line how many such users it loaded as they are (they have no Linux account; config validate lists them). A test pins the line, the maintenance page, the man page and CHANGELOG item 3 describe it. CHANGELOG item 2 (the rollback to 0.2.28) listed what had moved in 0.2.29 as item 1, a test and the documentation, which stopped being true with the later items. It now says the claim it needs: no change of 0.2.29 writes a stored file in a form 0.2.28 does not read. upgrading.md said both that a name too long with its suffix is cut before it and that the upgrade shortens no name. The upgrade shortens a name only to make room for a suffix (upgrade_dots.go); a name it renames without one keeps its length. The page and the man page say that. --- CHANGELOG.md | 12 ++++++++---- docs/cli/maintenance.md | 2 ++ docs/install/upgrading.md | 2 +- internal/store/import.go | 20 ++++++++++++++++++++ internal/store/import_test.go | 20 ++++++++++++++++++++ man/tacctl.1 | 11 ++++++++--- 6 files changed, 59 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b8b0d05..fd90cf78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,9 +44,9 @@ current behaviour; this file is where history lives. manual page say so. 2. **`tacctl rollback 0.2.28`, the release before this one, is a target.** - This release changed no stored file 0.2.28 reads strictly (the mode a file - uploaded through the console gets, item 1, a test and the documentation are - all that moved), so 0.2.28 reads everything it writes: the rollback + This release changed no stored file 0.2.28 reads strictly: no change of + 0.2.29 writes a stored file in a form 0.2.28 does not read, so 0.2.28 reads + everything it writes: the rollback converts no file, removes no key and no field, takes no snapshot and needs no `--yes`. The file transfer settings of `console.yaml` (`settings.file_transfer`) stay, 0.2.28 has them, and so do the limits of @@ -81,7 +81,11 @@ current behaviour; this file is where history lives. given in full). A name of exactly 32 is accepted. Only the creation paths check it: a user that exists with a longer name keeps working (it is shown, changed, renamed away to a shorter name and removed as before) and - `backup restore` and `tacctl upgrade` carry it unchanged. `docs/cli/user.md`, `docs/install/upgrading.md` and the + `backup restore` and `tacctl upgrade` carry it unchanged; `store import` + loads it as it is too, with one line (`1 user name(s) are longer than 32 + characters and are loaded as they are; new names are at most 32, and such + a user has no Linux account (tacctl config validate lists them).`), as it + says for names with upper case. `docs/cli/user.md`, `docs/install/upgrading.md` and the manual page say so; they no longer say that every user has an account. 4. **`config validate` warns of a user whose name is longer than 32 diff --git a/docs/cli/maintenance.md b/docs/cli/maintenance.md index cab7f11f..41ec677f 100644 --- a/docs/cli/maintenance.md +++ b/docs/cli/maintenance.md @@ -293,6 +293,8 @@ Old-style `tacquito.yaml.` files (made before the store existed, or k `store import` of a rendered `tacquito.yaml` that cut users out of their scopes (a required password change, an emergency lockdown: the users section names them in a `# tacctl-carved reason= protocol= users=` comment) lists each as something the store cannot represent, since the file holds neither the scopes they had nor the requirement, and wants `--force`; `--check` reports them the same way. +Names from before load as they are: one line says how many users and scopes have upper case, and one how many users have a name longer than 32 characters (a new name is at most 32; such a user has no Linux account, and `config validate` lists them). + The scope `tacctl` of a rendered file is the login of the server the file came from, which every user is in: `store import` does not import it and takes it out of the users' scopes, with one line that says so, so a migrated store enrols its own server cleanly (`host enroll --local`). A server that is registered in its own scope `tacctl` keeps it, with its secret and prefixes. A scope of that name that answers other addresses than a server's own login (one or two single-address prefixes, `127.0.0.1` among them) is yours and is imported as it is. `store import`, `backup restore` (a snapshot or an old-style backup) and `store rollback` rewrite the list of users held to a password change in the console's sshd drop-in once they have changed the store (the rollback writes it empty: legacy mode holds nobody), when the drop-in is installed; the list is read under the apply lock and a failure is one warning that names `tacctl console install` ([Login console](../security/login-console.md)). Nothing else that writes the store does this, apart from the verbs that sync this server and the ones that change who is held (`user require-password-change`, `user add`, `remove`, `rename`, `move` and `passwd`, `passwd`, the group commands that lower a tier), which rewrite it themselves. diff --git a/docs/install/upgrading.md b/docs/install/upgrading.md index f11debb7..81954484 100644 --- a/docs/install/upgrading.md +++ b/docs/install/upgrading.md @@ -26,7 +26,7 @@ The upgrade command: **A user name with a period is renamed.** User names are letters, digits, `_` and `-`, and 0.2.20 and 0.2.21 allowed periods; a period cannot be part of a Linux account name. The upgrade renames every such user, replacing each period with `_` (`alice.smith` becomes `alice_smith`), with everything that follows a user name: the store record (group, scopes, email, flags and limits), the user's line in `linux-uids` and the user's settings in `console.yaml` (the system shell, the password cache and the ignored override of the `users` mapping). It takes a snapshot first and names it (`snapshot holds the state before the rename`; `tacctl backup restore ` undoes the rename), and takes none when no user has a period. One line says each rename (`renamed user alice.smith to alice_smith`; when that name is taken, see below), and a note tells you to have the people log in with the new name: the name typed at a device's login changed, and the old one no longer works. A name with a period never had a Linux account, so no account on this server or on a host is renamed; the new name gets its account at the next sync, unless it cannot be a Linux account name (see below). When `linux-uids` has a line for the new name already, the line of the old name is not moved: the new name keeps its UID, the old line stays in the file as it is, and a warning says so (`'alice_smith' already has UID 80007 in linux-uids, so the line of 'alice.smith' (UID 80001) is not moved: 'alice_smith' keeps UID 80007 and the line of 'alice.smith' stays in the file as it is`). A second upgrade does nothing. -If the new name is taken (a user of that name, a second name that becomes the same, or a break-glass local user of one of the user's scopes), the user gets `_` and four random lowercase letters or digits after it, drawn again until the name is free of every user, every other new name and the break-glass users of the user's scopes: `alice.smith` becomes `alice_smith_k3x9`, and the line says so (`renamed user alice.smith to alice_smith_k3x9 (alice_smith was taken)`). Of two names that meet, the first in the store keeps the name without a suffix, and a name that would be longer than a Linux account name (32 characters) is cut before the suffix. Rename the user again afterwards with `tacctl user rename` if you want another name. The rule for the new name is not changed by what a Linux account may be: a new name with upper case letters (`Alice.Smith` becomes `Alice_Smith`) or longer than 32 characters is a user name but no account name (`user add` and `user rename` refuse a new name of more than 32 characters, but the upgrade carries a name it renames and shortens none), so that user gets no account at a sync (and `device reports generate` cannot store a report for them). After the renames the upgrade lists each such user with the reason and the fix (`Alice_Smith has upper case letters: tacctl user rename Alice_Smith `), and its closing note says that the other new names get their accounts, or that none can. Only a name that is not a user name even with the periods replaced (one with a space, say) stops the upgrade, before anything is changed: it names the key to edit under `users:` in the store, and you run `tacctl upgrade` again afterwards. When the release you upgrade from has already replaced `tacctl` and the tacquito build, the message says so: the store, the configuration and the services are not changed. An install that cannot read its store is not held up by this step; the warning says so. +If the new name is taken (a user of that name, a second name that becomes the same, or a break-glass local user of one of the user's scopes), the user gets `_` and four random lowercase letters or digits after it, drawn again until the name is free of every user, every other new name and the break-glass users of the user's scopes: `alice.smith` becomes `alice_smith_k3x9`, and the line says so (`renamed user alice.smith to alice_smith_k3x9 (alice_smith was taken)`). Of two names that meet, the first in the store keeps the name without a suffix, and a name that would be longer than a Linux account name (32 characters) is cut before the suffix. Rename the user again afterwards with `tacctl user rename` if you want another name. The rule for the new name is not changed by what a Linux account may be: a new name with upper case letters (`Alice.Smith` becomes `Alice_Smith`) or longer than 32 characters is a user name but no account name (`user add` and `user rename` refuse a new name of more than 32 characters, but the upgrade shortens a name only to make room for a suffix: a name it renames without one keeps its length, even over 32 characters), so that user gets no account at a sync (and `device reports generate` cannot store a report for them). After the renames the upgrade lists each such user with the reason and the fix (`Alice_Smith has upper case letters: tacctl user rename Alice_Smith `), and its closing note says that the other new names get their accounts, or that none can. Only a name that is not a user name even with the periods replaced (one with a space, say) stops the upgrade, before anything is changed: it names the key to edit under `users:` in the store, and you run `tacctl upgrade` again afterwards. When the release you upgrade from has already replaced `tacctl` and the tacquito build, the message says so: the store, the configuration and the services are not changed. An install that cannot read its store is not held up by this step; the warning says so. The store is renamed before `linux-uids` and `console.yaml` follow, so the upgrade checks both first, before the snapshot and before any write: a `console.yaml` that cannot be read or holds a name the rule refuses (a space, say), or a ledger that cannot be read or locked, stops it with the file and the reason, `No user was renamed.` and `Nothing was changed.`; repair the file and run it again. A key with a period in `console.yaml` that no rename covers (a hand edit, a user who is gone, the `users` mapping) would make the file unreadable, and its settings belong to nobody: the upgrade drops it and says so (`dropped the console settings of 'alice.gone' ...`), also when no user in the store has a period; it is not renamed, because the next user of that name would inherit the system shell or the password cache. If the upgrade stops after the store was written (a crash, a failed write), the renames stay recorded in `upgrade-renames` in the state directory, and the next `tacctl upgrade` finishes the move for those users (`finished the rename of user alice.smith to alice_smith`: the ledger line and the console settings) and removes the file; `tacctl backup restore ` of the snapshot it named is the other way back (a restore forgets the record, since the state it describes is replaced). Until the upgrade has finished the move, `user add`, `user remove` and `user rename` refuse the new name of such a record, and `store import` and the restore of an old-style backup refuse whatever the names, with `The upgrade's rename of user alice.smith to alice_smith is not finished: run 'tacctl upgrade' first. Nothing was changed.`, because the upgrade would otherwise give the ledger line and the console settings of the person it renamed to whoever holds the name by then. The record is emptied before it is removed, so a removal that fails (it says so) does not replay the renames. diff --git a/internal/store/import.go b/internal/store/import.go index e1902367..207f53a0 100644 --- a/internal/store/import.go +++ b/internal/store/import.go @@ -260,6 +260,22 @@ func (s *Store) mixedCaseNote() string { return strings.Join(parts, " and ") + " name(s) have upper case and are loaded as they are; new names are lower case (tacctl config validate lists them)." } +// longNameNote is the one line an import says when users have names longer +// than names.UsernameMax: existing data loads as it is, and only new names are +// checked, so such a user has no Linux account. "" when there are none. +func (s *Store) longNameNote() string { + n := 0 + for _, k := range sortedKeys(s.section("users")) { + if len(k) > names.UsernameMax { + n++ + } + } + if n == 0 { + return "" + } + return fmt.Sprintf("%d user name(s) are longer than %d characters and are loaded as they are; new names are at most %d, and such a user has no Linux account (tacctl config validate lists them).", n, names.UsernameMax, names.UsernameMax) +} + // pyLen is len() of a list (0 for anything else). func pyLen(v any) int { l, _ := v.([]any) @@ -376,6 +392,10 @@ func Import(out ui.Output, opts ImportOptions) error { say("") say(" " + n) } + if n := s.longNameNote(); n != "" { + say("") + say(" " + n) + } if opts.Adjust != nil { note, err := opts.Adjust(s) if err != nil { diff --git a/internal/store/import_test.go b/internal/store/import_test.go index 2591b7c3..a9abc38c 100644 --- a/internal/store/import_test.go +++ b/internal/store/import_test.go @@ -1112,3 +1112,23 @@ func TestImportNotesNamesWithUpperCase(t *testing.T) { contains(t, out, "1 user name(s) have upper case and are loaded as they are; new names are lower case") contains(t, string(readFile(t, e.path)), " Engineer:\n") } + +// A user from before with a name over 32 characters is imported as it is, and +// one line says how many (a new name is at most 32; such a user has no Linux +// account). +func TestImportNotesNamesOverTheLimit(t *testing.T) { + long := strings.Repeat("e", 33) + e := newImportEnv(t) + e.place("legacy.fresh-install.yaml") + out, _ := e.imp("--check") + refute(t, out, "longer than") + + e = newImportEnv(t) + text := string(readFile(t, fixtures+"legacy.fresh-install.yaml")) + text = strings.Replace(text, " - name: engineer\n", " - name: "+long+"\n", 1) + e.write(e.config, text) + out = e.mustImport() + contains(t, out, "1 user name(s) are longer than 32 characters and are loaded as they are; new names are at most 32, and such a user has no Linux account (tacctl config validate lists them).") + refute(t, out, "upper case") + contains(t, string(readFile(t, e.path)), " "+long+":\n") +} diff --git a/man/tacctl.1 b/man/tacctl.1 index a0117d98..514b2212 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -282,8 +282,9 @@ break-glass users of the user's scopes the line reads .BR "renamed user alice.smith to alice_smith_k3x9 (alice_smith was taken)" ). Of two names that meet the first in the store keeps the name without a suffix, -and a name longer than a Linux account name (32 characters) is cut before the -suffix. A new name with upper case letters or longer than 32 characters is a user +and a name that would be longer than a Linux account name (32 characters) with +its suffix is cut before the suffix; the upgrade shortens a name only to make +room for a suffix, so a name renamed without one keeps its length. A new name with upper case letters or longer than 32 characters is a user name but not a Linux account name: the user gets no account at a sync, so after the renames the upgrade lists each such user with the reason and .BR "tacctl user rename" " " , @@ -6730,7 +6731,11 @@ which a rendered or legacy file cannot hold. The scope .B tacctl of a rendered file (the login of the server it came from, which every user is in) is not imported and is taken out of the users' scopes, in one line; a -server registered in its own keeps it. An import that holds users to a +server registered in its own keeps it. Names from before load as they are, +with one line each saying how many users or scopes have upper case and how many +users have a name longer than 32 characters (such a user has no Linux account; +.B config validate +lists them). An import that holds users to a password change rewrites the list of them in the console's sshd drop-in at once (see .BR "console forwarding" ). From b99896f29be4f5772d856834f7524d6d8ccefe99 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 21:38:13 -0900 Subject: [PATCH 51/52] docs: release notes of 0.2.29 docs/release-notes-0.2.29.md tells what the release is, in the form of the 0.2.28 notes: the console keeps the owner's execute bit of an uploaded file, a new user name is at most 32 characters with the config validate warning for longer stored names, tacctl ssh --login , and the rollback to 0.2.28 that converts nothing. Every claim is taken from the CHANGELOG items of 0.2.29 and the pages they name; the CHANGELOG list stays the full record. --- docs/release-notes-0.2.29.md | 124 +++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 docs/release-notes-0.2.29.md diff --git a/docs/release-notes-0.2.29.md b/docs/release-notes-0.2.29.md new file mode 100644 index 00000000..db841728 --- /dev/null +++ b/docs/release-notes-0.2.29.md @@ -0,0 +1,124 @@ +# tacctl 0.2.29 + +0.2.29 is a small release. A file uploaded through the console keeps its owner's execute bit, +a new user name is at most 32 characters and `config validate` warns of the longer names an +earlier release stored, and `tacctl ssh --login ` opens a session as one +of a device's own accounts, which is the way in from the console while break-glass is held. +`tacctl rollback 0.2.28` is a target. The numbered list in `CHANGELOG.md` (0.2.29) is +everything that differs from 0.2.28. + +## File transfer: a script keeps its execute bit + +In 0.2.28 the console gave every new file the mode 0644 and ignored the mode the client asked +for, so a script copied with the `scp` of OpenSSH 9 or later lost its execute bit. + +- **The mode of the open.** A new file now gets the mode the client asks for in the request + that opens it, when that request carries the permissions alone, which is what the OpenSSH + `sftp` and `scp` send. Only the permission bits count (set-user-ID, set-group-ID and sticky + are ignored), reduced by the console's umask, 077: the owner's bits survive and the group + and other bits go. A script asked at 0755 is 0700, a file asked at 0644 is 0600. +- **No mode asked.** A request without permissions, or that asks for no permission bits, + still gives 0644, 0600 after the umask. A file that already exists keeps its mode, and a + download changes nothing. +- **A read-only source.** A file asked at a mode without the owner's write bit (0444, or 0555, + which `scp` sends for a read-only source) is created writable by its owner and gets the mode + asked for, reduced by the umask, when the client closes the handle, since `scp` ends an + upload by setting the size of the file. A change of the permissions before the close (by the + client, a `chmod` in a shell, another session) is kept. An interrupted upload of a read-only + source ends read-only (0400, say), and resuming it with `put -a` or `reput` is refused with + permission denied, as it is by the OpenSSH server. +- **`scp -p`.** It sends the times together with the permissions in the open request, which is + read as carrying none, so the file is created at 0644 (0600). `scp -p` then sets the + permissions and times after the upload, which are applied as given, with no umask, so a + script ends with the mode of its source, 0755. +- **Directories are unchanged.** The library does not deliver the mode of a request to make a + directory, so a new directory is 0755, 0700 after the umask, whatever the client asks; a + client that wants another mode sets it afterwards. + +```bash +scp deploy.sh alice@tacacs.example.net: # 0755 at the source, 0700 in the home +scp -p deploy.sh alice@tacacs.example.net: # the mode of the source, 0755 +``` + +The pages are `docs/cli/console.md` (The root is the home) and the manual page. + +## User names of at most 32 characters + +**A new user name is at most 32 characters**, the longest a Linux account name can be. Before, +`user add` took any length, so a longer name became a tacctl user with no account on the +tacctl server or on a host. `user add` and the new name of `user rename` now refuse a longer +name, change nothing and exit 1: + +```text +Username 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is 33 characters; a user name is at most 32 (the longest a Linux account name can be). +``` + +A name of exactly 32 is accepted. Only a new name is checked: a user an earlier release +stored with a longer name keeps working (it is shown, changed, renamed away to a shorter name +and removed as before), and `backup restore` and `tacctl upgrade` carry it unchanged. It still +has no Linux account, so it gets none at a sync. `store import` loads it as it is and prints +one line that counts such names. Rename it with `tacctl user rename `. + +**`config validate` warns of such a user** under `Names:`, as it does of a name with upper +case, and names the rename that fixes it. It is a warning, never an error; `config validate +--json` has it under `names`, and `--fix-names` does not offer it, since there is no name to +propose. A user whose name is also in upper case gets this one warning only. It is the +superuser's view only. + +The length is not the only reason a user has no account: a name with upper case letters, and a +name that starts with a digit or `-` (`1alice`), which `user add` still accepts, have none +either. The pages are `docs/cli/user.md`, `docs/cli/config.md` and `docs/install/upgrading.md`. + +## A session as a device's local account + +In the console the words after `--` are the remote command and ssh's `-l admin` is refused, and +while break-glass is held on a device only its local accounts work, so there was no way to +open a session as `admin` from the console. `tacctl ssh` (and `tacctl device ssh`, the same +command) now takes `--login `: + +```bash +tacctl ssh sw1 --login admin +``` + +- It runs ssh as you, as before, with `-l ` in place of your name, for registered + devices of any vendor. An enrolled host is refused (hosts are reached as you) and nothing is + started. +- The device must have a pinned host key, since a local password goes only to a device whose + key was verified: without one the line is refused and names `tacctl device hostkey + accept`. With one, ssh checks the key strictly against the pin. +- It needs the engineer tier or above, as the other `--login` verbs do, and the device must be + in one of your scopes. A session as you stays every tier's. The name is letters, digits, + `.`, `_` and `-`. +- The device asks for the account's password at its own prompt. tacctl never asks for it, + caches it or stores it, and the password cache of the shell and the console is not used for + the line. +- The session's `ssh` and `ssh end` audit lines carry `login=` after the device and + address fields and have no `password=` field; a plain session's lines are unchanged. On a + device with break-glass held the warning says `you log in as its local account + ''` and the session goes on. + +The pages are `docs/devices/connecting.md`, `docs/devices/break-glass.md`, `docs/cli/device.md`, +`docs/cli/console.md` and the manual page. + +## Rollback + +**`tacctl rollback 0.2.28`, the release before this one, is a target.** No change of 0.2.29 +writes a stored file in a form 0.2.28 does not read, so the rollback converts no file, removes +no key and no field, takes no snapshot and needs no `--yes`. The file transfer settings of +`console.yaml` stay, as do the report limits, the chassis members of the pull records, the +reports in the users' homes and the per-tier sudoers drop-in. It is refused only while a +device's apply is not settled, and it ends with `tacctl upgrade --branch 0.2.28`, with no +closing note. After that upgrade a new uploaded file is 0644 (0600) again whatever the client +asks; the files uploaded in between keep their mode. `rollback 0.2.27` and older behave as +before, and `tacctl rollback` now takes fifteen targets. + +```bash +tacctl rollback 0.2.28 # the dry run: steps, writes nothing +tacctl rollback 0.2.28 --apply +tacctl upgrade --branch 0.2.28 +``` + +## Upgrading + +`tacctl upgrade` converts nothing in this release. A user whose name is longer than 32 +characters is carried unchanged; `tacctl config validate` lists it. From 3c43b64bd437cd43796a9b1506bcb9057fc954b3 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Mon, 9 Nov 2026 22:53:04 -0900 Subject: [PATCH 52/52] Bumped version number to 0.2.29 --- CHANGELOG.md | 2 +- man/tacctl.1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd90cf78..bb84764a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to tacctl. The README and the manual page describe only the current behaviour; this file is where history lives. -## 0.2.29 (unreleased) +## 0.2.29 (2026-11-09) 1. **A file uploaded through the console keeps the owner's execute bit.** The console's file transfer gave every new file the mode 0644 and ignored the diff --git a/man/tacctl.1 b/man/tacctl.1 index 514b2212..a77b2f82 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -1,6 +1,6 @@ .\" Manual page for tacctl, the management CLI for pluggable network-device AAA. .\" Render locally with: groff -man -Tascii man/tacctl.1 | less -.TH TACCTL 1 "2026-11-09" "tacctl 0.2.28" "tacctl Manual" +.TH TACCTL 1 "2026-11-09" "tacctl 0.2.29" "tacctl Manual" .\" The body margin is 7n on every groff: 1.24 narrowed its default (BP) to 5n, which moves the .\" columns that `tacctl man` searches for. .nr BP 7n