2026-01-01 01:36:58 -05:00
|
|
|
{ pkgs, inputs, config, keys, ... }: {
|
2026-04-04 04:57:47 -04:00
|
|
|
users.users.ai-worker = {
|
2026-01-01 01:36:58 -05:00
|
|
|
isSystemUser = true;
|
2026-04-04 04:57:47 -04:00
|
|
|
group = "ai-worker";
|
2026-04-04 17:07:13 -04:00
|
|
|
home = "/home/ai-worker";
|
|
|
|
|
createHome = true;
|
fix: restrict docker commands for ai-worker (wrapper blacklist)
SECURITY CHANGE: Keep ai-worker in docker group but block dangerous
docker subcommands via a wrapper script.
Approach:
- docker group membership preserved (ps, start, stop, compose still work)
- Docker binary wrapped with a script that blocks dangerous subcommands
- BLOCKED: exec, cp, commit, diff, export, import, load, save, attach, push, tag
- ALLOWED: ps, images, inspect, logs, start, stop, restart, rm, rmi,
pull, build, run, compose, system, network ls, volume ls
The wrapper is installed in both system packages and ai-worker's
personal profile to ensure it takes precedence over the real docker.
This is effective for the LLM agent threat model — the agent uses CLI
commands and blocked subcommands simply return an error.
Files modified:
- users/ai-worker.nix — restored docker group, kept sudo audit rules
- modules/nixos/security/ai-worker-restricted.nix — added docker wrapper
script with blacklist logic and NixOS module integration
- modules/nixos/security/README-ai-worker.md — documentation update
2026-05-20 20:34:19 -04:00
|
|
|
# ai-worker stays in docker group for normal docker operations (ps, start, stop, compose, ...)
|
|
|
|
|
# Dangerous commands (exec, cp, commit) are blocked by a wrapper script.
|
2026-01-01 01:36:58 -05:00
|
|
|
extraGroups = [ "docker" ];
|
|
|
|
|
shell = pkgs.bashInteractive;
|
|
|
|
|
openssh.authorizedKeys.keys = [
|
2026-04-04 04:57:47 -04:00
|
|
|
keys.users.ai-worker.main
|
2026-01-01 01:36:58 -05:00
|
|
|
];
|
2026-04-28 15:34:38 +00:00
|
|
|
# No password login - SSH key only
|
|
|
|
|
hashedPassword = "!";
|
2026-01-01 01:36:58 -05:00
|
|
|
};
|
2026-04-04 04:57:47 -04:00
|
|
|
users.groups.ai-worker = {};
|
2026-04-28 15:34:38 +00:00
|
|
|
|
fix: restrict docker commands for ai-worker (wrapper blacklist)
SECURITY CHANGE: Keep ai-worker in docker group but block dangerous
docker subcommands via a wrapper script.
Approach:
- docker group membership preserved (ps, start, stop, compose still work)
- Docker binary wrapped with a script that blocks dangerous subcommands
- BLOCKED: exec, cp, commit, diff, export, import, load, save, attach, push, tag
- ALLOWED: ps, images, inspect, logs, start, stop, restart, rm, rmi,
pull, build, run, compose, system, network ls, volume ls
The wrapper is installed in both system packages and ai-worker's
personal profile to ensure it takes precedence over the real docker.
This is effective for the LLM agent threat model — the agent uses CLI
commands and blocked subcommands simply return an error.
Files modified:
- users/ai-worker.nix — restored docker group, kept sudo audit rules
- modules/nixos/security/ai-worker-restricted.nix — added docker wrapper
script with blacklist logic and NixOS module integration
- modules/nixos/security/README-ai-worker.md — documentation update
2026-05-20 20:34:19 -04:00
|
|
|
# Enable restricted AI worker SSH access
|
|
|
|
|
# SECURITY: ai-worker is in docker group but docker commands are filtered:
|
|
|
|
|
# ALLOWED: ps, images, logs, start, stop, restart, rm, rmi, pull, build, run, compose
|
|
|
|
|
# BLOCKED: exec, cp, commit, diff, export, import, load, save, attach, push
|
|
|
|
|
# The filtering is done by a docker wrapper in ai-worker's PATH.
|
2026-04-28 15:34:38 +00:00
|
|
|
services.aiWorkerAccess = true;
|
fix: restrict docker commands for ai-worker (wrapper blacklist)
SECURITY CHANGE: Keep ai-worker in docker group but block dangerous
docker subcommands via a wrapper script.
Approach:
- docker group membership preserved (ps, start, stop, compose still work)
- Docker binary wrapped with a script that blocks dangerous subcommands
- BLOCKED: exec, cp, commit, diff, export, import, load, save, attach, push, tag
- ALLOWED: ps, images, inspect, logs, start, stop, restart, rm, rmi,
pull, build, run, compose, system, network ls, volume ls
The wrapper is installed in both system packages and ai-worker's
personal profile to ensure it takes precedence over the real docker.
This is effective for the LLM agent threat model — the agent uses CLI
commands and blocked subcommands simply return an error.
Files modified:
- users/ai-worker.nix — restored docker group, kept sudo audit rules
- modules/nixos/security/ai-worker-restricted.nix — added docker wrapper
script with blacklist logic and NixOS module integration
- modules/nixos/security/README-ai-worker.md — documentation update
2026-05-20 20:34:19 -04:00
|
|
|
|
|
|
|
|
# Restricted sudo for ai-worker - security checks only (not for docker)
|
2026-04-30 17:33:05 +00:00
|
|
|
security.sudo.extraRules = [
|
|
|
|
|
{
|
|
|
|
|
users = [ "ai-worker" ];
|
|
|
|
|
commands = [
|
2026-04-30 17:36:13 +00:00
|
|
|
# Firewall checks
|
2026-04-30 17:33:05 +00:00
|
|
|
{
|
|
|
|
|
command = "/run/wrappers/bin/sudo iptables -L -n -v";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
command = "/run/wrappers/bin/sudo iptables -S";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
2026-04-30 17:36:13 +00:00
|
|
|
# Fail2ban status
|
2026-04-30 17:33:05 +00:00
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/fail2ban-client status";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/fail2ban-client status *";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/fail2ban-client get * banned";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
2026-04-30 17:36:13 +00:00
|
|
|
# Log inspection
|
2026-04-30 17:33:05 +00:00
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/journalctl -t kernel -n 100";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/journalctl -u fail2ban -n 50";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
2026-04-30 17:36:13 +00:00
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/journalctl -u firewall -n 50";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
# SSH config verification
|
2026-04-30 17:33:05 +00:00
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/sshd -T";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
# Network diagnostics
|
|
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/ss -tlnp";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/cat /proc/net/tcp";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
];
|
2026-01-01 02:25:34 -05:00
|
|
|
}
|