Skip to content

Commit 22ee2aa

Browse files
author
Ben Lucas
authored
fix(secure-policy): Add support for name/value exceptions (#239)
* add support for exceptions without fields and comps * update documentation * switch fields to optional in documentation
1 parent ab1ca09 commit 22ee2aa

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

sysdig/internal/client/secure/models.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ type Condition struct {
202202

203203
type Exception struct {
204204
Name string `json:"name"`
205-
Fields interface{} `json:"fields"`
206-
Comps interface{} `json:"comps"`
205+
Fields interface{} `json:"fields,omitempty"`
206+
Comps interface{} `json:"comps,omitempty"`
207207
Values interface{} `json:"values,omitempty"`
208+
Value interface{} `json:"value,omitempty"`
208209
}
209210

210211
func (r *Rule) ToJSON() io.Reader {

sysdig/resource_sysdig_secure_rule_falco.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ func resourceSysdigSecureRuleFalco() *schema.Resource {
7979
},
8080
"values": {
8181
Type: schema.TypeString,
82-
Required: true,
82+
Optional: true,
83+
},
84+
"value": {
85+
Type: schema.TypeString,
86+
Optional: true,
8387
},
8488
"fields": {
8589
Type: schema.TypeList,
86-
Required: true,
90+
Optional: true,
8791
Elem: &schema.Schema{Type: schema.TypeString},
8892
},
8993
},
@@ -283,20 +287,31 @@ func resourceSysdigRuleFalcoFromResourceData(d *schema.ResourceData) (secure.Rul
283287
Name: exceptionMap["name"].(string),
284288
}
285289

290+
fields := cast.ToStringSlice(exceptionMap["fields"])
291+
if len(fields) >= 1 {
292+
newFalcoException.Fields = fields
293+
}
294+
286295
comps := cast.ToStringSlice(exceptionMap["comps"])
287296
if len(comps) >= 1 {
288297
newFalcoException.Comps = comps
289298
}
290299

291300
values := cast.ToString(exceptionMap["values"])
292-
err := json.Unmarshal([]byte(values), &newFalcoException.Values)
293-
if err != nil {
294-
return secure.Rule{}, err
301+
if values != "" {
302+
err := json.Unmarshal([]byte(values), &newFalcoException.Values)
303+
if err != nil {
304+
return secure.Rule{}, err
305+
}
306+
} else if newFalcoException.Fields != nil && newFalcoException.Comps != nil {
307+
return secure.Rule{}, errors.New("values is required on an exception when fields and comps are set")
295308
}
296309

297-
fields := cast.ToStringSlice(exceptionMap["fields"])
298-
if len(fields) >= 1 {
299-
newFalcoException.Fields = fields
310+
value := cast.ToString(exceptionMap["value"])
311+
newFalcoException.Value = value
312+
313+
if newFalcoException.Fields == nil && newFalcoException.Comps == nil && value == "" {
314+
return secure.Rule{}, errors.New("value is required on an exception when fields and comps are not set")
300315
}
301316

302317
falcoExceptions = append(falcoExceptions, newFalcoException)

website/docs/r/secure_rule_falco.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ resource "sysdig_secure_rule_falco" "example" {
5151
[["java"], "sdjagent.jar"]
5252
])
5353
}
54+
55+
exceptions {
56+
name = "image_suffix"
57+
value = "secure-inline-scan" # Example of an exception with just a name/value pair
58+
}
5459
}
5560
```
5661

@@ -76,9 +81,14 @@ For more information about the syntax of the exceptions, check the [official Fal
7681
Supported fields for exceptions:
7782

7883
* `name` - (Required) The name of the exception. Only used to provide a handy name, and to potentially link together values in a later rule that has `append = true`.
79-
* `fields` - (Required) Contains one or more fields that will extract a value from the syscall/k8s_audit events.
84+
* `fields` - (Optional) Contains one or more fields that will extract a value from the syscall/k8s_audit events.
8085
* `comps` - (Optional) Contains comparison operators that align 1-1 with the items in the fields property.
81-
* `values` - (Required) Contains tuples of values. Each item in the tuple should align 1-1 with the corresponding field and comparison operator. Since the value can be a string, a list of strings or a list of a list of strings, the value of this field must be supplied in JSON format. You can use the default `jsonencode` function to provide this value. See the usage example on the top.
86+
* `values` - (Optional) Contains tuples of values. Each item in the tuple should align 1-1 with the corresponding field
87+
and comparison operator. Since the value can be a string, a list of strings or a list of a list of strings, the value
88+
of this field must be supplied in JSON format. You can use the default `jsonencode` function to provide this value.
89+
See the usage example on the top. **Required** if `fields` and `comps` are set.
90+
* `value` - (Optional) Contains the single value used when exception is a name/value pair. **Required** if `fields` and
91+
`comps` are not set
8292

8393
## Attributes Reference
8494

0 commit comments

Comments
 (0)