Skip to content

docs(osapi): a root broker for declared work - #756

Merged
retr0h merged 29 commits into
mainfrom
docs/osapi-privilege-commands
Dec 6, 2026
Merged

retr0h merged 29 commits into
mainfrom
docs/osapi-privilege-commands

Conversation

@retr0h

@retr0h retr0h commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

The owner chose a root broker in place of sudo for osapi#1907. This PR changes the least-privilege page and the lab page to the broker design.

  • The broker: osapi agent privileged serve. systemd starts it as root for each connection on osapi-privileged.socket (mode 0660, group osapi). It checks SO_PEERCRED, reads one capped JSON request, takes the declaration from its own binary, and matches the arguments exactly, with no glob and no join on a space. Then it runs each call or step in a transient unit (systemd-run --wait --pipe) that has only the Writes, Needs and Relaxes of that call or step. It writes one journal entry for each request. It refuses a request whose declaration hash differs from its own. On macOS, launchd starts it with inetdCompatibility.
  • Enabled behaviors: /etc/osapi-privileged/enabled, which root owns. osapi agent privileged enable|disable|list and service install --privileged change it. The broker refuses each behavior that is not in the list.
  • The agent's unit: the same on each host. It has NoNewPrivileges=yes, an empty bounding set and RestrictSUIDSGID=yes, and no sudo rule. Groups(...) refuses a group that gives root.
  • Preflight: the start fails when osapi has a sudo rule, a root group or a capability. It warns when the broker does not answer, or when the broker has different declarations from the agent.
  • Declared calls: AnyArgs is gone. validate refuses a call without a shape, with no exception. Sudo is renamed to Root.
  • Steps: each behavior that writes a file has its own write and remove steps. The guard walks each path with openat and O_NOFOLLOW, sets the owner and mode through the descriptor, and refuses the setuid, setgid and sticky bits and a file with more than one link. Each step has its refusals (sysctl, user, group, sshkey, process).
  • Read steps: they return only fields that hold no secret. A gohai-partial read gets a warnings field.
  • Removed: sudoers get and systemd get. privileges get remains.
  • Also: osapi start is for a test only. The lab checks that /var/lib/osapi/pki keeps osapi:osapi-admin 2750 after a restart.

The commits before 59d0a99 hold the sudo design that this PR replaces. Earlier reviews of this PR were of that design.

Refs osapi-io/osapi#1907. The component pull request links back here when it opens.

Component: osapi-io/osapi#1943
Component: osapi-io/osapi-lab#117 (the lab page, components/osapi-lab/README.md)

🤖 Generated with Claude Code

@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Code review: approved (head 75c1caa). The three commands match the group in osapi main: osapi dsl behavior method get and openapi get are the same kind of command (reference/cli/_catalog.mdx), so privileges get, sudoers get and systemd get fit beside them. No --section is left in the repository, except the sentence that says it is not a flag. The install example, the lab and CI text, the build list, and the base-set sentence (osapi agent service install writes the base set, the drop-in adds only its own capabilities) agree with each other and with the earlier pages. Relaxes(ProtectKernelTunables) for sysctl matches the first row of the table of relaxed settings, and behavior validate refusing a setting that is not in the table is consistent. More commits are coming on this PR, so I review the head again when they land.

@retr0h retr0h added the code-reviewed An independent reviewer checked correctness, bugs and edge cases label Dec 5, 2026
@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Standards review at 75c1caa. Changes requested: three lines still give the privileges to behavior get.

The change itself fits the rules:

  • privileges get, sudoers get and systemd get sit beside the method get and openapi get that the behavior group has on osapi main.
  • The reason, that a command has one output type, is stated one time.
  • The install block, the capabilities text, command exec, the skill and the order of work all use the new commands. No --section is left, except the sentence that says why it is not used.
  • Relaxes(...) is named next to the table of costs that behavior validate checks against.

There is no em dash. The title has 44 characters. The commit has 48 characters and its trailer. Lint passes. Refs and not Closes is correct, because osapi#1907 has more work.

Open. With this change, behavior get is a summary that lists only the names of the steps and whether the behavior is root equivalent. These lines still say that it prints the privileges:

  1. Line 58: "The agent-hardening page of the docs, the agent preflight and osapi dsl behavior get print the same data." The data is the declared calls, which behavior privileges get now prints.
  2. Line 310: "behavior get and the privileges page of the docs mark such a group as root equivalent." The groups are in privileges get.
  3. Line 454: "Thus the page, the preflight and get cannot show different rules." Name privileges get, or the three commands.

Line 63 ("osapi dsl behavior get --json prints the programs of each behavior") is about today, and is correct as it is.

The label stays needs-standards-review.

