Skip to content

Commit 55fc068

Browse files
authored
Negate block_inbound and block_outbound tags for network rules (#385)
* SSPROD-27032 Negate block_inboud and block_outbound tags * SSPROD-27032 Forbid omissions of block_inbound and block_outbound * Add unit test for network rule allowing all traffic
1 parent 5173630 commit 55fc068

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

sysdig/data_source_sysdig_secure_rule_network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ func dataSourceSysdigRuleNetworkRead(ctx context.Context, d *schema.ResourceData
7676
}
7777

7878
func networkRuleDataSourceToResourceData(rule v2.Rule, d *schema.ResourceData) diag.Diagnostics {
79-
_ = d.Set("block_inbound", rule.Details.AllInbound)
80-
_ = d.Set("block_outbound", rule.Details.AllOutbound)
79+
_ = d.Set("block_inbound", !rule.Details.AllInbound)
80+
_ = d.Set("block_outbound", !rule.Details.AllOutbound)
8181

8282
if rule.Details.TCPListenPorts == nil {
8383
return diag.Errorf("no tcpListenPorts for a network rule")

sysdig/internal/client/v2/model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ type Details struct {
296296
ReadPaths *ReadPaths `json:"readPaths,omitempty"`
297297

298298
// Network
299-
AllOutbound bool `json:"allOutbound,omitempty"`
300-
AllInbound bool `json:"allInbound,omitempty"`
299+
AllOutbound bool `json:"allOutbound"`
300+
AllInbound bool `json:"allInbound"`
301301
TCPListenPorts *TCPListenPorts `json:"tcpListenPorts,omitempty"`
302302
UDPListenPorts *UDPListenPorts `json:"udpListenPorts,omitempty"`
303303

sysdig/resource_sysdig_secure_rule_network.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ func resourceSysdigRuleNetworkRead(ctx context.Context, d *schema.ResourceData,
125125
}
126126
updateResourceDataForRule(d, rule)
127127

128-
_ = d.Set("block_inbound", rule.Details.AllInbound)
129-
_ = d.Set("block_outbound", rule.Details.AllOutbound)
128+
_ = d.Set("block_inbound", !rule.Details.AllInbound)
129+
_ = d.Set("block_outbound", !rule.Details.AllOutbound)
130130

131131
if rule.Details.TCPListenPorts == nil {
132132
return diag.Errorf("no tcpListenPorts for a filesystem rule")
@@ -216,8 +216,8 @@ func resourceSysdigRuleNetworkFromResourceData(d *schema.ResourceData) (rule v2.
216216
rule.Details.TCPListenPorts = &v2.TCPListenPorts{}
217217
rule.Details.UDPListenPorts = &v2.UDPListenPorts{}
218218

219-
rule.Details.AllInbound = d.Get("block_inbound").(bool)
220-
rule.Details.AllOutbound = d.Get("block_outbound").(bool)
219+
rule.Details.AllInbound = !d.Get("block_inbound").(bool)
220+
rule.Details.AllOutbound = !d.Get("block_outbound").(bool)
221221

222222
rule.Details.TCPListenPorts.Items = []string{}
223223
if tcpRules := d.Get("tcp").([]interface{}); len(tcpRules) > 0 {

sysdig/resource_sysdig_secure_rule_network_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func TestAccRuleNetwork(t *testing.T) {
4141
{
4242
Config: ruleNetworkWithUDP(rText()),
4343
},
44+
{
45+
Config: ruleNetworkAllowingAllTraffic(rText()),
46+
},
4447
{
4548
ResourceName: "sysdig_secure_rule_network.foo",
4649
ImportState: true,
@@ -75,6 +78,28 @@ resource "sysdig_secure_rule_network" "foo" {
7578
}`, name, name)
7679
}
7780

81+
func ruleNetworkAllowingAllTraffic(name string) string {
82+
return fmt.Sprintf(`
83+
resource "sysdig_secure_rule_network" "foo" {
84+
name = "TERRAFORM TEST %s" // ID
85+
description = "TERRAFORM TEST %s"
86+
tags = ["network", "cis"]
87+
88+
block_inbound = false
89+
block_outbound = false
90+
91+
tcp {
92+
matching = true // default
93+
ports = [80, 443]
94+
}
95+
96+
udp {
97+
matching = true // default
98+
ports = [80, 443]
99+
}
100+
}`, name, name)
101+
}
102+
78103
func ruleNetworkWithoutTags(name string) string {
79104
return fmt.Sprintf(`
80105
resource "sysdig_secure_rule_network" "foo" {

0 commit comments

Comments
 (0)