Skip to content

Commit e60877e

Browse files
authored
[policies] add support for sysdig secure aws gaurdduty policies and rules (#603)
* add support for guardduty policy and rules * fix test * fix string formatting
1 parent b2b9b9a commit e60877e

12 files changed

+71
-11
lines changed

sysdig/resource_sysdig_secure_policy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var validatePolicyType = validation.StringInSlice([]string{
3232
"drift",
3333
"aws_machine_learning",
3434
"machine_learning",
35+
"guardduty",
3536
}, false)
3637

3738
func resourceSysdigSecurePolicy() *schema.Resource {

sysdig/resource_sysdig_secure_policy_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestAccPolicy(t *testing.T) {
5656
resource.TestStep{Config: policiesForFalcoCloudAWSCloudtrail(rText())},
5757
resource.TestStep{Config: policiesForOkta(rText())},
5858
resource.TestStep{Config: policiesForGithub(rText())},
59+
resource.TestStep{Config: policiesForGuardDuty(rText())},
5960
)
6061
}
6162
}
@@ -254,3 +255,14 @@ resource "sysdig_secure_policy" "sample9" {
254255
}
255256
`, name, name)
256257
}
258+
259+
func policiesForGuardDuty(name string) string {
260+
return fmt.Sprintf(`
261+
resource "sysdig_secure_policy" "sample10" {
262+
name = "TERRAFORM TEST 4 %s"
263+
description = "TERRAFORM TEST %s"
264+
type = "guardduty"
265+
actions {}
266+
}
267+
`, name, name)
268+
}

sysdig/resource_sysdig_secure_rule_falco.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/spf13/cast"
1919
)
2020

21-
var validateFalcoRuleSource = validation.StringInSlice([]string{"syscall", "k8s_audit", "aws_cloudtrail", "gcp_auditlog", "azure_platformlogs", "awscloudtrail", "okta", "github"}, false)
21+
var validateFalcoRuleSource = validation.StringInSlice([]string{"syscall", "k8s_audit", "aws_cloudtrail", "gcp_auditlog", "azure_platformlogs", "awscloudtrail", "okta", "github", "guardduty"}, false)
2222

2323
func resourceSysdigSecureRuleFalco() *schema.Resource {
2424
timeout := 5 * time.Minute

sysdig/resource_sysdig_secure_rule_falco_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ func TestRuleGithubAppends(t *testing.T) {
285285
runTest(steps, t)
286286
}
287287

288+
func TestRuleGuardDuty(t *testing.T) {
289+
steps := []resource.TestStep{
290+
{
291+
Config: ruleGuardDuty(randomString()),
292+
},
293+
}
294+
runTest(steps, t)
295+
}
296+
297+
func TestRuleGuardDutyAppends(t *testing.T) {
298+
steps := []resource.TestStep{
299+
{
300+
Config: ruleGuardDutyWithAppend(),
301+
},
302+
}
303+
runTest(steps, t)
304+
}
305+
288306
func randomString() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
289307

290308
func runTest(steps []resource.TestStep, t *testing.T) {
@@ -564,3 +582,32 @@ resource "sysdig_secure_rule_falco" "github_append" {
564582
}
565583
}`
566584
}
585+
586+
func ruleGuardDuty(name string) string {
587+
return fmt.Sprintf(`
588+
resource "sysdig_secure_rule_falco" "guardduty" {
589+
name = "TERRAFORM TEST %[1]s - GuardDuty"
590+
description = "TERRAFORM TEST %[1]s"
591+
tags = ["guardduty"]
592+
593+
condition = "guardduty.resourceType=\"Container\""
594+
output = "GuardDuty Event received (account ID=%%guardduty.accountId)"
595+
priority = "debug"
596+
source = "guardduty"
597+
}`, name, name)
598+
}
599+
600+
func ruleGuardDutyWithAppend() string {
601+
return `
602+
resource "sysdig_secure_rule_falco" "guardduty_append" {
603+
name = "GuardDuty High Severity Finding on Container"
604+
source = "guardduty"
605+
append = true
606+
exceptions {
607+
name = "resource_type_tf"
608+
fields = ["guardduty.resourceType"]
609+
comps = ["="]
610+
values = jsonencode([ ["Amazon S2"] ])
611+
}
612+
}`
613+
}

website/docs/d/secure_custom_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data "sysdig_secure_custom_policy" "example" {
2626
* `name` - (Required) The name of the Secure custom policy.
2727

2828
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`,
29-
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`. By default it is `falco`.
29+
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`, `guardduty`. By default it is `falco`.
3030

3131
## Attributes Reference
3232

website/docs/d/secure_managed_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data "sysdig_secure_managed_policy" "example" {
2626
* `name` - (Required) The name of the Secure managed policy.
2727

2828
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`,
29-
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`. By default it is `falco`.
29+
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`, `guardduty`. By default it is `falco`.
3030

3131
## Attributes Reference
3232

website/docs/d/secure_managed_ruleset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data "sysdig_secure_managed_ruleset" "example" {
2626
* `name` - (Required) The name of the Secure managed ruleset.
2727

2828
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`,
29-
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`. By default it is `falco`.
29+
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`, `guardduty`. By default it is `falco`.
3030

3131
## Attributes Reference
3232

website/docs/r/secure_custom_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ resource "sysdig_secure_custom_policy" "write_apt_database" {
6060
* `enabled` - (Optional) Will secure process with this rule?. By default this is true.
6161

6262
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`,
63-
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`. By default it is `falco`.
63+
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`, `guardduty`. By default it is `falco`.
6464

6565
* `runbook` - (Optional) Customer provided url that provides a runbook for a given policy.
6666
- - -

website/docs/r/secure_managed_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ resource "sysdig_secure_managed_policy" "sysdig_runtime_threat_detection" {
5151
* `name` - (Required) The name of the Secure managed policy. It must match the name of an existing managed policy.
5252

5353
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`,
54-
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`. By default it is `falco`.
54+
`aws_cloudtrail`, `gcp_auditlog`, `azure_platformlogs`, `awscloudtrail`, `okta`, `github`, `guardduty`. By default it is `falco`.
5555

5656
* `enabled` - (Optional) Will secure process with this policy?. By default this is true.
5757

website/docs/r/secure_managed_ruleset.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ resource "sysdig_secure_managed_ruleset" "sysdig_runtime_threat_detection_manage
5959

6060
* `enabled` - (Optional) Will secure process with this rule?. By default this is true.
6161

62-
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`, `aws_cloudtrail`, `awscloudtrail`, `okta`, `github`. By default it is `falco`.
62+
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`, `aws_cloudtrail`, `awscloudtrail`, `okta`, `github`, `guardduty`. By default it is `falco`.
6363

6464
* `runbook` - (Optional) Customer provided url that provides a runbook for a given policy.
6565
- - -
@@ -70,7 +70,7 @@ The `inherited_from` block is required and identifies the managed policy that th
7070

7171
* `name` - (Required) The name of the Secure managed policy. It must match the name of an existing managed policy.
7272

73-
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`, `aws_cloudtrail`, `awscloudtrail`, `okta`, `github`. By default it is `falco`.
73+
* `type` - (Optional) Specifies the type of the runtime policy. Must be one of: `falco`, `list_matching`, `k8s_audit`, `aws_cloudtrail`, `awscloudtrail`, `okta`, `github`, `guardduty`. By default it is `falco`.
7474

7575
- - -
7676

0 commit comments

Comments
 (0)