Skip to content

Conversation

@robmry
Copy link
Contributor

@robmry robmry commented Feb 23, 2025

- What I did

With ip6tables enabled (by default), the daemon should start on a host with IPv6 disabled - then error if IPv6 network creation is attempted.

In 28.0.0, it fails with ...

failed to start daemon: Error initializing network controller: error creating default "bridge" network: add inter-network communication rule:  (iptables failed: ip6tables --wait -t filter -A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2: ip6tables v1.8.9 (nf_tables): Chain 'DOCKER-ISOLATION-STAGE-2' does not exist
Try `ip6tables -h' or 'ip6tables --help' for more information.
 (exit status 2))

- How I did it

In 27.x, the error wasn't propagated properly, a nil was returned following an attempt to roll-back the rule that wasn't created, so startup continued. Commit 255fff4 fixed the error propagation, breaking startup in this case.

The underlying problem was a missing check that the network had IPv6 enabled for INC rule setup. So, added that check.

- How to verify it

Start the daemon on host with IPv6 disabled.

- Human readable description for the release notes

Allow daemon startup on a host with IPv6 disabled without requiring `--ip6tables=false`.

@robmry robmry added this to the 28.0.1 milestone Feb 23, 2025
@robmry robmry self-assigned this Feb 23, 2025
@robmry robmry marked this pull request as ready for review February 23, 2025 10:51

// Install the rules to isolate this network against each of the other networks
if n.driver.config.EnableIPTables {
if n.driver.config.EnableIPTables && (!enable || n.config.EnableIPv4) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we use thisConfig here? (also in the other branch below)?

I must say that the 3 booleans combined make it hard to grasp what exactly the conditions are (perhaps a comment or breaking to a separate condition could help 🤔);

  • We only manipulate if IP(6)tables is enabled
  • And we want to disable, or (explicitly) enable

Is there a case where n.config.EnableIPv4 = false means we must disable things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll have a look ... but the intention is to only add the rules if iptables is enabled, and the network has IPv4 enabled.

But, in case the rule was created by an older version, it's unconditionally deleted if iptables is enabled (because it was unconditionally added before the EnableIPv4 check was added).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've split the condition and added a comment ... does that help?

Copy link
Member

Choose a reason for hiding this comment

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

Should we use thisConfig here? (also in the other branch below)?

There are a few other code paths that locks the network before accessing its config, but it's not really needed because this field is never written after struct initialization:

Anyway, let's keep it as is now it's been changed. We should probably refactor all those code paths after dealing with 28.0.1.

@robmry robmry force-pushed the startup_ip6_disabled branch from de48643 to a8c5cac Compare February 24, 2025 12:13
// Only create the rules if the network has IPv4 enabled. But, always delete
// rules, in case they were set up by an older daemon that didn't check whether
// the network has IPv4.
if !enable || thisConfig.EnableIPv4 {
Copy link
Contributor

@vvoland vvoland Feb 24, 2025

Choose a reason for hiding this comment

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

Does enable == true mean isolated and enabled == false not isolated, or the reverse?
I know this wasn't changed by this PR, but maybe we could rename it to make it a little bit more clear?

Copy link
Member

Choose a reason for hiding this comment

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

enable == true means 'create the rules'.

enabled == false means 'delete the rules'. It's used to rollback something fails down the line, or when the network is deleted.

// Only create the rules if the network has IPv4 enabled. But, always delete
// rules, in case they were set up by an older daemon that didn't check whether
// the network has IPv4.
if !enable || thisConfig.EnableIPv4 {
Copy link
Member

Choose a reason for hiding this comment

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

I find this version more confusing than the previous was, and now the comment right before if n.driver.config.EnableIPTables contradicts the inner comment as it talks about "installing" while the inner comment mentions the delete case.

But that's usual level of bikeshedding I guess, so whatever feels best for you seems okay to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've deleted the comment above, which mostly duplicated the function's comment - and updated the function's comment to say what "enable" does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Also rebased - so I'll let the tests run, then merge.)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! ❤️

With ip6tables enabled (by default), the daemon should start on a
host with IPv6 disabled - then error if IPv6 network creation is
attempted.

That regressed in commit 255fff4 - so, only try to set up network
isolation rules for a network if it's IPv6-enabled.

Signed-off-by: Rob Murray <[email protected]>
@robmry robmry force-pushed the startup_ip6_disabled branch from a8c5cac to 8cc4d1d Compare February 24, 2025 17:42
@robmry robmry merged commit f344ab1 into moby:master Feb 24, 2025
150 checks passed
@robmry robmry deleted the startup_ip6_disabled branch February 26, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

28.0.0: ipv6 cannot be disable, failed to load daemon.

4 participants