Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
506fae2
Migrate away from deprecated metal-networker
majst01 Mar 17, 2026
d15576b
Migrate to apiv2 and use os-installer
majst01 Mar 20, 2026
592ea98
Progress
majst01 Mar 20, 2026
078b26d
Merge Master
majst01 Aug 6, 2026
65bb5cb
Linter fix
majst01 Aug 6, 2026
b7911aa
Update os-installer and controller-gen
majst01 Aug 6, 2026
a32bb4d
Update k8s
majst01 Aug 6, 2026
ea4c729
scheme.Builder is deprecated
majst01 Aug 6, 2026
2f770e0
Updates
majst01 Oct 6, 2026
80aeda8
Updates
majst01 Oct 6, 2026
c4f5cb6
Merge master
majst01 Oct 7, 2026
4033063
Do not read config from filesystem
majst01 Oct 8, 2026
0ca5e5d
Do not read config from filesystem
majst01 Oct 8, 2026
81aa49c
Do not read config from filesystem
majst01 Oct 8, 2026
9c8bb5b
Simpler
majst01 Oct 14, 2026
6266e09
Fix some badass issues
majst01 Oct 14, 2026
101b57b
Dump machine allocation
majst01 Oct 15, 2026
fa0ba34
update fem dep
mwennrich Oct 15, 2026
02f60c2
fix variable naming
majst01 Oct 15, 2026
5155d51
Merge branch 'migrate-to-apiv2-and-os-installer' of https://github.co…
majst01 Oct 15, 2026
1746fe0
use os-installer@fix-hasvpn
mwennrich Oct 16, 2026
aaae5e2
Pin os-installer
majst01 Oct 16, 2026
b60e097
Merge master
majst01 Oct 16, 2026
25586b1
Cleanup go.mod
majst01 Oct 16, 2026
9d8da8b
Pin FWCM
majst01 Oct 21, 2026
374ecb1
Log message and modules
majst01 Nov 2, 2026
a6d2d8f
Create machine allocation from firewall during reconcile.
Gerrit91 Nov 2, 2026
5663579
Unnecessary func.
Gerrit91 Nov 2, 2026
e14d423
Remove CONTRIBUTING.md
Gerrit91 Nov 2, 2026
9dba856
Rename to nftables.
Gerrit91 Nov 2, 2026
29634c1
Comments.
Gerrit91 Nov 2, 2026
264f593
Do not skip error.
Gerrit91 Nov 2, 2026
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
3 changes: 0 additions & 3 deletions CONTRIBUTING.md

This file was deleted.

31 changes: 17 additions & 14 deletions controllers/clusterwidenetworkpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type ClusterwideNetworkPolicyReconciler struct {

Interval time.Duration
DnsProxy *dns.DNSProxy
SkipDNS bool
}

// SetupWithManager configures this controller to run in schedule
Expand Down Expand Up @@ -85,6 +84,11 @@ func (r *ClusterwideNetworkPolicyReconciler) Reconcile(ctx context.Context, _ ct
return ctrl.Result{}, client.IgnoreNotFound(err)
}

allocation, defaultRouteIP, err := toMachineAllocation(f)
if err != nil {
return ctrl.Result{}, err
}

