From 1e56e2b361530c98ad2f253acb35484073975835 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 00:02:11 -0900 Subject: [PATCH 01/27] rollback: 0.2.29, the release before this one, is a target Every release ships a rollback target for the release before it. 0.2.30 so far changes no stored file 0.2.29 reads strictly (the only change is a stricter check on the name of a new user, which writes no new form of a file), 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.29 and 0.2.30 write the same text), the pull records, the reports in the users' homes, the marker of the offer of the PDF tools and every user, whatever the name. None of the steps of rollbackAdditions fires for it. 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.29 stops being "not a release to roll back to" in the version refusal and becomes the release before this one; 0.2.28 stays a target and converts nothing. The usage, the completion, the top-level help and its golden file list it, the lists of "every target but" in the code comments, the documentation and the manual page name 0.2.29 beside 0.2.28, and the next steps of the 0.2.28 target are those of 0.2.29. rollbackFrom, the release a snapshot's state is of in the note that follows a rollback, is 0.2.30, and the tests that quote the note say so (TestRollbackFromIsTheReleaseOfTheChangelog passes with the new heading). docs/install/upgrading.md gets a "To 0.2.29" section and says sixteen targets; docs/cli/conventions.md, docs/releasing.md, docs/cli/emergency.md, docs/cli/user.md, docs/devices/reports.md and the manual page list the target; the CHANGELOG has item 1 of 0.2.30. 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.29 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. --- CHANGELOG.md | 32 ++++ docs/cli/conventions.md | 6 +- docs/cli/emergency.md | 2 +- docs/cli/user.md | 6 +- docs/devices/reports.md | 2 +- docs/install/upgrading.md | 76 ++++++---- docs/releasing.md | 6 +- internal/cli/completion_test.go | 2 +- internal/cli/help_text.go | 2 +- internal/cli/rollback.go | 32 ++-- 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 | 6 +- internal/cli/rollback_target0228_test.go | 14 +- internal/cli/rollback_target0229_test.go | 177 +++++++++++++++++++++++ internal/cli/rollback_test.go | 4 +- internal/cli/testdata/usage/top.out | 2 +- internal/lifecycle/rollback.go | 38 +++-- 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 | 8 +- internal/lifecycle/rollback0228.go | 43 +++--- internal/lifecycle/rollback0228_test.go | 9 +- internal/lifecycle/rollback0229.go | 41 ++++++ internal/lifecycle/rollback0229_test.go | 167 +++++++++++++++++++++ internal/lifecycle/rollback_additions.go | 2 +- internal/lifecycle/rollback_email.go | 2 +- internal/lifecycle/rollback_firewall.go | 2 +- internal/lifecycle/rollback_snmp_pool.go | 2 +- internal/lifecycle/rollback_staging.go | 2 +- internal/lifecycle/rollback_test.go | 9 +- internal/tier/report_limits_test.go | 24 ++- man/tacctl.1 | 120 ++++++++++----- tests/integration/rollback.bats | 45 +++++- 42 files changed, 744 insertions(+), 185 deletions(-) create mode 100644 internal/cli/rollback_target0229_test.go create mode 100644 internal/lifecycle/rollback0229.go create mode 100644 internal/lifecycle/rollback0229_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index bb84764a..be66f807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,38 @@ All notable changes to tacctl. The README and the manual page describe only the current behaviour; this file is where history lives. +## 0.2.30 (unreleased) + +1. **`tacctl rollback 0.2.29`, the release before this one, is a target.** + This release changed no stored file 0.2.29 reads strictly (the check of the + name of a new user, item 2, writes no new form of a file, and the + documentation moved), so 0.2.29 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.29 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.29 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, and so does every + user, whatever the name. It is refused only while a device's apply is not + settled. The command ends with `tacctl upgrade --branch 0.2.29` and, + having nothing to avoid, has no closing note. `rollback 0.2.28` and older + behave as before (`0.2.28` still converts nothing, `0.2.27` and older + 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.29. The + top-level help, `docs/cli/conventions.md`, `docs/install/upgrading.md` + (Rolling back, To 0.2.29), `docs/releasing.md`, the manual page and the + completion list the new target, and `tacctl rollback` now takes sixteen + targets. The note that follows a rollback that took a snapshot names this + release, 0.2.30, as the state the snapshot holds ("Restore it with 0.2.30 + only"). + ## 0.2.29 (2026-11-09) 1. **A file uploaded through the console keeps the owner's execute bit.** The diff --git a/docs/cli/conventions.md b/docs/cli/conventions.md index d17c964e..28b096c3 100644 --- a/docs/cli/conventions.md +++ b/docs/cli/conventions.md @@ -42,9 +42,9 @@ tacctl uninstall [--yes] tacctl rollback [--apply] [--yes] [--hosts] - 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, + Prepare the state for the release before this one (0.2.29), 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 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 6a2cb74c..147080cb 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.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 +but the ones to 0.2.29, 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 61fdaa7e..6d5d194c 100644 --- a/docs/cli/user.md +++ b/docs/cli/user.md @@ -177,7 +177,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`, `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 +(0.2.25 and older; `rollback 0.2.26`, `rollback 0.2.27`, `rollback 0.2.28` and `rollback 0.2.29` 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)). ``` @@ -219,7 +219,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.28, 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.29, 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)). @@ -363,7 +363,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.28 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.29 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 3293d8a2..5044d822 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`, `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). +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`, `tacctl rollback 0.2.28` and `tacctl rollback 0.2.29` keep them: all four 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 to 0.2.29 read it as it is). ## Exit status diff --git a/docs/install/upgrading.md b/docs/install/upgrading.md index 81954484..813398e4 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 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 +`tacctl rollback` takes sixteen targets: `0.2.29`, the release before this +one, `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` 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.28`, `0.2.27`, `0.2.26`, `0.2.25`, `0.2.24`, +refuse while an apply is not settled, all but `0.2.29`, `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.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 +lockdown locks a group, all but `0.2.29`, `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.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 break-glass firewall (0.2.24).** Every target but `0.2.29`, `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.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 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.29`, `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.29`, `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.29`, `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 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. +**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.29` and `0.2.28` (they read 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.30 state, which only 0.2.30 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.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 +needs it there (0.2.21 to 0.2.29 have it themselves), so every target but +`0.2.29`, `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.28`, `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.29`, `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.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 +target but `0.2.29`, `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.28`, `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.29`, `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.28`, `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.29`, `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.28`, `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.29`, `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.28`, `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.29`, `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.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 +one to 0.2.29, 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.28 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.29 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.28 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.29 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.28 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.29 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.28 to 0.2.20 read +its writes fail), so every target before 0.2.20 (0.2.19 and older; 0.2.29 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.28 to 0.2.20 read it +before 0.2.20 refuses. Every target before 0.2.20 (0.2.19 and older; 0.2.29 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.28` to `0.2.20` (which read +'password_change_required'`), so every target but `0.2.29` 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.29 + +0.2.29 reads every file this release writes: this release changed no stored file it reads strictly (the check of the name of a new user, which writes no new form of a file, 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.29 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.29 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, and so does every user, whatever the name: a user whose name starts with a digit, `-` or `_`, or has upper case, is read, listed and kept as before. 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.29 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.29's to undo or keep. After the `tacctl upgrade --branch 0.2.29` that ends the rollback, `user add` and `user rename` take a new name that starts with a digit, `-` or `_`, as they did. The users added in between keep their names. + +```bash +tacctl rollback 0.2.29 # the dry run: steps, writes nothing +tacctl rollback 0.2.29 --apply +tacctl upgrade --branch 0.2.29 # install 0.2.29 +``` + ### 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. +0.2.28 reads every file 0.2.29 and this release write: they changed no stored file it reads strictly (the mode a file uploaded through the console gets, the check of the name of a new user, 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 to 0.2.29 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. +What 0.2.29 and 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, and `user add` and `user rename` take a new name that starts with a digit, `-` or `_`, as they did. The files uploaded and the users added in between keep the mode and the name they got. ```bash tacctl rollback 0.2.28 # the dry run: steps, writes nothing @@ -366,9 +378,9 @@ tacctl upgrade --branch 0.2.28 # install 0.2.28 ### To 0.2.27 -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. +0.2.27 reads every file 0.2.28, 0.2.29 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, the check of a new user name, 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 to 0.2.29 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 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. +What 0.2.28 to 0.2.29 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 @@ -378,9 +390,9 @@ tacctl upgrade --branch 0.2.27 # install 0.2.27 ### To 0.2.26 -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. +0.2.26 reads every file 0.2.27 to 0.2.29 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.29 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, 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. +What 0.2.27 to 0.2.29 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 @@ -390,7 +402,7 @@ tacctl upgrade --branch 0.2.26 # install 0.2.26 ### To 0.2.25 -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. +0.2.25 reads every file 0.2.26 to 0.2.29 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.30 state and is to be restored with 0.2.30 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 @@ -417,7 +429,7 @@ 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.28 and this release write but `breakglass.firewall` +0.2.23 reads every file 0.2.24 to 0.2.29 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 @@ -425,7 +437,7 @@ firewall file and no limit it takes no snapshot and does not need `--yes`. When 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 to 0.2.28 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.29 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 @@ -445,7 +457,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.28 and this release write but the users' email addresses in +0.2.22 reads every file 0.2.23 to 0.2.29 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 db7f226f..3c4932ba 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.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 + release>` (0.2.17 to 0.2.29 each did). Check that the release before this + one is a constant in `internal/lifecycle/rollback.go` (`RollbackTarget0229` + for 0.2.30) 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/internal/cli/completion_test.go b/internal/cli/completion_test.go index 5d9d6b24..fc151c33 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.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}, + {[]string{"rollback", ""}, []string{"0.2.29", "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 5e11d258..a3606a4e 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.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 + rollback [options] Prepare the state for the release before this one (0.2.29), 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 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 ec3d3e07..87c48fce 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.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 +// state for the release before this one (0.2.29), 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, 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.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}, + Args: []string{lifecycle.RollbackTarget0229 + "|" + 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.RollbackTarget0229: + inv.rollbackNextSteps0229(version) + return case lifecycle.RollbackTarget0228: inv.rollbackNextSteps0228(version) return @@ -327,7 +330,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.29" +const rollbackFrom = "0.2.30" // 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 @@ -342,7 +345,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.28, 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.29, 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) { @@ -356,7 +359,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.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 +// addresses (every target but 0.2.29, 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) @@ -448,12 +451,12 @@ func (inv *invocation) rollbackFileTransferNote(version string) { inv.echo("If one did, run 'tacctl rollback " + version + " --apply' again (it removes them).") } -// 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 +// rollbackNextSteps0229 is the next steps of the rollback to 0.2.29: the +// upgrade of the tag. 0.2.29 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) { +// in the users' homes (the PDF ones too) stay, 0.2.29 has them. +func (inv *invocation) rollbackNextSteps0229(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:") @@ -461,6 +464,13 @@ func (inv *invocation) rollbackNextSteps0228(version string) { inv.echo(" 2. Check it: tacctl status; tacctl config validate") } +// rollbackNextSteps0228 is the next steps of the rollback to 0.2.28: those of +// 0.2.29, which reads the same files (0.2.28 reads every file 0.2.29 and this +// release write). +func (inv *invocation) rollbackNextSteps0228(version string) { + inv.rollbackNextSteps0229(version) +} + // 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 @@ -474,14 +484,14 @@ func (inv *invocation) rollbackNextSteps0227(version string, snapshot bool) { } // 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, 0.2.28 +// 0.2.27, which reads the same files (0.2.26 reads every file 0.2.27 to 0.2.29 // 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 to 0.2.28 and this release write but the +// upgrade of the tag. 0.2.25 reads every file 0.2.26 to 0.2.29 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 d3ca9ede..1879c578 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.29 state"} { + "do not add the 'audit' setting (audit.strict)", "holds the 0.2.30 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 9890005f..fefc31cc 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.29 state. Restore it with 0.2.29 only"} { + "Next steps", "tacctl upgrade --branch 0.2.9", "holds the 0.2.30 state. Restore it with 0.2.30 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 65b58b3d..181740f1 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.29 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.30 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.29 state. Restore it with 0.2.29 only") { + if hs.snapshots() != snaps+1 || strings.Contains(out, "takes no snapshot") || !strings.Contains(out, "holds the 0.2.30 state. Restore it with 0.2.30 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 a1a05b39..8be58f08 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.29 state. Restore it with 0.2.29 only:", + "The snapshot the rollback took first (the newest entry of 'tacctl backup list') holds the 0.2.30 state. Restore it with 0.2.30 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 1c5a9114..38874700 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.29 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.30 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.29 state", "The reports in the users' homes stay"} { + "holds the 0.2.30 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 d4a85d72..3771a723 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.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") + hs.run(hs.runner(), "rollback", "0.2.30") + hs.expect(1, "", "prepares the state for 0.2.29 (the release before this one), 0.2.28, 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.29 state. Restore it with 0.2.29 only"} { + for _, want := range []string{"--apply takes a snapshot of the state first", "holds the 0.2.30 state. Restore it with 0.2.30 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 1eac0b09..89b2649c 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.29 state +// users' own limits are data and need it. The snapshot holds the 0.2.30 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.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.", + "holds the 0.2.30 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.29 state") || !strings.Contains(out, c.target+c.tail) { + if !strings.Contains(out, "holds the 0.2.30 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 eb6dfacb..9e64f75f 100644 --- a/internal/cli/rollback_target0227_test.go +++ b/internal/cli/rollback_target0227_test.go @@ -167,8 +167,8 @@ func TestRollback0227LeavesTheDropIn(t *testing.T) { // 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.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", "0.2.30") + hs.expect(1, "", "prepares the state for 0.2.29 (the release before this one), 0.2.28, 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.29 only", "0.2.27's restore puts back a console.yaml with a setting it does not know", + "Restore it with 0.2.30 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 index afa06b14..be473327 100644 --- a/internal/cli/rollback_target0228_test.go +++ b/internal/cli/rollback_target0228_test.go @@ -9,10 +9,10 @@ import ( "github.com/rett/tacctl/internal/tier" ) -// 'tacctl rollback 0.2.28', the release before this one, on the host sandbox +// 'tacctl rollback 0.2.28', the release before 0.2.29, 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 +// 0.2.29 and 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, @@ -163,12 +163,12 @@ func TestRollback0228LeavesTheDropIn(t *testing.T) { 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) { +// 0.2.28 is the release before 0.2.29; this release is not a target, and the +// refusal names 0.2.29 as the release before this one, and 0.2.28 after it. +func TestRollback0228IsAccepted(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", "0.2.30") + hs.expect(1, "", "'0.2.30' is not a release to roll back to: 'tacctl rollback' prepares the state for 0.2.29 (the release before this one), 0.2.28, 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_target0229_test.go b/internal/cli/rollback_target0229_test.go new file mode 100644 index 00000000..aaa2db1d --- /dev/null +++ b/internal/cli/rollback_target0229_test.go @@ -0,0 +1,177 @@ +package cli + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/rett/tacctl/internal/tier" +) + +// 'tacctl rollback 0.2.29', 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.29 reads strictly (it checks the +// name of a new user more strictly), so 0.2.29 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 TestRollback0229ConvertsNothing(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.29", "--hosts") + hs.expect(0, "This was a dry run: nothing was changed.", "") + out := hs.all() + for _, want := range []string{"Roll back to 0.2.29 (dry run)", "nothing to remove (every key of tacctl.yaml is one 0.2.29 knows)", + "--apply converts no file of tacctl's own and takes no snapshot", + "nothing to do for 0.2.29: this release changed nothing on the enrolled hosts", "To convert the state: tacctl rollback 0.2.29 --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.29", "--apply") + hs.expect(0, "Nothing to convert: every file is one 0.2.29 can read.", "") + out = hs.all() + if !strings.Contains(out, "tacctl upgrade --branch 0.2.29") { + 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.29 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.29 and 0.2.28 keep. An emergency lockdown on the scope the +// enrolled host answers stays in both, and the older targets refuse it. +func TestRollback0229IsToldApartFromTheOlderTargets(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)", "") + hs.run(hs.runner(), "rollback", "0.2.29") + hs.expect(0, "nothing to remove (every key of tacctl.yaml is one 0.2.29 knows)", "") + if strings.Contains(hs.all(), "settings.file_transfer") { + t.Errorf("0.2.29 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.29", "--apply") + hs.expect(0, "Nothing to convert: every file is one 0.2.29 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.29 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.29 wrote the same, so +// it is left; the 0.2.25 target puts back its own, without the rows of +// 'device reports'. +func TestRollback0229LeavesTheDropIn(t *testing.T) { + hs := rollback0227State(t) + before := tree(t, hs.dir) + hs.run(hs.runner(), "rollback", "0.2.29", "--apply") + hs.expect(0, "Nothing to convert: every file is one 0.2.29 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.29 is the release before this one; this release is not a target, and +// the refusal names 0.2.29 first. +func TestRollback0229IsTheReleaseBeforeThisOne(t *testing.T) { + hs := rollback0227State(t) + hs.run(hs.runner(), "rollback", "0.2.30") + hs.expect(1, "", "'0.2.30' is not a release to roll back to: 'tacctl rollback' prepares the state for 0.2.29 (the release before this one), 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24") + hs.run(hs.runner(), "rollback", "v0.2.29") + hs.expect(0, "Roll back to 0.2.29 (dry run)", "") +} diff --git a/internal/cli/rollback_test.go b/internal/cli/rollback_test.go index c11c04b2..0acaa877 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.29 state. Restore it with 0.2.29 only"} { + "Next steps", "tacctl upgrade --branch 0.2.3", "holds the 0.2.30 state. Restore it with 0.2.30 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.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", ""}, []string{"0.2.29", "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 d0c78e39..c535f384 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.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 + rollback [options] Prepare the state for the release before this one (0.2.29), 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 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 67182f72..16b2b7cd 100644 --- a/internal/lifecycle/rollback.go +++ b/internal/lifecycle/rollback.go @@ -6,9 +6,10 @@ 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.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 +// The targets are 0.2.29 (the release before this one: RollbackTarget0229; +// rollback0229.go: nothing, this release changed no stored file 0.2.29 reads +// strictly), 0.2.28 (RollbackTarget0228; rollback0228.go: nothing, 0.2.29 and +// this release changed no stored file it 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 @@ -133,7 +134,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.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 +// 0.2.29, 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 @@ -205,7 +206,7 @@ import ( // 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, 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 +// transfer settings, RollbackTarget0228 the one before the 0.2.29 release and RollbackTarget0229 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 ( @@ -224,6 +225,7 @@ const ( RollbackTarget0226 = "0.2.26" RollbackTarget0227 = "0.2.27" RollbackTarget0228 = "0.2.28" + RollbackTarget0229 = "0.2.29" ) // RollbackRefusal is a version the command does not take: Lines say why. @@ -307,9 +309,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 " + RollbackTarget0228 + "|" + RollbackTarget0227 + "|" + RollbackTarget0226 + "|" + RollbackTarget0225 + "|" + RollbackTarget0224 + "|" + RollbackTarget0223 + "|" + RollbackTarget0222 + "|" + RollbackTarget0221 + "|" + RollbackTarget0220 + "|" + RollbackTarget0219 + "|" + RollbackTarget0218 + "|" + RollbackTarget0217 + "|" + RollbackTarget0216 + "|" + RollbackTarget029 + "|" + RollbackTarget + " [--apply] [--yes] [--hosts]" +const rollbackUsage = "Usage: tacctl rollback " + RollbackTarget0229 + "|" + 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.28", "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.29", "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 @@ -324,11 +326,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 || v == RollbackTarget0228 { + 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 || v == RollbackTarget0229 { return v, nil } n := func(i int) int { x, _ := strconv.Atoi(m[i]); return x } - 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" + both := "'tacctl rollback' prepares the state for " + RollbackTarget0229 + " (the release before this one), " + RollbackTarget0228 + ", " + 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: @@ -425,7 +427,7 @@ type RollbackInput struct { HasStore bool // WithHosts: the command was given --hosts. WithHosts bool - // Target is the release rolled back to: RollbackTarget0228, RollbackTarget0227, RollbackTarget0226, RollbackTarget0225, RollbackTarget0224, RollbackTarget0219, + // Target is the release rolled back to: RollbackTarget0229, 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 @@ -633,13 +635,19 @@ func planRollback(in RollbackInput) (*RollbackPlan, error) { if len(pend) > 0 { return nil, PendingRefusal(pend) } - // 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, + // 0.2.29 reads every file this release writes: it converts nothing + // (rollback0229.go), and has the managed scope of the server's own login, // so nothing is added to the users. + if in.Target == RollbackTarget0229 { + return planRollback0229(p) + } + // 0.2.28 reads every file 0.2.29 and this release write: 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 + // 0.2.27 reads every file 0.2.28, 0.2.29 and this release write 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 @@ -647,14 +655,14 @@ func planRollback(in RollbackInput) (*RollbackPlan, error) { if in.Target == RollbackTarget0227 { return planRollback0227(p) } - // 0.2.26 reads every file 0.2.27, 0.2.28 and this release write but the + // 0.2.26 reads every file 0.2.27 to 0.2.29 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 to 0.2.28 and this release write but what a step of + // 0.2.25 reads every file 0.2.26 to 0.2.29 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 a13db7e5..9bc3e45d 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.29", "0.2.160", "0.2.170"} { + for _, bad := range []string{"0.2.15", "0.2.10", "0.2.30", "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 6767edaa..b2b67fbb 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, RollbackTarget0228: + case RollbackTarget0222, RollbackTarget0223, RollbackTarget0224, RollbackTarget0225, RollbackTarget0226, RollbackTarget0227, RollbackTarget0228, RollbackTarget0229: 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 83e54b89..6bd46dd8 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.28 and this release write but what a step of +// 0.2.22 reads every file 0.2.23 to 0.2.29 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.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 +// when it is exactly this release's text (the same as 0.2.29's, 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 dbb38bd7..80ae3ac6 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.28 and this release write, and the plan of the +// 0.2.23 reads every file 0.2.24 to 0.2.29 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 to 0.2.28 and this release +// exactly the text of 0.2.24 and 0.2.25, or the one 0.2.26 to 0.2.29 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 to 0.2.28 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.29 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 8a6f61f4..87f88e9d 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, 0.2.28 and this release write and the plan of the target +// every file 0.2.27 to 0.2.29 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 to 0.2.28 and this release write the same text), removes no +// included (0.2.26 to 0.2.29 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, 0.2.28 and this release changed outside the stored files is 0.2.26's to +// What 0.2.27 to 0.2.29 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 f1105ce7..ef27cbe1 100644 --- a/internal/lifecycle/rollback0227.go +++ b/internal/lifecycle/rollback0227.go @@ -20,9 +20,9 @@ package lifecycle // 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 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 +// all as 0.2.27 reads them. So 0.2.27 reads every other file 0.2.28, 0.2.29 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.29 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: @@ -33,7 +33,7 @@ package lifecycle // 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 0.2.28 and this release changed outside the stored files is 0.2.27's +// What 0.2.28 to 0.2.29 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. diff --git a/internal/lifecycle/rollback0228.go b/internal/lifecycle/rollback0228.go index 64a1d22b..ca459e96 100644 --- a/internal/lifecycle/rollback0228.go +++ b/internal/lifecycle/rollback0228.go @@ -1,30 +1,35 @@ 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 +// The rollback to 0.2.28, the release before 0.2.29 (rollback0229.go). 0.2.29 +// 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; this release only checks the name of a new user more +// strictly, which writes no new form of a file. 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. +// are all as 0.2.28 reads them. So 0.2.28 reads every file 0.2.29 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.28 to 0.2.29 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. +// What 0.2.29 and 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, and a new +// user name is checked as 0.2.28 checks it (a name that starts with a digit, +// '-' or '_' is accepted again). // planRollback0228 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.28. func planRollback0228(p *RollbackPlan) (*RollbackPlan, error) { pt := p.in.Paths p.Steps = append(p.Steps, p.lockdownKeysStep(RollbackTarget0228)) diff --git a/internal/lifecycle/rollback0228_test.go b/internal/lifecycle/rollback0228_test.go index 8b0f6512..1423727a 100644 --- a/internal/lifecycle/rollback0228_test.go +++ b/internal/lifecycle/rollback0228_test.go @@ -10,10 +10,11 @@ import ( "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 +// The rollback to 0.2.28, the release before 0.2.29, on the sandbox of +// rollback_test.go: 0.2.29 and this release changed no stored file 0.2.28 +// reads strictly (0.2.29 changed the mode of a file uploaded through the +// console, this release the check of a new user name), 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 { diff --git a/internal/lifecycle/rollback0229.go b/internal/lifecycle/rollback0229.go new file mode 100644 index 00000000..ef070716 --- /dev/null +++ b/internal/lifecycle/rollback0229.go @@ -0,0 +1,41 @@ +package lifecycle + +// The rollback to 0.2.29, the release before this one. This release changed no +// stored file 0.2.29 reads strictly: what it changed is how a new user name is +// checked (a name must start with a lower case letter; 'user add' and the new +// name of 'user rename' refuse the others, and 'config validate' warns of an +// existing name that has no Linux account), a check in the code that creates +// a user and not a form of a file: a user stored under a name the check would +// refuse is read, listed and kept by 0.2.29 and by this release alike. 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.29 reads them. So 0.2.29 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.29 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.29 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.29's to undo or +// keep, and needs no step here: with 0.2.29 installed again 'user add' and +// 'user rename' take a new name that starts with a digit, '-' or '_', as they +// did. + +// planRollback0229 completes p (a plan whose tacctl.yaml was read and whose +// records hold no unsettled apply) for the release before this one. +func planRollback0229(p *RollbackPlan) (*RollbackPlan, error) { + pt := p.in.Paths + p.Steps = append(p.Steps, p.lockdownKeysStep(RollbackTarget0229)) + 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 " + RollbackTarget0229 + " 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 " + RollbackTarget0229 + ": this release changed nothing on the enrolled hosts; no host is synced"}}) + } + return p, nil +} diff --git a/internal/lifecycle/rollback0229_test.go b/internal/lifecycle/rollback0229_test.go new file mode 100644 index 00000000..aff9ecbd --- /dev/null +++ b/internal/lifecycle/rollback0229_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.29, the release before this one, on the sandbox of +// rollback_test.go: this release changed no stored file 0.2.29 reads strictly +// (it checks the name of a new user more strictly), so the plan converts +// nothing, whatever 0.2.28 and 0.2.29 added to the state (the console's file +// transfer settings included). + +func plan0229(t *testing.T, s *rbSandbox) *RollbackPlan { + t.Helper() + s.in.Target = RollbackTarget0229 + 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.29 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.29 and this release write +// alike. It writes nothing. +func TestPlanRollback0229ConvertsNothing(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 := plan0229(t, s) + if p.Target != RollbackTarget0229 { + t.Errorf("target %q", p.Target) + } + st := stepText(p) + for _, w := range []string{s.p.Overrides + ": remove the keys 0.2.29 does not know", "nothing to remove (every key of tacctl.yaml is one 0.2.29 knows)", + "leave every other file untouched", "are in formats 0.2.29 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 TestPlanRollback0229ConvertsNothingOnAPlainState(t *testing.T) { + s := newRBSandbox(t) + before := s.snapshotOf() + p := plan0229(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 = plan0229(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 TestPlanRollback0229WithHosts(t *testing.T) { + s := newRBSandbox(t) + s.in.WithHosts = true + p := plan0229(t, s) + if st := stepText(p); !strings.Contains(st, "nothing to do for 0.2.29: 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 TestPlanRollback0229RefusesAnUnsettledApply(t *testing.T) { + s := newRBSandbox(t) + s.in.Target = RollbackTarget0229 + 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.29 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 TestRollback0229ReaderKnowsTheFileTransferSettings(t *testing.T) { + r := execx.Real{} + if _, err := r.LookPath("git"); err != nil { + t.Skip("git is not installed, so the 0.2.29 tag cannot be read") + } + if res, err := r.Run(context.Background(), execx.Cmd{Name: "git", Args: []string{"rev-parse", "-q", "--verify", "0.2.29^{commit}"}}); err != nil || res.Code != 0 { + t.Skip("the 0.2.29 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.29:internal/console/config.go"}}) + if err != nil || res.Code != 0 { + t.Fatalf("cannot read the 0.2.29 tag's console config: %v %s", err, res.Stderr) + } + if !strings.Contains(string(res.Stdout), `case "file_transfer":`) { + t.Error("0.2.29'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 513ad6fa..53d47131 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.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 +// (0.2.29, 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 5167e502..5019178f 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.28, 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.29, 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 178726c1..e1bba438 100644 --- a/internal/lifecycle/rollback_firewall.go +++ b/internal/lifecycle/rollback_firewall.go @@ -2,7 +2,7 @@ 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.28, 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.29, 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.28, 0.2.27, 0.2.26, 0.2.25 and 0.2.24 (which have them) diff --git a/internal/lifecycle/rollback_snmp_pool.go b/internal/lifecycle/rollback_snmp_pool.go index 4ff05f4f..9826af9d 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.28, 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.29, 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 f48f4bb4..e191e671 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.28, 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.29, 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 2e0643de..a87723f6 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", "0.2.28": "0.2.28", "v0.2.28": "0.2.28"} { + 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", "0.2.29": "0.2.29", "v0.2.29": "0.2.29"} { 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.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)"}, + {"0.2.2", "'tacctl rollback' prepares the state for 0.2.29 (the release before this one), 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 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,9 +31,8 @@ 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.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.10", "'0.2.10' is not a release to roll back to: 'tacctl rollback' prepares the state for 0.2.29 (the release before this one), 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 and 0.2.3 only"}, {"0.2.15", "'0.2.15' 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"}, @@ -58,7 +57,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.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") { + if !strings.Contains(err212.Error(), "Usage: tacctl rollback 0.2.29|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 bf1561a0..82a13e5a 100644 --- a/internal/tier/report_limits_test.go +++ b/internal/tier/report_limits_test.go @@ -138,7 +138,7 @@ func TestSudoersIsTheTextOf0227(t *testing.T) { } } -// This release's per-tier text is the one 0.2.28 wrote, which is why the +// The 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 @@ -159,3 +159,25 @@ func TestSudoersIsTheTextOf0228(t *testing.T) { 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)") } } + +// This release's per-tier text is the one 0.2.29 wrote, which is why the +// rollback to 0.2.29 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 TestSudoersIsTheTextOf0229(t *testing.T) { + r := execx.Real{} + if _, err := r.LookPath("git"); err != nil { + t.Skip("git is not installed, so the 0.2.29 tag cannot be read") + } + if res, err := r.Run(context.Background(), execx.Cmd{Name: "git", Args: []string{"rev-parse", "-q", "--verify", "0.2.29^{commit}"}}); err != nil || res.Code != 0 { + t.Skip("the 0.2.29 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.29:internal/tier/testdata/sudoers.tiers"}}) + if err != nil || res.Code != 0 { + t.Fatalf("cannot read the 0.2.29 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.29 tag: freeze that text for the rollback to 0.2.29 (rollback0229.go leaves the drop-in alone only while they are the same)") + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index a77b2f82..f3378d77 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -419,8 +419,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.28 +.B 0.2.29 (the release before this one), +.BR 0.2.28 , .BR 0.2.27 , .BR 0.2.26 , .BR 0.2.25 , @@ -443,12 +444,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.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.15 included: the refusal names the targets). Every target but 0.2.29, 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.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 +scope; 0.2.19 has the record and keeps it), every target but 0.2.29, 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 @@ -463,7 +464,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.28 to 0.2.20 ignore +release before 0.2.20 (the targets 0.2.19 and older; 0.2.29 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 @@ -471,7 +472,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.28 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.29 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 , @@ -487,7 +488,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.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 +Every target but 0.2.29, 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 ) @@ -496,16 +497,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.28, 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.29, 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.28, 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.29, 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.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: +server's entry. Every target but 0.2.29, 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 @@ -520,7 +521,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.28, 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.29, 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 @@ -548,7 +549,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.28, 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.29, 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 ) @@ -577,7 +578,7 @@ the audit line adds and the apply names .BR "tacctl backup recover \-\-only snmp\-users" . .IP -Every target but 0.2.28, 0.2.27, 0.2.26, 0.2.25, 0.2.24 and 0.2.23 drops from +Every target but 0.2.29, 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 @@ -591,7 +592,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.28, 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.29, 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 @@ -637,7 +638,7 @@ and then .BR "systemctl daemon\-reload" . .IP -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 +Every target before 0.2.26 (0.2.25 and older; 0.2.26 to 0.2.29 read the limits and keep them) removes the limits of the stored reports of .BR "device reports" : the settings .B reports.max_size @@ -687,14 +688,14 @@ again (with .B \-\-yes while a user has a limit of their own). .IP -Every target but 0.2.28 removes the file transfer settings of the console, +Every target but 0.2.29 and 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 (0.2.28 reads the key, and so does this release): no release before 0.2.28 reads the key (its reader answers +included (0.2.28 and 0.2.29 read 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 @@ -708,13 +709,52 @@ 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 +.B "rollback 0.2.29" +converts nothing: this release changed no stored file 0.2.29 reads strictly +(the check of the name of a new user, which writes no new form of a file, and the +documentation are all that moved), so 0.2.29 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.29 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.29 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.29" , +with no note to follow: the settings, the limits and the reports are 0.2.29's own. +After the upgrade +.B "user add" +and +.B "user rename" +take a new name that starts with a digit, +.B \- +or +.BR _ , +as they did; every user keeps the name it has, whatever it is. +.IP +.B "rollback 0.2.28" +converts nothing: 0.2.29 and this release changed no stored file 0.2.28 reads strictly +(the mode a file uploaded through the console gets, the check of the name of a new user, a test and the +documentation are all that moved), so 0.2.28 reads every file they +write. 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 @@ -723,7 +763,7 @@ and a user's own limits, stay, and so do the break\-glass firewall and its setti 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 +per\-tier sudoers drop\-in (0.2.28 to 0.2.29 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 @@ -738,14 +778,22 @@ 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. +mode 0644 (0600 after the umask of the console) whatever mode it asks for, as in 0.2.28, and +.B "user add" +and +.B "user rename" +take a new name that starts with a digit, +.B \- +or +.BR _ , +as they did. .IP .B "rollback 0.2.27" converts only the file transfer settings of .IR console.yaml : -0.2.28 and this release changed no other stored file 0.2.27 reads strictly (how +0.2.28 to 0.2.29 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 +through the console, the check of the name of a new user, 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 @@ -755,7 +803,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, 0.2.28 and this release write the same text), the +per\-tier sudoers drop\-in (0.2.27 to 0.2.29 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 @@ -777,13 +825,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, 0.2.28 and this release changed no other stored file 0.2.26 reads strictly (what +0.2.27 to 0.2.29 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, 0.2.28 and this release +documentation are all that moved), so 0.2.26 reads every file 0.2.27 to 0.2.29 and this release write. It removes no other key and no field (the limits of the stored reports, the settings .B reports.max_size @@ -793,7 +841,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 to 0.2.28 and this release write the same text), the +per\-tier sudoers drop\-in (0.2.26 to 0.2.29 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 . @@ -804,8 +852,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 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 +removes the limits of the stored reports of 0.2.26 to 0.2.29 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.29 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 @@ -832,7 +880,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 to 0.2.28 and this release without the rows of +with the text 0.2.25 wrote, the text of 0.2.26 to 0.2.29 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 @@ -879,14 +927,14 @@ 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.28 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.29 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 to 0.2.28 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.29 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 @@ -924,7 +972,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.28 and this release write, so the server name, the timing +reads every other file 0.2.23 to 0.2.29 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 @@ -1049,7 +1097,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.28 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.29 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 @@ -1071,7 +1119,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.28 to 0.2.20 (which read it) removes the required password change +Every target but 0.2.29 to 0.2.20 (which read it) removes the required password change .RB ( password_change_required of a user in .IR store.yaml , diff --git a/tests/integration/rollback.bats b/tests/integration/rollback.bats index 051c6390..f20abc66 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.29 + run "$TACCTL_BIN_SCRIPT" rollback 0.2.30 assert_failure 1 - 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" + assert_output --partial "'0.2.30' is not a release to roll back to" + assert_output --partial "prepares the state for 0.2.29 (the release before this one), 0.2.28, 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.28: the release before this one; the dry run writes nothing and --apply converts nothing, the report limits stay" { +@test "rollback 0.2.29: 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.29 --hosts + assert_success + assert_output --partial "Roll back to 0.2.29 (dry run)" + assert_output --partial "nothing to remove (every key of tacctl.yaml is one 0.2.29 knows)" + assert_output --partial "nothing to do for 0.2.29: 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.29 --apply + assert_success + assert_output --partial "Nothing to convert: every file is one 0.2.29 can read." + assert_output --partial "tacctl upgrade --branch 0.2.29" + 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.28: the release before 0.2.29; 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 11b97803092329e38354fb20a56e900b95efcf16 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 00:14:56 -0900 Subject: [PATCH 02/27] user: a new user name starts with a lower case letter Every new user gets a Linux account, here and on the enrolled hosts, and a name that starts with a digit or '-' is no account name. 'user add' and the new name of 'user rename' now refuse a first character that is not a lower case letter (a to z; a digit, '-' and '_' are refused, '_' because the project does not take it for a new name though Linux does), with one sentence that names the rule and the name, exit status 1, nothing changed. names.RejectNonLetterUsername is the check, next to RejectLongUsername, and names.CheckNewUsername runs the whole creation check in a documented order: the shape, the reserved names, upper case, the length, the first character. So 'Alice' and '1Alice' are told the lower case spelling first and the letter rule follows on the retry. Both verbs call it. ValidateUsername stays what every other verb runs: a user that exists as 9dave, _svc or -x is shown, changed, renamed away, removed, restored and carried by the upgrade as before. config validate warns, under Names:, of an existing user whose name starts with a digit or '-' (no Linux account, here or on a host) and names 'tacctl user rename ', the rename that must itself pass the creation rules; a name that starts with '_' has an account and gets no warning. The length finding (lengthFindings) becomes userNameFindings and says every fault of a name in its one finding. --fix-names (caseFindings) offers the lower case spelling of a name with upper case only when that spelling passes all the rules of a new name. For '1Alice', 'Alice' followed by 41 characters, '_Alice' or 'Root' it offers nothing and the user has exactly one finding, userNameFindings', with no contradicting fix; --fix-names counts nothing as not offered or failed and exits 0 for it. Tests: names (the check, the order), 'user add' and 'user rename' with every kind of first character, users of any first character kept working through every verb and a restore, config validate in text and --json and --fix-names for 1alice, -x, 1Alice, Alice and 41 characters, 1Alice and 41 characters, _Svc (and a plain Bobby still offered), and the test of a user with no Linux account name and the hosts, which now creates the user in the fixture store directly. Documentation: docs/cli/user.md (user add, user rename, A new name starts with a letter), docs/cli/config.md, docs/cli/maintenance.md, docs/install/upgrading.md, the manual page, and CHANGELOG item 2 of 0.2.30. --- CHANGELOG.md | 32 ++++ docs/cli/config.md | 25 ++- docs/cli/maintenance.md | 2 +- docs/cli/user.md | 35 +++- docs/install/upgrading.md | 2 + internal/cli/config_report.go | 8 +- internal/cli/name_case.go | 111 ++++++++--- internal/cli/user.go | 21 +- internal/cli/user_firstletter_test.go | 263 ++++++++++++++++++++++++++ internal/cli/user_no_dots_test.go | 4 +- internal/cli/user_notice_test.go | 23 ++- internal/names/names.go | 41 ++++ internal/names/names_test.go | 62 ++++++ man/tacctl.1 | 48 ++++- 14 files changed, 598 insertions(+), 79 deletions(-) create mode 100644 internal/cli/user_firstletter_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index be66f807..60129835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,38 @@ current behaviour; this file is where history lives. release, 0.2.30, as the state the snapshot holds ("Restore it with 0.2.30 only"). +2. **A new user name starts with a lower-case letter.** Every new user gets a + Linux account, on this server and on the enrolled hosts, and a name that + starts with a digit or `-` is no account name, so `user add` and the new + name of `user rename` now refuse a first character that is not a letter, a + to z (a digit, `-` and `_`, which Linux itself would take, are refused so + that every new name is an account name everywhere): `Username '1alice' + must start with a letter (a to z): every new user gets a Linux account, and + a name that starts with a digit or '-' is no account name (a new name does + not start with '_' either).`, exit status 1, nothing changed. A new name is + now a lower-case letter, then lower-case letters, digits, `_` and `-`, at + most 32 characters. The checks run in a fixed order and the first that + fails is the answer (`names.CheckNewUsername`): the shape (no period), the + reserved names, upper case, the length, the first character, so `Alice` and + `1Alice` are told the lower-case spelling first (`Names are lower case: use + '1alice'.`) and the letter rule follows on the retry. Only a new name is + checked: a user that exists as `9dave`, `_svc` or `-x` keeps working and is + shown, changed, renamed away, removed, restored and carried by the upgrade + as before. `config validate` warns, under `Names:`, of an existing user + whose name starts with a digit or `-` (no Linux account, here or on a host) + and names `tacctl user rename `; a name that starts with + `_` has an account and gets no warning. `config validate --fix-names` + offers the rename to the lower-case spelling of a name with upper case only + when that spelling would pass all the rules of a new name: for `1Alice`, + `_Alice`, `Root` or `Alice` followed by 41 characters it offers nothing, + and the user gets exactly one warning, which names the rename to a name of + your choice and says what else is wrong with the name (`--fix-names` + counts nothing as not offered or failed for it and exits 0). The rollback + to 0.2.29 (item 1) leaves every user as it is. `docs/cli/user.md` + (`user add`, `user rename`, A new name starts with a letter), + `docs/cli/config.md`, `docs/install/upgrading.md` and the manual page say + so. + ## 0.2.29 (2026-11-09) 1. **A file uploaded through the console keeps the owner's execute bit.** The diff --git a/docs/cli/config.md b/docs/cli/config.md index 42d46a80..90638006 100644 --- a/docs/cli/config.md +++ b/docs/cli/config.md @@ -89,12 +89,17 @@ config validate [--json | --fix-names [--yes]] 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. 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. 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 + an earlier release whose name is longer than 32 characters or starts with a digit or `-` (a + new name is at most 32 and starts with a lower-case letter, 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 ` (the new name must pass the rules of a new name); + `--fix-names` does not offer that rename, since it has no name to propose. A name that starts + with `_` has an account and is not warned of. A user with several of these faults, upper + case included (`1Alice`, or `Alice` followed by 41 characters), gets that one warning only, + which says so: the lower-case spelling would be refused by `user rename` too (it is longer than + 32 characters, or does not start with a letter, or is reserved), so no warning proposes it. A + user with upper case and a name that starts with `_` gets one warning that names + `tacctl user rename ` the same way. 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. @@ -373,9 +378,11 @@ 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 user whose lower-case spelling `user rename` would refuse, because it is longer than 32 +characters, does not start with a lower-case letter (`1Alice`, `_Alice`) or is reserved +(`Root`), is not offered it: the `Names:` warning of that user names the rename to a name of +your choice (it is counted neither as not offered nor as failed, and the run ends with status +0 for it). 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 diff --git a/docs/cli/maintenance.md b/docs/cli/maintenance.md index 41ec677f..7eba944b 100644 --- a/docs/cli/maintenance.md +++ b/docs/cli/maintenance.md @@ -293,7 +293,7 @@ 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). +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 and starts with a lower-case letter; such a user has no Linux account, and `config validate` lists them, as it does a user whose name starts with a digit or `-`). 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. diff --git a/docs/cli/user.md b/docs/cli/user.md index 6d5d194c..e65cfbc9 100644 --- a/docs/cli/user.md +++ b/docs/cli/user.md @@ -16,14 +16,17 @@ user show 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 + 'alice'.`) and starts with a letter: a lower-case letter (a to z), then 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).`). 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"). - 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 + A first character that is not a letter is refused (`Username '1alice' must start with a + letter (a to z): every new user gets a Linux account, and a name that starts with a digit or + '-' is no account name (a new name does not start with '_' either).`), so that every new user + has an account on the tacctl server and on a host; see "A new name starts with a letter". + 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"). @@ -107,8 +110,8 @@ user enable user rename - 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 + Rename a user; the new name is lower case, starts with a letter, is 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 @@ -237,6 +240,24 @@ 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 new name starts with a letter.** Every new user gets a Linux account, on the tacctl server +and on the enrolled hosts, and a name that starts with a digit or `-` is no account name (Linux +itself takes a leading `_`, but a new name does not start with one, so that every new name is +an account name everywhere). So `user add` and the new name of `user rename` take a lower-case +letter, `a` to `z`, as the first character and refuse a digit, `-` and `_` with `Username '1alice' +must start with a letter (a to z): every new user gets a Linux account, and a name that starts +with a digit or '-' is no account name (a new name does not start with '_' either).` and change +nothing. The checks run in this order, and the first that fails is the answer: the shape (letters, +digits, `_` and `-`; no period), the reserved names, upper case (`Names are lower case: use +'alice'.`, so `Alice` and `1Alice` are told the lower-case spelling first, and the letter rule +follows on the retry with `1alice`), the length (at most 32) and the first character. Only a new +name is checked: a user from an earlier release named `9dave`, `_svc` or `-x` keeps working. It +is shown, listed, changed, renamed away to a name that passes the rules, removed and restored by +`backup restore` as before, and `tacctl upgrade` carries it unchanged. A name that starts with a +digit or `-` has no account on the tacctl server or on a host, so `config validate` warns of it +under `Names:` with `tacctl user rename `; a name that starts with `_` has an +account and is not warned of (see [config](config.md)). + **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 @@ -247,7 +268,7 @@ changed, renamed away to a shorter name and removed as before, and `backup resto 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. +name that starts with a digit or `-`, have none either (`user add` refuses a new one of them). **This server's accounts.** `user add`, `remove`, `rename`, `move`, `enable`, `disable`, `scope add|remove|replace|remove --all` and diff --git a/docs/install/upgrading.md b/docs/install/upgrading.md index 813398e4..a6bf851a 100644 --- a/docs/install/upgrading.md +++ b/docs/install/upgrading.md @@ -22,6 +22,8 @@ The upgrade command: 10. Sets up this machine's own login, or repairs it (see **This machine's own login (0.2.21)** below) 11. Offers the tools of the PDF device reports (0.2.27; see [PDF reports](#pdf-reports) below), last, once the upgrade is done +**A new user name starts with a letter (0.2.30).** `user add` and the new name of `user rename` refuse a name whose first character is not a lower-case letter, a to z (a digit, `-` and `_` are refused; a name with upper case is told its lower-case spelling first). Every new user gets a Linux account, and a name that starts with a digit or `-` is no account name. Nothing is changed in the files: a user that exists as `9dave`, `_svc` or `-x` keeps working, is carried by the upgrade and by `backup restore` unchanged, and can be shown, changed, renamed away and removed. After the upgrade `tacctl config validate` warns, under `Names:`, of each user whose name starts with a digit or `-` (it has no Linux account, here or on a host) and names `tacctl user rename `; a name that starts with `_` has an account and is not warned of. A user with upper case whose lower-case spelling could not be a new name (`1Alice`, a name longer than 32 characters) gets that one warning, and `config validate --fix-names` offers no rename for it. The upgrade's own renames of users with a period keep the rule they had (see below). + **The unit comments name the current commands (0.2.22).** The shipped unit files and the comment at the top of the generated drop-in (`tacquito.service.d/tacctl.conf`) name `tacctl server listen` and `tacctl server metrics` where they named `config listen` and `config metrics`. The first render after the upgrade rewrites the drop-in, reloads systemd and restarts tacquito once, a brief TACACS+ interruption (the upgrade's own restart for the changed unit files is that one); nothing else in them changes. **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. diff --git a/internal/cli/config_report.go b/internal/cli/config_report.go index 9df9becc..934abbf1 100644 --- a/internal/cli/config_report.go +++ b/internal/cli/config_report.go @@ -445,9 +445,11 @@ 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() { + // A user from before with a name no Linux account has (longer than 32 + // characters, or starting with a digit or '-'), or with upper case and a + // lower-case spelling a new user could not have: a warning with the + // rename that fixes it, once per user. + for _, fnd := range inv.userNameFindings() { r.found(howEchoE, " "+Y+"Names:"+NC+" "+fnd.String(), validateFinding{ Section: "names", Level: levelWarning, Text: fnd.Text, Fix: fnd.Fix}) } diff --git a/internal/cli/name_case.go b/internal/cli/name_case.go index c90d4244..ca082ee2 100644 --- a/internal/cli/name_case.go +++ b/internal/cli/name_case.go @@ -14,8 +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 (a user over -// names.UsernameMax is left to lengthFindings). Only the +// case, each with its fix, in that order and sorted within a kind (a user whose +// lower-case spelling is no name for a new user is left to userNameFindings). 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. @@ -85,10 +85,11 @@ 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 { + // A user whose lower-case spelling a new user could not have + // (over names.UsernameMax, or not starting with a letter, or + // reserved) is not offered it: 'user rename' would refuse it. + // userNameFindings names the rename for such a user, once. + if set.kind == "user" && names.CheckNewUsername(strings.ToLower(n)) != nil { continue } if names.HasUpper(n) { @@ -104,15 +105,22 @@ 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. 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 { +// userNameFindings are the users from before whose name a new user could not +// have and for whom caseFindings offers no lower-case rename: a name longer +// than names.UsernameMax or one that starts with a digit or '-' (a Linux +// account name does not: the user keeps working but has no account, here or on +// a host), and a name with upper case whose lower-case spelling 'user rename' +// would refuse (it starts with '_', which has an account but is not a letter, +// or is reserved). The rules are those of names.CheckNewUsername (the names +// are checked at 'user add' and 'user rename' only). They are warnings in +// 'config validate' with the verb that renames the user to a name of the +// person's choice, sorted by name, the superuser's view only. They carry no +// Kind, so 'config validate --fix-names' (case findings only) does not read +// them. A user that has several of these faults, upper case included, gets +// this one finding, which says so: the rename it names is the one that fixes +// all of them, and caseFindings leaves the user out, so that no finding +// proposes a rename that the creation rules refuse. +func (inv *invocation) userNameFindings() []hostFinding { if inv.callerScopes().restricted { return nil } @@ -120,24 +128,65 @@ func (inv *invocation) lengthFindings() []hostFinding { 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) + users := m.UserNames() + sort.Strings(users) var out []hostFinding - for _, n := range long { - also, andLower := "", "" - if names.HasUpper(n) { - also, andLower = " and has upper case letters", " and lower case" + for _, n := range users { + long := len(n) > names.UsernameMax + digit := names.StartsWithNoAccountChar(n) + upper := names.HasUpper(n) + var text string + switch { + case long || digit: + var has, rules []string + start := "starts with a digit" + if n[0] == '-' { + start = "starts with '-'" + } + switch { + case long: + has = append(has, "has a name of "+strconv.Itoa(len(n))+" characters") + rules = append(rules, "at most "+strconv.Itoa(names.UsernameMax)) + if digit { + has = append(has, start) + } + default: + has = append(has, "has a name that "+start) + } + if upper { + has = append(has, "has upper case letters") + rules = append(rules, "lower case") + } + var must []string + if len(rules) > 0 { + must = append(must, "are "+joinAnd(rules)) + } + if digit { + must = append(must, "start with a letter (a to z)") + } + text = "the user '" + n + "' " + strings.Join(has, " and ") + "; new user names " + strings.Join(must, " and ") + + ", and this user has no Linux account, here or on a host" + case upper: + // Only the lower-case spelling can be refused here: the user has an + // account (or a name another verb handles). + err := names.CheckNewUsername(strings.ToLower(n)) + if err == nil { + continue + } + text = "the user '" + n + "' has upper case letters; new user names are lower case, but its lower-case spelling '" + + strings.ToLower(n) + "' is not a name 'user rename' takes: " + strings.TrimSuffix(strings.SplitN(err.Error(), "\n", 2)[0], ".") + default: + continue } - out = append(out, hostFinding{ - 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 + " ", - }) + out = append(out, hostFinding{Text: text, Fix: "tacctl user rename " + n + " "}) } return out } + +// joinAnd joins phrases as "a", "a and b", "a, b and c". +func joinAnd(parts []string) string { + if len(parts) < 2 { + return strings.Join(parts, "") + } + return strings.Join(parts[:len(parts)-1], ", ") + " and " + parts[len(parts)-1] +} diff --git a/internal/cli/user.go b/internal/cli/user.go index b9cbe7b0..286a3538 100644 --- a/internal/cli/user.go +++ b/internal/cli/user.go @@ -468,16 +468,9 @@ func (inv *invocation) userAdd(args []string) error { if err := inv.requireStore(); err != nil { return err } - if err := names.ValidateUsername(username); err != nil { - return err - } - if err := names.RejectReservedUsername(username); err != nil { - return err - } - if err := names.RequireLower(username); err != nil { - return err - } - if err := names.RejectLongUsername(username); err != nil { + // A new name: the shape, the reserved names, upper case, the length and + // the first character, in that order (names.CheckNewUsername). + if err := names.CheckNewUsername(username); err != nil { return err } if err := inv.groupCheck(group, "Usage: tacctl user add "); err != nil { @@ -1078,12 +1071,12 @@ func (inv *invocation) userRename(args []string) error { if err := inv.requireStore(); err != nil { return err } + // The old name is any name that exists; the new one is a new name + // (names.CheckNewUsername: shape, reserved, upper case, length, first + // character). for _, check := range []func() error{ func() error { return names.ValidateUsername(oldname) }, - func() error { return names.ValidateUsername(newname) }, - func() error { return names.RejectReservedUsername(newname) }, - func() error { return names.RequireLower(newname) }, - func() error { return names.RejectLongUsername(newname) }, + func() error { return names.CheckNewUsername(newname) }, } { if err := check(); err != nil { return err diff --git a/internal/cli/user_firstletter_test.go b/internal/cli/user_firstletter_test.go new file mode 100644 index 00000000..5fde87cc --- /dev/null +++ b/internal/cli/user_firstletter_test.go @@ -0,0 +1,263 @@ +package cli + +// A new user name starts with a lower case letter (names.CheckNewUsername): +// every new user gets a Linux account, here and on the enrolled hosts. The rule +// is on the creation paths only ('user add' and the new name of 'user +// rename'): a user that exists as '9dave', '_svc' or '-x' (a store from an +// earlier release) keeps working, is restored as it is, and is warned of by +// 'config validate' when it has no Linux account. + +import ( + "strings" + "testing" + + "github.com/rett/tacctl/internal/hash" +) + +// letterWant is the refusal of a new name that does not start with a letter. +func letterWant(name string) string { + return "Username '" + name + "' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either)." +} + +// A digit, '-' and '_' are refused as the first character by 'user add' and +// by the new name of 'user rename', and nothing is changed; the order of the +// checks puts upper case first: 'Alice' and '1Alice' get the lower-case +// spelling, and the letter rule follows on the retry. +func TestNewUserNamesStartWithALetter(t *testing.T) { + sb := newSandbox(t, true) + before := sb.store() + for _, bad := range []string{"1alice", "9dave", "_svc", "_", "0", "1-a", "-x"} { + sb.run("", []string{"user", "add", bad, "operator", "--hash", testHash, "--scopes", "lab"}) + sb.expect(1, "", letterWant(bad)) + sb.run("", []string{"user", "rename", "bob", bad}) + sb.expect(1, "", letterWant(bad)) + } + if sb.store() != before { + t.Error("a refusal changed the store") + } + + // upper case first, then the letter rule on the retry + sb.run("", []string{"user", "add", "1Alice", "operator", "--hash", testHash, "--scopes", "lab"}) + sb.expect(1, "", "Names are lower case: use '1alice'. Nothing was changed.") + sb.run("", []string{"user", "add", "Alice", "operator", "--hash", testHash, "--scopes", "lab"}) + sb.expect(1, "", "Names are lower case: use 'alice'. Nothing was changed.") + sb.run("", []string{"user", "rename", "bob", "_Svc"}) + sb.expect(1, "", "Names are lower case: use '_svc'. Nothing was changed.") + // the length comes before the first character + long := "1" + strings.Repeat("a", 40) + sb.run("", []string{"user", "add", long, "operator", "--hash", testHash, "--scopes", "lab"}) + sb.expect(1, "", longWant(long)) + if sb.store() != before { + t.Error("a refusal changed the store") + } + + for _, ok := range []string{"a", "alice2", "a_b-c", "z9"} { + sb.run("", []string{"user", "add", ok, "operator", "--hash", testHash, "--scopes", "lab"}) + sb.expect(0, "User '"+ok+"' added", "") + } + sb.run("", []string{"user", "rename", "bob", "robert-2"}) + sb.expect(0, "User renamed: bob -> robert-2", "") +} + +// A user that exists with a name a new user could not have is shown, changed, +// renamed away to a good name and removed as ever, and a snapshot with such +// users is restored as it was: the first-character rule is not part of the +// check every verb runs. +func TestUsersWithAnyFirstCharacterKeepWorking(t *testing.T) { + h, err := hash.Generate("CorrectHorse99", 4) + if err != nil { + t.Fatal(err) + } + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " 9dave:") + sb.legacyStoreCase(" bob:", " _svc:") + for _, name := range []string{"9dave", "_svc"} { + sb.run("", []string{"user", "show", name}) + sb.expect(0, name, "") + sb.run("", []string{"user", "passwd", name, "--hash", h}) + sb.expect(0, "Password changed for '"+name+"'.", "") + sb.run("CorrectHorse99\n", []string{"user", "verify", name}) + sb.expect(0, "Password is correct.", "") + sb.run("", []string{"user", "disable", name}) + sb.expect(0, "", "") + sb.run("", []string{"user", "enable", name}) + sb.expect(0, "", "") + } + sb.run("", []string{"user", "list"}) + sb.expect(0, "9dave", "") + + // renamed away to a name a new user can have; the new name is checked, the old is not + sb.run("", []string{"user", "rename", "9dave", "dave"}) + sb.expect(0, "User renamed: 9dave -> dave", "") + sb.run("", []string{"user", "rename", "_svc", "9svc"}) + sb.expect(1, "", letterWant("9svc")) + sb.run("", []string{"user", "rename", "_svc", "svc"}) + sb.expect(0, "User renamed: _svc -> svc", "") + + sb2 := newSandbox(t, true) + sb2.legacyStoreCase(" alice:", " 9dave:") + sb2.run("y\n", []string{"user", "remove", "9dave"}) + sb2.expect(0, "", "") + if strings.Contains(sb2.store(), "9dave") { + t.Errorf("the store after the removal:\n%s", sb2.store()) + } + + sb3 := renderedSandbox(t) + snap := strings.ReplaceAll(strings.ReplaceAll(fixture(t, "store.multiscope.yaml"), " alice:", " 9dave:"), " bob:", " _svc:") + sb3.mkSnapshot("20200101_000000_001", snap, "") + sb3.run("y\n", []string{"backup", "restore", "20200101_000000_001"}) + sb3.expect(0, "Restored snapshot 20200101_000000_001.", "") + if sb3.read("state/store.yaml") != snap { + t.Errorf("the store is not the snapshot's:\n%s", sb3.read("state/store.yaml")) + } + sb3.run("", []string{"user", "show", "9dave"}) + sb3.expect(0, "9dave", "") +} + +// namesFindingsOf are the lines of the report of 'config validate' that are +// findings of the names section, and the findings of its json. +func namesFindingsOf(t *testing.T, sb *sandbox) (text string, found []validateFinding) { + t.Helper() + sb.run("", []string{"config", "validate"}) + text = plain(sb.out.String()) + v := validateJSONOf(t, sb.run("", []string{"config", "validate", "--json"})) + for _, f := range v.Findings { + if f.Section == "names" { + found = append(found, f) + } + } + return text, found +} + +// A user that exists with a name that starts with a digit gets one warning, that +// it has no Linux account and the rename that fixes it; '_svc' has an account +// and gets none; nothing is fixed automatically. +func TestConfigValidateWarnsOfAUserWithNoLinuxAccountName(t *testing.T) { + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " 1alice:") + sb.legacyStoreCase(" bob:", " _svc:") + sb.run("", []string{"config", "render"}) + sb.expect(0, "", "") + out, found := namesFindingsOf(t, sb) + want := "the user '1alice' has a name that starts with a digit; new user names start with a letter (a to z), and this user has no Linux account, here or on a host (tacctl user rename 1alice )" + if !strings.Contains(out, want) { + t.Errorf("config validate lacks %q:\n%s", want, out) + } + if strings.Contains(out, "_svc") { + t.Errorf("a name that starts with '_' is warned of:\n%s", out) + } + if len(found) != 1 || found[0].Fix != "tacctl user rename 1alice " || found[0].Kind != "" || found[0].Level != levelWarning { + t.Errorf("the json names findings: %+v", found) + } + before := sb.store() + 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 || strings.Contains(sb.printed(), "Rename user") { + t.Errorf("--fix-names changed something:\n%s", sb.printed()) + } +} + +// A name that starts with '-' is warned of the same way, saying so. +func TestConfigValidateWarnsOfAUserStartingWithAHyphen(t *testing.T) { + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " -x:") + sb.run("", []string{"config", "render"}) + sb.expect(0, "", "") + out, found := namesFindingsOf(t, sb) + want := "the user '-x' has a name that starts with '-'; new user names start with a letter (a to z), and this user has no Linux account, here or on a host (tacctl user rename -x )" + if !strings.Contains(out, want) || len(found) != 1 { + t.Errorf("config validate lacks %q (%d json findings):\n%s", want, len(found), out) + } +} + +// '1Alice' has upper case and starts with a digit: its lower-case spelling +// would be refused by 'user rename', so --fix-names does not offer it and the +// one finding names the rename, with both faults; 'Alice' followed by 41 +// characters has the same. Neither is counted as failed or not offered, and +// the run ends with status 0. A plain 'Alice' next to them is still offered +// its lower-case spelling. +func TestUpperCaseNamesThatCannotBeLowerCasedAreOneFindingEach(t *testing.T) { + long := "Alice" + strings.Repeat("a", 41) + for _, c := range []struct{ name, want string }{ + {"1Alice", "the user '1Alice' has a name that starts with a digit and has upper case letters; new user names are lower case and start with a letter (a to z), and this user has no Linux account, here or on a host (tacctl user rename 1Alice )"}, + {long, "the user '" + long + "' has a name of 46 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 + " )"}, + {"1Alice" + strings.Repeat("a", 41), "the user '1Alice" + strings.Repeat("a", 41) + "' has a name of 47 characters and starts with a digit and has upper case letters; new user names are at most 32 and lower case and start with a letter (a to z), and this user has no Linux account, here or on a host (tacctl user rename 1Alice" + strings.Repeat("a", 41) + " )"}, + } { + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " "+c.name+":") + sb.legacyStoreCase(" bob:", " Bobby:") + sb.run("", []string{"config", "render"}) + sb.expect(0, "", "") + + out, found := namesFindingsOf(t, sb) + if n := strings.Count(out, "'"+c.name+"'"); n != 1 { + t.Errorf("%s: %d findings name the user, want 1:\n%s", c.name, n, out) + } + if strings.Contains(out, "rename "+c.name+" "+strings.ToLower(c.name)) { + t.Errorf("%s: the lower-case rename is proposed:\n%s", c.name, out) + } + if !strings.Contains(out, c.want) { + t.Errorf("config validate lacks %q:\n%s", c.want, out) + } + // the plain upper case user keeps its finding, with the fix --fix-names runs + if !strings.Contains(out, "the user 'Bobby' has upper case in its name") { + t.Errorf("Bobby lost its finding:\n%s", out) + } + var ofName, ofBobby int + for _, f := range found { + switch { + case strings.Contains(f.Text, "'"+c.name+"'"): + ofName++ + if f.Fix != "tacctl user rename "+c.name+" " || f.Kind != "" { + t.Errorf("%s: the json finding: %+v", c.name, f) + } + case strings.Contains(f.Text, "'Bobby'"): + ofBobby++ + if f.Fix != "tacctl user rename Bobby bobby" { + t.Errorf("Bobby's json finding: %+v", f) + } + } + } + if ofName != 1 || ofBobby != 1 { + t.Errorf("%s: json findings %d and %d: %+v", c.name, ofName, ofBobby, found) + } + + sb.run("", []string{"config", "validate", "--fix-names", "--yes"}) + sb.expect(0, "Names: renamed 1, declined 0, not offered 0, failed 0.", "") + store := sb.store() + if !strings.Contains(store, " "+c.name+":") || !strings.Contains(store, " bobby:") { + t.Errorf("%s: the store after --fix-names:\n%s", c.name, store) + } + if strings.Contains(sb.printed(), "Rename user '"+c.name+"'") { + t.Errorf("%s: a rename was offered:\n%s", c.name, sb.printed()) + } + // and the same run only with the user: nothing to offer, status 0 + sb.run("", []string{"config", "validate", "--fix-names", "--yes"}) + sb.expect(0, "Names: renamed 0, declined 0, not offered 0, failed 0.", "") + } +} + +// A user with upper case whose name starts with '_' has an account, but the +// rename to its lower-case spelling would be refused: it gets one finding that +// says so and names the rename with a name of the person's choice, and +// --fix-names offers nothing. +func TestUpperCaseNameStartingWithAnUnderscoreIsNotOfferedTheLowerCaseSpelling(t *testing.T) { + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " _Svc:") + sb.run("", []string{"config", "render"}) + sb.expect(0, "", "") + out, found := namesFindingsOf(t, sb) + want := "the user '_Svc' has upper case letters; new user names are lower case, but its lower-case spelling '_svc' is not a name 'user rename' takes: " + strings.TrimSuffix(letterWant("_svc"), ".") + " (tacctl user rename _Svc )" + if !strings.Contains(out, want) || strings.Count(out, "'_Svc'") != 1 { + t.Errorf("config validate lacks %q:\n%s", want, out) + } + if len(found) != 1 || found[0].Kind != "" || found[0].Fix != "tacctl user rename _Svc " { + t.Errorf("the json names findings: %+v", found) + } + before := sb.store() + 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 { + t.Error("--fix-names changed the store") + } +} diff --git a/internal/cli/user_no_dots_test.go b/internal/cli/user_no_dots_test.go index a42d71bf..8a17c51f 100644 --- a/internal/cli/user_no_dots_test.go +++ b/internal/cli/user_no_dots_test.go @@ -37,8 +37,8 @@ func TestNewUserNamesHaveNoPeriods(t *testing.T) { sb.expect(1, "", noDotsWant) sb.run("", []string{"user", "rename", "bob", "root"}) sb.expect(1, "", "Username 'root' is reserved") - // The names that are letters, digits, '_' and '-' still go. - for _, name := range []string{"alice-smith", "a_b-c_d", "15", "j_smith2"} { + // The names that start with a letter, then letters, digits, '_' and '-', still go. + for _, name := range []string{"alice-smith", "a_b-c_d", "j15", "j_smith2"} { sb.run("", []string{"user", "add", name, "operator", "--hash", testHash, "--scopes", "lab"}) sb.expect(0, "[INFO] User '"+name+"' added (operator) with scopes: lab", "") } diff --git a/internal/cli/user_notice_test.go b/internal/cli/user_notice_test.go index 481ad78e..d38fd167 100644 --- a/internal/cli/user_notice_test.go +++ b/internal/cli/user_notice_test.go @@ -245,12 +245,29 @@ func TestUserChangeNamesNoHostWhoseAccountStaysAsItWas(t *testing.T) { } } -// A name that is no Linux account name has no account on any host. -func TestUserAddOfANameWithNoLinuxAccountNamesNoHost(t *testing.T) { +// A name that is no Linux account name is refused for a new user ('user add' +// and the new name of 'user rename'; internal/cli/user_firstletter_test.go), +// and a user from before with such a name has no account on any host: the +// verbs that change it name no host and offer no sync. +func TestUserOfANameWithNoLinuxAccountNamesNoHost(t *testing.T) { hs := userHostsSandbox(t) hs.run(hs.localRunner(), "user", "add", "9dave", "operator", "--hash", hashOf(t, "CorrectHorse99"), "--scopes", "lab") all := plain(hs.out.String() + hs.err.String()) - if hs.code != 0 || !strings.Contains(all, "User '9dave' added") || strings.Contains(all, "web1") || strings.Contains(all, "enrolled host") { + if hs.code != 1 || !strings.Contains(all, "Username '9dave' must start with a letter (a to z)") || strings.Contains(all, "web1") || strings.Contains(all, "enrolled host") { + t.Errorf("%d\n%s", hs.code, all) + } + hs.run(hs.localRunner(), "user", "rename", "bob", "9dave") + all = plain(hs.out.String() + hs.err.String()) + if hs.code != 1 || !strings.Contains(all, "Username '9dave' must start with a letter (a to z)") || strings.Contains(all, "web1") { + t.Errorf("%d\n%s", hs.code, all) + } + + // the user from before: the store of an earlier release has it + hs.legacyStoreCase(" bob:", " 9dave:") + hs.answerOn("n\n") + hs.run(hs.localRunner(), "user", "passwd", "9dave", "--hash", hashOf(t, "CorrectHorse99")) + all = plain(hs.out.String() + hs.err.String()) + if hs.code != 0 || !strings.Contains(all, "Password changed for '9dave'") || strings.Contains(all, "web1") || strings.Contains(all, "enrolled host") || strings.Contains(all, "Sync these hosts now") { t.Errorf("%d\n%s", hs.code, all) } } diff --git a/internal/names/names.go b/internal/names/names.go index dc983c83..622923f5 100644 --- a/internal/names/names.go +++ b/internal/names/names.go @@ -172,6 +172,47 @@ func RejectLongUsername(value string) error { return nil } +// RejectNonLetterUsername is the first-character check of the creation paths +// ('user add' and the new name of 'user rename'): a new user name starts with a +// lower case letter, a to z. Every new user gets a Linux account on the tacctl +// server and on the enrolled hosts, and a name that starts with a digit or '-' +// is no Linux account name; Linux itself allows a leading '_', the project does +// not for a new name, so that every new name is an account name on every +// system. It is not part of ValidateUsername, which every verb runs: a user +// that exists as '9dave', '_svc' or '-x' is shown, changed, renamed away and +// removed as before. An upper case first letter is the business of +// RequireLower, which comes first in CheckNewUsername and suggests the lower +// case spelling. +func RejectNonLetterUsername(value string) error { + if value == "" || value[0] < 'a' || value[0] > 'z' { + return fail(fmt.Sprintf("Username '%s' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either).", value)) + } + return nil +} + +// StartsWithNoAccountChar reports whether the name of an existing user starts +// with a digit or '-': no Linux account name does (a leading '_' is one, so a +// user named '_svc' has an account). 'config validate' warns of such a user. +func StartsWithNoAccountChar(value string) bool { + return value != "" && (value[0] == '-' || (value[0] >= '0' && value[0] <= '9')) +} + +// CheckNewUsername is the whole check of a name a user is created with, by +// 'user add' and by the new name of 'user rename', in this order: the shape +// (ValidateUsername), the reserved names, upper case (RequireLower, so that +// 'Alice' gets the lower case spelling suggested and '1Alice' is first told +// the same, the letter rule following on the retry), the length and the first +// character. The first failing check is the answer. Existing users are never +// checked with it: ValidateUsername is what every other verb runs. +func CheckNewUsername(value string) error { + for _, check := range []func(string) error{ValidateUsername, RejectReservedUsername, RequireLower, RejectLongUsername, RejectNonLetterUsername} { + if err := check(value); err != nil { + return err + } + } + 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 4086719a..3a4f2fb7 100644 --- a/internal/names/names_test.go +++ b/internal/names/names_test.go @@ -353,3 +353,65 @@ func TestMatchersStillTakeUpperCase(t *testing.T) { t.Error("an existing name with upper case no longer matches") } } + +// --- the first character of a new user name --- + +func TestRejectNonLetterUsername(t *testing.T) { + for _, s := range []string{"a", "alice", "z9", "a_b-c", strings.Repeat("a", UsernameMax)} { + if err := RejectNonLetterUsername(s); err != nil { + t.Errorf("%q: %v", s, err) + } + } + for _, s := range []string{"1alice", "9dave", "0", "-x", "_svc", "_", "-", "A", "Alice", ""} { + var e *Error + want := "Username '" + s + "' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either)." + if !errors.As(RejectNonLetterUsername(s), &e) || len(e.Lines()) != 1 || e.Lines()[0] != want { + t.Errorf("%q: %v", s, e) + } + } + // ValidateUsername, which every verb runs, takes a user from before. + for _, s := range []string{"9dave", "_svc", "-x", "Alice"} { + if err := ValidateUsername(s); err != nil { + t.Errorf("ValidateUsername refuses %q: %v", s, err) + } + } +} + +func TestStartsWithNoAccountChar(t *testing.T) { + for s, want := range map[string]bool{"1a": true, "9dave": true, "-x": true, "_svc": false, "alice": false, "Alice": false, "": false} { + if got := StartsWithNoAccountChar(s); got != want { + t.Errorf("%q: %v", s, got) + } + } +} + +// CheckNewUsername runs the checks in a fixed order: the shape, the reserved +// names, upper case (the lower-case spelling is suggested first), the length, +// then the first character. +func TestCheckNewUsernameOrder(t *testing.T) { + long := strings.Repeat("a", 40) + for _, c := range []struct{ name, want string }{ + {"alice", ""}, + {"a1_-", ""}, + {"j.smith", usernameShape}, + {"root", "Username 'root' is reserved as an accounting-only sink"}, + {"tacquito", "Username 'tacquito' is reserved"}, + {"Alice", "Names are lower case: use 'alice'. Nothing was changed."}, + {"1Alice", "Names are lower case: use '1alice'. Nothing was changed."}, + {"1" + long, "Username '1" + long + "' is 41 characters"}, + {"1alice", "Username '1alice' must start with a letter (a to z)"}, + {"_svc", "Username '_svc' must start with a letter (a to z)"}, + {"-x", "Username '-x' must start with a letter (a to z)"}, + } { + err := CheckNewUsername(c.name) + if c.want == "" { + if err != nil { + t.Errorf("%q: %v", c.name, err) + } + continue + } + if err == nil || !strings.HasPrefix(err.Error(), c.want) { + t.Errorf("%q: %v, want %q", c.name, err, c.want) + } + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index f3378d77..de4fbb62 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -1704,7 +1704,8 @@ Requires: \fBreadonly\fR. .\" END GENERATED: command user show .TP .BI "user add " "name group " [ "--hash " hash ] [ "--scopes " name[,name...] ] [ "--email " address ] [ --no\-change\-required ] -Add a user. The name is lower case (lower\-case letters, digits, +Add a user. The name is lower case and starts with a letter (a lower\-case letter, +then lower\-case letters, digits, .BR _ " and " \- ): 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 @@ -1722,9 +1723,27 @@ case letters or starts with a digit or .BR \- : a Linux account name starts with a lower case letter or .BR _ , +but every new user gets an account, so a new name must start with a lower case +letter, a to z: a digit, +.B \- and -.B "user add" -still accepts a name that starts with a digit or +.B _ +are refused as the first character +.RB ( "Username '1alice' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either)." ), +and nothing is changed. The checks run in this order and the first that fails is +the answer: the shape, the reserved names, upper case (so +.B Alice +and +.B 1Alice +are told the lower case spelling first), the length and the first character. A +user that exists as +.BR 9dave , +.B _svc +or +.B \-x +keeps working as it is; only a new name is checked, and +.B "config validate" +warns of an existing 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 @@ -2068,7 +2087,7 @@ 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, at most 32 characters, and follows the rules of +setting moves to the new name, and the command says so. The new name is lower case, starts with a letter, is at most 32 characters, and follows the rules of .BR "user add" ; 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). @@ -3264,15 +3283,26 @@ 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. A user from -an earlier release whose name is longer than 32 characters (a new name is at -most 32) is a warning under +an earlier release whose name is longer than 32 characters or starts with a +digit or +.B \- +(a new name is at most 32 and starts with a lower case letter) 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. 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. +does not offer that rename. A name that starts with +.B _ +has an account and is not warned of. A user with several of these faults, upper +case included, gets that one warning only, which says so: the lower case +spelling would be refused by +.B "user rename" +too, so no warning proposes it, and +.B \-\-fix\-names +offers nothing for the user and counts it as neither not offered nor failed. So +does a user with upper case and a name that starts with +.BR _ . +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 8ba856f28d9b6e3b0cb3ea1cdc93462698830e41 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 00:29:26 -0900 Subject: [PATCH 03/27] test: a user from before with no Linux account name names no host The host-notice filter in otherHostsWith (a name that is no Linux account name has no account on any host) lost its test when the 'user add' case became a refusal: 'user passwd' returns at its barrier before the filter. The table now runs the verbs that reach afterUserChange (disable, enable, move, scope, remove, rename away, require-password-change) on a stored '9dave' in the scope of an enrolled host: each must exit 0 and name no host and offer no sync. Dropping the LinuxName check from otherHostsWith makes disable, enable, move, scope and remove fail. --- internal/cli/user_notice_test.go | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/internal/cli/user_notice_test.go b/internal/cli/user_notice_test.go index d38fd167..e2f5fd67 100644 --- a/internal/cli/user_notice_test.go +++ b/internal/cli/user_notice_test.go @@ -272,6 +272,45 @@ func TestUserOfANameWithNoLinuxAccountNamesNoHost(t *testing.T) { } } +// The verbs that reach afterUserChange for a user from before whose name is no +// Linux account name (otherHostsWith drops such a name): the same store with +// bob as '9dave', who is in the scope of the enrolled host web1 and would be +// named for any other name. 'user passwd' returns before it gets there +// (the barrier), so it does not cover the filter. +func TestUserVerbsOfANameWithNoLinuxAccountNameNoHost(t *testing.T) { + for _, c := range []struct { + name string + setup []string + args []string + stdin string + }{ + {name: "disable", args: []string{"user", "disable", "9dave"}}, + {name: "enable", setup: []string{"user", "disable", "9dave"}, args: []string{"user", "enable", "9dave"}}, + {name: "move", args: []string{"user", "move", "9dave", "readonly"}}, + {name: "scope", args: []string{"user", "scope", "9dave", "replace", "prod"}}, + {name: "require-password-change", args: []string{"user", "require-password-change", "9dave"}}, + {name: "remove", args: []string{"user", "remove", "9dave"}, stdin: "y\n"}, + {name: "rename away", args: []string{"user", "rename", "9dave", "dave"}}, + } { + t.Run(c.name, func(t *testing.T) { + hs := userHostsSandbox(t) + hs.legacyStoreCase(" bob:", " 9dave:") + if c.setup != nil { + hs.run(hs.localRunner(), c.setup...) + if hs.code != 0 { + t.Fatalf("%v: %d\n%s%s", c.setup, hs.code, hs.out.String(), hs.err.String()) + } + } + hs.stdin = c.stdin + hs.run(hs.localRunner(), c.args...) + all := plain(hs.out.String() + hs.err.String()) + if hs.code != 0 || strings.Contains(all, "web1") || strings.Contains(all, "enrolled host") || strings.Contains(all, "Sync these hosts now") || hs.pushed != "" { + t.Errorf("%d, pushed %q\n%s", hs.code, hs.pushed, all) + } + }) + } +} + // A rename to a name that has a UID of its own: the hosts remove the old // account and create the new one, and are named, with the command and the // offer. From 1f7015cb06fcfc3e5d1ae692ceda6c730935ac20 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 00:30:17 -0900 Subject: [PATCH 04/27] comments: the rollback target lists reach 0.2.29, an upper case name has no account The comments of the lockdown-on-hosts and firewall rollback steps listed the targets that keep their parts as 0.2.28 and older; 0.2.29 keeps them too (the code does, and a test pins it). The comments on the user-name findings said a user with upper case has an account; a Linux account name is lower case, so such a user has none. Comments only, no behaviour change. --- internal/cli/name_case.go | 9 +++++---- internal/cli/user_firstletter_test.go | 7 ++++--- internal/lifecycle/rollback_firewall.go | 2 +- internal/lifecycle/rollback_lockdown_hosts.go | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/internal/cli/name_case.go b/internal/cli/name_case.go index ca082ee2..f2de6c89 100644 --- a/internal/cli/name_case.go +++ b/internal/cli/name_case.go @@ -110,8 +110,8 @@ func (inv *invocation) caseFindings() []hostFinding { // than names.UsernameMax or one that starts with a digit or '-' (a Linux // account name does not: the user keeps working but has no account, here or on // a host), and a name with upper case whose lower-case spelling 'user rename' -// would refuse (it starts with '_', which has an account but is not a letter, -// or is reserved). The rules are those of names.CheckNewUsername (the names +// would refuse (it starts with '_', which Linux would take but a new name does +// not, or is reserved). The rules are those of names.CheckNewUsername (the names // are checked at 'user add' and 'user rename' only). They are warnings in // 'config validate' with the verb that renames the user to a name of the // person's choice, sorted by name, the superuser's view only. They carry no @@ -167,8 +167,9 @@ func (inv *invocation) userNameFindings() []hostFinding { text = "the user '" + n + "' " + strings.Join(has, " and ") + "; new user names " + strings.Join(must, " and ") + ", and this user has no Linux account, here or on a host" case upper: - // Only the lower-case spelling can be refused here: the user has an - // account (or a name another verb handles). + // The name has upper case, so the user has no Linux account (a + // Linux account name is lower case); only the lower-case spelling + // can be refused here, and 'user rename' would refuse it. err := names.CheckNewUsername(strings.ToLower(n)) if err == nil { continue diff --git a/internal/cli/user_firstletter_test.go b/internal/cli/user_firstletter_test.go index 5fde87cc..56b55816 100644 --- a/internal/cli/user_firstletter_test.go +++ b/internal/cli/user_firstletter_test.go @@ -237,9 +237,10 @@ func TestUpperCaseNamesThatCannotBeLowerCasedAreOneFindingEach(t *testing.T) { } } -// A user with upper case whose name starts with '_' has an account, but the -// rename to its lower-case spelling would be refused: it gets one finding that -// says so and names the rename with a name of the person's choice, and +// A user with upper case whose name starts with '_' has no account (a Linux +// account name is lower case), and the rename to its lower-case spelling, which +// would be one, is refused because a new name starts with a letter: it gets one +// finding that says so and names the rename with a name of the person's choice, and // --fix-names offers nothing. func TestUpperCaseNameStartingWithAnUnderscoreIsNotOfferedTheLowerCaseSpelling(t *testing.T) { sb := newSandbox(t, true) diff --git a/internal/lifecycle/rollback_firewall.go b/internal/lifecycle/rollback_firewall.go index e1bba438..9c2f65d1 100644 --- a/internal/lifecycle/rollback_firewall.go +++ b/internal/lifecycle/rollback_firewall.go @@ -5,7 +5,7 @@ package lifecycle // conf.Added0224 lists so that the key list of every target but 0.2.29, 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.28, 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.29, 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 01e09faf..02bd2cd7 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.28, 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.29, 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, From 748b16407ea27c39a854efc16891d201c2731324 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 00:36:57 -0900 Subject: [PATCH 05/27] user: a name with upper case is refused with a name that is accepted CheckNewUsername put the upper case check first, so '1Alice' was told to use '1alice', and the retry was refused by the letter rule; the same for '_Alice', 'Root' (reserved) and an upper case name over 32 characters. The lower-case message is now given only when the lower-case spelling passes every other check, so that the suggestion is a name the command takes. Otherwise the answer is the first check the lower-case spelling fails, said with the name as typed and with "lower case" among what to fix: the reserved name ('root', 'tacquito'), the length (plus "Names are lower case as well."), or "must be lower case and start with a letter". A name with no upper case is checked in the order it had: shape, reserved, length, first character. A stored user whose name starts with '_' and is over 32 characters is now told the letter rule as well as the length in the 'config validate' finding, so that a replacement such as '_svc' is not refused next. Tests: the order table, the suggestion being accepted itself, the user add and rename refusals, the over-long '_' finding, the findings of a stored 'Root' and 'Tacquito' (text, json, --fix-names: one finding, nothing offered), and a stored '-x' through show, passwd, disable, move, rename away and remove (a bare word works; '--' is not an end-of-options marker of the user verbs). --- internal/cli/name_case.go | 16 ++- internal/cli/user_firstletter_test.go | 182 ++++++++++++++++++++++++-- internal/names/names.go | 65 ++++++--- internal/names/names_test.go | 32 ++++- 4 files changed, 261 insertions(+), 34 deletions(-) diff --git a/internal/cli/name_case.go b/internal/cli/name_case.go index f2de6c89..c786362b 100644 --- a/internal/cli/name_case.go +++ b/internal/cli/name_case.go @@ -109,7 +109,8 @@ func (inv *invocation) caseFindings() []hostFinding { // have and for whom caseFindings offers no lower-case rename: a name longer // than names.UsernameMax or one that starts with a digit or '-' (a Linux // account name does not: the user keeps working but has no account, here or on -// a host), and a name with upper case whose lower-case spelling 'user rename' +// a host; a long name that starts with '_' is told the letter rule as well, so +// that its replacement is not refused), and a name with upper case whose lower-case spelling 'user rename' // would refuse (it starts with '_', which Linux would take but a new name does // not, or is reserved). The rules are those of names.CheckNewUsername (the names // are checked at 'user add' and 'user rename' only). They are warnings in @@ -134,20 +135,27 @@ func (inv *invocation) userNameFindings() []hostFinding { for _, n := range users { long := len(n) > names.UsernameMax digit := names.StartsWithNoAccountChar(n) + // A name that starts with '_' has an account if it is short enough and + // has no upper case; one that is over the length is told the letter rule + // as well, or a natural replacement such as '_svc' would be refused. + under := long && n[0] == '_' upper := names.HasUpper(n) var text string switch { case long || digit: var has, rules []string start := "starts with a digit" - if n[0] == '-' { + switch n[0] { + case '-': start = "starts with '-'" + case '_': + start = "starts with '_'" } switch { case long: has = append(has, "has a name of "+strconv.Itoa(len(n))+" characters") rules = append(rules, "at most "+strconv.Itoa(names.UsernameMax)) - if digit { + if digit || under { has = append(has, start) } default: @@ -161,7 +169,7 @@ func (inv *invocation) userNameFindings() []hostFinding { if len(rules) > 0 { must = append(must, "are "+joinAnd(rules)) } - if digit { + if digit || under { must = append(must, "start with a letter (a to z)") } text = "the user '" + n + "' " + strings.Join(has, " and ") + "; new user names " + strings.Join(must, " and ") + diff --git a/internal/cli/user_firstletter_test.go b/internal/cli/user_firstletter_test.go index 56b55816..f4af6b01 100644 --- a/internal/cli/user_firstletter_test.go +++ b/internal/cli/user_firstletter_test.go @@ -19,10 +19,18 @@ func letterWant(name string) string { return "Username '" + name + "' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either)." } +// upperLetterWant is the refusal of a new name that has upper case and does not +// start with a letter: it names both. +func upperLetterWant(name string) string { + return "Username '" + name + "' must be lower case and start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either)." +} + // A digit, '-' and '_' are refused as the first character by 'user add' and -// by the new name of 'user rename', and nothing is changed; the order of the -// checks puts upper case first: 'Alice' and '1Alice' get the lower-case -// spelling, and the letter rule follows on the retry. +// by the new name of 'user rename', and nothing is changed. A name with upper +// case is told to be lower case only when its lower-case spelling would be +// accepted ('Alice'); otherwise it is told what to fix at once, so that the +// retry is not refused again ('1Alice', '_Svc', 'Root', 'Tacquito', an upper +// case name over the length). func TestNewUserNamesStartWithALetter(t *testing.T) { sb := newSandbox(t, true) before := sb.store() @@ -36,17 +44,31 @@ func TestNewUserNamesStartWithALetter(t *testing.T) { t.Error("a refusal changed the store") } - // upper case first, then the letter rule on the retry - sb.run("", []string{"user", "add", "1Alice", "operator", "--hash", testHash, "--scopes", "lab"}) - sb.expect(1, "", "Names are lower case: use '1alice'. Nothing was changed.") + // the lower-case spelling is suggested only when it is accepted sb.run("", []string{"user", "add", "Alice", "operator", "--hash", testHash, "--scopes", "lab"}) sb.expect(1, "", "Names are lower case: use 'alice'. Nothing was changed.") - sb.run("", []string{"user", "rename", "bob", "_Svc"}) - sb.expect(1, "", "Names are lower case: use '_svc'. Nothing was changed.") - // the length comes before the first character - long := "1" + strings.Repeat("a", 40) - sb.run("", []string{"user", "add", long, "operator", "--hash", testHash, "--scopes", "lab"}) - sb.expect(1, "", longWant(long)) + sb.run("", []string{"user", "rename", "bob", "Robert"}) + sb.expect(1, "", "Names are lower case: use 'robert'. Nothing was changed.") + upperLong := "A" + strings.Repeat("a", 40) + for _, c := range []struct{ name, want string }{ + {"1Alice", upperLetterWant("1Alice")}, + {"_Svc", upperLetterWant("_Svc")}, + {"-X", upperLetterWant("-X")}, + {"Root", "Username 'root' is reserved as an accounting-only sink"}, + {"ROOT", "Username 'root' is reserved as an accounting-only sink"}, + {"Tacquito", "Username 'tacquito' is reserved"}, + {upperLong, longWant(upperLong) + " Names are lower case as well."}, + // the length comes before the first character + {"1" + strings.Repeat("a", 40), longWant("1" + strings.Repeat("a", 40))}, + } { + sb.run("", []string{"user", "add", c.name, "operator", "--hash", testHash, "--scopes", "lab"}) + sb.expect(1, "", c.want) + sb.run("", []string{"user", "rename", "bob", c.name}) + sb.expect(1, "", c.want) + if strings.Contains(sb.printed(), "Names are lower case: use") { + t.Errorf("%s: a lower-case spelling is suggested:\n%s", c.name, sb.printed()) + } + } if sb.store() != before { t.Error("a refusal changed the store") } @@ -114,6 +136,49 @@ func TestUsersWithAnyFirstCharacterKeepWorking(t *testing.T) { sb3.expect(0, "9dave", "") } +// A user stored as '-x' is reached by the verbs as an ordinary word, typed as +// it is ('tacctl user show -x'): the command line takes a word that starts with +// '-' and is no option of the verb as a positional. '--' is not an end-of-options +// marker of the user verbs (it would be read as the user name), so there is no +// other form. A new name of that shape is refused ('user rename' to '-x'). +func TestUserStoredWithALeadingHyphenKeepsWorking(t *testing.T) { + h, err := hash.Generate("CorrectHorse99", 4) + if err != nil { + t.Fatal(err) + } + for _, c := range []struct { + name string + args []string + stdin string + out string + store func(string) bool // what the store must satisfy afterwards + }{ + {name: "show", args: []string{"user", "show", "-x"}, out: "-x"}, + {name: "passwd", args: []string{"user", "passwd", "-x", "--hash", h}, out: "Password changed for '-x'."}, + {name: "disable", args: []string{"user", "disable", "-x"}, out: "User '-x' disabled."}, + {name: "move", args: []string{"user", "move", "-x", "readonly"}, out: "User '-x' moved: superuser -> readonly"}, + {name: "rename away", args: []string{"user", "rename", "-x", "xx"}, out: "User renamed: -x -> xx", + store: func(st string) bool { return !strings.Contains(st, " -x:") && strings.Contains(st, " xx:") }}, + {name: "remove", args: []string{"user", "remove", "-x"}, stdin: "y\n", out: "User '-x' removed.", + store: func(st string) bool { return !strings.Contains(st, " -x:") }}, + } { + t.Run(c.name, func(t *testing.T) { + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " -x:") + sb.run(c.stdin, c.args) + sb.expect(0, c.out, "") + if c.store != nil && !c.store(sb.store()) { + t.Errorf("the store after %v:\n%s", c.args, sb.store()) + } + }) + } + // there is no end-of-options form: '--' is taken for the user name + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " -x:") + sb.run("", []string{"user", "show", "--", "-x"}) + sb.expect(1, "", "User '--' does not exist.") +} + // namesFindingsOf are the lines of the report of 'config validate' that are // findings of the names section, and the findings of its json. func namesFindingsOf(t *testing.T, sb *sandbox) (text string, found []validateFinding) { @@ -262,3 +327,96 @@ func TestUpperCaseNameStartingWithAnUnderscoreIsNotOfferedTheLowerCaseSpelling(t t.Error("--fix-names changed the store") } } + +// A user from before whose name starts with '_' and is over the length is told +// both rules: a natural replacement such as '_svc' would be refused by the +// letter rule. A short '_svc' is not warned of, and a long name that starts +// with a letter is told the length only. +func TestOverLongNameStartingWithAnUnderscoreIsToldTheLetterRule(t *testing.T) { + long := "_" + strings.Repeat("a", 39) + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " "+long+":") + sb.legacyStoreCase(" bob:", " "+strings.Repeat("b", 40)+":") + sb.run("", []string{"config", "render"}) + sb.expect(0, "", "") + out, found := namesFindingsOf(t, sb) + want := "the user '" + long + "' has a name of 40 characters and starts with '_'; new user names are at most 32 and start with a letter (a to z), 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) + } + wantB := "the user '" + strings.Repeat("b", 40) + "' has a name of 40 characters; new user names are at most 32, and this user has no Linux account, here or on a host" + if !strings.Contains(out, wantB) { + t.Errorf("config validate lacks %q:\n%s", wantB, out) + } + if len(found) != 2 { + t.Errorf("the json names findings: %+v", found) + } + before := sb.store() + 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 { + t.Error("--fix-names changed the store") + } + + // the same name with upper case: both rules and lower case, once + up := "_A" + strings.Repeat("a", 38) + sb2 := newSandbox(t, true) + sb2.legacyStoreCase(" alice:", " "+up+":") + sb2.run("", []string{"config", "render"}) + sb2.expect(0, "", "") + out, found = namesFindingsOf(t, sb2) + want = "the user '" + up + "' has a name of 40 characters and starts with '_' and has upper case letters; new user names are at most 32 and lower case and start with a letter (a to z), and this user has no Linux account, here or on a host (tacctl user rename " + up + " )" + if !strings.Contains(out, want) || len(found) != 1 { + t.Errorf("config validate lacks %q (%d json findings):\n%s", want, len(found), out) + } +} + +// A user with upper case whose lower-case spelling is reserved ('Root', +// 'Tacquito') gets one finding, in the text and the json, that says the +// spelling is reserved and names the rename with a name of the person's choice; +// --fix-names offers nothing and counts nothing as not offered or failed. +func TestUpperCaseNameWhoseLowerCaseSpellingIsReservedIsOneFinding(t *testing.T) { + for _, c := range []struct{ name, reserved string }{ + {"Root", "Username 'root' is reserved as an accounting-only sink for Junos internal daemons (non-tty CLI as root)"}, + {"Tacquito", "Username 'tacquito' is reserved (matches the service user). Pick a different name"}, + } { + sb := newSandbox(t, true) + sb.legacyStoreCase(" alice:", " "+c.name+":") + sb.legacyStoreCase(" bob:", " Bobby:") + sb.run("", []string{"config", "render"}) + sb.expect(0, "", "") + out, found := namesFindingsOf(t, sb) + lower := strings.ToLower(c.name) + want := "the user '" + c.name + "' has upper case letters; new user names are lower case, but its lower-case spelling '" + lower + "' is not a name 'user rename' takes: " + c.reserved + " (tacctl user rename " + c.name + " )" + if !strings.Contains(out, want) || strings.Count(out, "'"+c.name+"'") != 1 { + t.Errorf("%s: config validate lacks %q:\n%s", c.name, want, out) + } + if strings.Contains(out, "rename "+c.name+" "+lower) { + t.Errorf("%s: the lower-case rename is proposed:\n%s", c.name, out) + } + var ofName, ofBobby int + for _, f := range found { + switch { + case strings.Contains(f.Text, "'"+c.name+"'"): + ofName++ + if f.Fix != "tacctl user rename "+c.name+" " || f.Kind != "" || f.Level != levelWarning { + t.Errorf("%s: the json finding: %+v", c.name, f) + } + case strings.Contains(f.Text, "'Bobby'"): + ofBobby++ + } + } + if ofName != 1 || ofBobby != 1 { + t.Errorf("%s: json findings %d and %d: %+v", c.name, ofName, ofBobby, found) + } + + sb.run("", []string{"config", "validate", "--fix-names", "--yes"}) + sb.expect(0, "Names: renamed 1, declined 0, not offered 0, failed 0.", "") + if !strings.Contains(sb.store(), " "+c.name+":") || !strings.Contains(sb.store(), " bobby:") { + t.Errorf("%s: the store after --fix-names:\n%s", c.name, sb.store()) + } + if strings.Contains(sb.printed(), "Rename user '"+c.name+"'") { + t.Errorf("%s: a rename was offered:\n%s", c.name, sb.printed()) + } + } +} diff --git a/internal/names/names.go b/internal/names/names.go index 622923f5..c25ea20b 100644 --- a/internal/names/names.go +++ b/internal/names/names.go @@ -166,12 +166,23 @@ func RejectReservedUsername(value string) error { // 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)) + if len(value) > UsernameMax { + return longUsername(value, false) } return nil } +// longUsername is the refusal of a name over UsernameMax characters; upper adds +// that the name has upper case, which a new name does not (the lower-case +// spelling would be over the limit too). +func longUsername(value string, upper bool) error { + msg := fmt.Sprintf("Username '%s' is %d characters; a user name is at most %d (the longest a Linux account name can be).", value, len(value), UsernameMax) + if upper { + msg += " Names are lower case as well." + } + return fail(msg) +} + // RejectNonLetterUsername is the first-character check of the creation paths // ('user add' and the new name of 'user rename'): a new user name starts with a // lower case letter, a to z. Every new user gets a Linux account on the tacctl @@ -181,15 +192,26 @@ func RejectLongUsername(value string) error { // system. It is not part of ValidateUsername, which every verb runs: a user // that exists as '9dave', '_svc' or '-x' is shown, changed, renamed away and // removed as before. An upper case first letter is the business of -// RequireLower, which comes first in CheckNewUsername and suggests the lower -// case spelling. +// CheckNewUsername, which suggests the lower case spelling when that is a +// name it takes. func RejectNonLetterUsername(value string) error { if value == "" || value[0] < 'a' || value[0] > 'z' { - return fail(fmt.Sprintf("Username '%s' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either).", value)) + return nonLetterUsername(value, false) } return nil } +// nonLetterUsername is the refusal of a name whose first character is no lower +// case letter; upper says that the name has upper case too, so that the refusal +// names both faults ("must be lower case and start with a letter"). +func nonLetterUsername(value string, upper bool) error { + must := "must start with a letter (a to z)" + if upper { + must = "must be lower case and start with a letter (a to z)" + } + return fail(fmt.Sprintf("Username '%s' %s: every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either).", value, must)) +} + // StartsWithNoAccountChar reports whether the name of an existing user starts // with a digit or '-': no Linux account name does (a leading '_' is one, so a // user named '_svc' has an account). 'config validate' warns of such a user. @@ -198,19 +220,32 @@ func StartsWithNoAccountChar(value string) bool { } // CheckNewUsername is the whole check of a name a user is created with, by -// 'user add' and by the new name of 'user rename', in this order: the shape -// (ValidateUsername), the reserved names, upper case (RequireLower, so that -// 'Alice' gets the lower case spelling suggested and '1Alice' is first told -// the same, the letter rule following on the retry), the length and the first -// character. The first failing check is the answer. Existing users are never +// 'user add' and by the new name of 'user rename'. For a name with no upper +// case the checks run in this order and the first that fails is the answer: the +// shape (ValidateUsername), the reserved names, the length and the first +// character. A name with upper case is told to be lower case (RequireLower, +// with the lower case spelling suggested) only when that spelling would pass +// every other check, so that the suggestion is a name the command takes; +// otherwise the answer is the first check its lower case spelling fails: the +// reserved name, or the length or the first character, said with the name as +// typed and with "lower case" among what to fix. Existing users are never // checked with it: ValidateUsername is what every other verb runs. func CheckNewUsername(value string) error { - for _, check := range []func(string) error{ValidateUsername, RejectReservedUsername, RequireLower, RejectLongUsername, RejectNonLetterUsername} { - if err := check(value); err != nil { - return err - } + if err := ValidateUsername(value); err != nil { + return err } - return nil + upper := HasUpper(value) + lower := strings.ToLower(value) + if err := RejectReservedUsername(lower); err != nil { + return err + } + if len(value) > UsernameMax { + return longUsername(value, upper) + } + if RejectNonLetterUsername(lower) != nil { + return nonLetterUsername(value, upper) + } + return RequireLower(value) } // ValidateGroupName is the group-name check of 'group add'. diff --git a/internal/names/names_test.go b/internal/names/names_test.go index 3a4f2fb7..5123c504 100644 --- a/internal/names/names_test.go +++ b/internal/names/names_test.go @@ -386,19 +386,30 @@ func TestStartsWithNoAccountChar(t *testing.T) { } // CheckNewUsername runs the checks in a fixed order: the shape, the reserved -// names, upper case (the lower-case spelling is suggested first), the length, -// then the first character. +// names, upper case, the length, then the first character, for a name with no +// upper case. A name with upper case is told to be lower case only when its +// lower-case spelling would be accepted (the suggestion is a name the command +// takes); otherwise the first check the lower-case spelling fails is the answer. func TestCheckNewUsernameOrder(t *testing.T) { long := strings.Repeat("a", 40) for _, c := range []struct{ name, want string }{ {"alice", ""}, {"a1_-", ""}, {"j.smith", usernameShape}, + {"J.smith", usernameShape}, {"root", "Username 'root' is reserved as an accounting-only sink"}, {"tacquito", "Username 'tacquito' is reserved"}, {"Alice", "Names are lower case: use 'alice'. Nothing was changed."}, - {"1Alice", "Names are lower case: use '1alice'. Nothing was changed."}, + {"A1_-", "Names are lower case: use 'a1_-'. Nothing was changed."}, + {"Root", "Username 'root' is reserved as an accounting-only sink"}, + {"ROOT", "Username 'root' is reserved as an accounting-only sink"}, + {"Tacquito", "Username 'tacquito' is reserved"}, + {"1Alice", "Username '1Alice' must be lower case and start with a letter (a to z)"}, + {"_Alice", "Username '_Alice' must be lower case and start with a letter (a to z)"}, + {"-X", "Username '-X' must be lower case and start with a letter (a to z)"}, + {"A" + long, "Username 'A" + long + "' is 41 characters; a user name is at most 32 (the longest a Linux account name can be). Names are lower case as well."}, {"1" + long, "Username '1" + long + "' is 41 characters"}, + {"1A" + long, "Username '1A" + long + "' is 42 characters; a user name is at most 32 (the longest a Linux account name can be). Names are lower case as well."}, {"1alice", "Username '1alice' must start with a letter (a to z)"}, {"_svc", "Username '_svc' must start with a letter (a to z)"}, {"-x", "Username '-x' must start with a letter (a to z)"}, @@ -415,3 +426,18 @@ func TestCheckNewUsernameOrder(t *testing.T) { } } } + +// What CheckNewUsername suggests, it takes: the lower-case spelling it names is +// a name that passes, for every name it tells to be lower case. +func TestCheckNewUsernameSuggestionIsAcceptedItself(t *testing.T) { + for _, name := range []string{"Alice", "ALICE", "A", "Z9_-", "aLICE", "Root2", "Tacquito2"} { + err := CheckNewUsername(name) + if err == nil || !strings.HasPrefix(err.Error(), "Names are lower case: use '") { + t.Errorf("%q: %v", name, err) + continue + } + if again := CheckNewUsername(strings.ToLower(name)); again != nil { + t.Errorf("%q: the suggestion %q is refused: %v", name, strings.ToLower(name), again) + } + } +} From 7e42f74b8a2b70c9ad042183ae28b0b31bf9dee4 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 00:40:39 -0900 Subject: [PATCH 06/27] docs: the rule for a new user name, as the code now answers it CHANGELOG item 2 said a digit, '-' and '_' were refused although Linux itself would take them; only '_' is a valid first character of a Linux account name. Reworded in place: a digit and '-', which no account name starts with, and '_', which Linux would take, are refused. The pages that told an upper case name 'the lower-case spelling first, the letter rule on the retry' (docs/cli/user.md, docs/install/upgrading.md, the manual page, the CHANGELOG item) now say what the code does: the spelling is suggested only when it is accepted, else the first check it fails is the answer. Also said: a stored name over 32 characters that starts with '_' is warned of with the letter rule too, and a stored '-x' is typed as a bare word (the user verbs have no '--'). man/tacctl.1 regenerated with make man. --- CHANGELOG.md | 23 ++++++++++++++++------- docs/cli/config.md | 4 +++- docs/cli/user.md | 13 +++++++++---- docs/install/upgrading.md | 2 +- man/tacctl.1 | 26 ++++++++++++++++++-------- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60129835..619bbfca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,23 +39,32 @@ current behaviour; this file is where history lives. Linux account, on this server and on the enrolled hosts, and a name that starts with a digit or `-` is no account name, so `user add` and the new name of `user rename` now refuse a first character that is not a letter, a - to z (a digit, `-` and `_`, which Linux itself would take, are refused so - that every new name is an account name everywhere): `Username '1alice' + to z (a digit and `-`, which no Linux account name starts with, and `_`, + which Linux would take, are refused so that every new name is an account + name everywhere): `Username '1alice' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either).`, exit status 1, nothing changed. A new name is now a lower-case letter, then lower-case letters, digits, `_` and `-`, at most 32 characters. The checks run in a fixed order and the first that fails is the answer (`names.CheckNewUsername`): the shape (no period), the - reserved names, upper case, the length, the first character, so `Alice` and - `1Alice` are told the lower-case spelling first (`Names are lower case: use - '1alice'.`) and the letter rule follows on the retry. Only a new name is - checked: a user that exists as `9dave`, `_svc` or `-x` keeps working and is + reserved names, upper case, the length, the first character. A name with + upper case is told its lower-case spelling (`Names are lower case: use + 'alice'.`) only when that spelling passes every other check, so the + suggestion is always a name the command takes; for `1Alice`, `_Alice`, + `Root`, `Tacquito` or `Alice` followed by 41 characters the answer is the + first check the lower-case spelling fails, said with the name as typed and + with the lower case among what to fix (`Username '1Alice' must be lower + case and start with a letter (a to z): ...`). Only a new name is checked: a user that exists as `9dave`, `_svc` or `-x` keeps working and is shown, changed, renamed away, removed, restored and carried by the upgrade as before. `config validate` warns, under `Names:`, of an existing user whose name starts with a digit or `-` (no Linux account, here or on a host) and names `tacctl user rename `; a name that starts with - `_` has an account and gets no warning. `config validate --fix-names` + `_` has an account and gets no warning, unless it is also longer than 32 + characters, when the warning gives the letter rule next to the length so + that the replacement is not refused in turn. A user stored as `-x` is + reached by the verbs as a bare word (`tacctl user show -x`); `--` is not + an end-of-options marker of the user verbs. `config validate --fix-names` offers the rename to the lower-case spelling of a name with upper case only when that spelling would pass all the rules of a new name: for `1Alice`, `_Alice`, `Root` or `Alice` followed by 41 characters it offers nothing, diff --git a/docs/cli/config.md b/docs/cli/config.md index 90638006..1c391f9f 100644 --- a/docs/cli/config.md +++ b/docs/cli/config.md @@ -94,7 +94,9 @@ config validate [--json | --fix-names [--yes]] warning too: it works but has no Linux account, here or on a host, and the warning names `tacctl user rename ` (the new name must pass the rules of a new name); `--fix-names` does not offer that rename, since it has no name to propose. A name that starts - with `_` has an account and is not warned of. A user with several of these faults, upper + with `_` has an account and is not warned of, unless it is longer than 32 characters: its + warning then gives the letter rule next to the length, so that the replacement (`_svc` is no + new name) is not refused in turn. A user with several of these faults, upper case included (`1Alice`, or `Alice` followed by 41 characters), gets that one warning only, which says so: the lower-case spelling would be refused by `user rename` too (it is longer than 32 characters, or does not start with a letter, or is reserved), so no warning proposes it. A diff --git a/docs/cli/user.md b/docs/cli/user.md index e65cfbc9..2540961d 100644 --- a/docs/cli/user.md +++ b/docs/cli/user.md @@ -249,10 +249,15 @@ must start with a letter (a to z): every new user gets a Linux account, and a na with a digit or '-' is no account name (a new name does not start with '_' either).` and change nothing. The checks run in this order, and the first that fails is the answer: the shape (letters, digits, `_` and `-`; no period), the reserved names, upper case (`Names are lower case: use -'alice'.`, so `Alice` and `1Alice` are told the lower-case spelling first, and the letter rule -follows on the retry with `1alice`), the length (at most 32) and the first character. Only a new -name is checked: a user from an earlier release named `9dave`, `_svc` or `-x` keeps working. It -is shown, listed, changed, renamed away to a name that passes the rules, removed and restored by +'alice'.`), the length (at most 32) and the first character. The lower-case spelling is suggested +only when it passes the other checks, so the retry is accepted: `Alice` is told `alice`, while +`1Alice` and `_Alice` are told at once that the name must be lower case and start with a letter +(`Username '1Alice' must be lower case and start with a letter (a to z): ...`), `Root` and +`Tacquito` that `root` and `tacquito` are reserved, and an upper-case name over 32 characters its +length and that names are lower case as well. Only a new name is checked: a user from an earlier +release named `9dave`, `_svc` or `-x` keeps working. A name that starts with `-` is typed as an +ordinary word (`tacctl user show -x`, `tacctl user remove -x`); `--` is not an end-of-options marker +of the user verbs and would be read as the user name. The user is shown, listed, changed, renamed away to a name that passes the rules, removed and restored by `backup restore` as before, and `tacctl upgrade` carries it unchanged. A name that starts with a digit or `-` has no account on the tacctl server or on a host, so `config validate` warns of it under `Names:` with `tacctl user rename `; a name that starts with `_` has an diff --git a/docs/install/upgrading.md b/docs/install/upgrading.md index a6bf851a..ab5b0c71 100644 --- a/docs/install/upgrading.md +++ b/docs/install/upgrading.md @@ -22,7 +22,7 @@ The upgrade command: 10. Sets up this machine's own login, or repairs it (see **This machine's own login (0.2.21)** below) 11. Offers the tools of the PDF device reports (0.2.27; see [PDF reports](#pdf-reports) below), last, once the upgrade is done -**A new user name starts with a letter (0.2.30).** `user add` and the new name of `user rename` refuse a name whose first character is not a lower-case letter, a to z (a digit, `-` and `_` are refused; a name with upper case is told its lower-case spelling first). Every new user gets a Linux account, and a name that starts with a digit or `-` is no account name. Nothing is changed in the files: a user that exists as `9dave`, `_svc` or `-x` keeps working, is carried by the upgrade and by `backup restore` unchanged, and can be shown, changed, renamed away and removed. After the upgrade `tacctl config validate` warns, under `Names:`, of each user whose name starts with a digit or `-` (it has no Linux account, here or on a host) and names `tacctl user rename `; a name that starts with `_` has an account and is not warned of. A user with upper case whose lower-case spelling could not be a new name (`1Alice`, a name longer than 32 characters) gets that one warning, and `config validate --fix-names` offers no rename for it. The upgrade's own renames of users with a period keep the rule they had (see below). +**A new user name starts with a letter (0.2.30).** `user add` and the new name of `user rename` refuse a name whose first character is not a lower-case letter, a to z (a digit and `-`, which no Linux account name starts with, and `_`, which Linux would take, are refused; a name with upper case is told its lower-case spelling only when that spelling is accepted, else what to fix at once). Every new user gets a Linux account, and a name that starts with a digit or `-` is no account name. Nothing is changed in the files: a user that exists as `9dave`, `_svc` or `-x` keeps working, is carried by the upgrade and by `backup restore` unchanged, and can be shown, changed, renamed away and removed. After the upgrade `tacctl config validate` warns, under `Names:`, of each user whose name starts with a digit or `-` (it has no Linux account, here or on a host) and names `tacctl user rename `; a name that starts with `_` has an account and is not warned of. A user with upper case whose lower-case spelling could not be a new name (`1Alice`, a name longer than 32 characters) gets that one warning, and `config validate --fix-names` offers no rename for it. The upgrade's own renames of users with a period keep the rule they had (see below). **The unit comments name the current commands (0.2.22).** The shipped unit files and the comment at the top of the generated drop-in (`tacquito.service.d/tacctl.conf`) name `tacctl server listen` and `tacctl server metrics` where they named `config listen` and `config metrics`. The first render after the upgrade rewrites the drop-in, reloads systemd and restarts tacquito once, a brief TACACS+ interruption (the upgrade's own restart for the changed unit files is that one); nothing else in them changes. diff --git a/man/tacctl.1 b/man/tacctl.1 index de4fbb62..9ff324bc 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -1731,17 +1731,26 @@ and are refused as the first character .RB ( "Username '1alice' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either)." ), and nothing is changed. The checks run in this order and the first that fails is -the answer: the shape, the reserved names, upper case (so -.B Alice -and -.B 1Alice -are told the lower case spelling first), the length and the first character. A -user that exists as +the answer: the shape, the reserved names, upper case, the length and the first +character. The lower case spelling is suggested only when it passes the other +checks, so that the retry is accepted +.RB ( Alice +is told +.BR alice ; +.BR 1Alice " and " _Alice +are told at once to be lower case and start with a letter, +.BR Root " and " Tacquito +that their lower case spelling is reserved). A user that exists as .BR 9dave , .B _svc or .B \-x -keeps working as it is; only a new name is checked, and +keeps working as it is (a name that starts with +.B \- +is typed as an ordinary word, +.BR "tacctl user show \-x" ; +.B \-\- +is not an end\-of\-options marker of the user verbs); only a new name is checked, and .B "config validate" warns of an existing name that starts with a digit or .BR \- . @@ -3293,7 +3302,8 @@ too: it works but has no Linux account, here or on a host, and the warning names .B \-\-fix\-names does not offer that rename. A name that starts with .B _ -has an account and is not warned of. A user with several of these faults, upper +has an account and is not warned of, unless it is longer than 32 characters: +its warning then gives the letter rule next to the length. A user with several of these faults, upper case included, gets that one warning only, which says so: the lower case spelling would be refused by .B "user rename" From 889d987100b30e0184d75146acad9220fbd45666 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 00:40:47 -0900 Subject: [PATCH 07/27] docs: rewrap two lines of the CHANGELOG item of the new user name Whitespace only; fold into the docs commit before it. --- CHANGELOG.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 619bbfca..8f1097da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,10 +41,10 @@ current behaviour; this file is where history lives. name of `user rename` now refuse a first character that is not a letter, a to z (a digit and `-`, which no Linux account name starts with, and `_`, which Linux would take, are refused so that every new name is an account - name everywhere): `Username '1alice' - must start with a letter (a to z): every new user gets a Linux account, and - a name that starts with a digit or '-' is no account name (a new name does - not start with '_' either).`, exit status 1, nothing changed. A new name is + name everywhere): `Username '1alice' must start with a letter (a to z): + every new user gets a Linux account, and a name that starts with a digit or + '-' is no account name (a new name does not start with '_' either).`, exit + status 1, nothing changed. A new name is now a lower-case letter, then lower-case letters, digits, `_` and `-`, at most 32 characters. The checks run in a fixed order and the first that fails is the answer (`names.CheckNewUsername`): the shape (no period), the @@ -55,9 +55,10 @@ current behaviour; this file is where history lives. `Root`, `Tacquito` or `Alice` followed by 41 characters the answer is the first check the lower-case spelling fails, said with the name as typed and with the lower case among what to fix (`Username '1Alice' must be lower - case and start with a letter (a to z): ...`). Only a new name is checked: a user that exists as `9dave`, `_svc` or `-x` keeps working and is - shown, changed, renamed away, removed, restored and carried by the upgrade - as before. `config validate` warns, under `Names:`, of an existing user + case and start with a letter (a to z): ...`). Only a new name is checked: + a user that exists as `9dave`, `_svc` or `-x` keeps working and is shown, + changed, renamed away, removed, restored and carried by the upgrade as + before. `config validate` warns, under `Names:`, of an existing user whose name starts with a digit or `-` (no Linux account, here or on a host) and names `tacctl user rename `; a name that starts with `_` has an account and gets no warning, unless it is also longer than 32 From 4c48439065074c501b1aea8d2db423151d50e8aa Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:08:06 -0900 Subject: [PATCH 08/27] tier: the notes of the two ssh rows live in tier.Rules The two sentences about 'ssh --login' were added to tierNotes by withSSHNotes in internal/cli/shell_view.go, because the 'ssh' row is an AnySub row. They are now the Note of the 'ssh' and 'device ssh' rows in internal/tier/tier.go, and withSSHNotes is gone: tier.Notes() already keys an AnySub row as "ssh " (empty Sub), the key the man generator trims and the shell help reads. The tier test that kept a Note off AnySub rows now asks only that a row with a Note has a Cmd and a Sub unless it is an AnySub row. No user-visible change: the texts are byte for byte the same, and man/tacctl.1 is unchanged. --- internal/cli/shell_view.go | 17 ++--------------- internal/tier/tier.go | 13 ++++++++++--- internal/tier/tier_test.go | 2 +- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/internal/cli/shell_view.go b/internal/cli/shell_view.go index 341ca5b5..14e43238 100644 --- a/internal/cli/shell_view.go +++ b/internal/cli/shell_view.go @@ -187,21 +187,8 @@ 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. 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 -} +// edited in one place. The key of an AnySub row ("ssh ") has no sub-verb. +var tierNotes = tier.Notes() // 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/tier/tier.go b/internal/tier/tier.go index f2aec6c9..0ea3e43f 100644 --- a/internal/tier/tier.go +++ b/internal/tier/tier.go @@ -133,10 +133,15 @@ type Rule struct { // Note is the sentence the verb's help carries where the gate cannot // tell its sub-verbs apart (it sees two words): what the code decides // beyond the row. One note per Cmd and Sub, on the first row of the - // pair; the manual page's TIERS block is generated from it. + // pair (an AnySub row has the Sub ""); the manual page's TIERS block is + // generated from it. Note string } +// 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." + // Rules is the tier table (tier_permits and emit_tier_sudoers). Anything // that prints a shared secret or a password hash (scope secret, backup diff, // config dump, store show) is superuser-only, and so is everything that @@ -182,7 +187,8 @@ var Rules = []Rule{ {Tier: Readonly, Cmd: "backend", Sub: "status", Sudoers: []string{"backend status", "backend status *"}, Wrap: true}, // 'ssh ' and the device registry's reads (0.2.1): the root side // filters them to the caller's own scopes (docs/plans/operator-console.md 8). - {Tier: Readonly, Cmd: "ssh", AnySub: true, Sudoers: []string{"ssh *"}}, + {Tier: Readonly, Cmd: "ssh", AnySub: true, Sudoers: []string{"ssh *"}, + Note: "ssh" + sshLoginNote}, {Tier: Readonly, Cmd: "device", Sub: "list", Sudoers: []string{"device list", "device list *"}, Note: "device list: the CONFIG column (and config, release, model and serial of --json) is the operator tier's; a read-only user's list has none."}, {Tier: Readonly, Cmd: "device", Sub: "show", Sudoers: []string{"device show *"}, @@ -199,7 +205,8 @@ var Rules = []Rule{ // 'device notice', and the verb keeps 'ack' and 'unack' the superuser's. {Tier: Readonly, Cmd: "device", Sub: "notice", Sudoers: []string{"device notice list", "device notice list *"}, Note: "device notice: every tier may run list; ack and unack need the superuser tier."}, - {Tier: Readonly, Cmd: "device", Sub: "ssh", Sudoers: []string{"device ssh *"}}, + {Tier: Readonly, Cmd: "device", Sub: "ssh", Sudoers: []string{"device ssh *"}, + Note: "device ssh" + sshLoginNote}, {Tier: Readonly, Cmd: "device", Sub: "client-config", Sudoers: []string{"device client-config"}, Wrap: true}, {Tier: Readonly, Cmd: "_completion-names", AnySub: true, Sudoers: []string{"_completion-names *"}}, // The login console asks for its settings once per session (console.go). diff --git a/internal/tier/tier_test.go b/internal/tier/tier_test.go index c4384d2b..a2cce59f 100644 --- a/internal/tier/tier_test.go +++ b/internal/tier/tier_test.go @@ -838,7 +838,7 @@ func TestNotesAreOnePerCommandAndSub(t *testing.T) { t.Errorf("two rows carry a note for %q", k) } seen[k] = true - if r.Cmd == "" || r.Sub == "" || r.AnySub { + if r.Cmd == "" || (r.Sub == "") != r.AnySub { t.Errorf("a note on a row without Cmd and Sub: %+v", r) } } From 1f06c29ebb639c017cad9d7d6165cdbc55a73327 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:08:40 -0900 Subject: [PATCH 09/27] tests: gate-go names the failing tests above its FAIL verdict On a FAIL, gate-go.sh now prints up to ten 'FAIL: ' lines above the verdict line, after the skipped and slowest lines: one for each '--- FAIL:' line of the log (a top-level test or a subtest, a name once, in the order of the log). A package that failed without a failing test (a build failure, a panic, a timeout) is named by its 'FAIL ' line instead. This is the form gate-ci.sh already uses for its failures, and the one a tool reading a gate's output for failing test names looks for; before, a FAIL printed only the verdict line and the log path. The verdict line is unchanged and stays the last line. gate_go.bats covers a failing test, subtests and duplicates, the limit of ten, a package without a failing test, the order among the lines above the verdict and a PASS without any. The header of the script and AGENTS.md say so. --- AGENTS.md | 2 +- tests/integration/gate_go.bats | 61 ++++++++++++++++++++++++++++++++++ tests/tools/gate-go.sh | 20 ++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index c679cca1..8ef8cf67 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,7 +24,7 @@ groups and scopes, network devices and enrolled Linux hosts. - 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. +- 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, and a `GATE-GO FAIL` line has up to ten `FAIL: ` lines above it. `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`) diff --git a/tests/integration/gate_go.bats b/tests/integration/gate_go.bats index 743995b6..1ce5971b 100644 --- a/tests/integration/gate_go.bats +++ b/tests/integration/gate_go.bats @@ -23,6 +23,13 @@ test) case "$STUB_MODE" in printf 'ok \tp/a\t0.1s\n? \tp/b\t[no test files]\n' ;; slowmany) for i in $(seq 12); do printf -- '--- PASS: TestT%02d (%d.00s)\n' "$i" "$i"; done printf 'ok \tp/a\t0.1s\n? \tp/b\t[no test files]\n' ;; + failsub) printf -- '=== RUN TestB\n--- FAIL: TestB (0.00s)\n --- FAIL: TestB/sub (0.00s)\n--- FAIL: TestA (0.00s)\nFAIL\tp/a\t0.1s\n' + printf -- '--- FAIL: TestB (0.00s)\nFAIL\tp/b\t0.1s\n'; exit 1 ;; + failmany) for i in $(seq -w 12); do printf -- '--- FAIL: TestF%s (0.00s)\n' "$i"; done + printf 'FAIL\tp/a\t0.1s\nok \tp/b\t0.1s\n'; exit 1 ;; + failslow) printf -- '--- SKIP: TestY (0.00s)\n--- PASS: TestSlow (47.12s)\n--- FAIL: TestX (0.00s)\nFAIL\tp/a\t0.1s\nok \tp/b\t0.1s\n'; exit 1 ;; + build) printf 'FAIL\tp/a [build failed]\nok \tp/b\t0.1s\n'; exit 1 ;; + panic) printf 'panic: boom [recovered]\nFAIL\tp/a\t0.1s\nFAIL\tp/b\t0.1s\nFAIL\n'; exit 1 ;; hang) exec sleep 30 ;; tmp) printf '%s\n' "$TMPDIR" >"$STUB_TMP_OUT"; printf 'ok \tp/a\t0.1s\n? \tp/b\t[no test files]\n' ;; args) printf '%s\n' "$*" >"$STUB_ARGS_OUT"; printf 'ok \tp/a\t0.1s\n? \tp/b\t[no test files]\n' ;; @@ -128,6 +135,60 @@ sleeper_below() { [[ "${lines[-1]}" == "GATE-GO FAIL rc=1 packages=1/2 failures=2 "* ]] } +@test "a failing test is named in a FAIL: line above the FAIL verdict, which stays the last line" { + STUB_MODE=fail run -1 "$GATE" -o "$LOG" + [[ "${lines[-1]}" == "GATE-GO FAIL rc=1 "* ]] + [[ "${lines[-2]}" == "FAIL: TestX" ]] + [[ "$(printf '%s\n' "${lines[@]}" | grep -c '^FAIL: ')" -eq 1 ]] + # the log ends the same way + [[ "$(tail -n 1 "$LOG")" == "${lines[-1]}" ]] + [[ "$(tail -n 2 "$LOG" | head -n 1)" == "FAIL: TestX" ]] +} + +@test "failing tests and subtests are each named once, in the order of the log" { + STUB_MODE=failsub run -1 "$GATE" -o "$LOG" + [[ "${lines[-1]}" == "GATE-GO FAIL rc=1 packages=0/2 failures=5 "* ]] + [[ "${lines[-2]}" == "FAIL: TestA" ]] + [[ "${lines[-3]}" == "FAIL: TestB/sub" ]] + [[ "${lines[-4]}" == "FAIL: TestB" ]] + [[ "$(printf '%s\n' "${lines[@]}" | grep -c '^FAIL: ')" -eq 3 ]] + # a package that has a failing test is not named + [[ "$output" != *"FAIL: p/a"* ]] +} + +@test "the failing tests come below the skipped names and the slowest tests, right above the verdict" { + STUB_MODE=failslow run -1 "$GATE" -o "$LOG" + [[ "${lines[-1]}" == "GATE-GO FAIL "*" skipped=1 log=$LOG" ]] + [[ "${lines[-2]}" == "FAIL: TestX" ]] + [[ "${lines[-3]}" == "gate-go: slowest: TestSlow 47.1s" ]] + [[ "${lines[-4]}" == "gate-go: skipped: TestY" ]] +} + +@test "no more than ten failing tests are named, the failures= count stays exact" { + STUB_MODE=failmany run -1 "$GATE" -o "$LOG" + [[ "${lines[-1]}" == "GATE-GO FAIL rc=1 packages=1/2 failures=13 "* ]] + [[ "$(printf '%s\n' "${lines[@]}" | grep -c '^FAIL: ')" -eq 10 ]] + [[ "${lines[-2]}" == "FAIL: TestF10" ]] + [[ "${lines[-11]}" == "FAIL: TestF01" ]] + [[ "$output" != *"FAIL: TestF11"* ]] +} + +@test "a package that failed to build or panicked, with no failing test, is named by its FAIL line" { + STUB_MODE=build run -1 "$GATE" -o "$LOG" + [[ "${lines[-1]}" == "GATE-GO FAIL rc=1 packages=1/2 failures=1 "* ]] + [[ "${lines[-2]}" == "FAIL: p/a" ]] + STUB_MODE=panic run -1 "$GATE" -o "$LOG" + [[ "${lines[-1]}" == "GATE-GO FAIL rc=1 packages=0/2 failures=4 "* ]] + [[ "${lines[-2]}" == "FAIL: p/b" ]] + [[ "${lines[-3]}" == "FAIL: p/a" ]] + [[ "$(printf '%s\n' "${lines[@]}" | grep -c '^FAIL: ')" -eq 2 ]] +} + +@test "a PASS names no failing test" { + STUB_MODE=ok run -0 "$GATE" -o "$LOG" + [[ "$output" != *"FAIL: "* ]] +} + @test "SIGTERM stops the run, reaps go and prints a FAIL verdict" { STUB_MODE=hang "$GATE" -o "$LOG" >"$BATS_TEST_TMPDIR/out" 2>&1 & pid=$! diff --git a/tests/tools/gate-go.sh b/tests/tools/gate-go.sh index 85b445f9..86c188c5 100755 --- a/tests/tools/gate-go.sh +++ b/tests/tools/gate-go.sh @@ -19,6 +19,14 @@ # several packages counts with its longest time): where the time went, and the # input of 'tests/tools/go-test-shard.sh --regen'. # +# A FAIL verdict is preceded, last of the lines above it, by the failing tests, +# at most ten, one 'FAIL: ' line each, from the '--- FAIL: TestX' lines of +# the log (a top-level test and a subtest each, a name once, in the order of +# the log; the form 'qargi feature verify' reads). A package that failed +# without a failing test (a build failure, a panic, a timeout) is named by its +# 'FAIL ' line instead ('FAIL: '). The failures= field of the +# verdict line counts every FAIL and panic line, listed or not. +# # A run of the whole suite (no package listed, no --tags) first runs 'make # lint-go': gofmt, go vet and golangci-lint in both tag sets, the Go half of # the lint job of CI, so a finding the pull request would fail on shows up at @@ -119,7 +127,7 @@ start=$(date +%s) child="" verdict() { # - local rc=$1 note=${2:-} got bad v secs skipped names n max=20 + local rc=$1 note=${2:-} got bad v secs skipped names n max=20 failing got=$(grep -cE '^(ok|\?)[[:space:]]' "$log") bad=$(grep -cE '^(FAIL|--- FAIL|panic:)' "$log") secs=$(($(date +%s) - start)) @@ -143,6 +151,16 @@ verdict() { # awk '{ printf "gate-go: slowest: %s %.1fs\n", $2, $1 }' | tee -a "$log" v=FAIL if [[ "$rc" -eq 0 && "$got" -eq "$want" && "$want" -gt 0 && "$bad" -eq 0 && -z "$note" ]]; then v=PASS; fi + if [[ "$v" = FAIL ]]; then + # The failing tests (at most ten, in the order of the log, each once); + # without one, the packages that failed (a build failure, a panic). + failing=$(sed -n 's/^[[:space:]]*--- FAIL: \([^ ]*\).*/\1/p' "$log" | awk '!seen[$0]++') + [[ -n "$failing" ]] || + failing=$(sed -n 's/^FAIL[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*/\1/p' "$log" | awk '!seen[$0]++') + if [[ -n "$failing" ]]; then + head -n 10 <<<"$failing" | sed 's/^/FAIL: /' | tee -a "$log" + fi + fi echo "GATE-GO $v rc=$rc packages=$got/$want failures=$bad secs=$secs skipped=$skipped${note:+ $note} log=$log" | tee -a "$log" [[ "$v" = PASS ]] } From b1216af0008ca2f5aca6a3e38be7c5e0e9480ac2 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:11:23 -0900 Subject: [PATCH 10/27] outpath: test that a home root cannot write is refused plainly On an NFS export with root_squash the three commands that write as root (config render --dry-run, config linux script, remove-script) pass the path check and are refused by the write. The tests pin that each says in one line which path was not written and Permission denied, exits 1 and leaves no new or half-written file and the old one as it was. The refusal is made with a directory its owner cannot write; the tests skip as root. --- internal/cli/outpath_squash_test.go | 110 ++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 internal/cli/outpath_squash_test.go diff --git a/internal/cli/outpath_squash_test.go b/internal/cli/outpath_squash_test.go new file mode 100644 index 00000000..be6baf56 --- /dev/null +++ b/internal/cli/outpath_squash_test.go @@ -0,0 +1,110 @@ +package cli + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +// squashedDir makes a directory inside the sandbox's home that its owner +// cannot write: what a home on an NFS export with root_squash is to tacctl +// under sudo, where root is mapped to nobody and the path check (which only +// looks at where the path is) has passed. The test process is not root, so +// the refusal comes from the kernel, as the server's does (EACCES). +func squashedDir(t *testing.T, home string) string { + t.Helper() + if os.Geteuid() == 0 { + t.Skip("root writes into a directory without the write permission, so there is no refusal to see") + } + d := filepath.Join(home, "squashed") + if err := os.Mkdir(d, 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(d, "old.sh"), []byte("# old\n"), 0o600); err != nil { + t.Fatal(err) + } + if err := os.Chmod(d, 0o500); err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = os.Chmod(d, 0o700) }) + return d +} + +// leftIn is the names in dir, to prove that a refused write left nothing. +func leftIn(t *testing.T, dir string) []string { + t.Helper() + ents, err := os.ReadDir(dir) + if err != nil { + t.Fatal(err) + } + var names []string + for _, e := range ents { + names = append(names, e.Name()) + } + return names +} + +// A path inside a home that root cannot write (an NFS root_squash export) +// passes the check of outPath and is refused by the write: each of the three +// commands that write as root says in one line which path was not written and +// why ("Permission denied"), exits 1, and leaves no new or half-written file +// and the old one as it was. The files written as the caller (plan, reports +// export, support-bundle) are not concerned: they take the caller's identity. +func TestOutPathRootSquashedHomeIsRefusedPlainly(t *testing.T) { + hs := newHostSandbox(t) + d := squashedDir(t, hs.dir) + want := []string{"old.sh"} + same := func(what string) { + t.Helper() + if got := leftIn(t, d); strings.Join(got, ",") != strings.Join(want, ",") { + t.Errorf("%s: left %v, want %v", what, got, want) + } + if b, _ := os.ReadFile(filepath.Join(d, "old.sh")); string(b) != "# old\n" { + t.Errorf("%s: the old file is now %q", what, b) + } + } + for _, name := range []string{"new.sh", "old.sh"} { + path := filepath.Join(d, name) + hs.run(nil, "config", "linux", "script", "--scope", "lab", "--server", "192.0.2.10", "--output", path) + hs.expect(1, "", "Cannot write "+path+": Permission denied") + same("script " + name) + hs.run(nil, "config", "linux", "remove-script", "--output", path) + hs.expect(1, "", "install: cannot ") + if !strings.Contains(hs.err.String(), "'"+path+"': Permission denied") { + t.Errorf("remove-script %s: %q", name, hs.err.String()) + } + same("remove-script " + name) + } + + // 'config render --dry-run --out': a directory to make, then one that + // exists and is empty + out := filepath.Join(d, "preview") + hs.run(nil, "config", "render", "--dry-run", "--out", out) + hs.expect(1, "", "Cannot create '"+out+"': Permission denied") + same("render --dry-run (new directory)") +} + +// The same for a directory that exists, is empty and cannot be written. +func TestOutPathRootSquashedEmptyDirIsRefusedPlainly(t *testing.T) { + sb := newSandbox(t, true) + home := sb.homePath("") + d := squashedDir(t, home) + if err := os.Chmod(d, 0o700); err != nil { + t.Fatal(err) + } + if err := os.Remove(filepath.Join(d, "old.sh")); err != nil { + t.Fatal(err) + } + if err := os.Chmod(d, 0o500); err != nil { + t.Fatal(err) + } + sb.run("", []string{"config", "render", "--dry-run", "--out", d}) + sb.expect(1, "", "Cannot write "+d+"/") + if !strings.Contains(sb.stderr(), ": Permission denied") { + t.Errorf("not told why: %q", sb.stderr()) + } + if got := leftIn(t, d); len(got) != 0 { + t.Errorf("left %v", got) + } +} From 1f421d10924ac7f3919839855bf573dea53040fd Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:11:23 -0900 Subject: [PATCH 11/27] docs: what a root-squashed home does to the files written as root The conventions page, the manual page and the changelog say that the commands that write as root write nothing into a home that root cannot write, name the path and the cause in one line, and what to do instead. --- CHANGELOG.md | 18 ++++++++++++++++++ docs/cli/conventions.md | 2 +- man/tacctl.1 | 6 +++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f1097da..5cf69b7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,24 @@ current behaviour; this file is where history lives. `docs/cli/config.md`, `docs/install/upgrading.md` and the manual page say so. +3. **A home that root cannot write is refused in one line, and a test says + so.** `config render --dry-run --out`, `config linux script --output` and + `config linux remove-script --output` write as root, inside the home of the + person who ran `sudo`. On an NFS export with `root_squash` root is mapped to + an unprivileged account and cannot write there, although the path is inside + the home. This was already a plain refusal and is unchanged: nothing is + written, no file or directory is left half made, a file of that name stays + as it was, and the line names the path and the cause (`Cannot write + : Permission denied`, `Cannot create '': Permission denied` or + `install: cannot create regular file '': Permission denied`), exit + status 1. The files written as the caller (`device config plan`, + `device reports export`, `device support-bundle`) take the caller's + identity and are not affected. A test (`TestOutPathRootSquashedHome...`) + pins the three, with a directory its owner cannot write for the refusal. + `docs/cli/conventions.md` and the manual page say what to do: name a path + inside the home that root can write, or run the command without `sudo` + where the tier allows it. + ## 0.2.29 (2026-11-09) 1. **A file uploaded through the console keeps the owner's execute bit.** The diff --git a/docs/cli/conventions.md b/docs/cli/conventions.md index 28b096c3..503823f2 100644 --- a/docs/cli/conventions.md +++ b/docs/cli/conventions.md @@ -19,7 +19,7 @@ These patterns apply across every subcommand family: - **Service restart** — changes to the store, and to the `tacctl.yaml` settings a backend renders (command rules, listeners, `backends.*`), re-render every enabled backend and restart the ones whose files changed. Settings only device configs read (mgmt-acl permits + names, priv-exec mappings, per-scope AAA order, exec timeout, group labels) and tacctl's own tunables (bcrypt cost, password age, …) restart nothing. - **Notices** — INFO says what was done: the change, the service restart, a sync. WARN says that something failed or that the operator has to act: a sync that failed (with the command to retry it), hosts left to sync (with the command), a device that still accepts a user who must change the password. A fact is said once, at one level. A `user` verb that changes an account syncs this server's own accounts at once and names the other enrolled hosts it reaches in one warning; on a terminal it asks `Sync these hosts now? [y/N]` (the default is no and `--yes` does not answer it); see [User Commands](user.md). - **Flags** — long-form flags (`--hash`, `--scopes`, `--scope`, `--prefixes`, `--secret`, `--protocols`, `--vendor-attrs`, `--match`, `--action`, `--branch`, `--protocol`, `--method`, `--backend`, `--listener`, `--out`) take a single argument; `--default`, `--force`, `--legacy`, `--check`, `--replace`, `--json`, `--local`, `--all`, `--dry-run`, `--long`, `--apply`, `--hosts` and `--yes` take none. Required positional args come before flags. -- **Paths you name to write** — a flag that names a file or directory tacctl writes (`--out` and `--out-dir` of `device config plan`, `--out` of `device reports export` and of `config render --dry-run`, `--output` (`-o`) of `config linux script` and `remove-script`) is checked first: the path must be inside your home, the home of the person who ran `sudo` (else of the user running tacctl) as the account database gives it, never `$HOME`. Your shell expands `~` and variables before tacctl sees them; tacctl itself expands neither, so a path that still starts with `~` or holds a `$` or a backtick, an empty path, a path that leaves the home through `..` or through a symbolic link, and the home itself are refused with the one-sentence rule (`tacctl does not expand ~ or variables; name a path inside your home, relative to the current directory`) and nothing is written. A relative path is taken from the current directory. `device support-bundle --out` takes a name, not a path, and writes under `support-bundles` in your home ([Support bundles](../devices/support-bundle.md)). Files tacctl writes as you (`device config plan`, `device reports export`, `device support-bundle`) keep the protections they had: new files only, a link never followed, `--force` where it exists to replace. Two commands write as root: `config render --dry-run` makes its directory and files root-owned (0700, 0600), through a handle on the directory so that a link planted in it is not followed out, and into a directory that is new or empty only; `config linux script` and `remove-script` make the file as root (0600, 0644), hand it to the person who ran `sudo`, replace a file of that name without `--force`, and refuse a directory (or a link to one) as the name. A home directory of `/` is refused for all of these. +- **Paths you name to write** — a flag that names a file or directory tacctl writes (`--out` and `--out-dir` of `device config plan`, `--out` of `device reports export` and of `config render --dry-run`, `--output` (`-o`) of `config linux script` and `remove-script`) is checked first: the path must be inside your home, the home of the person who ran `sudo` (else of the user running tacctl) as the account database gives it, never `$HOME`. Your shell expands `~` and variables before tacctl sees them; tacctl itself expands neither, so a path that still starts with `~` or holds a `$` or a backtick, an empty path, a path that leaves the home through `..` or through a symbolic link, and the home itself are refused with the one-sentence rule (`tacctl does not expand ~ or variables; name a path inside your home, relative to the current directory`) and nothing is written. A relative path is taken from the current directory. `device support-bundle --out` takes a name, not a path, and writes under `support-bundles` in your home ([Support bundles](../devices/support-bundle.md)). Files tacctl writes as you (`device config plan`, `device reports export`, `device support-bundle`) keep the protections they had: new files only, a link never followed, `--force` where it exists to replace. Two commands write as root: `config render --dry-run` makes its directory and files root-owned (0700, 0600), through a handle on the directory so that a link planted in it is not followed out, and into a directory that is new or empty only; `config linux script` and `remove-script` make the file as root (0600, 0644), hand it to the person who ran `sudo`, replace a file of that name without `--force`, and refuse a directory (or a link to one) as the name. A home directory of `/` is refused for all of these. A home on an NFS export with `root_squash` is inside the home and so passes the check, but the two commands that write as root cannot write there (the server maps root to an unprivileged account): they write nothing, leave no file (a file of that name that was there stays as it was), say so in one line that names the path and the cause (`Cannot write : Permission denied`, `Cannot create '': Permission denied` or `install: cannot create regular file '': Permission denied`) and exit with status 1. Name a path inside your home that root can write, or run the command without `sudo` where your tier allows it; the commands that write as you are not affected. ## Top-Level Commands diff --git a/man/tacctl.1 b/man/tacctl.1 index 9ff324bc..b498046d 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -3480,7 +3480,7 @@ and so on) instead of installing them. Nothing live is touched: no artifact, no render record, no service. A hand edit does not stop a dry run. .I dir must be new or empty and is private to root (the artifacts hold secrets and -password hashes). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. +password hashes). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. On a home exported by NFS with \fBroot_squash\fR, root cannot write there: nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied" (name a path root can write, or run the command without \fBsudo\fR where your tier allows it). .\" BEGIN GENERATED: command config render .RS .PP @@ -4915,7 +4915,7 @@ the port, as they were). .B \-\-output names the file (default .B tacctl\-linux\-.sh -in the current directory). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The default name is not a path you named and is not checked. A file of the name you give is replaced; a directory, or a link to one, is refused and nothing is written in it. The file is made as root with mode 0600, and under \fBsudo\fR it is handed to the person who ran it. +in the current directory). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The default name is not a path you named and is not checked. A file of the name you give is replaced; a directory, or a link to one, is refused and nothing is written in it. The file is made as root with mode 0600, and under \fBsudo\fR it is handed to the person who ran it. On a home exported by NFS with \fBroot_squash\fR, root cannot write there: nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied" (name a path root can write, or run the command without \fBsudo\fR where your tier allows it). .\" BEGIN GENERATED: command config linux script .RS .PP @@ -5075,7 +5075,7 @@ tac-* groups and installed packages are left in place. .B \-\-output names the file (default .B tacctl\-linux\-remove.sh -in the current directory). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The default name is not a path you named and is not checked. A file of the name you give is replaced; a directory, or a link to one, is refused and nothing is written in it. The file is made as root with mode 0644, and under \fBsudo\fR it is handed to the person who ran it. +in the current directory). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The default name is not a path you named and is not checked. A file of the name you give is replaced; a directory, or a link to one, is refused and nothing is written in it. The file is made as root with mode 0644, and under \fBsudo\fR it is handed to the person who ran it. On a home exported by NFS with \fBroot_squash\fR, root cannot write there: nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied" (name a path root can write, or run the command without \fBsudo\fR where your tier allows it). .\" BEGIN GENERATED: command config linux remove-script .RS .PP From 67d73db4a3f2e41e1400fe23d249f4cb4fc7bd08 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:10:59 -0900 Subject: [PATCH 12/27] console: a file transfer session ends sooner after the client leaves The console ends a file transfer only when every audit line is logged, one 'logger' process per line, in order. The lines waited in a queue of 256, so a client that did many small requests and then left was held until the console had logged all that was still queued: measured with a fake logger of 5 ms a call and 200 requests, the console returned 1.09 s after the client's close, with 197 lines still to log. The queue holds 32 lines now (sftpAuditQueue): at most that many are left when the client leaves (0.19 s at that speed), and a client that is ahead of the audit is held back by it request by request instead. No line is dropped or reordered and none is logged after the console has ended; a line cannot be logged after the process without losing it, so the bound is on the backlog, not on the drain. TestConsoleSFTPEndsWithABacklogOfAuditLines is the measurement and the regression test: it bounds the lines that had not begun when the last request was answered (a count a loaded host cannot change), checks every line and their order, and only logs the time. CHANGELOG item 3. --- CHANGELOG.md | 15 ++++++++ internal/cli/console_sftp.go | 10 ++++- internal/cli/console_sftp_test.go | 62 +++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f1097da..de63deb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,21 @@ current behaviour; this file is where history lives. `docs/cli/config.md`, `docs/install/upgrading.md` and the manual page say so. +3. **A file transfer session ends sooner after the client leaves.** Every + request of a console file transfer that changes something (an upload, a + download, a delete, a rename, a make-directory, a refusal) is one audit + line, one `logger` process, and the console ends only when every line is + logged, in order. The lines wait in a queue while the client goes on, and + the queue held 256: a client that did many small requests (a tree of small + files) and then left was held until the console had logged all that was + still queued, about a second for 200 lines at 5 ms a line, which is where + a transfer seemed to linger after the client had left. The queue now holds + 32 lines, so at most 32 lines are left to log when the client leaves (about + 0.2 s at that speed) and a client that is ahead of the audit is held back + by it, request by request, as it goes. No line is dropped, none is logged + out of order and none after the console has ended. Nothing else changes: + the lines, their words and their order are as before. + ## 0.2.29 (2026-11-09) 1. **A file uploaded through the console keeps the owner's execute bit.** The diff --git a/internal/cli/console_sftp.go b/internal/cli/console_sftp.go index 0759505c..2dde16e7 100644 --- a/internal/cli/console_sftp.go +++ b/internal/cli/console_sftp.go @@ -154,6 +154,14 @@ type sftpTotals struct { ops, refused int } +// sftpAuditQueue is how many events wait for their log line. The session +// ends only when every line is logged (none is dropped, none follows the end +// of the process), so what is queued when the client leaves is the wait of the +// client's end: at 256 it was about a second at 5 ms a line, and a client +// that is ahead of the log is now held back by it, a request at a time, +// instead of at the end. +const sftpAuditQueue = 32 + // sftpAudit turns the events of the server into log lines, in order, off the // goroutines that serve the requests (each line is a 'logger' process). type sftpAudit struct { @@ -164,7 +172,7 @@ type sftpAudit struct { } func (cs *consoleSession) newSFTPAudit() *sftpAudit { - au := &sftpAudit{cs: cs, ch: make(chan sftpd.Event, 256), done: make(chan struct{})} + au := &sftpAudit{cs: cs, ch: make(chan sftpd.Event, sftpAuditQueue), done: make(chan struct{})} go au.run() return au } diff --git a/internal/cli/console_sftp_test.go b/internal/cli/console_sftp_test.go index 2ec34e6f..aade222f 100644 --- a/internal/cli/console_sftp_test.go +++ b/internal/cli/console_sftp_test.go @@ -18,12 +18,15 @@ import ( "slices" "strings" "sync" + "sync/atomic" "syscall" "testing" + "time" "github.com/pkg/sftp" "github.com/rett/tacctl/internal/console" + "github.com/rett/tacctl/internal/execx" ) // protocolTap keeps what the console wrote to its standard output, so that a @@ -615,3 +618,62 @@ func TestConsoleSFTPWithoutAPolicyAnswer(t *testing.T) { } } } + +// A session whose audit lines are slow to log ends soon after the client +// leaves: every line is still logged, in order, before the console ends, so +// what the client waits for at its end is the lines queued, and the queue is +// short (sftpAuditQueue); a client that is ahead of the log is held back +// request by request, not all at once at the end (it was about a second for +// 200 lines at 5 ms a line, with a queue of 256). +// +// The fake logger takes 5 ms a call: a real timer, which is the point (the +// time a 'logger' process takes is what the audit is slow by), and the only +// wait of the test. The client makes 200 requests that are each a line and +// leaves at once. The bound is on the lines that were not yet begun when the +// client's last request was answered, which a loaded machine cannot change; +// the time from the close to the end is only logged. +func TestConsoleSFTPEndsWithABacklogOfAuditLines(t *testing.T) { + const lines = 200 + var begun atomic.Int64 + r := startSFTPSetup(t, context.Background(), sftpPolicy(console.FileTransfer{Enabled: true}), "internal-sftp", + func(h *harness) { + h.runner.OnFunc([]string{"logger"}, func(execx.Cmd) (execx.Result, error) { + begun.Add(1) + time.Sleep(5 * time.Millisecond) // the fake 'logger': 5 ms a line + return execx.Result{}, nil + }) + }) + c := r.client() + for i := 0; i < lines; i++ { + if err := c.Mkdir(fmt.Sprintf("d%03d", i)); err != nil { + t.Fatal(err) + } + } + // The two start lines (the console's, the transfer's) are the first calls, + // then comes one for each request answered. + backlog := int64(2+lines) - begun.Load() + left := time.Now() + _ = c.Close() + status := <-r.done + t.Logf("handler returned %v after the client's close; %d lines were not yet begun at the close", time.Since(left), backlog) + if status != 0 { + t.Fatalf("status %d, stderr %q", status, r.h.err.String()) + } + // A line being logged, and the one the request that was answered last may + // still be handing over, are not in the queue. + if backlog > sftpAuditQueue+2 { + t.Errorf("%d lines waited for their log at the client's close, the queue holds %d", backlog, sftpAuditQueue) + } + log := consoleLog(r.h.runner) + if len(log) != 2+lines+2 { + t.Fatalf("%d lines logged, want %d: the start lines, a line for each request, the totals, the end", len(log), 2+lines+2) + } + for i := 0; i < lines; i++ { + if want := fmt.Sprintf(` path="/d%03d"`, i); !strings.HasSuffix(log[2+i], want) || !strings.Contains(log[2+i], "console sftp mkdir") { + t.Fatalf("line %d is %q, want the mkdir of d%03d in order", 2+i, log[2+i], i) + } + } + if !strings.Contains(log[lines+2], "console sftp end") || !strings.Contains(log[lines+3], "console end") { + t.Errorf("the last lines are %q", log[lines+2:]) + } +} From 46facb4a52d6a5f19da1708300117478f3e8bf9e Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:06:57 -0900 Subject: [PATCH 13/27] docs: the diff corpus run against the baseline is informational tests/README.md, diff corpus section: say that the run against the 0.1.18 baseline is informational (0 stale markers, 17 inert doubled markers, about 281 unmarked differences) and that the gate is the run against the previous release tag. Say that a @known directly followed by another @known is inert, that 17 exist and are kept as a record, and that a new doubled marker is merged into one. No marker, the runner or the policy changes. --- tests/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/README.md b/tests/README.md index 6b2da0cb..368f7789 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1047,6 +1047,18 @@ tests/diff/run.sh --self-test # the runner against itself and aga 0.2.19, the markers written for 0.2.1 to 0.2.18: most of the corpus). So do not drop a marker because a run against the previous release reports it; drop one only when no tag the corpus is run with differs from it. +- **The run against the baseline is informational, not a gate.** + `tests/diff/run.sh --all` (A = the 0.1.18 tag) currently shows 0 stale + markers, 17 inert doubled markers (below) and about 281 unmarked + differences (added audit `logger` calls on failing commands, and usage + text). The gate is the run against the previous release tag + (`tests/diff/run.sh --all --against `). +- **A doubled `@known` is inert.** The runner keeps one reason at a time, so + a `@known` directive directly followed by another `@known` replaces the + first, which is never consulted. 17 such pairs exist (in the `config`, + `devices`, `scopes` and `store` corpora); they are kept as a record under + the policy above. Merge a new doubled marker into one `@known` line that + gives both reasons. ## Characterisation tests: `tests/integration/characterisation.bats` From 37c402d8abf56026be29c1f293d9906c7f3c1b69 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:17:20 -0900 Subject: [PATCH 14/27] docs: tests/README.md names the FAIL: lines of gate-go gate-go.sh prints up to ten "FAIL: " lines above its FAIL verdict line (a failing test from the "--- FAIL:" lines of the log, else the package of a "FAIL " line). The README described the skipped and slowest lines but not these; add them in the same place and say which tool reads them. --- tests/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 368f7789..a11a9e03 100644 --- a/tests/README.md +++ b/tests/README.md @@ -89,7 +89,11 @@ skip) with the names of the skipped tests, at most 20, listed above the line: a test that skips for a missing tool passes silently, and an unexpected skip count is how a green run shows it did not test what it should; the ten slowest top-level tests of the run (`gate-go: slowest: TestX 47.1s`) follow -the skipped names, still above the verdict line. A run of the whole suite +the skipped names, still above the verdict line. A FAIL verdict is preceded, +last of the lines above it, by the failing tests, at most ten `FAIL: ` +lines (from the `--- FAIL:` lines of the log, else the package of a +`FAIL ` line), which `qargi feature verify` reads to name the failing +test. A run of the whole suite (no package listed, no `--tags`) first runs `make lint-go` (gofmt, `go vet` and golangci-lint in both tag sets, the Go half of the lint job of CI), so a finding fails the run before any test runs (`lint-failed` in the verdict line, From 9a794cfa1d448c014e81ec77c51e660cb8c4393a Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:27:47 -0900 Subject: [PATCH 15/27] console sftp: the audit queue holds 256 again, and its test checks order and completeness A full queue blocks the goroutine that serves a request, against the contract of sftpd.Config.Audit, and the whole session takes as long as its lines take to log whatever the size. The CHANGELOG item about the queue is dropped and the next one renumbered. The test no longer bounds the backlog by the constant under test. --- CHANGELOG.md | 17 +-------------- internal/cli/console_sftp.go | 10 ++++----- internal/cli/console_sftp_test.go | 35 +++++++++---------------------- 3 files changed, 16 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a7db6c..5cf69b7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,22 +77,7 @@ current behaviour; this file is where history lives. `docs/cli/config.md`, `docs/install/upgrading.md` and the manual page say so. -3. **A file transfer session ends sooner after the client leaves.** Every - request of a console file transfer that changes something (an upload, a - download, a delete, a rename, a make-directory, a refusal) is one audit - line, one `logger` process, and the console ends only when every line is - logged, in order. The lines wait in a queue while the client goes on, and - the queue held 256: a client that did many small requests (a tree of small - files) and then left was held until the console had logged all that was - still queued, about a second for 200 lines at 5 ms a line, which is where - a transfer seemed to linger after the client had left. The queue now holds - 32 lines, so at most 32 lines are left to log when the client leaves (about - 0.2 s at that speed) and a client that is ahead of the audit is held back - by it, request by request, as it goes. No line is dropped, none is logged - out of order and none after the console has ended. Nothing else changes: - the lines, their words and their order are as before. - -4. **A home that root cannot write is refused in one line, and a test says +3. **A home that root cannot write is refused in one line, and a test says so.** `config render --dry-run --out`, `config linux script --output` and `config linux remove-script --output` write as root, inside the home of the person who ran `sudo`. On an NFS export with `root_squash` root is mapped to diff --git a/internal/cli/console_sftp.go b/internal/cli/console_sftp.go index 2dde16e7..900a3e6c 100644 --- a/internal/cli/console_sftp.go +++ b/internal/cli/console_sftp.go @@ -156,11 +156,11 @@ type sftpTotals struct { // sftpAuditQueue is how many events wait for their log line. The session // ends only when every line is logged (none is dropped, none follows the end -// of the process), so what is queued when the client leaves is the wait of the -// client's end: at 256 it was about a second at 5 ms a line, and a client -// that is ahead of the log is now held back by it, a request at a time, -// instead of at the end. -const sftpAuditQueue = 32 +// of the process). A full queue blocks the goroutine that serves a request +// until a line is logged, so the number is a bound of the memory the queue +// holds, not of the wait at the end of the session: the whole session takes +// as long as its lines take to log, whatever the size. +const sftpAuditQueue = 256 // sftpAudit turns the events of the server into log lines, in order, off the // goroutines that serve the requests (each line is a 'logger' process). diff --git a/internal/cli/console_sftp_test.go b/internal/cli/console_sftp_test.go index aade222f..7829f06f 100644 --- a/internal/cli/console_sftp_test.go +++ b/internal/cli/console_sftp_test.go @@ -18,7 +18,6 @@ import ( "slices" "strings" "sync" - "sync/atomic" "syscall" "testing" "time" @@ -619,26 +618,20 @@ func TestConsoleSFTPWithoutAPolicyAnswer(t *testing.T) { } } -// A session whose audit lines are slow to log ends soon after the client -// leaves: every line is still logged, in order, before the console ends, so -// what the client waits for at its end is the lines queued, and the queue is -// short (sftpAuditQueue); a client that is ahead of the log is held back -// request by request, not all at once at the end (it was about a second for -// 200 lines at 5 ms a line, with a queue of 256). +// A session whose audit lines are slow to log still logs every one of them, +// in order, before the console ends: the start lines, a line for each +// request, the totals, the end. The client leaves while lines are still +// queued, and none is dropped or put out of order. // // The fake logger takes 5 ms a call: a real timer, which is the point (the -// time a 'logger' process takes is what the audit is slow by), and the only -// wait of the test. The client makes 200 requests that are each a line and -// leaves at once. The bound is on the lines that were not yet begun when the -// client's last request was answered, which a loaded machine cannot change; -// the time from the close to the end is only logged. -func TestConsoleSFTPEndsWithABacklogOfAuditLines(t *testing.T) { - const lines = 200 - var begun atomic.Int64 +// time a 'logger' process takes is what makes the audit slower than the +// client), and the only wait of the test. The time from the close to the end +// is only logged, it is not a bound: it depends on the machine. +func TestConsoleSFTPLogsEveryAuditLineInOrderWithASlowLogger(t *testing.T) { + const lines = 60 r := startSFTPSetup(t, context.Background(), sftpPolicy(console.FileTransfer{Enabled: true}), "internal-sftp", func(h *harness) { h.runner.OnFunc([]string{"logger"}, func(execx.Cmd) (execx.Result, error) { - begun.Add(1) time.Sleep(5 * time.Millisecond) // the fake 'logger': 5 ms a line return execx.Result{}, nil }) @@ -649,21 +642,13 @@ func TestConsoleSFTPEndsWithABacklogOfAuditLines(t *testing.T) { t.Fatal(err) } } - // The two start lines (the console's, the transfer's) are the first calls, - // then comes one for each request answered. - backlog := int64(2+lines) - begun.Load() left := time.Now() _ = c.Close() status := <-r.done - t.Logf("handler returned %v after the client's close; %d lines were not yet begun at the close", time.Since(left), backlog) + t.Logf("handler returned %v after the client's close", time.Since(left)) if status != 0 { t.Fatalf("status %d, stderr %q", status, r.h.err.String()) } - // A line being logged, and the one the request that was answered last may - // still be handing over, are not in the queue. - if backlog > sftpAuditQueue+2 { - t.Errorf("%d lines waited for their log at the client's close, the queue holds %d", backlog, sftpAuditQueue) - } log := consoleLog(r.h.runner) if len(log) != 2+lines+2 { t.Fatalf("%d lines logged, want %d: the start lines, a line for each request, the totals, the end", len(log), 2+lines+2) From a248379dbac836962c860dce7fa9197c28f4c1ed Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:35:50 -0900 Subject: [PATCH 16/27] docs: what a root_squash home does to the commands that write as root A home others may not search is refused by the path check; in one they may search the two commands that write as root write nothing. The advice is to write the file on the local disk and copy it as yourself. A test pins the refusal of the home others cannot search. --- CHANGELOG.md | 25 ++++-------- docs/cli/conventions.md | 2 +- internal/cli/outpath_squash_test.go | 63 ++++++++++++++++++++++++----- man/tacctl.1 | 6 +-- 4 files changed, 65 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf69b7f..40ae94b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,23 +77,14 @@ current behaviour; this file is where history lives. `docs/cli/config.md`, `docs/install/upgrading.md` and the manual page say so. -3. **A home that root cannot write is refused in one line, and a test says - so.** `config render --dry-run --out`, `config linux script --output` and - `config linux remove-script --output` write as root, inside the home of the - person who ran `sudo`. On an NFS export with `root_squash` root is mapped to - an unprivileged account and cannot write there, although the path is inside - the home. This was already a plain refusal and is unchanged: nothing is - written, no file or directory is left half made, a file of that name stays - as it was, and the line names the path and the cause (`Cannot write - : Permission denied`, `Cannot create '': Permission denied` or - `install: cannot create regular file '': Permission denied`), exit - status 1. The files written as the caller (`device config plan`, - `device reports export`, `device support-bundle`) take the caller's - identity and are not affected. A test (`TestOutPathRootSquashedHome...`) - pins the three, with a directory its owner cannot write for the refusal. - `docs/cli/conventions.md` and the manual page say what to do: name a path - inside the home that root can write, or run the command without `sudo` - where the tier allows it. +3. **What a home on an NFS `root_squash` export does to the commands that + write as root is documented and tested.** The behaviour is unchanged: a + home that others may not search is refused by the path check + (`cannot be resolved (Permission denied)`), and in one that others may + search `config render --dry-run` and `config linux script|remove-script` + write nothing and say `Permission denied`, with the path. Tests pin both, + and `docs/cli/conventions.md` and the manual page say to write the file on + the local disk of the host and copy it to the home as yourself. ## 0.2.29 (2026-11-09) diff --git a/docs/cli/conventions.md b/docs/cli/conventions.md index 503823f2..22124501 100644 --- a/docs/cli/conventions.md +++ b/docs/cli/conventions.md @@ -19,7 +19,7 @@ These patterns apply across every subcommand family: - **Service restart** — changes to the store, and to the `tacctl.yaml` settings a backend renders (command rules, listeners, `backends.*`), re-render every enabled backend and restart the ones whose files changed. Settings only device configs read (mgmt-acl permits + names, priv-exec mappings, per-scope AAA order, exec timeout, group labels) and tacctl's own tunables (bcrypt cost, password age, …) restart nothing. - **Notices** — INFO says what was done: the change, the service restart, a sync. WARN says that something failed or that the operator has to act: a sync that failed (with the command to retry it), hosts left to sync (with the command), a device that still accepts a user who must change the password. A fact is said once, at one level. A `user` verb that changes an account syncs this server's own accounts at once and names the other enrolled hosts it reaches in one warning; on a terminal it asks `Sync these hosts now? [y/N]` (the default is no and `--yes` does not answer it); see [User Commands](user.md). - **Flags** — long-form flags (`--hash`, `--scopes`, `--scope`, `--prefixes`, `--secret`, `--protocols`, `--vendor-attrs`, `--match`, `--action`, `--branch`, `--protocol`, `--method`, `--backend`, `--listener`, `--out`) take a single argument; `--default`, `--force`, `--legacy`, `--check`, `--replace`, `--json`, `--local`, `--all`, `--dry-run`, `--long`, `--apply`, `--hosts` and `--yes` take none. Required positional args come before flags. -- **Paths you name to write** — a flag that names a file or directory tacctl writes (`--out` and `--out-dir` of `device config plan`, `--out` of `device reports export` and of `config render --dry-run`, `--output` (`-o`) of `config linux script` and `remove-script`) is checked first: the path must be inside your home, the home of the person who ran `sudo` (else of the user running tacctl) as the account database gives it, never `$HOME`. Your shell expands `~` and variables before tacctl sees them; tacctl itself expands neither, so a path that still starts with `~` or holds a `$` or a backtick, an empty path, a path that leaves the home through `..` or through a symbolic link, and the home itself are refused with the one-sentence rule (`tacctl does not expand ~ or variables; name a path inside your home, relative to the current directory`) and nothing is written. A relative path is taken from the current directory. `device support-bundle --out` takes a name, not a path, and writes under `support-bundles` in your home ([Support bundles](../devices/support-bundle.md)). Files tacctl writes as you (`device config plan`, `device reports export`, `device support-bundle`) keep the protections they had: new files only, a link never followed, `--force` where it exists to replace. Two commands write as root: `config render --dry-run` makes its directory and files root-owned (0700, 0600), through a handle on the directory so that a link planted in it is not followed out, and into a directory that is new or empty only; `config linux script` and `remove-script` make the file as root (0600, 0644), hand it to the person who ran `sudo`, replace a file of that name without `--force`, and refuse a directory (or a link to one) as the name. A home directory of `/` is refused for all of these. A home on an NFS export with `root_squash` is inside the home and so passes the check, but the two commands that write as root cannot write there (the server maps root to an unprivileged account): they write nothing, leave no file (a file of that name that was there stays as it was), say so in one line that names the path and the cause (`Cannot write : Permission denied`, `Cannot create '': Permission denied` or `install: cannot create regular file '': Permission denied`) and exit with status 1. Name a path inside your home that root can write, or run the command without `sudo` where your tier allows it; the commands that write as you are not affected. +- **Paths you name to write** — a flag that names a file or directory tacctl writes (`--out` and `--out-dir` of `device config plan`, `--out` of `device reports export` and of `config render --dry-run`, `--output` (`-o`) of `config linux script` and `remove-script`) is checked first: the path must be inside your home, the home of the person who ran `sudo` (else of the user running tacctl) as the account database gives it, never `$HOME`. Your shell expands `~` and variables before tacctl sees them; tacctl itself expands neither, so a path that still starts with `~` or holds a `$` or a backtick, an empty path, a path that leaves the home through `..` or through a symbolic link, and the home itself are refused with the one-sentence rule (`tacctl does not expand ~ or variables; name a path inside your home, relative to the current directory`) and nothing is written. A relative path is taken from the current directory. `device support-bundle --out` takes a name, not a path, and writes under `support-bundles` in your home ([Support bundles](../devices/support-bundle.md)). Files tacctl writes as you (`device config plan`, `device reports export`, `device support-bundle`) keep the protections they had: new files only, a link never followed, `--force` where it exists to replace. Two commands write as root: `config render --dry-run` makes its directory and files root-owned (0700, 0600), through a handle on the directory so that a link planted in it is not followed out, and into a directory that is new or empty only; `config linux script` and `remove-script` make the file as root (0600, 0644), hand it to the person who ran `sudo`, replace a file of that name without `--force`, and refuse a directory (or a link to one) as the name. A home directory of `/` is refused for all of these. On an NFS export with `root_squash` root is mapped to an unprivileged account. A home that others may not search (0700, 0750) is refused by the path check itself, for every command that names a path, with ` '' cannot be resolved (Permission denied): ...`. In a home that others may search the check passes, and the two commands that write as root cannot write there: they write nothing, leave no half-made file (a file of that name that was there stays as it was), say so in one line that names the path and the cause (`Cannot write : Permission denied`, `Cannot create '': Permission denied` or `install: cannot create regular file '': Permission denied`) and exit with status 1. Write the file somewhere that is not root-squashed (the local disk of the host) and copy it to your home as yourself. ## Top-Level Commands diff --git a/internal/cli/outpath_squash_test.go b/internal/cli/outpath_squash_test.go index be6baf56..4f909d5c 100644 --- a/internal/cli/outpath_squash_test.go +++ b/internal/cli/outpath_squash_test.go @@ -8,10 +8,12 @@ import ( ) // squashedDir makes a directory inside the sandbox's home that its owner -// cannot write: what a home on an NFS export with root_squash is to tacctl -// under sudo, where root is mapped to nobody and the path check (which only -// looks at where the path is) has passed. The test process is not root, so -// the refusal comes from the kernel, as the server's does (EACCES). +// cannot write, with a file in it: what a home on an NFS export with +// root_squash that others may search (0755, say) is to the two commands that +// write as root under sudo, where root is mapped to an unprivileged account +// and the path check, which ran as root and only looks at where the path is, +// has passed. The test process is not root, so the refusal comes from the +// kernel, as the server's does (EACCES). func squashedDir(t *testing.T, home string) string { t.Helper() if os.Geteuid() == 0 { @@ -45,12 +47,12 @@ func leftIn(t *testing.T, dir string) []string { return names } -// A path inside a home that root cannot write (an NFS root_squash export) -// passes the check of outPath and is refused by the write: each of the three -// commands that write as root says in one line which path was not written and -// why ("Permission denied"), exits 1, and leaves no new or half-written file -// and the old one as it was. The files written as the caller (plan, reports -// export, support-bundle) are not concerned: they take the caller's identity. +// A path inside a home that others may search but root, mapped to an +// unprivileged account, cannot write (an NFS root_squash export) passes the +// check of outPath and is refused by the write: each of the three commands +// that write as root says in one line which path was not written and why +// ("Permission denied"), exits 1, and leaves no new or half-written file and +// the old one as it was. func TestOutPathRootSquashedHomeIsRefusedPlainly(t *testing.T) { hs := newHostSandbox(t) d := squashedDir(t, hs.dir) @@ -108,3 +110,44 @@ func TestOutPathRootSquashedEmptyDirIsRefusedPlainly(t *testing.T) { t.Errorf("left %v", got) } } + +// A home that others may not search (0700, 0750), seen as the unprivileged +// account root is mapped to, is refused by the path check itself, for every +// command that names a path (the three that write as root are run here): the +// check cannot resolve the path. Mode 0000 stands for it here, since the test +// user owns the directory and could search anything less. Nothing is written. +func TestOutPathRootSquashedHomeOthersCannotSearchIsRefusedByTheCheck(t *testing.T) { + hs := newHostSandbox(t) + if os.Geteuid() == 0 { + t.Skip("root searches a directory without the search permission, so there is no refusal to see") + } + d := filepath.Join(hs.dir, "closed") + if err := os.Mkdir(d, 0o700); err != nil { + t.Fatal(err) + } + if err := os.Chmod(d, 0o000); err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = os.Chmod(d, 0o700) }) + path := filepath.Join(d, "x") + for _, args := range [][]string{ + {"config", "linux", "script", "--scope", "lab", "--server", "192.0.2.10", "--output", path}, + {"config", "linux", "remove-script", "--output", path}, + {"config", "render", "--dry-run", "--out", path}, + } { + hs.run(nil, args...) + if hs.code != 1 { + t.Errorf("%v: status %d, want 1", args, hs.code) + } + flag := args[len(args)-2] + if want := flag + " '" + path + "' cannot be resolved (Permission denied)"; !strings.Contains(hs.err.String(), want) { + t.Errorf("%v: stderr %q, want it to hold %q", args, hs.err.String(), want) + } + } + if err := os.Chmod(d, 0o700); err != nil { + t.Fatal(err) + } + if got := leftIn(t, d); len(got) != 0 { + t.Errorf("left %v", got) + } +} diff --git a/man/tacctl.1 b/man/tacctl.1 index b498046d..6a82f156 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -3480,7 +3480,7 @@ and so on) instead of installing them. Nothing live is touched: no artifact, no render record, no service. A hand edit does not stop a dry run. .I dir must be new or empty and is private to root (the artifacts hold secrets and -password hashes). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. On a home exported by NFS with \fBroot_squash\fR, root cannot write there: nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied" (name a path root can write, or run the command without \fBsudo\fR where your tier allows it). +password hashes). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. On a home exported by NFS with \fBroot_squash\fR, root is mapped to an unprivileged account: a home that others may not search is refused by the path check ("cannot be resolved (Permission denied)"), and in one that others may search nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied". Write the file on the local disk of the host, which is not root-squashed, and copy it to the home as yourself. .\" BEGIN GENERATED: command config render .RS .PP @@ -4915,7 +4915,7 @@ the port, as they were). .B \-\-output names the file (default .B tacctl\-linux\-.sh -in the current directory). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The default name is not a path you named and is not checked. A file of the name you give is replaced; a directory, or a link to one, is refused and nothing is written in it. The file is made as root with mode 0600, and under \fBsudo\fR it is handed to the person who ran it. On a home exported by NFS with \fBroot_squash\fR, root cannot write there: nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied" (name a path root can write, or run the command without \fBsudo\fR where your tier allows it). +in the current directory). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The default name is not a path you named and is not checked. A file of the name you give is replaced; a directory, or a link to one, is refused and nothing is written in it. The file is made as root with mode 0600, and under \fBsudo\fR it is handed to the person who ran it. On a home exported by NFS with \fBroot_squash\fR, root is mapped to an unprivileged account: a home that others may not search is refused by the path check ("cannot be resolved (Permission denied)"), and in one that others may search nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied". Write the file on the local disk of the host, which is not root-squashed, and copy it to the home as yourself. .\" BEGIN GENERATED: command config linux script .RS .PP @@ -5075,7 +5075,7 @@ tac-* groups and installed packages are left in place. .B \-\-output names the file (default .B tacctl\-linux\-remove.sh -in the current directory). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The default name is not a path you named and is not checked. A file of the name you give is replaced; a directory, or a link to one, is refused and nothing is written in it. The file is made as root with mode 0644, and under \fBsudo\fR it is handed to the person who ran it. On a home exported by NFS with \fBroot_squash\fR, root cannot write there: nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied" (name a path root can write, or run the command without \fBsudo\fR where your tier allows it). +in the current directory). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The default name is not a path you named and is not checked. A file of the name you give is replaced; a directory, or a link to one, is refused and nothing is written in it. The file is made as root with mode 0644, and under \fBsudo\fR it is handed to the person who ran it. On a home exported by NFS with \fBroot_squash\fR, root is mapped to an unprivileged account: a home that others may not search is refused by the path check ("cannot be resolved (Permission denied)"), and in one that others may search nothing is written, a file of that name stays as it was, and the error names the path and says "Permission denied". Write the file on the local disk of the host, which is not root-squashed, and copy it to the home as yourself. .\" BEGIN GENERATED: command config linux remove-script .RS .PP From 8e36819553f05bbd06e1cc666225f92cdd86e85f Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:29:57 -0900 Subject: [PATCH 17/27] gate-go: the package names stand in only when no test failed A run with a failing test and a package that failed to build names only the test; the build failure is counted in failures= and is in the log. The header, AGENTS.md and tests/README.md say so, and a bats case pins the mixed log. --- AGENTS.md | 2 +- tests/README.md | 4 ++-- tests/integration/gate_go.bats | 11 +++++++++++ tests/tools/gate-go.sh | 10 ++++++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8ef8cf67..df8b72f7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,7 +24,7 @@ groups and scopes, network devices and enrolled Linux hosts. - 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, and a `GATE-GO FAIL` line has up to ten `FAIL: ` lines above it. `GATE_TMPFS=1 make gate-go` runs the tests' sandboxes on `/dev/shm`, about three times faster. +- 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, and a `GATE-GO FAIL` line has up to ten `FAIL: ` lines above it (the packages instead, when no test failed). `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`) diff --git a/tests/README.md b/tests/README.md index a11a9e03..076ec8cc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -91,8 +91,8 @@ count is how a green run shows it did not test what it should; the ten slowest top-level tests of the run (`gate-go: slowest: TestX 47.1s`) follow the skipped names, still above the verdict line. A FAIL verdict is preceded, last of the lines above it, by the failing tests, at most ten `FAIL: ` -lines (from the `--- FAIL:` lines of the log, else the package of a -`FAIL ` line), which `qargi feature verify` reads to name the failing +lines (from the `--- FAIL:` lines of the log, or, when no test failed, the +package of a `FAIL ` line), which `qargi feature verify` reads to name the failing test. A run of the whole suite (no package listed, no `--tags`) first runs `make lint-go` (gofmt, `go vet` and golangci-lint in both tag sets, the Go half of the lint job of CI), so a diff --git a/tests/integration/gate_go.bats b/tests/integration/gate_go.bats index 1ce5971b..0ece29c2 100644 --- a/tests/integration/gate_go.bats +++ b/tests/integration/gate_go.bats @@ -28,6 +28,7 @@ test) case "$STUB_MODE" in failmany) for i in $(seq -w 12); do printf -- '--- FAIL: TestF%s (0.00s)\n' "$i"; done printf 'FAIL\tp/a\t0.1s\nok \tp/b\t0.1s\n'; exit 1 ;; failslow) printf -- '--- SKIP: TestY (0.00s)\n--- PASS: TestSlow (47.12s)\n--- FAIL: TestX (0.00s)\nFAIL\tp/a\t0.1s\nok \tp/b\t0.1s\n'; exit 1 ;; + mixed) printf -- '--- FAIL: TestX (0.00s)\nFAIL\tp/a\t0.1s\nFAIL\tp/b [build failed]\n'; exit 1 ;; build) printf 'FAIL\tp/a [build failed]\nok \tp/b\t0.1s\n'; exit 1 ;; panic) printf 'panic: boom [recovered]\nFAIL\tp/a\t0.1s\nFAIL\tp/b\t0.1s\nFAIL\n'; exit 1 ;; hang) exec sleep 30 ;; @@ -184,6 +185,16 @@ sleeper_below() { [[ "$(printf '%s\n' "${lines[@]}" | grep -c '^FAIL: ')" -eq 2 ]] } +@test "a failing test and a package that failed to build: only the test is named, the build failure is counted" { + STUB_MODE=mixed run -1 "$GATE" -o "$LOG" + [[ "${lines[-1]}" == "GATE-GO FAIL rc=1 packages=0/2 failures=3 "* ]] + [[ "${lines[-2]}" == "FAIL: TestX" ]] + [[ "$(printf '%s\n' "${lines[@]}" | grep -c '^FAIL: ')" -eq 1 ]] + [[ "$output" != *"FAIL: p/b"* ]] + # the build failure is in the log + grep -q '^FAIL p/b \[build failed\]' "$LOG" +} + @test "a PASS names no failing test" { STUB_MODE=ok run -0 "$GATE" -o "$LOG" [[ "$output" != *"FAIL: "* ]] diff --git a/tests/tools/gate-go.sh b/tests/tools/gate-go.sh index 86c188c5..f4b2e980 100755 --- a/tests/tools/gate-go.sh +++ b/tests/tools/gate-go.sh @@ -22,10 +22,12 @@ # A FAIL verdict is preceded, last of the lines above it, by the failing tests, # at most ten, one 'FAIL: ' line each, from the '--- FAIL: TestX' lines of # the log (a top-level test and a subtest each, a name once, in the order of -# the log; the form 'qargi feature verify' reads). A package that failed -# without a failing test (a build failure, a panic, a timeout) is named by its -# 'FAIL ' line instead ('FAIL: '). The failures= field of the -# verdict line counts every FAIL and panic line, listed or not. +# the log; the form 'qargi feature verify' reads). Only when no test failed +# (no '--- FAIL:' line at all: a build failure, a panic, a timeout) are the +# packages named by their 'FAIL ' lines instead ('FAIL: '); a +# run with a failing test and a package that failed to build names only the +# test. The failures= field of the verdict line counts every FAIL and panic +# line, listed or not, and the build failure is in the log. # # A run of the whole suite (no package listed, no --tags) first runs 'make # lint-go': gofmt, go vet and golangci-lint in both tag sets, the Go half of From ef79a91859d6a3907fed97e1da47ee3260e2949d Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:34:13 -0900 Subject: [PATCH 18/27] tier: the message of the note check describes the condition The check fails for a row without Cmd, and also for an AnySub row that has a Sub and for a row that is not AnySub and has none. The old text, 'a row without Cmd and Sub', no longer described that, so the message now names the condition: a note on a row without Cmd, or whose Sub does not match AnySub. --- internal/tier/tier_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/tier/tier_test.go b/internal/tier/tier_test.go index a2cce59f..69ac043c 100644 --- a/internal/tier/tier_test.go +++ b/internal/tier/tier_test.go @@ -839,7 +839,7 @@ func TestNotesAreOnePerCommandAndSub(t *testing.T) { } seen[k] = true if r.Cmd == "" || (r.Sub == "") != r.AnySub { - t.Errorf("a note on a row without Cmd and Sub: %+v", r) + t.Errorf("a note on a row without Cmd, or whose Sub does not match AnySub: %+v", r) } } if len(seen) != len(Notes()) || len(seen) < 13 { From 7e9ebf2d01a021fc360c34560291a6de203a5c72 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:56:02 -0900 Subject: [PATCH 19/27] outpath: the check runs as the caller for the commands that write as the caller outPath stat'ed the path as root (Lstat, EvalSymlinks) also for the commands that then write through asCaller: device config plan, device reports export and device support-bundle. On an NFS home with root_squash that others cannot search (0700, 0750) root cannot look at the path, so the check refused it with "cannot be resolved (Permission denied)" although the write, as the caller, would work. outPathAsCaller runs the file-system calls of the check through asCaller; outPath keeps running them as root for the two commands that write as root (config render --dry-run, config linux script|remove-script), where the check must fail where the write would. Both are one function, checkOutPath, so there is one place for the rules. A test replaces the identity switch, which needs root, with hooks.asCallerRun; the switch itself stays covered by TestWithFSIdentity. A "cannot be resolved ()" refusal is about what the file system says, not about the spelling of the path: it now gives the cause and the path and no longer ends with the hint about ~ and variables, which stays on the refusals about the spelling. The CHANGELOG, the docs page and the man page follow in the next commit. --- internal/cli/device_config_plan.go | 2 +- internal/cli/device_reports_view.go | 2 +- internal/cli/device_support_bundle.go | 2 +- internal/cli/hooks.go | 3 + internal/cli/outpath.go | 62 +++++++++++--- internal/cli/outpath_squash_test.go | 118 +++++++++++++++++++++++++- internal/cli/outpath_test.go | 20 ++++- 7 files changed, 192 insertions(+), 17 deletions(-) diff --git a/internal/cli/device_config_plan.go b/internal/cli/device_config_plan.go index 02fdc1c2..7dda42ae 100644 --- a/internal/cli/device_config_plan.go +++ b/internal/cli/device_config_plan.go @@ -133,7 +133,7 @@ func (inv *invocation) parsePlanOptions(p Parsed) (planOptions, error) { if *f.path == "" { continue } - path, err := inv.outPath(f.flag, *f.path) + path, err := inv.outPathAsCaller(f.flag, *f.path) if err != nil { return bad(err.Error()) } diff --git a/internal/cli/device_reports_view.go b/internal/cli/device_reports_view.go index 245e8304..b3c9481e 100644 --- a/internal/cli/device_reports_view.go +++ b/internal/cli/device_reports_view.go @@ -264,7 +264,7 @@ func (inv *invocation) deviceReportsExport(args []string) error { // the file is written inside the caller's home only out := "" if p.Has("--out") { - if out, err = inv.outPath("--out", p.Value("--out")); err != nil { + if out, err = inv.outPathAsCaller("--out", p.Value("--out")); err != nil { return inv.argErr(err.Error(), usage) } } diff --git a/internal/cli/device_support_bundle.go b/internal/cli/device_support_bundle.go index 00fb6ec6..ff87cc04 100644 --- a/internal/cli/device_support_bundle.go +++ b/internal/cli/device_support_bundle.go @@ -230,7 +230,7 @@ func (inv *invocation) bundleDir(out, device string) (string, error) { if err != nil { return "", inv.usageErr("--out: " + err.Error() + ".") } - dir, err := inv.outPath("--out", filepath.Join(home, bundleFolder, out)) + dir, err := inv.outPathAsCaller("--out", filepath.Join(home, bundleFolder, out)) if err != nil { return "", inv.usageErr(err.Error()) } diff --git a/internal/cli/hooks.go b/internal/cli/hooks.go index 56684184..a3673408 100644 --- a/internal/cli/hooks.go +++ b/internal/cli/hooks.go @@ -110,6 +110,9 @@ type hooks struct { pdfStat func(path string) (uid uint32, perm fs.FileMode, err error) // sshAccountOf looks an account up in the local account database. sshAccountOf func(name string) (sshAccount, error) + // asCallerRun replaces asCaller where a test cannot switch the + // file-system identity (nil: asCaller). + asCallerRun func(fn func() error) error // homeOfUID looks the home directory of an account up by its id in the // local account database (nil: the system's). homeOfUID func(uid int) (string, error) diff --git a/internal/cli/outpath.go b/internal/cli/outpath.go index b25d517a..dab626fd 100644 --- a/internal/cli/outpath.go +++ b/internal/cli/outpath.go @@ -55,10 +55,47 @@ func (inv *invocation) callerHome() (string, error) { // do. An empty path, a NUL, a first component that starts with '~', a '$' or // a backtick, and a path that, with the symbolic links of its longest existing // part resolved, is not strictly inside the caller's home are refused. +// +// The refusals about the spelling of the path end with outPathHint; one that +// is about what the file system says ("cannot be resolved") gives the cause +// and the path and no hint, since it is not a matter of '~' or variables. +// +// The file-system calls run as this process, which is root under sudo. A +// command that then writes as the caller (asCaller) uses outPathAsCaller +// instead, so that the check sees what the write will see: on an NFS home +// with root_squash that others cannot search, root cannot stat the path and +// the caller can. A command that writes as root keeps outPath: the check +// must fail where its write would. func (inv *invocation) outPath(flag, p string) (string, error) { + return inv.checkOutPath(flag, p, func(fn func() error) error { return fn() }) +} + +// outPathAsCaller is outPath with the file-system calls of the check run with +// the identity of the person who ran sudo (inv.callerRun), for a command that +// writes the file as that person. +func (inv *invocation) outPathAsCaller(flag, p string) (string, error) { + return inv.checkOutPath(flag, p, inv.callerRun) +} + +// callerRun runs fn as the person who ran sudo: asCaller, or the hook that +// replaces it in a test (the identity switch itself needs root). +func (inv *invocation) callerRun(fn func() error) error { + if h := inv.hooks; h != nil && h.asCallerRun != nil { + return h.asCallerRun(fn) + } + return inv.asCaller(fn) +} + +// checkOutPath is the one place of the rules; run runs the calls that touch +// the file system (the symbolic links of the path and of its directory). +func (inv *invocation) checkOutPath(flag, p string, run func(func() error) error) (string, error) { refuse := func(why string) (string, error) { return "", errors.New(flag + " " + why + ": " + outPathHint + ".") } + // what the file system says is told as it is, with the path + unresolved := func(err error) (string, error) { + return "", errors.New(flag + " '" + p + "' cannot be resolved (" + cfgErrno(err) + ").") + } switch { case p == "": return refuse("takes a path, and none was given") @@ -76,24 +113,29 @@ func (inv *invocation) outPath(flag, p string) (string, error) { } abs, err := filepath.Abs(p) if err != nil { - return refuse("'" + p + "' cannot be resolved (" + err.Error() + ")") + return unresolved(err) } outside := func() (string, error) { return refuse("'" + p + "' is not inside your home (" + home + "), the only place tacctl writes") } - // the path itself, a symbolic link in it followed (it must lead inside) - full, err := resolveExisting(abs) - if err != nil { - return refuse("'" + p + "' cannot be resolved (" + cfgErrno(err) + ")") + // the path itself, a symbolic link in it followed (it must lead inside), + // and what is written: its directory resolved, the name as given + var full, dir string + if err := run(func() (err error) { + if full, err = resolveExisting(abs); err != nil { + return err + } + if !strictlyInside(home, full) { + return nil // refused below, as outside + } + dir, err = resolveExisting(filepath.Dir(abs)) + return err + }); err != nil { + return unresolved(err) } if !strictlyInside(home, full) { return outside() } - // what is written: its directory resolved, the name as given - dir, err := resolveExisting(filepath.Dir(abs)) - if err != nil { - return refuse("'" + p + "' cannot be resolved (" + cfgErrno(err) + ")") - } out := filepath.Join(dir, filepath.Base(abs)) if !strictlyInside(home, out) { return outside() diff --git a/internal/cli/outpath_squash_test.go b/internal/cli/outpath_squash_test.go index 4f909d5c..567218a6 100644 --- a/internal/cli/outpath_squash_test.go +++ b/internal/cli/outpath_squash_test.go @@ -112,9 +112,10 @@ func TestOutPathRootSquashedEmptyDirIsRefusedPlainly(t *testing.T) { } // A home that others may not search (0700, 0750), seen as the unprivileged -// account root is mapped to, is refused by the path check itself, for every -// command that names a path (the three that write as root are run here): the -// check cannot resolve the path. Mode 0000 stands for it here, since the test +// account root is mapped to, is refused by the path check itself for the +// commands that write as root (the three of them are run here): the check +// cannot resolve the path, and says what the system says, with the path and +// without the hint about '~'. Mode 0000 stands for it here, since the test // user owns the directory and could search anything less. Nothing is written. func TestOutPathRootSquashedHomeOthersCannotSearchIsRefusedByTheCheck(t *testing.T) { hs := newHostSandbox(t) @@ -143,6 +144,9 @@ func TestOutPathRootSquashedHomeOthersCannotSearchIsRefusedByTheCheck(t *testing if want := flag + " '" + path + "' cannot be resolved (Permission denied)"; !strings.Contains(hs.err.String(), want) { t.Errorf("%v: stderr %q, want it to hold %q", args, hs.err.String(), want) } + if strings.Contains(hs.err.String(), "~") { + t.Errorf("%v: the refusal carries the hint about '~': %q", args, hs.err.String()) + } } if err := os.Chmod(d, 0o700); err != nil { t.Fatal(err) @@ -151,3 +155,111 @@ func TestOutPathRootSquashedHomeOthersCannotSearchIsRefusedByTheCheck(t *testing t.Errorf("left %v", got) } } + +// closedForRoot makes a mode-0000 directory in dir and returns it with a hook +// that stands for the identity switch of asCaller: inside the function it runs +// the directory can be searched (the caller owns it), outside it cannot (root +// mapped to an unprivileged account by root_squash). The switch itself needs +// root, so it cannot be done here (withFSIdentity is tested with the system +// calls injected, TestWithFSIdentity): what is tested is that the check's file +// system calls run inside the hook and the root variant's do not. calls counts +// the runs. +func closedForRoot(t *testing.T, dir string) (closed string, hook func(func() error) error, calls *int) { + t.Helper() + if os.Geteuid() == 0 { + t.Skip("root searches a directory without the search permission, so there is no refusal to see") + } + closed = filepath.Join(dir, "closed") + if err := os.Mkdir(closed, 0o700); err != nil { + t.Fatal(err) + } + if err := os.Chmod(closed, 0o000); err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = os.Chmod(closed, 0o700) }) + n := 0 + return closed, func(fn func() error) error { + n++ + if err := os.Chmod(closed, 0o700); err != nil { + return err + } + defer func() { _ = os.Chmod(closed, 0o000) }() + return fn() + }, &n +} + +// The check of the commands that write as the caller runs as the caller: a +// home others cannot search is no obstacle to it, where the root variant, +// which the commands that write as root keep, is refused. +func TestOutPathAsCallerSearchesAsTheCaller(t *testing.T) { + inv, sb := outInv(t) + closed, hook, calls := closedForRoot(t, sb.home) + inv.hooks.asCallerRun = hook + path := filepath.Join(closed, "x") + + if _, err := inv.outPath("--out", path); err == nil || !strings.Contains(err.Error(), "cannot be resolved (Permission denied)") { + t.Errorf("as root: %v, want the refusal", err) + } + if *calls != 0 { + t.Errorf("the root variant ran %d times as the caller", *calls) + } + got, err := inv.outPathAsCaller("--out", path) + if err != nil || got != path { + t.Errorf("as the caller: %q, %v; want %q", got, err, path) + } + if *calls != 1 { + t.Errorf("the check ran as the caller %d times, want 1", *calls) + } + // the other rules are the same: a spelling is refused with the hint, + // outside the home is refused, whoever asks + for _, c := range []struct{ p, want string }{{"~/x", "starts with '~'"}, {"/etc/x", "not inside your home"}} { + if _, err := inv.outPathAsCaller("--out", c.p); err == nil || !strings.Contains(err.Error(), c.want) { + t.Errorf("%s: %v", c.p, err) + } + } + // a failure of the hook's own (the identity not taken) is a refusal too + inv.hooks.asCallerRun = func(func() error) error { return os.ErrPermission } + if _, err := inv.outPathAsCaller("--out", path); err == nil || !strings.Contains(err.Error(), "cannot be resolved (Permission denied)") { + t.Errorf("a failed switch: %v", err) + } +} + +// The three commands that write as the caller run the check as the caller +// (the hook stands for the identity switch, see closedForRoot): 'plan' gets +// past the check in a directory that root, mapped by root_squash, cannot +// search; 'support-bundle' names a folder of the home, so it is only seen to +// take the hook. +func TestOutPathCommandsThatWriteAsTheCallerCheckAsTheCaller(t *testing.T) { + b := newPullBox(t) + b.devices([3]string{"lab-j", "192.168.1.20", "juniper"}) + closed, hook, calls := closedForRoot(t, b.sb.homePath(".")) + b.sb.hooks.asCallerRun = hook + path := filepath.Join(closed, "p.txt") + + b.run("device", "config", "plan", "lab-j", "--out", path) + if strings.Contains(b.sb.stderr(), "cannot be resolved") || *calls == 0 { + t.Errorf("plan --out: exit %d, %d runs as the caller: %q", b.sb.code, *calls, b.sb.stderr()) + } + *calls = 0 + b.run("device", "config", "plan", "lab-j", "--out-dir", filepath.Join(closed, "d")) + if strings.Contains(b.sb.stderr(), "cannot be resolved") || *calls == 0 { + t.Errorf("plan --out-dir: exit %d, %d runs as the caller: %q", b.sb.code, *calls, b.sb.stderr()) + } + *calls = 0 + b.run("device", "support-bundle", "lab-j") + if strings.Contains(b.sb.stderr(), "cannot be resolved") || *calls == 0 { + t.Errorf("support-bundle: exit %d, %d runs as the caller: %q", b.sb.code, *calls, b.sb.stderr()) + } +} + +// 'device reports export --out' too (a report that does not exist is no +// matter: the check comes first). +func TestOutPathReportsExportChecksAsTheCaller(t *testing.T) { + b := newReportsBox(t) + closed, hook, calls := closedForRoot(t, b.sb.homePath(".")) + b.sb.hooks.asCallerRun = hook + b.as("alice", asSuper, "export", "anything", "--out", filepath.Join(closed, "x.csv")) + if strings.Contains(b.sb.stderr(), "cannot be resolved") || *calls == 0 { + t.Errorf("export --out: exit %d, %d runs as the caller: %q", b.sb.code, *calls, b.sb.stderr()) + } +} diff --git a/internal/cli/outpath_test.go b/internal/cli/outpath_test.go index 735ae0a8..7833dced 100644 --- a/internal/cli/outpath_test.go +++ b/internal/cli/outpath_test.go @@ -52,7 +52,6 @@ func TestOutPathRefusals(t *testing.T) { {"link out", sb.homePath("escape/x"), "not inside your home"}, {"link out, deep", sb.homePath("escape/a/b/c"), "not inside your home"}, {"link itself out", sb.homePath("escape"), "not inside your home"}, - {"dangling link", sb.homePath("dangling"), "cannot be resolved"}, {"sibling with the home's name as prefix", sb.home + "-other/x", "not inside your home"}, } { got, err := inv.outPath("--out", c.path) @@ -66,6 +65,25 @@ func TestOutPathRefusals(t *testing.T) { } } +// What the file system says is told with the path and the cause and without +// the hint about '~' and variables, which has nothing to do with it. +func TestOutPathUnresolvedHasNoHint(t *testing.T) { + inv, sb := outInv(t) + if err := os.Symlink(filepath.Join(t.TempDir(), "gone"), sb.homePath("dangling")); err != nil { + t.Fatal(err) + } + for _, run := range []func(flag, p string) (string, error){inv.outPath, inv.outPathAsCaller} { + p := sb.homePath("dangling") + got, err := run("--out", p) + if err == nil || got != "" { + t.Fatalf("%q, %v; want a refusal", got, err) + } + if !strings.HasPrefix(err.Error(), "--out '"+p+"' cannot be resolved (No such file or directory)") || strings.Contains(err.Error(), "~") || strings.Contains(err.Error(), outPathHint) { + t.Errorf("%v", err) + } + } +} + func TestOutPathAccepts(t *testing.T) { inv, sb := outInv(t) if err := os.MkdirAll(sb.homePath("d/e"), 0o755); err != nil { From c505db292844882e11d9a39591ac1bf23aae0ec5 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:56:02 -0900 Subject: [PATCH 20/27] docs: the commands that write as the caller check the path as the caller Describes the change of the previous commit. CHANGELOG item 3 of 0.2.30 (unreleased) is narrowed to the two commands that write as root (config render --dry-run, config linux script|remove-script), which still check the path as root and so still refuse a root_squash home that others cannot search; the new item 4 is the user-visible part: device config plan, device reports export and device support-bundle work in such a home, and a "cannot be resolved" refusal no longer carries the hint about ~ and variables. docs/cli/conventions.md (Paths you name to write) now says which commands check as the caller and which as root, and man/tacctl.1 says it at the device config plan --out spot. --- CHANGELOG.md | 34 +++++++++++++++++++++++++++------- docs/cli/conventions.md | 2 +- man/tacctl.1 | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40ae94b7..285918a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,14 +77,34 @@ current behaviour; this file is where history lives. `docs/cli/config.md`, `docs/install/upgrading.md` and the manual page say so. -3. **What a home on an NFS `root_squash` export does to the commands that - write as root is documented and tested.** The behaviour is unchanged: a - home that others may not search is refused by the path check +3. **What a home on an NFS `root_squash` export does to the two commands + that write as root is documented and tested.** `config render --dry-run` + and `config linux script|remove-script` check the path as root, so a home + that others may not search is refused by the check (`cannot be resolved (Permission denied)`), and in one that others may - search `config render --dry-run` and `config linux script|remove-script` - write nothing and say `Permission denied`, with the path. Tests pin both, - and `docs/cli/conventions.md` and the manual page say to write the file on - the local disk of the host and copy it to the home as yourself. + search they write nothing and say `Permission denied`, with the path. + Tests pin both, and `docs/cli/conventions.md` and the manual page say to + write the file on the local disk of the host and copy it to the home as + yourself. + +4. **The three commands that write as you work in a root-squashed home that + others cannot search, and a path that cannot be resolved is not told to + be spelled differently.** `device config plan --out|--out-dir`, + `device reports export --out` and `device support-bundle` write as the + person who ran `sudo`, but their check of the path (inside the home, links + resolved) ran as root: on an NFS home with `root_squash` that others may + not search (0700, 0750) root could not look at the path and the check + refused it, `cannot be resolved (Permission denied)`, although the write, + as you, would work. The check now runs as you for these three, and the + other rules are unchanged. `config render --dry-run` and + `config linux script|remove-script` write as root and still check as root + (item 3). A refusal that says `cannot be resolved ()` (permission + denied, a link that leads nowhere) now gives the cause and the path and no + longer ends with `tacctl does not expand ~ or variables; name a path inside + your home, relative to the current directory`, which is about the + spelling of the path and stays on the other refusals (an empty path, a + NUL, a `$` or backtick, a `~`, a path outside the home). + `docs/cli/conventions.md` and the manual page (`device config plan`) say so. ## 0.2.29 (2026-11-09) diff --git a/docs/cli/conventions.md b/docs/cli/conventions.md index 22124501..033ede57 100644 --- a/docs/cli/conventions.md +++ b/docs/cli/conventions.md @@ -19,7 +19,7 @@ These patterns apply across every subcommand family: - **Service restart** — changes to the store, and to the `tacctl.yaml` settings a backend renders (command rules, listeners, `backends.*`), re-render every enabled backend and restart the ones whose files changed. Settings only device configs read (mgmt-acl permits + names, priv-exec mappings, per-scope AAA order, exec timeout, group labels) and tacctl's own tunables (bcrypt cost, password age, …) restart nothing. - **Notices** — INFO says what was done: the change, the service restart, a sync. WARN says that something failed or that the operator has to act: a sync that failed (with the command to retry it), hosts left to sync (with the command), a device that still accepts a user who must change the password. A fact is said once, at one level. A `user` verb that changes an account syncs this server's own accounts at once and names the other enrolled hosts it reaches in one warning; on a terminal it asks `Sync these hosts now? [y/N]` (the default is no and `--yes` does not answer it); see [User Commands](user.md). - **Flags** — long-form flags (`--hash`, `--scopes`, `--scope`, `--prefixes`, `--secret`, `--protocols`, `--vendor-attrs`, `--match`, `--action`, `--branch`, `--protocol`, `--method`, `--backend`, `--listener`, `--out`) take a single argument; `--default`, `--force`, `--legacy`, `--check`, `--replace`, `--json`, `--local`, `--all`, `--dry-run`, `--long`, `--apply`, `--hosts` and `--yes` take none. Required positional args come before flags. -- **Paths you name to write** — a flag that names a file or directory tacctl writes (`--out` and `--out-dir` of `device config plan`, `--out` of `device reports export` and of `config render --dry-run`, `--output` (`-o`) of `config linux script` and `remove-script`) is checked first: the path must be inside your home, the home of the person who ran `sudo` (else of the user running tacctl) as the account database gives it, never `$HOME`. Your shell expands `~` and variables before tacctl sees them; tacctl itself expands neither, so a path that still starts with `~` or holds a `$` or a backtick, an empty path, a path that leaves the home through `..` or through a symbolic link, and the home itself are refused with the one-sentence rule (`tacctl does not expand ~ or variables; name a path inside your home, relative to the current directory`) and nothing is written. A relative path is taken from the current directory. `device support-bundle --out` takes a name, not a path, and writes under `support-bundles` in your home ([Support bundles](../devices/support-bundle.md)). Files tacctl writes as you (`device config plan`, `device reports export`, `device support-bundle`) keep the protections they had: new files only, a link never followed, `--force` where it exists to replace. Two commands write as root: `config render --dry-run` makes its directory and files root-owned (0700, 0600), through a handle on the directory so that a link planted in it is not followed out, and into a directory that is new or empty only; `config linux script` and `remove-script` make the file as root (0600, 0644), hand it to the person who ran `sudo`, replace a file of that name without `--force`, and refuse a directory (or a link to one) as the name. A home directory of `/` is refused for all of these. On an NFS export with `root_squash` root is mapped to an unprivileged account. A home that others may not search (0700, 0750) is refused by the path check itself, for every command that names a path, with ` '' cannot be resolved (Permission denied): ...`. In a home that others may search the check passes, and the two commands that write as root cannot write there: they write nothing, leave no half-made file (a file of that name that was there stays as it was), say so in one line that names the path and the cause (`Cannot write : Permission denied`, `Cannot create '': Permission denied` or `install: cannot create regular file '': Permission denied`) and exit with status 1. Write the file somewhere that is not root-squashed (the local disk of the host) and copy it to your home as yourself. +- **Paths you name to write** — a flag that names a file or directory tacctl writes (`--out` and `--out-dir` of `device config plan`, `--out` of `device reports export` and of `config render --dry-run`, `--output` (`-o`) of `config linux script` and `remove-script`) is checked first: the path must be inside your home, the home of the person who ran `sudo` (else of the user running tacctl) as the account database gives it, never `$HOME`. Your shell expands `~` and variables before tacctl sees them; tacctl itself expands neither, so a path that still starts with `~` or holds a `$` or a backtick, an empty path, a path that leaves the home through `..` or through a symbolic link, and the home itself are refused with the one-sentence rule (`tacctl does not expand ~ or variables; name a path inside your home, relative to the current directory`) and nothing is written. A relative path is taken from the current directory. `device support-bundle --out` takes a name, not a path, and writes under `support-bundles` in your home ([Support bundles](../devices/support-bundle.md)). Files tacctl writes as you (`device config plan`, `device reports export`, `device support-bundle`) keep the protections they had: new files only, a link never followed, `--force` where it exists to replace. Two commands write as root: `config render --dry-run` makes its directory and files root-owned (0700, 0600), through a handle on the directory so that a link planted in it is not followed out, and into a directory that is new or empty only; `config linux script` and `remove-script` make the file as root (0600, 0644), hand it to the person who ran `sudo`, replace a file of that name without `--force`, and refuse a directory (or a link to one) as the name. A home directory of `/` is refused for all of these. On an NFS export with `root_squash` root is mapped to an unprivileged account. The three commands that write as you (`device config plan`, `device reports export`, `device support-bundle`) check the path as you too, so a home that others may not search (0700, 0750) is no obstacle to them. The two commands that write as root check the path as root, so a home that others may not search is refused by the check itself, with ` '' cannot be resolved (Permission denied)` (the cause the system gives, with the path; the refusal about `~` and variables is not repeated for it). In a home that others may search the check passes, and the two commands that write as root cannot write there: they write nothing, leave no half-made file (a file of that name that was there stays as it was), say so in one line that names the path and the cause (`Cannot write : Permission denied`, `Cannot create '': Permission denied` or `install: cannot create regular file '': Permission denied`) and exit with status 1. Write the file somewhere that is not root-squashed (the local disk of the host) and copy it to your home as yourself. ## Top-Level Commands diff --git a/man/tacctl.1 b/man/tacctl.1 index 6a82f156..b53459e8 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -13456,7 +13456,7 @@ are 0600 and written as the user who ran sudo; .B \-\-out\-dir makes its directory with mode 0700 (an existing directory open to others is refused, and so is one that only a supplementary -group of that user may write). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. +group of that user may write). The path may be relative to the current directory or absolute, but it must be inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; taken from the account database, never from \fB$HOME\fR): tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or a symbolic link. The path is checked as that user, so a home exported by NFS with \fBroot_squash\fR that others may not search is no obstacle. An existing file is refused, all of them before any is written, unless .BR \-\-force . From 5353e9d86574289c2810ccc431fe2935f109b8fe Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:48:47 -0900 Subject: [PATCH 21/27] sftpd: an open's attribute block is read with its flags, so permissions with times count The library drops the attribute flags of an open request, so the handlers could not tell a twelve byte block of the permissions with the times (what the scp of OpenSSH 9 sends with -p) from a size with the permissions, and read only a block of four bytes. The session now reads the client's packets through a filter that frames the stream, passes every packet but an open through as it came, and rewrites the attribute block of an open to the permissions alone (or to nothing) using the flags it finds there. openMode is unchanged and reads the result: a file made by scp -p is created with the permission bits of the request (less the umask of the console) and not 0644, and a size is never read as a mode. An open that is too short or too long to be rewritten is passed on, and gets the default mode. The umask, the owner-write restore and the 4-byte cases are as before. Nothing under vendor/ changes. The tests that pinned the 12 byte block as asking for nothing now pin the permissions. --- internal/sftpd/file.go | 20 ++- internal/sftpd/openattrs.go | 158 +++++++++++++++++++++++ internal/sftpd/openattrs_test.go | 211 +++++++++++++++++++++++++++++++ internal/sftpd/openmode_test.go | 18 +-- internal/sftpd/sftpd.go | 14 +- 5 files changed, 401 insertions(+), 20 deletions(-) create mode 100644 internal/sftpd/openattrs.go create mode 100644 internal/sftpd/openattrs_test.go diff --git a/internal/sftpd/file.go b/internal/sftpd/file.go index aadec841..11f89c16 100644 --- a/internal/sftpd/file.go +++ b/internal/sftpd/file.go @@ -96,17 +96,15 @@ 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 is read as the -// 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 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. +// would read the wrong thing), so the session rewrites the request before the +// library reads it (openFilter): the block r.Attrs holds here is the +// permissions alone, four bytes, or nothing, whatever the client sent (the +// OpenSSH sftp sends the permissions alone, and scp -p the permissions with the +// times). A value without any permission bit (zero, or only file type bits, +// which permBits drops) is read as asking for nothing (a client that really +// asks for 0000 gets the default, and can set the mode afterwards). Any other +// length asks for nothing too, so that a request the filter did not see (it +// passes on one that is too long or not well formed) gets the default mode. func openMode(r *sftp.Request) (uint32, bool) { if len(r.Attrs) != 4 { return 0, false diff --git a/internal/sftpd/openattrs.go b/internal/sftpd/openattrs.go new file mode 100644 index 00000000..1839e33f --- /dev/null +++ b/internal/sftpd/openattrs.go @@ -0,0 +1,158 @@ +package sftpd + +import ( + "bufio" + "encoding/binary" + "io" +) + +// The library hands a handler the attribute block of an open request as raw +// bytes and drops the attribute flags that say which fields it holds, so a +// block of twelve bytes could be the permissions with the times (what the +// OpenSSH scp sends with -p) or a size with the permissions, and a block of +// four bytes could be the permissions or the count of the extended attributes +// of a version 3 block that holds nothing else. The open is therefore +// rewritten on its way in, before the library reads it: the attribute flags +// are read here, where they are known, and the block the library gets is the +// permissions alone (four bytes, the flag of the permissions) or nothing (no +// flags, no bytes). openMode reads that. +// +// Only the open request is touched, the bytes of every other packet go through +// as they came, and an open that is not well formed is passed on as it is, +// which openMode reads as asking for nothing: the new file gets the default +// mode, the safe side. So is an open too long to be read whole (maxOpenPacket: +// its path is longer than the file system takes, and the open fails). +const ( + sshFxpOpen = 3 // the type of an open request + + // maxOpenPacket is the longest open request that is read whole to be + // rewritten: a path (at most a few thousand bytes), the flags and a + // block of attributes are far below it. A longer one cannot be a real + // open and is passed through. + maxOpenPacket = 64 * 1024 + + openAttrSize = 0x1 // the size field (8 bytes) + openAttrUIDGID = 0x2 // the owner and group (8 bytes) + openAttrPerm = 0x4 // the permissions (4 bytes) +) + +// openFilter is the reader the library reads the client's packets from. It +// frames the stream (a packet is a four byte length, a type byte and the +// rest), keeps the bytes of every packet but an open as they came and +// rewrites the attribute block of an open. +type openFilter struct { + r *bufio.Reader + out []byte // bytes ready to be read: a header, or a rewritten packet + passing int // bytes of the current packet still to be passed through + err error // the error that ends the stream, given once out is read +} + +func newOpenFilter(r io.Reader) *openFilter { + return &openFilter{r: bufio.NewReaderSize(r, 4096)} +} + +func (f *openFilter) Read(p []byte) (int, error) { + if len(p) == 0 { + return 0, nil + } + for len(f.out) == 0 { + if f.err != nil { + return 0, f.err + } + if f.passing > 0 { + n, err := f.r.Read(p[:min(len(p), f.passing)]) + f.passing -= n + if err != nil { + f.err = err + } + if n > 0 { + return n, nil + } + continue + } + f.next() + } + n := copy(p, f.out) + f.out = f.out[n:] + return n, nil +} + +// next reads the header of the next packet and, for an open request, the +// whole packet; it sets out and passing. A failure of the stream is kept in +// err, to be given after the bytes read so far. +func (f *openFilter) next() { + var hdr [5]byte + n, err := io.ReadFull(f.r, hdr[:4]) + if err != nil { + f.out, f.err = hdr[:n], err + return + } + length := binary.BigEndian.Uint32(hdr[:4]) + if length == 0 { + f.out = hdr[:4] // the library refuses it + return + } + n, err = io.ReadFull(f.r, hdr[4:5]) + if err != nil { + f.out, f.err = hdr[:4+n], err + return + } + if hdr[4] != sshFxpOpen || length > maxOpenPacket { + f.out, f.passing = hdr[:], int(length)-1 + return + } + body := make([]byte, length-1) + n, err = io.ReadFull(f.r, body) + if err != nil { + // A stream that ends inside the open: what came goes on as it is. + f.out, f.err = append(hdr[:], body[:n]...), err + return + } + f.out = rewriteOpen(hdr[4], body) +} + +// rewriteOpen returns the open request of type typ and body (the bytes after +// the type), whole with its length, with its attribute block cut down to the +// permissions, or to nothing when the request carries none. A request that is +// too short to hold the open flags and the attribute flags is returned as it +// is. +func rewriteOpen(typ byte, body []byte) []byte { + // The id, the path (a length and its bytes), the open flags, then the + // attribute flags. + if len(body) < 8 { + return frame(typ, body) + } + pathLen := uint64(binary.BigEndian.Uint32(body[4:])) + end := 8 + pathLen + 4 // the end of the open flags + if uint64(len(body)) < end+4 { + return frame(typ, body) + } + aflags := binary.BigEndian.Uint32(body[end:]) + attrs := body[end+4:] + + // The fields come in the order of the flags: size, owner and group, + // permissions, times, extended attributes. Only what precedes the + // permissions has to be skipped. + skip := 0 + if aflags&openAttrSize != 0 { + skip += 8 + } + if aflags&openAttrUIDGID != 0 { + skip += 8 + } + out := append([]byte(nil), body[:end]...) + if aflags&openAttrPerm != 0 && len(attrs) >= skip+4 { + out = binary.BigEndian.AppendUint32(out, openAttrPerm) + out = append(out, attrs[skip:skip+4]...) + } else { + out = binary.BigEndian.AppendUint32(out, 0) + } + return frame(typ, out) +} + +// frame is a packet of the type typ and the content body, with its length. +func frame(typ byte, body []byte) []byte { + b := binary.BigEndian.AppendUint32(make([]byte, 0, 5+len(body)), uint32(1+len(body))) + b = append(b, typ) + return append(b, body...) +} diff --git a/internal/sftpd/openattrs_test.go b/internal/sftpd/openattrs_test.go new file mode 100644 index 00000000..37aab821 --- /dev/null +++ b/internal/sftpd/openattrs_test.go @@ -0,0 +1,211 @@ +package sftpd + +import ( + "bytes" + "encoding/binary" + "errors" + "io" + "os" + "path/filepath" + "testing" + "testing/iotest" +) + +// openPacket is an open request, whole with its length, as a client sends it. +func openPacket(id uint32, path string, pflags, aflags uint32, attrs []byte) []byte { + b := binary.BigEndian.AppendUint32(nil, id) + b = str(b, path) + b = binary.BigEndian.AppendUint32(b, pflags) + b = binary.BigEndian.AppendUint32(b, aflags) + b = append(b, attrs...) + return frame(rawOpen, b) +} + +// writePacket is a write request of n bytes of data. +func writePacket(id uint32, n int) []byte { + b := binary.BigEndian.AppendUint32(nil, id) + b = str(b, "h") + b = binary.BigEndian.AppendUint64(b, 0) + b = str(b, string(bytes.Repeat([]byte{'x'}, n))) + return frame(rawWrite, b) +} + +func u32(v ...uint32) []byte { + var b []byte + for _, x := range v { + b = binary.BigEndian.AppendUint32(b, x) + } + return b +} + +// What the library is given for an open: the attribute flags the client sent +// are read where they are known, and the block is the permissions alone or +// nothing. +func TestRewriteOpen(t *testing.T) { + const mtime = 1_700_000_000 + times := u32(mtime, mtime) + size := binary.BigEndian.AppendUint64(nil, 0x1ED_00000000) // its high word reads as 0755 + owner := binary.BigEndian.AppendUint64(nil, 0x1ED_00000000) + cat := func(parts ...[]byte) []byte { return bytes.Join(parts, nil) } + tests := []struct { + name string + aflags uint32 + attrs []byte + want []byte // the block the library gets; nil with the flags 0 + }{ + {"no attributes", 0, nil, nil}, + {"permissions alone", rawAttrPerm, u32(0o755), u32(0o755)}, + {"permissions with times", rawAttrPerm | rawAttrTimes, cat(u32(0o755), times), u32(0o755)}, + {"size with permissions", openAttrSize | rawAttrPerm, cat(size, u32(0o600)), u32(0o600)}, + {"owner with permissions", openAttrUIDGID | rawAttrPerm, cat(owner, u32(0o640)), u32(0o640)}, + {"size, owner, permissions and times", openAttrSize | openAttrUIDGID | rawAttrPerm | rawAttrTimes, cat(size, owner, u32(0o750), times), u32(0o750)}, + {"permissions with no extended attributes", rawAttrPerm | rawAttrExtended, u32(0o755, 0), u32(0o755)}, + {"times alone", rawAttrTimes, times, nil}, + {"size alone", openAttrSize, size, nil}, + {"extended attributes alone", rawAttrExtended, u32(0), nil}, + {"permissions flag, block too short", rawAttrPerm, []byte{0, 0, 1}, nil}, + {"size and permissions flags, block holds the size only", openAttrSize | rawAttrPerm, size, nil}, + {"bytes without a flag", 0, u32(0o755), nil}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + in := openPacket(7, "f", rawFlagWrite|rawFlagCreat, tc.aflags, tc.attrs) + var wantFlags uint32 + if tc.want != nil { + wantFlags = rawAttrPerm + } + want := openPacket(7, "f", rawFlagWrite|rawFlagCreat, wantFlags, tc.want) + got := readAll(t, newOpenFilter(bytes.NewReader(in))) + if !bytes.Equal(got, want) { + t.Errorf("rewritten to %x, want %x", got, want) + } + }) + } +} + +func readAll(t *testing.T, r io.Reader) []byte { + t.Helper() + b, err := io.ReadAll(r) + if err != nil { + t.Fatal(err) + } + return b +} + +// A stream of packets comes out with the open rewritten and every other packet +// as it was, however the reader asks for it (a byte at a time, in the sizes of +// the library, in one go), and a zero length packet and a long open are passed +// on for the library to judge. +func TestOpenFilterStream(t *testing.T) { + times := u32(1, 2) + long := openPacket(9, string(bytes.Repeat([]byte{'p'}, maxOpenPacket)), rawFlagWrite, rawAttrPerm|rawAttrTimes, append(u32(0o755), times...)) + var in, want []byte + add := func(inp, wantp []byte) { in, want = append(in, inp...), append(want, wantp...) } + init := frame(rawInit, u32(3)) + add(init, init) + w1 := writePacket(2, 30000) + add(w1, w1) + add(openPacket(3, "a", rawFlagWrite|rawFlagCreat, rawAttrPerm|rawAttrTimes, append(u32(0o755), times...)), + openPacket(3, "a", rawFlagWrite|rawFlagCreat, rawAttrPerm, u32(0o755))) + add([]byte{0, 0, 0, 0}, []byte{0, 0, 0, 0}) + add(long, long) // too long to be an open: as it came + add(openPacket(4, "b", rawFlagRead, 0, nil), openPacket(4, "b", rawFlagRead, 0, nil)) + add(writePacket(5, 1), writePacket(5, 1)) + for name, wrap := range map[string]func(io.Reader) io.Reader{ + "whole": func(r io.Reader) io.Reader { return r }, + "one byte": iotest.OneByteReader, + "half": iotest.HalfReader, + "data err": iotest.DataErrReader, + } { + t.Run(name, func(t *testing.T) { + got := readAll(t, newOpenFilter(wrap(bytes.NewReader(in)))) + if !bytes.Equal(got, want) { + t.Errorf("the stream differs: %d bytes, want %d", len(got), len(want)) + } + }) + } +} + +// A stream that ends inside a packet gives the bytes that came, then the +// error, at every cut of an open and of a write. +func TestOpenFilterTruncated(t *testing.T) { + for _, pkt := range [][]byte{ + openPacket(3, "a", rawFlagWrite|rawFlagCreat, rawAttrPerm|rawAttrTimes, append(u32(0o755), u32(1, 2)...)), + writePacket(2, 20), + } { + for cut := 1; cut < len(pkt); cut++ { + got, err := io.ReadAll(newOpenFilter(bytes.NewReader(pkt[:cut]))) + // io.ReadAll hides a plain end of stream: the library meets + // the same end where it expects the rest of the packet. + if err != nil && !errors.Is(err, io.ErrUnexpectedEOF) { + t.Fatalf("cut at %d: error %v", cut, err) + } + if !bytes.Equal(got, pkt[:cut]) { + t.Fatalf("cut at %d: got %x, want the bytes that came, %x", cut, got, pkt[:cut]) + } + } + } + if got, err := io.ReadAll(newOpenFilter(bytes.NewReader(nil))); err != nil || len(got) != 0 { + t.Errorf("an empty stream: %x, %v", got, err) + } +} + +// The session: the file is created with the permission bits of the open +// whatever else the block holds (what the scp of OpenSSH 9 sends with -p is +// the permissions and the times), and a block that holds no permissions gives +// the default, so a size is never read as a mode. +func TestOpenModeBlocksOfTheOpenRequest(t *testing.T) { + const creat = rawFlagWrite | rawFlagCreat | rawFlagTrunc + times := u32(1_700_000_000, 1_700_000_000) + size := binary.BigEndian.AppendUint64(nil, 0x1ED_00000000) // its high word reads as 0755 + owner := binary.BigEndian.AppendUint64(nil, 0) + cat := func(parts ...[]byte) []byte { return bytes.Join(parts, nil) } + tests := []struct { + name string + aflags uint32 + attrs []byte + want os.FileMode // under umask 022 + }{ + {"permissions with times, twelve bytes", rawAttrPerm | rawAttrTimes, cat(u32(0o755), times), 0o755}, + {"size with permissions, twelve bytes, is not permissions with times", openAttrSize | rawAttrPerm, cat(size, u32(0o600)), 0o600}, + {"owner with permissions, twelve bytes", openAttrUIDGID | rawAttrPerm, cat(owner, u32(0o750)), 0o750}, + {"everything", openAttrSize | openAttrUIDGID | rawAttrPerm | rawAttrTimes, cat(size, owner, u32(0o700), times), 0o700}, + {"permissions with extended attributes", rawAttrPerm | rawAttrExtended, u32(0o755, 0), 0o755}, + {"size alone, eight bytes", openAttrSize, size, 0o644}, + {"times alone, eight bytes", rawAttrTimes, times, 0o644}, + {"bytes the flags do not announce", 0, cat(u32(0o755), times), 0o644}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + setUmask(t, 0o022) + home := newHome(t) + r := newRawConn(t, home) + h, code := r.open("f", creat, tc.aflags, tc.attrs) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + if got := modeOfFile(t, filepath.Join(home, "f")); got != tc.want { + t.Errorf("mode after the open %v, want %v", got, tc.want) + } + r.finish(h, "data") + }) + } +} + +// The requests that follow a rewritten open are read where they begin: a long +// upload after an open with times goes through, byte for byte. +func TestOpenModeWithTimesThenData(t *testing.T) { + setUmask(t, 0o077) + home := newHome(t) + r := newRawConn(t, home) + h, code := r.open("f", rawFlagWrite|rawFlagCreat|rawFlagTrunc, rawAttrPerm|rawAttrTimes, append(u32(0o755), u32(1, 2)...)) + if h == "" { + t.Fatalf("open refused: status %d", code) + } + data := string(bytes.Repeat([]byte("0123456789"), 3000)) + r.finish(h, data) + b, err := os.ReadFile(filepath.Join(home, "f")) + if err != nil || string(b) != data { + t.Errorf("content: %d bytes, %v, want %d", len(b), err, len(data)) + } +} diff --git a/internal/sftpd/openmode_test.go b/internal/sftpd/openmode_test.go index bf4f3aa3..c4502ba2 100644 --- a/internal/sftpd/openmode_test.go +++ b/internal/sftpd/openmode_test.go @@ -189,10 +189,10 @@ func sizeAttrs(size uint64) []byte { return binary.BigEndian.AppendUint64(nil, s 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. +// less the umask of the process (the console runs with 077). The library does +// not deliver the attribute flags of the request to the handlers, so the +// server rewrites the request before the library reads it (openattrs.go): the +// permissions are found whatever else the block holds. func TestOpenModeOfTheRequest(t *testing.T) { const ( creatTrunc = rawFlagWrite | rawFlagCreat | rawFlagTrunc @@ -228,7 +228,9 @@ func TestOpenModeOfTheRequest(t *testing.T) { {"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}, + {"permissions with times are read: 0755 under umask 022", 0o022, creatTrunc, rawAttrPerm | times, twelve, 0, 0o755}, + {"permissions with times are read: 0755 under the console umask", 0o077, creatTrunc, rawAttrPerm | times, twelve, 0, 0o700}, + {"times alone ask for nothing: 0644 under umask 022", 0o022, creatTrunc, times, make([]byte, 8), 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}, @@ -566,7 +568,7 @@ func TestMkdirIgnoresTheModeOfTheRequest(t *testing.T) { } // 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 +// bytes, read as the permissions, so the file is created 0755 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) { @@ -581,8 +583,8 @@ func TestOpenModeWithTimesThenSetstat(t *testing.T) { 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) + if got := modeOfFile(t, p); got != 0o700 { + t.Errorf("mode after the open %v, want -rwx------", got) } r.writeAt(h, "#!/bin/sh\n") if c := r.fsetstat(h, rawAttrPerm|rawAttrTimes, append(permAttrs(0o755), times...)); c != 0 { diff --git a/internal/sftpd/sftpd.go b/internal/sftpd/sftpd.go index 7c017fb8..f9006f48 100644 --- a/internal/sftpd/sftpd.go +++ b/internal/sftpd/sftpd.go @@ -102,7 +102,10 @@ func serve(rw io.ReadWriteCloser, cfg Config, sm seams) error { } defer h.close() s := newServer(h, cfg, sm) - rs := sftp.NewRequestServer(rw, sftp.Handlers{FileGet: s, FilePut: s, FileCmd: s, FileList: s}) + // The library reads the client's packets through the filter that gives + // an open request the attributes it was sent in a form the handlers can + // read (openattrs.go); it writes and closes through rw. + rs := sftp.NewRequestServer(filtered{rw, newOpenFilter(rw)}, sftp.Handlers{FileGet: s, FilePut: s, FileCmd: s, FileList: s}) err = rs.Serve() if errors.Is(err, io.EOF) { return nil @@ -110,6 +113,15 @@ func serve(rw io.ReadWriteCloser, cfg Config, sm seams) error { return err } +// filtered is the connection the library gets: reads come from the filter, +// writes and the close go to the connection. +type filtered struct { + io.ReadWriteCloser + r io.Reader +} + +func (f filtered) Read(p []byte) (int, error) { return f.r.Read(p) } + // 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 { From a7f4d66273e547043544dcff261b17d3491bbe77 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 08:53:24 -0900 Subject: [PATCH 22/27] docs: a file made by scp -p is created with the mode of its source The console page and the manual page said the open request of scp -p was read as carrying no permissions, so the file was created 0644 (0600 after the umask) and got its mode only from the fsetstat. The open request is now read with its attribute flags, so both pages say the mode is given at creation whatever else the request carries, and the CHANGELOG has the item. --- CHANGELOG.md | 18 ++++++++++++++++++ docs/cli/console.md | 2 +- man/tacctl.1 | 19 +++++++++---------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40ae94b7..0b8682e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,24 @@ current behaviour; this file is where history lives. and `docs/cli/conventions.md` and the manual page say to write the file on the local disk of the host and copy it to the home as yourself. +5. **A file uploaded with `scp -p` is created with its mode.** The `scp` of + OpenSSH 9 or later sends the permissions together with the times in the + request that opens the file (twelve bytes of attributes), and the console + read only a block of four bytes, because the library that speaks SFTP does + not say which attributes a request holds: the file was created 0644 (0600 + after the umask, 077) and got its mode only from the permissions that + follow the data. The console now reads the attribute flags of the open + request itself, before the library sees it, so the permissions are found + whatever else the request carries (the times, a size, an owner), and a + size is never read as a mode. A new file is created with the permission + bits asked for, reduced by the umask as before: a script asked at 0755 is + 0700 from the start, and an upload of `scp -p` that is interrupted leaves + that mode and not 0600. A request without permissions, or that asks for no + permission bit, still gives 0644 (0600), a file that exists keeps its + mode, and the mode and the times the client sets at the end are applied as + given, as before. The page of the console (`docs/cli/console.md`, file + transfer) and the manual page say so. + ## 0.2.29 (2026-11-09) 1. **A file uploaded through the console keeps the owner's execute bit.** The diff --git a/docs/cli/console.md b/docs/cli/console.md index 3b937522..ed24dcce 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -221,7 +221,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 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 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, whatever other attributes the request carries (the `sftp` of OpenSSH sends the permissions alone and `scp -p` the permissions with the times), and 0644 otherwise: a request without permissions gets it, and so does one that asks for no permission bits (the mode 0, with or without file type bits), which is read as asking for nothing; 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 gives the file its mode at creation (a script asked at 0755 is created 0700), 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/man/tacctl.1 b/man/tacctl.1 index 6a82f156..fc95ac7d 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -16649,15 +16649,14 @@ 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 +the mode the client asks for in the request that opens it, whatever other +attributes the request carries (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, 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); +sends the permissions alone and +.B scp \-p +the permissions with the times), and 0644 otherwise: a request without +permissions gets it, and so does one that asks for no permission bits (the mode +0, with or without file type bits), which is read as asking for nothing; 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 @@ -16689,8 +16688,8 @@ 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 +which gives the file its mode at creation (a script asked at 0755 is created +0700), 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 From 1b1d550000256aa7981c350e7d31e0c133c18295 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 09:12:12 -0900 Subject: [PATCH 23/27] sftpd: the open filter decides on a packet's length before it reads the type byte The filter read the type byte of every packet before it handed the four length bytes to the library, even when the length was zero or above the limit of the library (256 KiB). A client that sent only the length of a 300 KiB packet and then stayed silent used to end the session at once with "packet too long"; with the filter the session waited for one more byte or for the client to close. The length now decides first: a length of zero or above maxOpenPacket goes through as the four bytes alone and the rest of the packet is passed on as it comes, so the library answers from the length as it did before the filter. Only a length in range reads the type byte, and the type byte test no longer carries the length. The count of bytes to pass is capped at MaxInt32 so that it cannot go negative where an int has 32 bits. The test is the experiment of the review: a raw connection sends the four bytes of the length of a 300 KiB packet and nothing else, and the session must end with the library's error. It fails (the session does not end) on the previous code. The comment of maxOpenPacket said that an open over 64 KiB cannot be a real open because its path is too long. That is not so: the library cleans the path, so one padded with "./" opens the same file, and a block of extended attributes can be long too. Such an open is passed through as it came and openMode gives the new file the default mode, the safe side. The comments now say that. --- internal/sftpd/openattrs.go | 24 ++++++++++++++++-------- internal/sftpd/openattrs_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/internal/sftpd/openattrs.go b/internal/sftpd/openattrs.go index 1839e33f..bfd5e5e9 100644 --- a/internal/sftpd/openattrs.go +++ b/internal/sftpd/openattrs.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/binary" "io" + "math" ) // The library hands a handler the attribute block of an open request as raw @@ -20,15 +21,16 @@ import ( // Only the open request is touched, the bytes of every other packet go through // as they came, and an open that is not well formed is passed on as it is, // which openMode reads as asking for nothing: the new file gets the default -// mode, the safe side. So is an open too long to be read whole (maxOpenPacket: -// its path is longer than the file system takes, and the open fails). +// mode, the safe side. So is an open too long to be read whole (maxOpenPacket). const ( sshFxpOpen = 3 // the type of an open request // maxOpenPacket is the longest open request that is read whole to be - // rewritten: a path (at most a few thousand bytes), the flags and a - // block of attributes are far below it. A longer one cannot be a real - // open and is passed through. + // rewritten, a bound on what one packet may make the filter hold. The + // opens real clients send are far below it; a longer one (a path padded + // with "./", which the library cleans, or a block of extended + // attributes) is passed through as it came, and openMode gives the new + // file the default mode. maxOpenPacket = 64 * 1024 openAttrSize = 0x1 // the size field (8 bytes) @@ -88,8 +90,14 @@ func (f *openFilter) next() { return } length := binary.BigEndian.Uint32(hdr[:4]) - if length == 0 { - f.out = hdr[:4] // the library refuses it + if length == 0 || length > maxOpenPacket { + // The length alone decides: the library refuses a length of zero + // and one above its own limit as soon as it has the four bytes (a + // client that sends them and stops is answered at once), and a + // packet longer than maxOpenPacket is not read whole here. So the + // type byte is not waited for. The cap keeps int(length) from + // going negative where an int has 32 bits. + f.out, f.passing = hdr[:4], int(min(length, math.MaxInt32)) return } n, err = io.ReadFull(f.r, hdr[4:5]) @@ -97,7 +105,7 @@ func (f *openFilter) next() { f.out, f.err = hdr[:4+n], err return } - if hdr[4] != sshFxpOpen || length > maxOpenPacket { + if hdr[4] != sshFxpOpen { f.out, f.passing = hdr[:], int(length)-1 return } diff --git a/internal/sftpd/openattrs_test.go b/internal/sftpd/openattrs_test.go index 37aab821..01a22e89 100644 --- a/internal/sftpd/openattrs_test.go +++ b/internal/sftpd/openattrs_test.go @@ -7,8 +7,10 @@ import ( "io" "os" "path/filepath" + "strings" "testing" "testing/iotest" + "time" ) // openPacket is an open request, whole with its length, as a client sends it. @@ -126,6 +128,30 @@ func TestOpenFilterStream(t *testing.T) { } } +// The length of a packet above the limit of the library ends the session at +// once, from the four bytes alone: the filter does not wait for the type byte +// of a packet it does not read whole. A client that sends the length of a +// 300 KiB packet and then stays silent gets the library's error without +// sending or closing anything more. +func TestOpenFilterLongLengthEndsTheSession(t *testing.T) { + r := newRawConn(t, newHome(t)) + if _, err := r.c.Write(binary.BigEndian.AppendUint32(nil, 300*1024)); err != nil { + t.Fatal(err) + } + select { + case err := <-r.done: + r.done <- err // for the cleanup of the connection + if err == nil || !strings.Contains(err.Error(), "packet too long") { + t.Errorf("the session ended with %v, want the error for a packet too long", err) + } + // The timer is real: the session is a goroutine on a pipe and the + // failure this guards against is a read that waits for the client, which + // no fake clock shows. It runs out only when the session does not end. + case <-time.After(10 * time.Second): + t.Fatal("the session did not end after the length of a packet over the limit") + } +} + // A stream that ends inside a packet gives the bytes that came, then the // error, at every cut of an open and of a write. func TestOpenFilterTruncated(t *testing.T) { From 3e6ba6cdac3283d1ea2c63852bf62344c1028eb9 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 09:15:04 -0900 Subject: [PATCH 24/27] docs: an open over 64 KiB is not read for its permissions; the path check as the caller in the man page for all three commands The page of the console and the manual page said a new file gets the mode the client asks for in the open request, whatever other attributes it carries. That is exact only up to the length the filter reads whole: an open longer than 64 KiB is passed through as it came and gets the default mode, 0644 before the umask. Both texts now say so, and that such an open is not one real clients send (a path padded with "./", which the library cleans to the same file, or a long block of extended attributes). CHANGELOG item 4 and docs/cli/conventions.md say that the three commands that write as the caller (device config plan, device reports export, device support-bundle) check the path as the caller, so a home exported by NFS with root_squash that others may not search is no obstacle. The manual page said it only at device config plan; the same sentence is now at the entries of device reports export --out and device support-bundle --out. It is hand-written text outside the generated blocks, and make man changes nothing. --- docs/cli/console.md | 2 +- man/tacctl.1 | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/cli/console.md b/docs/cli/console.md index ed24dcce..9473d893 100644 --- a/docs/cli/console.md +++ b/docs/cli/console.md @@ -221,7 +221,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, whatever other attributes the request carries (the `sftp` of OpenSSH sends the permissions alone and `scp -p` the permissions with the times), and 0644 otherwise: a request without permissions gets it, and so does one that asks for no permission bits (the mode 0, with or without file type bits), which is read as asking for nothing; 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 gives the file its mode at creation (a script asked at 0755 is created 0700), 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, whatever other attributes the request carries (the `sftp` of OpenSSH sends the permissions alone and `scp -p` the permissions with the times), and 0644 otherwise: a request without permissions gets it, and so does one that asks for no permission bits (the mode 0, with or without file type bits), which is read as asking for nothing, and so does an open longer than 64 KiB, which is not read for its permissions (the opens real clients send are far shorter; one that long has a path padded with `./`, which is cleaned to the same file, or a long block of extended attributes); 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 gives the file its mode at creation (a script asked at 0755 is created 0700), 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/man/tacctl.1 b/man/tacctl.1 index 1d49c018..54b967cd 100644 --- a/man/tacctl.1 +++ b/man/tacctl.1 @@ -10755,6 +10755,9 @@ or variables, and writes only inside your home (the home of the account of the p .BR sudo , else of the user running tacctl, never .BR $HOME ). +The path is checked as that user, so a home exported by NFS with +.B root_squash +that others may not search is no obstacle. The success lines print the full paths. Logged: .B "auth.info device support-bundle user= device= vendor= login=own|local: files= result=ok" (never a command's text). Exit status: 0, 1 refused or the login failed, 2 wrong arguments, 130 interrupted. @@ -14647,7 +14650,9 @@ Print a report as it is stored, or with write it to a file, made as the caller with mode 0600 inside the home of the person who ran \fBsudo\fR (else of the user running tacctl; never \fB$HOME\fR: tacctl does not expand \fB~\fR or variables, and refuses a path that leaves the home through \fB..\fR or -a symbolic link); a file that exists is refused unless +a symbolic link). The path is checked as that user, so a home exported by NFS +with \fBroot_squash\fR that others may not search is no obstacle. A file that +exists is refused unless .B \-\-force is given. tacctl sends a report nowhere itself: the .B scp @@ -16656,7 +16661,11 @@ sends the permissions alone and .B scp \-p the permissions with the times), and 0644 otherwise: a request without permissions gets it, and so does one that asks for no permission bits (the mode -0, with or without file type bits), which is read as asking for nothing; +0, with or without file type bits), which is read as asking for nothing, and +so does an open longer than 64 KiB, which is not read for its permissions (the +opens real clients send are far shorter; one that long has a path padded with +"\&./", which is cleaned to the same file, or a long block of extended +attributes); 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 baf820b0e41c91d2661b3a2392ef0d4de5ff237b Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 10:31:10 -0900 Subject: [PATCH 25/27] docs: the release notes of 0.2.30 The notes tell what the numbered list of the CHANGELOG (0.2.30) holds, checked against the code and the pages: a new user name starts with a lower-case letter (item 2), what a root_squash home does to the commands that write as root and to the three that write as the caller, with the path check run as the caller and no hint for a path that cannot be resolved (items 3 and 4), a file uploaded with scp -p created with the mode of its source less the umask (item 5), and the rollback target 0.2.29, which converts nothing (item 1; sixteen targets). They have the form of the notes of 0.2.29 and are what the release preflight (tests/tools/release-notes-check.sh 0.2.30) asks for. --- docs/release-notes-0.2.30.md | 130 +++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 docs/release-notes-0.2.30.md diff --git a/docs/release-notes-0.2.30.md b/docs/release-notes-0.2.30.md new file mode 100644 index 00000000..24d9e236 --- /dev/null +++ b/docs/release-notes-0.2.30.md @@ -0,0 +1,130 @@ +# tacctl 0.2.30 + +0.2.30 is a small release. A new user name now starts with a lower-case letter, so that every +new user has a Linux account; the commands that write a file as you check its path as you, which +makes them work in a home on an NFS `root_squash` export; and a file uploaded with `scp -p` is +created with the mode of its source. `tacctl rollback 0.2.29` is a target. The numbered list in +`CHANGELOG.md` (0.2.30) is everything that differs from 0.2.29. + +## User names start with a letter + +Every new user gets a Linux account, on the tacctl server and on the enrolled hosts, and a name +that starts with a digit or `-` is no account name. `user add` and the new name of `user rename` +now refuse a first character that is not a lower-case letter, a to z, change nothing and exit +1: + +```text +Username '1alice' must start with a letter (a to z): every new user gets a Linux account, and a name that starts with a digit or '-' is no account name (a new name does not start with '_' either). +``` + +A new name is now a lower-case letter, then lower-case letters, digits, `_` and `-`, at most 32 +characters. A leading `_` is refused too, although Linux would take it, so that every new name +is an account name everywhere. + +- **The first check that fails is the answer.** The checks run in a fixed order: the shape (no + period), the reserved names, upper case, the length, the first character. A name with upper + case is told its lower-case spelling (`Names are lower case: use 'alice'.`) only when that + spelling passes every other check, so the suggestion is always a name the command takes. For + a name such as `1Alice` or `_Alice` the answer is the check its lower-case spelling fails, + said with the name as typed and with the lower case among what to fix (`Username '1Alice' + must be lower case and start with a letter (a to z): ...`). +- **Existing users are unaffected.** Only a new name is checked. A user that exists as `9dave`, + `_svc` or `-x` keeps working: it is shown, changed, renamed away, removed and restored as + before, and `tacctl upgrade` and `backup restore` carry it unchanged. A user stored as `-x` + is reached by the verbs as a bare word (`tacctl user show -x`). +- **`config validate` warns once per user whose name has no Linux account.** Under `Names:` it + warns of a user whose name starts with a digit or `-` and names `tacctl user rename + `. A name that starts with `_` has an account and gets no warning, unless it is + also longer than 32 characters. A user gets one warning, whatever else is wrong with the name. +- **`--fix-names` never offers a refused rename.** `config validate --fix-names` offers the + rename to the lower-case spelling of a name with upper case only when that spelling would + pass every rule of a new name. For `1Alice` or a name over 32 characters it offers nothing, + the warning names the rename to a name of your choice, and the run counts nothing as not + offered or failed for it and exits 0. + +```bash +tacctl user add alice ops-rw +tacctl user rename 9dave dave +tacctl config validate +``` + +The pages are `docs/cli/user.md` (`user add`, `user rename`, A new name starts with a letter), +`docs/cli/config.md`, `docs/install/upgrading.md` and the manual page. + +## Writing a file from a home on an NFS `root_squash` export + +On an NFS export with `root_squash`, root is mapped to an unprivileged account, and a home that +others may not search (0700, 0750) is out of its reach. This release documents what that does to +the commands that write a file, and fixes it for three of them. + +- **The three commands that write as you check the path as you.** `device config plan + --out|--out-dir`, `device reports export --out` and `device support-bundle` write as the + person who ran `sudo`, but their check of the path (inside the home, links resolved) ran as + root, so in such a home it refused the path with `cannot be resolved (Permission denied)` + although the write, as you, would work. The check now runs as you, and the other rules are + unchanged. +- **A path that cannot be resolved is not told to be spelled differently.** A refusal that says + `cannot be resolved ()` (permission denied, a link that leads nowhere) now gives the + cause and the path and no longer ends with `tacctl does not expand ~ or variables; name a + path inside your home, relative to the current directory`. That sentence is about the + spelling of the path and stays on the other refusals: an empty path, a NUL, a `$` or + backtick, a `~`, a path outside the home. +- **The two commands that write as root are unchanged.** `config render --dry-run` and `config + linux script|remove-script` still check the path as root. A home that others may not search + is refused by the check (`cannot be resolved (Permission denied)`); in one that others may + search they write nothing, leave no half-made file and say `Permission denied` with the path. + Write the file on the local disk of the host and copy it to the home as yourself. Tests pin + both cases. + +The pages are `docs/cli/conventions.md` (Paths you name to write) and the manual page. + +## File transfer: `scp -p` creates the file with its mode + +In 0.2.29 a script uploaded with `scp -p` was created 0644 (0600 after the console's umask, +077) and got its mode only from the permissions that follow the data. The `scp` of OpenSSH 9 or +later sends the permissions together with the times in the request that opens the file (twelve +bytes of attributes), and the console read only four bytes of them. The console now reads the +attribute flags of the open request itself, so the permissions are found whatever else the +request carries (the times, a size, an owner), and a size is never read as a mode. + +- **The mode at creation.** A new file is created with the permission bits asked for, reduced + by the umask as before: a script asked at 0755 is 0700 from the start, and an upload of + `scp -p` that is interrupted leaves that mode and not 0600. +- **Unchanged.** A request without permissions, or that asks for no permission bit, still gives + 0644 (0600). A file that exists keeps its mode, and the mode and the times the client sets at + the end are applied as given, with no umask, so `scp -p` still ends with the mode of its + source. + +```bash +scp -p deploy.sh alice@tacacs.example.net: # created 0700, ends 0755 +``` + +The pages are `docs/cli/console.md` (file transfer) and the manual page. + +## Rollback + +**`tacctl rollback 0.2.29`, the release before this one, is a target.** This release changed no +stored file 0.2.29 reads strictly, 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, and so does every user, whatever the name. It is +refused only while a device's apply is not settled, and it ends with `tacctl upgrade --branch +0.2.29`, with no closing note. After that upgrade `user add` and `user rename` take a new name +that starts with a digit, `-` or `_` again, the three commands above check the path as root +again, and a file uploaded with `scp -p` is created 0644 (0600) again; what was done in between +keeps its name and its mode. `rollback 0.2.28` and older behave as before, and `tacctl +rollback` now takes sixteen targets. + +```bash +tacctl rollback 0.2.29 # the dry run: steps, writes nothing +tacctl rollback 0.2.29 --apply +tacctl upgrade --branch 0.2.29 +``` + +The pages are `docs/cli/conventions.md`, `docs/install/upgrading.md` (Rolling back, To 0.2.29) +and the manual page. + +## Upgrading + +`tacctl upgrade` converts nothing in this release. A user whose name starts with a digit or `-` +is carried unchanged; `tacctl config validate` lists it. From 54fd662678714ea5e5e5584ec12919287bcc68cd Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 10:31:10 -0900 Subject: [PATCH 26/27] docs: the rollback to 0.2.29 also undoes the path check and the scp -p mode The section "To 0.2.29" of the upgrade page said that the check of the name of a new user and the documentation were all that 0.2.30 changed outside the stored files. It also changed the user the check of the path of three commands runs as (item 4) and the mode scp -p creates a file with (item 5), and a rollback to 0.2.29 brings both back: say so, as the sections of the older targets say what the later releases changed. The count of the targets (sixteen) and the lists of "every target but" were checked against internal/lifecycle/rollback.go and the CLI's argument list and stand as they are. --- docs/install/upgrading.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/install/upgrading.md b/docs/install/upgrading.md index ab5b0c71..d04e864c 100644 --- a/docs/install/upgrading.md +++ b/docs/install/upgrading.md @@ -356,9 +356,9 @@ snapshot; this release, if it stays, reads the two as missing until its next ### To 0.2.29 -0.2.29 reads every file this release writes: this release changed no stored file it reads strictly (the check of the name of a new user, which writes no new form of a file, 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.29 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.29 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, and so does every user, whatever the name: a user whose name starts with a digit, `-` or `_`, or has upper case, is read, listed and kept as before. 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.29 pulls from. The command ends with the upgrade and has no closing note, because there is nothing to avoid. +0.2.29 reads every file this release writes: this release changed no stored file it reads strictly (the check of the name of a new user, the user the check of the path of three commands runs as, the mode `scp -p` creates a file with, none of which writes a new form of a file, 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.29 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.29 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, and so does every user, whatever the name: a user whose name starts with a digit, `-` or `_`, or has upper case, is read, listed and kept as before. 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.29 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.29's to undo or keep. After the `tacctl upgrade --branch 0.2.29` that ends the rollback, `user add` and `user rename` take a new name that starts with a digit, `-` or `_`, as they did. The users added in between keep their names. +What this release changed outside the stored files is 0.2.29's to undo or keep. After the `tacctl upgrade --branch 0.2.29` that ends the rollback, `user add` and `user rename` take a new name that starts with a digit, `-` or `_`, as they did. The users added in between keep their names. `device config plan --out|--out-dir`, `device reports export --out` and `device support-bundle` check the path as root again, so in a home on an NFS export with `root_squash` that others may not search they refuse it with `cannot be resolved (Permission denied)`, followed by the sentence about `~` and variables, as they did. A file uploaded with `scp -p` is created 0644 (0600 after the console's umask) and gets the mode of its source only from the permissions the client sends after the data, as it did; the files uploaded in between keep the mode they got. ```bash tacctl rollback 0.2.29 # the dry run: steps, writes nothing From 219777c13713a3128ad9ff05fb8f6a0e4e26a346 Mon Sep 17 00:00:00 2001 From: "Everett C. Haimes III" Date: Tue, 10 Nov 2026 12:56:20 -0900 Subject: [PATCH 27/27] Bumped version number to 0.2.30 --- CHANGELOG.md | 2 +- man/tacctl.1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fff4457..a65c6243 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.30 (unreleased) +## 0.2.30 (2026-11-10) 1. **`tacctl rollback 0.2.29`, the release before this one, is a target.** This release changed no stored file 0.2.29 reads strictly (the check of the diff --git a/man/tacctl.1 b/man/tacctl.1 index 54b967cd..f2fa7663 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.29" "tacctl Manual" +.TH TACCTL 1 "2026-11-10" "tacctl 0.2.30" "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