Skip to content

Add sudoCopy: copy the closure as root through sudo - #414

Open
FlorianFranzen wants to merge 1 commit into
serokell:masterfrom
FlorianFranzen:sudo-copy
Open

FlorianFranzen wants to merge 1 commit into
serokell:masterfrom
FlorianFranzen:sudo-copy

Conversation

@FlorianFranzen

@FlorianFranzen FlorianFranzen commented Oct 29, 2026 •

Copy link
Copy Markdown

Problem

Deploying as an sshUser other than root fails with "cannot add path ... because
it lacks a signature by a trusted key" unless that user is in the target's
nix.settings.trusted-users (#280, #293). A trusted user can add arbitrary paths
to the store, so that workaround makes the deploy user root-equivalent through
the Nix daemon, even on hosts where root login is off and sudo is the intended
way up.

Solution

A new setting, sudoCopy (and --sudo-copy), wherever interactiveSudo can be
set. When it is on and sshUser is not root, the closure is copied with

nix copy --to 'ssh://<sshUser>@<host>?remote-program=sudo%20-u%20root%20nix-store'

so nix-store --serve --write runs as root on the target and imports the paths
itself; the daemon's trusted users stay as they are. The prefix is the node's
sudo setting, so doas -u and the like work too.

Sudo has to succeed without a password (NOPASSWD, or e.g. pam_rssh against a
forwarded agent): the copy protocol runs over the connection's standard input.
sudoCopy with interactiveSudo is therefore an error rather than a hang.

Tests

  • New VM test sudo-copy: a pusher user with sudo but not trusted by the
    daemon. Without sudoCopy the deploy fails on the signature check; with
    interactiveSudo it is refused; with sudoCopy it succeeds, and sudo's
    journal shows nix-store --serve --write run as root.
  • Unit tests for the store URL and its percent-encoding, and for when the copy goes through sudo.

Related

#334 (--remote-bin-path) also sets remote-program on the copy. The two
compose (sudo -u root <remote-bin-path>/nix-store); whichever lands second can
build on the other's helper, and I am happy to rebase.

Problem: an sshUser other than root can only copy unsigned paths if the
target's Nix daemon trusts it, which makes it root-equivalent.

Solution: with `sudoCopy`, `nix copy` runs the target's `nix-store`
through the node's sudo command, so root imports the paths.
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