Compare commits
47 Commits
feat/wireg
...
feat/restr
| Author | SHA1 | Date | |
|---|---|---|---|
| 9459839d74 | |||
| 36359de6aa | |||
|
|
10b8565fd6 | ||
|
|
f672696b8e | ||
| 0980dca455 | |||
| 96bc20ab70 | |||
| 670ae4f002 | |||
| f785abfd49 | |||
| 6f44aa7f76 | |||
| 8d40f1691f | |||
|
|
2dd2e64986 | ||
|
|
23fc5e0597 | ||
| 0c9c33d735 | |||
| 0bb6890f1c | |||
| 9d5434425f | |||
| 1fb4320dd1 | |||
| 51e9f47fd4 | |||
| 06b3eb840f | |||
| 28ab52209c | |||
|
|
e6f7f0c263 | ||
|
|
5c136e0765 | ||
|
|
f722af7803 | ||
|
|
c07debf088 | ||
| 6806898f04 | |||
| 96e77c5ef2 | |||
| ff7303cf6a | |||
| 9e42f5d2cc | |||
| 614883f3c3 | |||
| 374d022593 | |||
| 9679846cdb | |||
| 4056f91ec6 | |||
| 1ba7d31d2f | |||
| c7e9f8a1e0 | |||
| bbe1a4a850 | |||
| 2b8316060c | |||
| cc2c62faf7 | |||
| 47f1ba6cf2 | |||
| db89881d75 | |||
| 0bb0a270e6 | |||
| 41256ccbde | |||
| e551f0e5c5 | |||
| b11d599f37 | |||
| 782f2fa9ed | |||
| 2e14069584 | |||
|
|
7d3d072961 | ||
| f0e21d95e4 | |||
| 18df45819d |
Submodule assets/compose updated: 434b2835ff...d3f2e3b7b9
106
assets/ollama/Dockerfile
Normal file
106
assets/ollama/Dockerfile
Normal file
@@ -0,0 +1,106 @@
|
||||
# ollama-gfx906/Dockerfile
|
||||
#
|
||||
# Custom ollama image with ROCm 6.1 + gfx906 (MI50) support.
|
||||
# The official ollama/rocm image ships ROCm 7.2 which dropped gfx906.
|
||||
# This uses v0.23.2's native CMake build system with AMDGPU_TARGETS including gfx906.
|
||||
#
|
||||
# Build: docker build -t ollama/ollama:rocm-gfx906 ai/ollama
|
||||
|
||||
FROM rocm/dev-ubuntu-22.04:6.1.2-complete AS builder
|
||||
|
||||
# Build dependencies (CMake, Ninja, Go)
|
||||
ARG CMAKEVERSION=3.31.2
|
||||
ARG NINJAVERSION=1.12.1
|
||||
ARG GOLANG_VERSION=1.22.0
|
||||
|
||||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
curl git ccache build-essential pkg-config unzip \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install CMake from official binaries
|
||||
RUN curl -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKEVERSION}/cmake-${CMAKEVERSION}-linux-x86_64.tar.gz \
|
||||
| tar xz -C /usr/local --strip-components 1
|
||||
|
||||
# Install Ninja
|
||||
RUN curl -fsSL -o /tmp/ninja.zip \
|
||||
https://github.com/ninja-build/ninja/releases/download/v${NINJAVERSION}/ninja-linux.zip \
|
||||
&& unzip /tmp/ninja.zip -d /usr/local/bin && rm /tmp/ninja.zip
|
||||
|
||||
# Install Go
|
||||
RUN curl -fsSL https://go.dev/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz \
|
||||
| tar xz -C /usr/local
|
||||
ENV PATH=/usr/local/go/bin:$PATH
|
||||
|
||||
ARG OLLAMA_VERSION=v0.23.2
|
||||
RUN git clone --depth 1 --branch ${OLLAMA_VERSION} https://github.com/ollama/ollama.git /build
|
||||
WORKDIR /build
|
||||
|
||||
# ROCm paths
|
||||
ENV HIP_PATH=/opt/rocm
|
||||
ENV ROCM_PATH=/opt/rocm
|
||||
ENV CMAKE_GENERATOR=Ninja
|
||||
ENV LDFLAGS=-s
|
||||
|
||||
# Step 1: Build CPU backends with GCC (no ROCm preset)
|
||||
# Pre-set CMAKE_HIP_COMPILER="" to prevent check_language(HIP) from
|
||||
# finding a HIP compiler (it searches /opt/rocm even without PATH).
|
||||
# Remove /opt/rocm from PATH to prevent find_program from finding hipcc.
|
||||
RUN mkdir -p build-cpu && \
|
||||
PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
|
||||
cmake -B build-cpu -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_HIP_COMPILER="" \
|
||||
-DCMAKE_INSTALL_PREFIX=/build/dist && \
|
||||
cmake --build build-cpu --target ggml-cpu -- -l $(nproc) && \
|
||||
cmake --install build-cpu --component CPU --strip && \
|
||||
echo "=== CPU install ===" && \
|
||||
(find /build/dist/lib/ollama -type f -o -type l 2>&1 | head -20 || echo "empty")
|
||||
|
||||
# Step 2: Build HIP backend with ROCm preset + gfx906 target only
|
||||
# The ROCm 6 preset enables HIP language detection (enable_language(HIP))
|
||||
# which ensures GPU kernels are properly compiled for gfx906.
|
||||
# OLLAMA_RUNNER_DIR=rocm from the preset, so HIP goes to lib/ollama/rocm/
|
||||
# Need CMAKE_PREFIX_PATH so find_package(hip) finds hip-config.cmake
|
||||
# at /opt/rocm/lib/cmake/hip/hip-config.cmake.
|
||||
RUN mkdir -p build-hip && \
|
||||
cmake -B build-hip \
|
||||
--preset 'ROCm 6' \
|
||||
-DAMDGPU_TARGETS="gfx906:xnack-" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH="/opt/rocm" && \
|
||||
cmake --build build-hip --target ggml-hip -- -l $(nproc) && \
|
||||
cmake --install build-hip --component HIP --strip && \
|
||||
echo "=== HIP install ===" && \
|
||||
find /build/dist/lib/ollama -type f -o -type l | head -20
|
||||
|
||||
# Step 3: Build Go binary (GCC for CGo linking)
|
||||
ENV CGO_ENABLED=1
|
||||
RUN go build -trimpath -ldflags="-X=github.com/ollama/ollama/version.Version=${OLLAMA_VERSION}" -o /build/dist/ollama .
|
||||
|
||||
# ---------- Runtime image ----------
|
||||
FROM ubuntu:24.04
|
||||
|
||||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
ca-certificates curl libstdc++6 libgomp1 libvulkan1 libopenblas0 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy ROCm 6.1 runtime libraries
|
||||
# These are needed at runtime by ggml-hip via LD_LIBRARY_PATH
|
||||
COPY --from=builder /opt/rocm/lib/ /opt/rocm/lib/
|
||||
COPY --from=builder /opt/rocm/share/ /opt/rocm/share/
|
||||
|
||||
# Copy ollama binary + all backends (CPU + HIP)
|
||||
# CPU install: /build/dist/lib/ollama/libggml-*.so
|
||||
# HIP install: /build/dist/lib/ollama/rocm/libggml-hip.so
|
||||
COPY --from=builder /build/dist/ollama /usr/bin/ollama
|
||||
COPY --from=builder /build/dist/lib/ollama/ /usr/lib/ollama/
|
||||
|
||||
RUN ldconfig
|
||||
|
||||
ENV LD_LIBRARY_PATH=/opt/rocm/lib:/usr/lib/ollama/rocm:/usr/lib/ollama
|
||||
ENV HSA_OVERRIDE_GFX_VERSION=9.0.6
|
||||
ENV HCC_AMDGPU_TARGET=gfx906
|
||||
ENV HSA_ENABLE_SDMA=0
|
||||
|
||||
EXPOSE 11434
|
||||
ENTRYPOINT ["/bin/ollama"]
|
||||
CMD ["serve"]
|
||||
@@ -61,6 +61,7 @@
|
||||
./modules/nixos/services/open_code_server.nix
|
||||
./modules/nixos/services/ollama_init_custom_models.nix
|
||||
./modules/nixos/services/openclaw_node.nix
|
||||
./modules/nixos/security/ai-worker-restricted.nix
|
||||
./users/gortium.nix
|
||||
./users/ai-worker.nix
|
||||
];
|
||||
|
||||
@@ -207,6 +207,7 @@
|
||||
ai = {
|
||||
path = self + "/assets/compose/ai";
|
||||
envFile = config.age.secrets.containers_env.path;
|
||||
ports = [ 22000 ]; # Syncthing TCP sync
|
||||
};
|
||||
|
||||
cloudstorage = {
|
||||
@@ -474,7 +475,7 @@
|
||||
services.openssh.settings = {
|
||||
PermitRootLogin = "no";
|
||||
MaxAuthTries = 3;
|
||||
MaxSessions = 10;
|
||||
MaxSessions = 20;
|
||||
LoginGraceTime = 30;
|
||||
ClientAliveInterval = 300;
|
||||
ClientAliveCountMax = 2;
|
||||
|
||||
126
modules/nixos/security/README-ai-worker.md
Normal file
126
modules/nixos/security/README-ai-worker.md
Normal file
@@ -0,0 +1,126 @@
|
||||
# AI Worker Restricted Access
|
||||
|
||||
This module provides SSH access for the AI worker (hermes-agent) to run docker commands on the host.
|
||||
|
||||
## Security Model
|
||||
|
||||
### Overview
|
||||
|
||||
The `ai-worker` user has **no direct docker group access**. All docker commands must go through `sudo`, and only specific subcommands are whitelisted:
|
||||
|
||||
- **Container lifecycle**: `docker ps`, `docker inspect`, `docker logs`, `docker images`, `docker info`, `docker version`, `docker stats`
|
||||
- **Control**: `docker start`, `docker stop`, `docker restart`, `docker rm`, `docker rmi`, `docker wait`
|
||||
- **Image management**: `docker pull`, `docker build`, `docker run`, `docker compose`
|
||||
- **Disk cleanup**: `docker system`
|
||||
- **Network/Volume**: `docker network ls`, `docker volume ls` (read-only)
|
||||
|
||||
### EXPLICITLY BLOCKED (not in sudo whitelist)
|
||||
|
||||
| Command | Risk | Result |
|
||||
|---------|------|--------|
|
||||
| `docker exec` | Execute arbitrary commands inside containers (FILE MODIFICATION) | Blocked by sudo |
|
||||
| `docker cp` | Copy files between containers and host | Blocked by sudo |
|
||||
| `docker commit` | Create images from running containers (data exfil) | Blocked by sudo |
|
||||
| `docker diff` | Inspect filesystem changes | Blocked by sudo |
|
||||
| `docker export` | Export container filesystem | Blocked by sudo |
|
||||
| `docker import` | Import filesystem archives | Blocked by sudo |
|
||||
| `docker load` | Load docker images | Blocked by sudo |
|
||||
| `docker save` | Save docker images to tar | Blocked by sudo |
|
||||
| `docker attach` | Interactive access to containers | Blocked by sudo |
|
||||
| `docker push` | Push images to registries | Blocked by sudo |
|
||||
| `docker tag` | Rename images | Blocked by sudo |
|
||||
|
||||
### Why This Approach?
|
||||
|
||||
Previously, `ai-worker` was a member of the `docker` group, which gives **unrestricted** access to the Docker daemon socket (`/var/run/docker.sock`). Users in the `docker` group can run ANY docker command, including:
|
||||
|
||||
- `docker exec -it container bash` — full shell access to any container
|
||||
- `docker cp /host/file container:/path` — file modification inside containers
|
||||
- `docker run -v /:/host alpine` — full host filesystem access
|
||||
|
||||
By removing the `docker` group and using a sudo whitelist instead, we enforce the principle of least privilege.
|
||||
|
||||
### Filesystem Access
|
||||
- **Home directory**: `/home/ai-worker` (standard user home)
|
||||
- **No bind mounts**: Cannot access `/home/gortium/infra` or other host files
|
||||
- **Cannot access**: Any files outside standard system paths
|
||||
|
||||
### Sudo Access
|
||||
- **Restricted**: ai-worker has `NOPASSWD` access only to whitelisted commands
|
||||
- Cannot run `nh`, `nixos-rebuild`, `nixpkgs-fmt`, or `nix` with elevated permissions
|
||||
|
||||
## Workflow: SSH + Restricted Docker
|
||||
|
||||
All docker commands must be prefixed with `sudo`:
|
||||
|
||||
```bash
|
||||
# From Hermes container, SSH to host
|
||||
ssh -i /path/to/ssh/key ai-worker@host.docker.internal
|
||||
|
||||
# Check container status (works)
|
||||
sudo docker ps
|
||||
|
||||
# Restart a container (works)
|
||||
sudo docker restart ollama
|
||||
|
||||
# Run benchmark (works - docker run is allowed)
|
||||
sudo docker run --rm alpine echo "test"
|
||||
|
||||
# ANY of these will FAIL (not in whitelist):
|
||||
sudo docker exec ollama ollama list # FAILS - docker exec blocked
|
||||
sudo docker cp file.txt container:/path/ # FAILS - docker cp blocked
|
||||
sudo docker commit container new-image # FAILS - docker commit blocked
|
||||
|
||||
# For ollama operations, use the HTTP API instead of docker exec:
|
||||
curl http://ollama:11434/api/tags
|
||||
```
|
||||
|
||||
## SSH Access
|
||||
|
||||
Connect as:
|
||||
```bash
|
||||
ssh ai-worker@lazyworkhorse
|
||||
```
|
||||
|
||||
The working directory will be `/home/ai-worker`. No infra repo access.
|
||||
|
||||
## Verification
|
||||
|
||||
Check ai-worker permissions:
|
||||
```bash
|
||||
# On the host, as root or gortium:
|
||||
sudo -u ai-worker sudo -l
|
||||
# Should show the whitelisted commands only (no docker exec/cp/commit)
|
||||
|
||||
# Verify NOT in docker group
|
||||
groups ai-worker
|
||||
# Should show: ai-worker (NO docker group)
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If docker commands fail:
|
||||
|
||||
```bash
|
||||
# Check sudo permissions
|
||||
sudo -u ai-worker sudo -l | grep docker
|
||||
|
||||
# Verify group membership
|
||||
groups ai-worker
|
||||
|
||||
# Test allowed command
|
||||
sudo -u ai-worker sudo docker ps
|
||||
|
||||
# Test blocked command (should fail)
|
||||
sudo -u ai-worker sudo docker exec ollama ollama list
|
||||
# Expected: "Sorry, user ai-worker is not allowed to execute"
|
||||
```
|
||||
|
||||
If SSH connection fails:
|
||||
```bash
|
||||
# Check SSH key is authorized
|
||||
cat /home/ai-worker/.ssh/authorized_keys
|
||||
|
||||
# Check SSH service
|
||||
systemctl status sshd
|
||||
```
|
||||
24
modules/nixos/security/ai-worker-restricted.nix
Normal file
24
modules/nixos/security/ai-worker-restricted.nix
Normal file
@@ -0,0 +1,24 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options.services.aiWorkerAccess = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable AI worker SSH access with restricted sudo docker commands";
|
||||
};
|
||||
|
||||
config = mkIf config.services.aiWorkerAccess {
|
||||
# SECURITY: ai-worker is NOT added to docker group.
|
||||
# Docker access is granted via sudo whitelist in users/ai-worker.nix.
|
||||
# This prevents unrestricted docker daemon access (docker exec, cp, commit, etc.)
|
||||
# Only specific docker subcommands are allowed via sudo NOPASSWD rules.
|
||||
|
||||
# The old approach (docker group membership) has been removed because:
|
||||
# - Docker group gives UNRESTRICTED access to the docker daemon socket
|
||||
# - No way to limit which docker subcommands a docker group member can run
|
||||
# - Allowed: docker exec, docker cp, docker run -v /:/host, etc.
|
||||
# users.groups.docker.members = [ "ai-worker" ]; // REMOVED
|
||||
};
|
||||
}
|
||||
@@ -1,67 +1,87 @@
|
||||
{ pkgs, ... }: {
|
||||
systemd.services.init-ollama-model = {
|
||||
description = "Initialize LLM models with extra context in Ollama Docker";
|
||||
after = [ "docker-ollama.service" ];
|
||||
|
||||
# On s'assure que Docker tourne avant de lancer ce script
|
||||
after = [ "docker.service" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
script = ''
|
||||
# Wait for Ollama
|
||||
while ! ${pkgs.curl}/bin/curl -s http://localhost:11434/api/tags > /dev/null; do
|
||||
sleep 2
|
||||
done
|
||||
# Fonction de création asynchrone pour ne pas bloquer le démarrage
|
||||
(
|
||||
echo "Starting asynchronous Ollama initialization..."
|
||||
|
||||
# Attente d'Ollama (maximum 120 secondes pour éviter une boucle infinie)
|
||||
TIMEOUT=60
|
||||
COUNT=0
|
||||
while ! ${pkgs.curl}/bin/curl -s -f http://127.0.0.1:11434/api/tags > /dev/null; do
|
||||
if [ $COUNT -ge $TIMEOUT ]; then
|
||||
echo "Ollama did not become ready in time. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
echo "Waiting for Ollama API to be reachable..."
|
||||
sleep 5
|
||||
COUNT=$((COUNT + 5))
|
||||
done
|
||||
|
||||
create_model_if_missing() {
|
||||
local model_name=$1
|
||||
local base_model=$2
|
||||
if ! ${pkgs.docker}/bin/docker exec ollama ollama list | grep -q "$model_name"; then
|
||||
echo "$model_name not found, creating from $base_model..."
|
||||
create_model_if_missing() {
|
||||
local model_name=$1
|
||||
local base_model=$2
|
||||
|
||||
# We use a custom TEMPLATE block to strip the 'currentDate' function
|
||||
# which is unsupported in Ollama 0.5.7 but present in Devstral's default manifest.
|
||||
${pkgs.docker}/bin/docker exec ollama sh -c "cat <<EOF > /root/.ollama/$model_name.modelfile
|
||||
# Vérification robuste via l'API HTTP d'Ollama plutôt que docker exec (évite les conflits de tty)
|
||||
if ! ${pkgs.curl}/bin/curl -s http://127.0.0.1:11434/api/tags | ${pkgs.jq}/bin/jq -e ".models[] | select(.name == \"$model_name\")" > /dev/null; then
|
||||
echo "$model_name not found, creating from $base_model..."
|
||||
|
||||
# Utilisation d'un fichier temporaire sur l'hôte pour l'injecter proprement dans Docker
|
||||
TMP_FILE=$(mktemp)
|
||||
cat <<EOF > "$TMP_FILE"
|
||||
FROM $base_model
|
||||
TEMPLATE \"\"\"{{- if .System }}
|
||||
TEMPLATE """{{- if .System }}
|
||||
[SYSTEM_PROMPT]
|
||||
{{ .System }}
|
||||
[/SYSTEM_PROMPT]
|
||||
{{- end }}
|
||||
{{- range .Messages }}
|
||||
{{- if eq .Role \"user\" }}
|
||||
{{- if eq .Role "user" }}
|
||||
[INST]
|
||||
{{ .Content }}
|
||||
[/INST]
|
||||
{{- else if eq .Role \"assistant\" }}
|
||||
{{- else if eq .Role "assistant" }}
|
||||
{{ .Content }}
|
||||
{{- end }}
|
||||
{{- end }}\"\"\"
|
||||
{{- end }}"""
|
||||
PARAMETER num_ctx 131072
|
||||
PARAMETER num_predict 4096
|
||||
PARAMETER num_keep 1024
|
||||
PARAMETER repeat_penalty 1.1
|
||||
PARAMETER top_k 40
|
||||
PARAMETER stop \"[INST]\"
|
||||
PARAMETER stop \"[/INST]\"
|
||||
PARAMETER stop \"</s>\"
|
||||
EOF"
|
||||
${pkgs.docker}/bin/docker exec ollama ollama create "$model_name" -f "/root/.ollama/$model_name.modelfile"
|
||||
${pkgs.docker}/bin/docker exec ollama rm "/root/.ollama/$model_name.modelfile"
|
||||
else
|
||||
echo "$model_name already exists, skipping."
|
||||
fi
|
||||
}
|
||||
PARAMETER stop "[INST]"
|
||||
PARAMETER stop "[/INST]"
|
||||
PARAMETER stop "</s>"
|
||||
EOF
|
||||
|
||||
# Create Nemotron
|
||||
create_model_if_missing "nemotron-3-nano:30b-128k" "nemotron-3-nano:30b"
|
||||
|
||||
# Create Devstral
|
||||
create_model_if_missing "devstral-small-2:24b-128k" "devstral-small-2:24b"
|
||||
|
||||
# create_model_if_missing "qwen2.5-coder:32b-128k" "qwen2.5-coder:32b"
|
||||
|
||||
# create_model_if_missing "mistral-large-planner:123b" "mistral-large:123b-instruct-v2407-q4_K_S"
|
||||
# Copie et création dans le conteneur
|
||||
${pkgs.docker}/bin/docker cp "$TMP_FILE" ollama:/tmp/model.modelfile
|
||||
${pkgs.docker}/bin/docker exec ollama ollama create "$model_name" -f /tmp/model.modelfile
|
||||
${pkgs.docker}/bin/docker exec ollama rm /tmp/model.modelfile
|
||||
rm -f "$TMP_FILE"
|
||||
else
|
||||
echo "$model_name already exists, skipping."
|
||||
fi
|
||||
}
|
||||
|
||||
# Create Nemotron
|
||||
create_model_if_missing "nemotron-3-nano:30b-128k" "nemotron-3-nano:30b"
|
||||
|
||||
# Create Devstral
|
||||
create_model_if_missing "devstral-small-2:24b-128k" "devstral-small-2:24b"
|
||||
|
||||
) &
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
Type = "forking"; # Permet à systemd de savoir que le script passe en arrière-plan via '&'
|
||||
User = "root";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
9
secrets/wireguard_preshared_key.age
Normal file
9
secrets/wireguard_preshared_key.age
Normal file
@@ -0,0 +1,9 @@
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IEdoTUQ4QSA3VG9Z
|
||||
MVFPVFc2VVJ3d0h0dmtBUnI3WHl2SzUxTkRZbjFCaGloWmV3dnd3ClcxdnVPeGd6
|
||||
SU4zR0Q0K1dtVjRRVHd0VW5XSFI0dVFpTjZnYk1DNjRxTVEKLT4gQzlgRy1ncmVh
|
||||
c2UKeUozOWgyUytSTVF0NjY2STBEb2VadwotLS0gblI3bmJCUWxxU3QrYTEyVFBI
|
||||
Snc4NC9rTkh0NnZYbUtxUE9hRWRkelpmMAq58fmH6cK13GeD7wGLxKmx10hmJeW4
|
||||
b7KqnCD1ZP7uG85s32xzVRwRG8RrG4xZo5nR9Mrtg1CoTSFfUGeFnf5xveN+Ej0X
|
||||
wDVB1LwC+Q==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
11
secrets/wireguard_private_key.age
Normal file
11
secrets/wireguard_private_key.age
Normal file
@@ -0,0 +1,11 @@
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IEdoTUQ4QSA5dzVG
|
||||
WUNvT3NlRmcrWS81bzJqSWlTekVYaDFFTE10SkI2dEgzaGpxcUI4Cmk5Y0FGYTRZ
|
||||
K0NGYzY3VUp4aS9ZZGRmWTgybDJFUURva2pZNmVOS3QxdEUKLT4gPnVRTCtldGMt
|
||||
Z3JlYXNlCk04OTJZeFRNeDI5aGpMVTk1ZTE0Y2FMMnFEMjlJalJpMHRlaTE4ZWIx
|
||||
d2lCRGQ5RHVjcktOMGJCb1VERlNWcTYKaSt0L1Z6dVJ0QWIyZkhsYzFEVjZSQWUr
|
||||
ZWpwVlo1TmhoUFJZdkEvR0gxNlVhcXF2ZTRnCi0tLSBLcmM2MThNVkdWclpHUXRr
|
||||
VTF6QVk2WUZlTXpZMVNLMlpBOFc3M1o5WjZzCs9xbPlIX+u5vRSQ/z9utu+I9S2c
|
||||
02DOsIb1kzxzb1OK91b8Kh4JucQSq3qkyEvRucsNn5QW8hIHDnRuND6EbPyN7p4S
|
||||
YB/F0dxSqgnq
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
@@ -4,20 +4,149 @@
|
||||
group = "ai-worker";
|
||||
home = "/home/ai-worker";
|
||||
createHome = true;
|
||||
extraGroups = [ "docker" ];
|
||||
# SECURITY: ai-worker is NOT in the docker group.
|
||||
# Docker access is restricted via sudo whitelist — only specific subcommands allowed.
|
||||
# extraGroups = [ "docker" ]; — REMOVED: docker group gives unrestricted docker daemon access
|
||||
shell = pkgs.bashInteractive;
|
||||
openssh.authorizedKeys.keys = [
|
||||
keys.users.ai-worker.main
|
||||
];
|
||||
# No password login - SSH key only
|
||||
hashedPassword = "!";
|
||||
};
|
||||
users.groups.ai-worker = {};
|
||||
|
||||
# Restricted sudo for ai-worker - security checks only
|
||||
|
||||
# Enable restricted AI worker SSH access for ollama benchmarking
|
||||
# SECURITY: ai-worker can only:
|
||||
# - SSH into host from Hermes container
|
||||
# - Run docker commands via sudo (whitelist below — no exec/cp/commit)
|
||||
# - Run specific security audit commands
|
||||
# - NO access to infra repo (no bind mount)
|
||||
# - NO nix/nixos-rebuild/nh commands
|
||||
# WORKFLOW: SSH from Hermes container, run docker commands via sudo, return and save results
|
||||
services.aiWorkerAccess = true;
|
||||
|
||||
# Restricted sudo for ai-worker
|
||||
# IMPORTANT: ai-worker is NOT in docker group. All docker access goes through sudo.
|
||||
# Only the subcommands listed below are allowed — everything else is denied.
|
||||
# This prevents: docker exec, docker cp, docker commit, and other file-modifying operations.
|
||||
security.sudo.extraRules = [
|
||||
{
|
||||
users = [ "ai-worker" ];
|
||||
commands = [
|
||||
# Firewall checks
|
||||
# === Docker commands: lifecycle management (NO file modification) ===
|
||||
# ps/inspect/logs — read-only status checks
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker ps";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker inspect *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker logs *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker images";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker info";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker version";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker stats *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
|
||||
# start/stop/restart — container lifecycle
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker start *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker stop *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker restart *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker rm *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker rmi *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker wait *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
|
||||
# pull/build/run — image management and container creation
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker pull *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker build *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker run *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
|
||||
# compose — orchestration
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker compose *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
|
||||
# system — disk cleanup
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker system *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
|
||||
# network — list only (create/modify not needed)
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker network ls";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
|
||||
# volume — list only (create/modify not needed)
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker volume ls";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
|
||||
# === EXPLICITLY DENIED docker commands (not in whitelist — sudo rejects them) ===
|
||||
# docker exec — executes arbitrary commands inside running containers (FILE MODIFICATION)
|
||||
# docker cp — copies files between containers and host (FILE ACCESS)
|
||||
# docker commit — creates images from running containers (DATA EXFIL)
|
||||
# docker diff — inspects filesystem changes (INFO LEAK)
|
||||
# docker export — exports container filesystem (DATA EXFIL)
|
||||
# docker import — imports filesystem archives
|
||||
# docker load — loads docker images
|
||||
# docker save — saves docker images to tar (DATA EXFIL)
|
||||
# docker attach — attaches to running containers (INTERACTIVE ACCESS)
|
||||
# docker push — pushes images to registries (DATA EXFIL)
|
||||
# docker tag — renames images
|
||||
# docker create — creates containers (use 'docker run' instead)
|
||||
# docker plugin — manages plugins
|
||||
# docker network create/rm — network management
|
||||
# docker volume create/rm — volume management
|
||||
|
||||
# === Firewall checks ===
|
||||
{
|
||||
command = "/run/wrappers/bin/sudo iptables -L -n -v";
|
||||
options = [ "NOPASSWD" ];
|
||||
@@ -26,7 +155,8 @@
|
||||
command = "/run/wrappers/bin/sudo iptables -S";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
# Fail2ban status
|
||||
|
||||
# === Fail2ban status ===
|
||||
{
|
||||
command = "/run/current-system/sw/bin/fail2ban-client status";
|
||||
options = [ "NOPASSWD" ];
|
||||
@@ -39,7 +169,8 @@
|
||||
command = "/run/current-system/sw/bin/fail2ban-client get * banned";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
# Log inspection
|
||||
|
||||
# === Log inspection ===
|
||||
{
|
||||
command = "/run/current-system/sw/bin/journalctl -t kernel -n 100";
|
||||
options = [ "NOPASSWD" ];
|
||||
@@ -52,21 +183,14 @@
|
||||
command = "/run/current-system/sw/bin/journalctl -u firewall -n 50";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
# SSH config verification
|
||||
|
||||
# === SSH config verification ===
|
||||
{
|
||||
command = "/run/current-system/sw/bin/sshd -T";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
# Docker service checks
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker ps";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/docker inspect *";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
# Network diagnostics
|
||||
|
||||
# === Network diagnostics ===
|
||||
{
|
||||
command = "/run/current-system/sw/bin/ss -tlnp";
|
||||
options = [ "NOPASSWD" ];
|
||||
|
||||
Reference in New Issue
Block a user