Optionalen HTTP(S)-Proxy ueber .env unterstuetzen

- .env: HTTP_PROXY, HTTPS_PROXY, NO_PROXY (leer = kein Proxy)
- Image-Build: Proxy als Build-Argumente (dnf, apt, pip)
- Laufzeit: Manager und Dashboard bekommen den Proxy (Wazuh-Feeds, Update-Check);
  interne Dienstnamen stehen immer in NO_PROXY
- setup.sh: exportiert den Proxy (Podman-Pulls/-Builds), reicht ihn ans
  Zertifikat-Tool weiter, warnt bei Docker-Daemon ohne Proxy, uebernimmt beim
  ersten Lauf einen Proxy aus der Shell und ergaenzt neue Schluessel in bestehenden .env
- README: Abschnitt Proxy

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
duffyduck
2026-10-07 12:57:55 +02:00
co-authored by Claude Opus 5.5
parent 61232af61c
commit e6aad53fb5
4 changed files with 115 additions and 3 deletions
+57 -3
View File
@@ -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" \