Skip to content

Commit

Permalink
Add query to check if there isnt a ConfigRule for Encrypted Volumes C…
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomartinscx authored Mar 26, 2021
1 parent 8a701e9 commit 490ee46
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 4 deletions.
4 changes: 4 additions & 0 deletions assets/libraries/cloudformation/library.rego
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
package generic.cloudformation

getResourcesByType(resources, type) = list {
list = [resource | resources[i].Type == type; resource := resources[i]]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "7674a686-e4b1-4a95-83d4-1fd53c623d84",
"queryName": "Config Rule For Encrypted Volumes Is Disabled",
"queryName": "Config Rule For Encrypted Volumes Disabled",
"severity": "MEDIUM",
"category": "Encryption",
"descriptionText": "Check if AWS config rules do not identify Encrypted Volumes as a source.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"queryName": "Config Rule For Encrypted Volumes Is Disabled",
"queryName": "Config Rule For Encrypted Volumes Disabled",
"severity": "MEDIUM",
"line": 2
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "1b6322d9-c755-4f8c-b804-32c19250f2d9",
"queryName": "Config Rule For Encrypted Volumes Disabled",
"severity": "MEDIUM",
"category": "Encryption",
"descriptionText": "Check if AWS config rules do not identify Encrypted Volumes as a source.",
"descriptionUrl": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-config-configrule.html#cfn-config-configrule-source",
"platform": "CloudFormation"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Cx

import data.generic.cloudformation as cfLib

CxPolicy[result] {
resources := input.document[i].Resources
configRules := cfLib.getResourcesByType(resources, "AWS::Config::ConfigRule")

count(configRules) > 0
not hasEncryptedVolsRule(configRules)

firstRule := resources[name]
firstRule.Type == "AWS::Config::ConfigRule"

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("Resources.%s", [name]),
"issueType": "MissingAttribute",
"keyExpectedValue": "There is a ConfigRule for encrypted volumes.",
"keyActualValue": "There isn't a ConfigRule for encrypted volumes."
}
}

hasEncryptedVolsRule(configRules) {
configRule := configRules[_]
source := configRule.Properties.Source
source_id := source.SourceIdentifier
source_id == "ENCRYPTED_VOLUMES"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Resources:
ConfigRule:
Type: AWS::Config::ConfigRule
Properties:
ConfigRuleName: access-keys-rotated
InputParameters:
maxAccessKeyAge: 90
Source:
Owner: AWS
SourceIdentifier: ENCRYPTED_VOLUMES
MaximumExecutionFrequency: TwentyFour_Hours

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Resources": {
"ConfigRule": {
"Type": "AWS::Config::ConfigRule",
"Properties": {
"MaximumExecutionFrequency": "TwentyFour_Hours",
"ConfigRuleName": "access-keys-rotated",
"InputParameters": {
"maxAccessKeyAge": 90
},
"Source": {
"SourceIdentifier": "ENCRYPTED_VOLUMES",
"Owner": "AWS"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Resources:
ConfigRule:
Type: AWS::Config::ConfigRule
Properties:
ConfigRuleName: access-keys-rotated
InputParameters:
maxAccessKeyAge: 100
Source:
Owner: AWS
SourceIdentifier: ACCESS_KEYS_ROTATED
MaximumExecutionFrequency: TwentyFour_Hours

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Resources": {
"ConfigRule": {
"Type": "AWS::Config::ConfigRule",
"Properties": {
"ConfigRuleName": "access-keys-rotated",
"InputParameters": {
"maxAccessKeyAge": 100
},
"Source": {
"Owner": "AWS",
"SourceIdentifier": "ACCESS_KEYS_ROTATED"
},
"MaximumExecutionFrequency": "TwentyFour_Hours"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"queryName": "Config Rule For Encrypted Volumes Disabled",
"severity": "MEDIUM",
"line": 2,
"fileName": "positive1.yaml"
},
{
"fileName": "positive2.json",
"queryName": "Config Rule For Encrypted Volumes Disabled",
"severity": "MEDIUM",
"line": 3
}
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "abdb29d4-5ca1-4e91-800b-b3569bbd788c",
"queryName": "Config Rule For Encrypted Volumes Is Disabled",
"queryName": "Config Rule For Encrypted Volumes Disabled",
"severity": "MEDIUM",
"category": "Encryption",
"descriptionText": "Check if AWS config rules do not identify Encrypted Volumes as a source.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"queryName": "Config Rule For Encrypted Volumes Is Disabled",
"queryName": "Config Rule For Encrypted Volumes Disabled",
"severity": "MEDIUM",
"line": 1
}
Expand Down

0 comments on commit 490ee46

Please sign in to comment.