Skip to content

feat(lab): unprivileged VM agents via the broker - #117

Merged
retr0h merged 6 commits into
mainfrom
feat/lab-least-privilege
Dec 6, 2026
Merged

retr0h merged 6 commits into
mainfrom
feat/lab-least-privilege

Conversation

@retr0h

@retr0h retr0h commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Each VM agent of the lab now runs as osapi, as osapi-io/osapi#1907 installs it, with no sudo rule. The agent gets root only through the root broker.

  • lab_agent runs osapi agent service install --join <join> --privileged <each behavior> --force. It runs on each bump, and on each VM that a deploy clones (new group vms_install). Then it puts the lab's agent config back, owned by osapi, and restarts the agent.
  • A VM that upgrades in place (debian-lts) moves its keys from the old /etc/osapi/pki/agent into the install's key directory. It fixes the creds path in the join record, and gives osapi the state that a root agent made.
  • packer bakes no agent unit, no rescue units and no ping range file. The install writes the units on each host.
  • The firewall and the sudo rule of the lab's admin operator do not change. The owner approved the change of the VM agents in this session.

Lab: just deploy and just bump with the #1943 build passed on the five VMs, and each agent came back Ready as osapi. just int found failures in osapi, not in this change. #1943 fixes them, and the session runs again.

Specs: osapi-io/specs#756 (the lab page section "Each component as its own user")

Part of #115 (the VM part). The hub part is #116, blocked by osapi-io/osapi#1945.

Merge after osapi-io/osapi#1943.

🤖 Generated with Claude Code

@retr0h retr0h added needs-standards-review The author asks for the independent standards review needs-code-review The author asks for the independent code review labels Dec 6, 2026
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review at 8ed6faa. Changes requested.

What meets the rules:

  • The change removes the baked units and adds no copy of them. The units come from osapi agent service install, so they have one source, RescueFiles and the unit of the agent in osapi.
  • The join string goes to the install with no_log: true.
  • Part of #115 is correct, because lab_least_privilege: NATS and the controller as their own users #116, the hub part, is open and blocked by osapi#1945. The description says to merge after osapi#1943.
  • No stale reference to the baked units, the ping range file or /etc/osapi/pki/agent is left outside lab_agent. The packer comment about docker now says why no user joins the docker group.
  • There is no em dash. The commit has its trailer, and the branch is on the current origin/main.

Open:

  1. The commit subject has 52 characters. "feat(lab): unprivileged VM agents through the broker". The PR has one commit, so the squash uses this subject, not the PR title, which has 48. Shorten it to 50 or fewer, for example to the PR title.

  2. The lab page does not describe this change. The description gives Specs: https://github.com/osapi-io/specs/pull/756, but components/osapi-lab/README.md at specs#756 (442d538) says what the lab does before this PR, and a design that this PR does not build:

    • Lines 36 to 43, 280 to 285 and 587 say that the image bakes the three rescue units, and that lab_agent installs them from the files of packer/ and enables the boot unit. This PR deletes those files and tasks.
    • "Each component as its own user" says that a flag, lab_least_privilege in group_vars/all.yml, chooses the mode, that false keeps the agent as root, and that just bump refuses a change of the flag. This PR has no flag: each VM agent runs as osapi. That agrees with AGENTS.md, "Do not keep backward compatibility", so the page is the part to change.
    • "On each VM" says that the image creates the osapi user and osapi-admin, and adds the lab's login user to osapi-admin before the image is saved. In this PR the image makes neither. lab_agent installs on each run, and nothing adds the login user to osapi-admin.
    • The page does not have the vms_install group, or the move of the keys of debian-lts from /etc/osapi/pki/agent.

    specs#756 is correct for the lab of main, so the fix goes in a specs PR for this change, or in specs#756 before it merges. Change the lab page to what this PR does. Keep "Build now" only for what is still to do in lab_least_privilege: unprivileged VM agents through the broker #115 and lab_least_privilege: NATS and the controller as their own users #116, such as the refusal probes as osapi and the login user in osapi-admin. Then put that PR in Specs:, and link back from it.

Notes that do not block:

  • The move of the keys of debian-lts runs at each install. It does nothing after the first run, because /etc/osapi/pki/agent is gone. When debian-lts is rebuilt, the step can go.
  • Give the agent's state to osapi has changed_when: true, so each install reports a change. A test of the old directory in changed_when would show when it moved something.
  • The owner's approval of the change of the VM agents is in the description. I cannot see it, so the team lead confirms it.

The label stays needs-standards-review.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at 8ed6faa, for use with osapi#1943 (the --privileged flag, --force and the agent.pki.key_dir default of /var/lib/osapi/pki are in that branch). I read the full diff against main and built osapi at 08d127ba17 to check what the role calls: osapi dsl behavior list --json prints items[].name (35 names), and agent service install has --join, --privileged (a string slice), --force and --json. I did not run the playbook or a VM.

Security, as asked:

  • Key dir and state modes. The shell step ends with chown -R osapi:osapi /var/lib/osapi, chgrp -R osapi-admin on the key dir and chmod 2750. That is the install's own result (state 0711 for osapi, key dir 2750 with group osapi-admin). chown -R and chgrp -R do not follow links by default. The old key dir is removed after the copy.
  • Creds path. The sed rewrites the old /etc/osapi/pki/agent/ path in nats-join.json to the new key dir, and the config comes back with mode 0600 and owner osapi, as the install writes it.
  • No root left in the agent. The image no longer bakes osapi-agent.service, the rescue units or the ping range; the install writes them, so the agent unit is the sandboxed one of #1943. The only drop-in left is IGNORE_LINUX=1 on Fedora and openSUSE, which sets no user or sandbox option.
  • Firewall and sudo. The diff touches neither.

