Skip to content

docs(logging): record that root-written log files break the itsUP user's read - #151

Open
Morriz wants to merge 11 commits into
mainfrom
docs/logger-root-ownership-limit
Open

Morriz wants to merge 11 commits into
mainfrom
docs/logger-root-ownership-limit

Conversation

@Morriz

@Morriz Morriz commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Builds on #150. The base is main, and this branch contains #150's head (d8fa92c, taken by merge commit 6a4b28e), so until #150 merges the diff here also shows #150's commits. The commits that belong to this PR are 4378182 and 172337d, documentation only; against #150's head the diff is README.md and docs/project/design/logging.md.

Why

The goal was for the API server and the container security monitor to write their diagnostics through instrukt_ai_logging, so that instrukt-ai-logs itsup shows everything itsUP's own code logs. That work stopped before any code changed: a root-run process and the itsUP user cannot share the logger's directory without breaking the user's read. Under systemd the monitor's unit runs as root with HOME pinned to the itsUP user, and the backup job's unit already does. The launchd agents run as the user and are not affected.

Making that sharing work is a change to the logger, or to which user the units run as. It is not something itsUP's logging setup should work around, so this PR records the limit and changes nothing else.

What was established

At the locked logger release (0.10.3):

Fact How it was established
The writer creates the app directory closed to everyone but its owner, and creates each log file readable by its producing user only, re-applying that mode on every open. Logger contract (docs/contract.md, File handling) and writer source at tag v0.10.3; observed in a local run.
User first, then root with HOME pinned to that user (the order on an installed host): root's file is owned by root inside the user's directory, the user cannot read it, and the user's own writes keep working. Reproduced in a disposable Linux container with the released 0.10.3 package, as root and as an unprivileged user.
Root first, where the user's state directory does not exist yet: every missing directory on the way is created owned by root and closed to others, and the user's configure_logging then raises PermissionError. For itsUP that means the CLI does not start. Same container run.
The reader fails with Permission denied (exit 1) in two cases. A file it cannot open was last written inside the requested window: no lines are printed, not even from the readable sources. Or nothing in the window matches and that file holds the folder's most recent write: the no-match note needs the newest entry and opens that file to find it, so this fails in any window, a bare instrukt-ai-logs itsup included. With a readable file holding the newest write and entry, the no-match note prints and the exit is 0. --include <source> limited to readable sources works in both cases. Reader built from tag v0.10.3 and run locally against a directory holding one unreadable file; reader.rs (no-match branch) and merge.rs (newest_log_timestamp) at that tag. The second case was found in review and reproduced here.
The logger's own design assumes one producing user per directory: rotation runs as that user and root never touches the files. Logger docs/design.md and contract, Rotation.

Consequence: on a systemd host a bare instrukt-ai-logs itsup from the itsUP user fails from a backup run that wrote to its file until the CLI next logs, and any window that reaches back to that write fails too. The monitor's unit also runs as root, so routing its diagnostics through the logger would add a second such file, written on every event it logs.

