servicePath omits /run/wrappers/bin and NoNewPrivileges=true blocks sudo; add an enableSudo option #1

Closed
opened 2026-11-16 16:59:45 -06:00 by OpenWebUI · 1 comment
Member

Problem

servicePath (the module's Environment=PATH= entry) never contains /run/wrappers/bin, and the unit hardcodes NoNewPrivileges = true. On NixOS hosts where the terminal must run sudo/su/ping, bare sudo resolves the non-setuid store symlink and fails with "must be owned by uid 0 and have the setuid bit set".

Login shells appear to work (NixOS patches bash to source /etc/bashrc, which prepends /run/wrappers/bin), but non-login shells - i.e. what POST /execute runs (bash flags hBc) - do not. That asymmetry makes the bug look like an auth problem.

Workarounds today need an overlay that fights the module's private let: servicePath is not exported, so overriding Environment=PATH means duplicating the whole toolchain list, which rots on every upstream bump.

Proposal

Add services.open-terminal.enableSudo (default false):

systemd.services.open-terminal.serviceConfig = lib.mkIf cfg.enableSudo {
  NoNewPrivileges = false;
  PathPrepend = "/run/wrappers/bin";
};

PathPrepend matters: PATH is first-match, and /run/current-system/sw/bin is already on the service PATH, so PathAppend leaves the broken symlink first and the fix is silently dead.

Option docs should warn that this grants root to anyone who can reach the API as that user, and that it does not by itself enable passwordless sudo (the host still needs security.sudo.wheelNeedsPassword / sudoers).

Context

Discovered while enabling sudo on nix-dev (RandomRepair/nixos-config 4e303e1, ac82268).

## Problem `servicePath` (the module's `Environment=PATH=` entry) never contains `/run/wrappers/bin`, and the unit hardcodes `NoNewPrivileges = true`. On NixOS hosts where the terminal must run `sudo`/`su`/`ping`, bare `sudo` resolves the non-setuid store symlink and fails with "must be owned by uid 0 and have the setuid bit set". Login shells appear to work (NixOS patches bash to source `/etc/bashrc`, which prepends `/run/wrappers/bin`), but non-login shells - i.e. what `POST /execute` runs (bash flags `hBc`) - do not. That asymmetry makes the bug look like an auth problem. Workarounds today need an overlay that fights the module's private `let`: `servicePath` is not exported, so overriding `Environment=PATH` means duplicating the whole toolchain list, which rots on every upstream bump. ## Proposal Add `services.open-terminal.enableSudo` (default `false`): ```nix systemd.services.open-terminal.serviceConfig = lib.mkIf cfg.enableSudo { NoNewPrivileges = false; PathPrepend = "/run/wrappers/bin"; }; ``` `PathPrepend` matters: PATH is first-match, and `/run/current-system/sw/bin` is already on the service PATH, so `PathAppend` leaves the broken symlink first and the fix is silently dead. Option docs should warn that this grants root to anyone who can reach the API as that user, and that it does not by itself enable passwordless sudo (the host still needs `security.sudo.wheelNeedsPassword` / sudoers). ## Context Discovered while enabling sudo on nix-dev (RandomRepair/nixos-config `4e303e1`, `ac82268`).
Author
Member

Fixed in 9f458ff on main: new services.open-terminal.enableSudo (bool, default false).

When true the emitted unit gets NoNewPrivileges=false plus PathPrepend=/run/wrappers/bin via serviceConfig. Prepended, not appended: /run/current-system/sw/bin/sudo is a plain non-setuid store symlink and PATH is first-match. ExtraEnv was ruled out -- the generated unit emits a literal ignored ExtraEnv= line, and the unit sets PATH twice (a quoted nixpkgs default line and the module toolchain line), so parsing them can pick the default one.

Verified by evaluating the pinned example config: default arm is byte-identical to before (still NoNewPrivileges=true, no PathPrepend); enableSudo=true yields both lines. README option table updated.

Downstream RandomRepair/nixos-config#1 now sets enableSudo = true and keeps only the ProtectSystem = mkForce "off" host override; generated unit diff against the deployed one was empty, so no behavior change on nix-dev. The api.key 0700/root-owner tradeoff is tracked separately as RandomRepair/nixos-config#3 and stays open there; this issue covers only the module option.

Fixed in 9f458ff on main: new `services.open-terminal.enableSudo` (bool, default false). When true the emitted unit gets `NoNewPrivileges=false` plus `PathPrepend=/run/wrappers/bin` via `serviceConfig`. Prepended, not appended: `/run/current-system/sw/bin/sudo` is a plain non-setuid store symlink and PATH is first-match. `ExtraEnv` was ruled out -- the generated unit emits a literal ignored `ExtraEnv=` line, and the unit sets PATH twice (a quoted nixpkgs default line and the module toolchain line), so parsing them can pick the default one. Verified by evaluating the pinned example config: default arm is byte-identical to before (still `NoNewPrivileges=true`, no `PathPrepend`); `enableSudo=true` yields both lines. README option table updated. Downstream RandomRepair/nixos-config#1 now sets `enableSudo = true` and keeps only the `ProtectSystem = mkForce "off"` host override; generated unit diff against the deployed one was empty, so no behavior change on nix-dev. The api.key 0700/root-owner tradeoff is tracked separately as RandomRepair/nixos-config#3 and stays open there; this issue covers only the module option.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Public/open-terminal-flake#1
No description provided.