noproxy: sofort wirksam machen, und Ziele fuer Dienste

Zwei Luecken im vorherigen Stand.

Erstens war der Eintrag erst in einer neuen Sitzung wirksam. Ein
Programm kann die Umgebung seiner Elternshell nicht aendern - dafuer
gibt es jetzt "noproxy --export", das nur die beiden Zeilen ausgibt:

  eval "$(cmk-manage.sh noproxy --export)"

Danach gilt es sofort; nachgemessen mit curl -v (vorher "Uses proxy env
variable http_proxy", danach "Trying 127.0.0.1"). Der Wert wird dabei
aus denselben Regeln gebildet wie beim Schreiben in eine Datei -
Vorhandenes zuerst, unsere Adressen dahinter, ohne Doppelte.

Zweitens lesen Systemdienste weder profile.d noch .bashrc noch
/etc/environment. Dafuer gibt es zwei weitere Ziele:

  noproxy --fix --environment   ergaenzt /etc/environment, ohne die
                                uebrigen Zeilen anzuruehren
  noproxy --fix --service       schreibt eine Ergaenzung der systemd-Unit
                                des Stacks; der Proxy selbst kommt mit
                                hinein, sonst kaeme der Dienst beim Holen
                                von Images nicht mehr ins Internet

Findet sich keine passende Unit, zeigt der Befehl den Abschnitt zum
Einfuegen von Hand. Die Schreibpfade sind ueber NOPROXY_ENV_FILE und
NOPROXY_UNIT_DIR ueberschreibbar - damit liessen sie sich pruefen, ohne
/etc dieses Rechners anzufassen.

In der Oberflaeche stehen alle vier Ziele zur Auswahl, dazu der
Menuepunkt fuer die laufende Sitzung, der den eval-Befehl zum Kopieren
zeigt.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-20 23:20:56 +02:00
co-authored by Claude Opus 5
parent 467796e23a
commit 20eceda183
3 changed files with 223 additions and 32 deletions
+34 -6
View File
@@ -2551,6 +2551,7 @@ A file chooser with directory navigation is built in.
| `firewall [check\|open\|close]` | check, open, and close again what is no longer needed (firewalld, ufw, nftables, iptables); `close --keep-admin` keeps the admin port open |
| `shell` | root shell in the Checkmk container |
| `omd …` | any `omd` command inside the container |
| `noproxy [--export\|--fix]` | check whether local addresses bypass the HTTP proxy; write it to profile.d, `.bashrc`, `/etc/environment` or the systemd unit |
Global options: `--env-file FILE`, `-y/--yes` (no prompts, e.g. for cron jobs),
`-v/--verbose`.
@@ -2648,13 +2649,40 @@ This is not guessed but read from what `curl -v` reports itself
(`Uses proxy env variable http_proxy == …`) – nothing needs to be listening on
the target address for that.
To make it permanent:
**In the running session** – a program cannot change its parent shell's
environment, hence the detour via `eval`:
```bash
sudo ./scripts/cmk-manage.sh noproxy --fix # /etc/profile.d/cmk-noproxy.sh
./scripts/cmk-manage.sh noproxy --fix --user # ~/.bashrc
eval "$(./scripts/cmk-manage.sh noproxy --export)"
```
**Permanently** – the targets are not mutually exclusive; depending on the
machine you need several:
| Command | takes effect for |
|---|---|
| `sudo … noproxy --fix` | login shells (`/etc/profile.d/cmk-noproxy.sh`) |
| `… noproxy --fix --user` | this user only (`~/.bashrc`) |
| `sudo … noproxy --fix --environment` | logins without a shell (`/etc/environment`) |
| `sudo … noproxy --fix --service` | **system services** – systemd unit drop-in |
The last one is easily overlooked: **system services read neither `profile.d`
nor `.bashrc` nor `/etc/environment`.** If the stack runs under systemd,
`--service` writes a drop-in to
`/etc/systemd/system/checkmk-stack.service.d/cmk-noproxy.conf`:
```ini
[Service]
Environment=no_proxy=localhost,127.0.0.1,::1,checkmk-host,172.0.250.82
Environment=NO_PROXY=localhost,127.0.0.1,::1,checkmk-host,172.0.250.82
Environment=http_proxy=http://proxy.customer.local:3128
Environment=https_proxy=http://proxy.customer.local:3128
```
The proxy itself is carried over – without it the service could not reach the
internet to pull images. If no matching unit exists, the command prints the
section to paste by hand.
**Whatever is already there stays – and stays first.** The entry collects both
spellings (`no_proxy` *and* `NO_PROXY`; some systems only set the uppercase
one), appends the local addresses and drops duplicates:
@@ -2680,9 +2708,9 @@ Runtime und Zeitzone → Lokale Verbindungen prüfen**.
> it deliberately, because in CGI environments an incoming `Proxy:` header
> could set it. The report points this out when only that one is set.
> **Services do not read profile files.** If the stack runs under systemd and a
> proxy is configured there, the exception also belongs in `/etc/environment`
> or in the unit: `Environment=no_proxy=localhost,127.0.0.1,…`
> **Order of operations:** first `noproxy` to look, then write it, then apply it
> to the running session with `eval "$(… noproxy --export)"` – otherwise you
> will wonder why nothing changed.
---