@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 9b3519a, for the standards review at 75c1caa:

  1. Line 58 now names osapi dsl behavior privileges get.
  2. The groups line now names behavior privileges get and the page of the behavior in the docs.
  3. The build-now paragraph of #1908 now names privileges get. It also says what the docs do: one page tells how to install the files, and the generated page of each behavior lists its calls and steps.

The same commit adds three things that the build of osapi#1907 found. Each is a change to the design, so it needs a new review:

  • A declared call names the files that its program writes itself, and the capabilities that it needs, with .Writes(...) and .Needs(...). The sandbox holds root too, so useradd and netplan apply cannot run under the unit without them. The drop-in table and the paragraph about the sandbox now say this.
  • ProtectSystem=no is a new row of the cost table, for package only. behavior validate refuses it on a behavior that is not root equivalent.
  • The two files of a behavior also hold those of each behavior that it uses. For example, the files of dns hold the rules of netplan. A step with the same name as a step of a used behavior replaces that step, so managedfile's write, which accepts each path, never reaches a caller.

@retr0h retr0h added needs-code-review The author asks for the independent code review and removed code-reviewed An independent reviewer checked correctness, bugs and edge cases labels Dec 5, 2026
@retr0h retr0h changed the title docs(osapi): commands that render privileges docs(osapi): a root broker for declared work Dec 5, 2026
@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Standards review at 59d0a99, of the broker design. This is a full review, and replaces my review of the sudo design. Changes requested.