What changes here

  • docs/project/design/logging.md: two failure modes (a root-written file in the itsUP user's diagnostic folder; root as the first writer), the ownership of backup.log, and a corrected reading flow that no longer promises the itsUP user can read backup.log.
  • README.md: what an operator sees on a systemd host and which command still works.

No code, no unit files, no dependency change.

Also grounded, for whoever takes the daemon move further

  • Why the daemons log to the journal. Before the native-daemon-supervision delivery the monitor did write monitor.log through the logger, as root. That delivery moved both daemons to the supervisor journal so that records survive a restart, rotate under host policy, and are readable regardless of which user ran the process. The third reason is this same ownership problem; older logger releases created files under the process umask, which is why it did not show then.
  • The logger has no console mode. configure_logging installs exactly one root handler, the file writer. A daemon that moves to the logger stops attaching its own stdout handler; nothing is duplicated to stdout by the library.
  • The failure alert quotes the journal. lib/alerting.py reads the failed unit's last journal lines. Once a daemon's diagnostics leave the journal, an alert carries only what the supervisor itself captured (start, stop, crashes, anything printed before logging is configured) unless the alert composer also reads the logger's file.
  • uvicorn keeps its own handlers. Its server, error and access loggers do not propagate to the root logger, so they stay on the unit's stdout and stderr whatever the root handler is.
  • The API runs as the itsUP user, so it has no ownership conflict of its own. It was left on the journal too: its records would land in a directory whose merged read already fails for that user when the backup's file is in the window, and splitting the two daemons across two sinks was not asked for.

Verified

  • instrukt docs validate and instrukt docs render --check pass on this head.
  • The table above; nothing in it was run on the container host.

Not verified

  • Nothing here was observed on the container host by the author. Relayed from the session that dispatched the review: there backup.log is root:root 0600 inside the user's 0700 folder, a long-window instrukt-ai-logs itsup as the itsUP user fails on it with a permission error, and the installed reader is still the pre-0.7 Python script.
  • Whether the logger's per-user rotation can rotate a root-owned file in the user's directory. By its design it should not have to.
  • bin/format.sh and bin/lint.sh were not run on this head: it changes no Python.

… the bound

itsup imports instrukt_ai_logging.cli, which the logger stopped shipping in
0.7.0. The bound set for that was rewritten to <0.11 by the next grouped
Dependabot bump, because a 0.x minor is not a semver-major and the existing
ignore rule let it through. The lock moved to 0.10.2 and the container host
installed it on its next self-update, after which every itsup command failed
on import: boot bringup, the nightly apply, the API and the monitor start.

Restore the bound, relock to 0.6.7, and tell Dependabot to ignore logger
releases from 0.7 so the bound is not rewritten again.

Session: t3:5128ca34-972f-4682-ada6-678a5e45024e
Human-Involved: true
The logs command took both from the logger's reader side, which the logger
removed in 0.7.0 when its Python package became the writer SDK only. The CLI
imports the logs command at start, so that one import kept every itsup command
from starting on a current logger.

itsUP now carries the two helpers in lib/log_reading.py. The follower keeps the
behaviour the access log needs: it follows an existing file from its end and
keeps going across truncation in place (copytruncate), replacement at the same
path, and a file that is not there yet.

Three things differ from the code it replaces. A line is held until its newline
arrives, so --grep and --since see whole records, and a file that appears after
the follow started is read from its beginning instead of from its end; the
logger project's current follower does both. The file is read as bytes, so
truncation is judged against a true byte offset and line endings pass through
unchanged, as they already do when the file is read without --follow.

The third-party note that documented the removed reader primitives as something
itsUP reuses goes with the imports.

Session: t3:5128ca34-972f-4682-ada6-678a5e45024e
Human-Involved: true
Nothing in itsUP imports the logger's removed reader side any more, so the
upper bound has no reason left. The requirement becomes a floor at the 0.10
line, the lock moves to 0.10.3, and the Dependabot rule that kept updates from
lifting the bound is removed so the logger follows the same update path as
every other dependency. The writer API itsUP calls, configure_logging and
get_logger, has the same signatures on that release.

The logging design follows: the diagnostic viewer is a standalone tool that the
Python package no longer installs, the handler is no longer named after a class
the logger replaced, and the read path of itsup logs is stated as itsUP's own.

Session: t3:5128ca34-972f-4682-ada6-678a5e45024e
Human-Involved: true
itsUP uses the organisation's one logger so that every project carries the
same instruction for reading its own logs, `instrukt-ai-logs <app>`. An
itsUP-owned reader stands against that: it is a second place to read logs,
and because the CLI imported it at start, the reader helpers it borrowed
from the logger package took every itsup command down when the logger
dropped its reader side. Copying those helpers into itsUP kept the second
reader alive under itsUP's ownership instead of removing it.

The command, its helpers, its host-gate entry and the path helpers nothing
else uses are gone. The CLI spec, the logging design, the host-boundary
rules and the README state where each log is read with the tool that owns
it: logger-written diagnostics with instrukt-ai-logs (the logger project's
standalone tool, with its install step), the supervised units in the
supervisor journal, and the Traefik access log as Traefik's own file.

Session: t3:thread:delegated-task:command%3Amcp%3A90097403-c516-484c-8d66-e31ba569c0c1%3Adelegate-task%3A07981b9a-bc91-45b2-a78c-d360166c6c63
Human-Involved: true
The README and the itsup domain's CLI surface still sent readers to
`instrukt-ai-logs itsup --include monitor`. The monitor has logged to its
supervised unit's stdout since it became a supervised daemon and writes no
file in the logger's directory, so that instruction shows none of its
current records. They now name the journal, where the records are.

Session: t3:thread:delegated-task:command%3Amcp%3A90097403-c516-484c-8d66-e31ba569c0c1%3Adelegate-task%3A07981b9a-bc91-45b2-a78c-d360166c6c63
Human-Involved: true
The Test workflow formats and lints `api` and `lib` and never starts
`itsup`, so a dependency update that stops the CLI from importing merges
green and fails first on the host, where boot bringup, the nightly apply
and the daemon starts all go through that CLI. `make smoke` starts it from
the synced environment and the workflow runs it after lint, so an import
that no longer resolves fails the check before merge.

Session: t3:thread:delegated-task:command%3Amcp%3A90097403-c516-484c-8d66-e31ba569c0c1%3Adelegate-task%3A07981b9a-bc91-45b2-a78c-d360166c6c63
Human-Involved: true
Moving the API server and the security monitor onto the logger's files was
meant to make `instrukt-ai-logs itsup` show everything itsUP's own code
logs. The monitor runs as root with HOME pinned to the itsUP user. At the
locked logger release the writer keeps each file private to the user that
wrote it, and the reader refuses a merged read that includes a file it
cannot open, so a root-run producer in that directory breaks the itsUP
user's read instead of completing it. The backup job is already such a
producer.

The logging design now states this as a failure mode, together with the
case where root is the first writer and locks the itsUP user out of its
own state directory, and the README tells an operator what to expect on
the container host. The daemons keep logging to the supervisor journal:
making root and user share the directory is a change to the logger or to
how the units run, not to itsUP's logging setup.

Session: t3:thread:delegated-task:command%3Amcp%3A90097403-c516-484c-8d66-e31ba569c0c1%3Adelegate-task%3A07981b9a-bc91-45b2-a78c-d360166c6c63
Human-Involved: true
…n which hosts

The failure mode said a window shorter than the backup's last write skips
the root-written file. The reader also fails in a short window: when
nothing in the window matches, it reports the newest entry in the folder
and opens the most recently written file to find it. A bare
`instrukt-ai-logs itsup` therefore fails from a backup run that wrote to
its file until the CLI next logs, which is the common state on a host.

The text also said the backup runs as root on the container host without
qualification. Only the systemd units run a producer as root; the launchd
agents run as the user, whose files are then its own.

The reader's behaviour is no longer attributed to the lock, which pins the
writer only, and the claim that the monitor's file would fail every read
is reduced to what is established: its unit runs as root.

Session: t3:thread:delegated-task:command%3Amcp%3A90097403-c516-484c-8d66-e31ba569c0c1%3Adelegate-task%3A07981b9a-bc91-45b2-a78c-d360166c6c63
Human-Involved: true
The recipe carried a guard for a missing environment: a conditional with
its own error handling inside the Makefile, where no linter or reviewer
of scripts sees it. The recipe now only names the CLI. A missing
environment or an import that no longer resolves both end the recipe
non-zero, so the Test workflow still fails before merge.

Session: t3:thread:delegated-task:command%3Amcp%3A90097403-c516-484c-8d66-e31ba569c0c1%3Adelegate-task%3A07981b9a-bc91-45b2-a78c-d360166c6c63
Human-Involved: true
The design said the default source is avoided because independent
processes must not share one log file. The CLI and the two CLI-family
one-shots do share the default file, and the logger writes each line whole
so that they can. The sentence now states what the code does: a producer
with its own trigger declares a source, the CLI family shares the default.

Session: t3:thread:delegated-task:command%3Amcp%3A90097403-c516-484c-8d66-e31ba569c0c1%3Adelegate-task%3A07981b9a-bc91-45b2-a78c-d360166c6c63
Human-Involved: true
This branch starts at the head of the logger-reader removal and is read as
a diff against main, so it carried that branch's rejected smoke recipe and
the incorrect default-source sentence. Merging the fixed head keeps this
branch's tree equal to that head plus its own two documentation commits.

Session: t3:thread:delegated-task:command%3Amcp%3A90097403-c516-484c-8d66-e31ba569c0c1%3Adelegate-task%3A07981b9a-bc91-45b2-a78c-d360166c6c63
Human-Involved: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant