Skip to content

Commit c9a4212

Browse files
committed
fix(chart): legacy default_addresses_by_gateway drops scope=link / nowhere too
The legacy v1.11 helper `talm.discovered.default_addresses_by_gateway` filtered only the `host` scope, while the v1.12 multi-doc sibling `talm.discovered.addresses_by_link` rejects the full `host` / `link` / `nowhere` triple (the kernel-managed scopes that should never land in node config). Real Talos COSI always sets scope=link for the 169.254/16 link-local range, so the divergence was latent — but a future COSI schema bump that produced link-local entries on the default-gateway-bearing link would have leaked them verbatim into the legacy `machine.network.interfaces[].addresses` block while the v1.12 path correctly dropped them. Hoist the same `$skipScopes := list "host" "link" "nowhere"` the v1.12 helper uses and apply `has (.spec.scope | toString) $skipScopes` symmetrically. The two helpers now share one scope-filter rule. Pinned by TestContract_NetworkLegacy_DefaultAddressesFilterLinkScope with a new linkScopedAddressOnDefaultGatewayLookup fixture — a realistic Hetzner topology with a link-scoped 169.254/16 sandwiched between two global-scope siblings on the default- route-bearing link. Asserts the link-scoped entry is absent from the rendered output AND a global-scope sibling on the same link is still present (the filter must be scope-selective, not "drop everything on this link"). Verified regression-pin: stashed the chart fix, test failed at the expected assertion; restored, test passed. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 0c4786a commit c9a4212

4 files changed

Lines changed: 154 additions & 1 deletion

File tree

‎charts/talm/templates/_helpers.tpl‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,25 @@
142142
it cannot match a real CIDR prefix. */ -}}
143143
{{- $fipStr := $.Values.floatingIP | toString }}
144144
{{- $addresses := list }}
145+
{{- /* Drop the same kernel-managed scopes addresses_by_link
146+
rejects (host loopback, link-local, "nowhere"). Real Talos
147+
COSI always sets scope=link for the 169.254/16 link-local
148+
range, so a legacy v1.11 render that filtered only the
149+
"host" scope was at risk of leaking link-local addresses
150+
verbatim into machine.network.interfaces[].addresses on
151+
the next COSI schema bump. Mirror the two helpers so a
152+
future bump that produces new link-local entries on the
153+
default-gateway-bearing link can't slip through one path
154+
while being correctly rejected by the other. */ -}}
155+
{{- $skipScopes := list "host" "link" "nowhere" }}
145156
{{- range (lookup "addresses" "" "").items }}
146157
{{- /* Filter malformed or future-format entries the same way
147158
addresses_by_link does (cidrPrefixLen >= 0). A corrupt entry
148159
in the COSI addresses table must not leak verbatim into the
149160
legacy v1.11 machine.network.interfaces[].addresses block. */ -}}
150161
{{- $address := .spec.address | toString }}
151162
{{- $validCidr := ge (cidrPrefixLen $address) 0 }}
152-
{{- if and (eq .spec.linkName $linkName) (eq .spec.family $family) (not (eq .spec.scope "host")) $validCidr }}
163+
{{- if and (eq .spec.linkName $linkName) (eq .spec.family $family) (not (has (.spec.scope | toString) $skipScopes)) $validCidr }}
153164
{{- if not (hasPrefix (printf "%s/" $fipStr) $address) }}
154165
{{- $addresses = append $addresses $address }}
155166
{{- end }}

‎docs/manual-test-plan.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,24 @@ When the local `charts/talm/` is older than the talm binary's embedded preset, `
228228

229229
**Regression anchor**: `template -I` is rewrite, not merge — verify by adding a `# my comment` line above the modeline in `nodes/node0.yaml`, running B4, and confirming the comment is GONE in the new body. If the comment survives, a behaviour change shipped (could be either an intentional new `--preserve-comments` flag or an undocumented merge mode — neither should appear silently).
230230