What meets the rules:

  • The page is in the right place. The README index row and the lab page link it, and the anchors resolve (#the-agents-unit, #the-root-broker, #each-component-as-its-own-user).
  • The order of preference, the broker's checks, the sandbox table and the cost table are each stated one time.
  • The threat model is checked against a taken-over agent at each step.
  • There is no em dash.
  • The PR title has 44 characters, which becomes the squash subject, and each commit has its trailer. Refs osapi-io/osapi#1907 is correct for a design that is not built yet.

Open:

  1. osapi start contradicts itself. Line 332 says "When the agent is root, as in a test of osapi start, Escalate calls Apply." Line 591 says osapi start "refuses to run as root". Both cannot hold. Say when Escalate calls Apply directly, for example in a unit test with a fake host, and remove osapi start from that sentence.

  2. Hand-written providers. The page says that "The agent never runs as root, and never gets root", and that the unit "is the same for each host". "Hand-written providers" then says that they "stay as they are and need root", and lists writes that fail under User=osapi. Say what happens to those writes under this design. If they fail until the provider moves to a behavior, say so, and say how the operator sees it, such as an error or a preflight warning.

  3. One fact in one place: the groups that give root. The list is in three places, in three different orders:

    • the refusals of the user and group steps, around line 348
    • the agent's unit, around line 485
    • preflight, around line 696

    Keep one list, for example with the rule that behavior validate checks, and link to it from the other two places.

  4. behaviors.md now describes the design as today. That page tells how behaviors work today. The changed row of behavior.Sudo("prog") now says "A program the provider runs as root". Today the provider runs it with sudo, which is what the code does. The row of behavior.SudoOnPlatform beside it still says "with sudo", so the two rows disagree. Keep the text of today, and keep the link to the design.

  5. The name of the field. Line 239 says the build renames Sudo to Root. Line 280 says osapi dsl behavior spec get prints the rule "with the Sudo and Privileged fields". After the build, that is Root.

  6. Order of work, item 1. It says that preflight runs sudo -n -l and gives warnings, and that "The broker replaces it". Preflight still runs sudo -n -l (line 694), but now a rule fails the start. Say that the warning becomes a failure, not that the check is replaced.

Minor:

  • The footer says "Written from ... internal/privileged/". That directory is not on osapi main. If it is on the branch of #1907, say so.
  • No checks were reported on the branch when I looked.

The label stays needs-standards-review.

@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Code review: changes requested (head 59d0a99). I read the new least-privilege.md and the lab, README and behaviors.md changes, and checked the page against osapi main and what I know of systemd and the kernel. I ran nothing on a host: the systemd points below come from its documentation and from reading the page, and the lab should confirm each one.

Required

  1. StandardError goes to the socket. The broker unit sets StandardInput=socket and StandardOutput=socket and nothing for StandardError. Its default is inherit, which duplicates standard output, so the standard error of the broker, and of each log line that the Go code writes to stderr, goes into the connection that the agent reads. The response then has log text in it, or the agent can write nothing into the protocol except through the broker's own bytes. Fix: StandardError=journal (or null) in osapi-privileged@.service, and write the journal entry through the journal's native socket, not stderr. The macOS launch daemon has the same shape: with inetdCompatibility, launchd gives the socket as stdin, stdout and stderr, so the broker must not log to stderr there either.
  2. behavior.Regex(re) is AnyArgs again. The page says there is no AnyArgs and validate refuses a call without a shape, but Regex(".*") is a shape. The rule bullets (a class never negated, never holds a space or a control character, a variable argument never starts with -, a bounded length) are written for Class and OneOf only. State that validate parses each Regex (with regexp/syntax) and applies the same rule: no ., no negated class, no \s or \S, no unbounded repeat, a first element that is a literal not starting with - or a class without -. Or remove Regex. Also say how the matcher anchors it (\A...\z).
  3. The capability table has no CAP_DAC_OVERRIDE or CAP_DAC_READ_SEARCH, and the units start with an empty bounding set. Root with an empty set is an ordinary user to the file system. So: the sshkey write step writes into ~user/.ssh (mode 0700, owned by the user) and needs CAP_DAC_OVERRIDE; the user and group steps write /etc/shadow, which is mode 0000 on the RHEL family and Fedora (earlier rounds of this page found that), so they need CAP_DAC_OVERRIDE or CAP_DAC_READ_SEARCH; the read step keys that reads other users' authorized_keys needs CAP_DAC_READ_SEARCH. The example Needs("CAP_CHOWN") for useradd is not enough either: useradd also writes an audit record (CAP_AUDIT_WRITE, and AF_NETLINK, which the table gives) and I expect it to fail without it as root. Add the rows, with the cost ("read or write each file of the host"), and say that behavior validate or the lab run finds a missing one. Read CapBnd from /proc/self/status in the unit of one call in the lab, to prove that the property took effect, as -p CapabilityBoundingSet= with an empty value is easy to get wrong.
  4. A call or step has no time limit, and the broker has no cap on what it keeps. systemd-run --wait ends only when the unit ends. A hung apt or dpkg lock, or an agent that closes the socket and leaves, holds a root unit for ever. Add RuntimeMaxSec= to the transient unit (a value for each call, with a default), say that the broker stops the unit (systemctl stop) when the agent's connection closes or the request's deadline passes, and that the broker keeps at most 1 MiB of standard output and of standard error and stops the unit above it. Add a deadline to the read of the request too: Accept=yes has MaxConnections=64 by default, so 64 idle connections stop every later request, and a burst past TriggerLimitBurst puts the socket unit in the failed state until root restarts it. The only client is the osapi user, so this is an availability problem and not a privilege one, but the rescue start goes through the same socket.
  5. Escalate and osapi start contradict. "When the agent is root, as in a test of osapi start, Escalate calls Apply" (Privileged steps), and "osapi start ... refuses to run as root" (A user for each component). The integration job today runs osapi start as root (sudo -E ... go-unit-int), which this page says CI stops doing. Say which one it is: either osapi start may run as root in a test, or Escalate has a different test path.
  6. macOS has links at the front of each path. The guard "walks each path from / with O_NOFOLLOW" and the steps on macOS enforce Writes themselves, but on macOS /etc, /var and /tmp are links to /private/.... The older text of this page already used /private/etc/sudoers.d. State that a macOS Writes glob names /private/etc/..., or that the walk follows a link that root owns, in a directory that root owns, and refuses the others. Linux has the same case at a smaller size (/var/run to /run, /etc/resolv.conf).
  7. The branch is behind main, and the neighbor pages still say sudo. main has docs(osapi): add pending changes and the rescue #749, docs(osapi-lab): each VM gets the boot rescue unit #750, docs(osapi-lab): lab_agent adds the rescue units #757 and docs(osapi): collectors from gohai's command #758 since this branch started, so the PR will conflict on the lab README (the paragraph on the three rescue units that docs(osapi-lab): lab_agent adds the rescue units #757 added, which this diff drops), on behaviors.md (docs(osapi): collectors from gohai's command #758's text about gohai collector list --json and the rhel platform, which this diff reverts to the old text) and on the page list in components/osapi/README.md, which loses the "Pending changes" row. Rebase, and keep those. After the rebase, pending-changes.md still has "The rescue unit and its sudo rule" with three sudoers lines, and says osapi declares systemctl with behavior.Sudo; permissions.md, exec.md and behaviors.md also mention sudo. Change pending-changes.md in this PR, because it contradicts "no sudo rule" and the rescue and the check are the first calls that go through the broker: say that the rescue start and stop, and the check start, are declared calls of the broker, and keep the UUID shape.

The five points you asked about

  • Accept=yes, StandardInput=socket, StandardOutput=socket: correct for an inetd-style template (osapi-privileged@.service for Accept=yes), and a new process for each connection runs the binary on disk, so the declaration-hash text is right. The missing StandardError is item 1. User=root is the default and not needed. SocketUser, SocketGroup and SocketMode do what the page says, and systemd makes /run/osapi with DirectoryMode (0755). Add Wants=osapi-privileged.socket and After= to the agent's unit, and enable --now of the socket to the install list: the install table lists the files and not that the socket is started.
  • SO_PEERCRED: read on the connected descriptor (fd 0), it gives the pid, uid and gid of the process that called connect, set by the kernel, so a peer cannot forge it, and passing the descriptor to another process does not change it. The check "uid is the uid of osapi" is right, and the socket mode alone would let any member of the group osapi in, as the page says. The page should also say that a process that the agent starts, such as command exec, passes the check, which "Who the design protects against" already says.
  • systemd-run --wait --pipe --collect: --pipe connects the standard input, output and error of systemd-run to the unit, and keeps them as three separate descriptors, so the response can hold stdout and stderr apart; --wait with --pipe returns after the unit ends, and propagates its exit status on the systemd versions of the platforms in the lab. Give the unit a name (--unit=osapi-priv-<n>) so the journal entry, the stop on a closed connection and the log can name it. Environment= none is right. The properties are right as a list; I would test ProtectKernelTunables=yes with netplan apply: I recall that it runs udevadm trigger, which writes under /sys, so the netplan rows may need ProtectKernelTunables=no in addition to CAP_NET_ADMIN. I did not run it.
  • What the broker needs to start a transient unit as root: as far as I know, systemd-run as uid 0 connects to PID 1's private socket (/run/systemd/private), which checks the peer uid and not a capability, so an empty bounding set may be enough, and the lab should try the empty set first and add only what fails. If the system bus is used (no private socket, or /run/systemd hidden), the caller needs polkit or CAP_SYS_ADMIN. The page should say what the set is for, not "only what it needs": whatever the set is, a root process that can ask PID 1 for any transient unit is root-equivalent, so the sandbox of the broker is hygiene, not containment. Add one sentence to "Who the design protects against" that the broker is the one trusted component: a bug in its matcher is root. The transient units, not the broker, hold the limits.
  • The StateDirectory chown note: it matches what I know: systemd recurses with chown over the tree only when the top directory's owner differs from the unit's user, and the recursion also applies the unit's UMask as a mask to the modes it finds (0640 would become 0600, 2750 would become 0700), so the lab check of owner, group and mode after a restart is the right test. Say that the mode matters too, not only the group, and that the check runs on each platform of the lab, because the recursion rules differ by systemd version.

Notes, not blocking

  • Preflight "sudo -n -l succeeds for osapi" cannot succeed under NoNewPrivileges=yes: sudo refuses to run, so the check is dead under the real unit and the NoNewPrivs check does the work. Keep it for a hand run, and say so.
  • behavior.Reads(...): validate refuses a path "that the agent writes". Say how it knows (the Writes of the agent's own behaviors and the state directory), so the rule is something a test can hold.
  • The page says Escalate is the same Go code on both sides of the socket, and the transient unit runs osapi agent privileged run. A taken-over agent can run that command itself as osapi, with no privilege; say that it does nothing for it, so a reader does not wonder.

retr0h and others added 4 commits December 5, 2026 14:31
The build of osapi#1907 showed that a --section flag of behavior get
cannot print a file: a command of osapi has one output type. Three
commands of the behavior group render the privileges, the sudoers file
and the drop-in, as method get and openapi get do. The page also names
Relaxes, which declares a sandbox setting that a drop-in turns off, and
says that the agent's unit carries the base bounding set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three lines still gave the privileges to behavior get. They now name
behavior privileges get, and the generated page of each behavior.

What the build of osapi#1907 found:
- A declared call names the files that its program writes, and the
  capabilities that it needs, with .Writes and .Needs. The sandbox of
  the unit holds root too, so useradd failed without them.
- Relaxes(ProtectSystem), for package, on a root-equivalent behavior
  only.
- The files of a behavior hold those of each behavior that it uses. A
  step of the same name replaces the step of the used behavior.

Refs osapi-io/osapi#1907

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The owner chose a root broker in place of sudo. The agent has no sudo
rule, no capability and NoNewPrivileges=yes. It sends one request on a
socket to osapi agent privileged serve, which systemd starts as root
for each connection. The broker checks the peer, takes the declaration
from its own binary, matches the arguments exactly, and runs each call
or step in a transient unit with only what it declares.

Also: the enabled list of each host, read steps that return no secret,
no AnyArgs, the guard and its walk for each file step, the refusals of
each step, a fixed unit for the agent, the preflight for a path to root
around the broker, the pki lab check, and osapi start as a test only.
The lab page installs and checks the broker in place of sudoers files.

Refs osapi-io/osapi#1907

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Standards re-review at 29e6427. Changes requested. I checked the page against the component PR, osapi-io/osapi#1943 at 44a078b3.

Fixed:

  1. osapi start: line 332 now says that Escalate runs the step in the same process inside a step and on the fake host, and line 608 says that osapi start refuses root. They agree.
  • The footer cites internal/privileged/, which is on the branch of osapi#1943. That is correct when the two merge together.

Still open, from my last review:

  1. Hand-written providers (line 829). The section says that they "stay as they are and need root". Its table puts writes to cron, service unit files, NTP sources, netplan, packages, users, groups and SSH keys in the column "Fails". On osapi#1943 each of these is a behavior: schedule, service, ntp, netplan, packages, user, group and sshkey, under internal/behaviors/. The only hand-written providers that are left are the node reads under internal/provider/node/ (disk, host, load, memory). Change the section to say that, or remove it. Keep the text about the ping range, which is still correct.

  2. One fact in one place: the groups that give root. The list is still in three places, in three orders: line 349 (the user and group steps), line 503 (the agent's unit) and line 713 (preflight). In osapi#1943 the code has one list, internal/behavior/systemd.go:66. Write the list one time, and link to it from the other two places.

  3. behaviors.md. The row behavior.Sudo("prog") now says "runs as root", and the row behavior.SudoOnPlatform says "with sudo". The two rows disagree. osapi#1943 renames them to behavior.Root and behavior.RootOnPlatform (internal/behavior/root.go:185, :196). This PR merges with it, so the page describes that code: change both rows to the new names, and say "as root, through the root broker" in each. The row behavior.Runs says "without sudo". Change it to "as the agent's user".

  4. The name of the field. Line 239 says that Sudo and SudoOnPlatform "stay from the first build", and that the build renames them. Line 280 says that spec get prints the Sudo field. osapi#1943 makes the rename, so both lines are wrong after the merge. Use Root and RootOnPlatform.

  5. Order of work, item 1 (line 859). It still says "The broker replaces it". Preflight still runs sudo -n -l (line 711), but now a sudo rule stops the start. Say that the warning became a failure.

New:

  1. Order of work, item 3 (line 862). It says "Build now, in Behaviors declare exact sudo calls; osapi generates and checks the sudoers rules osapi#1907". osapi#1943 builds it, and the two PRs merge together. AGENTS.md, "Remove a plan when its work is built", applies: mark the item done. Move each part that is built into the text of the page, as current behavior.

No em dash. The PR title has 44 characters, and the squash uses it. One commit subject has 52 characters, but it is not the squash subject. Each commit has its trailer.

The label stays needs-standards-review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Standards re-review at c5c5d73. Changes requested on two items. I checked the page against osapi#1943 at ed0946bc.

Fixed:

  1. osapi start: lines 394 and 721 agree. Escalate runs in the same process inside a step and on the fake host, and osapi start is for a test only.
  2. Hand-written providers (line 947). It now says that only the node reads of host, memory, load and disk stay in internal/provider, and that each of them runs as osapi. It also says that each domain that a hand-written provider wrote before is a behavior now. This agrees with internal/provider/node/ and internal/behaviors/ on osapi#1943. The rule for a later provider, and the empty list, are clear.
  3. Groups that give root. There is one list, at line 584, which names rootGroups in internal/behavior/systemd.go and its three users. Lines 410, 581 and 824 link to it.
  4. Field name. Line 337 says Root and Privileged.
  5. Preflight and sudo. Lines 829 and 977 say that preflight no longer runs sudo -n -l, and why. osapi#1943 at ed0946bc removes the check (internal/agent/preflight.go:69). They agree.
  • pending-changes.md now describes the three systemctl calls as calls that the broker matches. The sudoers rules are gone, and the text about the shape of a job ID is stated one time.
  • The footer says that internal/privileged/ is in osapi#1943 and not yet on main.

Open:

  1. behaviors.md, lines 130 and 133. This head reverts the rows to main: behavior.Sudo("prog") "runs with sudo", and behavior.SudoOnPlatform "runs with sudo". osapi#1943 at ed0946bc removes Sudo and has behavior.Root and behavior.RootOnPlatform (internal/behavior/root.go:179, :190), and no code runs sudo. This PR merges first and osapi#1943 merges right after it, so after the pair these rows name a function that does not exist. Change them to Root and RootOnPlatform, "as root, through the root broker". In line 131, change "without sudo" to "as the agent's user".

  2. Order of work, item 3 (line 982), and line 293. Item 3 still says "Build now, in Behaviors declare exact sudo calls; osapi generates and checks the sudoers rules osapi#1907". Line 293 still says "The build renames". osapi#1943 builds both, and it merges with this PR. Mark item 3 "Done (feat: a root broker in place of sudo osapi#1943)", and write line 293 as current: "Root and RootOnPlatform declare...". AGENTS.md, "Remove a plan when its work is built", applies to the rest of the order of work when items 4 to 6 are complete.

No em dash. The PR title has 44 characters, and the squash uses it. Each commit has its trailer.

The label stays needs-standards-review.

@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Code review of the page at c5c5d73 (based on current main). I re-read the page against my 7 items of the review of 59d0a99 and against osapi#1943 at 44a078b35c. Where the page is ahead of the code, I say so: those code fixes are in the next push of #1943.

My 7 items

  1. StandardError: fixed (StandardError=journal, and StandardErrorPath for the macOS daemon).
  2. Regex: fixed in the page (no regular expression). The code at 44a078b still has behavior.Regex for the image reference; it goes with the image steps.
  3. Capabilities: fixed. The table has CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH and CAP_AUDIT_WRITE. The code at 44a078b does not: sshkey add, remove and keys need them, and the user steps lack CAP_AUDIT_WRITE.
  4. Limits: fixed in the page (a 5 s read, RuntimeMaxSec, stop on a closed connection, 1 MiB, trigger limits). Not in the code yet.
  5. Escalate and osapi start: fixed ("refuses to run as root", and CI runs under the real units).
  6. Links: fixed in the page by a fixed table. The code at 44a078b still follows a root-owned link in a root-owned directory (guard_unix.go link), so the page and the code disagree until the next push.
  7. Branch and neighbor pages: rebased, and pending-changes.md now has the broker calls. One neighbor is still stale; see Required 1.

Required

  1. behaviors.md and agent-skills.md still describe Sudo. behaviors.md:131-133 (behavior.Runs "without sudo", behavior.SudoOnPlatform), :537, :551 and :760, and agent-skills.md:106 and :161, say that a provider runs a program with sudo. The page of this PR renames Sudo to Root, and the code does. Change those lines in this PR, because they describe the API that the PR removes. (The PR diff against main has no change to either file now.)
  2. A 5-minute default runtime cannot hold the long calls. The code gave the broker 30 minutes for one request (brokerTimeout). apt-get install and upgrade, the docker pull that stays a call or becomes the image step, and docker create of a large image can run longer than 5 minutes on a slow host. The page says only that a call may set .MaxRuntime(d). List the runtime of packages, updatepackages and the image steps, so that the build sets them and the lab run does not find them as timeouts.

Notes, not blocking

  • The capability table says "each other call and step declares no capability". Some programs need a capability for a reason other than DAC. The lab write tests find them, as the page says. Two I expect: hostname (setting the hostname needs CAP_SYS_ADMIN when the step uses hostname and not hostnamectl) and a sysctl key that the kernel checks with capable(). Say which program the hostname step runs.
  • The page says the broker's unit name has no job ID because the request does not carry one. The journal entry of a request then cannot be tied to the job that asked. Say that this is accepted, or add the job ID to the request as a non-secret field that the broker only records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Standards re-review at 06a3eb1. One item is open.

Fixed:

  • Item 4, behaviors.md. The rows are behavior.Root, behavior.RootOnPlatform and behavior.Privileged, "as root, through the root broker". Runs is "as the agent's user", and the method row is .Root, .Runs. This agrees with internal/behavior/root.go on osapi#1943.
  • Item 5. No Sudo field or "The build renames" is left.
  • Item 7. The header says what osapi#1943 builds. Order item 3 says "Done, in feat: a root broker in place of sudo osapi#1943", and the sections without a mark describe that build. Order item 1 says that osapi#1943 removes the sudo -n -l check, which agrees with internal/agent/preflight.go.
  • Item 2. The hand-written providers section is gone. No other line depends on it.
  • Items 1, 3 and 6 are still fixed. No em dash. just test passes. The PR title has 44 characters, and each commit has its trailer.

Open:

  1. Order item 5 has no issue (line 1014). "Build now: a user for the NATS server and the controller, and the pages of each component..." names no issue. Items 6 and 7 name docs: one page for the agent's privileges osapi#1908 and lab_least_privilege: unprivileged VM agents through the broker osapi-lab#115. Before this, item 5 was part of Behaviors declare exact sudo calls; osapi generates and checks the sudoers rules osapi#1907, which osapi#1943 closes. CONSTITUTION.md, "Tracking", and AGENTS.md say that work agreed for later is an issue in the repository where the change goes. Open it in osapi with its labels, and cite it in item 5 and in the line 7 list of the header.

The label stays needs-standards-review.

@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Code review of 06a3eb1 against osapi#1943 at a634a9d4df. I checked the page against the code and found no mismatch in these claims: the 5 minute default runtime and the 10 second wait, the enabled list naming the requester itself, UsesSteps as the only write steps of a required behavior (the grants match: password gets user.password, and dns, route and interface get the netplan write and remove steps and calls), the 16 KiB room in the request limit, the macOS StandardErrorPath of /var/log/osapi-privileged.log, and CAP_NET_RAW for the Linux ping.

One point depends on the code review: the page says a call has .MaxRuntime(d) or 5 minutes, which is true, but no call or step sets it, so apt-get and docker pull get 5 minutes (details on osapi#1943). When the code sets them, add them to the page.

Clean for the page: I remove needs-code-review and add code-reviewed only after the code pull request is clean, so this one stays queued.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Standards re-review at c982990. Approved.

  • Item 8. Order item 5, the header list and "A user for each component" cite Run NATS and the controller as their own users osapi#1945. The issue is open, with enhancement, component/controller and architecture.
  • The new text agrees with osapi#1943 at 0c654645:
    • the journal fields of the broker;
    • the 30-minute runtimes of packages, updatepackages, the image pull step and the docker create step;
    • .Named and UsesCalls, with the names generate and apply of netplan;
    • a behavior that is root equivalent through a call or a step that it gets.
  • Output sample. The sample in agent-skills.md and cli.md shows Root: and Privileged:, not Sudo:.
  • Items 1 to 7 are still fixed. just test passes. No em dash. The new commit has 50 characters and its trailer, and the branch is on the current origin/main.

The label is now standards-reviewed.

@retr0h retr0h added standards-reviewed An independent reviewer checked this PR against the standards and removed needs-standards-review The author asks for the independent standards review labels Dec 5, 2026
@retr0h

retr0h commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at c982990 for the pages this pull request changes. The page matches osapi#1943 at 0c65464597 on the 30 minute runtimes, UsesCalls and .Named, the journal fields (no job ID), the hostname set step with no capability, and the macOS log file.

Two lines that this pull request does not change are stale and say sudo: components/osapi/built-in-behaviors.md lines 307 ("run the docker CLI with sudo") and 381 (shutdown "through sudo"). The code runs both as root in a privileged step. Fix them here or in a follow-up; I do not block on it.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: changes requested (head 50c9a19). There is 1 finding.

  1. components/osapi/least-privilege.md, the table of the unit of a call. It has two rows for Environment=. One says "Environment=HOME=/tmp | always". The other says "Environment= | none: the unit starts with the environment of systemd, not of the agent". The second row does not agree with the code: internal/behavior/systemd.go on osapi#1943 at ad9f3373 adds Environment=HOME=/tmp to each unit. AGENTS.md, "What you find during the work": "A page that does not agree with the code" is a fix. Fix: keep one row, such as "Environment= | only HOME=/tmp: the unit starts with the environment of systemd, not of the agent, and the home of root is closed, so a program such as docker reads its config in the private /tmp".

Checked, with no finding:

  • Ping. The text says why ping runs as root with only CAP_NET_RAW, with the result from the lab. It agrees with osapi#1943 at ad9f3373, where AsDynamicUser is gone. No mention of .AsDynamicUser() is left.
  • No em dash. just test passes. The commit has its trailer.

@retr0h retr0h added needs-standards-review The author asks for the independent standards review and removed standards-reviewed An independent reviewer checked this PR against the standards labels Dec 6, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head a9ba67d). Checked: the finding from 50c9a19 is fixed. The unit table in components/osapi/least-privilege.md has one Environment= row, "only HOME=/tmp", which agrees with internal/behavior/systemd.go on osapi#1943 at a089b907. The commit changes only that table, has its trailer, and is a fast-forward of 50c9a19. No em dash. just test passes.

@retr0h retr0h added standards-reviewed An independent reviewer checked this PR against the standards and removed needs-standards-review The author asks for the independent standards review labels Dec 6, 2026
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review at a9ba67d (the head is not 50c9a19), against osapi#1943 at ad9f33733e: the page matches the code on the ping unit running as root with CAP_NET_RAW only, on NoNewPrivileges being relaxed only with Needs and an argument shape, on the removal of AsDynamicUser, and on Environment=HOME=/tmp. One addition, not blocking: say what uid 0 with only CAP_NET_RAW can still read (a file that root owns and that has an owner read bit, such as /etc/shadow), and why it cannot write (ProtectSystem=strict is read-only at the mount, with no ReadWritePaths). The page now says only that the dynamic user was refused.

The ping of connectivity is an ICMP datagram socket in the agent, not a
root call. Only a RootEquivalent call may relax NoNewPrivileges. The
unit of a call that is not RootEquivalent hides the secrets of the host,
except where SELinux refuses the mount; the openSUSE gap stays open.
The RestrictAddressFamilies row now matches systemd.go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head b77b545). Checked: b77b545 is a fast-forward of a9ba67d with its trailer. just test passes (0 problems). No em dash. least-privilege.md: the RestrictAddressFamilies= row now matches systemd.go (AF_UNIX AF_NETLINK AF_INET AF_INET6), the InaccessiblePaths= row and the NoNewPrivileges= row match the code and the new validate rule at osapi#1943 562fc3c3, and the broker ping text and the CAP_NET_RAW row are gone. built-in-behaviors.md: the connectivity text describes the ICMP datagram socket through h.ListenICMP, and links the reason instead of copying it.

Note, not blocking: "This gap stays open." about /etc/shadow on openSUSE links no issue. CONSTITUTION.md, Tracking: link the issue that keeps it.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at b77b545 against osapi#1943 at 562fc3c368. The page matches the code on the ping in the agent (h.ListenICMP, no broker, the fake host answers loopback only), the refusal of a NoNewPrivileges relax on a call that is not RootEquivalent, InaccessiblePaths= for each such call, the shadow_t skip, and the uid 0 read note. One addition, not blocking: the four paths are a list, so say that other root-owned files with an owner read bit (such as /etc/ssl/private) stay readable by uid 0 in those units.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head 7bb6586). Checked: one commit on b77b545, a fast-forward with its trailer. least-privilege.md now links osapi-io/osapi#1960 for the openSUSE shadow gap (CONSTITUTION.md, Tracking). just test passes (0 problems). No em dash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head 53d95b2). Checked: one commit on 7bb6586, fast-forward with its trailer. The same read-gap sentence in components/osapi/least-privilege.md as osapi#1943 at 0e2b729a, with the link to osapi#1960. just test passes (0 problems). No em dash.

Ubuntu keeps the kernel default of net.ipv4.ping_group_range, which holds no group. osapi agent service install widens the range to hold the gid of osapi, and uninstall puts it back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head 43126b1). Checked: one commit on 53d95b2, fast-forward with its trailer. The ping paragraph of least-privilege.md and the sentence in built-in-behaviors.md agree with agentservice/ping.go at osapi#1943 508ef96e: the file /etc/sysctl.d/60-osapi-ping.conf, the smallest range that holds the gid, sysctl -p at install, and sysctl -w then sysctl --system at uninstall. just test passes (0 problems). No em dash.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at 43126b1. The ping_group_range text in least-privilege.md and built-in-behaviors.md matches osapi#1943 at 508ef96e7e: the install file, the smallest range, "# Before:", sysctl -p, never smaller, and the uninstall steps (remove file, sysctl -w, sysctl --system).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head 303b9df). Checked: one commit on 43126b1, fast-forward with its trailer. The uninstall paragraph of least-privilege.md agrees with osapi#1943 at 975d87d4: only sysctl -w, no sysctl --system, and the error at the end after the units are removed. just test passes (0 problems). No em dash.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at 303b9df. The uninstall text (sysctl -w only, no sysctl --system, units still removed on failure, error returned at the end) matches osapi#1943 at 975d87d43c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head 7402335). Checked: one commit on 303b9df, a fast-forward with its trailer. The sentence in least-privilege.md about the SIGKILL fallback and an ended unit agrees with StopUnit at osapi#1943 764f368b. just test passes (0 problems). No em dash.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at 7402335. The SIGKILL fallback and ended-unit sentence in least-privilege.md matches StopUnit in osapi#1943 at 764f368ba3 (stop exit 5 and a kill that says "not loaded" count as stopped).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head 79080af). Checked: one commit on 7402335, a fast-forward with its trailer. The .As(user) paragraph of least-privilege.md agrees with osapi#1943 at 69724bd7: User= with no capability, the chronyc call as _chrony with .Writes("/run/chrony/*"), and the validate refusals of .As on macOS and .As("root"). just test passes (0 problems). No em dash.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at 79080af. The paragraph on .As(user) matches osapi#1943 at 69724bd747 (User=, no capability, validate refuses As("root") and As on a macOS call, chronyc as _chrony with Writes("/run/chrony/*")).

@retr0h
retr0h merged commit 41485eb into main Dec 6, 2026
4 checks passed
@retr0h
retr0h deleted the docs/osapi-privilege-commands branch December 6, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-reviewed An independent reviewer checked correctness, bugs and edge cases kind/yaml standards-reviewed An independent reviewer checked this PR against the standards

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant