Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions sysdig/data_source_sysdig_secure_drift_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ func createDriftPolicyDataSourceSchema() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": ReadOnlyIntSchema(),
"name": ReadOnlyStringSchema(),
"description": DescriptionComputedSchema(),
"tags": TagsSchema(),
"version": VersionSchema(),
"enabled": BoolComputedSchema(),
"exceptions": ExceptionsComputedSchema(),
"prohibited_binaries": ExceptionsComputedSchema(),
"mounted_volume_drift_enabled": BoolComputedSchema(),
"id": ReadOnlyIntSchema(),
"name": ReadOnlyStringSchema(),
"description": DescriptionComputedSchema(),
"tags": TagsSchema(),
"version": VersionSchema(),
"enabled": BoolComputedSchema(),
"exceptions": ExceptionsComputedSchema(),
"prohibited_binaries": ExceptionsComputedSchema(),
"process_based_exceptions": ExceptionsComputedSchema(),
"process_based_prohibited_binaries": ExceptionsComputedSchema(),
"mounted_volume_drift_enabled": BoolComputedSchema(),
"use_regex": BoolComputedSchema(),
},
},
},
Expand Down
81 changes: 81 additions & 0 deletions sysdig/data_source_sysdig_secure_drift_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func TestAccDriftPolicyDataSource(t *testing.T) {
{
Config: driftPolicyDataSource(rText),
},
{
Config: driftPolicyWithUseRegexDataSource(rText),
},
{
Config: driftPolicyWithProcessExceptionsDataSource(rText),
},
},
})
}
Expand Down Expand Up @@ -68,3 +74,78 @@ data "sysdig_secure_drift_policy" "policy_2" {
}
`, name, name)
}

func driftPolicyWithUseRegexDataSource(name string) string {
return fmt.Sprintf(`
resource "sysdig_secure_drift_policy" "policy_1" {
name = "Test Drift Policy %s"
description = "Test Drift Policy Description %s"
enabled = true
severity = 4

rule {
description = "Test Drift Rule Description"
enabled = true
mounted_volume_drift_enabled = true
use_regex = true

exceptions {
items = ["/usr/bin/sh"]
}
prohibited_binaries {
items = ["/usr/bin/curl"]
}
process_based_exceptions {
items = ["/usr/bin/curl"]
}
process_based_prohibited_binaries {
items = ["/usr/bin/sh"]
}
}

actions {
prevent_drift = true
}

}

data "sysdig_secure_drift_policy" "policy_2" {
name = sysdig_secure_drift_policy.policy_1.name
depends_on = [sysdig_secure_drift_policy.policy_1]
}
`, name, name)
}

func driftPolicyWithProcessExceptionsDataSource(name string) string {
return fmt.Sprintf(`
resource "sysdig_secure_drift_policy" "policy_1" {
name = "Test Drift Policy %s"
description = "Test Drift Policy Description %s"
enabled = true
severity = 4

rule {
description = "Test Drift Rule Description"
enabled = true
mounted_volume_drift_enabled = true

process_based_exceptions {
items = ["/usr/bin/curl"]
}
process_based_prohibited_binaries {
items = ["/usr/bin/sh"]
}
}

actions {
prevent_drift = true
}

}

data "sysdig_secure_drift_policy" "policy_2" {
name = sysdig_secure_drift_policy.policy_1.name
depends_on = [sysdig_secure_drift_policy.policy_1]
}
`, name, name)
}
1 change: 1 addition & 0 deletions sysdig/internal/client/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ type DriftRuleDetails struct {
ProhibitedBinaries *RuntimePolicyRuleList `json:"prohibitedBinaries"`
Mode string `json:"mode"`
MountedVolumeDriftEnabled bool `json:"mountedVolumeDriftEnabled"`
UseRegex bool `json:"useRegex"`
Details `json:"-"`
}

Expand Down
1 change: 1 addition & 0 deletions sysdig/resource_sysdig_secure_drift_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func resourceSysdigSecureDriftPolicy() *schema.Resource {
"process_based_exceptions": ExceptionsSchema(),
"process_based_prohibited_binaries": ExceptionsSchema(),
"mounted_volume_drift_enabled": BoolSchema(),
"use_regex": BoolSchema(),
},
},
},
Expand Down
57 changes: 47 additions & 10 deletions sysdig/resource_sysdig_secure_drift_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func TestAccDriftPolicy(t *testing.T) {
{
Config: driftPolicyWithMountedVolumeDriftEnabled(rText()),
},
{
Config: driftPolicyWithProcessBasedAndRegexEnabled(rText()),
},
},
})
}
Expand All @@ -67,9 +70,9 @@ resource "sysdig_secure_drift_policy" "sample" {
prohibited_binaries {
items = ["/usr/bin/curl"]
}
process_based_exceptions {
process_based_exceptions {
items = ["/usr/bin/curl"]
}
}
}

actions {
Expand Down Expand Up @@ -103,9 +106,9 @@ resource "sysdig_secure_drift_policy" "sample" {
prohibited_binaries {
items = ["/usr/bin/curl"]
}
process_based_exceptions {
process_based_exceptions {
items = ["/usr/bin/curl"]
}
}
}

actions {
Expand Down Expand Up @@ -145,9 +148,9 @@ resource "sysdig_secure_drift_policy" "sample" {
prohibited_binaries {
items = ["/usr/bin/curl"]
}
process_based_exceptions {
process_based_exceptions {
items = ["/usr/bin/curl"]
}
}
}

actions {}
Expand Down Expand Up @@ -177,9 +180,9 @@ resource "sysdig_secure_drift_policy" "sample" {
prohibited_binaries {
items = ["/usr/bin/curl"]
}
process_based_exceptions {
process_based_exceptions {
items = ["/usr/bin/curl"]
}
}
}

actions {
Expand Down Expand Up @@ -228,18 +231,52 @@ resource "sysdig_secure_drift_policy" "sample" {
rule {
description = "Test Drift Rule Description"
mounted_volume_drift_enabled = true

enabled = true

exceptions {
items = ["/usr/bin/sh"]
}
prohibited_binaries {
items = ["/usr/bin/curl"]
}
process_based_exceptions {
items = ["/usr/bin/curl"]
}
}
}
`, name)
}

