Skip to content

Commit 5949ebe

Browse files
authored
feat: Add support for appending rules (#53)
1 parent f75093c commit 5949ebe

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

sysdig/resource_sysdig_secure_rule_falco.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func resourceSysdigSecureRuleFalco() *schema.Resource {
4545
Required: true,
4646
ValidateFunc: validation.StringInSlice([]string{"syscall", "k8s_audit"}, false),
4747
},
48+
"append": {
49+
Type: schema.TypeBool,
50+
Optional: true,
51+
Default: false,
52+
},
4853
}),
4954
}
5055
}
@@ -95,6 +100,9 @@ func resourceSysdigRuleFalcoRead(ctx context.Context, d *schema.ResourceData, me
95100
d.Set("output", rule.Details.Output)
96101
d.Set("priority", strings.ToLower(rule.Details.Priority))
97102
d.Set("source", rule.Details.Source)
103+
if rule.Details.Append != nil {
104+
d.Set("append", *rule.Details.Append)
105+
}
98106

99107
return nil
100108
}
@@ -140,7 +148,6 @@ func resourceSysdigRuleFalcoFromResourceData(d *schema.ResourceData) secure.Rule
140148
rule := ruleFromResourceData(d)
141149
rule.Details.RuleType = "FALCO"
142150

143-
rule.Details.Append = false
144151
rule.Details.Source = d.Get("source").(string)
145152
rule.Details.Output = d.Get("output").(string)
146153
rule.Details.Priority = d.Get("priority").(string)
@@ -149,5 +156,10 @@ func resourceSysdigRuleFalcoFromResourceData(d *schema.ResourceData) secure.Rule
149156
Components: []interface{}{},
150157
}
151158

159+
if appendMode, ok := d.GetOk("append"); ok {
160+
ptr := appendMode.(bool)
161+
rule.Details.Append = &ptr
162+
}
163+
152164
return rule
153165
}

sysdig/resource_sysdig_secure_rule_falco_test.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package sysdig_test
22

33
import (
44
"fmt"
5-
"github.com/draios/terraform-provider-sysdig/sysdig"
5+
"os"
6+
"testing"
7+
68
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9-
"os"
10-
"testing"
11+
12+
"github.com/draios/terraform-provider-sysdig/sysdig"
1113
)
1214

1315
func TestAccRuleFalco(t *testing.T) {
@@ -33,6 +35,9 @@ func TestAccRuleFalco(t *testing.T) {
3335
{
3436
Config: ruleFalcoUpdatedTerminalShell(ruleRandomImmutableText),
3537
},
38+
{
39+
Config: ruleFalcoTerminalShellWithAppend(),
40+
},
3641
{
3742
Config: ruleFalcoKubeAudit(rText()),
3843
},
@@ -81,3 +86,18 @@ resource "sysdig_secure_rule_falco" "kube_audit" {
8186
source = "k8s_audit" // syscall or k8s_audit
8287
}`, name, name)
8388
}
89+
90+
func ruleFalcoTerminalShellWithAppend() string {
91+
return fmt.Sprintf(`
92+
resource "sysdig_secure_rule_falco" "terminal_shell_append" {
93+
name = "Terminal shell in container" # Sysdig-provided
94+
description = ""
95+
tags = ["shell", "mitre_execution"]
96+
97+
condition = "and spawned_process and shell_procs and proc.tty != 0 and container_entrypoint"
98+
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)"
99+
priority = "notice"
100+
source = "syscall" // syscall or k8s_audit
101+
append = true
102+
}`)
103+
}

sysdig/secure/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ type Details struct {
148148
Syscalls *Syscalls `json:"syscalls,omitempty"`
149149

150150
// Falco
151-
Append bool `json:"append,omitempty"`
151+
Append *bool `json:"append,omitempty"`
152152
Source string `json:"source,omitempty"`
153153
Output string `json:"output,omitempty"`
154154
Condition *Condition `json:"condition,omitempty"`

website/docs/r/sysdig_secure_rule_falco.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The following arguments are supported:
4444
* `output` - (Required) Add additional information to each Falco notification's output.
4545
* `priority` - (Required) The priority of the Falco rule. It can be: "emergency", "alert", "critical", "error", "warning", "notice", "informational", "informational" or "debug".
4646
* `source` - (Required) The source of the event. It can be either "syscall" or "k8s_audit".
47+
* `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.
4748

4849
## Attributes Reference
4950

0 commit comments

Comments
 (0)