Skip to content

Commit b4c4077

Browse files
amogh09timj-hh
authored andcommitted
Require ip6tables for fault injection capabilty on IPv6-only instances (aws#4675)
1 parent bcb0b7a commit b4c4077

6 files changed

+31
-12
lines changed

agent/app/agent_capability.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func (agent *ecsAgent) appendFaultInjectionCapabilities(capabilities []types.Att
551551
return capabilities
552552
}
553553

554-
if isFaultInjectionToolingAvailable() {
554+
if isFaultInjectionToolingAvailable(agent.cfg) {
555555
capabilities = appendNameOnlyAttribute(capabilities, attributePrefix+capabilityFaultInjection)
556556
seelog.Debug("Fault injection capability is enabled.")
557557
} else {

agent/app/agent_capability_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ func TestAppendFaultInjectionCapabilities(t *testing.T) {
15641564
defer func() { isFaultInjectionToolingAvailable = originalIsFaultInjectionToolingAvailable }()
15651565
t.Run("Fault Injection Capability Available", func(t *testing.T) {
15661566
// Test case where required tooling is available
1567-
isFaultInjectionToolingAvailable = func() bool { return true }
1567+
isFaultInjectionToolingAvailable = func(cfg *config.Config) bool { return true }
15681568
capabilities := []types.Attribute{}
15691569
agent := &ecsAgent{
15701570
cfg: &config.Config{},
@@ -1576,7 +1576,7 @@ func TestAppendFaultInjectionCapabilities(t *testing.T) {
15761576
})
15771577
t.Run("Fault Injection Capability Not Available", func(t *testing.T) {
15781578
// Test case where required tooling is not available
1579-
isFaultInjectionToolingAvailable = func() bool { return false }
1579+
isFaultInjectionToolingAvailable = func(cfg *config.Config) bool { return false }
15801580
capabilities := []types.Attribute{}
15811581
agent := &ecsAgent{
15821582
cfg: &config.Config{},
@@ -1588,7 +1588,7 @@ func TestAppendFaultInjectionCapabilities(t *testing.T) {
15881588

15891589
t.Run("Fault Injection Capability Not Available for EXTERNAL Launch Type", func(t *testing.T) {
15901590
// Test case where required tooling is available but EXTERNAL Launch Type
1591-
isFaultInjectionToolingAvailable = func() bool { return true }
1591+
isFaultInjectionToolingAvailable = func(cfg *config.Config) bool { return true }
15921592
capabilities := []types.Attribute{}
15931593
agent := &ecsAgent{
15941594
cfg: &config.Config{

agent/app/agent_capability_unix.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,13 @@ var networkConfigClient = netconfig.NewNetworkConfigClient()
258258

259259
// checkFaultInjectionTooling checks for the required network packages like iptables, tc
260260
// to be available on the host before ecs.capability.fault-injection can be advertised
261-
func checkFaultInjectionTooling() bool {
261+
func checkFaultInjectionTooling(cfg *config.Config) bool {
262262
tools := []string{"iptables", "tc", "nsenter"}
263+
if cfg.InstanceIPCompatibility.IsIPv6Only() {
264+
// ip6tables is a required dependency on IPv6-only instances.
265+
// TODO: Consider making ip6tables a required dependency for all instances (need to consider backwards compatibility)
266+
tools = append(tools, "ip6tables")
267+
}
263268
for _, tool := range tools {
264269
if _, err := lookPathFunc(tool); err != nil {
265270
seelog.Warnf(

agent/app/agent_capability_unix_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ func TestCheckFaultInjectionTooling(t *testing.T) {
10411041
)
10421042
osExecWrapper = mockExec
10431043
assert.True(t,
1044-
checkFaultInjectionTooling(),
1044+
checkFaultInjectionTooling(&config.Config{}),
10451045
"Expected checkFaultInjectionTooling to return true when all tools are available")
10461046
})
10471047

@@ -1059,7 +1059,7 @@ func TestCheckFaultInjectionTooling(t *testing.T) {
10591059
)
10601060
osExecWrapper = mockExec
10611061
assert.False(t,
1062-
checkFaultInjectionTooling(),
1062+
checkFaultInjectionTooling(&config.Config{}),
10631063
"Expected checkFaultInjectionTooling to return false when kernel modules are not available")
10641064
})
10651065

@@ -1083,7 +1083,7 @@ func TestCheckFaultInjectionTooling(t *testing.T) {
10831083
)
10841084
osExecWrapper = mockExec
10851085
assert.False(t,
1086-
checkFaultInjectionTooling(),
1086+
checkFaultInjectionTooling(&config.Config{}),
10871087
"Expected checkFaultInjectionTooling to return false when unable to find default host interface name")
10881088
})
10891089

@@ -1112,7 +1112,7 @@ func TestCheckFaultInjectionTooling(t *testing.T) {
11121112
)
11131113
osExecWrapper = mockExec
11141114
assert.False(t,
1115-
checkFaultInjectionTooling(),
1115+
checkFaultInjectionTooling(&config.Config{}),
11161116
"Expected checkFaultInjectionTooling to return false when required tc show command failed")
11171117
})
11181118

@@ -1126,10 +1126,24 @@ func TestCheckFaultInjectionTooling(t *testing.T) {
11261126
return "/usr/bin/" + file, nil
11271127
}
11281128
assert.False(t,
1129-
checkFaultInjectionTooling(),
1129+
checkFaultInjectionTooling(&config.Config{}),
11301130
"Expected checkFaultInjectionTooling to return false when a tool is missing")
11311131
})
11321132
}
1133+
1134+
t.Run("missing ip6tables on IPv6-only instance", func(t *testing.T) {
1135+
lookPathFunc = func(file string) (string, error) {
1136+
if file == "ip6tables" {
1137+
return "", exec.ErrNotFound
1138+
}
1139+
return "/usr/bin/" + file, nil
1140+
}
1141+
assert.False(t,
1142+
checkFaultInjectionTooling(&config.Config{
1143+
InstanceIPCompatibility: ipcompatibility.NewIPv6OnlyCompatibility(),
1144+
}),
1145+
"Expected checkFaultInjectionTooling to return false when ip6tables is missing on IPv6-only instance")
1146+
})
11331147
}
11341148

11351149
func convertToInterfaceList(strings []string) []interface{} {

agent/app/agent_capability_unspecified.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,6 @@ var isFaultInjectionToolingAvailable = checkFaultInjectionTooling
151151

152152
// checkFaultInjectionTooling checks for the required network packages like iptables, tc
153153
// to be available on the host before ecs.capability.fault-injection can be advertised
154-
func checkFaultInjectionTooling() bool {
154+
func checkFaultInjectionTooling(_ *config.Config) bool {
155155
return false
156156
}

agent/app/agent_capability_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ var isFaultInjectionToolingAvailable = checkFaultInjectionTooling
149149

150150
// checkFaultInjectionTooling checks for the required network packages like iptables, tc
151151
// to be available on the host before ecs.capability.fault-injection can be advertised
152-
func checkFaultInjectionTooling() bool {
152+
func checkFaultInjectionTooling(_ *config.Config) bool {
153153
seelog.Warnf("Fault injection tooling is not supported on windows")
154154
return false
155155
}

0 commit comments

Comments
 (0)