chore: remove NetBird and Authentik layers from homelab
ansible-deploy / plan (push) Successful in 2s
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-mon, ) (push) Successful in 39s
ansible-deploy / deploy (core-net, ) (push) Successful in 57s
ansible-deploy / deploy (core-secrets, ) (push) Successful in 25s
ansible-deploy / deploy (ger-nod-02, ) (push) Successful in 57s
ansible-deploy / deploy (opnsense, ) (push) Successful in 15s
ansible-deploy / plan (push) Successful in 2s
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-mon, ) (push) Successful in 39s
ansible-deploy / deploy (core-net, ) (push) Successful in 57s
ansible-deploy / deploy (core-secrets, ) (push) Successful in 25s
ansible-deploy / deploy (ger-nod-02, ) (push) Successful in 57s
ansible-deploy / deploy (opnsense, ) (push) Successful in 15s
This commit is contained in:
1 parent
6417bdcc75
commit
6a2f90797a
55 files changed
+134
-2460
No files matched your search
@@ -20,11 +20,10 @@ on:
|
||||
- core-net
|
||||
- core-secrets
|
||||
- core-mon
|
||||
- rus-central
|
||||
- ger-nod-02
|
||||
- opnsense
|
||||
tags:
|
||||
description: 'Необязательный фильтр тегов (например: remnawave, netbird, monitoring)'
|
||||
description: 'Необязательный фильтр тегов (например: remnawave, monitoring, xray)'
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
|
||||
@@ -29,7 +29,6 @@ jobs:
|
||||
bash -n ansible/ci/deploy-machine.sh
|
||||
python3 -m py_compile ansible/ci/ansible-plan.py \
|
||||
ansible/roles/core-net/remnawave/files/sync_remnawave.py \
|
||||
ansible/roles/rus-central/netbird/files/sync_access.py \
|
||||
ansible/roles/opnsense/xray/files/vless_to_outbound.py \
|
||||
ansible/roles/opnsense/xray/files/sync_xray.py
|
||||
cd ansible
|
||||
|
||||
+12
-47
@@ -6,13 +6,12 @@
|
||||
|
||||
| Машина | Плейбук | Роли | Каталоги |
|
||||
|---|---|---|---|
|
||||
| `core-net` | `playbooks/core-net.yml` | `roles/core-net/traefik`; `roles/core-net/netbird`; `roles/core-net/remnawave`; `roles/core-net/vmagent`; `roles/core-net/authentik` *(опц., по умолчанию выкл.)* | `/opt/traefik`; клиент NetBird; `/opt/remnawave`; `/opt/vmagent`; `/opt/authentik` *(если включён)* |
|
||||
| `core-net` | `playbooks/core-net.yml` | `roles/core-net/traefik`; `roles/core-net/remnawave`; `roles/core-net/vmagent`; `roles/vector` | `/opt/traefik`; `/opt/remnawave`; `/opt/vmagent`; `/opt/vector` |
|
||||
| `core-secrets` | `playbooks/core-secrets.yml` | `roles/core-secrets/infisical`, `roles/core-secrets/vaultwarden`, `roles/core-secrets/cadvisor` | `/opt/infisical`, `/opt/vaultwarden`, `/opt/cadvisor` |
|
||||
| `core-mon` | `playbooks/core-mon.yml` | `roles/core-mon/monitoring` | `/opt/monitoring` (VictoriaMetrics, vmalert, Grafana) |
|
||||
| `core-git` | `playbooks/core-git.yml` | `roles/core-git/gitea`, `roles/core-git/cadvisor` | `/opt/gitea`, `/opt/cadvisor` |
|
||||
| `rus-central` | `playbooks/rus-central.yml` | `roles/rus-central/netbird`, `roles/rus-central/cadvisor` | `/opt/netbird`, `/opt/cadvisor` |
|
||||
| `ger-nod-02` | `playbooks/ger-nod-02.yml` | `roles/netbird_exit_node`; `roles/remnanode`; `roles/vmagent` | клиент NetBird (Exit Node); `/opt/remnanode`; `/opt/vmagent` |
|
||||
| `opnsense` | `playbooks/opnsense.yml` | `roles/opnsense/netbird`; `roles/opnsense/xray` | REST API (`192.168.1.1:4433`) |
|
||||
| `ger-nod-02` | `playbooks/ger-nod-02.yml` | `roles/remnanode`; `roles/vmagent` | `/opt/remnanode`; `/opt/vmagent` |
|
||||
| `opnsense` | `playbooks/opnsense.yml` | `roles/opnsense/xray` | REST API (`192.168.1.1:4433`) |
|
||||
|
||||
Полная сверка одной машины: `ansible-playbook playbooks/site.yml --limit <машина>`. Боевой Gitea после cutover — `core-git` (`192.168.1.105`). Пайплайны клонируют с `http://192.168.1.105:3000`. CT 109 на `pve` оставлен как rollback, стек на нём остановлен — не удалять, пока не подтверждён стабильный прогон.
|
||||
|
||||
@@ -36,18 +35,15 @@ Terraform в этом репозитории описывает узел `netcor
|
||||
|---|---|---|---|---|
|
||||
| **CT 109** | `pve` | `192.168.1.217` | `gitea` / DNS `gitea-old` | Старый стек остановлен (rollback). Не удалять до проверки |
|
||||
| **CT 901** | `netcore` | `192.168.1.102` | `core-secrets` | Infisical (`:8080`), Postgres, Redis, Vaultwarden (`:8000`) |
|
||||
| **CT 902** | `netcore` | `192.168.1.104` | `core-net` | Traefik (`:80`, `:443`); Remnawave Panel (`127.0.0.1:3000`) + Subscription (`127.0.0.1:3010`); клиент NetBird (нужен `/dev/net/tun`); Authentik (`127.0.0.1:9000`) — опционально, по умолчанию выкл. |
|
||||
| **CT 902** | `netcore` | `192.168.1.104` | `core-net` | Traefik (`:80`, `:443`); Remnawave Panel (`127.0.0.1:3000`) + Subscription (`127.0.0.1:3010`); vmagent (`127.0.0.1:8429`) + cAdvisor (`127.0.0.1:9101`) |
|
||||
| **CT 903** | `netcore` | `192.168.1.108` | `core-mon` | VictoriaMetrics (`:8428`), vmalert (`127.0.0.1:8880`), Alertmanager (`:9093`), Grafana (`:3000`), Ntfy (`:80`) |
|
||||
| **CT 904** | `netcore` | `192.168.1.105` | `core-git` | Gitea (`:3000`, git SSH `:222`), Postgres, Actions Runner (`dind`); cAdvisor (`:9101`) |
|
||||
|
||||
### 1.3. Внешние узлы
|
||||
| Имя | IP | Роль | Стек |
|
||||
|---|---|---|---|
|
||||
| **rus-central** | `45.154.185.208` | Внешний шлюз NetBird | `/opt/netbird`: NetBird и его собственный Traefik |
|
||||
| **ger-nod-02** | `150.241.64.209` | Remnawave Node (DE) + SelfSteal | `/opt/remnanode`: remnanode + nginx (`yali.gunis.top`) |
|
||||
|
||||
Домен панели NetBird задаётся в `ansible/inventories/prod/host_vars/rus-central.yml`.
|
||||
|
||||
Старая панель на Голове (`remna.gunihome.ru`) **не входит** в эту автоматизацию и не трогается.
|
||||
|
||||
`ansible/roles/core-net/traefik/files/dynamic/` — известный бардак: плоский список старых и новых маршрутов. Имена вроде `tv.yml` — это поддомены, а не описание сервиса. Каталог разбирается после того, как вся старая инфраструктура переедет на роли машин. До этого файлы оттуда не переименовывать и не раскладывать. Подробности — в `README.md` внутри каталога.
|
||||
@@ -63,12 +59,12 @@ API Endpoint (внутренний LAN): `http://192.168.1.102:8080/api`
|
||||
### Пути секретов:
|
||||
- `/USER/ADMIN`:
|
||||
- `ADMIN_USER`: имя администратора хоумлаба (по умолчанию `karpenok`).
|
||||
- `ADMIN_PASSWORD`: единый пароль администратора (Traefik Dashboard, Grafana, Ntfy, NetBird).
|
||||
- `MAIL_ADMIN_USER`: почта администратора (для Grafana, NetBird и алертов).
|
||||
- `ADMIN_PASSWORD`: единый пароль администратора (Traefik Dashboard, Grafana, Ntfy).
|
||||
- `MAIL_ADMIN_USER`: почта администратора (для Grafana и алертов).
|
||||
- `/ci-cd`:
|
||||
- `RUNNER_SSH_KEY`: приватный SSH-ключ раннера (ed25519) для деплоя на хосты.
|
||||
- `TF_STATE_TOKEN`: токен доступа к HTTP State Backend Gitea.
|
||||
- `CLOUDFLARE_API`: API-токен Cloudflare (Zone DNS Edit для `gunis.top`, DNS-01 сертификаты ноды).
|
||||
- `CLOUDFLARE_API`: API-токен Cloudflare (Zone DNS Edit для `gunis.top`).
|
||||
- `/services/gitea`:
|
||||
- `POSTGRES_USER` / `POSTGRES_DB` / `POSTGRES_PASSWORD`: учётка БД (пароль же в `GITEA__database__PASSWD`). До cutover — значения боевого инстанса на CT 109.
|
||||
- `GITEA_RUNNER_REGISTRATION_TOKEN`: опционально; после переноса `runner-data/.runner` не нужен.
|
||||
@@ -78,19 +74,6 @@ API Endpoint (внутренний LAN): `http://192.168.1.102:8080/api`
|
||||
- `POSTGRES_PASSWORD`: пароль БД Infisical.
|
||||
- `ENCRYPTION_KEY`: 32-байтный hex-ключ шифрования хранилища.
|
||||
- `AUTH_SECRET`: base64 секрет сессий/JWT Infisical.
|
||||
- `/services/authentik` *(нужен только если включите Authentik)*:
|
||||
- `AUTHENTIK_SECRET_KEY`: случайный ключ шифрования сессий Authentik.
|
||||
- `AUTHENTIK_POSTGRES_PASSWORD`: пароль БД PostgreSQL Authentik.
|
||||
- `/services/netbird`:
|
||||
- `NETBIRD_LETSENCRYPT_EMAIL`: почта для сертификата. Если секрета нет, берётся `letsencrypt_email` из `group_vars/all.yml` или `MAIL_ADMIN_USER`.
|
||||
- `NETBIRD_AUTH_SECRET`: секрет auth.
|
||||
- `NETBIRD_DATASTORE_KEY`: 32-байтный ключ SQLite/datastore.
|
||||
- `NETBIRD_SESSION_KEY`: 32-байтный ключ веб-сессий.
|
||||
- `NETBIRD_API_TOKEN`: сервисный API-токен управления (создаётся и сохраняется пайплайном автоматически).
|
||||
- `NETBIRD_SETUP_KEY`: многоразовый ключ регистрации роутеров (`homelab-routers`). Панель и ноды им не пользуются.
|
||||
- `NETBIRD_REMNAWAVE_SETUP_KEY`: многоразовый ключ `remnawave-peers` для core-net и ger-nod-02. В группу роутеров не входит.
|
||||
- `NETBIRD_EXIT_CLIENTS_SETUP_KEY`: многоразовый ключ `exit-clients-key` для клиентских устройств, выходящих в интернет через Exit Node `ger-nod-02` (группа `exit-clients`). Дополнительные клиентские ключи из `ansible/roles/rus-central/netbird/files/access.yml` сохраняются сюда же по имени поля `secret`.
|
||||
- *(Параметры `NETBIRD_ADMIN_NAME`, `NETBIRD_ADMIN_PASSWORD`, `NETBIRD_ADMIN_EMAIL` наследуются из `/USER/ADMIN`)*.
|
||||
- `/services/opnsense`:
|
||||
- `OPNSENSE_API_KEY`: API-ключ администратора OPNsense.
|
||||
- `OPNSENSE_API_SECRET`: API-секрет администратора OPNsense.
|
||||
@@ -129,7 +112,7 @@ API Endpoint (внутренний LAN): `http://192.168.1.102:8080/api`
|
||||
|
||||
Креденшл роль читает из Infisical сама (`infisical secrets get --plain`), поэтому токен не проходит через переменные Ansible и не может попасть в лог прогона.
|
||||
|
||||
По умолчанию прокси подставляет `Authorization: Bearer <токен>`. Если сервис ждёт другой префикс (NetBird — `Authorization: Token <токен>`), задайте `agent_vault_service_header_prefix: Token`; для Basic-авторизации креденшл задаётся типом `basic`.
|
||||
По умолчанию прокси подставляет `Authorization: Bearer <токен>`. Для Basic-авторизации креденшл задаётся типом `basic`.
|
||||
|
||||
По умолчанию сервис кладётся в бандл `homelab-ops` проекта `homelab-agents`. Запись идёт только в Infisical: прокси подхватывает изменение на следующем poll (60 с), агента перезапускать не нужно. Идентичность пайплайна должна быть **Admin** в этом проекте Agent Vault — иначе регистрация вернёт 403.
|
||||
|
||||
@@ -173,20 +156,11 @@ API Endpoint (внутренний LAN): `http://192.168.1.102:8080/api`
|
||||
### Шаг 4. Traefik (CT 902)
|
||||
1. Запустить пайплайн **`ansible-core-net`** в Gitea Actions. Первый прогон на новом CT должен быть полным: ручной запуск выполняет `site.yml --limit core-net` и ставит Docker ролью `host`.
|
||||
2. Раннер подключается к `http://192.168.1.102:8080/api`, забирает SSH-ключ раннера и `ADMIN_*` из Infisical. Панель Traefik (`proxy.gunihome.ru`) закрывается BasicAuth из `/USER/ADMIN`.
|
||||
3. Плейбук поднимает Traefik на CT 902. Роль Authentik в плейбуке есть, но **по умолчанию выключена** (`authentik_enabled=false` в defaults и в CI): compose не стартует, стек на cold bootstrap не нужен.
|
||||
3. Плейбук поднимает Traefik на CT 902.
|
||||
4. Проверить `https://proxy.gunihome.ru`, `https://gitea.gunihome.ru` и `https://infisical.gunihome.ru`.
|
||||
|
||||
Правка только роли `traefik` ставит эту роль, без повторной подготовки машины.
|
||||
|
||||
#### Authentik (опционально, не часть cold bootstrap)
|
||||
Стек оставляем в репозитории на будущее: SSO/forwardAuth для выбранных приложений, не для всего edge сразу.
|
||||
|
||||
Чтобы включить:
|
||||
1. Положить секреты в Infisical `/services/authentik` (`AUTHENTIK_SECRET_KEY`, `AUTHENTIK_POSTGRES_PASSWORD`).
|
||||
2. Убрать принудительный `-e authentik_enabled=false` из `ansible/ci/deploy-machine.sh` (или передать `authentik_enabled=true` при ручном прогоне) и выставить `authentik_enabled: true`.
|
||||
3. Прогнать `ansible-core-net` (или `--tags authentik`): стек слушает `127.0.0.1:9000`, снаружи — `https://auth.gunihome.ru`. Blueprints заводят группы `admins`/`family` и пользователей `karpenok`/`ksynia`; пароли blueprint не задаёт. Первый запуск создаёт `akadmin` (пароль в логе `authentik-server`).
|
||||
4. На нужных роутерах Traefik повесить middleware `authentik` (forwardAuth из `roles/core-net/traefik/files/dynamic/authentik.yml`) — точечно, не на все сервисы.
|
||||
|
||||
#### Remnawave Panel + Subscription (на core-net)
|
||||
Новая панель рядом с Traefik. Старый `remna.gunihome.ru` на Голове не затрагивается.
|
||||
|
||||
@@ -194,7 +168,7 @@ API Endpoint (внутренний LAN): `http://192.168.1.102:8080/api`
|
||||
- `/ci-cd` → `CLOUDFLARE_API`
|
||||
- `/VPS` → `PASS_GER_NOD_02` (пароль нового VPS)
|
||||
2. Запустить **`ansible-core-net`** (полный прогон или `--tags remnawave` после того, как Traefik уже с роутами `rw`/`sub`).
|
||||
3. Роль поднимает `/opt/remnawave` (panel+db+redis) и `/opt/remnawave/subscription`, создаёт `REMNAWAVE_ADMIN_*`, каждый прогон **перевыпускает** API-токен `infra-automation` и кладёт его в Infisical (старый сразу недействителен). Config profile **`DE-Yali`**, сквад `Default-Squad` на inbound Steal-Yali, нода **`Ger-nod-02`**, host **`yali.gunis.top`**. Пользователи — файл `ansible/roles/core-net/remnawave/files/users.yml` (добавление/изменение/удаление = правка файла). Когда peer `ger-nod-02` уже есть в NetBird, адрес ноды в панели меняется на его NetBird IP. Пока peer нет, остаётся `150.241.64.209`. Ссылка подписки `homelab` пишется в `XRAY_CHECKER_SUBSCRIPTION_URL` и в лог не попадает.
|
||||
3. Роль поднимает `/opt/remnawave` (panel+db+redis) и `/opt/remnawave/subscription`, создаёт `REMNAWAVE_ADMIN_*`, при отсутствии/невалидности выпускает API-токен `infra-automation` и кладёт его в Infisical. Config profile **`DE-Yali`**, сквад `Default-Squad` на inbound Steal-Yali, нода **`Ger-nod-02`** (`150.241.64.209:2222`), host **`yali.gunis.top`**. Пользователи — файл `ansible/roles/core-net/remnawave/files/users.yml` (добавление/изменение/удаление = правка файла). Ссылка подписки `homelab` пишется в `XRAY_CHECKER_SUBSCRIPTION_URL` и в лог не попадает.
|
||||
4. Проверить `https://rw.gunihome.ru` и `https://sub.gunihome.ru`.
|
||||
|
||||
> [!IMPORTANT]
|
||||
@@ -202,15 +176,6 @@ API Endpoint (внутренний LAN): `http://192.168.1.102:8080/api`
|
||||
|
||||
### Шаг 4b. Remnawave Node ger-nod-02 (SelfSteal)
|
||||
1. После успешного `ansible-core-net` (чтобы в Infisical был `REMNANODE_SECRET_KEY`) запустить **`ansible-ger-nod-02`**.
|
||||
2. Первый прогон: как у rus-central — `ansible_password` из `/VPS` → `PASS_GER_NOD_02`; роль `host` кладёт ключ и отключает пароль. Роль `remnanode` держит A-запись `yali.gunis.top` в Cloudflare, выпускает LE по **HTTP-01** (порт 80, без TXT `_acme-challenge` в зоне), поднимает remnanode + nginx SelfSteal.
|
||||
2. Первый прогон: `ansible_password` из `/VPS` → `PASS_GER_NOD_02`; роль `host` кладёт ключ и отключает пароль. Роль `remnanode` держит A-запись `yali.gunis.top` в Cloudflare, выпускает LE по **HTTP-01** (порт 80, без TXT `_acme-challenge` в зоне), поднимает remnanode + nginx SelfSteal.
|
||||
3. В панели нода должна стать зелёной; браузер на `https://yali.gunis.top` — маскировочный сайт.
|
||||
4. Клиент NetBird ходит на `https://central.gunihome.ru` ключом `remnawave-peers`. В UFW открыт `51820/udp` для прямых P2P-туннелей WireGuard, а в `/etc/sysctl.d/99-netbird-exit.conf` зафиксированы `ip_forward=1` и `src_valid_mark=1`: помимо служебного канала `2222` нода входит в группу `exit-ger-nod-02` и работает как Exit Node (`0.0.0.0/0` с маскарадингом) для клиентов из группы `exit-clients`. Пока peer панели не виден, `NODE_PORT` 2222 остаётся открыт для WAN egress панели. Когда peer `core-net` есть, 2222 разрешён только с его NetBird IP. Публичный `:9100` закрыт: метрики ноды уходят vmagent-ом в VictoriaMetrics на `192.168.1.108:8428` через маршрут `homelab-lan`.
|
||||
5. На `core-net` (unprivileged LXC) `/dev/net/tun` сам не появляется. Токен Terraform получает 403: проброс устройства разрешён только `root@pam`. На netcore: `pct set 902 -dev0 /dev/net/tun,mode=0666 && pct reboot 902`, затем ещё раз `ansible-core-net`. До этого панель остаётся на публичном адресе ноды.
|
||||
|
||||
### Шаг 5. NetBird (rus-central) и связка с OPNsense
|
||||
1. Запустить пайплайн **`ansible-rus-central`** в Gitea Actions. Ручной запуск сверяет машину целиком. Push в `roles/rus-central/netbird` ставит только NetBird.
|
||||
2. Раннер считывает ключи из `/services/netbird`, деплоит стек в `/opt/netbird` на `45.154.185.208`, автоматически регистрирует первого суперпользователя (`POST /api/setup`), создаёт сервисный токен (`NETBIRD_API_TOKEN`), группу `homelab-routers`, маршрут к подсети `192.168.1.0/24` и многоразовый ключ установки (`NETBIRD_SETUP_KEY`). Отдельно создаётся группа `remnawave` и ключ `remnawave-peers` (`NETBIRD_REMNAWAVE_SETUP_KEY`): он не добавляет peer в `homelab-routers`. Клиентский доступ (`client_groups`, `exit_nodes`, `dns_nameservers`, `setup_keys`, `peers`) задаётся декларативно в `ansible/roles/rus-central/netbird/files/access.yml` и применяется задачей `tasks/access.yml` (`sync_access.py`):
|
||||
- **Добавить ключ клиента**: дописать новую запись в `setup_keys` (`name`, `secret`, `groups`) и запушить — ключ создастся в NetBird и сохранится в Infisical `/services/netbird`.
|
||||
- **Отозвать ключ**: выставить `enabled: false` (или удалить запись) в `setup_keys`.
|
||||
- **Управлять устройством**: в `peers` можно зафиксировать группы пира (`groups`) или удалить/отключить устройство через `state: absent`.
|
||||
3. Запустить пайплайн **`ansible-opnsense`** в Gitea Actions. Раннер обращается по HTTPS REST API к `192.168.1.1`, проверяет/устанавливает плагин `os-netbird`, включает службу и регистрирует шлюз OPNsense на `https://central.gunihome.ru:443` по `NETBIRD_SETUP_KEY`.
|
||||
4. Служебный порт `NODE_PORT` (`2222/tcp`) и порты метрик (`9100/tcp`, `9101/tcp`) в UFW открыты **только** для WAN egress панели (`213.128.28.107` и `185.160.137.140`). Публичный доступ к метрикам закрыт: `vmagent` на `core-net` забирает их по whitelist и отправляет в VictoriaMetrics на `192.168.1.108:8428`.
|
||||
@@ -101,11 +101,6 @@ if [ "$full" -eq 0 ] && [ -n "$changed" ]; then
|
||||
full_from_files=1
|
||||
fi
|
||||
;;
|
||||
ansible/roles/netbird_client/* | ansible/roles/netbird_exit_node/*)
|
||||
if grep -qE "role: (netbird_client|netbird_exit_node)" "$playbook"; then
|
||||
add_tag netbird
|
||||
fi
|
||||
;;
|
||||
ansible/roles/remnanode/*)
|
||||
if grep -q "role: remnanode" "$playbook"; then
|
||||
add_tag remnanode
|
||||
|
||||
@@ -74,7 +74,6 @@ case "$machine" in
|
||||
export TRAEFIK_DASHBOARD_AUTH="${ADMIN_USER}:${TRAEFIK_HASH}"
|
||||
extra+=(-e "traefik_dashboard_auth=${TRAEFIK_DASHBOARD_AUTH}")
|
||||
fi
|
||||
extra+=(-e "authentik_enabled=false")
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/remnawave" --format=dotenv-export --silent 2>/dev/null || true)"
|
||||
export REMNAWAVE_ADMIN_USER="${REMNAWAVE_ADMIN_USER:-${ADMIN_USER:-karpenok}}"
|
||||
export REMNAWAVE_ADMIN_PASSWORD="${REMNAWAVE_ADMIN_PASSWORD:-}"
|
||||
@@ -84,9 +83,6 @@ case "$machine" in
|
||||
export REMNAWAVE_WEBHOOK_SECRET_HEADER="${REMNAWAVE_WEBHOOK_SECRET_HEADER:-}"
|
||||
export REMNAWAVE_API_TOKEN="${REMNAWAVE_API_TOKEN:-}"
|
||||
export REMNANODE_SECRET_KEY="${REMNANODE_SECRET_KEY:-}"
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/netbird" --format=dotenv-export --silent)"
|
||||
export NETBIRD_API_TOKEN="${NETBIRD_API_TOKEN:-}"
|
||||
export NETBIRD_REMNAWAVE_SETUP_KEY="${NETBIRD_REMNAWAVE_SETUP_KEY:-}"
|
||||
;;
|
||||
core-secrets)
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/infisical" --format=dotenv-export --silent)"
|
||||
@@ -106,31 +102,10 @@ case "$machine" in
|
||||
export OPNSENSE_API_KEY="${OPNSENSE_API_KEY:-}"
|
||||
export OPNSENSE_API_SECRET="${OPNSENSE_API_SECRET:-}"
|
||||
;;
|
||||
rus-central)
|
||||
input_email="${INPUT_LETSENCRYPT_EMAIL:-}"
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/netbird" --format=dotenv-export --silent)"
|
||||
export NETBIRD_AUTH_SECRET="${NETBIRD_AUTH_SECRET:-}"
|
||||
export NETBIRD_DATASTORE_KEY="${NETBIRD_DATASTORE_KEY:-}"
|
||||
export NETBIRD_SESSION_KEY="${NETBIRD_SESSION_KEY:-}"
|
||||
export NETBIRD_ADMIN_EMAIL="${NETBIRD_ADMIN_EMAIL:-${MAIL_ADMIN_USER:-}}"
|
||||
export NETBIRD_ADMIN_NAME="${NETBIRD_ADMIN_NAME:-${ADMIN_USER:-karpenok}}"
|
||||
export NETBIRD_ADMIN_PASSWORD="${NETBIRD_ADMIN_PASSWORD:-${ADMIN_PASSWORD:-}}"
|
||||
export NETBIRD_API_TOKEN="${NETBIRD_API_TOKEN:-}"
|
||||
export NETBIRD_SETUP_KEY="${NETBIRD_SETUP_KEY:-}"
|
||||
export NETBIRD_REMNAWAVE_SETUP_KEY="${NETBIRD_REMNAWAVE_SETUP_KEY:-}"
|
||||
if [ -n "$input_email" ]; then
|
||||
NETBIRD_LETSENCRYPT_EMAIL="$input_email"
|
||||
fi
|
||||
if [ -n "${NETBIRD_LETSENCRYPT_EMAIL:-}" ]; then
|
||||
extra+=(-e "netbird_letsencrypt_email=${NETBIRD_LETSENCRYPT_EMAIL}")
|
||||
fi
|
||||
;;
|
||||
opnsense)
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/netbird" --format=dotenv-export --silent)"
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/opnsense" --format=dotenv-export --silent)"
|
||||
# VLESS-ссылки подписок Xray (роль opnsense/xray; ключи — в instances.yml).
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/opnsense-xray" --format=dotenv-export --silent 2>/dev/null || true)"
|
||||
export NETBIRD_SETUP_KEY="${NETBIRD_SETUP_KEY:-}"
|
||||
export OPNSENSE_API_KEY="${OPNSENSE_API_KEY:-}"
|
||||
export OPNSENSE_API_SECRET="${OPNSENSE_API_SECRET:-}"
|
||||
;;
|
||||
@@ -141,9 +116,6 @@ case "$machine" in
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/VPS" --format=dotenv-export --silent)"
|
||||
# CLOUDFLARE_API уже из /ci-cd выше (только A-запись, без DNS-01).
|
||||
export REMNANODE_SECRET_KEY="${REMNANODE_SECRET_KEY:-}"
|
||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/netbird" --format=dotenv-export --silent 2>/dev/null || true)"
|
||||
export NETBIRD_API_TOKEN="${NETBIRD_API_TOKEN:-}"
|
||||
export NETBIRD_REMNAWAVE_SETUP_KEY="${NETBIRD_REMNAWAVE_SETUP_KEY:-}"
|
||||
export CLOUDFLARE_API="${CLOUDFLARE_API:-}"
|
||||
pass_var="PASS_${machine^^}"
|
||||
pass_var="${pass_var//-/_}"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
---
|
||||
opnsense_host: "192.168.1.1:4433"
|
||||
opnsense_netbird_management_url: "https://central.gunihome.ru:443"
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
---
|
||||
netbird_domain: central.gunihome.ru
|
||||
@@ -2,8 +2,7 @@
|
||||
# Scrape node-exporter (:9100) центральным vmagent: все записи ниже,
|
||||
# кроме monitoring_scrape_exclude_hosts, хостов с monitoring_scrape_enabled: false
|
||||
# и хостов из vmagent_central_scrape_skip (у них свой vmagent).
|
||||
# ger-nod-02 отдаёт метрики своим vmagent.
|
||||
# Выходные ноды Remnawave: имя с «-nod-», группы remnanodes и exit_nodes.
|
||||
# Выходные ноды Remnawave: имя с «-nod-», группа remnanodes.
|
||||
all:
|
||||
hosts:
|
||||
core-net:
|
||||
@@ -18,9 +17,6 @@ all:
|
||||
core-git:
|
||||
ansible_host: 192.168.1.105
|
||||
ansible_user: root
|
||||
rus-central:
|
||||
ansible_host: 45.154.185.208
|
||||
ansible_user: root
|
||||
ger-nod-02:
|
||||
ansible_host: 150.241.64.209
|
||||
ansible_user: root
|
||||
@@ -31,6 +27,3 @@ all:
|
||||
remnanodes:
|
||||
hosts:
|
||||
ger-nod-02:
|
||||
exit_nodes:
|
||||
hosts:
|
||||
ger-nod-02:
|
||||
@@ -5,15 +5,53 @@
|
||||
roles:
|
||||
- role: core-net/traefik
|
||||
tags: [traefik]
|
||||
- role: core-net/authentik
|
||||
tags: [authentik]
|
||||
- role: core-net/vmagent
|
||||
tags: [vmagent]
|
||||
- role: core-net/netbird
|
||||
tags: [netbird]
|
||||
- role: vector
|
||||
tags: [vector]
|
||||
tasks:
|
||||
- name: Удалить остатки NetBird и Authentik на core-net
|
||||
tags: [always]
|
||||
block:
|
||||
- name: Проверить наличие клиента NetBird
|
||||
ansible.builtin.stat:
|
||||
path: /usr/bin/netbird
|
||||
register: core_net_nb_bin
|
||||
|
||||
- name: Отключить и остановить NetBird
|
||||
ansible.builtin.command: netbird down
|
||||
when: core_net_nb_bin.stat.exists
|
||||
changed_when: true
|
||||
failed_when: false
|
||||
|
||||
- name: Удалить пакет netbird
|
||||
ansible.builtin.apt:
|
||||
name: netbird
|
||||
state: absent
|
||||
purge: true
|
||||
when: core_net_nb_bin.stat.exists
|
||||
|
||||
- name: Остановить и удалить контейнеры Authentik (если остались)
|
||||
ansible.builtin.stat:
|
||||
path: /opt/authentik/compose.yaml
|
||||
register: core_net_authentik_compose
|
||||
|
||||
- name: Остановить стек Authentik
|
||||
ansible.builtin.command: docker compose -f /opt/authentik/compose.yaml down -v --remove-orphans
|
||||
when: core_net_authentik_compose.stat.exists
|
||||
changed_when: true
|
||||
failed_when: false
|
||||
|
||||
- name: Удалить файлы и каталоги NetBird и Authentik
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /etc/apt/sources.list.d/netbird.list
|
||||
- /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||
- /etc/netbird
|
||||
- /var/lib/netbird
|
||||
- /opt/authentik
|
||||
- name: Развернуть панель Remnawave
|
||||
ansible.builtin.import_role:
|
||||
name: core-net/remnawave
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
hosts: ger-nod-02
|
||||
gather_facts: false
|
||||
roles:
|
||||
- role: netbird_exit_node
|
||||
tags: [netbird]
|
||||
- role: remnanode
|
||||
tags: [remnanode]
|
||||
- role: vmagent
|
||||
|
||||
@@ -2,9 +2,50 @@
|
||||
- name: Маршрутизатор OPNsense
|
||||
hosts: opnsense
|
||||
gather_facts: false
|
||||
pre_tasks:
|
||||
- name: Проверить наличие плагина os-netbird на OPNsense
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/service/status"
|
||||
method: GET
|
||||
url_username: "{{ lookup('env', 'OPNSENSE_API_KEY') }}"
|
||||
url_password: "{{ lookup('env', 'OPNSENSE_API_SECRET') }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: [200, 404]
|
||||
register: opnsense_nb_check
|
||||
tags: [always]
|
||||
|
||||
- name: Остановить службу NetBird на OPNsense перед удалением плагина
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/service/stop"
|
||||
method: POST
|
||||
url_username: "{{ lookup('env', 'OPNSENSE_API_KEY') }}"
|
||||
url_password: "{{ lookup('env', 'OPNSENSE_API_SECRET') }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
body: {}
|
||||
status_code: [200]
|
||||
when: opnsense_nb_check.status == 200 and (opnsense_nb_check.json.status | default('')) == 'running'
|
||||
changed_when: true
|
||||
failed_when: false
|
||||
tags: [always]
|
||||
|
||||
- name: Удалить плагин os-netbird из OPNsense
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/core/firmware/remove/os-netbird"
|
||||
method: POST
|
||||
url_username: "{{ lookup('env', 'OPNSENSE_API_KEY') }}"
|
||||
url_password: "{{ lookup('env', 'OPNSENSE_API_SECRET') }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
body: {}
|
||||
status_code: [200]
|
||||
when: opnsense_nb_check.status == 200
|
||||
changed_when: true
|
||||
tags: [always]
|
||||
roles:
|
||||
- role: opnsense/netbird
|
||||
tags: [netbird]
|
||||
- role: opnsense/xray
|
||||
tags: [xray]
|
||||
post_tasks:
|
||||
@@ -15,7 +56,7 @@
|
||||
agent_vault_service_name: opnsense
|
||||
agent_vault_service_description: >-
|
||||
Маршрутизатор OPNsense (opnsense.gunihome.ru): статус системы, интерфейсы,
|
||||
правила фаервола, маршруты, NetBird и Xray. Read-only доступ (GET) через
|
||||
правила фаервола, маршруты и Xray. Read-only доступ (GET) через
|
||||
Basic Auth (OPNSENSE_API_KEY / OPNSENSE_API_SECRET).
|
||||
agent_vault_service_host: "opnsense.gunihome.ru:443"
|
||||
agent_vault_service_paths: ["/api"]
|
||||
@@ -24,4 +65,4 @@
|
||||
agent_vault_secret_path: /services/opnsense
|
||||
agent_vault_secret_username_key: OPNSENSE_API_KEY
|
||||
agent_vault_secret_password_key: OPNSENSE_API_SECRET
|
||||
tags: [agent_vault, netbird, xray]
|
||||
tags: [agent_vault, xray]
|
||||
@@ -3,8 +3,6 @@
|
||||
hosts: remnanodes
|
||||
gather_facts: false
|
||||
roles:
|
||||
- role: netbird_exit_node
|
||||
tags: [netbird]
|
||||
- role: remnanode
|
||||
tags: [remnanode]
|
||||
- role: vmagent
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
- name: VPS rus-central, NetBird
|
||||
hosts: rus-central
|
||||
gather_facts: false
|
||||
roles:
|
||||
- role: rus-central/netbird
|
||||
tags: [netbird]
|
||||
- role: rus-central/cadvisor
|
||||
tags: [cadvisor]
|
||||
@@ -4,6 +4,5 @@
|
||||
- ansible.builtin.import_playbook: core-secrets.yml
|
||||
- ansible.builtin.import_playbook: core-mon.yml
|
||||
- ansible.builtin.import_playbook: core-git.yml
|
||||
- ansible.builtin.import_playbook: rus-central.yml
|
||||
- ansible.builtin.import_playbook: remnanodes.yml
|
||||
- ansible.builtin.import_playbook: opnsense.yml
|
||||
@@ -31,7 +31,6 @@ vmagent_cluster: homelab
|
||||
monitoring_cadvisor_port: 9101
|
||||
monitoring_cadvisor_scrape_hosts:
|
||||
- core-secrets
|
||||
- rus-central
|
||||
- core-git
|
||||
|
||||
grafana_admin_user: "{{ lookup('ansible.builtin.env', 'ADMIN_USER', default='karpenok') }}"
|
||||
|
||||
@@ -251,7 +251,7 @@
|
||||
"gridPos": { "h": 6, "w": 12, "x": 12, "y": 23 },
|
||||
"id": 13,
|
||||
"options": { "colorMode": "background", "graphMode": "none", "justifyMode": "auto", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "value_and_name" },
|
||||
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_service_running{name=~\"unbound|xray|netbird|dhcpd|pf|node_exporter\"}", "legendFormat": "{{name}}", "refId": "A" }],
|
||||
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_service_running{name=~\"unbound|xray|dhcpd|pf|node_exporter\"}", "legendFormat": "{{name}}", "refId": "A" }],
|
||||
"title": "OPNsense Services",
|
||||
"type": "stat"
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ groups:
|
||||
(
|
||||
time() - tlast_over_time(up{job="integrations/node_exporter"}[30m]) > 180
|
||||
)
|
||||
[% for h in (['core-mon', 'core-net', 'core-secrets', 'rus-central'] + (groups['exit_nodes'] | default([]))) | unique | sort %]
|
||||
[% for h in (['core-mon', 'core-net', 'core-secrets', 'core-git'] + (groups['remnanodes'] | default([]))) | unique | sort %]
|
||||
or absent_over_time(up{job="integrations/node_exporter",instance="[[ h ]]"}[30m])
|
||||
[% endfor %]
|
||||
for: 1m
|
||||
@@ -137,7 +137,7 @@ groups:
|
||||
(
|
||||
time() - tlast_over_time(up{job="integrations/cAdvisor"}[30m]) > 180
|
||||
)
|
||||
[% for h in (['core-mon', 'core-net', 'core-secrets', 'rus-central'] + (groups['exit_nodes'] | default([]))) | unique | sort %]
|
||||
[% for h in (['core-mon', 'core-net', 'core-secrets', 'core-git'] + (groups['remnanodes'] | default([]))) | unique | sort %]
|
||||
or absent_over_time(up{job="integrations/cAdvisor",instance="[[ h ]]"}[30m])
|
||||
[% endfor %]
|
||||
for: 1m
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
authentik_version: "2024.12.3"
|
||||
authentik_dir: "/opt/authentik"
|
||||
authentik_enabled: false
|
||||
authentik_http_port: 9000
|
||||
authentik_secret_key: "{{ lookup('env', 'AUTHENTIK_SECRET_KEY') }}"
|
||||
authentik_postgres_password: "{{ lookup('env', 'AUTHENTIK_POSTGRES_PASSWORD') }}"
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# yaml-language-server: $schema=https://goauthentik.io/blueprints/schema.json
|
||||
# Каталог пользователей. Пароли не задаются: их выставляет суперадмин в интерфейсе.
|
||||
version: 1
|
||||
metadata:
|
||||
name: homelab-directory
|
||||
labels:
|
||||
blueprints.goauthentik.io/description: "Группы admins и family"
|
||||
entries:
|
||||
- model: authentik_core.group
|
||||
id: admins
|
||||
identifiers:
|
||||
name: admins
|
||||
|
||||
- model: authentik_core.group
|
||||
id: family
|
||||
identifiers:
|
||||
name: family
|
||||
|
||||
- model: authentik_core.user
|
||||
identifiers:
|
||||
username: karpenok
|
||||
attrs:
|
||||
name: karpenok
|
||||
is_active: true
|
||||
is_superuser: true
|
||||
groups:
|
||||
- !Find [authentik_core.group, [name, "authentik Admins"]]
|
||||
- !KeyOf admins
|
||||
- !KeyOf family
|
||||
|
||||
- model: authentik_core.user
|
||||
identifiers:
|
||||
username: ksynia
|
||||
attrs:
|
||||
name: ksynia
|
||||
is_active: true
|
||||
is_superuser: false
|
||||
groups:
|
||||
- !KeyOf family
|
||||
@@ -1,49 +0,0 @@
|
||||
# yaml-language-server: $schema=https://goauthentik.io/blueprints/schema.json
|
||||
version: 1
|
||||
metadata:
|
||||
name: traefik-dashboard
|
||||
labels:
|
||||
blueprints.goauthentik.io/description: "Панель Traefik только для группы admins"
|
||||
entries:
|
||||
- model: authentik_core.group
|
||||
id: group-admins
|
||||
identifiers:
|
||||
name: admins
|
||||
|
||||
- model: authentik_providers_proxy.proxyprovider
|
||||
id: provider-traefik-dashboard
|
||||
identifiers:
|
||||
name: traefik-dashboard
|
||||
attrs:
|
||||
mode: forward_single
|
||||
external_host: https://proxy.gunihome.ru
|
||||
authorization_flow: !Find [authentik_flows.flow, [slug, default-provider-authorization-implicit-consent]]
|
||||
invalidation_flow: !Find [authentik_flows.flow, [slug, default-provider-invalidation-flow]]
|
||||
|
||||
- model: authentik_core.application
|
||||
id: app-traefik-dashboard
|
||||
identifiers:
|
||||
slug: traefik-dashboard
|
||||
attrs:
|
||||
name: Traefik
|
||||
meta_launch_url: https://proxy.gunihome.ru
|
||||
policy_engine_mode: any
|
||||
provider: !KeyOf provider-traefik-dashboard
|
||||
|
||||
- model: authentik_policies.policybinding
|
||||
identifiers:
|
||||
order: 0
|
||||
target: !KeyOf app-traefik-dashboard
|
||||
attrs:
|
||||
group: !KeyOf group-admins
|
||||
|
||||
- model: authentik_outposts.outpost
|
||||
identifiers:
|
||||
name: authentik Embedded Outpost
|
||||
attrs:
|
||||
type: proxy
|
||||
service_connection: null
|
||||
config:
|
||||
authentik_host: https://auth.gunihome.ru
|
||||
providers:
|
||||
- !KeyOf provider-traefik-dashboard
|
||||
@@ -1,75 +0,0 @@
|
||||
---
|
||||
- name: Остановить Authentik если сервис отключен
|
||||
when: not (authentik_enabled | bool)
|
||||
block:
|
||||
- name: Проверить наличие compose.yaml для Authentik
|
||||
ansible.builtin.stat:
|
||||
path: "{{ authentik_dir }}/compose.yaml"
|
||||
register: authentik_compose_stat
|
||||
|
||||
- name: Остановить контейнеры Authentik
|
||||
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml stop
|
||||
when: authentik_compose_stat.stat.exists
|
||||
register: compose_stop
|
||||
changed_when: "'Stopping' in compose_stop.stderr or 'Stopped' in compose_stop.stderr"
|
||||
failed_when: false
|
||||
|
||||
- name: Управление сервисом Authentik
|
||||
when: authentik_enabled | bool
|
||||
block:
|
||||
- name: Создать каталоги для сервиса Authentik с корректными правами
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
owner: "{{ item.owner }}"
|
||||
group: "{{ item.group }}"
|
||||
mode: "{{ item.mode }}"
|
||||
loop:
|
||||
- { path: "{{ authentik_dir }}", owner: "root", group: "root", mode: "0755" }
|
||||
- { path: "{{ authentik_dir }}/db", owner: "70", group: "70", mode: "0700" }
|
||||
- { path: "{{ authentik_dir }}/redis", owner: "999", group: "999", mode: "0700" }
|
||||
- { path: "{{ authentik_dir }}/media", owner: "1000", group: "1000", mode: "0775" }
|
||||
- { path: "{{ authentik_dir }}/custom-templates", owner: "1000", group: "1000", mode: "0775" }
|
||||
- { path: "{{ authentik_dir }}/blueprints", owner: "root", group: "root", mode: "0755" }
|
||||
|
||||
- name: Проверить наличие обязательных секретов Authentik
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- authentik_secret_key is defined and authentik_secret_key | length > 0
|
||||
- authentik_postgres_password is defined and authentik_postgres_password | length > 0
|
||||
fail_msg: "Один или несколько секретов Authentik (AUTHENTIK_SECRET_KEY, AUTHENTIK_POSTGRES_PASSWORD) не переданы!"
|
||||
|
||||
- name: Установить compose.yaml для Authentik
|
||||
ansible.builtin.template:
|
||||
src: compose.yaml.j2
|
||||
dest: "{{ authentik_dir }}/compose.yaml"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
no_log: true
|
||||
|
||||
- name: Синхронизировать статические blueprints Authentik
|
||||
ansible.builtin.copy:
|
||||
src: blueprints/
|
||||
dest: "{{ authentik_dir }}/blueprints/"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
register: authentik_blueprint
|
||||
|
||||
- name: Запустить сервисы Authentik через Docker Compose
|
||||
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml up -d --remove-orphans
|
||||
register: compose_up
|
||||
changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr or 'Pulled' in compose_up.stderr"
|
||||
|
||||
- name: Перезапустить воркер Authentik при обновлении blueprints
|
||||
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml restart authentik-worker
|
||||
when: authentik_blueprint.changed and not compose_up.changed
|
||||
|
||||
- name: Применить blueprints Authentik в authentik-server
|
||||
ansible.builtin.command: >
|
||||
docker compose -f {{ authentik_dir }}/compose.yaml exec -T authentik-server
|
||||
ak apply_blueprint /blueprints/custom/traefik-dashboard.yaml
|
||||
when: authentik_blueprint.changed or compose_up.changed
|
||||
register: apply_blueprints_cmd
|
||||
changed_when: true
|
||||
@@ -1,96 +0,0 @@
|
||||
services:
|
||||
authentik-db:
|
||||
image: postgres:16-alpine
|
||||
container_name: authentik-db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_PASSWORD: {{ authentik_postgres_password | to_json }}
|
||||
POSTGRES_USER: authentik
|
||||
POSTGRES_DB: authentik
|
||||
volumes:
|
||||
- {{ authentik_dir }}/db:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -d authentik -U authentik"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
networks:
|
||||
- authentik-net
|
||||
|
||||
authentik-redis:
|
||||
image: redis:8-alpine
|
||||
container_name: authentik-redis
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- {{ authentik_dir }}/redis:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
networks:
|
||||
- authentik-net
|
||||
|
||||
authentik-server:
|
||||
image: ghcr.io/goauthentik/server:{{ authentik_version }}
|
||||
container_name: authentik-server
|
||||
restart: unless-stopped
|
||||
command: server
|
||||
environment:
|
||||
AUTHENTIK_REDIS__HOST: authentik-redis
|
||||
AUTHENTIK_POSTGRESQL__HOST: authentik-db
|
||||
AUTHENTIK_POSTGRESQL__USER: authentik
|
||||
AUTHENTIK_POSTGRESQL__NAME: authentik
|
||||
AUTHENTIK_POSTGRESQL__PASSWORD: {{ authentik_postgres_password | to_json }}
|
||||
AUTHENTIK_SECRET_KEY: {{ authentik_secret_key | to_json }}
|
||||
AUTHENTIK_DISABLE_UPDATE_CHECK: "true"
|
||||
AUTHENTIK_DISABLE_STARTUP_ANALYTICS: "true"
|
||||
AUTHENTIK_ERROR_REPORTING__ENABLED: "false"
|
||||
AUTHENTIK_OUTPOSTS__DISCOVER: "false"
|
||||
volumes:
|
||||
- {{ authentik_dir }}/media:/media
|
||||
- {{ authentik_dir }}/custom-templates:/templates
|
||||
- {{ authentik_dir }}/blueprints:/blueprints/custom:ro
|
||||
ports:
|
||||
- "127.0.0.1:{{ authentik_http_port }}:9000"
|
||||
depends_on:
|
||||
authentik-db:
|
||||
condition: service_healthy
|
||||
authentik-redis:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- authentik-net
|
||||
|
||||
authentik-worker:
|
||||
image: ghcr.io/goauthentik/server:{{ authentik_version }}
|
||||
container_name: authentik-worker
|
||||
restart: unless-stopped
|
||||
command: worker
|
||||
environment:
|
||||
AUTHENTIK_REDIS__HOST: authentik-redis
|
||||
AUTHENTIK_POSTGRESQL__HOST: authentik-db
|
||||
AUTHENTIK_POSTGRESQL__USER: authentik
|
||||
AUTHENTIK_POSTGRESQL__NAME: authentik
|
||||
AUTHENTIK_POSTGRESQL__PASSWORD: {{ authentik_postgres_password | to_json }}
|
||||
AUTHENTIK_SECRET_KEY: {{ authentik_secret_key | to_json }}
|
||||
AUTHENTIK_DISABLE_UPDATE_CHECK: "true"
|
||||
AUTHENTIK_DISABLE_STARTUP_ANALYTICS: "true"
|
||||
AUTHENTIK_ERROR_REPORTING__ENABLED: "false"
|
||||
AUTHENTIK_OUTPOSTS__DISCOVER: "false"
|
||||
volumes:
|
||||
- {{ authentik_dir }}/media:/media
|
||||
- {{ authentik_dir }}/custom-templates:/templates
|
||||
- {{ authentik_dir }}/blueprints:/blueprints/custom:ro
|
||||
depends_on:
|
||||
authentik-db:
|
||||
condition: service_healthy
|
||||
authentik-redis:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- authentik-net
|
||||
|
||||
networks:
|
||||
authentik-net:
|
||||
name: authentik-net
|
||||
driver: bridge
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
---
|
||||
- name: Клиент NetBird на панели
|
||||
ansible.builtin.include_role:
|
||||
name: netbird_client
|
||||
@@ -26,7 +26,6 @@ remnawave_metrics_pass: "{{ lookup('env', 'REMNAWAVE_METRICS_PASS', default='')
|
||||
remnawave_webhook_secret: "{{ lookup('env', 'REMNAWAVE_WEBHOOK_SECRET_HEADER', default='') }}"
|
||||
remnawave_api_token: "{{ lookup('env', 'REMNAWAVE_API_TOKEN', default='') }}"
|
||||
|
||||
remnawave_netbird_peers_url: "https://central.gunihome.ru/api/peers"
|
||||
remnawave_xray_checker_user: "homelab"
|
||||
remnawave_api_token_name: "infra-automation"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Шаблоны команд Remnawave API. Новый однотипный ресурс — шаг здесь.
|
||||
# prepare/compare_with/after/run — короткие хуки в sync_remnawave.py
|
||||
# (ключ Reality, адрес NetBird, uuid профилей, правило Browser, пользователи).
|
||||
# (ключ Reality, uuid профилей, правило Browser, пользователи).
|
||||
# {поле} подставляется из элемента. Целая строка "{поле}" сохраняет тип (объект, список).
|
||||
steps:
|
||||
- id: xray_templates
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Желаемое состояние панели Remnawave.
|
||||
# Новая выходная нода: запись в nodes, профиль (если новый), сквад, хост в inventory
|
||||
# (группы remnanodes и exit_nodes, имя с «-nod-»). Повторный прогон панели — тег remnawave_sync,
|
||||
# (группа remnanodes, имя с «-nod-»). Повторный прогон панели — тег remnawave_sync,
|
||||
# без pull образов. Сквад, нода, host и профиль, которых здесь нет, с панели удаляются.
|
||||
# Тег inbound уникален среди профилей.
|
||||
|
||||
@@ -25,7 +25,7 @@ subscription_page_config: Homelab
|
||||
nodes:
|
||||
- name: Ger-nod-02
|
||||
address: "150.241.64.209"
|
||||
netbird_hostname: ger-nod-02
|
||||
hostname: ger-nod-02
|
||||
port: 2222
|
||||
country_code: DE
|
||||
profile: DE-Yali
|
||||
|
||||
@@ -71,36 +71,6 @@ class RemnawaveAPI:
|
||||
return status, data
|
||||
|
||||
|
||||
def resolve_netbird_peers(peers_url: str, nb_token: str) -> dict[str, str]:
|
||||
if not peers_url or not nb_token:
|
||||
return {}
|
||||
proc = subprocess.run(
|
||||
["curl", "-fsS", "--max-time", "20", "-H", f"Authorization: Token {nb_token}", peers_url],
|
||||
capture_output=True,
|
||||
check=False,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
return {}
|
||||
try:
|
||||
raw = json.loads(proc.stdout.decode("utf-8", errors="replace"))
|
||||
except json.JSONDecodeError:
|
||||
return {}
|
||||
peers = raw if isinstance(raw, list) else (raw.get("items") or raw.get("peers") or [])
|
||||
mapping: dict[str, str] = {}
|
||||
ip_re = re.compile(r"^\d+\.\d+\.\d+\.\d+$")
|
||||
for peer in peers:
|
||||
if not isinstance(peer, dict):
|
||||
continue
|
||||
ip = str(peer.get("ip") or "").strip()
|
||||
if not ip_re.match(ip):
|
||||
continue
|
||||
for key in ("hostname", "name", "dns_label"):
|
||||
val = str(peer.get(key) or "").strip()
|
||||
if val and val not in mapping:
|
||||
mapping[val] = ip
|
||||
return mapping
|
||||
|
||||
|
||||
def _extract_list(resp: Any, *keys: str) -> list[dict[str, Any]]:
|
||||
if isinstance(resp, dict):
|
||||
inner = resp.get("response", resp)
|
||||
@@ -197,14 +167,8 @@ class Sync:
|
||||
self.refs: dict[str, dict[str, dict[str, Any]]] = {}
|
||||
self.inbounds: dict[str, dict[str, Any]] = {}
|
||||
self.xray_url = ""
|
||||
self.peers: dict[str, str] = {}
|
||||
|
||||
def run(self) -> dict[str, Any]:
|
||||
if self.cfg.get("netbird_connected"):
|
||||
self.peers = resolve_netbird_peers(
|
||||
self.cfg.get("netbird_peers_url", ""),
|
||||
os.environ.get("NB_API_TOKEN", "").strip(),
|
||||
)
|
||||
pending: list[tuple[dict[str, Any], list[dict[str, Any]], set[tuple[Any, ...]]]] = []
|
||||
later = [step for step in self.commands if step.get("run")]
|
||||
for step in self.commands:
|
||||
@@ -388,13 +352,7 @@ class Sync:
|
||||
inbound = self.inbounds.get(profile["inbound_tag"])
|
||||
if not inbound or not inbound.get("uuid"):
|
||||
raise RuntimeError(f"Нет inbound {profile.get('inbound_tag')} у профиля {item['profile']}")
|
||||
host = item.get("netbird_hostname") or ""
|
||||
address = item["address"]
|
||||
if self.cfg.get("netbird_connected") and host and host in self.peers:
|
||||
address = self.peers[host]
|
||||
elif host:
|
||||
self.warnings.append(f"node {item['name']}: fallback-адрес {address} (NetBird peer {host} недоступен)")
|
||||
item["address"] = address
|
||||
item["address"] = item["address"]
|
||||
item["port"] = int(item["port"])
|
||||
item["countryCode"] = item["country_code"]
|
||||
item["configProfile"] = {
|
||||
@@ -652,8 +610,6 @@ def _selftest() -> None:
|
||||
cfg = {
|
||||
"panel_domain": "panel.example",
|
||||
"sub_domain": "sub.example",
|
||||
"netbird_connected": True,
|
||||
"netbird_peers_url": "",
|
||||
"xray_checker_user": "homelab",
|
||||
"desired": {
|
||||
"xray_templates": [{"name": "Except-RU", "templateType": "XRAY_JSON", "file": "xray-except-ru.json"}],
|
||||
@@ -669,7 +625,7 @@ def _selftest() -> None:
|
||||
"nodes": [{
|
||||
"name": "Ger-nod-02",
|
||||
"address": "150.241.64.209",
|
||||
"netbird_hostname": "ger-nod-02",
|
||||
"hostname": "ger-nod-02",
|
||||
"port": 2222,
|
||||
"country_code": "DE",
|
||||
"profile": "DE-Yali",
|
||||
@@ -702,7 +658,6 @@ def _selftest() -> None:
|
||||
return status, data
|
||||
|
||||
globals()["_rest"] = wrapped_rest
|
||||
os.environ["NB_API_TOKEN"] = ""
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
os.environ["RW_XRAY_URL_FILE"] = str(pathlib.Path(tmp) / "url")
|
||||
first = Sync(cfg, Fake()).run()
|
||||
|
||||
@@ -5,12 +5,6 @@
|
||||
remnawave_users_cfg: "{{ lookup('file', role_path ~ '/files/users.yml') | from_yaml }}"
|
||||
remnawave_commands: "{{ lookup('file', role_path ~ '/files/commands.yml') | from_yaml }}"
|
||||
|
||||
- name: Проверить, что панель сама в NetBird
|
||||
ansible.builtin.command: netbird status
|
||||
register: remnawave_local_netbird
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Собрать тексты JSON-шаблонов
|
||||
ansible.builtin.set_fact:
|
||||
remnawave_spec_files: "{{ remnawave_spec_files | default({}) | combine({item: lookup('file', role_path ~ '/files/' ~ item)}) }}"
|
||||
@@ -21,8 +15,6 @@
|
||||
remnawave_sync_payload:
|
||||
panel_domain: "{{ remnawave_panel_domain }}"
|
||||
sub_domain: "{{ remnawave_sub_domain }}"
|
||||
netbird_peers_url: "{{ remnawave_netbird_peers_url }}"
|
||||
netbird_connected: "{{ 'Management: Connected' in (remnawave_local_netbird.stdout | default('')) }}"
|
||||
xray_checker_user: "{{ remnawave_xray_checker_user }}"
|
||||
desired: "{{ remnawave_desired }}"
|
||||
users_doc: "{{ remnawave_users_cfg }}"
|
||||
@@ -49,7 +41,6 @@
|
||||
ansible.builtin.command: "python3 {{ remnawave_dir }}/sync_remnawave.py {{ remnawave_dir }}/sync_config.json"
|
||||
environment:
|
||||
RW_API_TOKEN: "{{ remnawave_api_token }}"
|
||||
NB_API_TOKEN: "{{ lookup('env', 'NETBIRD_API_TOKEN', default='') }}"
|
||||
RW_XRAY_URL_FILE: "{{ remnawave_dir }}/.xray-checker-url"
|
||||
register: remnawave_sync_raw
|
||||
changed_when: remnawave_sync_raw.rc == 0 and ((remnawave_sync_raw.stdout | from_json).changed | default(false))
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
|
||||
http:
|
||||
routers:
|
||||
authentik:
|
||||
rule: "Host(`auth.gunihome.ru`)"
|
||||
entryPoints:
|
||||
- websecure
|
||||
service: authentik
|
||||
tls:
|
||||
certResolver: letsencrypt
|
||||
|
||||
services:
|
||||
authentik:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: "http://127.0.0.1:9000"
|
||||
|
||||
middlewares:
|
||||
authentik:
|
||||
forwardAuth:
|
||||
address: "http://127.0.0.1:9000/outpost.goauthentik.io/auth/traefik"
|
||||
trustForwardHeader: true
|
||||
authResponseHeaders:
|
||||
- "X-authentik-username"
|
||||
- "X-authentik-groups"
|
||||
- "X-authentik-email"
|
||||
- "X-authentik-name"
|
||||
- "X-authentik-uid"
|
||||
- "X-authentik-jwt"
|
||||
- "X-authentik-meta-jwks"
|
||||
- "X-authentik-meta-outpost"
|
||||
- "X-authentik-meta-provider"
|
||||
- "X-authentik-meta-app"
|
||||
- "X-authentik-meta-version"
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
|
||||
# NetBird Central TCP SNI passthrough -> rus-central VPS
|
||||
tcp:
|
||||
routers:
|
||||
netbird-central:
|
||||
rule: HostSNI(`central.gunihome.ru`)
|
||||
entryPoints:
|
||||
- websecure
|
||||
service: netbird-central
|
||||
tls:
|
||||
passthrough: true
|
||||
|
||||
services:
|
||||
netbird-central:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- address: "45.154.185.208:443"
|
||||
@@ -1,4 +0,0 @@
|
||||
---
|
||||
netbird_client_management_url: "https://central.gunihome.ru"
|
||||
netbird_client_setup_key: "{{ lookup('env', 'NETBIRD_REMNAWAVE_SETUP_KEY', default='') }}"
|
||||
netbird_client_hostname: "{{ inventory_hostname }}"
|
||||
@@ -1,86 +0,0 @@
|
||||
---
|
||||
- name: Проверить ключ установки Remnawave
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- netbird_client_setup_key | length > 0
|
||||
fail_msg: "Нет NETBIRD_REMNAWAVE_SETUP_KEY. Сначала прогоните ansible-rus-central."
|
||||
|
||||
- name: Проверить /dev/net/tun
|
||||
ansible.builtin.stat:
|
||||
path: /dev/net/tun
|
||||
register: netbird_tun
|
||||
|
||||
- name: Нет TUN для NetBird
|
||||
ansible.builtin.fail:
|
||||
msg: "Нет /dev/net/tun. На core-net это unprivileged LXC: API-токен Proxmox не может пробросить устройство (403, только root@pam). На хосте: pct set 902 -dev0 /dev/net/tun,mode=0666 && pct reboot 902. После перезапуска повторите ansible-core-net."
|
||||
when: not netbird_tun.stat.exists
|
||||
|
||||
- name: Поставить зависимости NetBird
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gnupg
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Ключ репозитория NetBird
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
install -d -m 0755 /usr/share/keyrings
|
||||
curl -fsSL https://pkgs.netbird.io/debian/public.key \
|
||||
| gpg --dearmor --yes -o /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||
chmod 0644 /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||
args:
|
||||
executable: /bin/bash
|
||||
creates: /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||
|
||||
- name: Репозиторий NetBird
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/apt/sources.list.d/netbird.list
|
||||
content: |
|
||||
deb [signed-by=/usr/share/keyrings/netbird-archive-keyring.gpg] https://pkgs.netbird.io/debian stable main
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Поставить клиент NetBird
|
||||
ansible.builtin.apt:
|
||||
name: netbird
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Включить службу NetBird
|
||||
ansible.builtin.systemd:
|
||||
name: netbird
|
||||
enabled: true
|
||||
state: started
|
||||
|
||||
- name: Узнать, подключён ли NetBird
|
||||
ansible.builtin.command: netbird status
|
||||
register: netbird_status_before
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Подключить NetBird к central.gunihome.ru
|
||||
ansible.builtin.command: >
|
||||
netbird up
|
||||
--management-url {{ netbird_client_management_url }}
|
||||
--setup-key {{ netbird_client_setup_key }}
|
||||
--hostname {{ netbird_client_hostname }}
|
||||
no_log: true
|
||||
when: "'Management: Connected' not in (netbird_status_before.stdout | default(''))"
|
||||
register: netbird_up
|
||||
changed_when: true
|
||||
|
||||
- name: Дождаться Management Connected
|
||||
ansible.builtin.command: netbird status
|
||||
register: netbird_status
|
||||
changed_when: false
|
||||
retries: 10
|
||||
delay: 3
|
||||
until: "'Management: Connected' in netbird_status.stdout"
|
||||
|
||||
- name: Показать состояние NetBird
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ netbird_status.stdout_lines | select('search', 'Management:|NetBird IP:|FQDN:|Peers:') | list }}"
|
||||
@@ -1,6 +0,0 @@
|
||||
---
|
||||
netbird_exit_group: "exit-{{ inventory_hostname }}"
|
||||
netbird_exit_clients_group: "exit-clients"
|
||||
netbird_exit_network_id: "exit-{{ inventory_hostname }}"
|
||||
netbird_exit_route_description: "Exit Node {{ inventory_hostname }} (0.0.0.0/0)"
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
---
|
||||
- name: Зафиксировать параметры ядра для NetBird Exit Node
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/sysctl.d/99-netbird-exit.conf
|
||||
content: |
|
||||
net.ipv4.ip_forward = 1
|
||||
net.ipv4.conf.all.src_valid_mark = 1
|
||||
net.ipv4.conf.all.rp_filter = 2
|
||||
net.ipv4.conf.default.rp_filter = 2
|
||||
net.ipv6.conf.all.disable_ipv6 = 0
|
||||
net.ipv6.conf.default.disable_ipv6 = 0
|
||||
net.core.default_qdisc = fq
|
||||
net.ipv4.tcp_congestion_control = bbr
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
register: netbird_exit_sysctl
|
||||
|
||||
- name: Применить параметры sysctl для Exit Node
|
||||
ansible.builtin.command: sysctl --system
|
||||
when: netbird_exit_sysctl is changed
|
||||
changed_when: true
|
||||
|
||||
- name: Разрешить порт WireGuard NetBird (51820/udp) только по IPv4
|
||||
ansible.builtin.command: "{{ item }}"
|
||||
loop:
|
||||
- ufw delete allow 51820/udp
|
||||
- ufw allow proto udp from any to 0.0.0.0/0 port 51820
|
||||
- ufw deny in proto udp from ::/0 to ::/0 port 51820
|
||||
- ufw deny out proto udp from ::/0 to ::/0 port 51820
|
||||
register: ufw_netbird_wg
|
||||
changed_when: "'added' in (ufw_netbird_wg.stdout | lower) or 'deleted' in (ufw_netbird_wg.stdout | lower)"
|
||||
failed_when: false
|
||||
|
||||
- name: Запретить любой исходящий доступ с exit node в домашнюю LAN (defense-in-depth)
|
||||
ansible.builtin.command: "{{ item }}"
|
||||
loop:
|
||||
- ufw delete allow out proto tcp from any to 192.168.1.108 port 8428
|
||||
- ufw deny out to 192.168.1.0/24
|
||||
register: ufw_lan_restrict
|
||||
changed_when: "'added' in (ufw_lan_restrict.stdout | lower) or 'deleted' in (ufw_lan_restrict.stdout | lower)"
|
||||
failed_when: false
|
||||
|
||||
- name: Клиент NetBird на ноде
|
||||
ansible.builtin.include_role:
|
||||
name: netbird_client
|
||||
|
||||
- name: Перезапустить NetBird после изменения sysctl
|
||||
ansible.builtin.systemd:
|
||||
name: netbird
|
||||
state: restarted
|
||||
when: netbird_exit_sysctl is changed
|
||||
|
||||
- name: Дождаться переподключения NetBird после перезапуска
|
||||
ansible.builtin.command: netbird status
|
||||
register: netbird_status_after_restart
|
||||
changed_when: false
|
||||
retries: 20
|
||||
delay: 3
|
||||
until: "'Management: Connected' in netbird_status_after_restart.stdout"
|
||||
when: netbird_exit_sysctl is changed
|
||||
|
||||
- name: Установить jq для синхронизации Exit Node через API NetBird
|
||||
ansible.builtin.apt:
|
||||
name: jq
|
||||
state: present
|
||||
|
||||
- name: Привязать ger-nod-02 к группе Exit Node и проверить маршрут 0.0.0.0/0
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
API_BASE="https://central.gunihome.ru/api"
|
||||
nb_api_call() {
|
||||
local method="$1" path="$2" body="$3"
|
||||
local resp code
|
||||
resp=$(curl -sS --max-time 20 -w '\n%{http_code}' -X "$method" "${API_BASE}${path}" \
|
||||
-H "Authorization: Token ${NB_API_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${body}")
|
||||
code=${resp##*$'\n'}
|
||||
resp=${resp%$'\n'*}
|
||||
if [ "${code}" != "200" ] && [ "${code}" != "201" ]; then
|
||||
echo "NetBird API ${method} ${path} failed (HTTP ${code}): ${resp}" >&2
|
||||
return 1
|
||||
fi
|
||||
printf '%s' "${resp}"
|
||||
}
|
||||
|
||||
exit_group_updated=0
|
||||
exit_route_created=0
|
||||
|
||||
peers_json=$(curl -fsS --max-time 20 -H "Authorization: Token ${NB_API_TOKEN}" "${API_BASE}/peers")
|
||||
ger_peer_id=$(printf '%s' "${peers_json}" | jq -r --arg h "${NB_PEER_HOST}" '.[] | select((.name // "") == $h or (.hostname // "") == $h) | .id' | head -n 1)
|
||||
if [ -z "${ger_peer_id}" ]; then
|
||||
echo "Пир ${NB_PEER_HOST} не найден в NetBird API" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
groups_json=$(curl -fsS --max-time 20 -H "Authorization: Token ${NB_API_TOKEN}" "${API_BASE}/groups")
|
||||
exit_group_id=$(printf '%s' "${groups_json}" | jq -r --arg g "${NB_EXIT_GROUP}" '.[] | select(.name == $g) | .id' | head -n 1)
|
||||
|
||||
if [ -z "${exit_group_id}" ]; then
|
||||
grp_payload=$(jq -n --arg name "${NB_EXIT_GROUP}" --arg pid "${ger_peer_id}" '{name: $name, peers: [$pid]}')
|
||||
grp_resp=$(nb_api_call POST "/groups" "${grp_payload}")
|
||||
exit_group_id=$(printf '%s' "${grp_resp}" | jq -r '.id // empty')
|
||||
if [ -z "${exit_group_id}" ]; then
|
||||
echo "Не удалось создать группу ${NB_EXIT_GROUP}" >&2
|
||||
exit 1
|
||||
fi
|
||||
exit_group_updated=1
|
||||
else
|
||||
exit_grp_obj=$(printf '%s' "${groups_json}" | jq -c --arg id "${exit_group_id}" '.[] | select(.id == $id)')
|
||||
has_ger=$(printf '%s' "${exit_grp_obj}" | jq -r --arg pid "${ger_peer_id}" '[.peers[]?.id] | index($pid) != null')
|
||||
if [ "${has_ger}" != "true" ]; then
|
||||
upd_payload=$(printf '%s' "${exit_grp_obj}" | jq -c --arg pid "${ger_peer_id}" '{name: .name, peers: (([.peers[]?.id] + [$pid]) | unique)}')
|
||||
nb_api_call PUT "/groups/${exit_group_id}" "${upd_payload}" >/dev/null
|
||||
exit_group_updated=1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Удалить внешнюю ноду из группы remnawave (панель), чтобы у неё не было прав панели
|
||||
remna_grp_obj=$(printf '%s' "${groups_json}" | jq -c '.[] | select(.name == "remnawave")' | head -n 1)
|
||||
if [ -n "${remna_grp_obj}" ]; then
|
||||
remna_grp_id=$(printf '%s' "${remna_grp_obj}" | jq -r '.id')
|
||||
in_remna=$(printf '%s' "${remna_grp_obj}" | jq -r --arg pid "${ger_peer_id}" '[.peers[]?.id] | index($pid) != null')
|
||||
if [ "${in_remna}" = "true" ]; then
|
||||
remna_upd=$(printf '%s' "${remna_grp_obj}" | jq -c --arg pid "${ger_peer_id}" '{name: .name, peers: ([.peers[]?.id | select(. != $pid)] | unique)}')
|
||||
nb_api_call PUT "/groups/${remna_grp_id}" "${remna_upd}" >/dev/null
|
||||
exit_group_updated=1
|
||||
fi
|
||||
fi
|
||||
|
||||
exit_clients_group_id=$(printf '%s' "${groups_json}" | jq -r --arg g "${NB_EXIT_CLIENTS_GROUP}" '.[] | select(.name == $g) | .id' | head -n 1)
|
||||
if [ -n "${exit_clients_group_id}" ]; then
|
||||
routes_json=$(curl -fsS --max-time 20 -H "Authorization: Token ${NB_API_TOKEN}" "${API_BASE}/routes")
|
||||
existing_exit_route=$(printf '%s' "${routes_json}" | jq -c --arg nid "${NB_EXIT_NET_ID}" '.[] | select(.network_id == $nid and .network == "0.0.0.0/0")' | head -n 1)
|
||||
existing_exit_route_id=$(printf '%s' "${existing_exit_route}" | jq -r '.id // empty')
|
||||
needs_exit_route_update="false"
|
||||
if [ -n "${existing_exit_route_id}" ]; then
|
||||
needs_exit_route_update=$(printf '%s' "${existing_exit_route}" | jq -r '(.metric != 9999) or (.keep_route != false)')
|
||||
fi
|
||||
if [ -z "${existing_exit_route_id}" ] || [ "${needs_exit_route_update}" = "true" ]; then
|
||||
exit_route_payload=$(jq -n \
|
||||
--arg desc "${NB_EXIT_DESC}" \
|
||||
--arg nid "${NB_EXIT_NET_ID}" \
|
||||
--arg eg "${exit_group_id}" \
|
||||
--arg cg "${exit_clients_group_id}" \
|
||||
'{
|
||||
description: $desc,
|
||||
network_id: $nid,
|
||||
enabled: true,
|
||||
peer_groups: [$eg],
|
||||
network: "0.0.0.0/0",
|
||||
metric: 9999,
|
||||
masquerade: true,
|
||||
groups: [$cg],
|
||||
keep_route: false,
|
||||
skip_auto_apply: false
|
||||
}')
|
||||
if [ -z "${existing_exit_route_id}" ]; then
|
||||
nb_api_call POST "/routes" "${exit_route_payload}" >/dev/null
|
||||
else
|
||||
nb_api_call PUT "/routes/${existing_exit_route_id}" "${exit_route_payload}" >/dev/null
|
||||
fi
|
||||
exit_route_created=1
|
||||
fi
|
||||
fi
|
||||
|
||||
jq -n \
|
||||
--argjson exit_group_updated "${exit_group_updated}" \
|
||||
--argjson exit_route_created "${exit_route_created}" \
|
||||
'{
|
||||
exit_group_updated: ($exit_group_updated == 1),
|
||||
exit_route_created: ($exit_route_created == 1),
|
||||
changed: (($exit_group_updated + $exit_route_created) > 0)
|
||||
}'
|
||||
args:
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
NB_API_TOKEN: "{{ lookup('env', 'NETBIRD_API_TOKEN', default='') }}"
|
||||
NB_PEER_HOST: "{{ inventory_hostname }}"
|
||||
NB_EXIT_GROUP: "{{ netbird_exit_group }}"
|
||||
NB_EXIT_CLIENTS_GROUP: "{{ netbird_exit_clients_group }}"
|
||||
NB_EXIT_NET_ID: "{{ netbird_exit_network_id }}"
|
||||
NB_EXIT_DESC: "{{ netbird_exit_route_description }}"
|
||||
when: lookup('env', 'NETBIRD_API_TOKEN', default='') | length > 0
|
||||
register: ger_netbird_exit_sync
|
||||
changed_when: (ger_netbird_exit_sync.stdout | from_json).changed
|
||||
no_log: true
|
||||
|
||||
- name: Дождаться применения конфигурации Exit Node на клиенте NetBird
|
||||
ansible.builtin.command: netbird status
|
||||
register: ger_netbird_status_after
|
||||
changed_when: false
|
||||
when: ger_netbird_exit_sync is changed
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
opnsense_host: "192.168.1.1:4433"
|
||||
opnsense_api_key: "{{ lookup('env', 'OPNSENSE_API_KEY') }}"
|
||||
opnsense_api_secret: "{{ lookup('env', 'OPNSENSE_API_SECRET') }}"
|
||||
|
||||
opnsense_netbird_management_url: "https://central.gunihome.ru:443"
|
||||
netbird_setup_key: "{{ lookup('env', 'NETBIRD_SETUP_KEY') }}"
|
||||
|
||||
opnsense_netbird_wg_port: "51820"
|
||||
opnsense_netbird_ssh_enable: "1"
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
---
|
||||
- name: Проверить наличие обязательных секретов OPNsense и NetBird
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- opnsense_api_key is defined and opnsense_api_key | length > 0
|
||||
- opnsense_api_secret is defined and opnsense_api_secret | length > 0
|
||||
- netbird_setup_key is defined and netbird_setup_key | length > 0
|
||||
- opnsense_netbird_management_url is defined and opnsense_netbird_management_url | length > 0
|
||||
fail_msg: "Отсутствует один из обязательных секретов: OPNSENSE_API_KEY, OPNSENSE_API_SECRET или NETBIRD_SETUP_KEY."
|
||||
|
||||
- name: Проверить наличие плагина os-netbird в OPNsense
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/settings/get"
|
||||
method: GET
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: [200, 404]
|
||||
register: opnsense_nb_check
|
||||
|
||||
- name: Установить плагин os-netbird (если отсутствует)
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/core/firmware/install/os-netbird"
|
||||
method: POST
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
body: {}
|
||||
status_code: [200]
|
||||
when: opnsense_nb_check.status == 404
|
||||
|
||||
- name: Дождаться появления API плагина os-netbird после установки
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/settings/get"
|
||||
method: GET
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: [200]
|
||||
register: opnsense_nb_settings_wait
|
||||
retries: 30
|
||||
delay: 5
|
||||
until: opnsense_nb_settings_wait.status == 200
|
||||
when: opnsense_nb_check.status == 404
|
||||
|
||||
- name: Сформировать текущие настройки плагина os-netbird
|
||||
ansible.builtin.set_fact:
|
||||
opnsense_nb_current_settings: "{{ (opnsense_nb_settings_wait.json if opnsense_nb_check.status == 404 else opnsense_nb_check.json).settings }}"
|
||||
|
||||
- name: Применить настройки сервиса NetBird в OPNsense
|
||||
vars:
|
||||
need_settings_update: >-
|
||||
{{
|
||||
(opnsense_nb_current_settings.general.enable | string) != '1' or
|
||||
(opnsense_nb_current_settings.general.wireguardPort | string) != (opnsense_netbird_wg_port | string) or
|
||||
(opnsense_nb_current_settings.firewall.allowConfig | string) != '1' or
|
||||
(opnsense_nb_current_settings.firewall.blockInboundConnection | string) != '1' or
|
||||
(opnsense_nb_current_settings.ssh.enable | string) != (opnsense_netbird_ssh_enable | string) or
|
||||
(opnsense_nb_current_settings.dns.enable | string) != '1' or
|
||||
(opnsense_nb_current_settings.routing.accessLan | string) != '0' or
|
||||
(opnsense_nb_current_settings.routing.acceptClientRoutes | string) != '1' or
|
||||
(opnsense_nb_current_settings.routing.acceptServerRoutes | string) != '1'
|
||||
}}
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/settings/set"
|
||||
method: POST
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
body:
|
||||
settings:
|
||||
general:
|
||||
enable: "1"
|
||||
wireguardPort: "{{ opnsense_netbird_wg_port }}"
|
||||
firewall:
|
||||
allowConfig: "1"
|
||||
blockInboundConnection: "1"
|
||||
ssh:
|
||||
enable: "{{ opnsense_netbird_ssh_enable }}"
|
||||
dns:
|
||||
enable: "1"
|
||||
routing:
|
||||
accessLan: "0"
|
||||
acceptClientRoutes: "1"
|
||||
acceptServerRoutes: "1"
|
||||
postquantum:
|
||||
enableRosenpass: "0"
|
||||
rosenpassPermissive: "0"
|
||||
syslog:
|
||||
logLevel: "info"
|
||||
status_code: [200]
|
||||
register: opnsense_nb_settings_set
|
||||
when: need_settings_update
|
||||
changed_when: true
|
||||
|
||||
- name: Переконфигурировать сервис NetBird в OPNsense
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/service/reconfigure"
|
||||
method: POST
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
body: {}
|
||||
status_code: [200]
|
||||
when: opnsense_nb_settings_set is changed
|
||||
changed_when: true
|
||||
|
||||
- name: Проверить статус службы NetBird в OPNsense
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/service/status"
|
||||
method: GET
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: [200]
|
||||
register: opnsense_nb_service_status
|
||||
|
||||
- name: Запустить службу NetBird в OPNsense (если остановлена)
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/service/start"
|
||||
method: POST
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
body: {}
|
||||
status_code: [200]
|
||||
when: (opnsense_nb_service_status.json.status | default('')) != 'running'
|
||||
changed_when: true
|
||||
|
||||
- name: Проверить текущее подключение NetBird в OPNsense
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/status/status"
|
||||
method: GET
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: [200]
|
||||
register: opnsense_nb_status
|
||||
|
||||
- name: Задать параметры аутентификации NetBird (Management URL и Setup Key)
|
||||
vars:
|
||||
nb_connected: "{{ opnsense_nb_status.json.management.connected | default(false) | bool }}"
|
||||
nb_current_url: "{{ opnsense_nb_status.json.management.url | default('') }}"
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/authentication/set"
|
||||
method: POST
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
body:
|
||||
authentication:
|
||||
managementUrl: "{{ opnsense_netbird_management_url }}"
|
||||
setupKey: "{{ netbird_setup_key }}"
|
||||
status_code: [200]
|
||||
register: opnsense_nb_auth_set
|
||||
when: (not nb_connected) or (nb_current_url != opnsense_netbird_management_url)
|
||||
changed_when: true
|
||||
no_log: true
|
||||
|
||||
- name: Подключить OPNsense к координатору NetBird (authentication/up)
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/authentication/up"
|
||||
method: POST
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
body_format: json
|
||||
body: {}
|
||||
status_code: [200]
|
||||
timeout: 60
|
||||
when: opnsense_nb_auth_set is changed
|
||||
changed_when: true
|
||||
|
||||
- name: Синхронизировать конфигурацию клиента NetBird в OPNsense
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/settings/sync"
|
||||
method: GET
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: [200]
|
||||
when: opnsense_nb_settings_set is changed or opnsense_nb_auth_set is changed
|
||||
changed_when: true
|
||||
|
||||
- name: Дождаться перехода пира OPNsense в состояние connected на новом сервере
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/netbird/status/status"
|
||||
method: GET
|
||||
url_username: "{{ opnsense_api_key }}"
|
||||
url_password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: [200]
|
||||
register: opnsense_nb_final_status
|
||||
retries: 15
|
||||
delay: 4
|
||||
until:
|
||||
- (opnsense_nb_final_status.json.management.connected | default(false) | bool)
|
||||
- (opnsense_nb_final_status.json.management.url | default('')) == opnsense_netbird_management_url
|
||||
|
||||
- name: Итог подключения OPNsense к NetBird
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Management URL: {{ opnsense_nb_final_status.json.management.url }}"
|
||||
- "Connected: {{ opnsense_nb_final_status.json.management.connected }}"
|
||||
- "NetBird IP: {{ opnsense_nb_final_status.json.netbirdIp | default('N/A') }}"
|
||||
- "FQDN: {{ opnsense_nb_final_status.json.fqdn | default('N/A') }}"
|
||||
- "Networks: {{ opnsense_nb_final_status.json.networks | default([]) }}"
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
- name: Найти эту ноду в desired.yml
|
||||
ansible.builtin.set_fact:
|
||||
remnanode_node_matches: "{{ remnanode_stack.nodes | selectattr('netbird_hostname', 'equalto', inventory_hostname) | list }}"
|
||||
remnanode_node_matches: "{{ remnanode_stack.nodes | selectattr('hostname', 'equalto', inventory_hostname) | list }}"
|
||||
|
||||
- name: Нода должна быть описана в desired.yml
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- remnanode_node_matches | length == 1
|
||||
fail_msg: "В desired.yml нет ровно одной ноды с netbird_hostname={{ inventory_hostname }}"
|
||||
fail_msg: "В desired.yml нет ровно одной ноды с hostname={{ inventory_hostname }}"
|
||||
|
||||
- name: Подставить профиль ноды
|
||||
ansible.builtin.set_fact:
|
||||
@@ -231,49 +231,12 @@
|
||||
register: ufw_https
|
||||
changed_when: "'added' in (ufw_https.stdout | lower)"
|
||||
|
||||
- name: Узнать NetBird IP панели
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
if [ -z "${NB_API_TOKEN:-}" ]; then
|
||||
exit 0
|
||||
fi
|
||||
curl -fsS --max-time 20 -H "Authorization: Token ${NB_API_TOKEN}" \
|
||||
"https://central.gunihome.ru/api/peers" \
|
||||
| jq -r --arg h "core-net" '
|
||||
(if type == "array" then . elif type == "object" then (.items // .peers // []) else [] end)
|
||||
| map(select((.hostname // "") == $h or (.name // "") == $h or (.dns_label // "") == $h))
|
||||
| .[0].ip // empty'
|
||||
args:
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
NB_API_TOKEN: "{{ lookup('env', 'NETBIRD_API_TOKEN', default='') }}"
|
||||
register: remnanode_panel_nb
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Разрешить NODE_PORT с NetBird IP панели
|
||||
ansible.builtin.command: >
|
||||
ufw allow from {{ remnanode_panel_nb.stdout | trim }} to any port {{ remnanode_node_port }} proto tcp
|
||||
register: ufw_node_nb
|
||||
changed_when: "'added' in (ufw_node_nb.stdout | lower)"
|
||||
when: remnanode_panel_nb.stdout | default('') | trim is match('^[0-9.]+$')
|
||||
|
||||
- name: Убрать WAN-доступ к NODE_PORT
|
||||
ansible.builtin.command: >
|
||||
ufw --force delete allow from {{ item }} to any port {{ remnanode_node_port }} proto tcp
|
||||
loop: "{{ remnanode_panel_egress_ips }}"
|
||||
register: ufw_node_wan_del
|
||||
changed_when: "'deleted' in (stdout | default('') | lower)"
|
||||
failed_when: false
|
||||
when: remnanode_panel_nb.stdout | default('') | trim is match('^[0-9.]+$')
|
||||
|
||||
- name: Разрешить NODE_PORT только с egress панели (оба провайдера)
|
||||
ansible.builtin.command: >
|
||||
ufw allow from {{ item }} to any port {{ remnanode_node_port }} proto tcp
|
||||
loop: "{{ remnanode_panel_egress_ips }}"
|
||||
register: ufw_node
|
||||
changed_when: "'added' in (stdout | default('') | lower)"
|
||||
when: remnanode_panel_nb.stdout | default('') | trim is not match('^[0-9.]+$')
|
||||
|
||||
- name: Включить firewall
|
||||
ansible.builtin.command: ufw --force enable
|
||||
@@ -328,10 +291,5 @@
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "SelfSteal: https://{{ remnanode_selfsteal_domain }}"
|
||||
- >-
|
||||
{{
|
||||
'NODE_PORT ' ~ remnanode_node_port ~ ' только с NetBird панели ' ~ (remnanode_panel_nb.stdout | trim)
|
||||
if (remnanode_panel_nb.stdout | default('') | trim is match('^[0-9.]+$'))
|
||||
else 'Peer core-net ещё не в сети, NODE_PORT ' ~ remnanode_node_port ~ ' остаётся с WAN egress ' ~ (remnanode_panel_egress_ips | join(', '))
|
||||
}}
|
||||
- "NODE_PORT {{ remnanode_node_port }} разрешён с WAN egress панели: {{ remnanode_panel_egress_ips | join(', ') }}"
|
||||
- "Compose: {{ remnanode_dir }}/compose.yaml"
|
||||
@@ -1,7 +0,0 @@
|
||||
---
|
||||
- name: cAdvisor шлюза
|
||||
ansible.builtin.include_role:
|
||||
name: cadvisor
|
||||
vars:
|
||||
# Docker на этой машине не принимает API 1.41, которым говорит cAdvisor 0.49.
|
||||
cadvisor_image: ghcr.io/google/cadvisor:v0.60.6
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
netbird_dir: /opt/netbird
|
||||
netbird_ports:
|
||||
- 80/tcp
|
||||
- 443/tcp
|
||||
- 3478/udp
|
||||
|
||||
netbird_letsencrypt_email: "{{ letsencrypt_email }}"
|
||||
|
||||
netbird_auth_secret: "{{ lookup('env', 'NETBIRD_AUTH_SECRET') }}"
|
||||
netbird_datastore_key: "{{ lookup('env', 'NETBIRD_DATASTORE_KEY') }}"
|
||||
netbird_session_key: "{{ lookup('env', 'NETBIRD_SESSION_KEY') }}"
|
||||
|
||||
netbird_admin_email: "{{ lookup('env', 'NETBIRD_ADMIN_EMAIL') | default(letsencrypt_email, true) }}"
|
||||
netbird_admin_name: "{{ lookup('env', 'NETBIRD_ADMIN_NAME') | default('karpenok', true) }}"
|
||||
netbird_admin_password: "{{ lookup('env', 'NETBIRD_ADMIN_PASSWORD') }}"
|
||||
netbird_api_token: "{{ lookup('env', 'NETBIRD_API_TOKEN') }}"
|
||||
netbird_setup_key: "{{ lookup('env', 'NETBIRD_SETUP_KEY') }}"
|
||||
|
||||
netbird_router_group_name: "homelab-routers"
|
||||
netbird_setup_key_name: "homelab-routers-key"
|
||||
netbird_remnawave_group_name: "remnawave"
|
||||
netbird_remnawave_setup_key_name: "remnawave-peers"
|
||||
netbird_remnawave_setup_key: "{{ lookup('env', 'NETBIRD_REMNAWAVE_SETUP_KEY') }}"
|
||||
netbird_lan_network_id: "homelab-lan"
|
||||
netbird_lan_subnet: "192.168.1.0/24"
|
||||
@@ -1,6 +0,0 @@
|
||||
COMPOSE_PROJECT_NAME=netbird
|
||||
NETBIRD_DOMAIN=
|
||||
NETBIRD_LETSENCRYPT_EMAIL=
|
||||
NETBIRD_AUTH_SECRET=
|
||||
NETBIRD_DATASTORE_KEY=
|
||||
NETBIRD_SESSION_KEY=
|
||||
@@ -1,99 +0,0 @@
|
||||
# Декларативное описание клиентского доступа и политик NetBird.
|
||||
# Применяется задачей rus-central/netbird (tasks/access.yml → sync_access.py).
|
||||
#
|
||||
# Секреты setup-ключей сохраняются в Infisical (/services/netbird) автоматически
|
||||
# и не попадают в Git или логи CI.
|
||||
|
||||
# Группы exit-<hostname> для нод из desired.yml добавляет sync_access.py.
|
||||
client_groups:
|
||||
- exit-clients
|
||||
- remnawave
|
||||
|
||||
# DNS для клиентских групп
|
||||
dns_nameservers:
|
||||
- name: exit-dns
|
||||
description: "Public DNS for Exit Node clients"
|
||||
servers:
|
||||
- "1.1.1.1"
|
||||
- "8.8.8.8"
|
||||
groups:
|
||||
- exit-clients
|
||||
primary: true
|
||||
enabled: false
|
||||
|
||||
# Ключи подключения клиентов (секреты сохраняются в Infisical /services/netbird).
|
||||
setup_keys:
|
||||
- name: exit-clients-key
|
||||
secret: NETBIRD_EXIT_CLIENTS_SETUP_KEY
|
||||
type: reusable
|
||||
expires_in: 31536000
|
||||
usage_limit: 0
|
||||
ephemeral: false
|
||||
groups:
|
||||
- exit-clients
|
||||
enabled: true
|
||||
|
||||
# Управление подключёнными пирами (жёсткое разделение: внешние ноды не входят в remnawave).
|
||||
peers:
|
||||
- name: "A55 пользователя Vacheslav"
|
||||
groups:
|
||||
- exit-clients
|
||||
state: present
|
||||
- name: "core-net"
|
||||
groups:
|
||||
- remnawave
|
||||
state: present
|
||||
|
||||
# Zero-Trust политики доступа (заменяют дефолтную политику Default All <-> All).
|
||||
# Инициировать соединения в сторону внешних нод могут только панель (core-net) и клиенты (exit-clients).
|
||||
# Сами внешние ноды не могут открыть ни одного соединения внутрь домашней сети или к пирам.
|
||||
policies:
|
||||
- name: "remnawave-panel-to-exit-nodes"
|
||||
description: "One-way access from Remnawave panel (core-net) to Exit Nodes (NODE_PORT + metrics)"
|
||||
enabled: true
|
||||
rules:
|
||||
- name: "panel-to-node-tcp"
|
||||
description: "Allow TCP 2222 (remnanode), 9100 (node-exporter), 9101 (cAdvisor) from core-net"
|
||||
enabled: true
|
||||
action: accept
|
||||
protocol: tcp
|
||||
bidirectional: false
|
||||
ports:
|
||||
- "2222"
|
||||
- "9100"
|
||||
- "9101"
|
||||
sources:
|
||||
- remnawave
|
||||
destinations: "@remnawave_exit_groups"
|
||||
|
||||
- name: "exit-clients-to-exit-nodes"
|
||||
description: "One-way traffic from Exit Node clients to Exit Nodes"
|
||||
enabled: true
|
||||
rules:
|
||||
- name: "exit-clients-tcp"
|
||||
description: "Allow outbound TCP from exit-clients via exit node"
|
||||
enabled: true
|
||||
action: accept
|
||||
protocol: tcp
|
||||
bidirectional: false
|
||||
sources:
|
||||
- exit-clients
|
||||
destinations: "@remnawave_exit_groups"
|
||||
- name: "exit-clients-udp"
|
||||
description: "Allow outbound UDP from exit-clients via exit node"
|
||||
enabled: true
|
||||
action: accept
|
||||
protocol: udp
|
||||
bidirectional: false
|
||||
sources:
|
||||
- exit-clients
|
||||
destinations: "@remnawave_exit_groups"
|
||||
- name: "exit-clients-icmp"
|
||||
description: "Allow ICMP for exit-clients via exit node"
|
||||
enabled: true
|
||||
action: accept
|
||||
protocol: icmp
|
||||
bidirectional: true
|
||||
sources:
|
||||
- exit-clients
|
||||
destinations: "@remnawave_exit_groups"
|
||||
@@ -1,154 +0,0 @@
|
||||
name: netbird
|
||||
|
||||
services:
|
||||
traefik:
|
||||
image: traefik:v3.7.14
|
||||
container_name: netbird-traefik
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
netbird:
|
||||
ipv4_address: 172.30.0.10
|
||||
command:
|
||||
- "--log.level=INFO"
|
||||
- "--accesslog=true"
|
||||
- "--providers.docker=true"
|
||||
- "--providers.docker.exposedbydefault=false"
|
||||
- "--providers.docker.network=netbird_netbird"
|
||||
- "--entrypoints.web.address=:80"
|
||||
- "--entrypoints.websecure.address=:443"
|
||||
- "--entrypoints.websecure.allowACMEByPass=true"
|
||||
- "--entrypoints.web.http.aliasHeadersStrategy=delete"
|
||||
- "--entrypoints.websecure.http.aliasHeadersStrategy=delete"
|
||||
- "--entrypoints.websecure.transport.respondingTimeouts.readTimeout=0"
|
||||
- "--entrypoints.websecure.transport.respondingTimeouts.writeTimeout=0"
|
||||
- "--entrypoints.websecure.transport.respondingTimeouts.idleTimeout=0"
|
||||
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
|
||||
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
|
||||
- "--certificatesresolvers.letsencrypt.acme.email=${NETBIRD_LETSENCRYPT_EMAIL}"
|
||||
- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
|
||||
- "--certificatesresolvers.letsencrypt.acme.tlschallenge=true"
|
||||
- "--serverstransport.forwardingtimeouts.responseheadertimeout=0s"
|
||||
- "--serverstransport.forwardingtimeouts.idleconntimeout=0s"
|
||||
- "--ping=true"
|
||||
- "--ping.entrypoint=ping"
|
||||
- "--entrypoints.ping.address=:8082"
|
||||
ports:
|
||||
- "443:443"
|
||||
- "80:80"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- netbird_traefik_letsencrypt:/letsencrypt
|
||||
healthcheck:
|
||||
test: ["CMD", "traefik", "healthcheck", "--ping", "--ping.entrypoint=ping", "--entrypoints.ping.address=:8082"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 10s
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "500m"
|
||||
max-file: "2"
|
||||
|
||||
dashboard:
|
||||
image: netbirdio/dashboard@sha256:340b13c00b84349572a2acc5605e907cb09250a9e6461c757097eabdb8e02f2c
|
||||
container_name: netbird-dashboard
|
||||
restart: unless-stopped
|
||||
networks: [netbird]
|
||||
env_file:
|
||||
- ./dashboard.env
|
||||
depends_on:
|
||||
server-health:
|
||||
condition: service_healthy
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
- traefik.http.routers.netbird-dashboard.rule=Host(`${NETBIRD_DOMAIN}`)
|
||||
- traefik.http.routers.netbird-dashboard.entrypoints=websecure
|
||||
- traefik.http.routers.netbird-dashboard.tls=true
|
||||
- traefik.http.routers.netbird-dashboard.tls.certresolver=letsencrypt
|
||||
- traefik.http.routers.netbird-dashboard.service=dashboard
|
||||
- traefik.http.routers.netbird-dashboard.priority=1
|
||||
- traefik.http.services.dashboard.loadbalancer.server.port=80
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "500m"
|
||||
max-file: "2"
|
||||
|
||||
dashboard-health:
|
||||
image: curlimages/curl:8.22.0
|
||||
network_mode: service:dashboard
|
||||
depends_on:
|
||||
dashboard:
|
||||
condition: service_started
|
||||
entrypoint: ["sleep", "infinity"]
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-fsS", "http://127.0.0.1/"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 15s
|
||||
restart: unless-stopped
|
||||
|
||||
netbird-server:
|
||||
image: netbirdio/netbird-server:0.82.0
|
||||
container_name: netbird-server
|
||||
restart: unless-stopped
|
||||
networks: [netbird]
|
||||
environment:
|
||||
- NB_SETUP_PAT_ENABLED=true
|
||||
ports:
|
||||
- "3478:3478/udp"
|
||||
volumes:
|
||||
- netbird_data:/var/lib/netbird
|
||||
- ./config.yaml:/etc/netbird/config.yaml:ro
|
||||
command: ["--config", "/etc/netbird/config.yaml"]
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
- traefik.http.routers.netbird-grpc.rule=Host(`${NETBIRD_DOMAIN}`) && (PathPrefix(`/signalexchange.SignalExchange/`) || PathPrefix(`/management.ManagementService/`) || PathPrefix(`/management.ProxyService/`))
|
||||
- traefik.http.routers.netbird-grpc.entrypoints=websecure
|
||||
- traefik.http.routers.netbird-grpc.tls=true
|
||||
- traefik.http.routers.netbird-grpc.tls.certresolver=letsencrypt
|
||||
- traefik.http.routers.netbird-grpc.service=netbird-server-h2c
|
||||
- traefik.http.routers.netbird-grpc.priority=100
|
||||
- traefik.http.routers.netbird-backend.rule=Host(`${NETBIRD_DOMAIN}`) && (PathPrefix(`/relay`) || PathPrefix(`/ws-proxy/`) || PathPrefix(`/api`) || PathPrefix(`/oauth2`))
|
||||
- traefik.http.routers.netbird-backend.entrypoints=websecure
|
||||
- traefik.http.routers.netbird-backend.tls=true
|
||||
- traefik.http.routers.netbird-backend.tls.certresolver=letsencrypt
|
||||
- traefik.http.routers.netbird-backend.service=netbird-server
|
||||
- traefik.http.routers.netbird-backend.priority=100
|
||||
- traefik.http.services.netbird-server.loadbalancer.server.port=80
|
||||
- traefik.http.services.netbird-server-h2c.loadbalancer.server.port=80
|
||||
- traefik.http.services.netbird-server-h2c.loadbalancer.server.scheme=h2c
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "500m"
|
||||
max-file: "2"
|
||||
|
||||
server-health:
|
||||
image: curlimages/curl:8.22.0
|
||||
network_mode: service:netbird-server
|
||||
depends_on:
|
||||
netbird-server:
|
||||
condition: service_started
|
||||
entrypoint: ["sleep", "infinity"]
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-fsS", "http://127.0.0.1:80/oauth2/.well-known/openid-configuration"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
start_period: 20s
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
netbird_data:
|
||||
netbird_traefik_letsencrypt:
|
||||
|
||||
networks:
|
||||
netbird:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.30.0.0/24
|
||||
gateway: 172.30.0.1
|
||||
@@ -1,486 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Идемпотентная синхронизация клиентских групп, Exit Nodes, DNS, setup-ключей и пиров NetBird."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
|
||||
class NetBirdAPI:
|
||||
"""Минимальный клиент NetBird API через curl с --resolve на 127.0.0.1."""
|
||||
|
||||
def __init__(self, domain: str, token: str) -> None:
|
||||
self.domain = domain
|
||||
self.base_url = f"https://{domain}/api"
|
||||
self.token = token
|
||||
|
||||
def request(
|
||||
self,
|
||||
method: str,
|
||||
path: str,
|
||||
payload: dict[str, Any] | None = None,
|
||||
) -> Any:
|
||||
cmd = [
|
||||
"curl",
|
||||
"-sSk",
|
||||
"--resolve",
|
||||
f"{self.domain}:443:127.0.0.1",
|
||||
"-w",
|
||||
"\n%{http_code}",
|
||||
"-X",
|
||||
method,
|
||||
f"{self.base_url}{path}",
|
||||
"-H",
|
||||
f"Authorization: Token {self.token}",
|
||||
]
|
||||
stdin_bytes = None
|
||||
if payload is not None:
|
||||
cmd.extend(["-H", "Content-Type: application/json", "--data-binary", "@-"])
|
||||
stdin_bytes = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
||||
|
||||
proc = subprocess.run(cmd, input=stdin_bytes, capture_output=True, check=False)
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError(
|
||||
f"curl error for {method} {path}: {proc.stderr.decode(errors='replace')}"
|
||||
)
|
||||
|
||||
raw = proc.stdout.decode("utf-8", errors="replace")
|
||||
body, _, code = raw.rpartition("\n")
|
||||
code = code.strip()
|
||||
if code not in ("200", "201", "204"):
|
||||
raise RuntimeError(f"NetBird API {method} {path} returned HTTP {code}: {body}")
|
||||
|
||||
if not body.strip():
|
||||
return None
|
||||
return json.loads(body)
|
||||
|
||||
def get(self, path: str) -> Any:
|
||||
return self.request("GET", path)
|
||||
|
||||
def post(self, path: str, payload: dict[str, Any]) -> Any:
|
||||
return self.request("POST", path, payload)
|
||||
|
||||
def put(self, path: str, payload: dict[str, Any]) -> Any:
|
||||
return self.request("PUT", path, payload)
|
||||
|
||||
def delete(self, path: str) -> Any:
|
||||
return self.request("DELETE", path)
|
||||
|
||||
|
||||
def group_peer_ids(grp: dict[str, Any]) -> list[str]:
|
||||
return [p["id"] for p in (grp.get("peers") or []) if p.get("id")]
|
||||
|
||||
|
||||
def expand_remnawave(cfg: dict[str, Any]) -> None:
|
||||
"""Группы, exit-маршруты и пиры нод берутся из desired.yml, не копируются руками."""
|
||||
if "remnawave_nodes" not in cfg:
|
||||
return
|
||||
nodes = cfg.pop("remnawave_nodes") or []
|
||||
groups: list[str] = []
|
||||
for node in nodes:
|
||||
host = str(node.get("netbird_hostname") or "").strip()
|
||||
if not host:
|
||||
continue
|
||||
group = f"exit-{host}"
|
||||
groups.append(group)
|
||||
client_groups = cfg.setdefault("client_groups", [])
|
||||
if group not in client_groups:
|
||||
client_groups.append(group)
|
||||
exits = cfg.setdefault("exit_nodes", [])
|
||||
if not any(item.get("network_id") == group for item in exits):
|
||||
code = str(node.get("country_code") or "").strip()
|
||||
exits.append(
|
||||
{
|
||||
"network_id": group,
|
||||
"description": f"Exit Node {code} via {host}".strip(),
|
||||
"peer": host,
|
||||
"peer_group": group,
|
||||
"client_groups": ["exit-clients"],
|
||||
"metric": 9999,
|
||||
"masquerade": True,
|
||||
"keep_route": False,
|
||||
"skip_auto_apply": False,
|
||||
"enabled": True,
|
||||
}
|
||||
)
|
||||
peers = cfg.setdefault("peers", [])
|
||||
if not any(item.get("name") == host for item in peers):
|
||||
peers.append({"name": host, "groups": [group], "state": "present"})
|
||||
cfg["_remnawave_exit_groups"] = groups
|
||||
for policy in cfg.get("policies") or []:
|
||||
for rule in policy.get("rules") or []:
|
||||
dest = rule.get("destinations")
|
||||
if dest == "@remnawave_exit_groups":
|
||||
rule["destinations"] = list(groups)
|
||||
elif isinstance(dest, list) and "@remnawave_exit_groups" in dest:
|
||||
expanded: list[str] = []
|
||||
for item in dest:
|
||||
expanded.extend(groups if item == "@remnawave_exit_groups" else [item])
|
||||
rule["destinations"] = expanded
|
||||
|
||||
|
||||
def sync(cfg: dict[str, Any], api: NetBirdAPI) -> dict[str, Any]:
|
||||
changes: list[str] = []
|
||||
warnings: list[str] = []
|
||||
updated_secrets: dict[str, str] = {}
|
||||
expand_remnawave(cfg)
|
||||
|
||||
peers_raw = api.get("/peers") or []
|
||||
groups_raw = api.get("/groups") or []
|
||||
|
||||
groups_by_name: dict[str, dict[str, Any]] = {g["name"]: g for g in groups_raw if g.get("name")}
|
||||
peers_by_name: dict[str, dict[str, Any]] = {}
|
||||
for p in peers_raw:
|
||||
if p.get("name"):
|
||||
peers_by_name[p["name"]] = p
|
||||
if p.get("hostname"):
|
||||
peers_by_name.setdefault(p["hostname"], p)
|
||||
|
||||
def ensure_group(name: str) -> dict[str, Any]:
|
||||
if name in groups_by_name:
|
||||
return groups_by_name[name]
|
||||
created = api.post("/groups", {"name": name, "peers": []})
|
||||
groups_by_name[name] = created
|
||||
changes.append(f"group.create:{name}")
|
||||
return created
|
||||
|
||||
def set_group_peers(grp: dict[str, Any], new_ids: list[str]) -> None:
|
||||
unique_ids = sorted(set(new_ids))
|
||||
payload: dict[str, Any] = {"name": grp["name"], "peers": unique_ids}
|
||||
if grp.get("resources"):
|
||||
payload["resources"] = [
|
||||
{"id": r["id"], "type": r["type"]}
|
||||
for r in grp["resources"]
|
||||
if r.get("id") and r.get("type")
|
||||
]
|
||||
updated = api.put(f"/groups/{grp['id']}", payload)
|
||||
if isinstance(updated, dict) and updated.get("id"):
|
||||
groups_by_name[grp["name"]] = updated
|
||||
else:
|
||||
grp["peers"] = [{"id": pid} for pid in unique_ids]
|
||||
groups_by_name[grp["name"]] = grp
|
||||
|
||||
# 1. Группы клиентов
|
||||
managed_client_groups: set[str] = set()
|
||||
for gname in cfg.get("client_groups") or []:
|
||||
ensure_group(gname)
|
||||
managed_client_groups.add(gname)
|
||||
|
||||
# 2. Управление пирами
|
||||
for item in cfg.get("peers") or []:
|
||||
pname = item["name"]
|
||||
state = item.get("state", "present")
|
||||
peer = peers_by_name.get(pname)
|
||||
|
||||
if state == "absent":
|
||||
if peer is not None:
|
||||
api.delete(f"/peers/{peer['id']}")
|
||||
changes.append(f"peer.delete:{pname}")
|
||||
peers_by_name = {k: v for k, v in peers_by_name.items() if v.get("id") != peer["id"]}
|
||||
for grp in groups_by_name.values():
|
||||
if grp.get("peers"):
|
||||
grp["peers"] = [p for p in grp["peers"] if p.get("id") != peer["id"]]
|
||||
continue
|
||||
|
||||
desired_groups = set(item.get("groups") or [])
|
||||
for gname in desired_groups:
|
||||
ensure_group(gname)
|
||||
|
||||
if peer is None:
|
||||
warnings.append(f"peer not found yet: {pname}")
|
||||
continue
|
||||
|
||||
pid = peer["id"]
|
||||
for gname in sorted(desired_groups):
|
||||
grp = groups_by_name[gname]
|
||||
current_ids = group_peer_ids(grp)
|
||||
if pid not in current_ids:
|
||||
set_group_peers(grp, current_ids + [pid])
|
||||
changes.append(f"group.add_peer:{gname}:{pname}")
|
||||
|
||||
for gname in sorted(managed_client_groups - desired_groups):
|
||||
if gname not in groups_by_name:
|
||||
continue
|
||||
grp = groups_by_name[gname]
|
||||
current_ids = group_peer_ids(grp)
|
||||
if pid in current_ids:
|
||||
set_group_peers(grp, [x for x in current_ids if x != pid])
|
||||
changes.append(f"group.remove_peer:{gname}:{pname}")
|
||||
|
||||
# 3. Выходные шлюзы (Exit Nodes)
|
||||
routes_raw = api.get("/routes") or []
|
||||
for item in cfg.get("exit_nodes") or []:
|
||||
net_id = item["network_id"]
|
||||
peer_name = item.get("peer", "")
|
||||
peer_group_name = item["peer_group"]
|
||||
client_group_names = item.get("client_groups") or []
|
||||
|
||||
peer_grp = ensure_group(peer_group_name)
|
||||
if peer_name and peer_name in peers_by_name:
|
||||
pid = peers_by_name[peer_name]["id"]
|
||||
current_ids = group_peer_ids(peer_grp)
|
||||
if pid not in current_ids:
|
||||
set_group_peers(peer_grp, current_ids + [pid])
|
||||
changes.append(f"group.add_peer:{peer_group_name}:{peer_name}")
|
||||
|
||||
client_group_ids = [ensure_group(g)["id"] for g in client_group_names]
|
||||
peer_group_ids = [groups_by_name[peer_group_name]["id"]]
|
||||
|
||||
desired = {
|
||||
"description": item.get("description", f"Exit Node ({net_id})"),
|
||||
"network_id": net_id,
|
||||
"enabled": bool(item.get("enabled", True)),
|
||||
"peer_groups": peer_group_ids,
|
||||
"network": "0.0.0.0/0",
|
||||
"metric": int(item.get("metric", 100)),
|
||||
"masquerade": bool(item.get("masquerade", True)),
|
||||
"groups": client_group_ids,
|
||||
"keep_route": bool(item.get("keep_route", True)),
|
||||
"skip_auto_apply": bool(item.get("skip_auto_apply", False)),
|
||||
}
|
||||
|
||||
existing = next(
|
||||
(r for r in routes_raw if r.get("network_id") == net_id and r.get("network") == "0.0.0.0/0"),
|
||||
None,
|
||||
)
|
||||
if existing is None:
|
||||
if not group_peer_ids(groups_by_name[peer_group_name]):
|
||||
warnings.append(f"exit_node {net_id}: no peers in {peer_group_name} yet")
|
||||
continue
|
||||
api.post("/routes", desired)
|
||||
changes.append(f"route.create:{net_id}")
|
||||
else:
|
||||
needs_update = (
|
||||
(existing.get("description") or "") != desired["description"]
|
||||
or bool(existing.get("enabled")) != desired["enabled"]
|
||||
or int(existing.get("metric", 100)) != desired["metric"]
|
||||
or bool(existing.get("masquerade")) != desired["masquerade"]
|
||||
or bool(existing.get("keep_route")) != desired["keep_route"]
|
||||
or bool(existing.get("skip_auto_apply")) != desired["skip_auto_apply"]
|
||||
or sorted(existing.get("peer_groups") or []) != sorted(desired["peer_groups"])
|
||||
or sorted(existing.get("groups") or []) != sorted(desired["groups"])
|
||||
)
|
||||
if needs_update:
|
||||
api.put(f"/routes/{existing['id']}", desired)
|
||||
changes.append(f"route.update:{net_id}")
|
||||
|
||||
keep_exit_groups = cfg.get("_remnawave_exit_groups")
|
||||
if keep_exit_groups is not None:
|
||||
keep = set(keep_exit_groups)
|
||||
for route in routes_raw:
|
||||
net_id = str(route.get("network_id") or "")
|
||||
if route.get("network") == "0.0.0.0/0" and net_id.startswith("exit-") and net_id not in keep and route.get("id"):
|
||||
api.delete(f"/routes/{route['id']}")
|
||||
changes.append(f"route.delete:{net_id}")
|
||||
for gname, grp in list(groups_by_name.items()):
|
||||
if not gname.startswith("exit-") or gname == "exit-clients" or gname in keep:
|
||||
continue
|
||||
current_ids = group_peer_ids(grp)
|
||||
if current_ids:
|
||||
set_group_peers(grp, [])
|
||||
changes.append(f"group.clear:{gname}")
|
||||
|
||||
# 4. DNS Nameservers
|
||||
ns_raw = api.get("/dns/nameservers") or []
|
||||
for item in cfg.get("dns_nameservers") or []:
|
||||
name = item["name"]
|
||||
existing = next((n for n in ns_raw if n.get("name") == name), None)
|
||||
if not bool(item.get("enabled", True)):
|
||||
if existing is not None:
|
||||
api.delete(f"/dns/nameservers/{existing['id']}")
|
||||
changes.append(f"dns.delete:{name}")
|
||||
continue
|
||||
|
||||
group_ids = [ensure_group(g)["id"] for g in (item.get("groups") or [])]
|
||||
desired = {
|
||||
"name": name,
|
||||
"description": item.get("description", ""),
|
||||
"nameservers": [
|
||||
{"ip": s, "ns_type": "udp", "port": 53}
|
||||
for s in (item.get("servers") or [])
|
||||
],
|
||||
"enabled": True,
|
||||
"groups": group_ids,
|
||||
"primary": bool(item.get("primary", True)),
|
||||
"domains": item.get("domains") or [],
|
||||
"search_domains_enabled": bool(item.get("search_domains_enabled", False)),
|
||||
}
|
||||
|
||||
if existing is None:
|
||||
api.post("/dns/nameservers", desired)
|
||||
changes.append(f"dns.create:{name}")
|
||||
else:
|
||||
needs_update = (
|
||||
(existing.get("description") or "") != desired["description"]
|
||||
or (existing.get("nameservers") or []) != desired["nameservers"]
|
||||
or bool(existing.get("enabled")) != desired["enabled"]
|
||||
or sorted(existing.get("groups") or []) != sorted(desired["groups"])
|
||||
or bool(existing.get("primary")) != desired["primary"]
|
||||
or (existing.get("domains") or []) != desired["domains"]
|
||||
or bool(existing.get("search_domains_enabled")) != desired["search_domains_enabled"]
|
||||
)
|
||||
if needs_update:
|
||||
api.put(f"/dns/nameservers/{existing['id']}", desired)
|
||||
changes.append(f"dns.update:{name}")
|
||||
|
||||
# 5. Setup-ключи клиентов
|
||||
keys_raw = api.get("/setup-keys") or []
|
||||
for item in cfg.get("setup_keys") or []:
|
||||
name = item["name"]
|
||||
secret_var = item["secret"]
|
||||
enabled = bool(item.get("enabled", True))
|
||||
matching = [k for k in keys_raw if k.get("name") == name]
|
||||
|
||||
if not enabled:
|
||||
for k in matching:
|
||||
api.delete(f"/setup-keys/{k['id']}")
|
||||
changes.append(f"setup_key.delete:{name}")
|
||||
continue
|
||||
|
||||
group_ids = [ensure_group(g)["id"] for g in (item.get("groups") or [])]
|
||||
env_present = bool(os.environ.get(secret_var, ""))
|
||||
valid_match = next(
|
||||
(
|
||||
k
|
||||
for k in matching
|
||||
if k.get("valid") is True
|
||||
and k.get("revoked") is False
|
||||
and sorted(k.get("auto_groups") or []) == sorted(group_ids)
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
if valid_match is not None and env_present:
|
||||
continue
|
||||
|
||||
for k in matching:
|
||||
api.delete(f"/setup-keys/{k['id']}")
|
||||
|
||||
key_payload = {
|
||||
"name": name,
|
||||
"type": item.get("type", "reusable"),
|
||||
"expires_in": int(item.get("expires_in", 31536000)),
|
||||
"revoked": False,
|
||||
"auto_groups": group_ids,
|
||||
"usage_limit": int(item.get("usage_limit", 0)),
|
||||
"ephemeral": bool(item.get("ephemeral", False)),
|
||||
}
|
||||
created_key = api.post("/setup-keys", key_payload)
|
||||
plain_key = (created_key or {}).get("key", "")
|
||||
if not plain_key:
|
||||
raise RuntimeError(f"NetBird API did not return key for setup_key {name}")
|
||||
updated_secrets[secret_var] = plain_key
|
||||
changes.append(f"setup_key.reissue:{name}")
|
||||
|
||||
# 6. Политики доступа (Zero-Trust ACL)
|
||||
if "policies" in cfg:
|
||||
policies_raw = api.get("/policies") or []
|
||||
existing_by_name = {p.get("name"): p for p in policies_raw if p.get("name")}
|
||||
desired_policy_names: set[str] = set()
|
||||
|
||||
def _extract_group_ids(items: list[Any]) -> list[str]:
|
||||
out: list[str] = []
|
||||
for x in items or []:
|
||||
if isinstance(x, dict) and x.get("id"):
|
||||
out.append(str(x["id"]))
|
||||
elif isinstance(x, str):
|
||||
out.append(x)
|
||||
return sorted(out)
|
||||
|
||||
for p_cfg in cfg.get("policies") or []:
|
||||
p_name = p_cfg["name"]
|
||||
desired_policy_names.add(p_name)
|
||||
rules_payload: list[dict[str, Any]] = []
|
||||
for r_cfg in p_cfg.get("rules") or []:
|
||||
src_ids = sorted(ensure_group(g)["id"] for g in (r_cfg.get("sources") or []))
|
||||
dst_ids = sorted(ensure_group(g)["id"] for g in (r_cfg.get("destinations") or []))
|
||||
rule_obj: dict[str, Any] = {
|
||||
"name": r_cfg["name"],
|
||||
"description": r_cfg.get("description", ""),
|
||||
"enabled": bool(r_cfg.get("enabled", True)),
|
||||
"action": r_cfg.get("action", "accept"),
|
||||
"protocol": r_cfg.get("protocol", "tcp"),
|
||||
"bidirectional": bool(r_cfg.get("bidirectional", False)),
|
||||
"sources": src_ids,
|
||||
"destinations": dst_ids,
|
||||
}
|
||||
if r_cfg.get("ports"):
|
||||
rule_obj["ports"] = [str(p) for p in r_cfg["ports"]]
|
||||
rules_payload.append(rule_obj)
|
||||
|
||||
desired_pol = {
|
||||
"name": p_name,
|
||||
"description": p_cfg.get("description", ""),
|
||||
"enabled": bool(p_cfg.get("enabled", True)),
|
||||
"rules": rules_payload,
|
||||
}
|
||||
|
||||
ex_pol = existing_by_name.get(p_name)
|
||||
if ex_pol is None:
|
||||
api.post("/policies", desired_pol)
|
||||
changes.append(f"policy.create:{p_name}")
|
||||
else:
|
||||
ex_rules = ex_pol.get("rules") or []
|
||||
norm_ex_rules = [
|
||||
{
|
||||
"name": r.get("name", ""),
|
||||
"description": r.get("description", ""),
|
||||
"enabled": bool(r.get("enabled", True)),
|
||||
"action": r.get("action", "accept"),
|
||||
"protocol": r.get("protocol", "tcp"),
|
||||
"bidirectional": bool(r.get("bidirectional", False)),
|
||||
"sources": _extract_group_ids(r.get("sources") or []),
|
||||
"destinations": _extract_group_ids(r.get("destinations") or []),
|
||||
**(
|
||||
{"ports": [str(p) for p in r["ports"]]}
|
||||
if r.get("ports")
|
||||
else {}
|
||||
),
|
||||
}
|
||||
for r in ex_rules
|
||||
]
|
||||
needs_pol_update = (
|
||||
(ex_pol.get("description") or "") != desired_pol["description"]
|
||||
or bool(ex_pol.get("enabled", True)) != desired_pol["enabled"]
|
||||
or norm_ex_rules != rules_payload
|
||||
)
|
||||
if needs_pol_update:
|
||||
api.put(f"/policies/{ex_pol['id']}", desired_pol)
|
||||
changes.append(f"policy.update:{p_name}")
|
||||
|
||||
# Удаляем дефолтную (All <-> All) и любые лишние политики после создания целевых
|
||||
for ex_name, ex_pol in existing_by_name.items():
|
||||
if ex_name not in desired_policy_names and ex_pol.get("id"):
|
||||
api.delete(f"/policies/{ex_pol['id']}")
|
||||
changes.append(f"policy.delete:{ex_name}")
|
||||
|
||||
return {
|
||||
"changed": bool(changes or updated_secrets),
|
||||
"changes": changes,
|
||||
"warnings": warnings,
|
||||
"updated_secret_names": sorted(updated_secrets.keys()),
|
||||
"updated_secrets": updated_secrets,
|
||||
}
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if len(sys.argv) < 2:
|
||||
raise SystemExit("Usage: sync_access.py <access.json>")
|
||||
|
||||
domain = os.environ.get("NB_DOMAIN", "")
|
||||
token = os.environ.get("NB_API_TOKEN", "")
|
||||
if not domain or not token:
|
||||
raise SystemExit("NB_DOMAIN and NB_API_TOKEN are required")
|
||||
|
||||
with open(sys.argv[1], "r", encoding="utf-8") as fh:
|
||||
cfg = json.load(fh)
|
||||
|
||||
api = NetBirdAPI(domain=domain, token=token)
|
||||
result = sync(cfg, api)
|
||||
sys.stdout.write(json.dumps(result, ensure_ascii=False) + "\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
- name: Перезапустить NetBird
|
||||
ansible.builtin.command: docker compose up -d --force-recreate --remove-orphans
|
||||
args:
|
||||
chdir: "{{ netbird_dir }}"
|
||||
register: compose_up
|
||||
changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr"
|
||||
tags: [always]
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
---
|
||||
- name: Загрузить декларативную конфигурацию доступа NetBird
|
||||
ansible.builtin.set_fact:
|
||||
netbird_access_cfg: "{{ lookup('file', role_path ~ '/files/access.yml') | from_yaml }}"
|
||||
netbird_remnawave_nodes: "{{ (lookup('file', playbook_dir ~ '/../roles/core-net/remnawave/files/desired.yml') | from_yaml).nodes | default([]) }}"
|
||||
|
||||
- name: Передать ноды Remnawave в синхронизацию доступа
|
||||
ansible.builtin.set_fact:
|
||||
netbird_access_cfg: "{{ netbird_access_cfg | combine({'remnawave_nodes': netbird_remnawave_nodes}) }}"
|
||||
|
||||
- name: Положить скрипт синхронизации доступа NetBird
|
||||
ansible.builtin.copy:
|
||||
src: sync_access.py
|
||||
dest: "{{ netbird_dir }}/sync_access.py"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0700"
|
||||
|
||||
- name: Записать конфигурацию доступа NetBird
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ netbird_dir }}/access.json"
|
||||
content: "{{ netbird_access_cfg | to_json }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
|
||||
- name: Подготовить базовое окружение для sync_access.py
|
||||
ansible.builtin.set_fact:
|
||||
netbird_access_env:
|
||||
NB_DOMAIN: "{{ netbird_domain }}"
|
||||
NB_API_TOKEN: "{{ netbird_effective_api_token }}"
|
||||
no_log: true
|
||||
|
||||
- name: Добавить текущие клиентские setup-ключи в окружение sync_access.py
|
||||
ansible.builtin.set_fact:
|
||||
netbird_access_env: "{{ netbird_access_env | combine({item.secret: lookup('env', item.secret)}) }}"
|
||||
loop: "{{ netbird_access_cfg.setup_keys | default([]) }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
no_log: true
|
||||
|
||||
- name: Синхронизировать группы, Exit Nodes, DNS, ключи и пиры NetBird
|
||||
ansible.builtin.command: "python3 {{ netbird_dir }}/sync_access.py {{ netbird_dir }}/access.json"
|
||||
environment: "{{ netbird_access_env }}"
|
||||
register: netbird_access_raw
|
||||
changed_when: (netbird_access_raw.stdout | from_json).changed
|
||||
no_log: true
|
||||
|
||||
- name: Разобрать результат синхронизации доступа NetBird
|
||||
ansible.builtin.set_fact:
|
||||
netbird_access_state: "{{ netbird_access_raw.stdout | from_json }}"
|
||||
netbird_access_summary:
|
||||
changed: "{{ (netbird_access_raw.stdout | from_json).changed }}"
|
||||
changes: "{{ (netbird_access_raw.stdout | from_json).changes }}"
|
||||
warnings: "{{ (netbird_access_raw.stdout | from_json).warnings }}"
|
||||
updated_secret_names: "{{ (netbird_access_raw.stdout | from_json).updated_secret_names }}"
|
||||
no_log: true
|
||||
|
||||
- name: Сохранить клиентские setup-ключи NetBird в Infisical
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
infisical secrets set \
|
||||
--domain="${INFISICAL_DOMAIN}" \
|
||||
--token="${INFISICAL_TOKEN}" \
|
||||
--env=prod \
|
||||
--projectId="${INFISICAL_PROJECT_ID}" \
|
||||
--path="/services/netbird" \
|
||||
"${NB_SECRET_KEY}=${NB_SECRET_VAL}" \
|
||||
--silent
|
||||
args:
|
||||
executable: /bin/bash
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
environment:
|
||||
NB_SECRET_KEY: "{{ item.key }}"
|
||||
NB_SECRET_VAL: "{{ item.value }}"
|
||||
loop: "{{ netbird_access_state.updated_secrets | default({}) | dict2items }}"
|
||||
loop_control:
|
||||
label: "{{ item.key }}"
|
||||
when: (netbird_access_state.updated_secrets | default({}) | length) > 0
|
||||
changed_when: true
|
||||
no_log: true
|
||||
@@ -1,288 +0,0 @@
|
||||
---
|
||||
- name: Инициализировать системный каркас NetBird (администратор, токен, базовые группы и маршруты)
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
|
||||
API_BASE="https://{{ netbird_domain }}/api"
|
||||
CURL_OPTS=(-fsSk --resolve "{{ netbird_domain }}:443:127.0.0.1")
|
||||
|
||||
admin_created=0
|
||||
token_updated=0
|
||||
setup_key_updated=0
|
||||
remna_key_updated=0
|
||||
route_created=0
|
||||
|
||||
setup_req=$(curl "${CURL_OPTS[@]}" "${API_BASE}/instance" | jq -r '.setup_required')
|
||||
bootstrap_auth_header=""
|
||||
|
||||
if [ "${setup_req}" = "true" ]; then
|
||||
setup_payload=$(jq -n \
|
||||
--arg email "$NB_ADMIN_EMAIL" \
|
||||
--arg password "$NB_ADMIN_PASSWORD" \
|
||||
--arg name "$NB_ADMIN_NAME" \
|
||||
'{email: $email, password: $password, name: $name, create_pat: true}')
|
||||
setup_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/setup" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${setup_payload}")
|
||||
bootstrap_token=$(printf '%s' "${setup_resp}" | jq -r '.personal_access_token // empty')
|
||||
if [ -z "${bootstrap_token}" ]; then
|
||||
echo "Не удалось получить personal_access_token из /api/setup" >&2
|
||||
exit 1
|
||||
fi
|
||||
bootstrap_auth_header="Authorization: Token ${bootstrap_token}"
|
||||
admin_created=1
|
||||
fi
|
||||
|
||||
active_token="${NB_API_TOKEN:-}"
|
||||
token_valid=0
|
||||
if [ -n "${active_token}" ]; then
|
||||
http_code=$(curl -sSk --resolve "{{ netbird_domain }}:443:127.0.0.1" -o /dev/null -w '%{http_code}' \
|
||||
-H "Authorization: Token ${active_token}" "${API_BASE}/users" || true)
|
||||
if [ "${http_code}" = "200" ]; then
|
||||
token_valid=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${token_valid}" -eq 0 ]; then
|
||||
if [ -z "${bootstrap_auth_header}" ]; then
|
||||
verifier="dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
|
||||
challenge="E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"
|
||||
redirect_uri="https://{{ netbird_domain }}/nb-auth"
|
||||
auth_url="https://{{ netbird_domain }}/oauth2/auth?client_id=netbird-dashboard&redirect_uri=${redirect_uri}&response_type=code&scope=openid+profile+email+groups&code_challenge=${challenge}&code_challenge_method=S256&state=ansible"
|
||||
|
||||
login_page=$(curl -sLk --resolve "{{ netbird_domain }}:443:127.0.0.1" "${auth_url}")
|
||||
login_action=$(printf '%s' "${login_page}" | grep -oE 'action="[^"]+"' | head -n 1 | cut -d'"' -f2 | sed 's/&/\&/g')
|
||||
if [ -z "${login_action}" ]; then
|
||||
echo "Не удалось получить форму входа OAuth2 для выпуска токена" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
redir_loc=$(curl -sSk --resolve "{{ netbird_domain }}:443:127.0.0.1" -o /dev/null -w '%{redirect_url}' \
|
||||
-X POST "https://{{ netbird_domain }}${login_action}" \
|
||||
--data-urlencode "login=${NB_ADMIN_EMAIL}" \
|
||||
--data-urlencode "password=${NB_ADMIN_PASSWORD}")
|
||||
|
||||
if printf '%s' "${redir_loc}" | grep -q '/oauth2/approval'; then
|
||||
redir_loc=$(curl -sSk --resolve "{{ netbird_domain }}:443:127.0.0.1" -o /dev/null -w '%{redirect_url}' "${redir_loc}")
|
||||
fi
|
||||
|
||||
auth_code=$(printf '%s' "${redir_loc}" | sed -n 's/.*[?&]code=\([^&]*\).*/\1/p')
|
||||
if [ -z "${auth_code}" ]; then
|
||||
echo "Не удалось получить authorization code через OAuth2 (проверьте NETBIRD_ADMIN_EMAIL / NETBIRD_ADMIN_PASSWORD)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
token_resp=$(curl "${CURL_OPTS[@]}" -X POST "https://{{ netbird_domain }}/oauth2/token" \
|
||||
--data-urlencode "grant_type=authorization_code" \
|
||||
--data-urlencode "client_id=netbird-dashboard" \
|
||||
--data-urlencode "redirect_uri=${redirect_uri}" \
|
||||
--data-urlencode "code=${auth_code}" \
|
||||
--data-urlencode "code_verifier=${verifier}")
|
||||
jwt_token=$(printf '%s' "${token_resp}" | jq -r '.access_token // .id_token // empty')
|
||||
if [ -z "${jwt_token}" ]; then
|
||||
echo "Не удалось обменять authorization code на JWT токен" >&2
|
||||
exit 1
|
||||
fi
|
||||
bootstrap_auth_header="Authorization: Bearer ${jwt_token}"
|
||||
fi
|
||||
|
||||
users_json=$(curl "${CURL_OPTS[@]}" -H "${bootstrap_auth_header}" "${API_BASE}/users")
|
||||
svc_user_id=$(printf '%s' "${users_json}" | jq -r '.[] | select(.is_service_user == true and .name == "infra-automation") | .id' | head -n 1)
|
||||
|
||||
if [ -z "${svc_user_id}" ]; then
|
||||
user_payload=$(jq -n '{name: "infra-automation", role: "admin", auto_groups: [], is_service_user: true}')
|
||||
svc_user_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/users" \
|
||||
-H "${bootstrap_auth_header}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${user_payload}")
|
||||
svc_user_id=$(printf '%s' "${svc_user_resp}" | jq -r '.id')
|
||||
fi
|
||||
|
||||
old_tokens=$(curl "${CURL_OPTS[@]}" -H "${bootstrap_auth_header}" "${API_BASE}/users/${svc_user_id}/tokens" || echo "[]")
|
||||
for old_tid in $(printf '%s' "${old_tokens}" | jq -r '.[] | select(.name == "infisical-ci-token") | .id'); do
|
||||
curl "${CURL_OPTS[@]}" -X DELETE -H "${bootstrap_auth_header}" "${API_BASE}/users/${svc_user_id}/tokens/${old_tid}" >/dev/null || true
|
||||
done
|
||||
|
||||
pat_payload=$(jq -n '{name: "infisical-ci-token", expires_in: 365}')
|
||||
pat_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/users/${svc_user_id}/tokens" \
|
||||
-H "${bootstrap_auth_header}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${pat_payload}")
|
||||
active_token=$(printf '%s' "${pat_resp}" | jq -r '.plain_token // .plain_text // empty')
|
||||
if [ -z "${active_token}" ]; then
|
||||
echo "Не удалось выпустить сервисный токен через /api/users/${svc_user_id}/tokens" >&2
|
||||
exit 1
|
||||
fi
|
||||
token_updated=1
|
||||
fi
|
||||
|
||||
groups_json=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/groups")
|
||||
router_group_id=$(printf '%s' "${groups_json}" | jq -r --arg g "$NB_ROUTER_GROUP" '.[] | select(.name == $g) | .id' | head -n 1)
|
||||
|
||||
if [ -z "${router_group_id}" ]; then
|
||||
grp_payload=$(jq -n --arg name "$NB_ROUTER_GROUP" '{name: $name, peers: []}')
|
||||
grp_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/groups" \
|
||||
-H "Authorization: Token ${active_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${grp_payload}")
|
||||
router_group_id=$(printf '%s' "${grp_resp}" | jq -r '.id')
|
||||
fi
|
||||
|
||||
remna_group_id=$(printf '%s' "${groups_json}" | jq -r --arg g "$NB_REMNAWAVE_GROUP" '.[] | select(.name == $g) | .id' | head -n 1)
|
||||
if [ -z "${remna_group_id}" ]; then
|
||||
grp_payload=$(jq -n --arg name "$NB_REMNAWAVE_GROUP" '{name: $name, peers: []}')
|
||||
grp_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/groups" \
|
||||
-H "Authorization: Token ${active_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${grp_payload}")
|
||||
remna_group_id=$(printf '%s' "${grp_resp}" | jq -r '.id // empty')
|
||||
if [ -z "${remna_group_id}" ]; then
|
||||
echo "Не удалось создать группу NetBird для Remnawave" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
routes_json=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/routes")
|
||||
existing_route=$(printf '%s' "${routes_json}" | jq -c --arg nid "$NB_LAN_NET_ID" --arg net "$NB_LAN_SUBNET" '.[] | select(.network_id == $nid or .network == $net)' | head -n 1)
|
||||
existing_route_id=$(printf '%s' "${existing_route}" | jq -r '.id // empty' 2>/dev/null || true)
|
||||
if [ -n "${existing_route_id}" ]; then
|
||||
curl "${CURL_OPTS[@]}" -X DELETE "${API_BASE}/routes/${existing_route_id}" \
|
||||
-H "Authorization: Token ${active_token}" >/dev/null || true
|
||||
route_created=1
|
||||
fi
|
||||
|
||||
active_setup_key="${NB_SETUP_KEY:-}"
|
||||
keys_json=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/setup-keys")
|
||||
valid_key_id=$(printf '%s' "${keys_json}" | jq -r --arg kname "$NB_SETUP_KEY_NAME" '.[] | select(.name == $kname and .valid == true and .revoked == false) | .id' | head -n 1)
|
||||
|
||||
if [ -z "${active_setup_key}" ] || [ -z "${valid_key_id}" ]; then
|
||||
for old_kid in $(printf '%s' "${keys_json}" | jq -r --arg kname "$NB_SETUP_KEY_NAME" '.[] | select(.name == $kname) | .id'); do
|
||||
curl "${CURL_OPTS[@]}" -X DELETE -H "Authorization: Token ${active_token}" "${API_BASE}/setup-keys/${old_kid}" >/dev/null || true
|
||||
done
|
||||
key_payload=$(jq -n \
|
||||
--arg name "$NB_SETUP_KEY_NAME" \
|
||||
--arg rg "$router_group_id" \
|
||||
'{
|
||||
name: $name,
|
||||
type: "reusable",
|
||||
expires_in: 31536000,
|
||||
revoked: false,
|
||||
auto_groups: [$rg],
|
||||
usage_limit: 0,
|
||||
ephemeral: false
|
||||
}')
|
||||
key_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/setup-keys" \
|
||||
-H "Authorization: Token ${active_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${key_payload}")
|
||||
active_setup_key=$(printf '%s' "${key_resp}" | jq -r '.key // empty')
|
||||
if [ -z "${active_setup_key}" ]; then
|
||||
echo "Не удалось создать ключ установки через /api/setup-keys" >&2
|
||||
exit 1
|
||||
fi
|
||||
setup_key_updated=1
|
||||
fi
|
||||
|
||||
active_remna_key="${NB_REMNAWAVE_SETUP_KEY:-}"
|
||||
valid_remna_id=$(printf '%s' "${keys_json}" | jq -r --arg kname "$NB_REMNAWAVE_KEY_NAME" '.[] | select(.name == $kname and .valid == true and .revoked == false) | .id' | head -n 1)
|
||||
if [ -z "${active_remna_key}" ] || [ -z "${valid_remna_id}" ]; then
|
||||
fresh_keys=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/setup-keys")
|
||||
for old_kid in $(printf '%s' "${fresh_keys}" | jq -r --arg kname "$NB_REMNAWAVE_KEY_NAME" '.[] | select(.name == $kname) | .id'); do
|
||||
curl "${CURL_OPTS[@]}" -X DELETE -H "Authorization: Token ${active_token}" "${API_BASE}/setup-keys/${old_kid}" >/dev/null || true
|
||||
done
|
||||
key_payload=$(jq -n \
|
||||
--arg name "$NB_REMNAWAVE_KEY_NAME" \
|
||||
--arg gid "$remna_group_id" \
|
||||
'{
|
||||
name: $name,
|
||||
type: "reusable",
|
||||
expires_in: 31536000,
|
||||
revoked: false,
|
||||
auto_groups: [$gid],
|
||||
usage_limit: 0,
|
||||
ephemeral: false
|
||||
}')
|
||||
key_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/setup-keys" \
|
||||
-H "Authorization: Token ${active_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${key_payload}")
|
||||
active_remna_key=$(printf '%s' "${key_resp}" | jq -r '.key // empty')
|
||||
if [ -z "${active_remna_key}" ]; then
|
||||
echo "Не удалось создать ключ установки remnawave-peers" >&2
|
||||
exit 1
|
||||
fi
|
||||
remna_key_updated=1
|
||||
fi
|
||||
|
||||
jq -n \
|
||||
--arg api_token "${active_token}" \
|
||||
--arg setup_key "${active_setup_key}" \
|
||||
--arg remna_key "${active_remna_key}" \
|
||||
--argjson admin_created "${admin_created}" \
|
||||
--argjson token_updated "${token_updated}" \
|
||||
--argjson setup_key_updated "${setup_key_updated}" \
|
||||
--argjson remna_key_updated "${remna_key_updated}" \
|
||||
--argjson route_created "${route_created}" \
|
||||
'{
|
||||
api_token: $api_token,
|
||||
setup_key: $setup_key,
|
||||
remnawave_setup_key: $remna_key,
|
||||
admin_created: ($admin_created == 1),
|
||||
token_updated: ($token_updated == 1),
|
||||
setup_key_updated: ($setup_key_updated == 1),
|
||||
remnawave_setup_key_updated: ($remna_key_updated == 1),
|
||||
route_created: ($route_created == 1),
|
||||
changed: (($admin_created + $token_updated + $setup_key_updated + $remna_key_updated + $route_created) > 0)
|
||||
}'
|
||||
args:
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
NB_ADMIN_EMAIL: "{{ netbird_admin_email }}"
|
||||
NB_ADMIN_NAME: "{{ netbird_admin_name }}"
|
||||
NB_ADMIN_PASSWORD: "{{ netbird_admin_password }}"
|
||||
NB_API_TOKEN: "{{ netbird_api_token }}"
|
||||
NB_SETUP_KEY: "{{ netbird_setup_key }}"
|
||||
NB_ROUTER_GROUP: "{{ netbird_router_group_name }}"
|
||||
NB_SETUP_KEY_NAME: "{{ netbird_setup_key_name }}"
|
||||
NB_REMNAWAVE_GROUP: "{{ netbird_remnawave_group_name }}"
|
||||
NB_REMNAWAVE_KEY_NAME: "{{ netbird_remnawave_setup_key_name }}"
|
||||
NB_REMNAWAVE_SETUP_KEY: "{{ netbird_remnawave_setup_key }}"
|
||||
NB_LAN_NET_ID: "{{ netbird_lan_network_id }}"
|
||||
NB_LAN_SUBNET: "{{ netbird_lan_subnet }}"
|
||||
register: netbird_bootstrap_raw
|
||||
changed_when: (netbird_bootstrap_raw.stdout | from_json).changed
|
||||
no_log: true
|
||||
|
||||
- name: Сохранить системный токен NetBird в фактах
|
||||
ansible.builtin.set_fact:
|
||||
netbird_bootstrap_state: "{{ netbird_bootstrap_raw.stdout | from_json }}"
|
||||
netbird_effective_api_token: "{{ (netbird_bootstrap_raw.stdout | from_json).api_token }}"
|
||||
no_log: true
|
||||
|
||||
- name: Сохранить системные ключи NetBird в Infisical
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
infisical secrets set \
|
||||
--domain="${INFISICAL_DOMAIN}" \
|
||||
--token="${INFISICAL_TOKEN}" \
|
||||
--env=prod \
|
||||
--projectId="${INFISICAL_PROJECT_ID}" \
|
||||
--path="/services/netbird" \
|
||||
"NETBIRD_API_TOKEN=${NEW_API_TOKEN}" \
|
||||
"NETBIRD_SETUP_KEY=${NEW_SETUP_KEY}" \
|
||||
"NETBIRD_REMNAWAVE_SETUP_KEY=${NEW_REMNAWAVE_SETUP_KEY}" \
|
||||
--silent
|
||||
args:
|
||||
executable: /bin/bash
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
environment:
|
||||
NEW_API_TOKEN: "{{ netbird_bootstrap_state.api_token }}"
|
||||
NEW_SETUP_KEY: "{{ netbird_bootstrap_state.setup_key }}"
|
||||
NEW_REMNAWAVE_SETUP_KEY: "{{ netbird_bootstrap_state.remnawave_setup_key }}"
|
||||
when: >-
|
||||
netbird_bootstrap_state.token_updated or
|
||||
netbird_bootstrap_state.setup_key_updated or
|
||||
netbird_bootstrap_state.remnawave_setup_key_updated
|
||||
changed_when: true
|
||||
no_log: true
|
||||
@@ -1,136 +0,0 @@
|
||||
---
|
||||
- name: Разрешить порты панели
|
||||
ansible.builtin.command: ufw allow {{ item }}
|
||||
register: ufw_rule
|
||||
changed_when: "'added' in (ufw_rule.stdout | lower)"
|
||||
loop: "{{ netbird_ports }}"
|
||||
|
||||
- name: Поставить openssl, curl и jq
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- openssl
|
||||
- curl
|
||||
- jq
|
||||
state: present
|
||||
|
||||
- name: Создать каталог панели
|
||||
ansible.builtin.file:
|
||||
path: "{{ netbird_dir }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0700"
|
||||
|
||||
- name: Проверить наличие обязательных секретов NetBird
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- netbird_domain is defined and netbird_domain | length > 3
|
||||
- netbird_auth_secret is defined and netbird_auth_secret | length > 0
|
||||
- netbird_datastore_key is defined and netbird_datastore_key | length > 0
|
||||
- netbird_session_key is defined and netbird_session_key | length > 0
|
||||
- netbird_letsencrypt_email is defined and netbird_letsencrypt_email | length > 3
|
||||
- netbird_admin_email is defined and netbird_admin_email | length > 3
|
||||
- netbird_admin_name is defined and netbird_admin_name | length > 0
|
||||
- netbird_admin_password is defined and netbird_admin_password | length >= 8
|
||||
fail_msg: "Не задан домен NetBird (host_vars) или один из секретов NETBIRD_AUTH_SECRET, NETBIRD_DATASTORE_KEY, NETBIRD_SESSION_KEY, NETBIRD_LETSENCRYPT_EMAIL, NETBIRD_ADMIN_EMAIL, NETBIRD_ADMIN_NAME, NETBIRD_ADMIN_PASSWORD (мин. 8 символов)."
|
||||
|
||||
- name: Записать .env
|
||||
ansible.builtin.template:
|
||||
src: env.j2
|
||||
dest: "{{ netbird_dir }}/.env"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
no_log: true
|
||||
notify: Перезапустить NetBird
|
||||
|
||||
- name: Положить манифест панели
|
||||
ansible.builtin.copy:
|
||||
src: compose.yaml
|
||||
dest: "{{ netbird_dir }}/compose.yaml"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Перезапустить NetBird
|
||||
|
||||
- name: Собрать dashboard.env
|
||||
ansible.builtin.template:
|
||||
src: dashboard.env.j2
|
||||
dest: "{{ netbird_dir }}/dashboard.env"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Перезапустить NetBird
|
||||
|
||||
- name: Собрать config.yaml
|
||||
ansible.builtin.template:
|
||||
src: config.yaml.j2
|
||||
dest: "{{ netbird_dir }}/config.yaml"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
no_log: true
|
||||
notify: Перезапустить NetBird
|
||||
|
||||
- name: Применить изменения конфигурации
|
||||
ansible.builtin.meta: flush_handlers
|
||||
|
||||
- name: Убедиться, что панель запущена
|
||||
ansible.builtin.command: docker compose up -d
|
||||
args:
|
||||
chdir: "{{ netbird_dir }}"
|
||||
register: compose_up
|
||||
changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr"
|
||||
|
||||
- name: Показать состояние контейнеров
|
||||
ansible.builtin.command: docker compose ps
|
||||
args:
|
||||
chdir: "{{ netbird_dir }}"
|
||||
register: compose_ps
|
||||
changed_when: false
|
||||
|
||||
- name: Дождаться ответа панели и API
|
||||
ansible.builtin.command: >
|
||||
curl -fsSk --resolve {{ netbird_domain }}:443:127.0.0.1
|
||||
https://{{ netbird_domain }}/api/instance
|
||||
register: instance_status
|
||||
changed_when: false
|
||||
retries: 30
|
||||
delay: 5
|
||||
until: instance_status.rc == 0 and ('setup_required' in instance_status.stdout)
|
||||
|
||||
- name: Настроить системный каркас NetBird
|
||||
ansible.builtin.include_tasks: bootstrap.yml
|
||||
|
||||
- name: Синхронизировать доступ и клиентов NetBird из access.yml
|
||||
ansible.builtin.include_tasks: access.yml
|
||||
|
||||
# Токен перевыпускается ролью, поэтому регистрация берёт его из Infisical
|
||||
# при каждом прогоне: агент не остаётся с протухшим креденшлом.
|
||||
- name: Зарегистрировать панель NetBird в Agent Vault
|
||||
ansible.builtin.include_role:
|
||||
name: agent_vault_service
|
||||
vars:
|
||||
agent_vault_service_name: netbird
|
||||
agent_vault_service_description: >-
|
||||
Панель NetBird (central.gunihome.ru): пиры, пользователи, setup-ключи
|
||||
и маршруты оверлейной сети. Креденшл — сервисный API-токен.
|
||||
agent_vault_service_host: "{{ netbird_domain }}:443"
|
||||
agent_vault_service_paths: ["/api"]
|
||||
agent_vault_service_methods: [GET]
|
||||
agent_vault_service_header_prefix: Token
|
||||
agent_vault_secret_path: /services/netbird
|
||||
agent_vault_secret_key: NETBIRD_API_TOKEN
|
||||
|
||||
- name: Итог установки
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Панель: https://{{ netbird_domain }}"
|
||||
- "Суперпользователь создан в этом прогоне: {{ netbird_bootstrap_state.admin_created }}"
|
||||
- "API-токен обновлен в Infisical: {{ netbird_bootstrap_state.token_updated }}"
|
||||
- "Setup-ключ роутеров обновлен в Infisical: {{ netbird_bootstrap_state.setup_key_updated }}"
|
||||
- "Ключ remnawave-peers обновлен в Infisical: {{ netbird_bootstrap_state.remnawave_setup_key_updated }}"
|
||||
- "Маршрут {{ netbird_lan_subnet }} создан в этом прогоне: {{ netbird_bootstrap_state.route_created }}"
|
||||
- "Изменения доступа (access.yml): {{ netbird_access_summary.changes }}"
|
||||
- "Обновлённые секреты клиентов в Infisical: {{ netbird_access_summary.updated_secret_names }}"
|
||||
- "Предупреждения access.yml: {{ netbird_access_summary.warnings }}"
|
||||
@@ -1,32 +0,0 @@
|
||||
server:
|
||||
listenAddress: ":80"
|
||||
exposedAddress: "https://{{ netbird_domain }}:443"
|
||||
stunPorts:
|
||||
- 3478
|
||||
metricsPort: 9090
|
||||
healthcheckAddress: ":9000"
|
||||
logLevel: "info"
|
||||
logFile: "console"
|
||||
|
||||
authSecret: "{{ netbird_auth_secret }}"
|
||||
dataDir: "/var/lib/netbird"
|
||||
|
||||
auth:
|
||||
issuer: "https://{{ netbird_domain }}/oauth2"
|
||||
signKeyRefreshEnabled: true
|
||||
sessionCookieEncryptionKey: "{{ netbird_session_key }}"
|
||||
dashboardRedirectURIs:
|
||||
- "https://{{ netbird_domain }}/nb-auth"
|
||||
- "https://{{ netbird_domain }}/nb-silent-auth"
|
||||
cliRedirectURIs:
|
||||
- "http://localhost:53000/"
|
||||
|
||||
reverseProxy:
|
||||
trustedHTTPProxies:
|
||||
- "172.30.0.10/32"
|
||||
trustedPeers:
|
||||
- "172.30.0.10/32"
|
||||
|
||||
store:
|
||||
engine: "sqlite"
|
||||
encryptionKey: "{{ netbird_datastore_key }}"
|
||||
@@ -1,12 +0,0 @@
|
||||
NETBIRD_MGMT_API_ENDPOINT=https://{{ netbird_domain }}
|
||||
NETBIRD_MGMT_GRPC_API_ENDPOINT=https://{{ netbird_domain }}
|
||||
AUTH_AUDIENCE=netbird-dashboard
|
||||
AUTH_CLIENT_ID=netbird-dashboard
|
||||
AUTH_CLIENT_SECRET=
|
||||
AUTH_AUTHORITY=https://{{ netbird_domain }}/oauth2
|
||||
USE_AUTH0=false
|
||||
AUTH_SUPPORTED_SCOPES=openid profile email groups
|
||||
AUTH_REDIRECT_URI=/nb-auth
|
||||
AUTH_SILENT_REDIRECT_URI=/nb-silent-auth
|
||||
NGINX_SSL_PORT=443
|
||||
LETSENCRYPT_DOMAIN=none
|
||||
@@ -1,6 +0,0 @@
|
||||
COMPOSE_PROJECT_NAME=netbird
|
||||
NETBIRD_DOMAIN={{ netbird_domain }}
|
||||
NETBIRD_LETSENCRYPT_EMAIL={{ netbird_letsencrypt_email }}
|
||||
NETBIRD_AUTH_SECRET={{ netbird_auth_secret }}
|
||||
NETBIRD_DATASTORE_KEY={{ netbird_datastore_key }}
|
||||
NETBIRD_SESSION_KEY={{ netbird_session_key }}
|
||||
@@ -14,5 +14,8 @@ vmagent_cadvisor_listen_ip: "{{ '0.0.0.0' if (vmagent_pull_only_target | bool) e
|
||||
vmagent_metrics_user: admin
|
||||
vmagent_metrics_pass: "{{ lookup('env', 'REMNAWAVE_METRICS_PASS', default='') }}"
|
||||
vmagent_metrics_port: 3001
|
||||
vmagent_panel_egress_ips:
|
||||
- "213.128.28.107" # провайдер 1 (МТС)
|
||||
- "185.160.137.140" # провайдер 2
|
||||
monitoring_node_exporter_public: true
|
||||
monitoring_node_exporter_listen: "0.0.0.0:9100"
|
||||
@@ -24,52 +24,27 @@
|
||||
enabled: true
|
||||
when: vmagent_exporter_env is changed
|
||||
|
||||
- name: Узнать NetBird IP панели (core-net) для pull-доступа к метрикам
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
netbird status --json | jq -r '.peers.details[]? | select(.fqdn | startswith("core-net.")) | .netbirdIp' | head -n 1
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: vmagent_panel_nb_ip
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
when: vmagent_pull_only_target | bool
|
||||
|
||||
- name: Разрешить pull метрик (9100, 9101) только с NetBird IP панели (core-net)
|
||||
- name: Разрешить pull метрик (9100, 9101) только с WAN egress панели (core-net)
|
||||
ansible.builtin.command: >
|
||||
ufw allow from {{ vmagent_panel_nb_ip.stdout | trim }} to any port {{ item }} proto tcp
|
||||
loop:
|
||||
- 9100
|
||||
- 9101
|
||||
ufw allow from {{ item.0 }} to any port {{ item.1 }} proto tcp
|
||||
loop: "{{ (remnanode_panel_egress_ips | default(vmagent_panel_egress_ips)) | product([9100, 9101]) | list }}"
|
||||
register: ufw_pull_metrics
|
||||
changed_when: "'added' in (ufw_pull_metrics.stdout | default('') | lower)"
|
||||
when:
|
||||
- vmagent_pull_only_target | bool
|
||||
- vmagent_panel_nb_ip.stdout | default('') | trim is match('^[0-9.]+$')
|
||||
when: vmagent_pull_only_target | bool
|
||||
|
||||
- name: Собрать NetBird IP выходных нод (exit_nodes) для pull с core-net
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
nb_json=$(netbird status --json)
|
||||
jq -c -n --argjson nb "${nb_json}" --argjson hosts '{{ (groups["exit_nodes"] | default([])) | to_json }}' '
|
||||
[
|
||||
$hosts[] as $h
|
||||
| ($nb.peers.details[]? | select(.fqdn | startswith($h + ".")) | .netbirdIp) as $ip
|
||||
| select($ip != null and $ip != "")
|
||||
| {name: $h, ip: $ip}
|
||||
]
|
||||
'
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: vmagent_exit_targets_raw
|
||||
changed_when: false
|
||||
when: vmagent_scrape_remnawave | bool
|
||||
|
||||
- name: Задать список NetBird pull-целей для vmagent
|
||||
- name: Сбросить список внешних pull-целей для vmagent
|
||||
ansible.builtin.set_fact:
|
||||
vmagent_netbird_exit_targets: "{{ vmagent_exit_targets_raw.stdout | from_json }}"
|
||||
vmagent_remote_pull_targets: []
|
||||
when: vmagent_scrape_remnawave | bool
|
||||
|
||||
- name: Собрать внешние ноды (remnanodes) для pull с core-net
|
||||
ansible.builtin.set_fact:
|
||||
vmagent_remote_pull_targets: "{{ vmagent_remote_pull_targets + [{'name': item, 'ip': hostvars[item].ansible_host}] }}"
|
||||
loop: "{{ groups['remnanodes'] | default([]) | sort }}"
|
||||
when:
|
||||
- vmagent_scrape_remnawave | bool
|
||||
- hostvars[item].ansible_host is defined
|
||||
|
||||
- name: Дождаться VictoriaMetrics
|
||||
ansible.builtin.command: curl -fsS --max-time 5 {{ vmagent_remote_health_url }}
|
||||
register: vmagent_vm_health
|
||||
@@ -171,7 +146,7 @@
|
||||
msg:
|
||||
- >-
|
||||
{{
|
||||
'Pull-таргет ' ~ inventory_hostname ~ ': node_exporter (:9100) и cAdvisor (:9101) доступны только по NetBird с core-net'
|
||||
'Pull-таргет ' ~ inventory_hostname ~ ': node_exporter (:9100) и cAdvisor (:9101) доступны с WAN egress core-net'
|
||||
if (vmagent_pull_only_target | bool)
|
||||
else 'vmagent ' ~ inventory_hostname ~ ' пишет в ' ~ vmagent_remote_write_url ~ ' (exit_targets=' ~ ((vmagent_netbird_exit_targets | default([])) | length) ~ ')'
|
||||
else 'vmagent ' ~ inventory_hostname ~ ' пишет в ' ~ vmagent_remote_write_url ~ ' (remote_targets=' ~ ((vmagent_remote_pull_targets | default([])) | length) ~ ')'
|
||||
}}
|
||||
@@ -5,7 +5,7 @@
|
||||
labels:
|
||||
instance: "{{ vmagent_instance }}"
|
||||
cluster: "{{ vmagent_cluster }}"
|
||||
{% for target in (vmagent_netbird_exit_targets | default([])) %}
|
||||
{% for target in (vmagent_remote_pull_targets | default([])) %}
|
||||
- targets: ["{{ target.ip }}:9101"]
|
||||
labels:
|
||||
instance: "{{ target.name }}"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
labels:
|
||||
instance: "{{ vmagent_instance }}"
|
||||
cluster: "{{ vmagent_cluster }}"
|
||||
{% for target in (vmagent_netbird_exit_targets | default([])) %}
|
||||
{% for target in (vmagent_remote_pull_targets | default([])) %}
|
||||
- targets: ["{{ target.ip }}:9100"]
|
||||
labels:
|
||||
instance: "{{ target.name }}"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
resource "proxmox_virtual_environment_container" "core_net" {
|
||||
description = "Managed by Terraform: core-net (Traefik, Authentik)"
|
||||
description = "Managed by Terraform: core-net (Traefik, Remnawave)"
|
||||
node_name = var.proxmox_node
|
||||
|
||||
vm_id = 902
|
||||
|
||||
Reference in new issue
Block a user