Skip to content

Commit cbb11f3

Browse files
committed
fix: fix reverse routing for KubeSpan
This allows it to not come down when rp_filter is enabled. Fixes #9814 Signed-off-by: Dmitry Sharshakov <[email protected]>
1 parent 650eb3a commit cbb11f3

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

internal/app/machined/pkg/controllers/kubespan/manager.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
378378
},
379379
Verdict: pointer.To(nethelpers.VerdictAccept),
380380
},
381+
// Mark packets to be sent over the KubeSpan link.
381382
{
382383
MatchDestinationAddress: &network.NfTablesAddressMatch{
383384
IncludeSubnets: allowedIPsSet.Prefixes(),
@@ -388,6 +389,18 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
388389
},
389390
Verdict: pointer.To(nethelpers.VerdictAccept),
390391
},
392+
// Mark incoming packets from the KubeSpan link for rp_filter to find the correct routing table.
393+
{
394+
MatchIIfName: &network.NfTablesIfNameMatch{
395+
InterfaceNames: []string{constants.KubeSpanLinkName},
396+
Operator: nethelpers.OperatorEqual,
397+
},
398+
SetMark: &network.NfTablesMark{
399+
Mask: ^uint32(constants.KubeSpanDefaultFirewallMask),
400+
Xor: constants.KubeSpanDefaultForceFirewallMark,
401+
},
402+
Verdict: pointer.To(nethelpers.VerdictAccept),
403+
},
391404
}
392405

393406
return nil

internal/app/machined/pkg/controllers/kubespan/manager_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ func (suite *ManagerSuite) TestReconcile() {
244244
asrt.Equal(nethelpers.ChainPriorityFilter, spec.Priority)
245245
asrt.Equal(nethelpers.VerdictAccept, spec.Policy)
246246

247-
asrt.Len(spec.Rules, 2)
247+
asrt.Len(spec.Rules, 3)
248248

249-
if len(spec.Rules) != 2 {
249+
if len(spec.Rules) != 3 {
250250
return
251251
}
252252

@@ -277,6 +277,21 @@ func (suite *ManagerSuite) TestReconcile() {
277277
},
278278
spec.Rules[1],
279279
)
280+
281+
asrt.Equal(
282+
network.NfTablesRule{
283+
MatchIIfName: &network.NfTablesIfNameMatch{
284+
InterfaceNames: []string{constants.KubeSpanLinkName},
285+
Operator: nethelpers.OperatorEqual,
286+
},
287+
SetMark: &network.NfTablesMark{
288+
Mask: ^uint32(constants.KubeSpanDefaultFirewallMask),
289+
Xor: constants.KubeSpanDefaultForceFirewallMark,
290+
},
291+
Verdict: pointer.To(nethelpers.VerdictAccept),
292+
},
293+
spec.Rules[2],
294+
)
280295
},
281296
)
282297

internal/app/machined/pkg/controllers/runtime/kernel_param_defaults.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
v1alpha1runtime "github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
1717
"github.com/siderolabs/talos/pkg/kernel/kspp"
18+
"github.com/siderolabs/talos/pkg/machinery/constants"
1819
"github.com/siderolabs/talos/pkg/machinery/kernel"
1920
"github.com/siderolabs/talos/pkg/machinery/resources/runtime"
2021
)
@@ -120,6 +121,11 @@ func (ctrl *KernelParamDefaultsController) getKernelParams() []*kernel.Param {
120121
Key: "proc.sys.net.ipv4.tcp_keepalive_intvl",
121122
Value: "60",
122123
},
124+
// Consider fwmark for rp_filter routing table lookup.
125+
{
126+
Key: "proc.sys.net.ipv4.conf." + constants.KubeSpanLinkName + ".src_valid_mark",
127+
Value: "1",
128+
},
123129
{
124130
Key: "proc.sys.kernel.panic",
125131
Value: "10",

0 commit comments

Comments
 (0)