diff --git a/.env.example b/.env.example index 0a7321a..6500e29 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,15 @@ DASHBOARD_PORT=443 INDEXER_HEAP=1g COLLECTOR_MAX_LOG_MB=50 +# Optionaler HTTP(S)-Proxy, falls der Server nicht direkt ins Internet kommt. +# Leer lassen = kein Proxy. Beispiel: HTTP_PROXY=http://proxy.firma.local:3128 +# Genutzt fuer: Image-Build (dnf/apt/pip), Zertifikat-Tool, Wazuh-Feeds (Schwachstellen, Updates), +# unter Podman auch fuer das Laden der Images. SSH zu den Hosts laeuft nie ueber den Proxy. +# NO_PROXY: zusaetzliche Ausnahmen; die internen Dienstnamen sind immer ausgenommen. +HTTP_PROXY= +HTTPS_PROXY= +NO_PROXY= + # Werden von ./setup.sh zufaellig erzeugt INDEXER_PASSWORD= DASHBOARD_PASSWORD= diff --git a/README.md b/README.md index 7f10b10..fc204c3 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,29 @@ unangetastet. Mit `CONTAINER_ENGINE=docker|podman` lässt sich die Erkennung üb nano hosts.yml # Hosts eintragen (siehe hosts.yml.example) ``` +### Proxy (optional) + +Kommt der Server nur über einen Proxy ins Internet, trägst du ihn in `.env` ein: + +```bash +cp .env.example .env # nur vor dem allerersten ./setup.sh nötig +nano .env # HTTP_PROXY=http://proxy.firma.local:3128, HTTPS_PROXY=..., ggf. NO_PROXY=... +``` + +Alternativ übernimmt `./setup.sh` beim ersten Lauf `HTTP_PROXY`/`HTTPS_PROXY` aus der Shell. +Genutzt wird der Proxy für: + +- Image-Build (`dnf`, `apt`, `pip`) und das Zertifikat-Tool +- Laufzeit: Manager und Dashboard (Schwachstellen-Feeds von cti.wazuh.com, Update-Check) +- Podman: auch für das Laden der Images + +Die internen Dienstnamen (`wazuh.manager`, `wazuh.indexer`, …) sind immer in `NO_PROXY`. SSH +zu den Hosts läuft nie über den Proxy. + +**Docker:** Images lädt der Docker-Daemon, nicht der Container. Ohne Daemon-Proxy gibt +`setup.sh` eine Warnung mit der fertigen systemd-Konfiguration aus. `setup.sh` ändert die nicht +selbst, weil ein Neustart von Docker alle Container auf dem Server neu startet. + ### Red Hat / Podman ```bash diff --git a/docker-compose.yml b/docker-compose.yml index 28848df..b93c2cc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,12 @@ services: dockerfile: manager/Dockerfile args: WAZUH_VERSION: ${WAZUH_VERSION} + HTTP_PROXY: ${HTTP_PROXY} + HTTPS_PROXY: ${HTTPS_PROXY} + NO_PROXY: ${NO_PROXY} + http_proxy: ${HTTP_PROXY} + https_proxy: ${HTTPS_PROXY} + no_proxy: ${NO_PROXY} image: localhost/sshpull/wazuh-manager:${WAZUH_VERSION} hostname: wazuh.manager restart: always @@ -41,6 +47,13 @@ services: - SSL_KEY=/etc/ssl/filebeat.key - API_USERNAME=wazuh-wui - API_PASSWORD=${API_PASSWORD} + # optionaler Proxy (.env); interne Namen nie ueber den Proxy + - HTTP_PROXY=${HTTP_PROXY} + - HTTPS_PROXY=${HTTPS_PROXY} + - NO_PROXY=wazuh.manager,wazuh.indexer,wazuh.dashboard,sshpull.collector,localhost,127.0.0.1,${NO_PROXY} + - http_proxy=${HTTP_PROXY} + - https_proxy=${HTTPS_PROXY} + - no_proxy=wazuh.manager,wazuh.indexer,wazuh.dashboard,sshpull.collector,localhost,127.0.0.1,${NO_PROXY} volumes: - wazuh_api_configuration:/var/ossec/api/configuration - wazuh_etc:/var/ossec/etc @@ -99,6 +112,12 @@ services: - DASHBOARD_PASSWORD=${DASHBOARD_PASSWORD} - API_USERNAME=wazuh-wui - API_PASSWORD=${API_PASSWORD} + - HTTP_PROXY=${HTTP_PROXY} + - HTTPS_PROXY=${HTTPS_PROXY} + - NO_PROXY=wazuh.manager,wazuh.indexer,wazuh.dashboard,sshpull.collector,localhost,127.0.0.1,${NO_PROXY} + - http_proxy=${HTTP_PROXY} + - https_proxy=${HTTPS_PROXY} + - no_proxy=wazuh.manager,wazuh.indexer,wazuh.dashboard,sshpull.collector,localhost,127.0.0.1,${NO_PROXY} volumes: - ./config/wazuh_indexer_ssl_certs/wazuh.dashboard.pem:/usr/share/wazuh-dashboard/certs/wazuh-dashboard.pem:ro,z - ./config/wazuh_indexer_ssl_certs/wazuh.dashboard-key.pem:/usr/share/wazuh-dashboard/certs/wazuh-dashboard-key.pem:ro,z @@ -114,6 +133,13 @@ services: build: context: . dockerfile: collector/Dockerfile + args: + HTTP_PROXY: ${HTTP_PROXY} + HTTPS_PROXY: ${HTTPS_PROXY} + NO_PROXY: ${NO_PROXY} + http_proxy: ${HTTP_PROXY} + https_proxy: ${HTTPS_PROXY} + no_proxy: ${NO_PROXY} image: localhost/sshpull/collector:latest hostname: sshpull.collector restart: always diff --git a/setup.sh b/setup.sh index f840025..63879d0 100755 --- a/setup.sh +++ b/setup.sh @@ -32,6 +32,7 @@ is_root() { [ "$(id -u)" -eq 0 ]; } ENGINE="" DC=() SELINUX=no +PROXY_ARGS=() detect_runtime() { [ -n "$ENGINE" ] && return @@ -71,6 +72,10 @@ detect_runtime() { if command -v getenforce >/dev/null 2>&1 && [ "$(getenforce)" != "Disabled" ]; then SELINUX=yes # docker-compose.yml nutzt ":z" auf allen Bind-Mounts fi + + sync_env_keys + load_proxy + check_docker_proxy } check_rootless() { @@ -96,7 +101,44 @@ set_env() { # set_env KEY VALUE if grep -q "^$1=" .env; then sed -i "s|^$1=.*|$1=$2|" .env; else echo "$1=$2" >> .env; fi } -env_get() { grep "^$1=" .env 2>/dev/null | cut -d= -f2-; } +env_get() { grep "^$1=" .env 2>/dev/null | cut -d= -f2- || true; } + +INTERNAL_NO_PROXY="wazuh.manager,wazuh.indexer,wazuh.dashboard,sshpull.collector,localhost,127.0.0.1" + +sync_env_keys() { + # Neue Schluessel aus .env.example in eine bestehende .env uebernehmen (leer bzw. Default) + [ -f .env ] || return 0 + local line key + while IFS= read -r line; do + [[ $line =~ ^([A-Z_]+)= ]] || continue + key=${BASH_REMATCH[1]} + grep -q "^$key=" .env || { echo "$line" >> .env; info ".env: $key ergaenzt"; } + done < .env.example +} + +load_proxy() { + # Proxy aus .env in die Umgebung dieses Skripts: Podman nutzt ihn fuer Pull und Build, + # "run" reicht ihn an das Zertifikat-Tool weiter. + local hp hsp np + hp=$(env_get HTTP_PROXY); hsp=$(env_get HTTPS_PROXY); np=$(env_get NO_PROXY) + [ -n "$hp$hsp" ] || return 0 + export HTTP_PROXY="$hp" http_proxy="$hp" HTTPS_PROXY="$hsp" https_proxy="$hsp" + export NO_PROXY="$INTERNAL_NO_PROXY${np:+,$np}" no_proxy="$INTERNAL_NO_PROXY${np:+,$np}" + PROXY_ARGS=(-e HTTP_PROXY -e HTTPS_PROXY -e NO_PROXY -e http_proxy -e https_proxy -e no_proxy) +} + +check_docker_proxy() { + # Docker laedt Images ueber den Daemon, nicht ueber die Umgebung dieses Skripts + [ "$ENGINE" = docker ] && [ -n "${HTTPS_PROXY:-}${HTTP_PROXY:-}" ] || return 0 + [ -n "$(docker info --format '{{.HTTPSProxy}}{{.HTTPProxy}}' 2>/dev/null)" ] && return 0 + warn "Proxy in .env gesetzt, aber der Docker-Daemon hat keinen (Image-Pulls brauchen ihn)." + warn "Als root /etc/systemd/system/docker.service.d/http-proxy.conf mit diesem Inhalt anlegen:" + { + echo " [Service]" + echo " Environment=\"HTTP_PROXY=${HTTP_PROXY:-}\" \"HTTPS_PROXY=${HTTPS_PROXY:-}\" \"NO_PROXY=localhost,127.0.0.1\"" + } >&2 + warn "Dann: systemctl daemon-reload && systemctl restart docker (startet alle Container neu)" +} tune_kernel() { local mmc @@ -147,6 +189,7 @@ cmd_info() { echo "SELinux: $SELINUX" echo "root: $(is_root && echo ja || echo nein)" echo "max_map: $(cat /proc/sys/vm/max_map_count)" + echo "Proxy: ${HTTPS_PROXY:-${HTTP_PROXY:-keiner}}${NO_PROXY:+ (NO_PROXY=$NO_PROXY)}" } cmd_init() { @@ -156,7 +199,18 @@ cmd_init() { tune_kernel # --- .env + Passwoerter ------------------------------------------------- - [ -f .env ] || cp .env.example .env + if [ ! -f .env ]; then + cp .env.example .env + # Proxy aus der Shell uebernehmen (z.B. export HTTPS_PROXY=... vor dem ersten Setup) + local k v + for k in HTTP_PROXY HTTPS_PROXY NO_PROXY; do + v=$(printenv "$k" || printenv "${k,,}" || true) + if [ -n "$v" ]; then set_env "$k" "$v"; info ".env: $k aus der Umgebung uebernommen"; fi + done + fi + sync_env_keys + load_proxy + check_docker_proxy for k in INDEXER_PASSWORD DASHBOARD_PASSWORD API_PASSWORD; do if [ -z "$(env_get $k)" ]; then set_env "$k" "$(genpw)"; info "$k erzeugt"; fi done @@ -202,7 +256,7 @@ EOF if [ ! -f config/wazuh_indexer_ssl_certs/root-ca.pem ]; then info "Erzeuge TLS-Zertifikate" mkdir -p config/wazuh_indexer_ssl_certs - engine run --rm \ + engine run --rm "${PROXY_ARGS[@]}" \ -e CERT_TOOL_VERSION="${version%.*}" \ -v "$PWD/config/wazuh_indexer_ssl_certs/:/certificates/:z" \ -v "$PWD/config/certs.yml:/config/certs.yml:ro,z" \