diff --git a/PROD.md b/PROD.md index 3894f85..fc8657c 100644 --- a/PROD.md +++ b/PROD.md @@ -4,7 +4,9 @@ docker swarm init --advertise-addr 192.168.1.96 --force-new-cluster Swarm initialized: current node (j9bljgaqh9qch2nmozvu2bprs) is now a manager. To add a worker to this swarm, run the following command: -docker swarm join --token SWMTKN-1-0eb9ypg3ouig0ac493scmjtogida7ddy79xr2e9kkvaitoz0y0-7t5lg5sx8q20uqz2uandsblc9 192.168.1.96:2377 + +docker swarm join --token \ +--advertise-addr 100.105.201.15 192.168.1.96:2377 ## Prod instances diff --git a/poc/anywherelan/Dockerfile b/poc/anywherelan/Dockerfile new file mode 100644 index 0000000..2da08c0 --- /dev/null +++ b/poc/anywherelan/Dockerfile @@ -0,0 +1,29 @@ +# Minimal image that downloads AWL binary from GitHub releases +FROM alpine:latest + +# Install dependencies for downloading and running AWL +RUN apk add --no-cache ca-certificates curl + +# Download AWL binary for Linux amd64 from v0.17.0 release +# Extract from the tar.gz archive +RUN set -e; \ + mkdir -p /tmp/awl-download; \ + cd /tmp/awl-download; \ + curl -L "https://github.com/anywherelan/awl/releases/download/v0.17.0/awl-linux-amd64-v0.17.0.tar.gz" -o awl.tar.gz; \ + tar -xzf awl.tar.gz; \ + mv awl /usr/local/bin/awl; \ + chmod +x /usr/local/bin/awl; \ + rm -rf /tmp/awl-download + +# Copy entrypoint script for automatic key generation +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Create directory for storing keys and configuration +WORKDIR /data + +# Expose ports: 8639 for Web UI, 4363 for P2P network +EXPOSE 8639 4363 + +# Run the entrypoint script that starts the AWL node +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/poc/anywherelan/README.md b/poc/anywherelan/README.md new file mode 100644 index 0000000..885ecb2 --- /dev/null +++ b/poc/anywherelan/README.md @@ -0,0 +1,147 @@ +### Start the Node + +The node will automatically generate its encryption key and configuration on first startup: + +```bash +docker run -d \ + --name anywherelan-node \ + --restart unless-stopped \ + --privileged \ + -v awl-config:/data \ + anywherelan:v0.17.0 +``` + +**Flags explained:** +- `-d`: Run in background (detached mode) +- `--restart unless-stopped`: Auto-restart on failure +- `--privileged`: Required for network interface creation (TUN/TAP device) +- `-v awl-config:/data`: Create and mount a named volume for config/key storage + +The container will generate `network.key` and `config.json` in the `awl-config` volume on first run. + +### Verify Node is Running + +```bash +docker ps | grep anywherelan +docker logs anywherelan-node +``` + + +## Web Interface + +The node exposes a web interface on port 8639. Access it at: +``` +http://localhost:8639 +``` + +## Docker Compose Alternative + +Create a `docker-compose.yml` file: + +```yaml +version: '3.8' +services: + anywherelan: + image: anywherelan:v0.17.0 + container_name: anywherelan-node + restart: unless-stopped + privileged: true + volumes: + - awl-config:/data + ports: + - "8639:8639" + +volumes: + awl-config: +``` + +Then start with: +```bash +docker-compose up -d +``` + +The network key and configuration will be automatically generated on first startup. + +## Stopping the Node + +```bash +docker stop anywherelan-node +``` + +## Removing the Node + +```bash +docker rm anywherelan-node +``` + +To also remove the configuration volume: + +```bash +docker volume rm awl-config +``` + +⚠️ **Warning**: Removing the volume will delete all configuration and keys. Only do this if you want a fresh start. + +## Configuration + +Configuration is stored in the `awl-config` volume: +- `network.key`: Your node's encryption key (auto-generated) +- `config.json`: Node configuration (auto-generated) + +To access or backup configuration: + +```bash +# View volume location +docker volume inspect awl-config + +# Backup configuration +docker run --rm -v awl-config:/data -v $(pwd):/backup alpine cp -r /data /backup/awl-config-backup + +# Restore configuration +docker run --rm -v awl-config:/data -v $(pwd):/backup alpine cp -r /backup/awl-config-backup /data +``` + +## Troubleshooting + +### Permission Denied Error +The `--privileged` flag is required for creating virtual network interfaces (TUN/TAP devices). + +### Port Already in Use +If port 8639 is taken, map to a different port: +```bash +docker run -d \ + --name anywherelan-node \ + --restart unless-stopped \ + --privileged \ + -p 8640:8639 \ + -v awl-config:/data \ + anywherelan:v0.17.0 +``` + +Then access the web interface at `http://localhost:8640` + +### View Logs +```bash +docker logs -f anywherelan-node +``` + +### Missing TUN Device +If you see "create tun: CreateTUN failed", ensure: +1. Docker is running with `--privileged` flag +2. The host has `/dev/net/tun` (on Linux hosts) +3. On non-Linux systems (Mac/Windows), Docker Desktop must have proper permissions + +### Inspect Volume +To see where Docker stores your volume: +```bash +docker volume inspect awl-config +``` + +## Version + +Built from tag: `v0.17.0` + +## References + +- [Anywherelan Official Repository](https://github.com/anywherelan/awl) +- [Project Documentation](https://github.com/anywherelan/awl/blob/main/README.md) \ No newline at end of file diff --git a/poc/anywherelan/docker-compose.yml b/poc/anywherelan/docker-compose.yml new file mode 100644 index 0000000..a49e37f --- /dev/null +++ b/poc/anywherelan/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.8' + +services: + anywherelan: + image: anywherelan:v0.17.0 + container_name: anywherelan-node + restart: unless-stopped + privileged: true + volumes: + - awl-config:/data + ports: + - "8639:8639" + networks: + - anywherelan-net + environment: + - TZ=UTC + logging: + driver: "json-file" + options: + max-size: "100m" + max-file: "10" + +volumes: + awl-config: + driver: local + +networks: + anywherelan-net: + driver: bridge diff --git a/poc/anywherelan/entrypoint.sh b/poc/anywherelan/entrypoint.sh new file mode 100644 index 0000000..e7f3bd2 --- /dev/null +++ b/poc/anywherelan/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +# Ensure /data directory exists +mkdir -p /data + +# Symlink the config directory to home config location so AWL can find it +mkdir -p /root/.config/anywherelan +ln -sf /data/config_awl.json /root/.config/anywherelan/config_awl.json 2>/dev/null || true + +# Run the AWL node (no command needed, it starts the server by default) +exec awl + diff --git a/poc/beszel/stack-compose.yml b/poc/beszel/stack-compose.yml new file mode 100644 index 0000000..71832e4 --- /dev/null +++ b/poc/beszel/stack-compose.yml @@ -0,0 +1,62 @@ +services: + beszel: + image: henrygd/beszel:latest + environment: + APP_URL: http://localhost:8090 + ports: + - 8090:8090 + volumes: + - beszel_data:/beszel_data + deploy: + mode: replicated + replicas: 1 + placement: + constraints: + - node.role == manager + restart_policy: + condition: on-failure + # healthcheck: + # test: ['CMD', '/beszel', 'health', '--url', 'http://localhost:8090'] + # interval: 120s + # start_period: 10s + # timeout: 5s + + beszel-agent: + image: henrygd/beszel-agent:latest + container_name: beszel-agent + restart: unless-stopped + network_mode: host + volumes: + - beszel_agent_data:/var/lib/beszel-agent + - beszel_socket:/beszel_socket + - /var/run/docker.sock:/var/run/docker.sock:ro + environment: + LISTEN: /beszel_socket/beszel.sock + HUB_URL: http://100.105.201.15:8090 + KEY: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOKMyuYnUwzLlYS7yZxcs1psBzRl7n9MhoZQ0Kek3XtV' + TOKEN: a2c7cabb-c849-4f64-89cf-1cf9afbfb018 + # healthcheck: + # test: ['CMD', '/agent', 'health'] + # interval: 120s + beszel-agent1: + image: henrygd/beszel-agent + container_name: beszel-agent1 + restart: unless-stopped + network_mode: host + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - beszel_agent_data:/var/lib/beszel-agent + # monitor other disks / partitions by mounting a folder in /extra-filesystems + # - /mnt/disk/.beszel:/extra-filesystems/sda1:ro + environment: + LISTEN: 45876 + KEY: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOKMyuYnUwzLlYS7yZxcs1psBzRl7n9MhoZQ0Kek3XtV' + TOKEN: cd057ffc-8af3-414f-bbd4-3d0c9986b8ba + HUB_URL: http://100.105.201.15:8090 + +volumes: + beszel_agent_data: +volumes: + beszel_data: + beszel_agent_data: + beszel_socket: \ No newline at end of file diff --git a/poc/netbird/Dockerfile b/poc/netbird/Dockerfile new file mode 100644 index 0000000..e081e54 --- /dev/null +++ b/poc/netbird/Dockerfile @@ -0,0 +1,11 @@ +FROM ubuntu:20.04 + +RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* + +RUN curl -fsSL https://pkgs.netbird.io/install.sh | sh + +RUN mkdir -p /scripts && \ + printf '#!/bin/bash\necho "=== Starting NetBird Entrypoint ==="\necho "Current user: $(whoami)"\necho "PATH: $PATH"\necho "Checking for netbird..."\nwhich netbird || echo "netbird not found in PATH"\necho "Attempting to start NetBird..."\nif command -v netbird &> /dev/null; then\n netbird up -F &\n NETBIRD_PID=$!\n echo "NetBird started with PID $NETBIRD_PID"\n trap "kill $NETBIRD_PID" TERM INT\n wait $NETBIRD_PID\nelse\n echo "ERROR: netbird command not available"\n echo "=== Container will keep running for debugging ==="\n tail -f /dev/null\nfi\n' > /scripts/entrypoint.sh && \ + chmod +x /scripts/entrypoint.sh + +ENTRYPOINT ["/scripts/entrypoint.sh"] diff --git a/poc/netbird/README.md b/poc/netbird/README.md new file mode 100644 index 0000000..ec11a9b --- /dev/null +++ b/poc/netbird/README.md @@ -0,0 +1,117 @@ +# Netbird Docker Deployment + +Docker Compose configurations and automated setup for Netbird - a zero-trust mesh VPN solution. + +## Quick Start + +**Start here**: Run the automated setup script +```bash +cd /media/DATA/src/ansible/poc/netbird +./setup-netbird.sh +``` + +Or manually clone official repo: +```bash +git clone https://github.com/netbirdio/netbird.git +cd netbird/infrastructure_files/compose +docker-compose up -d +``` + +## ⚠️ Important: OIDC Bug in Pre-built Images + +Pre-built Netbird Docker images crash on startup with segmentation fault in OIDC code. **Do not use local stack-server.yml directly.** Use official repository or setup script instead. + +## Files + +| File | Purpose | +|------|---------| +| **setup-netbird.sh** | ⭐ Automated setup script | +| **SETUP_NETBIRD_OFFICIAL.md** | Official deployment methods | +| **stack-server.yml** | Local Docker Compose (⚠️ management crashes) | +| **stack-client.yml** | Client instance | +| **VERSIONS.md** | Version reference | + +## Client Deployment + +Once you have working Netbird management: + +```bash +export MANAGEMENT_URL="https://your-server:33073" +export SETUP_KEY="from-dashboard" +docker-compose -f stack-client.yml up -d +``` + +Multiple clients: +```bash +docker-compose -f stack-client.yml -p client1 up -d +docker-compose -f stack-client.yml -p client2 up -d +``` + +## Android Setup (Same WiFi) + +1. Get server IP: `hostname -I` +2. Open firewall: `sudo ufw allow 33073` +3. Android app: Enter `http://:33073` + setup key + +Test: `curl http://:33073/api/health` + +## Docker Commands + +```bash +# Local infrastructure only (management will crash) +docker-compose -f stack-server.yml up -d +docker-compose -f stack-server.yml ps +docker-compose -f stack-server.yml logs -f + +# Stop +docker-compose -f stack-server.yml down + +# Database access +docker-compose -f stack-server.yml exec postgres \ + psql -U netbird -d netbird + +# Client commands +docker-compose -f stack-client.yml logs -f +``` + +## Services + +| Service | Port | +|---------|------| +| Management API | 33073 | +| Signal | 10000 | +| Dashboard | 80 | +| PostgreSQL | 5432 | +| Redis | 6379 | +| TURN | 3478, 5349 | + +## Environment Variables + +```bash +# Server (set before docker-compose up) +POSTGRES_PASSWORD=netbird123 +NETBIRD_MGMT_SINGLE_ACCOUNT_MODE=true +NETBIRD_MGMT_LOG_LEVEL=info + +# Client +MANAGEMENT_URL=https://server:33073 +SETUP_KEY=your-key +``` + +## Requirements + +**Server**: Docker, 2GB RAM, ports 80, 33073, 10000, 3478, 5349 + +**Client**: Docker with /dev/net/tun access, NET_ADMIN capability + +## Troubleshooting + +**Management crashes**: Use official repo or setup script +**Can't connect from Android**: Check firewall, use correct IP (not localhost) +**Database issues**: Check logs with `docker-compose logs postgres` + +## Resources + +- [Official Docs](https://docs.netbird.io/) +- [GitHub](https://github.com/netbirdio/netbird) +- Detailed guide in [SETUP_NETBIRD_OFFICIAL.md](SETUP_NETBIRD_OFFICIAL.md) diff --git a/poc/netbird/management.json b/poc/netbird/management.json new file mode 100644 index 0000000..162efc0 --- /dev/null +++ b/poc/netbird/management.json @@ -0,0 +1,51 @@ +{ + "Datadir": "/var/lib/netbird/", + "DataStoreEncryptionKey": "8zd4m/LHfTvaQtst9ZW29BpZ0U1/RrvRvhtE1y7OdKg=", + "StoreConfig": { + "Engine": "postgres" + }, + "HttpConfig": { + "Address": "0.0.0.0", + "Port": 33073, + "CertFile": "", + "CertKey": "" + }, + "Stuns": [ + { + "Proto": "udp", + "URI": "stun:3468", + "Username": "", + "Password": "" + } + ], + "TURNConfig": { + "Turns": [ + { + "Proto": "udp", + "URI": "turn:3478", + "Username": "", + "Password": "" + } + ], + "CredentialsMap": {} + }, + "Signal": { + "URI": "signal:10000", + "Proto": "grpc" + }, + "Relay": { + "URI": "relay:7835" + }, + "ReverseProxy": { + "TrustedHTTPProxies": null, + "TrustedHTTPProxiesCount": 0, + "TrustedPeers": null, + "AccessLogRetentionDays": 0, + "AccessLogCleanupIntervalHours": 0 + }, + "IdpManagerConfig": null, + "DeviceAuthorizationFlow": null, + "PKCEAuthorizationFlow": null, + "DisableDefaultPolicy": false, + "EmbeddedIdP": null +} \ No newline at end of file diff --git a/poc/netbird/stack-client.yml b/poc/netbird/stack-client.yml new file mode 100644 index 0000000..110b4c4 --- /dev/null +++ b/poc/netbird/stack-client.yml @@ -0,0 +1,33 @@ +version: '3.8' + +services: + netbird-client: + image: netbirdio/client:latest + container_name: netbird-client + cap_add: + - NET_ADMIN + devices: + - /dev/net/tun + environment: + NETBIRD_MANAGEMENT_URL: ${MANAGEMENT_URL:-https://management:33073} + NETBIRD_LOG_LEVEL: info + # Use setup key for automatic enrollment (optional) + NETBIRD_SETUP_KEY: ${SETUP_KEY:-} + volumes: + - netbird_client_data:/etc/netbird + - /etc/resolv.conf:/etc/resolv.conf:ro + ports: + - "41641:41641/udp" + networks: + - netbird + restart: unless-stopped + dns: + - 8.8.8.8 + - 8.8.4.4 + +volumes: + netbird_client_data: + +networks: + netbird: + driver: bridge diff --git a/poc/netbird/stack-server.yml b/poc/netbird/stack-server.yml new file mode 100644 index 0000000..2571d0d --- /dev/null +++ b/poc/netbird/stack-server.yml @@ -0,0 +1,118 @@ +version: '3.8' + +services: + postgres: + image: postgres:15-alpine + container_name: netbird-postgres + environment: + POSTGRES_DB: netbird + POSTGRES_USER: netbird + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-netbird123} + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U netbird"] + interval: 10s + timeout: 5s + retries: 5 + + redis: + image: redis:7-alpine + container_name: netbird-redis + ports: + - "6379:6379" + volumes: + - redis_data:/data + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + + management: + image: netbirdio/management:0.70.5 + container_name: netbird-management + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy + environment: + # PostgreSQL configuration + NETBIRD_MGMT_DATASTORE: postgres + NETBIRD_MGMT_DATASTORE_HOST: postgres + NETBIRD_MGMT_DATASTORE_PORT: "5432" + NETBIRD_MGMT_DATASTORE_DB: netbird + NETBIRD_MGMT_DATASTORE_USER: netbird + NETBIRD_MGMT_DATASTORE_PASSWORD: ${POSTGRES_PASSWORD:-netbird123} + # Redis + NETBIRD_MGMT_DATASTORE_CACHE: "redis" + NETBIRD_MGMT_DATASTORE_REDIS_URL: "redis://redis:6379" + # Management API + NETBIRD_MGMT_API_PORT: "33073" + NETBIRD_MGMT_LOG_LEVEL: debug + NETBIRD_MGMT_SINGLE_ACCOUNT_MODE: "true" + NETBIRD_MGMT_DISABLE_SINGLE_ACCOUNT_MODE_REQUIRE_CUSTOM_DOMAIN: "true" + # OIDC disabled + NETBIRD_MGMT_AUTH_OIDC_CONFIGURATION_ENDPOINT: "" + ports: + - "33073:33073" + volumes: + - management_data:/var/lib/netbird + - ./management.json:/etc/netbird/management.json + networks: + - netbird + restart: "no" + + signal: + image: netbirdio/signal:0.70.5 + container_name: netbird-signal + environment: + NETBIRD_SIGNAL_LOG_LEVEL: info + NETBIRD_SIGNAL_PORT: 10000 + ports: + - "10000:10000/tcp" + - "10000:10000/udp" + networks: + - netbird + depends_on: + - management + + dashboard: + image: netbirdio/dashboard:latest + container_name: netbird-dashboard + environment: + REACT_APP_API_URL: ${DASHBOARD_API_URL:-http://localhost:33073} + ports: + - "80:80" + networks: + - netbird + depends_on: + - management + + coturn: + image: coturn/coturn:latest + container_name: netbird-turn + ports: + - "3478:3478/tcp" + - "3478:3478/udp" + - "5349:5349/tcp" + - "5349:5349/udp" + volumes: + - ./coturn.conf:/etc/coturn/turnserver.conf:ro + - turn_data:/var/lib/coturn + networks: + - netbird + restart: unless-stopped + +volumes: + postgres_data: + redis_data: + management_data: + turn_data: + +networks: + netbird: + driver: bridge diff --git a/poc/vscode/README.md b/poc/vscode/README.md new file mode 100644 index 0000000..24e654b --- /dev/null +++ b/poc/vscode/README.md @@ -0,0 +1,21 @@ +Code-Server (code-server) Docker Swarm stack + +Deploy a lightweight web-accessible VS Code (code-server) on Docker Swarm. + +Quick usage + +- Edit `stack-code-server.yml` to set a secure `PASSWORD` (or use Docker secrets). +- Deploy the stack: + +```bash +docker stack deploy -c stack-code-server.yml code-server +``` + +Access + +- Open http://:8443 or https depending on the image configuration. Log in with the password set in the compose file. + +Notes + +- The service stores config in a named volume `code_server_data` and mounts `./workspace` into the container at `/config/workspace`. +- For production, replace the `PASSWORD` with a Docker secret and consider putting the service behind a reverse proxy/traefik with TLS. diff --git a/poc/vscode/stack-code-server.yml b/poc/vscode/stack-code-server.yml new file mode 100644 index 0000000..ec9ec30 --- /dev/null +++ b/poc/vscode/stack-code-server.yml @@ -0,0 +1,22 @@ +version: '3.8' +services: + code-server: + image: linuxserver/code-server:latest + ports: + - "8443:8443" + environment: + PUID: 1000 + PGID: 1000 + TZ: UTC + PASSWORD: changeme + volumes: + - config:/config + - workspace:/config/workspace + deploy: + replicas: 1 + restart_policy: + condition: on-failure + +volumes: + config: + workspace: