Repository navigation
feat: manage an existing firewall via spec.firewall-id (node-pool firewalls) - #39
Open
aweingarten wants to merge 1 commit into
Open
aweingarten wants to merge 1 commit into
aweingarten wants to merge 1 commit into
Conversation
aweingarten
marked this pull request as draft
October 14, 2026 00:18
aweingarten
marked this pull request as ready for review
October 14, 2026 00:27
aweingarten
marked this pull request as draft
October 14, 2026 02:44
aweingarten
force-pushed
the
feat/adopt-existing-firewall
branch
from
October 14, 2026 02:51
d64d6d3 to
6a78ad1
Compare
aweingarten
marked this pull request as ready for review
October 14, 2026 02:51
spec.firewall-id was declared on the CloudFirewall CRD but never read, so the controller always created its own lke-<clusterID> firewall and tried to attach every node to it. That conflicts with a firewall attached through an LKE node pool's firewall_id, which LKE attaches to every node it creates. When spec.firewall-id is set the controller adopts that firewall and reconciles only its rules. It never creates or recreates it, never manages its devices, never deletes it, and puts no finalizer on the object. Ownership is positive: the controller only deletes, or manages the devices of, a firewall it created, i.e. one labelled lke-<clusterID> that is not recorded as imported. The adopted firewall is recorded in the networking.linode.com/imported-firewall-id annotation (metadata, so an older CRD cannot prune it), but losing it can never get a firewall deleted. Transitions: - Adding firewall-id to an object whose firewall the controller created applies the rules to the imported firewall, moves each node onto it (detach then attach, one node at a time; a Linode can only be on one Cloud Firewall), then deletes the old firewall. Idempotent on retry. - Changing firewall-id adopts the new firewall and leaves the old one. - Removing it releases the firewall untouched. Safety: - Import mode requires defaultRules to be set explicitly, and defaultRules=false requires inbound rules (CEL rules on the CRD, checked in the controller too). The schema default on defaultRules is removed so "unset" is detectable; the controller still treats unset as true. - A firewall attached to any device outside this cluster is refused; a Linode in this LKE cluster that has not registered as a Node is not foreign. Linode-interface devices are matched through their parent. - Status conditions Imported and NodesProtected, plus Events, report adoption, refusals and unattached nodes. - --auto-create-default (default true) gates the Node watch creating an empty kube-system/primary object; the chart turns it off with firewallID. Import-mode objects are never migrated onto the default ruleset. - Deletion is handled before the rate limiter, the finalizer is only added for owned firewalls, and finalizer removal errors are returned. Fixes to existing behaviour: - removeNodes passed a Linode ID where DeleteFirewallDevice takes a device ID; devices are now looked up first. - The deferred write no longer drops a status change made in the same reconcile as a metadata change. - FirewallIsNotFound no longer dereferences a nil *linodego.Error. Also: CRD documents and validates firewall-id (config + helm copy); chart gains firewall.firewallID (integers only), firewall.defaultRules (required with firewallID) and autoCreateDefault; events.k8s.io RBAC; README section. Tests: envtest specs against a stateful fake Linode API, run against both the current CRD and the pre-firewall-id CRD. Refs linode#1
aweingarten
force-pushed
the
feat/adopt-existing-firewall
branch
from
October 15, 2026 16:22
6a78ad1 to
359786b
Compare
tameemakhtar
added a commit
to tameemakhtar/cloud-firewall-controller
that referenced
this pull request
Nov 5, 2026
The controller already honours spec.defaultRules on the CloudFirewall (unset or true merges the compiled default rules, false applies only spec.ruleset), but the chart left it as a comment, so a values file could not turn the compiled defaults off. Render spec.defaultRules when firewall.defaultRules is set, with the same key and template as upstream PR linode#39. When the key is not set, nothing is rendered and the CRD default (true) applies, as before.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The controller can't be used on clusters whose node pools already attach a Cloud Firewall (the node pool
firewall_id, set through the API, Cloud Manager or Terraform'slinode_lke_node_pool). LKE attaches that firewall to every node the pool creates, and the controller fights it:spec.firewall-idis declared on the CRD but never read.status.firewall-idempty, the first reconcile always callsCreateFirewallforlke-<clusterID>with every node as a device, and later reconciles add and remove devices.status.firewall-idisn't safe either: deleting theCloudFirewall(including through the owner reference on uninstall) runs the finalizer, which deletes that firewall.This also affects App Platform, which ships this controller as its
linode-cfwapp. #1 noted that importing an existing firewall ID was still needed; this implements it.Change
With
spec.firewall-idset, the controller adopts that firewall and reconciles only its rules: the defaults ifdefaultRules: true, plusspec.ruleset. These replace the firewall's inbound rules, outbound rules and both policies. It never creates or recreates the firewall, never manages its devices, never deletes it, and puts no finalizer on the object.Ownership is positive. The controller only deletes, or manages the devices of, a firewall it created: one labelled
lke-<clusterID>that isn't recorded as imported.networking.linode.com/imported-firewall-idannotation. It lives in metadata, so a CRD older than the controller can't prune it.Transitions:
Adding
firewall-idto an object whose firewall the controller created:Each step can be safely retried.
Changing
firewall-idto another ID adopts the new firewall and leaves the previous one in place.Removing
firewall-idreleases the firewall untouched.Safety checks:
defaultRules: import mode requiresdefaultRulesto be set explicitly, anddefaultRules: falserequires inbound rules. These are CEL rules on the CRD, checked in the controller too. An empty inbound ruleset under the DROP policy would cut the nodes off.defaultRulesis removed. The controller still treats unset astrue, so behaviour withoutfirewall-idis unchanged.ImportedandNodesProtected, plus Events, report adoption, refusals and unattached nodes.--auto-create-defaultflag: controls whether the Node watch creates an emptykube-system/primaryobject (defaulttrue). The chart turns it off whenfirewall.firewallIDis set, so a default object can't create a second firewall before the chart's object lands. Import-mode objects are never migrated onto the default ruleset.Fixes to existing behaviour:
removeNodes: passed a Linode ID whereDeleteFirewallDevicetakes a device ID. It now looks up the device first.FirewallIsNotFound: no longer dereferences a nil*linodego.Error.Also included:
firewall-idis documented and validated, there are CEL rules and status conditions, inconfig/crd/basesand the Helm copy.firewall.firewallIDaccepts integers only;firewall.defaultRulesis required whenfirewallIDis set;autoCreateDefaultvalue;events.k8s.ioRBAC.Questions for maintainers
defaultRulesschema default: it's needed to detect an unset value in import mode. Existing objects keep thetruethe old schema stored. Is that acceptable, or would you prefer a separate field?linode-cfwvendors this CRD undercrds/, which Helm doesn't upgrade. Against that older CRD, everything here still works except the admission-time checks.defaultRulesis defaulted totruethere, so the explicit-choice check only holds with the new CRD or through the chart.Known limits
linode,linode_interface) and the Linode-per-firewall limit come from linodego and the API docs.linodedevices, which may not be valid there.Testing
internal/controller/import_test.goruns envtest specs against a stateful fake Linode API, using linodego'sLINODE_URL. The fake keeps labels, stored rules, device IDs and instances. The specs run against both the current CRD and the CRD from beforefirewall-idwas supported (testdata/crd-before-import). They cover:firewall-idchanges;defaultRulesand inbound rules.There are also unit tests for
deviceLinodeIDandvalidateImportSpec.Each protection was checked by breaking it and confirming the matching specs fail against both CRDs:
Notes on the existing baseline:
cloudfirewall_controller_test.goalready fails onmain(failed to get API credentails: resource name may not be empty). I left it alone.golangci-lint runreports 46 issues against 48 onmain, and--new-from-rev=origin/mainreports none.helm lintpasses, and the template was rendered with and without the import values.