Repository navigation
Add patches with fixes for Docker engine - #4605
Conversation
This adds two patches with fixes/improvements for the Docker engine - `0001-daemon-respect-explicit-AppArmor-profile-on-privileg.patch`: Makes sure that AppArmor rules are always loaded, also on reboot. This is a long standing bug in Docker and affects Supervisor which is a privileged container with an AppArmor profile. Upstream PR: moby/moby#52215 - `0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch`: Makes sure that the whole network (including gateway IP) of any Docker bridge network in NAT mode is firewalled from access from the outside. This essentially implements on Docker level what Supervisor applies on startup with home-assistant/supervisor#6650. Upstream PR: moby/moby#52224.
๐ WalkthroughWalkthroughThese patches modify Docker Engine's AppArmor and network bridge handling. The first respects user-specified AppArmor profiles by only applying defaults when no profile is explicitly configured. The second implements subnet-scoped network protection rules at the network level rather than per-endpoint, blocking direct external access to bridge subnets. Changes
Estimated code review effort๐ฏ 3 (Moderate) | โฑ๏ธ ~20 minutes Poem
๐ฅ Pre-merge checks | โ 2 | โ 1โ Failed checks (1 inconclusive)
โ Passed checks (2 passed)
โ๏ธ Tip: You can configure your own custom pre-merge checks in the settings. โจ Finishing Touches๐งช Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
๐งน Nitpick comments (1)
buildroot-external/patches/docker-engine/0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch (1)
179-182: MissingInternalnetwork check compared to previous implementation.The old per-endpoint
filterDirectAccesscheckedn.config.Internaland skipped filtering for internal networks. The newsetSubnetProtectionomits this check. While internal networks shouldn't have external access anyway (making the rules harmless), this adds unnecessary firewall rules to internal networks.Consider adding the Internal check for consistency:
Suggested fix
func (n *network) setSubnetProtection(ctx context.Context, ipv iptables.IPVersion, config firewaller.NetworkConfigFam, enable bool) error { - if config.Unprotected || config.Routed || !config.Prefix.IsValid() { + if n.config.Internal || config.Unprotected || config.Routed || !config.Prefix.IsValid() { return nil }๐ค Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@buildroot-external/patches/docker-engine/0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch` around lines 179 - 182, The new setSubnetProtection method is missing the prior check for internal networks, causing unnecessary firewall rules to be added for networks where n.config.Internal is true; update setSubnetProtection to early-return when n.config.Internal is true (same behavior as the old filterDirectAccess) so that if config.Unprotected || config.Routed || !config.Prefix.IsValid() || n.config.Internal then return nil, ensuring internal networks skip subnet protection rule changes.
๐ค Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@buildroot-external/patches/docker-engine/0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch`:
- Around line 305-321: The nftables branch currently only checks
conf.Prefix.IsValid() && !n.fw.config.AllowDirectRouting, but must also skip
adding rules when the gateway mode is nat-unprotected or routed; update the
condition guarding the nftables.Rule creation to also require that
n.config.Unprotected is false and n.config.Routed is false (i.e., only proceed
when conf.Prefix.IsValid() && !n.fw.config.AllowDirectRouting &&
!n.config.Unprotected && !n.config.Routed) so the behavior matches the iptables
implementation; keep the same use of table.Family(), rawPreroutingChain and
initialRuleGroup when creating the rule.
---
Nitpick comments:
In
`@buildroot-external/patches/docker-engine/0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch`:
- Around line 179-182: The new setSubnetProtection method is missing the prior
check for internal networks, causing unnecessary firewall rules to be added for
networks where n.config.Internal is true; update setSubnetProtection to
early-return when n.config.Internal is true (same behavior as the old
filterDirectAccess) so that if config.Unprotected || config.Routed ||
!config.Prefix.IsValid() || n.config.Internal then return nil, ensuring internal
networks skip subnet protection rule changes.
โน๏ธ Review info
โ๏ธ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 06427d50-3bfd-4670-9247-b02ba410d60b
๐ Files selected for processing (2)
buildroot-external/patches/docker-engine/0001-daemon-respect-explicit-AppArmor-profile-on-privileg.patchbuildroot-external/patches/docker-engine/0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch
| + // Drop packets destined to any IP in the bridge subnet from interfaces | ||
| + // other than the bridge, loopback, or any trusted host interfaces. This | ||
| + // protects containers on unpublished ports and the host's gateway address | ||
| + // from external hosts that have a direct route to the bridge subnet. | ||
| + if conf.Prefix.IsValid() && !n.fw.config.AllowDirectRouting { | ||
| + family := string(table.Family()) | ||
| + ifNames := strings.Join(append([]string{n.config.IfName, "lo"}, n.config.TrustedHostInterfaces...), ", ") | ||
| + tm.Create(nftables.Rule{ | ||
| + Chain: rawPreroutingChain, | ||
| + Group: initialRuleGroup, | ||
| + Rule: []string{ | ||
| + family, "daddr", conf.Prefix.String(), | ||
| + "iifname != {", ifNames, `}`, | ||
| + `counter drop comment "SUBNET DROP EXTERNAL"`, | ||
| + }, | ||
| + }) | ||
| + } |
There was a problem hiding this comment.
Missing Unprotected and Routed checks in nftables implementation.
The condition on line 309 only checks conf.Prefix.IsValid() && !n.fw.config.AllowDirectRouting, but the iptables implementation (line 180 in the patch) also checks config.Unprotected || config.Routed. This inconsistency means:
- nftables will add subnet protection rules even for
nat-unprotectedgateway mode - nftables will add subnet protection rules even for
routedgateway mode
This contradicts the commit message: "The rules are not added for gateway modes 'routed' or 'nat-unprotected'".
Proposed fix to align with iptables and commit message
// Drop packets destined to any IP in the bridge subnet from interfaces
// other than the bridge, loopback, or any trusted host interfaces. This
// protects containers on unpublished ports and the host's gateway address
// from external hosts that have a direct route to the bridge subnet.
- if conf.Prefix.IsValid() && !n.fw.config.AllowDirectRouting {
+ if conf.Prefix.IsValid() && !conf.Unprotected && !conf.Routed && !n.fw.config.AllowDirectRouting {
family := string(table.Family())
ifNames := strings.Join(append([]string{n.config.IfName, "lo"}, n.config.TrustedHostInterfaces...), ", ")๐ Committable suggestion
โผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| + // Drop packets destined to any IP in the bridge subnet from interfaces | |
| + // other than the bridge, loopback, or any trusted host interfaces. This | |
| + // protects containers on unpublished ports and the host's gateway address | |
| + // from external hosts that have a direct route to the bridge subnet. | |
| + if conf.Prefix.IsValid() && !n.fw.config.AllowDirectRouting { | |
| + family := string(table.Family()) | |
| + ifNames := strings.Join(append([]string{n.config.IfName, "lo"}, n.config.TrustedHostInterfaces...), ", ") | |
| + tm.Create(nftables.Rule{ | |
| + Chain: rawPreroutingChain, | |
| + Group: initialRuleGroup, | |
| + Rule: []string{ | |
| + family, "daddr", conf.Prefix.String(), | |
| + "iifname != {", ifNames, `}`, | |
| + `counter drop comment "SUBNET DROP EXTERNAL"`, | |
| + }, | |
| + }) | |
| + } | |
| // Drop packets destined to any IP in the bridge subnet from interfaces | |
| // other than the bridge, loopback, or any trusted host interfaces. This | |
| // protects containers on unpublished ports and the host's gateway address | |
| // from external hosts that have a direct route to the bridge subnet. | |
| if conf.Prefix.IsValid() && !conf.Unprotected && !conf.Routed && !n.fw.config.AllowDirectRouting { | |
| family := string(table.Family()) | |
| ifNames := strings.Join(append([]string{n.config.IfName, "lo"}, n.config.TrustedHostInterfaces...), ", ") | |
| tm.Create(nftables.Rule{ | |
| Chain: rawPreroutingChain, | |
| Group: initialRuleGroup, | |
| Rule: []string{ | |
| family, "daddr", conf.Prefix.String(), | |
| "iifname != {", ifNames, `}`, | |
| `counter drop comment "SUBNET DROP EXTERNAL"`, | |
| }, | |
| }) | |
| } |
๐ค Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@buildroot-external/patches/docker-engine/0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch`
around lines 305 - 321, The nftables branch currently only checks
conf.Prefix.IsValid() && !n.fw.config.AllowDirectRouting, but must also skip
adding rules when the gateway mode is nat-unprotected or routed; update the
condition guarding the nftables.Rule creation to also require that
n.config.Unprotected is false and n.config.Routed is false (i.e., only proceed
when conf.Prefix.IsValid() && !n.fw.config.AllowDirectRouting &&
!n.config.Unprotected && !n.config.Routed) so the behavior matches the iptables
implementation; keep the same use of table.Family(), rawPreroutingChain and
initialRuleGroup when creating the rule.
This adds two patches with fixes/improvements for the Docker engine - `0001-daemon-respect-explicit-AppArmor-profile-on-privileg.patch`: Makes sure that AppArmor rules are always loaded, also on reboot. This is a long standing bug in Docker and affects Supervisor which is a privileged container with an AppArmor profile. Upstream PR: moby/moby#52215 - `0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch`: Makes sure that the whole network (including gateway IP) of any Docker bridge network in NAT mode is firewalled from access from the outside. This essentially implements on Docker level what Supervisor applies on startup with home-assistant/supervisor#6650. Upstream PR: moby/moby#52224. (cherry picked from commit 50c1efd)
This adds two patches with fixes/improvements for the Docker engine
0001-daemon-respect-explicit-AppArmor-profile-on-privileg.patch: Makes sure that AppArmor rules are always loaded, also on reboot. This is a long standing bug in Docker and affects Supervisor which is a privileged container with an AppArmor profile. Upstream PR: daemon: respect explicit AppArmor profile on privileged containersย moby/moby#522150002-bridge-protect-bridge-subnet-from-direct-external-ac.patch: Makes sure that the whole network (including gateway IP) of any Docker bridge network in NAT mode is firewalled from access from the outside. This essentially implements on Docker level what Supervisor applies on startup with Add firewall rules to protect Docker gateway from external accessย supervisor#6650. Upstream PR: bridge: protect bridge subnet from direct external access in raw PREROUTINGย moby/moby#52224.Summary by CodeRabbit
Release Notes
New Features
Bug Fixes