Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/cni/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,48 @@ is set in the entry's mask.
| `src_filter_stats` | Per-CPU array (8) | Checked, allowed, denied by prefix, denied by interface, bypassed before first sync |
| `src_filter_denied` | LRU hash (1024) | Denied source /64s with count, last interface, last reason and time, for triage |

#### Control plane

`galactic-cni run` (the DaemonSet's long-running `credential-refresh`
container) owns the allow-list through `internal/srcfilter`. It is started only
when `GALACTIC_CNI_SRV6_SOURCE_FILTER` is `audit` or `enforce`; with `off`, or
an invalid configuration, the container writes mode `off` and starts nothing.

- **Inputs.** Main-table IPv6 routes that forward and were installed by the
fabric's own routing: protocol `bgp` (FRR's underlay). The filter also considers
protocol 250 gateway and shard routes from the router's dedicated plain-route
table when their prefix does not overlap a specific main-table route.
Static, boot, kernel and other routes never count. Eligible prefixes lie
inside a configured SR domain, are at least a /64, and exclude this
node's own locator from its `BGPRouter`.
- **Fabric next hop.** When `GALACTIC_CNI_SRV6_FABRIC_NEXTHOPS` is set, only
hops whose gateway lies inside it and that leave through an uplink count,
and a route with no such hop is left out. Kernel routes carry the resolved,
directly connected gateway even for recursive or iBGP routes, so the list
names peer link and transit addresses (and `fe80::/10` for unnumbered
sessions), not loopbacks. The peer set lives in the underlay's own
configuration, which galactic does not read, so this is operator-supplied;
unset skips the check.
- **Interface binding.** An entry's mask is the union of the slots of every
hop's link, a bond master or a VLAN on a bond counting as the bond's slaves.
Uplinks are what `attach.ResolveInterfaces` returns, each keeping its slot
for as long as it exists (at most 32). Loose binding, or a hop whose link is
unknown, accepts the entry on any interface. Static extra sources always do.
- **Apply.** Uplink slots first, then new and changed entries, then removals,
then the config with `populated` set and the generation bumped. `populated`
is set only after a pass with no error, and the configured mode is written
as soon as the reconciler starts.
- **Failure.** A pass that cannot read routes, links, uplinks or the node's
locator, or that finds no fabric route at all, changes nothing, so the last
allow-list stays in force. The outcome is reported on the
`srv6-source-filter` gRPC health service, which no probe checks.
- **Triggers.** Startup, every debounced re-evaluation of the attach watch loop
(`Watcher.Reevaluated`), and a 60 s resync that keeps running if the watch
loop dies. The resync also logs the most-denied sources at debug level.
- **Reuse.** The reconciler writes through the `srcfilter.Target` interface;
`USIDTarget` adapts `srcfiltermap`. `SlotAssigner` lets a datapath that owns
its own uplink slots (`KeepSlots`) reuse it unchanged.

---

## Data flow
Expand Down
26 changes: 26 additions & 0 deletions docs/cni/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ they resolve only `LogFile`/`LogLevel` from `HostConf` — never `NodeName` or
| DAN directory | `GALACTIC_CNI_DAN_DIR` env → `HostConf.DANDir` | `/run/kata-containers/dans-rs` | `galactic-cni init`, `galactic-tap` |
| eBPF filter priority | `GALACTIC_CNI_EBPF_FILTER_PRIORITY` env (plain `os.Getenv`, no `HostConf`/conflist tier) | `1` | `galactic-cni init`/`run` |
| Fabric MTU limits | `GALACTIC_CNI_TCP_MSS_CLAMP` env (plain `os.Getenv`, no `HostConf`/conflist tier) | `auto` | `galactic-cni run` |
| SRv6 source filter | `GALACTIC_CNI_SRV6_*` env (plain `os.Getenv`, `galactic-cni run` only) | `off` | `galactic-cni run` |

`GALACTIC_CNI_*` env var names are shared as-is across every binary that
resolves node-level settings — there's no per-binary prefix for these, since
Expand Down Expand Up @@ -194,6 +195,31 @@ of 100; refusals are counted as `rate_limited`.

**Type:** `auto`, `off`, or an MTU · **Default:** `auto`

## SRv6 ingress source filter

Controls the uSID datapath's SRv6 ingress source filter: a node accepts SRv6 traffic for its tenant networks only from sources inside a fabric peer's locator, and only on the uplinks its route to that peer uses. `galactic-cni run` builds the allow-list from the fabric routes installed by underlay BGP in the main table or by `galactic-router` in its plain-route table and keeps it current. Static and other routes never become allowed sources. Read only by that container, with no conflist tier.

