prepare-data-dir leaves files with a second name to their owner (closes #143)
check / check (push) Canceled after 0s

A hard link in /data shares its owner with a file that can be anywhere
on the same filesystem, so chowning it gave that file to the netwatch
user. A regular file or symbolic link with more than one name now
keeps its owner and its path is logged.

Owners are now set on the opened directory, file or link after
checking it, as chmodDir sets modes, so a hard link swapped in
afterwards is caught. A symbolic link is opened without following it
and given to the netwatch user itself. Setting the owner on an open
file or link needs Linux, the image's system; elsewhere it returns an
error. Other files, such as devices, keep their owner.

Model: opus-5-5
This commit is contained in:
2026-10-18 21:48:41 +00:00
parent e43a710114
commit 54e3e83888
8 changed files with 191 additions and 47 deletions
+19
View File
@@ -0,0 +1,19 @@
//go:build !linux
package reportbuf
import (
"errors"
"io/fs"
"os"
)
// chownFile returns an error on every system but Linux. Giving a
// regular file or symbolic link to a user on the open file, never by
// name, needs O_PATH and AT_EMPTY_PATH, which only Linux has (see
// datadir_linux.go), and prepare-data-dir runs only in the Linux
// image. This file lets the package build elsewhere, such as on macOS,
// where a developer runs make build and make run.
func chownFile(_ *os.Root, name string, _, _ int) error {
return &fs.PathError{Op: "chown", Path: name, Err: errors.ErrUnsupported}
}