// Set CWNP requeue interval
if interval, err := time.ParseDuration(f.Spec.Interval); err == nil {
r.Interval = interval
Expand All @@ -103,11 +107,17 @@ func (r *ClusterwideNetworkPolicyReconciler) Reconcile(ctx context.Context, _ ct
}
cwnps.Items = validCwnps

nftablesFirewall := nftables.NewFirewall(f, &cwnps, &services, r.DnsProxy, r.Log, r.Recorder)
if err := r.manageDNSProxy(f, cwnps, nftablesFirewall); err != nil {
nft := nftables.New(f, &cwnps, &services, r.DnsProxy, r.Log, r.Recorder, allocation)

if err := nft.ApplyBaseRules(ctx); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to reconcile nftables for DNS proxy: %w", err)
}

if err := r.manageDNSProxy(f, cwnps, defaultRouteIP); err != nil {
return ctrl.Result{}, err
}
updated, err := nftablesFirewall.Reconcile()

updated, err := nft.Apply()
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -127,26 +137,19 @@ func (r *ClusterwideNetworkPolicyReconciler) Reconcile(ctx context.Context, _ ct
// manageDNSProxy start DNS proxy if toFQDN rules are present
// if rules were deleted it will stop running DNS proxy
func (r *ClusterwideNetworkPolicyReconciler) manageDNSProxy(
f *firewallv2.Firewall, cwnps firewallv1.ClusterwideNetworkPolicyList, nftablesFirewall *nftables.Firewall,
f *firewallv2.Firewall, cwnps firewallv1.ClusterwideNetworkPolicyList, defaultRouteIP string,
) (err error) {
// Skipping is needed for testing
if r.SkipDNS {
return nil
}

enableDNS := len(cwnps.GetFQDNs()) > 0

if err := nftablesFirewall.ReconcileNetconfTables(); err != nil {
return fmt.Errorf("failed to reconcile nftables for DNS proxy: %w", err)
}

if enableDNS && r.DnsProxy == nil {
r.Log.Info("DNS Proxy is initialized")

dnsProxyConfig := &dns.DNSProxyConfig{
Log: ctrl.Log.WithName("DNS proxy"),
DNSServer: f.Spec.DNSServerAddress,
Port: f.Spec.DNSPort,
ShootClient: r.ShootClient,
BindAddress: defaultRouteIP,
}
if r.DnsProxy, err = dns.NewDNSProxy(r.Ctx, dnsProxyConfig); err != nil {
return fmt.Errorf("failed to init DNS proxy: %w", err)
Expand Down
76 changes: 76 additions & 0 deletions controllers/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package controllers

import (
"errors"
"fmt"
"os"

"github.com/metal-stack/api/go/enum"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
firewallv2 "github.com/metal-stack/firewall-controller-manager/api/v2"
"github.com/metal-stack/metal-lib/pkg/pointer"

osnet "github.com/metal-stack/os-installer/pkg/network"
)

func toMachineAllocation(f *firewallv2.Firewall) (*apiv2.MachineAllocation, string, error) {
var vpn *apiv2.MachineVPN
if f.Status.VPN != nil {
vpn = &apiv2.MachineVPN{
// Authkey is omitted for security reasons
ControlPlaneAddress: pointer.SafeDeref(&f.Status.VPN.ControlPlaneAddress),
}
}

var networks []*apiv2.MachineNetwork
for _, nw := range f.Status.FirewallNetworks {

natType := apiv2.NATType_NAT_TYPE_NONE
if nw.Nat != nil && *nw.Nat {
natType = apiv2.NATType_NAT_TYPE_IPV4_MASQUERADE
}

networkType, err := enum.GetEnum[apiv2.NetworkType](pointer.SafeDeref(nw.NetworkTypeV2))
if err != nil {
return nil, "", err
}

networks = append(networks, &apiv2.MachineNetwork{
Network: pointer.SafeDeref(nw.NetworkID),
Prefixes: nw.Prefixes,
DestinationPrefixes: nw.DestinationPrefixes,
Ips: nw.IPs,
Vrf: uint64(pointer.SafeDeref(nw.Vrf)),
Asn: uint32(pointer.SafeDeref(nw.ASN)),
Project: nw.Project,
NatType: natType,
NetworkType: networkType,
})
}

hostname, err := os.Hostname()
if err != nil {
return nil, "", err
}
machineAllocation := &apiv2.MachineAllocation{
Project: f.Spec.Project,
Hostname: hostname,
AllocationType: apiv2.MachineAllocationType_MACHINE_ALLOCATION_TYPE_FIREWALL,
Networks: networks,
// TODO the following properties are not required during reconciliation
// FirewallRules: firewallRules,
// DnsServers: dnsservers,
// NtpServers: ntpservers,
Vpn: vpn,
}

defaultRouteNetwork, err := osnet.New(machineAllocation).GetDefaultRouteNetwork()
if err != nil {
return nil, "", fmt.Errorf("unable to get a default route network: %w", err)
}
if len(defaultRouteNetwork.Ips) == 0 {
return nil, "", errors.New("default route network does not have ips")
}

return machineAllocation, defaultRouteNetwork.Ips[0], nil
}
38 changes: 12 additions & 26 deletions controllers/firewall_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/metal-stack/firewall-controller-manager/api/v2/helper"
firewallv1 "github.com/metal-stack/firewall-controller/v2/api/v1"
"github.com/metal-stack/firewall-controller/v2/pkg/network"
"github.com/metal-stack/firewall-controller/v2/pkg/nftables"
"github.com/metal-stack/firewall-controller/v2/pkg/updater"
)

Expand Down Expand Up @@ -87,28 +86,14 @@ func (r *FirewallReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c

f := &firewallv2.Firewall{}
if err := r.SeedClient.Get(ctx, req.NamespacedName, f); err != nil {
if apierrors.IsNotFound(err) {
r.Log.Info("flushing k8s firewall rules")

defaultFw := nftables.NewFirewall(
&firewallv2.Firewall{},
&firewallv1.ClusterwideNetworkPolicyList{},
&corev1.ServiceList{}, nil, logr.Discard(),
r.Recorder,
)

flushErr := defaultFw.Flush()
if flushErr != nil {
r.Log.Error(flushErr, "error flushing k8s firewall rules")
return ctrl.Result{}, flushErr
}

return ctrl.Result{}, nil
}

return ctrl.Result{}, fmt.Errorf("error retrieving resource: %w", err)
}

allocation, _, err := toMachineAllocation(f)
if err != nil {
return ctrl.Result{}, err
}

if r.Updater != nil {
r.Log.Info("running binary updater")

Expand All @@ -124,7 +109,8 @@ func (r *FirewallReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
r.Log.Info("reconciling network settings")

var errs []error
changed, err := network.ReconcileNetwork(r.Log, f, r.FrrVersion)

changed, err := network.ReconcileNetwork(ctx, r.Log, f, allocation, r.FrrVersion)
if changed && err == nil {
r.recordFirewallEvent(f, corev1.EventTypeNormal, "Network settings", "reconciliation succeeded (frr.conf)")
} else if changed && err != nil {
Expand Down Expand Up @@ -169,16 +155,16 @@ type firewallService struct {
// reconcileFirewallServices reconciles the services and endpoints exposed by the firewall
func (r *FirewallReconciler) reconcileFirewallServices(ctx context.Context, f *firewallv2.Firewall) error {
services := []firewallService{
{
name: nodeExporterService,
port: nodeExporterPort,
namedPort: nodeExporterNamedPort,
},
{
name: nftablesExporterService,
port: nftablesExporterPort,
namedPort: nftablesExporterNamedPort,
},
{
name: nodeExporterService,
port: nodeExporterPort,
namedPort: nodeExporterNamedPort,
},
}

var errs []error
Expand Down
48 changes: 26 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ require (
github.com/google/go-cmp v0.7.0
github.com/google/nftables v0.3.0
github.com/ks2211/go-suricata v0.0.0-20200823200910-986ce1470707
github.com/metal-stack/firewall-controller-manager v0.6.1
github.com/metal-stack/metal-go v0.45.0
github.com/metal-stack/metal-lib v0.26.3
github.com/metal-stack/metal-networker v0.47.0
github.com/metal-stack/api v0.8.4
github.com/metal-stack/firewall-controller-manager v0.6.2
github.com/metal-stack/metal-lib v0.26.4
github.com/metal-stack/os-installer v0.3.3
github.com/metal-stack/v v1.0.3
github.com/miekg/dns v1.1.73
github.com/stretchr/testify v1.12.1
github.com/txn2/txeh v1.8.1
github.com/vishvananda/netlink v1.3.1
go4.org/netipx v0.0.0-20260823151212-3075585bcbeb
google.golang.org/protobuf v1.36.12
k8s.io/api v0.36.3
k8s.io/apiextensions-apiserver v0.36.3
k8s.io/apimachinery v0.36.3
Expand All @@ -31,20 +32,19 @@ require (
replace github.com/imdario/mergo => dario.cat/mergo v1.0.0

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.2 // indirect
dario.cat/mergo v1.0.2 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.14.0 // indirect
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.6 // indirect
github.com/go-openapi/analysis v1.0.1 // indirect
github.com/go-openapi/errors v0.22.9 // indirect
github.com/fxamacker/cbor/v2 v2.10.0 // indirect
github.com/go-openapi/jsonpointer v1.0.2 // indirect
github.com/go-openapi/jsonreference v1.0.3 // indirect
github.com/go-openapi/loads v0.25.3 // indirect
github.com/go-openapi/spec v1.0.1 // indirect
github.com/go-openapi/strfmt v0.27.3 // indirect
github.com/go-openapi/swag v0.29.2 // indirect
github.com/go-openapi/swag/cmdutils v0.29.2 // indirect
github.com/go-openapi/swag/conv v0.29.2 // indirect
Expand All @@ -57,48 +57,52 @@ require (
github.com/go-openapi/swag/stringutils v0.29.2 // indirect
github.com/go-openapi/swag/typeutils v0.29.2 // indirect
github.com/go-openapi/swag/yamlutils v0.29.2 // indirect
github.com/go-openapi/validate v1.0.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/go-openapi/testify/enable/yaml/v2 v2.8.0 // indirect
github.com/godbus/dbus/v5 v5.2.4 // indirect
github.com/google/gnostic-models v0.7.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/huandu/xstrings v1.6.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.16 // indirect
github.com/mattn/go-isatty v0.0.24 // indirect
github.com/mdlayher/netlink v1.11.2 // indirect
github.com/mdlayher/socket v0.8.0 // indirect
github.com/metal-stack/metal-hammer v0.13.17 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/ulid/v2 v2.1.2 // indirect
github.com/pandatix/go-abnf v0.5.3 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.25.0 // indirect
github.com/prometheus/client_model v0.6.3 // indirect
github.com/prometheus/common v0.72.1 // indirect
github.com/prometheus/procfs v0.22.0 // indirect
github.com/prometheus/common v0.73.1 // indirect
github.com/prometheus/procfs v0.23.0 // indirect
github.com/samber/lo v1.53.0 // indirect
github.com/shopspring/decimal v1.6.0 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/stretchr/objx v0.8.0 // indirect
github.com/vishvananda/netns v0.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/net v0.61.0 // indirect
go.yaml.in/yaml/v3 v3.0.6 // indirect
golang.org/x/crypto v0.58.0 // indirect
golang.org/x/net v0.62.0 // indirect
golang.org/x/oauth2 v0.37.0 // indirect
golang.org/x/sync v0.24.0 // indirect
golang.org/x/sys v0.49.0 // indirect
golang.org/x/term v0.47.0 // indirect
golang.org/x/text v0.43.0 // indirect
golang.org/x/time v0.16.0 // indirect
golang.org/x/tools v0.52.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
google.golang.org/protobuf v1.36.12 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.140.0 // indirect
k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a // indirect
k8s.io/utils v0.0.0-20260707023825-cf1189d6abe3 // indirect
k8s.io/utils v0.0.0-20261023123148-ca04ba58ecab // indirect
sigs.k8s.io/json v0.0.0-20260909141634-11ed52e25bc5 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.3 // indirect
Expand Down
Loading
Loading