feat(security): isolate exit nodes via NetBird Zero-Trust ACL and pull-mode metrics
ansible-deploy / plan (push) Successful in 2s
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-net, ) (push) Successful in 10s
ansible-deploy / deploy (ger-nod-02, ) (push) Successful in 1m27s
ansible-deploy / deploy (opnsense, ) (push) Successful in 16s
ansible-deploy / deploy (rus-central, ) (push) Successful in 28s
ansible-deploy / plan (push) Successful in 2s
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-net, ) (push) Successful in 10s
ansible-deploy / deploy (ger-nod-02, ) (push) Successful in 1m27s
ansible-deploy / deploy (opnsense, ) (push) Successful in 16s
ansible-deploy / deploy (rus-central, ) (push) Successful in 28s
This commit is contained in:
1 parent
ca25b1d042
commit
a5f3400c0c
12 files changed
+273
-56
No files matched your search
@@ -1,12 +1,14 @@
|
||||
# Декларативное описание клиентского доступа NetBird.
|
||||
# Декларативное описание клиентского доступа и политик NetBird.
|
||||
# Применяется задачей rus-central/netbird (tasks/access.yml → sync_access.py).
|
||||
#
|
||||
# Секреты setup-ключей сохраняются в Infisical (/services/netbird) автоматически
|
||||
# и не попадают в Git или логи CI.
|
||||
|
||||
# Группы клиентов
|
||||
# Управляемые группы пиров
|
||||
client_groups:
|
||||
- exit-clients
|
||||
- remnawave
|
||||
- exit-ger-nod-02
|
||||
|
||||
# Выходные шлюзы (Exit Nodes)
|
||||
exit_nodes:
|
||||
@@ -35,8 +37,6 @@ dns_nameservers:
|
||||
enabled: false
|
||||
|
||||
# Ключи подключения клиентов (секреты сохраняются в Infisical /services/netbird).
|
||||
# Чтобы выпустить отдельный ключ — добавьте запись с новым name и secret.
|
||||
# Чтобы отозвать ключ — поставьте enabled: false или удалите запись.
|
||||
setup_keys:
|
||||
- name: exit-clients-key
|
||||
secret: NETBIRD_EXIT_CLIENTS_SETUP_KEY
|
||||
@@ -48,11 +48,75 @@ setup_keys:
|
||||
- exit-clients
|
||||
enabled: true
|
||||
|
||||
# Управление подключёнными клиентскими устройствами (пирами).
|
||||
# Новые пиры, подключившиеся по setup-ключу, сохраняют свои группы автоматически.
|
||||
# Здесь можно явно зафиксировать группы пира или удалить/отключить устройство (state: absent).
|
||||
# Управление подключёнными пирами (жёсткое разделение: внешние ноды не входят в remnawave).
|
||||
peers:
|
||||
- name: "A55 пользователя Vacheslav"
|
||||
groups:
|
||||
- exit-clients
|
||||
state: present
|
||||
- name: "core-net"
|
||||
groups:
|
||||
- remnawave
|
||||
state: present
|
||||
- name: "ger-nod-02"
|
||||
groups:
|
||||
- exit-ger-nod-02
|
||||
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:
|
||||
- exit-ger-nod-02
|
||||
|
||||
- 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:
|
||||
- exit-ger-nod-02
|
||||
- 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:
|
||||
- exit-ger-nod-02
|
||||
- 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:
|
||||
- exit-ger-nod-02
|
||||
@@ -309,6 +309,88 @@ def sync(cfg: dict[str, Any], api: NetBirdAPI) -> dict[str, Any]:
|
||||
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,
|
||||
|
||||
Reference in new issue
Block a user