Skip to content

Commit 2e3ae14

Browse files
authored
Skip docker bridge iptables rules for introspection blocking when no bridge found (#4785)
1 parent 86eb32c commit 2e3ae14

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

ecs-init/docker/docker.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package docker
1616
import (
1717
"bytes"
1818
"encoding/json"
19-
"fmt"
19+
"errors"
2020
"io"
2121
"os"
2222
"os/exec"
@@ -165,6 +165,9 @@ var (
165165
execCommand = exec.Command
166166
execLookPath = exec.LookPath
167167
checkNvidiaGPUDevicesPresence = nvidiaGPUDevicesPresent
168+
// ErrNoBridgeNetwork indicates no docker bridge network interface was found
169+
ErrNoBridgeNetwork = errors.New(
170+
"unable to find any virtual docker bridge network interfaces on the host")
168171
)
169172

170173
// client enables business logic for running the Agent inside Docker
@@ -694,5 +697,5 @@ func (c *client) FindDefaultBridgeNetworkInterfaceName() (string, error) {
694697
}
695698
}
696699
}
697-
return "", fmt.Errorf("unable to find any virtual docker bridge network interfaces on the host")
700+
return "", ErrNoBridgeNetwork
698701
}

ecs-init/engine/engine.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ func New() (*Engine, error) {
100100
if err != nil {
101101
return nil, err
102102
}
103-
docker, err := getDockerClient()
103+
dockerClient, err := getDockerClient()
104104
if err != nil {
105105
return nil, err
106106
}
107-
dockerBridgeNetworkName, err := docker.FindDefaultBridgeNetworkInterfaceName()
107+
dockerBridgeNetworkName, err := dockerClient.FindDefaultBridgeNetworkInterfaceName()
108108
if err != nil {
109-
return nil, err
109+
if errors.Is(err, docker.ErrNoBridgeNetwork) {
110+
log.Info("No docker bridge network found, skipping bridge-specific iptables rules")
111+
dockerBridgeNetworkName = ""
112+
} else {
113+
return nil, err
114+
}
110115
}
111116
credentialsProxyRoute, err := iptables.NewNetfilterRoute(cmdExec, netlinkwrapper.New(), dockerBridgeNetworkName)
112117
if err != nil {

ecs-init/exec/iptables/iptables.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,15 @@ func (route *NetfilterRoute) Create() error {
118118

119119
// Allow docker's virtual bridge interface to access the introspection server. Inserting it after applying
120120
// the rule to drop all connections other than loopback interface will push it on top of priority.
121-
err = route.modifyNetfilterEntry(iptablesTableFilter, iptablesInsert, allowIntrospectionForDockerIptablesInputChainArgs, true)
122-
if err != nil {
123-
log.Errorf("Error adding input chain entry to allow %s access to introspection server: %w", err)
124-
return err
121+
if defaultDockerBridgeNetworkName != "" {
122+
err = route.modifyNetfilterEntry(iptablesTableFilter, iptablesInsert,
123+
allowIntrospectionForDockerIptablesInputChainArgs, true)
124+
if err != nil {
125+
log.Errorf(
126+
"Error adding input chain entry to allow %s access to introspection server: %w",
127+
err)
128+
return err
129+
}
125130
}
126131
}
127132

@@ -150,9 +155,13 @@ func (route *NetfilterRoute) Remove() error {
150155
introspectionInputError = fmt.Errorf("error removing input chain entry: %v", introspectionInputError)
151156
}
152157

153-
dockerIntrospectionInputError = route.modifyNetfilterEntry(iptablesTableFilter, iptablesDelete, allowIntrospectionForDockerIptablesInputChainArgs, true)
154-
if dockerIntrospectionInputError != nil {
155-
dockerIntrospectionInputError = fmt.Errorf("error removing input chain entry: %v", dockerIntrospectionInputError)
158+
if defaultDockerBridgeNetworkName != "" {
159+
dockerIntrospectionInputError = route.modifyNetfilterEntry(iptablesTableFilter,
160+
iptablesDelete, allowIntrospectionForDockerIptablesInputChainArgs, true)
161+
if dockerIntrospectionInputError != nil {
162+
dockerIntrospectionInputError = fmt.Errorf(
163+
"error removing input chain entry: %v", dockerIntrospectionInputError)
164+
}
156165
}
157166

158167
outputErr := route.modifyNetfilterEntry(iptablesTableNat, iptablesDelete, getOutputChainArgs, false)

0 commit comments

Comments
 (0)