231+
### B6. Scope-filter symmetry across v1.11 and v1.12 renders
232+
233+
Pin both schema renders dropping kernel-managed scopes (`host` / `link` / `nowhere`) from the COSI addresses table. On a node where 169.254/16 link-local addresses live on the default-gateway-bearing interface (Talos always sets `scope=link` for that range), assert:
234+
235+
```bash
236+
# Render the legacy v1.11 path first — explicit talosVersion pin:
237+
sed -i.bak 's/^talosVersion: "v1.12"/talosVersion: "v1.11"/' Chart.yaml
238+
talm template -f nodes/node0.yaml | grep -E "address: 169\.254" && echo "FAIL: link-scoped leaked into v1.11" || echo "OK v1.11"
239+
mv Chart.yaml.bak Chart.yaml
240+
241+
# Then render the v1.12 path (default):
242+
talm template -f nodes/node0.yaml | grep -E "address: 169\.254" && echo "FAIL: link-scoped leaked into v1.12" || echo "OK v1.12"
243+
```
244+
245+
Expected: both renders print "OK" — no `address: 169.254.…` lines anywhere in the rendered output. The two helpers (`talm.discovered.default_addresses_by_gateway` for v1.11 and `talm.discovered.addresses_by_link` for v1.12) share the same `$skipScopes := list "host" "link" "nowhere"` filter so a link-local address on the default-gateway link is dropped from both paths.
246+
247+
Regression anchor: a regression that re-introduces the v1.11-only `host`-scope filter would let link-local addresses leak into the legacy `machine.network.interfaces[].addresses` block on a future COSI schema bump that emitted them on the default-gateway-bearing link. Pinned by `TestContract_NetworkLegacy_DefaultAddressesFilterLinkScope` with a `linkScopedAddressOnDefaultGatewayLookup` fixture, but the live render is still useful as a sanity check against real cluster discovery output.
248+
231249
## C. Apply (auth path)
232250

233251
This section is the smoke-test for the apply pipe itself; the per-gate matrix lives in **Section C-safety** below.

‎pkg/engine/contract_network_multidoc_test.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,34 @@ func TestContract_NetworkLegacy_DefaultAddressesFilterMalformedCidr(t *testing.T
10051005
}
10061006
}
10071007

1008+
// Contract: legacy v1.11 default_addresses_by_gateway drops the
1009+
// same kernel-managed scopes addresses_by_link drops — host,
1010+
// link, nowhere. Without this symmetry a link-scoped 169.254/16
1011+
// entry on the default-gateway-bearing link could land verbatim
1012+
// in machine.network.interfaces[].addresses on a future COSI
1013+
// schema bump that produced link-local entries the legacy path
1014+
// hadn't yet seen. Real Talos COSI always uses scope=link for
1015+
// 169.254/16, so this case is currently latent — but the two
1016+
// helpers must apply the same filter for symmetry and to stay
1017+
// reasonable to maintain together.
1018+
//
1019+
// Fixture: a link-scoped 169.254.1.5/16 entry on the default-
1020+
// route-bearing link sandwiched between two global-scope
1021+
// siblings. The render asserts the link-scoped address is
1022+
// absent from the rendered output while the global-scope
1023+
// sibling on the same link is present.
1024+
func TestContract_NetworkLegacy_DefaultAddressesFilterLinkScope(t *testing.T) {
1025+
out := renderChartTemplateWithLookup(t, cozystackChartPath, controlplaneTpl, linkScopedAddressOnDefaultGatewayLookup(), "v1.11")
1026+
1027+
if strings.Contains(out, "169.254.1.5") {
1028+
t.Errorf("legacy v1.11: link-scoped 169.254/16 leaked into machine.network.interfaces[].addresses; default_addresses_by_gateway scope filter must drop scope=link (mirror addresses_by_link). got:\n%s", out)
1029+
}
1030+
1031+
if !strings.Contains(out, "88.99.210.37") {
1032+
t.Errorf("legacy v1.11: global-scope sibling on the default-gateway link missing from rendered output — scope filter dropped valid addresses too. got:\n%s", out)
1033+
}
1034+
}
1035+
10081036
// Generic-chart mirrors of the four legacy fail-fast contracts above.
10091037

10101038
func TestContract_NetworkLegacy_Generic_VIPFailsOnInvalidFloatingIP(t *testing.T) {

‎pkg/engine/render_test.go‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5749,6 +5749,102 @@ func malformedAddressEntryLookup() func(string, string, string) (map[string]any,
57495749
}
57505750
}
57515751

