Skip to content

Commit ea8c0e5

Browse files
committed
fix(rules): Fix incorrect endpoint for rule update
Signed-off-by: Federico Barcelona <[email protected]>
1 parent c1b238c commit ea8c0e5

File tree

7 files changed

+33
-14
lines changed

7 files changed

+33
-14
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/draios/terraform-provider-sysdig
22

33
go 1.12
44

5-
require github.com/hashicorp/terraform-plugin-sdk v1.10.0
5+
require github.com/hashicorp/terraform-plugin-sdk v1.12.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8
112112
github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A=
113113
github.com/hashicorp/terraform-json v0.4.0 h1:KNh29iNxozP5adfUFBJ4/fWd0Cu3taGgjHB38JYqOF4=
114114
github.com/hashicorp/terraform-json v0.4.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU=
115-
github.com/hashicorp/terraform-plugin-sdk v1.10.0 h1:JLV3dUnsAF8TKGUdEPkvl9H0Xb2LdcHxLJyDPZ1A5/U=
116-
github.com/hashicorp/terraform-plugin-sdk v1.10.0/go.mod h1:HiWIPD/T9HixIhQUwaSoDQxo4BLFdmiBi/Qz5gjB8Q0=
115+
github.com/hashicorp/terraform-plugin-sdk v1.12.0 h1:HPp65ShSsKUMPf6jD50UQn/xAjyrGVO4FxI63bvu+pc=
116+
github.com/hashicorp/terraform-plugin-sdk v1.12.0/go.mod h1:HiWIPD/T9HixIhQUwaSoDQxo4BLFdmiBi/Qz5gjB8Q0=
117117
github.com/hashicorp/terraform-plugin-test v1.3.0 h1:hU5LoxrOn9qvOo+LTKN6mSav2J+dAMprbdxJPEQvp4U=
118118
github.com/hashicorp/terraform-plugin-test v1.3.0/go.mod h1:QIJHYz8j+xJtdtLrFTlzQVC0ocr3rf/OjIpgZLK56Hs=
119119
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg=

sysdig/monitor/alerts.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import (
88
)
99

1010
func (c *sysdigMonitorClient) CreateAlert(alert Alert) (createdAlert Alert, err error) {
11-
//data, err := ioutil.ReadAll(alert.ToJSON())
12-
//if err != nil {
13-
// return
14-
//}
15-
//err = errors.New(string(data))
16-
//return
17-
1811
response, err := c.doSysdigMonitorRequest(http.MethodPost, c.alertsURL(), alert.ToJSON())
1912
if err != nil {
2013
return

sysdig/resource_sysdig_secure_rule_falco.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func resourceSysdigSecureRuleFalco() *schema.Resource {
2626
},
2727

2828
Schema: createRuleSchema(map[string]*schema.Schema{
29-
3029
"condition": {
3130
Type: schema.TypeString,
3231
Required: true,

sysdig/resource_sysdig_secure_rule_falco_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
func TestAccRuleFalco(t *testing.T) {
1414
rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
1515

16+
ruleRandomImmutableText := rText()
17+
1618
resource.Test(t, resource.TestCase{
1719
PreCheck: func() {
1820
if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" {
@@ -24,7 +26,10 @@ func TestAccRuleFalco(t *testing.T) {
2426
},
2527
Steps: []resource.TestStep{
2628
{
27-
Config: ruleFalcoTerminalShell(rText()),
29+
Config: ruleFalcoTerminalShell(ruleRandomImmutableText),
30+
},
31+
{
32+
Config: ruleFalcoUpdatedTerminalShell(ruleRandomImmutableText),
2833
},
2934
{
3035
Config: ruleFalcoKubeAudit(rText()),
@@ -47,6 +52,20 @@ resource "sysdig_secure_rule_falco" "terminal_shell" {
4752
}`, name, name)
4853
}
4954

55+
func ruleFalcoUpdatedTerminalShell(name string) string {
56+
return fmt.Sprintf(`
57+
resource "sysdig_secure_rule_falco" "terminal_shell" {
58+
name = "TERRAFORM TEST %s - Terminal Shell"
59+
description = "TERRAFORM TEST %s"
60+
tags = ["shell", "mitre_execution"]
61+
62+
condition = "spawned_process and shell_procs and proc.tty != 0 and container_entrypoint"
63+
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)"
64+
priority = "notice"
65+
source = "syscall" // syscall or k8s_audit
66+
}`, name, name)
67+
}
68+
5069
func ruleFalcoKubeAudit(name string) string {
5170
return fmt.Sprintf(`
5271
resource "sysdig_secure_rule_falco" "kube_audit" {

sysdig/secure/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package secure
22

33
import (
44
"io"
5+
"log"
56
"net/http"
7+
"net/http/httputil"
68
)
79

810
type SysdigSecureClient interface {
@@ -51,5 +53,11 @@ func (client *sysdigSecureClient) doSysdigSecureRequest(method string, url strin
5153
request.Header.Set("Authorization", "Bearer "+client.SysdigSecureAPIToken)
5254
request.Header.Set("Content-Type", "application/json")
5355

54-
return client.httpClient.Do(request)
56+
out, _ := httputil.DumpRequestOut(request, true)
57+
log.Printf("[DEBUG] %s", string(out))
58+
response, error := client.httpClient.Do(request)
59+
60+
out, _ = httputil.DumpResponse(response, true)
61+
log.Printf("[DEBUG] %s", string(out))
62+
return response, error
5563
}

sysdig/secure/rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (client *sysdigSecureClient) GetRuleByID(ruleID int) (result Rule, err erro
5050
}
5151

5252
func (client *sysdigSecureClient) UpdateRule(rule Rule) (result Rule, err error) {
53-
response, _ := client.doSysdigSecureRequest(http.MethodPut, client.policyURL(rule.ID), rule.ToJSON())
53+
response, _ := client.doSysdigSecureRequest(http.MethodPut, client.ruleURL(rule.ID), rule.ToJSON())
5454
body, _ := ioutil.ReadAll(response.Body)
5555

5656
if response.StatusCode != http.StatusOK {

0 commit comments

Comments
 (0)