Skip to content

feat(amd): add a polkit-gated rebuild unit alongside the sudo rule - #11970

Merged
dezren39 merged 3 commits into
mainfrom
claude/amd-agent-rebuild-polkit
Nov 19, 2026
Merged

dezren39 merged 3 commits into
mainfrom
claude/amd-agent-rebuild-polkit

Conversation

@dezren39

@dezren39 dezren39 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Before: the only passwordless rebuild path for agents on amd is sudo agent-rebuild-switch (#11959), which needs sudo unblocked in Desktop Commander. The wrapper also passes the token from /home/user/auth to nix, and that token now gets 401 Bad credentials from GitHub, so every fetch would fail.

After: agents can use either path, both running the same no-argument wrapper (switch to github:developing-today/code/main#amd):

The wrapper now checks the token first and fetches without it when GitHub rejects it.

How

  • systemd.services.agent-rebuild-switch: oneshot, runs the wrapper as root with WorkingDirectory=/ and systemd's clean environment. restartIfChanged/stopIfChanged are off so the switch it runs never stops the unit.
  • security.polkit.extraConfig: allows org.freedesktop.systemd1.manage-units only when the unit is agent-rebuild-switch.service, the verb is start, and the subject is user.
  • Token check: one request to api.github.com/rate_limit with the token, the header passed on stdin so the token never appears in ps. On 401 it logs that and continues without the token.
  • Follow a service run with journalctl -u agent-rebuild-switch -f.

Checks

  • Standalone module eval against current nixos-unstable: the sudoers rule is unchanged, the polkit rule renders, the unit and wrapper build (shellcheck passes).
  • On the laptop: the token in /home/user/auth returns 401 and no token returns 200; a dummy token sent via -H @- returns 401, so the check detects it.
  • nixfmt --check and statix check pass.

Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • System rebuilds can now be started either with the existing command or through a dedicated system service.
    • The service can be started by the designated account without requiring sudo.
  • Bug Fixes
    • Invalid GitHub tokens are detected before use. If a token is rejected, the rebuild continues without it.
    • The rebuild command’s guidance now explains the service option for users who cannot run it with sudo.

Replace the NOPASSWD sudo rule with agent-rebuild-switch.service and a
polkit rule that lets user start only that unit. Agents run
systemctl start --no-block agent-rebuild-switch.service, so sudo can
stay blocked in Desktop Commander. The unit runs the same no-argument
wrapper (switch to main#amd) from / with a fixed environment.

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

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The wrapper now checks valid tokens against GitHub’s rate-limit endpoint and continues without token configuration when GitHub returns 401. The host configuration adds a polkit-authorized systemd service that runs the wrapper as another entry point.

Changes: Agent rebuild access and token handling

Layer / File(s) Summary
Wrapper and token checks
nixos/hosts/amd-agent-rebuild.nix
The wrapper adds curl and checks valid tokens against GitHub’s rate-limit endpoint with a 15-second timeout. If GitHub returns 401, it logs a warning and continues without token configuration.
Systemd service and authorization
nixos/hosts/amd-agent-rebuild.nix, nixos/hosts/default.nix
A oneshot service runs the wrapper from / with HOME=/root. A polkit rule allows user to start that service. Comments document the service as an alternative entry point.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Polkit
  participant Systemd as agent-rebuild-switch.service
  participant Wrapper as agent-rebuild-switch
  participant GitHub as GitHub rate-limit endpoint
  User->>Polkit: Request to start the service
  Polkit->>Systemd: Authorize start for user
  Systemd->>Wrapper: Run wrapper from / with HOME=/root
  Wrapper->>GitHub: Check token with Authorization header
  GitHub-->>Wrapper: Return HTTP status
Loading

Possibly related PRs

  • developing-today/code#11959: Adds the no-argument wrapper and sudoers rule that this change retains and extends with a systemd service.

Suggested reviewers: claude

Merge Risk: Minimal · up to cc9a0

This change adds a polkit-authorized systemd service as a second way to run the existing agent rebuild wrapper, and it falls back to unauthenticated fetches when GitHub rejects the stored token. No concrete merge-blocking risk was identified. The host-level service run has not been exercised end to end.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a new polkit-gated systemd rebuild unit added next to the existing sudo rule for the AMD host. The raw summary and objectives both describe this unit and polkit rule a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a new polkit-gated systemd rebuild unit added next to the existing sudo rule for the AMD host. The raw summary and objectives both describe this unit and polkit rule as the central addition, and the sudo rule is kept as described. The title uses a conventional type(scope) prefix and fits within a readable length. It omits the token check and the wrapper changes, which is acceptable because the title need not cover every detail.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3994c59c-1289-4eeb-b503-3a7043383974
Commits

Reviewing files that changed from the base of the PR and between a6c87bb and cc9a035.

Files selected for processing: 2

  • nixos/hosts/amd-agent-rebuild.nix
  • nixos/hosts/default.nix

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Drew asked to allow both for now: restore the NOPASSWD rule for
sudo agent-rebuild-switch (no arguments) next to the
agent-rebuild-switch.service polkit path. Both run the same wrapper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dezren39 dezren39 changed the title feat(amd): trigger agent rebuilds via a polkit-gated unit, not sudo feat(amd): add a polkit-gated rebuild unit alongside the sudo rule Nov 19, 2026
The token in /home/user/auth now gets 401 Bad credentials from GitHub,
which fails every flake fetch, public inputs included. Check it first
(header on stdin, never in argv) and fetch without it when rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dezren39
dezren39 marked this pull request as ready for review November 19, 2026 00:10
@dezren39
dezren39 requested a review from a team as a code owner November 19, 2026 00:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T00:13:04.265174Z cc9a035 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit eaacc9f into main Nov 19, 2026
1 check passed
@dezren39
dezren39 deleted the claude/amd-agent-rebuild-polkit branch November 19, 2026 00:16
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.

2 participants