forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(query): Added Lifecycle_rule Disabled Query for Alicloud Terrafo…
…rm (Checkmarx#4935) * Added lifecycle_rule disabled query * Changed query
- Loading branch information
1 parent
446bdd0
commit 2b22cf0
Showing
6 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
assets/queries/terraform/alicloud/oss_bucket_lifecycle_disabled/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "7db8bd7e-9772-478c-9ec5-4bc202c5686f", | ||
"queryName": "OSS Bucket Lifecycle Rule Disabled", | ||
"severity": "LOW", | ||
"category": "Backup", | ||
"descriptionText": "OSS Bucket should have lifecycle rule enabled and set to true", | ||
"descriptionUrl": "https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/oss_bucket#lifecycle_rule", | ||
"platform": "Terraform", | ||
"descriptionID": "66609561", | ||
"cloudProvider": "alicloud" | ||
} |
35 changes: 35 additions & 0 deletions
35
assets/queries/terraform/alicloud/oss_bucket_lifecycle_disabled/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
|
||
CxPolicy[result] { | ||
some i | ||
resource := input.document[i].resource.alicloud_oss_bucket[name].lifecycle_rule[_] | ||
|
||
resource["enabled"] == false | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("alicloud_oss_bucket[%s].lifecycle_rule.enabled", [name]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "'lifecycle_rule' is set and enabled", | ||
"keyActualValue": "'lifecycle_rule' is set but disabled", | ||
"searchline":common_lib.build_search_line(["resource", "alicloud_oss_bucket", name, "lifecycle_rule", "enabled"], []), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
some i | ||
resource := input.document[i].resource.alicloud_oss_bucket[name] | ||
|
||
not common_lib.valid_key(resource, "lifecycle_rule") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("alicloud_oss_bucket[%s]", [name]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": "'lifecycle_rule' is set and enabled", | ||
"keyActualValue": "'lifecycle_rule' is not set", | ||
"searchline":common_lib.build_search_line(["resource", "alicloud_oss_bucket", name], []), | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
assets/queries/terraform/alicloud/oss_bucket_lifecycle_disabled/test/negative1.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
resource "alicloud_oss_bucket" "oss_bucket_lifecycle_enabled1" { | ||
bucket = "bucket-170309-lifecycle" | ||
acl = "public-read" | ||
|
||
lifecycle_rule { | ||
id = "rule-days" | ||
prefix = "path1/" | ||
enabled = true | ||
|
||
expiration { | ||
days = 365 | ||
} | ||
} | ||
lifecycle_rule { | ||
id = "rule-date" | ||
prefix = "path2/" | ||
enabled = true | ||
|
||
expiration { | ||
date = "2018-01-12" | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
assets/queries/terraform/alicloud/oss_bucket_lifecycle_disabled/test/positive1.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
resource "alicloud_oss_bucket" "oss_bucket_lifecycle_enabled2" { | ||
bucket = "bucket-170309-lifecycle" | ||
acl = "public-read" | ||
|
||
lifecycle_rule { | ||
id = "rule-days" | ||
prefix = "path1/" | ||
enabled = false | ||
|
||
expiration { | ||
days = 365 | ||
} | ||
} | ||
lifecycle_rule { | ||
id = "rule-date" | ||
prefix = "path2/" | ||
enabled = true | ||
|
||
expiration { | ||
date = "2018-01-12" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
assets/queries/terraform/alicloud/oss_bucket_lifecycle_disabled/test/positive2.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "alicloud_oss_bucket" "oss_bucket_lifecycle_enabled3" { | ||
bucket = "bucket-170309-versioning" | ||
acl = "private" | ||
|
||
versioning { | ||
status = "Enabled" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...eries/terraform/alicloud/oss_bucket_lifecycle_disabled/test/positive_expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ | ||
{ | ||
"queryName": "OSS Bucket Lifecycle Rule Disabled", | ||
"severity": "LOW", | ||
"line": 8, | ||
"fileName": "positive1.tf" | ||
}, | ||
{ | ||
"queryName": "OSS Bucket Lifecycle Rule Disabled", | ||
"severity": "LOW", | ||
"line": 1, | ||
"fileName": "positive2.tf" | ||
} | ||
] | ||
|