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;
|
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
|
|
|
|
2026-04-29 19:55:19 +00:00
|
|
|
# Enable restricted AI worker SSH access for ollama benchmarking
|
2026-04-28 15:34:38 +00:00
|
|
|
# SECURITY: ai-worker can only:
|
2026-04-29 19:55:19 +00:00
|
|
|
# - SSH into host from Hermes container
|
|
|
|
|
# - Run docker commands (docker exec ollama ...) via docker group
|
2026-05-03 05:28:39 -04:00
|
|
|
# - Run specific security audit commands
|
2026-04-29 19:55:19 +00:00
|
|
|
# - NO access to infra repo (no bind mount)
|
|
|
|
|
# - NO sudo access (no nh, nixos-rebuild, nixpkgs-fmt, nix)
|
|
|
|
|
# WORKFLOW: SSH from Hermes container, run docker benchmarks, return and save results to /opt/data/ai-optimizer/
|
2026-04-28 15:34:38 +00:00
|
|
|
services.aiWorkerAccess = true;
|
2026-04-30 17:33:05 +00:00
|
|
|
|
2026-04-30 17:36:13 +00:00
|
|
|
# Restricted sudo for ai-worker - security checks only
|
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" ];
|
|
|
|
|
}
|
2026-04-30 17:36:13 +00:00
|
|
|
# Docker service checks
|
2026-04-30 17:33:05 +00:00
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/docker ps";
|
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
command = "/run/current-system/sw/bin/docker inspect *";
|
|
|
|
|
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
|
|
|
}
|