Not blocking:

  1. The join string is on the command line of osapi agent service install for a moment, so another user on the VM can read it in ps. no_log hides it from the Ansible output only. It is a lab VM, so I did not ask for a change; a file or an environment variable would avoid it.
  2. The slurp and copy of the lab config have no no_log, and the config holds the join string. -v prints the slurp result. Add no_log: true to both for the same reason as the install.
  3. The install enables each behavior, root-equivalent ones included, so the lab agent can reach root through the broker for each of them. The comment says this is on purpose (the lab tests each one as CI does); I mention it only so that nobody takes the lab agent for a least-privilege sample.

@retr0h retr0h added code-reviewed An independent reviewer checked correctness, bugs and edge cases and removed needs-code-review The author asks for the independent code review 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 re-review at 35ebb9f. Approved.

  1. Commit subject. It now has 48 characters, the same as the PR title, and it has its trailer.
  2. Lab page. The page at specs#756 (3ec5817) now describes this change:
    • the image bakes no unit of osapi;
    • the steps of lab_agent, with the move of the keys of debian-lts;
    • the vms_install group;
    • no flag and no root agent.
      specs#756 links back here, and Specs: points to it.

The read of the lab's config and the write that puts it back are now no_log: true, as the install is. Thus the join string is in no task output.

The branch is on the current origin/main. No em dash. Merge after specs#756 and osapi#1943, as the description says.

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 6, 2026
The agent's state directory is /var/lib/osapi/agent, and root owns
/var/lib/osapi. A VM that upgrades in place moves its keys and its
pending changes there, from /etc/osapi/pki/agent or /var/lib/osapi, and
the join record names the new creds path.

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

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: changes requested (head 7404efb). There is 1 finding.

  1. .lab, a new symlink to ../../.lab, in commit 7404efb. CONTRIBUTING.md:260: "Do not commit a file under .lab/ or ansible/inventory.yml." .gitignore has .lab/, which matches only a directory, so the link was not ignored. The link points outside the repository, to the .lab of a worktree. Fix: remove .lab from the commit. Adding .lab to .gitignore, next to .lab/, would stop it the next time.

Checked, with no finding:

  • The move to /var/lib/osapi/agent.
    • It moves the keys of a root agent and of an earlier osapi agent, and the pending changes.
    • It skips a link.
    • It writes the new path of the creds file in the join record.
    • It gives osapi only the state directory, and root keeps /var/lib/osapi.
    • It agrees with osapi#1943 at 07a583dc and with the lab page at specs#756 (README.md:400-408).
  • Commits. The PR has two commits, so the squash uses the PR title, which has 48 characters. Each commit has its trailer. The branch is on the current origin/main. No em dash.

@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
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: changes requested at 7404efb.

Required

  1. .lab is committed as a symlink (120000, target ../../.lab). git diff 35ebb9fdc1 7404efb269 --summary shows create mode 120000 .lab. It is the link of a worktree to the lab state of the main checkout, so on any other checkout it is a dangling link, and a later .lab/ directory cannot be made over it. It got in because a .lab/ entry in .gitignore matches a directory and not a link. Remove the file from the commit (git rm --cached .lab), and make the ignore entry .lab with no slash so that it covers the link.

The rest of the diff is clean: the move of the keys and of pending to /var/lib/osapi/agent copies with cp -a (links stay links), skips a link at the old path, rewrites the old key directories in nats-join.json, and ends with chown -R osapi:osapi, chgrp -R osapi-admin on the key directory and mode 2750, which is what the install makes. I did not run the playbook.

@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 6, 2026
retr0h and others added 2 commits December 5, 2026 19:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at 53dd3b8. .lab is gone from the diff against main (no create mode 120000), and .gitignore now has .lab with no slash, so it covers the link. The rest is as reviewed at 7404efb.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Standards review: approved (head 53dd3b8). Checked: the finding from my last review is fixed. .lab is not in the tree. .gitignore now has .lab in place of .lab/, so a link named .lab is ignored too. That follows CONTRIBUTING.md:260. The rest is the same as at 7404efb. The PR has four commits, so the squash uses the PR title, which has 48 characters. Each commit has its trailer. The branch is on the current origin/main. No em dash.

@retr0h retr0h added standards-reviewed An independent reviewer checked this PR against the standards code-reviewed An independent reviewer checked correctness, bugs and edge cases and removed needs-standards-review The author asks for the independent standards review needs-code-review The author asks for the independent code review 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 939cd9b). Checked: one commit on 53dd3b8, a fast-forward with its trailer, and a subject of 50 characters or fewer. The comment in ansible/roles/lab_agent/tasks/main.yml now agrees with osapi#1943 at 0bd6a963: the agent pings on an ICMP datagram socket and the systemd default range covers its group. 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 6339ca5). Checked: one commit on 939cd9b, fast-forward with its trailer. The comment in ansible/roles/lab_agent/tasks/main.yml now agrees with osapi#1943 at 975d87d4 and specs#756: install widens the range, and Ubuntu keeps the kernel default. No em dash.

@retr0h

retr0h commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Code review: clean at 6339ca5. The delta from 939cd9b is a comment in ansible/roles/lab_agent/tasks/main.yml only.

@retr0h
retr0h merged commit 51c3776 into main Dec 6, 2026
6 checks passed
@retr0h
retr0h deleted the feat/lab-least-privilege branch December 6, 2026 07:08
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/ansible kind/image 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