From 7b3f002e5fb0abc35ce483cd0a5c6d1bb9eb2e9a Mon Sep 17 00:00:00 2001 From: Denozordec Date: Wed, 8 Jul 2026 17:50:38 +0700 Subject: [PATCH] feat(firewall): enhance firewall management with community selection and script handling Added a community selection feature to the firewall rules management UI, allowing users to specify BGP communities for block/accept policies. Updated the backend to support reading firewall scripts from a specified directory, improving script management. Enhanced documentation to clarify the new community functionality and its implications for firewall rules. Additionally, introduced tests for the firewall script endpoints to ensure proper functionality. --- apps/web/src/routes/_auth/firewall.tsx | 55 +++++-- deploy/docker/gobinary/Dockerfile | 2 + docs/firewall.md | 9 +- internal/firewallscripts/embed.go | 10 ++ internal/firewallscripts/evobgp-firewall.sh | 169 ++++++++++++++++++++ internal/firewallscripts/install.sh | 110 +++++++++++++ internal/firewallscripts/sync_test.go | 34 ++++ internal/firewallscripts/uninstall.sh | 19 +++ internal/httpapi/routes_firewall.go | 22 ++- internal/httpapi/routes_firewall_test.go | 33 ++++ 10 files changed, 447 insertions(+), 16 deletions(-) create mode 100644 internal/firewallscripts/embed.go create mode 100644 internal/firewallscripts/evobgp-firewall.sh create mode 100644 internal/firewallscripts/install.sh create mode 100644 internal/firewallscripts/sync_test.go create mode 100644 internal/firewallscripts/uninstall.sh diff --git a/apps/web/src/routes/_auth/firewall.tsx b/apps/web/src/routes/_auth/firewall.tsx index 5498179..b035e79 100644 --- a/apps/web/src/routes/_auth/firewall.tsx +++ b/apps/web/src/routes/_auth/firewall.tsx @@ -20,7 +20,10 @@ import { } from '@evobgp/ui/components/table' import { PageHeader } from '@/components/page-header' +import { CommunitySelect } from '@/components/modules/community-select' import { StatusBadge } from '@/components/status-badge' +import { communityLabel } from '@/lib/modules/helpers' +import { directoriesCommunitiesQueryOptions } from '@/queries/directories' import { firewallClientsQueryOptions, firewallInstallContextQueryOptions, @@ -29,7 +32,7 @@ import { useCreateFirewallRule, useDeleteFirewallRule, } from '@/queries/firewall' -import type { FirewallClient } from '@/types/api' +import type { BgpCommunity, FirewallClient } from '@/types/api' export const Route = createFileRoute('/_auth/firewall')({ component: FirewallPage, @@ -37,6 +40,7 @@ export const Route = createFileRoute('/_auth/firewall')({ function FirewallPage() { const installCtxQ = useQuery(firewallInstallContextQueryOptions()) + const communitiesQ = useQuery(directoriesCommunitiesQueryOptions()) const clientsQ = useQuery(firewallClientsQueryOptions()) const rulesQ = useQuery(firewallRulesQueryOptions('tenant')) const approve = useApproveFirewallClient() @@ -60,8 +64,11 @@ function FirewallPage() { } }, [installCtx?.bundle_seed, installCtx?.suggested_cp_url]) const [ruleAction, setRuleAction] = useState<'block' | 'accept'>('block') + const [ruleCommunityId, setRuleCommunityId] = useState(null) const [ruleComment, setRuleComment] = useState('') + const communities = communitiesQ.data?.items ?? [] + const clients = clientsQ.data?.items ?? [] const pending = clients.filter((c) => c.status === 'pending') const rules = rulesQ.data?.items ?? [] @@ -117,8 +124,9 @@ function FirewallPage() { Политика - Только явный block добавляет IP в blocklist. Правила accept сами по себе - не создают block all. Default — accept. + Правила сопоставляются с BGP community префиксов опубликованной revision.{' '} + block добавляет префиксы community в kernel; accept — не блокирует. + Community «Все» — правило для любого community. Default без совпадений — accept. @@ -179,7 +187,7 @@ function FirewallPage() { -
+
- setRuleComment(e.target.value)} + +
+ + setRuleComment(e.target.value)} + /> +
- deleteRule.mutate(id)} /> + deleteRule.mutate(id)} + /> @@ -279,9 +306,11 @@ function ClientsTable({ function RulesTable({ rules, + communities, onDelete, }: { - rules: { id: string; priority: number; action: string; comment?: string }[] + rules: { id: string; priority: number; action: string; community_id?: string | null; comment?: string }[] + communities: BgpCommunity[] onDelete: (id: string) => void }) { if (rules.length === 0) { @@ -293,6 +322,7 @@ function RulesTable({ # Действие + Community Комментарий @@ -304,6 +334,9 @@ function RulesTable({ + + {r.community_id ? communityLabel(r.community_id, communities) : 'Все'} + {r.comment || '—'}