Skip to content

Commit b2b9b9a

Browse files
authored
[policies] manage mounted volume toggle in drift policies (#602)
* manage mounted volume toggle in drift policies * update docs
1 parent 1f84b46 commit b2b9b9a

File tree

6 files changed

+66
-27
lines changed

6 files changed

+66
-27
lines changed

sysdig/data_source_sysdig_secure_drift_policy.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ func createDriftPolicyDataSourceSchema() map[string]*schema.Schema {
4747
Computed: true,
4848
Elem: &schema.Resource{
4949
Schema: map[string]*schema.Schema{
50-
"id": ReadOnlyIntSchema(),
51-
"name": ReadOnlyStringSchema(),
52-
"description": DescriptionComputedSchema(),
53-
"tags": TagsSchema(),
54-
"version": VersionSchema(),
55-
"enabled": BoolComputedSchema(),
56-
"exceptions": ExceptionsComputedSchema(),
57-
"prohibited_binaries": ExceptionsComputedSchema(),
50+
"id": ReadOnlyIntSchema(),
51+
"name": ReadOnlyStringSchema(),
52+
"description": DescriptionComputedSchema(),
53+
"tags": TagsSchema(),
54+
"version": VersionSchema(),
55+
"enabled": BoolComputedSchema(),
56+
"exceptions": ExceptionsComputedSchema(),
57+
"prohibited_binaries": ExceptionsComputedSchema(),
58+
"mounted_volume_drift_enabled": BoolComputedSchema(),
5859
},
5960
},
6061
},

sysdig/internal/client/v2/model.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,14 @@ type RuntimePolicyRuleList struct {
426426
}
427427

428428
type DriftRuleDetails struct {
429-
RuleType ElementType `json:"ruleType"`
430-
Exceptions *RuntimePolicyRuleList `json:"exceptionList"`
431-
ProcessBasedExceptions *RuntimePolicyRuleList `json:"allowlistProcess"`
432-
ProcessBasedDenylist *RuntimePolicyRuleList `json:"denylistProcess"`
433-
ProhibitedBinaries *RuntimePolicyRuleList `json:"prohibitedBinaries"`
434-
Mode string `json:"mode"`
435-
Details `json:"-"`
429+
RuleType ElementType `json:"ruleType"`
430+
Exceptions *RuntimePolicyRuleList `json:"exceptionList"`
431+
ProcessBasedExceptions *RuntimePolicyRuleList `json:"allowlistProcess"`
432+
ProcessBasedDenylist *RuntimePolicyRuleList `json:"denylistProcess"`
433+
ProhibitedBinaries *RuntimePolicyRuleList `json:"prohibitedBinaries"`
434+
Mode string `json:"mode"`
435+
MountedVolumeDriftEnabled bool `json:"mountedVolumeDriftEnabled"`
436+
Details `json:"-"`
436437
}
437438

438439
func (p DriftRuleDetails) GetRuleType() ElementType {

sysdig/resource_sysdig_secure_drift_policy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func resourceSysdigSecureDriftPolicy() *schema.Resource {
6666
"prohibited_binaries": ExceptionsSchema(),
6767
"process_based_exceptions": ExceptionsSchema(),
6868
"process_based_prohibited_binaries": ExceptionsSchema(),
69+
"mounted_volume_drift_enabled": BoolSchema(),
6970
},
7071
},
7172
},

sysdig/resource_sysdig_secure_drift_policy_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func TestAccDriftPolicy(t *testing.T) {
3939
{
4040
Config: driftPolicyWithoutExceptions(rText()),
4141
},
42+
{
43+
Config: driftPolicyWithMountedVolumeDriftEnabled(rText()),
44+
},
4245
},
4346
})
4447
}
@@ -212,3 +215,31 @@ resource "sysdig_secure_drift_policy" "sample" {
212215
213216
`, secureNotificationChannelEmailWithName(name), name)
214217
}
218+
219+
func driftPolicyWithMountedVolumeDriftEnabled(name string) string {
220+
return fmt.Sprintf(`
221+
resource "sysdig_secure_drift_policy" "sample" {
222+
223+
name = "Test Drift Policy %s"
224+
description = "Test Drift Policy Description"
225+
enabled = true
226+
severity = 4
227+
228+
rule {
229+
description = "Test Drift Rule Description"
230+
mounted_volume_drift_enabled = true
231+
enabled = true
232+
233+
exceptions {
234+
items = ["/usr/bin/sh"]
235+
}
236+
prohibited_binaries {
237+
items = ["/usr/bin/curl"]
238+
}
239+
process_based_exceptions {
240+
items = ["/usr/bin/curl"]
241+
}
242+
}
243+
}
244+
`, name)
245+
}

sysdig/tfresource.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,13 @@ func setTFResourcePolicyRulesDrift(d *schema.ResourceData, policy v2.PolicyRules
209209
enabled := (mode != "disabled")
210210

211211
ruleMap := map[string]interface{}{
212-
"id": rule.Id,
213-
"name": rule.Name,
214-
"description": rule.Description,
215-
"version": rule.Version,
216-
"tags": rule.Tags,
217-
"enabled": enabled,
212+
"id": rule.Id,
213+
"name": rule.Name,
214+
"description": rule.Description,
215+
"version": rule.Version,
216+
"tags": rule.Tags,
217+
"enabled": enabled,
218+
"mounted_volume_drift_enabled": driftDetails.MountedVolumeDriftEnabled,
218219
}
219220

220221
if exceptionsBlock != nil {
@@ -495,18 +496,21 @@ func setPolicyRulesDrift(policy *v2.PolicyRulesComposite, d *schema.ResourceData
495496
mode = "disabled"
496497
}
497498

499+
mountedVolumeDriftEnabled := d.Get("rule.0.mounted_volume_drift_enabled").(bool)
500+
498501
rule := &v2.RuntimePolicyRule{
499502
// TODO: Do not hardcode the indexes
500503
Name: d.Get("rule.0.name").(string),
501504
Description: d.Get("rule.0.description").(string),
502505
Tags: tags,
503506
Details: v2.DriftRuleDetails{
504-
RuleType: v2.ElementType(driftElementType), // TODO: Use const
505-
Mode: mode,
506-
Exceptions: &exceptions,
507-
ProhibitedBinaries: &prohibitedBinaries,
508-
ProcessBasedExceptions: &processBasedExceptions,
509-
ProcessBasedDenylist: &processBasedProhibitedBinaries,
507+
RuleType: v2.ElementType(driftElementType), // TODO: Use const
508+
Mode: mode,
509+
Exceptions: &exceptions,
510+
ProhibitedBinaries: &prohibitedBinaries,
511+
ProcessBasedExceptions: &processBasedExceptions,
512+
ProcessBasedDenylist: &processBasedProhibitedBinaries,
513+
MountedVolumeDriftEnabled: mountedVolumeDriftEnabled,
510514
},
511515
}
512516

website/docs/r/secure_drift_policy.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ The rule block is required and supports:
122122
* `items` - (Required) Specify comma separated list of processes, e.g. `/usr/bin/rm, /usr/bin/curl`.
123123
* `process_based_prohibited_binaries` - (Optional) List of processes that will be prohibited to execute a drifted file
124124
* `items` - (Required) Specify comma separated list of processes, e.g. `/usr/bin/rm, /usr/bin/curl`.
125+
* `mounted_volume_drift_enabled` - (Optional) Treat all binaries from mounted volumes as drifted. Default value is false/disabled.
125126

126127

127128

0 commit comments

Comments
 (0)