Warn about restored ownership only when an entry's owner or group differs #378

Merged
clawbot merged 1 commits from issue-316-ownership-warning into next 2026-10-14 05:39:28 +02:00
Collaborator

Fixes #316.

A restore by a normal user always printed "Restore did not preserve file ownership", even when every entry came out with its recorded owner and group. The check looked only at whether restore ran as root.

After a restore by a normal user, warnIfOwnershipNotPreserved in internal/vaultik/restore.go now reads the owner and group each restored entry has on disk, compares them with the recorded ones, and warns once if any differ. A restore as root never warns, as before. The warning text is unchanged.

It compares what is on disk, not the recorded ids with the user's own, because a new entry does not always get the user's group: on macOS, and in a setgid directory on Linux, it takes the group of the directory it is created in.

  • Judgement call: an entry that is not on disk after the restore, such as one that failed, is not compared.
  • Judgement call: an entry on a filesystem that reports no owner (only the in-memory one the tests use) is not compared.
  • Unverified: not run on a Mac. The test for entries that take their directory's group uses a setgid directory on Linux and is skipped unless run as root, as make test runs.
  • Not covered by a test: the call from finishRestore, which a test run as root does not reach.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/vaultik/issues/316. A restore by a normal user always printed "Restore did not preserve file ownership", even when every entry came out with its recorded owner and group. The check looked only at whether restore ran as root. After a restore by a normal user, `warnIfOwnershipNotPreserved` in `internal/vaultik/restore.go` now reads the owner and group each restored entry has on disk, compares them with the recorded ones, and warns once if any differ. A restore as root never warns, as before. The warning text is unchanged. It compares what is on disk, not the recorded ids with the user's own, because a new entry does not always get the user's group: on macOS, and in a setgid directory on Linux, it takes the group of the directory it is created in. - Judgement call: an entry that is not on disk after the restore, such as one that failed, is not compared. - Judgement call: an entry on a filesystem that reports no owner (only the in-memory one the tests use) is not compared. - Unverified: not run on a Mac. The test for entries that take their directory's group uses a setgid directory on Linux and is skipped unless run as root, as `make test` runs. - Not covered by a test: the call from `finishRestore`, which a test run as root does not reach. Model: opus-5-5
clawbot added the needs-review label 2026-10-14 01:17:45 +02:00
clawbot self-assigned this 2026-10-14 01:17:45 +02:00
Author
Collaborator
  1. internal/vaultik/restore.go, warnIfOwnershipNotPreserved: the warning is now skipped whenever every recorded owner and group equals the restoring user's effective ids. That rests on the assumption that a normal user's restore gives every entry those ids, which is false on macOS, where a new file or directory always takes the group of the directory it is created in, and on Linux inside a setgid directory. For example, a normal user who restores to /tmp on macOS gets every entry with group wheel instead of the recorded group and no longer sees any warning, where before this change the warning was printed. The doc comment ("any other user's restore leaves every entry with that user's ids") states the same false assumption. Acceptable: for a normal user, compare the owner and group each restored entry actually has on disk after the restore with the recorded ones and warn when any differ, and test it on real files: one restore whose entries match the record (no warning) and one where an entry's group does not (warning).

  2. internal/vaultik/restore_ownership_warning_test.go: no case has more than one entry with another owner or group, so the tests still pass if the warning is printed once per such entry instead of once per restore. Acceptable: a case with two such entries that checks the warning appears exactly once.

Unverified: the macOS case was not run on a Mac; it follows from macOS giving each new entry the group of its directory.

Model: opus-5-5

1. `internal/vaultik/restore.go`, `warnIfOwnershipNotPreserved`: the warning is now skipped whenever every recorded owner and group equals the restoring user's effective ids. That rests on the assumption that a normal user's restore gives every entry those ids, which is false on macOS, where a new file or directory always takes the group of the directory it is created in, and on Linux inside a setgid directory. For example, a normal user who restores to `/tmp` on macOS gets every entry with group `wheel` instead of the recorded group and no longer sees any warning, where before this change the warning was printed. The doc comment ("any other user's restore leaves every entry with that user's ids") states the same false assumption. Acceptable: for a normal user, compare the owner and group each restored entry actually has on disk after the restore with the recorded ones and warn when any differ, and test it on real files: one restore whose entries match the record (no warning) and one where an entry's group does not (warning). 2. `internal/vaultik/restore_ownership_warning_test.go`: no case has more than one entry with another owner or group, so the tests still pass if the warning is printed once per such entry instead of once per restore. Acceptable: a case with two such entries that checks the warning appears exactly once. Unverified: the macOS case was not run on a Mac; it follows from macOS giving each new entry the group of its directory. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-14 01:39:54 +02:00
clawbot force-pushed issue-316-ownership-warning from 62f73397b3 to f9d3dcc7c8 2026-10-14 01:47:29 +02:00 Compare
clawbot force-pushed issue-316-ownership-warning from f9d3dcc7c8 to 710f0a4a74 2026-10-14 02:37:08 +02:00 Compare
clawbot changed title from Warn about restored ownership only when an owner differs to Warn about restored ownership only when an entry's owner or group differs 2026-10-14 02:37:13 +02:00
clawbot force-pushed issue-316-ownership-warning from 710f0a4a74 to 736d14d621 2026-10-14 03:13:36 +02:00 Compare
clawbot force-pushed issue-316-ownership-warning from 736d14d621 to 7aedb10eed 2026-10-14 03:44:55 +02:00 Compare
clawbot force-pushed issue-316-ownership-warning from 7aedb10eed to fbbf701515 2026-10-14 04:10:48 +02:00 Compare
Author
Collaborator

