- Refactored the `mikrotik-install.rsc` script to fetch and process the agent policy as JSON instead of using the previous `.rsc` format, improving reliability and performance during policy synchronization. - Introduced a new global variable `EvofwLastHash` to track the hash of the fetched policy, enabling efficient updates and preventing unnecessary changes. - Updated the logging and error handling to provide clearer insights during the synchronization process. - Adjusted related test assertions in `install-links.test.ts` to reflect the new policy endpoint and ensure accurate testing of the installation logic. - Enhanced documentation in `agents.md` to clarify the new synchronization method and its implications for agent configuration. These changes enhance the robustness and clarity of the agent installation and synchronization process, ensuring better performance and user experience.
4.1 KiB
Agents
Short install (рекомендуется)
В UI /agents → Добавить агента:
- Создаётся агент со статусом Invited (сразу виден в таблице) + install-ссылка.
- Скопируйте one-liner (колонка Install или Sheet):
Linux:
curl -fsSL https://<cp>/agent-install/<id> | bash
MikroTik:
/tool fetch url="https://<cp>/agent-install/<id>" dst-path=evofw-install.rsc; /import file-name=evofw-install.rsc
- После enroll статус станет Pending — одобрите агента (Approve).
- Approved — агент синхронизирует политику.
Повторный запуск той же install-ссылки на хосте, где агент уже стоит: обновляет sync-скрипт / timer (или MikroTik scheduler), без повторного enroll — CLIENT_ID/token сохраняются. Полный переустановки с новым токеном: EVOFW_INSTALL_FORCE=1 (Linux).
API (auth): POST /api/v1/install-links { "name": "web-01", "platform": "linux" | "mikrotik" }.
Linux (legacy one-liner)
curl -fsSL https://<cp>/v1/agent/install.sh | \
EVOFW_CP_URL=https://<cp> \
EVOFW_SEED=<seed> \
EVOFW_CLIENT_NAME="web-01" \
bash
Создаёт нового агента со статусом Pending (без Invited).
Файлы: /etc/evofw/agent.conf, /usr/local/sbin/evofw-firewall.sh, timer evofw-firewall.timer (default 1min).
Install сам ставит зависимости через apt/dnf/yum/apk: curl, jq (или python3), nftables/iptables(+ipset). Планировщик: systemd timer если есть /run/systemd/system, иначе ставит cron/cronie и пишет crontab. Значения в agent.conf всегда в single quotes (имена с пробелами безопасны). Sync при статусе pending завершается с exit 0 (pending approval), чтобы systemd timer не был failed.
Если /etc/evofw/agent.conf уже есть — install переходит в update: скачивает свежий sync-script + uninstall.sh, перезаписывает unit/timer, оставляет токен. EVOFW_INSTALL_FORCE=1 — полный re-enroll (новый токен; для уже Approved install-link обычно не сработает).
Uninstall (Linux):
curl -fsSL https://<cp>/v1/agent/uninstall.sh | bash
# или локально после install:
sudo /usr/local/sbin/evofw-uninstall.sh
Backend auto-detect: nft → ipset → iptables.
Whitelist: nft chain policy drop + allow set. Blacklist: policy accept + deny set.
MikroTik (RouterOS 7.21+)
В UI /agents → Добавить агента → platform MikroTik. Скопируйте one-liner:
/tool fetch url="https://<cp>/agent-install/<id>" dst-path=evofw-install.rsc; /import file-name=evofw-install.rsc
Или короткий slug: https://<cp>/<slug>.
Install RSC:
- Enroll (с
install_link_id→ агент Invited → Pending). - Создаёт filter-правила
evofw-*и address-listEVOFW_DENY/EVOFW_ALLOW. - Scheduler
evofw-syncкаждую минуту:GET /v1/agent/policy(JSON) → rebuild address-list + toggle default. Не использует/importогромного.rsc(на больших списках часто падает молча).
Лог: /log print where message~"evofw". Ручной sync: /system script run evofw-sync.
Default action задаётся на агенте (default_action: accept | drop):
- accept — пакет вне deny/allow пропускается
- drop — пакет вне deny/allow отбрасывается (forward)
Цепочка всегда: deny-drop → allow-accept → default. Наборы несут только правила deny/allow, без exclusive mode.
Force sync
sudo rm -f /var/lib/evofw/last_hash
sudo /usr/local/sbin/evofw-firewall.sh