| Variable | Values | Default | Effect |
| -------------------------------------- | ----------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GALACTIC_CNI_SRV6_SOURCE_FILTER` | `off`, `audit`, `enforce` | `off` | `off` leaves traffic untouched and starts no reconciler. `audit` counts and records sources it would reject. `enforce` drops them. |
| `GALACTIC_CNI_SRV6_DOMAIN_PREFIXES` | comma-separated IPv6 prefixes | _(none)_ | The prefixes fabric locators are allocated from. Only routes inside them, and at least a /64, become allowed sources. Required unless `off`. |
| `GALACTIC_CNI_SRV6_SOURCE_BINDING` | `strict`, `loose` | `strict` | `strict` accepts a source only on the uplinks this node's route to it uses. `loose` accepts a known source on any uplink. |
| `GALACTIC_CNI_SRV6_SOURCE_ALLOW_EXTRA` | comma-separated IPv6 prefixes | _(none)_ | Extra sources allowed on any uplink, for senders with no route in the main table. |
| `GALACTIC_CNI_SRV6_FABRIC_NEXTHOPS` | comma-separated IPv6 prefixes | _(none)_ | Addresses of the fabric's BGP peers as route gateways: link and transit addresses, `fe80::/10` for unnumbered sessions. When set, a route counts only through a hop to one of them on an uplink. Unset skips the check. |

- An invalid value, or `audit`/`enforce` without domain prefixes, logs an error, writes `off` and reports the `srv6-source-filter` health service as not serving. The filter is never enforced on a configuration it could not read.
- The filter lets every packet through until the first complete sync, and a sync that cannot read routes, or finds no fabric route at all, keeps the previous allow-list rather than clearing it.
- A protocol 250 plain route contributes its uplinks only when its prefix has no overlap with a specific main-table route. This respects the kernel's preference for the underlay and avoids granting fallback interfaces for partially shadowed prefixes.
- Roll out with `audit` first and watch `galactic_usid_src_filter_packets_total{result=~"deny_.*"}` before switching to `enforce`. Debug logging lists the most-denied sources every minute.

| Metric | Type | Meaning |
| ----------------------------------------- | ------- | ---------------------------------------------------------------------------------------------- |
| `galactic_usid_src_filter_packets_total` | counter | Decisions by `result`: `checked`, `allowed`, `deny_prefix`, `deny_iface`, `bypass_unpopulated` |
| `galactic_usid_src_filter_entries` | gauge | Allowed source prefixes |
| `galactic_usid_src_filter_mode` | gauge | 0 off, 1 audit, 2 enforce |
| `galactic_usid_src_filter_populated` | gauge | 1 once the allow-list reflects a complete sync |
| `galactic_usid_src_filter_denied_sources` | gauge | Distinct denied source /64s recorded for triage |

## `GALACTIC_CNI_EGRESS_SHARD_SIDS`

Comma-separated list of the `galactic-nat` shards' `Status.ShardSID`s this
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/containernetworking/cni v1.3.1
github.com/containernetworking/plugins v1.9.1
github.com/coreos/go-iptables v0.8.0
github.com/gaissmai/bart v0.26.1
github.com/go-logr/logr v1.4.4
github.com/google/uuid v1.6.0
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.7
Expand Down Expand Up @@ -72,7 +73,6 @@ require (
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/fsnotify/fsnotify v1.10.1 // indirect
github.com/fxamacker/cbor/v2 v2.9.1 // indirect
github.com/gaissmai/bart v0.26.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v1.0.0 // indirect
Expand Down
28 changes: 28 additions & 0 deletions internal/config/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ const (
// internal/plumbing/ebpf/mssclamp.
EnvCNITCPMSSClamp = "GALACTIC_CNI_TCP_MSS_CLAMP"

// EnvCNISRv6SourceFilter sets the uSID datapath's SRv6 ingress source
// filter mode: off (the default), audit or enforce. Read only by
// galactic-cni run.
EnvCNISRv6SourceFilter = "GALACTIC_CNI_SRV6_SOURCE_FILTER"

// EnvCNISRv6DomainPrefixes is a comma-separated list of the IPv6 prefixes
// the fabric's locators are allocated from. Only routes inside them become
// allowed sources. Required unless the source filter is off.
EnvCNISRv6DomainPrefixes = "GALACTIC_CNI_SRV6_DOMAIN_PREFIXES"

// EnvCNISRv6SourceBinding is strict (the default), accepting a source only
// on the uplinks this node's route to it uses, or loose, accepting a known
// source on any uplink.
EnvCNISRv6SourceBinding = "GALACTIC_CNI_SRV6_SOURCE_BINDING"

// EnvCNISRv6SourceAllowExtra is a comma-separated list of extra IPv6
// source prefixes to allow on any uplink, for senders with no route in
// the main table.
EnvCNISRv6SourceAllowExtra = "GALACTIC_CNI_SRV6_SOURCE_ALLOW_EXTRA"

// EnvCNISRv6FabricNextHops is a comma-separated list of IPv6 prefixes
// holding the addresses of this fabric's BGP peers as they appear as route
// gateways: link and transit addresses, and fe80::/10 for unnumbered
// sessions. When set, a route becomes an allowed source only through a
// hop whose gateway lies inside it and that leaves through an uplink.
// Unset skips the next-hop check.
EnvCNISRv6FabricNextHops = "GALACTIC_CNI_SRV6_FABRIC_NEXTHOPS"

// EnvCNIEgressShardSIDs is a comma-separated list of every live egress
// shard's SID: the fabric-wide membership a tenant VRF's egress routes need.
// One SID per shard covers both address families -- a shard decides which
Expand Down
5 changes: 5 additions & 0 deletions internal/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,9 @@ func NewMetrics() *metrics.Metrics {
// replies to that guest's solicitations. This runs here, not from
// galactic-tap's cmdAdd, because a guest's boot outlives that short-lived
// process. It is independent of the eBPF datapath and runs regardless.
// 9. Keeps the SRv6 ingress source filter's allow-list in step with this
// node's routes when it is enabled, reporting on its own
// srcFilterHealthServiceName health service.
func Run(ctx context.Context, grpcHealthPort, metricsPort int) error {
slog.Info("Starting CNI installer run daemon", "grpcHealthPort", grpcHealthPort, "metricsPort", metricsPort)

Expand Down Expand Up @@ -1233,6 +1236,8 @@ func Run(ctx context.Context, grpcHealthPort, metricsPort int) error {
healthSrv.SetServingStatus(ebpfHealthServiceName, grpc_health_v1.HealthCheckResponse_SERVING)
}

startSourceFilter(ctx, ebpfState, healthSrv)

go func() {
if err := grpcSrv.Serve(lis); err != nil && !errors.Is(err, grpc.ErrServerStopped) {
slog.Error("gRPC health server exited with error", "err", err)
Expand Down
184 changes: 184 additions & 0 deletions internal/installer/srcfilter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Copyright 2026 Datum Cloud, Inc.
//
// SPDX-License-Identifier: AGPL-3.0-or-later

package installer

import (
"context"
"log/slog"
"net/netip"
"os"
"time"

"github.com/vishvananda/netlink"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"

"go.datum.net/galactic/internal/config"
"go.datum.net/galactic/internal/plumbing/ebpf/attach"
"go.datum.net/galactic/internal/plumbing/ebpf/srcfiltermap"
"go.datum.net/galactic/internal/srcfilter"
)

// srcFilterResyncInterval paces the source filter's periodic full pass, which
// heals drift no netlink event reports. A var so tests can shrink it.
var srcFilterResyncInterval = 60 * time.Second

// srcFilterTopDenied is how many denied sources each periodic pass logs at
// debug level.
const srcFilterTopDenied = 5

// srcFilterHealthServiceName is the gRPC health service reporting whether the
// source filter's last pass succeeded. It is separate from
// ebpfHealthServiceName so a control-plane fault here never fails the
// datapath's own probes.
const srcFilterHealthServiceName = "srv6-source-filter"

// startSourceFilter configures the uSID datapath's SRv6 ingress source filter
// from the environment and, unless it is off, starts a goroutine that keeps its
// allow-list in step with this node's routes until ctx is canceled.
//
// A pass runs at startup, after every debounced re-evaluation of st.watcher,
// and every srcFilterResyncInterval, so the filter keeps being maintained if
// the watch loop dies. Mode off, or a configuration error, writes mode off and
// starts nothing; a configuration error also reports the health service not
// serving. A nil st.objs means no datapath is loaded, and nothing happens.
func startSourceFilter(ctx context.Context, st ebpfDatapathState, healthSrv *health.Server) {
if st.objs == nil {
return
}
filter := srcfiltermap.NewFromObjects(st.objs)
target := srcfilter.USIDTarget{Filter: filter}

settings, err := srcfilter.LoadSettings(os.Getenv)
if err != nil {
slog.Error("SRv6 source filter configuration is invalid; leaving the filter off", "err", err)
healthSrv.SetServingStatus(srcFilterHealthServiceName, grpc_health_v1.HealthCheckResponse_NOT_SERVING)
disableSourceFilter(target)
return
}
if settings.Mode == srcfilter.ModeOff {
disableSourceFilter(target)
return
}

r, err := srcfilter.New(srcfilter.Options{
Settings: settings,
Target: target,
Routes: srcfilter.FabricRoutes,
Links: netlink.LinkList,
Uplinks: attach.ResolveInterfaces,
OwnLocator: ownLocatorFn(st),
})
if err != nil {
slog.Error("Could not start the SRv6 source filter reconciler; leaving the filter off", "err", err)
healthSrv.SetServingStatus(srcFilterHealthServiceName, grpc_health_v1.HealthCheckResponse_NOT_SERVING)
disableSourceFilter(target)
return
}

slog.Info("SRv6 source filter reconciler starting", "mode", settings.Mode.String(),
"binding", settings.Binding.String(), "domainPrefixes", settings.DomainPrefixes,
"extraSources", settings.ExtraSources, "fabricNextHops", settings.FabricNextHops)
if len(settings.FabricNextHops) == 0 {
slog.Warn("SRv6 source filter next-hop check is off: routes from the fabric's routing are accepted " +
"whatever their gateway; set " + config.EnvCNISRv6FabricNextHops + " to require a fabric peer")
}
healthSrv.SetServingStatus(srcFilterHealthServiceName, grpc_health_v1.HealthCheckResponse_NOT_SERVING)
go runSourceFilter(ctx, r, filter, st.watcher, healthSrv)
}

// runSourceFilter drives r until ctx is canceled, publishing each pass's
// outcome on the health service.
func runSourceFilter(
ctx context.Context, r *srcfilter.Reconciler, filter *srcfiltermap.Filter, w *attach.Watcher,
healthSrv *health.Server,
) {
ticker := time.NewTicker(srcFilterResyncInterval)
defer ticker.Stop()

var lastErr string
pass := func() {
lastErr = sourceFilterPass(ctx, r, healthSrv, lastErr)
}

pass()
for {
select {
case <-ctx.Done():
return
case <-w.Reevaluated():
pass()
case <-ticker.C:
pass()
logTopDeniedSources(ctx, filter)
}
}
}

// sourceFilterPass runs one pass and reports it. lastErr is the previous
// pass's error text, empty after a success; a repeated failure logs at debug
// rather than error. It returns this pass's error text.
func sourceFilterPass(ctx context.Context, r *srcfilter.Reconciler, healthSrv *health.Server, lastErr string) string {
res, err := r.Reconcile(ctx)
if err != nil {
healthSrv.SetServingStatus(srcFilterHealthServiceName, grpc_health_v1.HealthCheckResponse_NOT_SERVING)
level := slog.LevelError
if err.Error() == lastErr {
level = slog.LevelDebug
}
slog.Log(ctx, level, "SRv6 source filter pass failed; keeping the previous allow-list",
"err", err, "populated", res.State.Populated)
return err.Error()
}

healthSrv.SetServingStatus(srcFilterHealthServiceName, grpc_health_v1.HealthCheckResponse_SERVING)
if lastErr != "" {
slog.Info("SRv6 source filter pass recovered")
}
if res.Changed {
slog.Info("SRv6 source filter allow-list updated", "entries", res.Entries, "added", res.Added,
"updated", res.Updated, "removed", res.Removed, "unbound", res.Unbound,
"foreignNextHop", res.ForeignNextHop, "uplinks", res.SlotCount,
"mode", res.State.Mode.String(), "generation", res.State.Generation)
}
return ""
}

// ownLocatorFn returns the lookup for this node's own locator, or nil when no
// Kubernetes client is available, in which case the own locator is not
// excluded.
func ownLocatorFn(st ebpfDatapathState) func(context.Context) (netip.Prefix, error) {
if st.k8sClient == nil {
slog.Warn("SRv6 source filter cannot exclude this node's own locator: no Kubernetes client")
return nil
}
return func(ctx context.Context) (netip.Prefix, error) {
return nodeLocatorPrefix(ctx, st.k8sClient, st.namespace, st.nodeName)
}
}

// disableSourceFilter writes mode off, logging a failure.
func disableSourceFilter(target srcfilter.Target) {
if err := srcfilter.Disable(target); err != nil {
slog.Error("Could not turn the SRv6 source filter off", "err", err)
}
}

// logTopDeniedSources logs the most-denied sources at debug level, for triage
// without turning source addresses into metric labels.
func logTopDeniedSources(ctx context.Context, filter *srcfiltermap.Filter) {
if !slog.Default().Enabled(ctx, slog.LevelDebug) {
return
}
denied, err := filter.DeniedSources()
if err != nil {
slog.Debug("Could not read SRv6 source filter denials", "err", err)
return
}
for _, d := range denied[:min(len(denied), srcFilterTopDenied)] {
slog.Debug("SRv6 source filter denied source", "prefix", d.Prefix.String(), "count", d.Count,
"lastIfindex", d.LastIfindex, "lastReason", d.LastReason.String())
}
}
Loading
Loading