Skip to content

Commit

Permalink
fix more some lint issues and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturRibeiro-CX committed Nov 9, 2024
1 parent 2b316d2 commit 817f66e
Show file tree
Hide file tree
Showing 76 changed files with 285 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package Cx

import future.keywords.if
import future.keywords.in

CxPolicy[result] {
vm := input.document[i].playbooks[k].azure_rm_virtualmachine
some doc in input.document
vm := doc.playbooks[k].azure_rm_virtualmachine
is_linux_vm(vm)
not vm.ssh_password_enabled == false
not vm.linux_config.disable_password_authentication == false
result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": "azure_rm_virtualmachine",
"resourceName": vm.name,
"searchKey": sprintf("azure_rm_virtualmachine[%s].ssh_public_keys", [vm.name]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package Cx

import data.generic.ansible as ansLib
import future.keywords.in

CxPolicy[result] {
defaultsGroup := input.document[i].groups.defaults
some doc in input.document
defaultsGroup := doc.groups.defaults

defaultsGroup.allow_unsafe_lookups == true

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceName": "defaults",
"resourceType": "n/a",
"searchKey": "defaults.allow_unsafe_lookups",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package Cx

import data.generic.ansible as ansLib
import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
galaxyGroup := input.document[i].groups.galaxy
some doc in input.document
galaxyGroup := doc.groups.galaxy

url := galaxyGroup.server
startswith(url, "http://")

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": "n/a",
"resourceName": "n/a",
"searchKey": "[galaxy].server",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package Cx

import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
defaultsGroup := input.document[i].groups.defaults
some doc in input.document
defaultsGroup := doc.groups.defaults

not common_lib.valid_key(defaultsGroup, "no_log")

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"searchKey": "defaults",
"issueType": "IncorrectValue",
"resourceType": "n/a",
Expand All @@ -19,12 +21,13 @@ CxPolicy[result] {
}

CxPolicy[result] {
defaultsGroup := input.document[i].groups.defaults
some doc in input.document
defaultsGroup := doc.groups.defaults

defaultsGroup.no_log == false

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"searchKey": "defaults.no_log",
"issueType": "IncorrectValue",
"resourceType": "n/a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package Cx

import data.generic.azureresourcemanager as arm_lib
import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
doc := input.document[i]
some doc in input.document
[path, value] = walk(doc)

value.type == "microsoft.insights/logprofiles"
Expand All @@ -13,7 +14,7 @@ CxPolicy[result] {
all([category != "Write", category != "Delete", category != "Action"])

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": value.type,
"resourceName": value.name,
"searchKey": sprintf("%s.name={{%s}}.properties.categories", [common_lib.concat_path(path), value.name]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package Cx

import data.generic.azureresourcemanager as arm_lib
import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
doc := input.document[i]
some doc in input.document
[path, value] = walk(doc)

value.type == "Microsoft.Storage/storageAccounts"
Expand All @@ -16,7 +17,7 @@ CxPolicy[result] {
not contains_azure_service(bp_val)

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": value.type,
"resourceName": value.name,
"searchKey": sprintf("%s.name=%s.properties.networkAcls", [common_lib.concat_path(path), value.name]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package Cx

import data.generic.cloudformation as cf_lib
import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
document := input.document[i]
some document in input.document
some name in document.Resources
resource := document.Resources[name]
resource.Type == "AWS::CloudTrail::Trail"
attributes := {"CloudWatchLogsLogGroupArn", "CloudWatchLogsRoleArn"}
some a in attributes
attr := attributes[a]

not common_lib.valid_key(resource.Properties, attr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package Cx

import data.generic.cloudformation as cf_lib
import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
docs := input.document[i]
some docs in input.document
[path, Resources] := walk(docs)
resource := Resources[name]
resource.Type == "AWS::IAM::Role"

policy := resource.Properties.AssumeRolePolicyDocument
st := common_lib.get_statement(common_lib.get_policy(policy))
statement := st[_]
some statement in st

common_lib.is_allow_effect(statement)

Expand All @@ -22,7 +23,7 @@ CxPolicy[result] {
not common_lib.has_mfa(statement)

result := {
"documentId": input.document[i].id,
"documentId": docs.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, name),
"searchKey": sprintf("%s%s.Properties.AssumeRolePolicyDocument", [cf_lib.getPath(path), name]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import future.keywords.in

CxPolicy[result] {
some document in input.document
some key in document.Resources

resource := document.Resources[key]
resource.Type == "AWS::DynamoDB::Table"
properties := resource.Properties
Expand All @@ -26,8 +24,6 @@ CxPolicy[result] {

CxPolicy[result] {
some document in input.document
some key in document.Resources

resource := document.Resources[key]
resource.Type == "AWS::DynamoDB::Table"
properties := resource.Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package Cx

import data.generic.cloudformation as cf_lib
import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
document := input.document[i]
some document in input.document
some key in document.Resources
resource := document.Resources[key]
resource.Type == "AWS::EC2::Volume"

Expand All @@ -13,7 +15,7 @@ CxPolicy[result] {
not common_lib.valid_key(properties, "KmsKeyId")

result := {
"documentId": input.document[i].id,
"documentId": document.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, key),
"searchKey": sprintf("Resources.%s.Properties", [key]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package Cx
import data.generic.cloudformation as cf_lib

CxPolicy[result] {
document := input.document[i]
some document in input.document
some key in document.Resources

resource = document.Resources[key]
resource.Type == "AWS::EFS::FileSystem"
properties := resource.Properties
properties.Encrypted == false

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, key),
"searchKey": sprintf("Resources.%s.Properties.Encrypted", [key]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import future.keywords.in

CxPolicy[result] {
some document in input.document
some name in document.Resources

resource := document.Resources[name]
resource.Type = "AWS::ElastiCache::ReplicationGroup"
properties := resource.Properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package Cx

import data.generic.cloudformation as cf_lib
import future.keywords.in

CxPolicy[result] {
docs := input.document[i]
some docs in input.document
[path, Resources] := walk(docs)
some name in Resources

resource := Resources[name]
resource.Type == "AWS::RDS::DBInstance"
to_number(resource.Properties.BackupRetentionPeriod) == 0

result := {
"documentId": input.document[i].id,
"documentId": docs.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, name),
"searchKey": sprintf("%s%s.Properties.BackupRetentionPeriod", [cf_lib.getPath(path), name]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ package Cx

import data.generic.cloudformation as cf_lib
import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
docs := input.document[i]
some doc in input.document
[path, Resources] := walk(docs)
some key in Resources

resource := Resources[key]
resource.Type == "AWS::EC2::Route"

properties := resource.Properties
properties.DestinationCidrBlock == "0.0.0.0/0"

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, key),
"searchKey": sprintf("%s%s.Properties.DestinationCidrBlock", [cf_lib.getPath(path), key]),
Expand All @@ -24,16 +27,18 @@ CxPolicy[result] {
}

CxPolicy[result] {
docs := input.document[i]
some doc in input.document
[path, Resources] := walk(docs)
some key in Resources

resource := Resources[key]
resource.Type == "AWS::EC2::Route"

properties := resource.Properties
properties.DestinationIpv6CidrBlock == "::/0"

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, key),
"searchKey": sprintf("%s%s.Properties.DestinationIpv6CidrBlock", [cf_lib.getPath(path), key]),
Expand All @@ -44,16 +49,18 @@ CxPolicy[result] {
}

CxPolicy[result] {
docs := input.document[i]
some doc in input.document
[path, Resources] := walk(docs)
some key in Resources

resource := Resources[key]
resource.Type == "AWS::EC2::Route"

properties := resource.Properties
not common_lib.valid_key(properties, "NatGatewayId")

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, key),
"searchKey": sprintf("%s%s.Properties", [cf_lib.getPath(path), key]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package Cx

import data.generic.cloudformation as cf_lib
import future.keywords.in

CxPolicy[result] {
docs := input.document[i]
some doc in input.document
[path, Resources] := walk(docs)
some name in Resources

resource := Resources[name]
properties := resource.Properties
resource.Type == "AWS::S3::Bucket"
properties.AccessControl == "PublicReadWrite"

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, name),
"searchKey": sprintf("%s%s.AccessControl", [cf_lib.getPath(path), name]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ package Cx

import data.generic.cloudformation as cf_lib
import data.generic.common as common_lib
import future.keywords.in

CxPolicy[result] {
docs := input.document[i]
some doc in input.document
[path, Resources] := walk(docs)
some name in Resources

resource := Resources[name]
resource.Type == "AWS::S3::BucketPolicy"

policy := resource.Properties.PolicyDocument
st := common_lib.get_statement(common_lib.get_policy(policy))
statement := st[_]
some statement in st
common_lib.is_allow_effect(statement)
common_lib.equalsOrInArray(statement.Principal, "*")
cf_lib.checkAction(statement.Action, "delete")

result := {
"documentId": input.document[i].id,
"documentId": doc.id,
"resourceType": resource.Type,
"resourceName": cf_lib.get_resource_name(resource, name),
"searchKey": sprintf("%s%s.Properties.PolicyDocument", [cf_lib.getPath(path), name]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import future.keywords.in
CxPolicy[result] {
some doc in input.document
[path, Resources] := walk(docs)
some name in Resources
resource := Resources[name]
resource.Type == "AWS::S3::Bucket"
prop := resource.Properties
Expand Down
Loading

0 comments on commit 817f66e

Please sign in to comment.