fix(netbird): отключить IPv6/DNS-перехват на Exit Node и сузить маршрут LAN
ansible-ger-nod-02 / deploy (push) Failing after 43s
ansible-rus-central / deploy (push) Successful in 58s

This commit is contained in:
karpenok committed 2026-11-15 11:59:40 +07:00
1 parent 4884a61ad2
commit c90a78e160
3 files changed
+49 -17

No files matched your search

@@ -5,6 +5,12 @@
content: | content: |
net.ipv4.ip_forward = 1 net.ipv4.ip_forward = 1
net.ipv4.conf.all.src_valid_mark = 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 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
@@ -24,6 +30,12 @@
ansible.builtin.include_role: ansible.builtin.include_role:
name: netbird_client name: netbird_client
- name: Перезапустить NetBird после изменения sysctl
ansible.builtin.systemd:
name: netbird
state: restarted
when: netbird_exit_sysctl is changed
- name: Установить jq для синхронизации Exit Node через API NetBird - name: Установить jq для синхронизации Exit Node через API NetBird
ansible.builtin.apt: ansible.builtin.apt:
name: jq name: jq
@@ -84,8 +96,13 @@
exit_clients_group_id=$(printf '%s' "${groups_json}" | jq -r --arg g "${NB_EXIT_CLIENTS_GROUP}" '.[] | select(.name == $g) | .id' | head -n 1) 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 if [ -n "${exit_clients_group_id}" ]; then
routes_json=$(curl -fsS --max-time 20 -H "Authorization: Token ${NB_API_TOKEN}" "${API_BASE}/routes") routes_json=$(curl -fsS --max-time 20 -H "Authorization: Token ${NB_API_TOKEN}" "${API_BASE}/routes")
existing_exit_route_id=$(printf '%s' "${routes_json}" | jq -r --arg nid "${NB_EXIT_NET_ID}" '.[] | select(.network_id == $nid and .network == "0.0.0.0/0") | .id' | head -n 1) 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)
if [ -z "${existing_exit_route_id}" ]; then 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 \ exit_route_payload=$(jq -n \
--arg desc "Exit Node DE (0.0.0.0/0 via ${NB_PEER_HOST})" \ --arg desc "Exit Node DE (0.0.0.0/0 via ${NB_PEER_HOST})" \
--arg nid "${NB_EXIT_NET_ID}" \ --arg nid "${NB_EXIT_NET_ID}" \
@@ -97,13 +114,17 @@
enabled: true, enabled: true,
peer_groups: [$eg], peer_groups: [$eg],
network: "0.0.0.0/0", network: "0.0.0.0/0",
metric: 100, metric: 9999,
masquerade: true, masquerade: true,
groups: [$cg], groups: [$cg],
keep_route: true, keep_route: false,
skip_auto_apply: false skip_auto_apply: false
}') }')
nb_api_call POST "/routes" "${exit_route_payload}" >/dev/null 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 exit_route_created=1
fi fi
fi fi
@@ -16,9 +16,9 @@ exit_nodes:
peer_group: exit-ger-nod-02 peer_group: exit-ger-nod-02
client_groups: client_groups:
- exit-clients - exit-clients
metric: 100 metric: 9999
masquerade: true masquerade: true
keep_route: true keep_route: false
skip_auto_apply: false skip_auto_apply: false
enabled: true enabled: true
@@ -32,7 +32,7 @@ dns_nameservers:
groups: groups:
- exit-clients - exit-clients
primary: true primary: true
enabled: true enabled: false
# Ключи подключения клиентов (секреты сохраняются в Infisical /services/netbird). # Ключи подключения клиентов (секреты сохраняются в Infisical /services/netbird).
# Чтобы выпустить отдельный ключ — добавьте запись с новым name и secret. # Чтобы выпустить отдельный ключ — добавьте запись с новым name и secret.
@@ -117,7 +117,6 @@
fi fi
groups_json=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/groups") groups_json=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/groups")
all_group_id=$(printf '%s' "${groups_json}" | jq -r '.[] | select(.name == "All") | .id' | head -n 1)
router_group_id=$(printf '%s' "${groups_json}" | jq -r --arg g "$NB_ROUTER_GROUP" '.[] | select(.name == $g) | .id' | head -n 1) 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 if [ -z "${router_group_id}" ]; then
@@ -144,15 +143,20 @@
fi fi
routes_json=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/routes") routes_json=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/routes")
existing_route_id=$(printf '%s' "${routes_json}" | jq -r --arg nid "$NB_LAN_NET_ID" --arg net "$NB_LAN_SUBNET" '.[] | select(.network_id == $nid or .network == $net) | .id' | head -n 1) 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)
needs_lan_route_update="false"
if [ -n "${existing_route_id}" ]; then
needs_lan_route_update=$(printf '%s' "${existing_route}" | jq -r --arg rmg "$remna_group_id" '((.groups // []) | sort) != ([$rmg] | sort)')
fi
if [ -z "${existing_route_id}" ]; then if [ -z "${existing_route_id}" ] || [ "${needs_lan_route_update}" = "true" ]; then
route_payload=$(jq -n \ route_payload=$(jq -n \
--arg desc "Homelab LAN (${NB_LAN_SUBNET} via OPNsense)" \ --arg desc "Homelab LAN (${NB_LAN_SUBNET} via OPNsense)" \
--arg nid "$NB_LAN_NET_ID" \ --arg nid "$NB_LAN_NET_ID" \
--arg net "$NB_LAN_SUBNET" \ --arg net "$NB_LAN_SUBNET" \
--arg rg "$router_group_id" \ --arg rg "$router_group_id" \
--arg ag "$all_group_id" \ --arg rmg "$remna_group_id" \
'{ '{
description: $desc, description: $desc,
network_id: $nid, network_id: $nid,
@@ -161,13 +165,20 @@
network: $net, network: $net,
metric: 100, metric: 100,
masquerade: true, masquerade: true,
groups: [$ag], groups: [$rmg],
keep_route: true keep_route: true
}') }')
curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/routes" \ if [ -z "${existing_route_id}" ]; then
-H "Authorization: Token ${active_token}" \ curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/routes" \
-H "Content-Type: application/json" \ -H "Authorization: Token ${active_token}" \
-d "${route_payload}" >/dev/null -H "Content-Type: application/json" \
-d "${route_payload}" >/dev/null
else
curl "${CURL_OPTS[@]}" -X PUT "${API_BASE}/routes/${existing_route_id}" \
-H "Authorization: Token ${active_token}" \
-H "Content-Type: application/json" \
-d "${route_payload}" >/dev/null
fi
route_created=1 route_created=1
fi fi