func driftPolicyWithProcessBasedAndRegexEnabled(name string) string {
return fmt.Sprintf(`
resource "sysdig_secure_drift_policy" "sample" {

name = "Test Drift Policy %s"
description = "Test Drift Policy Description"
enabled = true
severity = 4

rule {
description = "Test Drift Rule Description"
mounted_volume_drift_enabled = true

enabled = true
use_regex = true

exceptions {
items = ["/usr/bin/sh"]
}
prohibited_binaries {
items = ["/usr/bin/curl"]
}
process_based_exceptions {
process_based_exceptions {
items = ["/usr/bin/curl"]
}
}
process_based_prohibited_binaries {
items = ["/usr/bin/sh"]
}
}
}
`, name)
}
3 changes: 3 additions & 0 deletions sysdig/tfresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func setTFResourcePolicyRulesDrift(d *schema.ResourceData, policy v2.PolicyRules
"tags": rule.Tags,
"enabled": enabled,
"mounted_volume_drift_enabled": driftDetails.MountedVolumeDriftEnabled,
"use_regex": driftDetails.UseRegex,
}

if exceptionsBlock != nil {
Expand Down Expand Up @@ -498,6 +499,7 @@ func setPolicyRulesDrift(policy *v2.PolicyRulesComposite, d *schema.ResourceData
}

mountedVolumeDriftEnabled := d.Get("rule.0.mounted_volume_drift_enabled").(bool)
useRegex := d.Get("rule.0.use_regex").(bool)

rule := &v2.RuntimePolicyRule{
// TODO: Do not hardcode the indexes
Expand All @@ -512,6 +514,7 @@ func setPolicyRulesDrift(policy *v2.PolicyRulesComposite, d *schema.ResourceData
ProcessBasedExceptions: &processBasedExceptions,
ProcessBasedDenylist: &processBasedProhibitedBinaries,
MountedVolumeDriftEnabled: mountedVolumeDriftEnabled,
UseRegex: useRegex,
},
}

Expand Down
8 changes: 6 additions & 2 deletions website/docs/d/secure_drift_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,9 @@ The rule block is required and supports:
* `items` - (Required) Specify comma separated list of exceptions, e.g. `/usr/bin/rm, /usr/bin/curl`.
* `prohibited_binaries` - (Optional) A prohibited binary can be a known harmful binary or one that facilitates discovery of your environment.
* `items` - (Required) Specify comma separated list of prohibited binaries, e.g. `/usr/bin/rm, /usr/bin/curl`.


* `process_based_exceptions` - (Optional) List of processes that will be able to execute a drifted file
* `items` - (Required) Specify comma separated list of processes, e.g. `/usr/bin/rm, /usr/bin/curl`.
* `process_based_prohibited_binaries` - (Optional) List of processes that will be prohibited to execute a drifted file
* `items` - (Required) Specify comma separated list of processes, e.g. `/usr/bin/rm, /usr/bin/curl`.
* `mounted_volume_drift_enabled` - (Optional) Treat all binaries from mounted volumes as drifted. Default value is false/disabled.
* `use_regex` - (Optional) Pass exceptions and prohibited binaries as regex strings. Requires agent version 13.2.0 and above
4 changes: 1 addition & 3 deletions website/docs/r/secure_drift_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,4 @@ The rule block is required and supports:
* `process_based_prohibited_binaries` - (Optional) List of processes that will be prohibited to execute a drifted file
* `items` - (Required) Specify comma separated list of processes, e.g. `/usr/bin/rm, /usr/bin/curl`.
* `mounted_volume_drift_enabled` - (Optional) Treat all binaries from mounted volumes as drifted. Default value is false/disabled.



* `use_regex` - (Optional) Pass exceptions and prohibited binaries as regex strings. Requires agent version 13.2.0 and above
Loading