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
@@ -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