Skip to content

Commit 7149041

Browse files
fix(CIS): fix skip action in custom rules (IBM-Cloud#6242)
* fix(CIS): fix skip action in custom rules * fix changes in update * Added documentation * Added documentation * Added documentation * Added validation changes * fix changes for validation
1 parent a4dbb01 commit 7149041

8 files changed

+76
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/IBM/logs-go-sdk v0.4.0
2828
github.com/IBM/logs-router-go-sdk v1.0.7
2929
github.com/IBM/mqcloud-go-sdk v0.2.0
30-
github.com/IBM/networking-go-sdk v0.51.4
30+
github.com/IBM/networking-go-sdk v0.51.5
3131
github.com/IBM/platform-services-go-sdk v0.81.1
3232
github.com/IBM/project-go-sdk v0.3.5
3333
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ github.com/IBM/logs-router-go-sdk v1.0.7 h1:uQjQAAcQdo3XvhY6MC7HakhZaXIUsGfUmKj2
147147
github.com/IBM/logs-router-go-sdk v1.0.7/go.mod h1:tCN2vFgu5xG0ob9iJcxi5M4bJ6mWmu3nhmRPnvlwev0=
148148
github.com/IBM/mqcloud-go-sdk v0.2.0 h1:QOWk8ZGk0QfIL0MOGTKzNdM3Qe0Hk+ifAFtNSFQo5HU=
149149
github.com/IBM/mqcloud-go-sdk v0.2.0/go.mod h1:VZQKMtqmcdXKhmLhLiPuS/UHMs/5yo2tA/nD83cQt9E=
150-
github.com/IBM/networking-go-sdk v0.51.4 h1:rkbR+gUkksLKjNYL5YEWEAMv3qddR0mUkxObDMa4l/s=
151-
github.com/IBM/networking-go-sdk v0.51.4/go.mod h1:gjCFEp+UVP7FUlcq2C1RaoZAXFcD39CQdlUk7uVKko4=
150+
github.com/IBM/networking-go-sdk v0.51.5 h1:75lKAx17y++hirXK5GcEM23mTRhHnhsv6gmhz70ex1Q=
151+
github.com/IBM/networking-go-sdk v0.51.5/go.mod h1:wyEnRnBnROgGmSn5UrryycIrbBujHKXf0PmI1NSwcjY=
152152
github.com/IBM/platform-services-go-sdk v0.81.1 h1:Ch9wUIigyA3HzW7MQnA1WTHAw+QA6W4bSP3ThgzDpx0=
153153
github.com/IBM/platform-services-go-sdk v0.81.1/go.mod h1:XOowH+JnIih3FA7uilLVM/9VH7XgCmJ4T/i6eZi7gkw=
154154
github.com/IBM/project-go-sdk v0.3.5 h1:L+YClFUa14foS0B/hOOY9n7sIdsT5/XQicnXOyJSpyM=

ibm/service/cis/data_source_ibm_cis_rulesets.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const (
5757
CISRulesetsRulePositionIndex = "index"
5858
CISRulesetRuleId = "rule_id"
5959
CISRulesetOverridesScoreThreshold = "score_threshold"
60+
CISRulesetsRulePhases = "phases"
61+
CISRulesetsRuleProducts = "products"
6062
)
6163

6264
var CISResponseObject = &schema.Resource{
@@ -219,7 +221,19 @@ var CISResponseObject = &schema.Resource{
219221
CISRuleset: {
220222
Type: schema.TypeString,
221223
Computed: true,
222-
Description: "Ruleset ID of the ruleset to apply action to.",
224+
Description: "Ruleset of the rule",
225+
},
226+
CISRulesetsRulePhases: {
227+
Type: schema.TypeList,
228+
Computed: true,
229+
Description: "Phases of the rule",
230+
Elem: &schema.Schema{Type: schema.TypeString},
231+
},
232+
CISRulesetsRuleProducts: {
233+
Type: schema.TypeList,
234+
Computed: true,
235+
Description: "Products of the rule",
236+
Elem: &schema.Schema{Type: schema.TypeString},
223237
},
224238
CISRulesetList: {
225239
Type: schema.TypeList,
@@ -489,7 +503,7 @@ func flattenCISRulesets(rulesetObj rulesetsv1.RulesetDetails) interface{} {
489503
ruleDetails[CISRulesetsRuleActionDescription] = ruleDetailsObj.Description
490504

491505
// Not Applicable for now
492-
ruleDetails[CISRulesetsRuleLogging] = ruleDetailsObj.Logging
506+
//ruleDetails[CISRulesetsRuleLogging] = ruleDetailsObj.Logging
493507

494508
flattenedActionParameter := flattenCISRulesetsRuleActionParameters(ruleDetailsObj.ActionParameters)
495509

@@ -526,6 +540,12 @@ func flattenCISRulesetsRuleActionParameters(rulesetsRuleActionParameterObj *rule
526540
if _, ok := actionParametersOutput["rulesets"]; ok {
527541
resultOutput[CISRulesetList] = rulesetsRuleActionParameterObj.Rulesets
528542
}
543+
if val, ok := actionParametersOutput["phases"]; ok {
544+
resultOutput[CISRulesetsRulePhases] = val.([]interface{})
545+
}
546+
if val, ok := actionParametersOutput["products"]; ok {
547+
resultOutput[CISRulesetsRuleProducts] = val.([]interface{})
548+
}
529549
if _, ok := actionParametersOutput["response"]; ok {
530550
flattenCISRulesetsRuleActionParameterResponse := flattenCISRulesetsRuleActionParameterResponse(rulesetsRuleActionParameterObj.Response)
531551
resultOutput[CISRulesetsRuleActionParametersResponse] = []map[string]interface{}{flattenCISRulesetsRuleActionParameterResponse}

ibm/service/cis/resource_ibm_cis_ruleset.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,19 @@ var CISResourceResponseObject = &schema.Resource{
175175
CISRuleset: {
176176
Type: schema.TypeString,
177177
Optional: true,
178-
Description: "Ruleset ID of the ruleset to apply action to",
178+
Description: "Ruleset of the rule",
179+
},
180+
CISRulesetsRulePhases: {
181+
Type: schema.TypeList,
182+
Optional: true,
183+
Description: "Phases of the rule",
184+
Elem: &schema.Schema{Type: schema.TypeString},
185+
},
186+
CISRulesetsRuleProducts: {
187+
Type: schema.TypeList,
188+
Optional: true,
189+
Description: "Products of the rule",
190+
Elem: &schema.Schema{Type: schema.TypeString},
179191
},
180192
CISRulesetList: {
181193
Type: schema.TypeList,
@@ -572,6 +584,19 @@ func expandCISRulesetsRulesActionParameters(obj interface{}) rulesetsv1.ActionPa
572584
}
573585
actionParameterRespObj.Rulesets = ruleList
574586

587+
ruleset := actionParameterObj[CISRuleset].(string)
588+
if ruleset != "" {
589+
actionParameterRespObj.Ruleset = &ruleset
590+
}
591+
592+
phases := actionParameterObj[CISRulesetsRulePhases].([]interface{})
593+
phasesList := flex.ExpandStringList(phases)
594+
actionParameterRespObj.Phases = phasesList
595+
596+
products := actionParameterObj[CISRulesetsRuleProducts].([]interface{})
597+
productsList := flex.ExpandStringList(products)
598+
actionParameterRespObj.Products = productsList
599+
575600
finalResponse := make([]rulesetsv1.ActionParameters, 0)
576601

577602
overrideObj := rulesetsv1.Overrides{}

ibm/service/cis/resource_ibm_cis_ruleset_rule.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,19 @@ var CISRulesetsRulesObject = &schema.Resource{
135135
CISRuleset: {
136136
Type: schema.TypeString,
137137
Optional: true,
138-
Description: "Ruleset ID of the ruleset to apply action to",
138+
Description: "Ruleset of the rule",
139+
},
140+
CISRulesetsRulePhases: {
141+
Type: schema.TypeList,
142+
Optional: true,
143+
Description: "Phases of the rule",
144+
Elem: &schema.Schema{Type: schema.TypeString},
145+
},
146+
CISRulesetsRuleProducts: {
147+
Type: schema.TypeList,
148+
Optional: true,
149+
Description: "Products of the rule",
150+
Elem: &schema.Schema{Type: schema.TypeString},
139151
},
140152
CISRulesetList: {
141153
Type: schema.TypeList,
@@ -433,11 +445,10 @@ func ResourceIBMCISRulesetRuleUpdate(d *schema.ResourceData, meta interface{}) e
433445
rulesetsRuleObject := d.Get(CISRulesetsRule).([]interface{})[0].(map[string]interface{})
434446
opt.SetDescription(rulesetsRuleObject[CISRulesetsDescription].(string))
435447
opt.SetAction(rulesetsRuleObject[CISRulesetsRuleAction].(string))
436-
if d.HasChange(CISRulesetsRuleActionParameters) {
448+
if rulesetsRuleObject[CISRulesetsRuleActionParameters] != nil {
437449
actionParameters := expandCISRulesetsRulesActionParameters(rulesetsRuleObject[CISRulesetsRuleActionParameters])
438450
opt.SetActionParameters(&actionParameters)
439451
}
440-
441452
opt.SetEnabled(rulesetsRuleObject[CISRulesetsRuleActionEnabled].(bool))
442453
opt.SetExpression(rulesetsRuleObject[CISRulesetsRuleExpression].(string))
443454
opt.SetRef(rulesetsRuleObject[CISRulesetsRuleRef].(string))
@@ -472,7 +483,7 @@ func ResourceIBMCISRulesetRuleUpdate(d *schema.ResourceData, meta interface{}) e
472483
opt.SetRef(rulesetsRuleObject[CISRulesetsRuleAction].(string))
473484
position, err := expandCISRulesetsRulesPositions(rulesetsRuleObject[CISRulesetsRulePosition])
474485
if err != nil {
475-
return fmt.Errorf("[ERROR] Error while updating the zone Ruleset %s", err)
486+
return fmt.Errorf("[ERROR] Error while updating the instance Ruleset %s", err)
476487
}
477488
opt.SetPosition(&position)
478489

@@ -483,7 +494,7 @@ func ResourceIBMCISRulesetRuleUpdate(d *schema.ResourceData, meta interface{}) e
483494
_, _, err = sess.UpdateInstanceRulesetRule(opt)
484495

485496
if err != nil {
486-
return fmt.Errorf("[ERROR] Error while updating the zone Ruleset %s", err)
497+
return fmt.Errorf("[ERROR] Error while updating the instance Ruleset %s", err)
487498
}
488499

489500
d.SetId(dataSourceCISRulesetsRuleCheckID(d, ruleId))

website/docs/d/cis_ruleset_entrypoint_versions.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ Extra attributes when `version` is provide.
8888
- `enabled` (Boolean) Enables/Disables the rule.
8989
- `action` (String) Action of the rule.
9090
- `version` (String) Latest version.
91-
- `ruleset` (String) ID of the ruleset.
91+
- `ruleset` (String) Ruleset of the rule.
92+
- `phases` (List) Phases of the rule.
93+
- `products` (List) Products of the rule.
9294
- `rulesets` (List) IDs of the rulesets.
9395
- `response` (Map) Custom response from the API.
9496
- `content` (String) Content of the response.

website/docs/r/cis_ruleset_entrypoint_version.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ Review the argument references that you can specify for your resource.
166166

167167
Nested scheme of `action parameters`
168168
- `id` (Required, String) ID of the managed ruleset to be deployed.
169+
- `ruleset` (Optional, String) Skips the remaining rules in the current ruleset. Allowed value is `current`.
170+
- `phases` (Optional, List) Skips the execution of one or more phases. Allowed values for phases are `http_ratelimit`, `http_request_sbfm`, `http_request_firewall_managed`.
171+
- `products` (Optional, List) Skips specific security products. Allowed values for products are `zoneLockdown`, `uaBlock`, `bic`, `hot`, `securityLevel`, `rateLimit`, `waf`.
169172
- `overrides` (Optional, List) Provides the parameters that are to be overridden.
170173

171174
Nested scheme of `overrides`

website/docs/r/cis_ruleset_rule.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ Review the argument references that you can specify for your resource.
108108
- `action_parameters` (Optional, List) Parameters that are used to modify the rules.
109109
Nested scheme of `action parameters`
110110
- `id` (Optional, String) ID of the managed ruleset to be deployed. It is not required in custom rule.
111+
- `ruleset` (Optional, String) Skips the remaining rules in the current ruleset. Allowed value is `current`.
112+
- `phases` (Optional, List) Skips the execution of one or more phases. Allowed values for phases are `http_ratelimit`, `http_request_sbfm`, `http_request_firewall_managed`.
113+
- `products` (Optional, List) Skips specific security products. Allowed values for products are `zoneLockdown`, `uaBlock`, `bic`, `hot`, `securityLevel`, `rateLimit`, `waf`.
111114
- `response` (Optional, Map). Custom response used for custom rules.
112115

113116
Nested scheme of `response`

0 commit comments

Comments
 (0)