5752+
// linkScopedAddressOnDefaultGatewayLookup mirrors
5753+
// malformedAddressEntryLookup's IPv4 Hetzner topology but
5754+
// sandwiches a link-scoped 169.254/16 entry on the
5755+
// default-gateway-bearing link between two global-scope
5756+
// siblings. Used by
5757+
// TestContract_NetworkLegacy_DefaultAddressesFilterLinkScope to
5758+
// pin that the legacy v1.11 default_addresses_by_gateway helper
5759+
// drops scope=link the same way addresses_by_link does. Real
5760+
// Talos COSI always emits scope=link for 169.254/16, so the
5761+
// fixture reflects realistic on-the-wire shape.
5762+
func linkScopedAddressOnDefaultGatewayLookup() func(string, string, string) (map[string]any, error) {
5763+
publicNIC := map[string]any{
5764+
"metadata": map[string]any{"id": "enp0s31f6"},
5765+
"spec": map[string]any{
5766+
"kind": "physical",
5767+
"index": 1,
5768+
"hardwareAddr": "aa:bb:cc:00:01:01",
5769+
"busPath": "pci-0000:00:1f.6",
5770+
"mtu": 1500,
5771+
},
5772+
}
5773+
routesList := map[string]any{
5774+
"apiVersion": "v1",
5775+
"kind": "List",
5776+
"items": []any{
5777+
map[string]any{
5778+
"spec": map[string]any{
5779+
"dst": "",
5780+
"gateway": "88.99.210.1",
5781+
"outLinkName": "enp0s31f6",
5782+
"family": "inet4",
5783+
"table": "main",
5784+
"priority": 100,
5785+
},
5786+
},
5787+
},
5788+
}
5789+
linksList := map[string]any{
5790+
"apiVersion": "v1",
5791+
"kind": "List",
5792+
"items": []any{publicNIC},
5793+
}
5794+
// Three entries on the default-gateway link: a global-scope
5795+
// global IP, a link-scoped 169.254 link-local that the new
5796+
// scope filter MUST drop, and another global-scope sibling
5797+
// so the test can assert the filter is scope-selective (it
5798+
// doesn't drop everything on the link).
5799+
addressesList := map[string]any{
5800+
"apiVersion": "v1",
5801+
"kind": "List",
5802+
"items": []any{
5803+
map[string]any{"spec": map[string]any{"linkName": "enp0s31f6", "address": "88.99.210.37/26", "family": "inet4", "scope": "global"}},
5804+
map[string]any{"spec": map[string]any{"linkName": "enp0s31f6", "address": "169.254.1.5/16", "family": "inet4", "scope": "link"}},
5805+
map[string]any{"spec": map[string]any{"linkName": "enp0s31f6", "address": "88.99.210.38/26", "family": "inet4", "scope": "global"}},
5806+
},
5807+
}
5808+
nodeDefault := map[string]any{
5809+
"spec": map[string]any{
5810+
"addresses": []any{"88.99.210.37/26"},
5811+
},
5812+
}
5813+
resolvers := map[string]any{
5814+
"spec": map[string]any{
5815+
"dnsServers": []any{"8.8.8.8"},
5816+
},
5817+
}
5818+
5819+
return func(resource, _, id string) (map[string]any, error) {
5820+
switch resource {
5821+
case "routes":
5822+
return routesList, nil
5823+
case "links":
5824+
if id == "enp0s31f6" {
5825+
return publicNIC, nil
5826+
}
5827+
if id == "" {
5828+
return linksList, nil
5829+
}
5830+
5831+
return map[string]any{}, nil
5832+
case "addresses":
5833+
return addressesList, nil
5834+
case "nodeaddress":
5835+
if id == "default" {
5836+
return nodeDefault, nil
5837+
}
5838+
case "resolvers":
5839+
if id == "resolvers" {
5840+
return resolvers, nil
5841+
}
5842+
}
5843+
5844+
return map[string]any{}, nil
5845+
}
5846+
}
5847+
57525848
// hetznerPublicNICWithPrivateIPv6VLANLookup is the IPv6-equivalent of
57535849
// hetznerPublicNICWithPrivateVLANLookup. The same physical / VLAN
57545850
// topology, but the private subnet is a /64 ULA and the VIP is an

0 commit comments

Comments
 (0)