Skip to content

fix(k8s): fall back to legacy iptables - #2130

Open
stephenlclarke wants to merge 2 commits into
apple:mainfrom
stephenlclarke:fix/k8s-legacy-iptables
Open

stephenlclarke wants to merge 2 commits into
apple:mainfrom
stephenlclarke:fix/k8s-legacy-iptables

Conversation

@stephenlclarke

@stephenlclarke stephenlclarke commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Closes #2120.

Probe the nftables backend during node preparation. When the node kernel cannot use it, select the available legacy iptables and ip6tables alternatives before applying the MSS rules. This also keeps subsequent Kubernetes components on the working backend.

Node preparation now runs through LinuxNodeProvisioner. All interpolated paths are shell-quoted. Each MSS rule is added only if it is absent.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

All five node-preparation tests passed on macOS. They cover nftables selection, quoted paths, repeated setup and failed rule insertion. Swift format and whitespace checks passed. Both commits are signed.

Earlier validation passed 758 non-integration tests. Without the fallback, the failure fixture applied neither the fallback nor the MSS rules. The broader suite was not rerun for the upstream module rename.

@stephenlclarke
stephenlclarke force-pushed the fix/k8s-legacy-iptables branch from f963e3e to 7ab8caf Compare August 23, 2026 16:32
@stephenlclarke

Copy link
Copy Markdown
Contributor Author

Rebased onto current main after K8sHelper was split into focused extensions. The fallback now lives in K8sHelper+Bootstrap.swift; the behavior and focused test coverage are unchanged.

Post-rebase validation:

  • swift test --filter K8sNodePreparationTests: 2/2 passed
  • git diff --check: passed
  • rebased commit signature: verified

The PR is mergeable again. GitHub currently reports the workflow as action_required, so an Apple maintainer still needs to approve the fork-originated run.

@stephenlclarke
stephenlclarke force-pushed the fix/k8s-legacy-iptables branch from 7ab8caf to b2d773b Compare August 26, 2026 22:37
@stephenlclarke

stephenlclarke commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Refresh 2026-08-26: rebased the single signed fix onto current main (d96dfa3), including the upstream K8sHelper split. New head: b2d773b. Focused K8sNodePreparationTests passed 2/2, and git diff --check passed.

@stephenlclarke
stephenlclarke force-pushed the fix/k8s-legacy-iptables branch from b2d773b to ea3c5f5 Compare August 31, 2026 10:34
@stephenlclarke

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto current Apple main (d925dab865cf). The updated head is signed and remains one commit over the base: ea3c5f5a039ed90c2c3aa81a66a4b8bb7b261ed4.

Exact-head focused verification: swift test --jobs 4 --filter K8sNodePreparationTests — 2 focused tests passed; git diff --check passed and the worktree is clean. The broader test evidence already recorded in this PR remains unchanged; this update only incorporates the newer Apple base.

@codex review

@stephenlclarke
stephenlclarke force-pushed the fix/k8s-legacy-iptables branch from ea3c5f5 to a496a3a Compare September 5, 2026 19:06
@stephenlclarke

Copy link
Copy Markdown
Contributor Author

Refresh 2026-09-05: rebased the single signed fix onto current Apple main (eee7ad097079). The new head is a496a3abba714baa510704b38339c8565418e07f; swift test --jobs 4 --filter K8sNodePreparationTests passed 2/2 and git diff --check passed. The PR is mergeable; fork-originated CI still requires Apple approval.

@stephenlclarke
stephenlclarke force-pushed the fix/k8s-legacy-iptables branch 3 times, most recently from a4e5e66 to e988163 Compare October 28, 2026 11:40
@stephenlclarke
stephenlclarke force-pushed the fix/k8s-legacy-iptables branch 2 times, most recently from 3410b90 to 8cd7cc7 Compare November 8, 2026 14:59
iptablesPath: String = "/usr/sbin/iptables"
) -> String {
"""
if ! \(nftPath) -t mangle -S >/dev/null 2>&1; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a helper like the following, and replace the direct interpolations here with one that expressly prohibits injection. I know we're injecting constants that we control here but better to be able to look at the code and know we're doing safe shell interpolation.

/// Quotes `value` as a single shell word: wrapped in single quotes, with each
/// embedded single quote written as '\''.
private static func shellQuote(_ value: String) -> String {
    "'" + value.replacingOccurrences(of: "'", with: "'\\''") + "'"
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jon. I added shellQuote and use it for every path in the helper. The tests cover spaces, quotes and shell characters in those paths. All five node-preparation tests pass on macOS.

\(updateAlternativesPath) --set iptables \(legacyPath)
\(updateAlternativesPath) --set ip6tables \(ip6LegacyPath)
fi
\(iptablesPath) -t mangle -A OUTPUT -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1220

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make these idempotent by trying -C … || -A …

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Each rule uses -C before -A. The test runs setup twice and checks that each rule is added once. A failed insertion still stops setup.

@jglogan

jglogan commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@stephenlclarke Looks good, made a couple suggestions.

Probe the nftables backend during node preparation and select the legacy iptables alternatives when the node kernel cannot use nftables. Apply the MSS rules through the selected system backend.

Fixes apple#2120
@stephenlclarke
stephenlclarke force-pushed the fix/k8s-legacy-iptables branch from 8cd7cc7 to b1fd7f4 Compare November 12, 2026 18:05

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container k8s create fails when node preparation invokes iptables-nft

2 participants