feat(colmena): passwordless activation via sudoers rules scoped to colmena's exact commands
Colmena connects with BatchMode=yes and no TTY (src/nix/host/ssh.rs),
so a sudo password prompt can never be answered - non-root deploys
REQUIRE NOPASSWD. New extraServices.colmenaDeploy (enabled on all
five hosts) grants m3tam3re passwordless sudo for exactly the two
invocations colmena performs (verified against colmena 0.5/0.6
profile.rs + host/{ssh,local}.rs, default NixFlags are empty):
- /run/current-system/sw/bin/nix-env --profile /nix/var/nix/profiles/system --set /nix/store/*
(system profile switch, goals switch/boot)
- /nix/store/*/bin/switch-to-configuration <boot|switch|test|dry-activate>
(activation, exact single argument)
Everything else keeps requiring the sudo password; extraRules sort
after the wheel rules, so last-match-wins keeps the exception scoped.
Also enables passwordless 'colmena apply-local' on the desktops, which
uses the same activation path.
Residual risk (documented in the module): anyone holding the deploy
user's SSH key can activate arbitrary store closures - that is the
deploy capability itself, inherent to NixOS remote activation.
One-time bootstrap per server (rules arrive WITH a deploy, and the
first deploy cannot answer a password prompt):
nixos-rebuild switch --flake .#m3-atlas --target-host m3tam3re@m3-atlas --use-remote-sudo
This commit is contained in:
1 parent
db0bfbc707
commit
0576b3c60b
9 files changed
+67
-2
No files matched your search
@@ -0,0 +1,58 @@
|
||||
# Passwordless privilege escalation for Colmena deployments, scoped to
|
||||
# exactly the two commands colmena executes on a non-root target host
|
||||
# (colmena src/nix/host/ssh.rs + profile.rs, verified for 0.5/0.6):
|
||||
#
|
||||
# sudo -H -- nix-env --profile /nix/var/nix/profiles/system --set /nix/store/<toplevel>
|
||||
# sudo -H -- /nix/store/<toplevel>/bin/switch-to-configuration <switch|boot|test|dry-activate>
|
||||
#
|
||||
# Colmena connects with BatchMode=yes and without a TTY, so a sudo
|
||||
# password prompt can never be answered — non-root deploys REQUIRE
|
||||
# NOPASSWD for these two invocations. Everything else the user runs via
|
||||
# sudo still asks for a password: the exception covers only these exact
|
||||
# command shapes.
|
||||
#
|
||||
# Residual risk (inherent to any NixOS remote activation): whoever can
|
||||
# run these commands can activate any closure present in the store as
|
||||
# the new system. That is the deploy capability itself, not an
|
||||
# unintended side effect.
|
||||
#
|
||||
# NOTE: if colmena is invoked with extra nix flags (e.g. --show-trace,
|
||||
# --option cores N) the nix-env argv grows trailing flags and no longer
|
||||
# matches the pinned rule — plain `colmena apply` is what this covers.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
deployUser = "m3tam3re";
|
||||
in
|
||||
with lib; {
|
||||
options.extraServices.colmenaDeploy.enable =
|
||||
mkEnableOption "passwordless colmena deployment (sudo NOPASSWD scoped to the system profile switch and switch-to-configuration activation only)";
|
||||
|
||||
config = mkIf config.extraServices.colmenaDeploy.enable {
|
||||
security.sudo.extraRules = [
|
||||
{
|
||||
users = [deployUser];
|
||||
commands =
|
||||
# Activate a store closure. Only the four goals colmena
|
||||
# passes, as the sole argument, are allowed.
|
||||
map (goal: {
|
||||
command = "/nix/store/*/bin/switch-to-configuration ${goal}";
|
||||
options = ["NOPASSWD"];
|
||||
}) ["boot" "switch" "test" "dry-activate"]
|
||||
++ [
|
||||
{
|
||||
# Make a store closure the system profile (goals
|
||||
# switch/boot). Over SSH "nix-env" deterministically
|
||||
# resolves to /run/current-system/sw/bin/nix-env — it
|
||||
# only ships in the system closure — which is the path
|
||||
# sudo matches here.
|
||||
command = "/run/current-system/sw/bin/nix-env --profile /nix/var/nix/profiles/system --set /nix/store/*";
|
||||
options = ["NOPASSWD"];
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
imports = [
|
||||
./colmena-deploy.nix
|
||||
./flatpak.nix
|
||||
./podman.nix
|
||||
./ollama.nix
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
];
|
||||
|
||||
extraServices = {
|
||||
colmenaDeploy.enable = true;
|
||||
flatpak.enable = true;
|
||||
ollama.enable = false;
|
||||
podman.enable = true;
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
];
|
||||
|
||||
extraServices = {
|
||||
colmenaDeploy.enable = true;
|
||||
flatpak.enable = false;
|
||||
ollama.enable = false;
|
||||
podman.enable = true;
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
];
|
||||
|
||||
extraServices = {
|
||||
colmenaDeploy.enable = true;
|
||||
flatpak.enable = true;
|
||||
ollama.enable = false;
|
||||
podman.enable = true;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
];
|
||||
|
||||
extraServices = {
|
||||
colmenaDeploy.enable = true;
|
||||
flatpak.enable = false;
|
||||
ollama.enable = false;
|
||||
podman.enable = false;
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
];
|
||||
|
||||
extraServices = {
|
||||
colmenaDeploy.enable = true;
|
||||
flatpak.enable = true;
|
||||
ollama.enable = true;
|
||||
podman.enable = true;
|
||||
|
||||
Reference in new issue
Block a user