Skip to content

Add patches with fixes for Docker engine - #4605

Merged
sairon merged 1 commit into
devfrom
add-docker-engine-patches
Mar 30, 2026
Merged

sairon merged 1 commit into
devfrom
add-docker-engine-patches

Conversation

@agners

@agners agners commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

This adds two patches with fixes/improvements for the Docker engine

Summary by CodeRabbit

Release Notes

  • New Features

    • Added subnet protection for bridge networks to block unauthorized direct external access to configured bridge subnets.
  • Bug Fixes

    • Fixed AppArmor profile settings being unconditionally overwritten on privileged containers; user-specified profiles are now preserved.

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.
@agners agners added this to the 17.2 milestone Mar 25, 2026
@agners
agners requested a review from sairon March 25, 2026 14:53
@coderabbitai

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
๐Ÿ“ Walkthrough

Walkthrough

These 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

Cohort / File(s) Summary
AppArmor Profile Handling
buildroot-external/patches/docker-engine/0001-daemon-respect-explicit-AppArmor-profile-on-privileg.patch
Updated saveAppArmorConfig to only apply default AppArmor profiles (unconfined for privileged, defaultAppArmorProfile otherwise) when container.AppArmorProfile is empty, preserving user-specified profiles set via --security-opt apparmor=<profile>.
Bridge Subnet Protection
buildroot-external/patches/docker-engine/0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch
Implemented network-scoped subnet protection rules in raw PREROUTING chain (iptables and nftables) to block direct external access to bridge subnets. Migrated from per-endpoint filtering to network-level configuration during initialization; modified endpoint methods to no-op for direct-access filtering and added setSubnetProtection function with conditional rule toggling based on gateway mode and configuration.

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~20 minutes

Poem

๐Ÿฐ A rabbit hops through networks so bright,
Where profiles stay safe and subnets stay right,
No more do the rules chase endpoints about,
For networks now guard from the outside and out! ๐ŸŒโœจ

๐Ÿšฅ Pre-merge checks | โœ… 2 | โŒ 1

โŒ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check โ“ Inconclusive The title 'Add patches with fixes for Docker engine' is vague and generic, using non-descriptive language that doesn't convey meaningful information about which specific issues are being addressed. Consider a more specific title like 'Add Docker engine patches for AppArmor and subnet protection' that better describes the two distinct fixes being introduced.
โœ… Passed checks (2 passed)
Check name Status Explanation
Description Check โœ… Passed Check skipped - CodeRabbitโ€™s high-level summary is enabled.
Docstring Coverage โœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

โœ๏ธ Tip: You can configure your own custom pre-merge checks in the settings.

โœจ Finishing Touches
๐Ÿงช Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-docker-engine-patches

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.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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: Missing Internal network check compared to previous implementation.

The old per-endpoint filterDirectAccess checked n.config.Internal and skipped filtering for internal networks. The new setSubnetProtection omits 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

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between a64767b and 94c919c.

๐Ÿ“’ Files selected for processing (2)
  • buildroot-external/patches/docker-engine/0001-daemon-respect-explicit-AppArmor-profile-on-privileg.patch
  • buildroot-external/patches/docker-engine/0002-bridge-protect-bridge-subnet-from-direct-external-ac.patch

Comment on lines +305 to +321
+ // 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"`,
+ },
+ })
+ }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

โš ๏ธ Potential issue | ๐Ÿ”ด Critical

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:

  1. nftables will add subnet protection rules even for nat-unprotected gateway mode
  2. nftables will add subnet protection rules even for routed gateway 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.

Suggested change
+ // 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.

@sairon sairon added the os label Mar 30, 2026
@sairon
sairon merged commit 50c1efd into dev Mar 30, 2026
1 check passed
@sairon
sairon deleted the add-docker-engine-patches branch March 30, 2026 09:25
sairon pushed a commit that referenced this pull request Mar 31, 2026
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)
@sairon sairon mentioned this pull request Mar 31, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants