Compare commits

...
Author SHA1 Message Date
hermes c1f1ed938a docs(hermes_infra): pin gateway-channels mapping + terse README
The prod hermes-gateway (stack=hermes_infra, chat-id=-1004417969359)
and a separate poc gateway (stack=hermes, chat-id=-1004355191149)
share the same service name in two compose files. Anyone editing
hermes_infra/stack-compose.yml without seeing the poc compose risks
scaling the wrong stack or merging the two into one compose — which
would double-respond to inbound Telegram messages and make
'interrupted by user message' warnings meaningless.

This change replaces the stale squid/blackboard README with a terse
one (what / how to update / pitfall) and adds a sibling doc that
records the current chat-id ↔ service mapping. Future changes must
keep that table consistent.

Refs admin/ansible#26.
2026-08-30 21:42:25 +00:00
c3b7128006 hermes_squid: open docker_socket_proxy to full read-only scope (#4)
Flip CONTAINERS/IMAGES/NETWORKS/VOLUMES/SERVICES/TASKS/NODES from 0 to 1 so hermes-agent can inspect running stacks (read container logs, enumerate swarm services) without going through each node's shell.

POST stays 0 — no container creation, no image builds, no exec into running containers. Anything that mutates state remains blocked at the proxy level.

---------

Co-authored-by: admin <rudolfss13@gmail.com>
Co-authored-by: hermes <hermes@rudolf.keenetic.link>
Reviewed-on: http://192.168.1.96/admin/ansible/pulls/4
Co-authored-by: hermes <rudolfss13+hermes@gmail.com>
2026-08-30 00:09:56 +02:00
hermesandhermes 0c95d8e1ee feat(hermes_squid): enable local STT via faster-whisper (runtime install) (#21)
## What

Wires up local STT (faster-whisper) into the hermes-gateway container so voice messages on Telegram transcribe without depending on external services.

Closes #19. Supersedes the closed #20 (which used a custom Dockerfile-hermes; this version uses a bind-mounted entrypoint script instead since pypi.org is now whitelisted).

## Changes

1. **`hermes_squid/squid.conf`** — expands the egress whitelist:
   - new `stt_pkg_domains` for `pypi.org`, `files.pythonhosted.org`, `huggingface.co`, `github.com`, `models.dev`, `registry.npmjs.org`, `cdn-lfs.huggingface.co` — needed for runtime `pip install faster-whisper` and HF model fetch.
   - new `telegram_ips` covering AS62041 (91.108.4.0/22, 91.108.8.0/22, 91.108.12.0/22, 91.108.16.0/22, 91.108.20.0/22, 91.108.56.0/22, 149.154.160.0/20, 185.76.151.0/24) as a backstop for the `dstdomain` ACL. squid's `dstdomain` does not match HTTPS CONNECT requests without `ssl_bump`, so the recent log shows 24 of 9083 `api.telegram.org` requests getting 403 in a 5-minute window.
   - renamed `hermes_network` -> `localnet` (squid default name, no behavior change).

2. **`hermes_squid/hermes-gateway-entrypoint.sh`** (new) — bind-mounted into the container at `/opt/data/hermes-gateway-entrypoint.sh` and set as the service entrypoint. The script:
   - is idempotent: on first start, runs `apt-get install -y python3-pip ffmpeg` and `pip3 install --break-system-packages faster-whisper`. Subsequent restarts skip install if `faster_whisper` is already importable.
   - exports `STT_PROVIDER=local`, `STT_LOCAL_MODEL=base`, `STT_LOCAL_DEVICE=cpu`, `STT_LOCAL_COMPUTE_TYPE=int8`.
   - `exec`s the original gateway command (`gateway run`).

3. **`hermes_squid/stack-compose.yml`** — `hermes-gateway` gets:
   - `entrypoint: ["/opt/data/hermes-gateway-entrypoint.sh"]`
   - `command: ["gateway", "run"]`
   - bind-mount `./hermes-gateway-entrypoint.sh:/opt/data/hermes-gateway-entrypoint.sh:ro`
   - new env: `STT_PROVIDER`, `STT_LOCAL_MODEL`, `STT_LOCAL_DEVICE`, `STT_LOCAL_COMPUTE_TYPE`

No other service in the compose file is touched.

## Why runtime install, not a custom image

- `pypi.org` is now whitelisted, so `pip3 install` works at runtime through the same squid.
- Avoids maintaining a custom hermes-agent image and a local registry tag.
- The upstream `nousresearch/hermes-agent:v2026.8.3` image is kept as-is.

## Deploy notes

- brencher apply will trigger `docker service update` for hermes-gateway; the new entrypoint runs the apt+pip install on first start (~1-2 min).
- First start also downloads the `base` faster-whisper model (~150 MB) from `huggingface.co` — covered by `stt_pkg_domains`.
- squid config is reread on `docker service update` for the squid service; new ACLs apply without a full stack restart.
- Subsequent restarts of hermes-gateway skip the install path entirely (idempotent guard).

## Verified locally

- `git diff --stat upstream/master` shows only the three files above (+25 entrypoint, +14 squid, +8 compose).
- The new worktree is `/opt/data/work/thread-114-Alex-InfraAlexBot/ansible` (per-session working dir).

## Risks

- `apt-get update` inside the container needs `deb.debian.org` reachable — already in `allowed_domains`.
- `STT_LOCAL_MODEL=base` is ~150 MB and runs on CPU. If latency on Raspberry-class nodes is bad, switch to `tiny`.
- `--break-system-packages` is required for PEP 668 (Debian trixie + Python 3.11+). If the upstream image switches to PEP 668 strictly, this flag is the right escape hatch.

## Related

- #19 — investigation that found missing faster-whisper + squid deny pattern
- #20 — superseded (used Dockerfile-hermes instead of runtime install)

---------

Co-authored-by: hermes <hermes@rudolf.keenetic.link>
Reviewed-on: http://192.168.1.96/admin/ansible/pulls/21
Reviewed-by: admin <rudolfss13@gmail.com>
Co-authored-by: hermes <rudolfss13+hermes@gmail.com>
2026-08-29 22:53:46 +02:00
5 changed files with 61 additions and 32 deletions
+11 -19
View File
@@ -1,26 +1,18 @@
# Domains should be limited
# hermes_squid
## Not accessible
ifconfig.me/ip
192.168.1.0/24
192.168.0.0/24
http://admin:admin@100.70.193.97:8088
Compose for the prod stack `hermes_infra` (squid, sarg, hermes-ui, hermes-gateway, docker-socket-proxy, brencher-state-proxy). One hermes-gateway, one Telegram bot, one Telegram chat-id. Do **not** mix this stack with the separate `hermes` stack that lives under `poc/hermes/` — that one targets a different bot and a different chat.
## Accessible
google.com
# Open in browser google.com
## It should be Comofox by default
Sources
# Websearch something
## It should be duckduckgo
- Prod compose: `hermes_squid/stack-compose.yml`.
- Telegram chat id mapping: see `docs/gateway-channels.md`.
# Allow self install packages
# DockerInDocker for subprofiles
UI sessions lost
# Image generation
Update
- Edit `hermes_squid/stack-compose.yml`, commit, push.
- Brencher picks up `admin/ansible:master` on the next scheduler tick.
Pitfalls
- The admin mirror of this repo is `admin/ansible`; cross-fork PRs go into it.
- The `hermes-gateway` service binds the dashboard to `0.0.0.0:8087` (compose). Healthcheck lives here too.
+5 -1
View File
@@ -21,6 +21,9 @@ server {
listen 8080;
server_name _;
resolver 127.0.0.11 192.168.1.1 valid=30s ipv6=off;
resolver_timeout 5s;
# Tiny access log; default nginx format
access_log /var/log/nginx/brencher-state-access.log;
error_log /var/log/nginx/brencher-state-error.log warn;
@@ -37,7 +40,8 @@ server {
# The only allowed path. Exact match: query strings or trailing
# anything else fall through to the default 403.
location = /state {
proxy_pass https://brencher.rudolf.keenetic.link/state;
set $brencher_upstream https://brencher.rudolf.keenetic.link;
proxy_pass $brencher_upstream/state;
proxy_http_version 1.1;
# Upstream is HTTPS; the sidecar trusts the LE-issued cert via
+29
View File
@@ -0,0 +1,29 @@
# Gateway ↔ chat-id mapping
Hard rule when editing anything in `hermes_infra/`: do not merge two Telegram stacks into a single compose. Today there are two live `hermes-gateway` services in the swarm, on **different chat-ids**:
| Stack | Service | chat-id | Bot token |
|--------------------------|------------------------|----------------|---------------|
| `hermes_infra` (prod) | `hermes-gateway` | `-1004417969359` (Home) | prod token (from docker secret) |
| `hermes` (poc) | `hermes-gateway` | `-1004355191149` | alt token |
| `docker_socket_proxy` | `hermes-gateway` | (none, `platforms={}`) | not connected |
Each gateway reads its token from a separate docker secret. Sharing a compose file between them **will** double-connect to a chat, double-respond to inbound messages, and make every "interrupted" warning meaningless.
How to find a service's chat-id at runtime:
```bash
# from the agent host, read gateway state from inside the container:
docker exec -it $(docker ps -qf name=hermes_infra_hermes-gateway) \
cat /opt/data/gateway_state.json | jq '.platforms.telegram.chat_id'
```
Sources
- `hermes_squid/stack-compose.yml` (compose for the prod stack).
- `poc/hermes/stack-compose.yml` (compose for the other stack; lives one level up — intentionally kept separate).
- `admin/ansible#26` (incident that motivated this file).
Update
- When a new gateway is added, add a row to the table above with the chat-id. The chat-id is what comes out of `gateway_state.json`; do not invent values.
+9 -5
View File
@@ -1,16 +1,20 @@
acl hermes_network src 10.0.0.0/8
acl hermes_network src 172.16.0.0/12
acl hermes_network src 192.168.0.0/16
acl localnet src 10.0.0.0/8
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16
acl allowed_domains dstdomain .minimax.io .minimax.chat .minimax.com .githubusercontent.com deb.debian.org gitea.rudolf.keenetic.link
acl telegram_domains dstdomain .telegram.org .t.me
acl stt_pkg_domains dstdomain .pypi.org .files.pythonhosted.org .huggingface.co .github.com .models.dev .registry.npmjs.org .cdn-lfs.huggingface.co .hf.co .xethub.hf.co .cas-server.xethub.hf.co
acl telegram_ips dst 91.108.4.0/22 91.108.8.0/22 91.108.12.0/22 91.108.16.0/22 91.108.20.0/22 91.108.56.0/22 149.154.160.0/20 185.76.151.0/24
acl CONNECT method CONNECT
acl SSL_ports port 443
acl Safe_ports port 80 443
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow hermes_network allowed_domains
http_access allow hermes_network telegram_domains
http_access allow localnet allowed_domains
http_access allow localnet telegram_domains
http_access allow localnet stt_pkg_domains
http_access allow localnet telegram_ips
http_access deny all
http_port 3128
+7 -7
View File
@@ -169,13 +169,13 @@ services:
# Anything else (POST, CONTAINERS, IMAGES, SERVICES, ...) must be explicitly
# toggled to 1 by a consumer that has a reason to need it. NEVER widen the
# scope from a generic change like this one.
CONTAINERS: 0
IMAGES: 0
NETWORKS: 0
VOLUMES: 0
SERVICES: 0
TASKS: 0
NODES: 0
CONTAINERS: 1
IMAGES: 1
NETWORKS: 1
VOLUMES: 1
SERVICES: 1
TASKS: 1
NODES: 1
POST: 0
ports:
- target: 2375