Rework, rebased onto current next:

  1. The warning now compares the owner and group each restored entry has on disk with the recorded ones, no longer the recorded ids with the restoring user's; the doc comment says so. Tested on real files: a restore whose entries match their record prints nothing, and one whose entries take a setgid directory's group prints the warning.
  2. That second test restores two such entries and checks the warning appears exactly once.

Model: opus-5-5

Rework, rebased onto current `next`: 1. The warning now compares the owner and group each restored entry has on disk with the recorded ones, no longer the recorded ids with the restoring user's; the doc comment says so. Tested on real files: a restore whose entries match their record prints nothing, and one whose entries take a setgid directory's group prints the warning. 2. That second test restores two such entries and checks the warning appears exactly once. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-14 04:28:34 +02:00
Author
Collaborator
  1. internal/vaultik/restore_ownership_warning_test.go: in every case, each entry ends up with the owner it was recorded with. The only mismatch tested is a group mismatch, so the tests still pass if warnIfOwnershipNotPreserved compares only the group and drops the owner.Uid != file.UID check. The definition of done in #316 asks for a restore where some owners do not match. Acceptable: a case where an entry is recorded with another owner than the one it gets on disk (for example otherOwnerID), which checks that the warning is printed. It needs no setgid directory, so it runs as any user.

  2. Commit message: the body is about 137 words, over the limit of about 120. Acceptable: a body of about 120 words or fewer, for example by leaving out what the PR body already says.

Unverified: the macOS case, which was not run on a Mac.

Model: opus-5-5

1. `internal/vaultik/restore_ownership_warning_test.go`: in every case, each entry ends up with the owner it was recorded with. The only mismatch tested is a group mismatch, so the tests still pass if `warnIfOwnershipNotPreserved` compares only the group and drops the `owner.Uid != file.UID` check. The definition of done in https://git.eeqj.de/sneak/vaultik/issues/316 asks for a restore where some owners do not match. Acceptable: a case where an entry is recorded with another owner than the one it gets on disk (for example `otherOwnerID`), which checks that the warning is printed. It needs no setgid directory, so it runs as any user. 2. Commit message: the body is about 137 words, over the limit of about 120. Acceptable: a body of about 120 words or fewer, for example by leaving out what the PR body already says. Unverified: the macOS case, which was not run on a Mac. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-14 04:47:04 +02:00
clawbot added 1 commit 2026-10-14 04:51:53 +02:00
A restore by a normal user always warned that file ownership was not
preserved, even when every entry came out with its recorded owner and
group. The owner and group each restored entry has on disk are now
compared with the recorded ones, and the warning is printed once if any
differ. The comparison is made on disk because on macOS, and in a setgid
directory on Linux, a new entry takes the group of its directory, not
the user's.

Judgement call: an entry that is not on disk after the restore is not compared.
Unverified: not run on a Mac; the directory-group test runs only as root.

Model: opus-5-5
clawbot force-pushed issue-316-ownership-warning from fbbf701515 to 2045476039 2026-10-14 04:51:53 +02:00 Compare
Author
Collaborator

Rework, rebased onto current next:

  1. Added a case where an entry is recorded with another owner than the one it gets on disk, with its group matching; it checks the warning is printed and runs as any user.
  2. Shortened the commit message body to under the limit.

Model: opus-5-5

Rework, rebased onto current `next`: 1. Added a case where an entry is recorded with another owner than the one it gets on disk, with its group matching; it checks the warning is printed and runs as any user. 2. Shortened the commit message body to under the limit. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-14 05:10:30 +02:00
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 291c39174f into next 2026-10-14 05:39:28 +02:00
clawbot deleted branch issue-316-ownership-warning 2026-10-14 05:39:30 +02:00
Sign in to join this conversation.