Skip to content

Commit b757a31

Browse files
author
Ben Lucas
authored
feat(policies): add minimum_engine_version argument to macro and falco rule resources (#366)
* initial changes to introduce argument for to falco_rule and macro resources * add minimum_engine_version output to data source for falco rule * update documentation for new argument
1 parent edc0967 commit b757a31

9 files changed

+92
-14
lines changed

sysdig/data_source_sysdig_secure_rule_falco.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func dataSourceSysdigSecureRuleFalco() *schema.Resource {
4242
Type: schema.TypeString,
4343
Computed: true,
4444
},
45+
"minimum_engine_version": {
46+
Type: schema.TypeInt,
47+
Computed: true,
48+
Optional: true,
49+
},
4550
"append": {
4651

4752
Type: schema.TypeBool,
@@ -108,6 +113,9 @@ func dataSourceSysdigRuleFalcoRead(ctx context.Context, d *schema.ResourceData,
108113
_ = d.Set("output", rule.Details.Output)
109114
_ = d.Set("priority", rule.Details.Priority)
110115
_ = d.Set("source", rule.Details.Source)
116+
if rule.Details.MinimumEngineVersion != nil {
117+
_ = d.Set("minimum_engine_version", *rule.Details.MinimumEngineVersion)
118+
}
111119
if rule.Details.Append != nil {
112120
_ = d.Set("append", *rule.Details.Append)
113121
}

sysdig/internal/client/v2/model.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,12 @@ type Items struct {
228228
}
229229

230230
type Macro struct {
231-
ID int `json:"id,omitempty"`
232-
Version int `json:"version,omitempty"`
233-
Name string `json:"name"`
234-
Condition MacroCondition `json:"condition"`
235-
Append bool `json:"append"`
231+
ID int `json:"id,omitempty"`
232+
Version int `json:"version,omitempty"`
233+
Name string `json:"name"`
234+
Condition MacroCondition `json:"condition"`
235+
Append bool `json:"append"`
236+
MinimumEngineVersion *int `json:"minimumEngineVersion,omitempty"`
236237
}
237238

238239
type MacroCondition struct {
@@ -294,12 +295,13 @@ type Details struct {
294295
Syscalls *Syscalls `json:"syscalls,omitempty"`
295296

296297
// Falco
297-
Append *bool `json:"append,omitempty"`
298-
Source string `json:"source,omitempty"`
299-
Output string `json:"output,omitempty"`
300-
Condition *Condition `json:"condition,omitempty"`
301-
Priority string `json:"priority,omitempty"`
302-
Exceptions []*Exception `json:"exceptions,omitempty"`
298+
Append *bool `json:"append,omitempty"`
299+
Source string `json:"source,omitempty"`
300+
Output string `json:"output,omitempty"`
301+
Condition *Condition `json:"condition,omitempty"`
302+
Priority string `json:"priority,omitempty"`
303+
Exceptions []*Exception `json:"exceptions,omitempty"`
304+
MinimumEngineVersion *int `json:"minimumEngineVersion,omitempty"`
303305

304306
RuleType string `json:"ruleType"`
305307
}

sysdig/resource_sysdig_secure_macro.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package sysdig
22

33
import (
44
"context"
5-
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
65
"strconv"
76
"time"
87

8+
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
9+
910
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1112
)
@@ -44,6 +45,10 @@ func resourceSysdigSecureMacro() *schema.Resource {
4445
Type: schema.TypeString,
4546
Required: true,
4647
},
48+
"minimum_engine_version": {
49+
Type: schema.TypeInt,
50+
Optional: true,
51+
},
4752
"version": {
4853
Type: schema.TypeInt,
4954
Computed: true,
@@ -110,6 +115,9 @@ func resourceSysdigMacroRead(ctx context.Context, d *schema.ResourceData, meta i
110115
_ = d.Set("version", macro.Version)
111116
_ = d.Set("condition", macro.Condition.Condition)
112117
_ = d.Set("append", macro.Append)
118+
if macro.MinimumEngineVersion != nil {
119+
_ = d.Set("minimum_engine_version", *macro.MinimumEngineVersion)
120+
}
113121

114122
return nil
115123
}
@@ -130,9 +138,15 @@ func resourceSysdigMacroDelete(ctx context.Context, d *schema.ResourceData, meta
130138
}
131139

132140
func macroFromResourceData(d *schema.ResourceData) v2.Macro {
133-
return v2.Macro{
141+
macro := v2.Macro{
134142
Name: d.Get("name").(string),
135143
Append: d.Get("append").(bool),
136144
Condition: v2.MacroCondition{Condition: d.Get("condition").(string)},
137145
}
146+
minimumEngineVersionInterface, ok := d.GetOk("minimum_engine_version")
147+
if ok {
148+
minimumEngineVersion := minimumEngineVersionInterface.(int)
149+
macro.MinimumEngineVersion = &minimumEngineVersion
150+
}
151+
return macro
138152
}

sysdig/resource_sysdig_secure_macro_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func TestAccMacro(t *testing.T) {
4848
{
4949
Config: macroWithMacroAndList(rText(), rText(), rText()),
5050
},
51+
{
52+
Config: macroWithMinimumEngineVersion(rText()),
53+
},
5154
},
5255
})
5356
}
@@ -109,3 +112,13 @@ resource "sysdig_secure_macro" "sample6" {
109112
}
110113
`, listWithName(name3), name1, name2)
111114
}
115+
116+
func macroWithMinimumEngineVersion(name string) string {
117+
return fmt.Sprintf(`
118+
resource "sysdig_secure_macro" "sample" {
119+
minimum_engine_version = 13
120+
name = "terraform_test_%s"
121+
condition = "always_true"
122+
}
123+
`, name)
124+
}

sysdig/resource_sysdig_secure_rule_falco.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func resourceSysdigSecureRuleFalco() *schema.Resource {
6060
Default: "",
6161
ValidateDiagFunc: validateDiagFunc(validateFalcoRuleSource),
6262
},
63+
"minimum_engine_version": {
64+
Type: schema.TypeInt,
65+
Optional: true,
66+
},
6367
"append": {
6468
Type: schema.TypeBool,
6569
Optional: true,
@@ -147,6 +151,9 @@ func resourceSysdigRuleFalcoRead(ctx context.Context, d *schema.ResourceData, me
147151
_ = d.Set("output", rule.Details.Output)
148152
_ = d.Set("priority", strings.ToLower(rule.Details.Priority))
149153
_ = d.Set("source", rule.Details.Source)
154+
if rule.Details.MinimumEngineVersion != nil {
155+
_ = d.Set("minimum_engine_version", *rule.Details.MinimumEngineVersion)
156+
}
150157
if rule.Details.Append != nil {
151158
_ = d.Set("append", *rule.Details.Append)
152159
}
@@ -272,6 +279,12 @@ func resourceSysdigRuleFalcoFromResourceData(d *schema.ResourceData) (v2.Rule, e
272279
return v2.Rule{}, errors.New("priority must be set when append = false")
273280
}
274281

282+
minimumEngineVersionInterface, ok := d.GetOk("minimum_engine_version")
283+
if ok {
284+
minimumEngineVersion := minimumEngineVersionInterface.(int)
285+
rule.Details.MinimumEngineVersion = &minimumEngineVersion
286+
}
287+
275288
rule.Details.Condition = &v2.Condition{
276289
Condition: d.Get("condition").(string),
277290
Components: []interface{}{},

sysdig/resource_sysdig_secure_rule_falco_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func TestAccRuleFalco(t *testing.T) {
3939
{
4040
Config: ruleFalcoUpdatedTerminalShell(ruleRandomImmutableText),
4141
},
42+
{
43+
Config: ruleFalcoTerminalShellWithMinimumEngineVersion(rText()),
44+
},
4245
{
4346
ResourceName: "sysdig_secure_rule_falco.terminal_shell",
4447
ImportState: true,
@@ -254,3 +257,18 @@ resource "sysdig_secure_rule_falco" "attach_to_cluster_admin_role_exceptions" {
254257
}
255258
}`
256259
}
260+
261+
func ruleFalcoTerminalShellWithMinimumEngineVersion(name string) string {
262+
return fmt.Sprintf(`
263+
resource "sysdig_secure_rule_falco" "terminal_shell" {
264+
name = "TERRAFORM TEST %s - Terminal Shell"
265+
minimum_engine_version = 13
266+
description = "TERRAFORM TEST %s"
267+
tags = ["container", "shell", "mitre_execution"]
268+
269+
condition = "spawned_process and container and shell_procs and proc.tty != 0 and container_entrypoint"
270+
output = "A shell was spawned in a container with an attached terminal (user=%%user.name %%container.info shell=%%proc.name parent=%%proc.pname cmdline=%%proc.cmdline terminal=%%proc.tty container_id=%%container.id image=%%container.image.repository)"
271+
priority = "notice"
272+
source = "syscall" // syscall or k8s_audit
273+
}`, name, name)
274+
}

website/docs/d/secure_rule_falco.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ In addition to the argument above, the following attributes are exported:
4040
* `priority` - The priority of the Falco rule. It can be: "emergency", "alert", "critical", "error", "warning", "notice", "info" or "debug". By default is "warning".
4141
* `exceptions` - The exceptions key is a list of identifier plus list of tuples of filtercheck fields. See below for details.
4242
* `append` - This indicates that the rule being created appends the condition to an existing Sysdig-provided rule
43+
* `minimum_engine_version` - This is used to indicate that the rule requires a minimum engine version.
4344
* `version` - Current version of the resource in Sysdig Secure.
4445

4546
### Exceptions

website/docs/r/secure_macro.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ resource "sysdig_secure_macro" "https_port" {
3737
The macros can only be extended once, for example if there is an existing macro called "foo", one can have another
3838
append macro called "foo" but not a second one. By default this is false.
3939

40+
* `minimum_engine_version` - (Optional) This is used to indicate that the macro requires a minimum engine version. This
41+
can allow you to add macros that would not normally pass validation with older agents in your environment. The macro
42+
will only be processed by agents that support the minimum_engine_version specified.
43+
44+
4045
## Attributes Reference
4146

4247
No additional attributes are exported.

website/docs/r/secure_rule_falco.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ The following arguments are supported:
6666
* `priority` - (Optional) The priority of the Falco rule. It can be: "emergency", "alert", "critical", "error", "warning", "notice", "info" or "debug". By default is "warning".
6767
* `source` - (Optional) The source of the event. It can be either "syscall", "k8s_audit", "aws_cloudtrail", "gcp_auditlog", or "azure_platformlogs". Required if append is false.
6868
* `exceptions` - (Optional) The exceptions key is a list of identifier plus list of tuples of filtercheck fields. See below for details.
69-
* `append` - (Optional) This indicates that the rule being created appends the condition to an existing Sysdig-provided rule. By default this is false. Appending to user-created rules is not supported by the API.
69+
* `append` - (Optional) This indicates that the rule being created appends the condition to an existing Sysdig-provided
70+
rule. By default this is false. Appending to user-created rules is not supported by the API.
71+
* `minimum_engine_version` - (Optional) This is used to indicate that the rule requires a minimum engine version. This
72+
can allow you to add rules that would not normally pass validation with older agents in your environment. The rule
73+
will only be processed by agents that support the minimum_engine_version specified.
7074

7175
### Exceptions
7276

0 commit comments

Comments
 (0)