This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support for CloudFormation * [RM-5219] Skip cloudtrail_s3_data_logging rules in templates without trails (#78) * [RM-5229] Docker image & bin/regula fixes * [RM-5269] Standardization (#80) * [RM-5269] Standardize package structure * [RM-5269] Standardize test package names and structure * [RM-5269] Fix regula report test import * [RM-5269] Re-organize cfn/aws -> cfn * [RM-5269] Update check-naming script and fix violations * Update README.md (#81) * Add git to Dockerfile for terraform module support (#83) * Update changelog for v0.6.0 release Co-authored-by: Jasper Van der Jeugt <[email protected]> Co-authored-by: fugue-chris <[email protected]>
- Loading branch information
1 parent
1858f03
commit bdf29b6
Showing
323 changed files
with
13,948 additions
and
870 deletions.
There are no files selected for viewing
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 @@ | ||
*.cfn linguist-language=YAML |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.terraform/ | ||
.DS_Store | ||
venv/ |
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
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,31 @@ | ||
FROM python:3.9.2-alpine3.13 | ||
|
||
# We need bash for the main regula script since it uses arrays. | ||
# We need git to support terraform modules | ||
RUN apk add --update bash git && rm -rf /var/cache/apk/* | ||
|
||
# Install OPA. | ||
ARG OPA_VERSION=0.26.0 | ||
RUN wget -O '/usr/local/bin/opa' \ | ||
"https://github.com/open-policy-agent/opa/releases/download/v${OPA_VERSION}/opa_linux_amd64" &&\ | ||
chmod +x '/usr/local/bin/opa' | ||
|
||
# Install terraform. | ||
ARG TERRAFORM_VERSION=0.14.7 | ||
ENV TF_IN_AUTOMATION=true | ||
RUN wget -O "/tmp/terraform-${TERRAFORM_VERSION}.zip" \ | ||
"https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" && \ | ||
unzip -d '/usr/local/bin' "/tmp/terraform-${TERRAFORM_VERSION}.zip" &&\ | ||
rm "/tmp/terraform-${TERRAFORM_VERSION}.zip" | ||
|
||
# Install cfn-flip | ||
ARG CFNFLIP_VERSION=1.2.3 | ||
RUN pip install "cfn-flip==${CFNFLIP_VERSION}" | ||
|
||
# Update regula files | ||
RUN mkdir -p /opt/regula | ||
COPY lib /opt/regula/lib | ||
COPY rules /opt/regula/rules | ||
COPY bin/regula /usr/local/bin | ||
|
||
ENTRYPOINT ["regula", "-", "/opt/regula"] |
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
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
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
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
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
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,42 @@ | ||
# Copyright 2020-2021 Fugue, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
package fugue.cfn.cloudtrail | ||
|
||
import data.fugue.cfn.s3 | ||
|
||
data_resource_value_matches_bucket(value, bucket) { | ||
s3.matches_bucket_name_or_id(bucket, value) | ||
} { | ||
is_string(value) | ||
value == "arn:aws:s3:::" | ||
} { | ||
is_string(value) | ||
# Workaround for fregot issue: we get a Subtype error from the concat() call if we | ||
# just use bucket.BucketName. The type checking seems to work as expected if we | ||
# pull bucket.BucketName out into its own variable. | ||
name := bucket.BucketName | ||
is_string(name) | ||
pattern := concat("", ["arn:aws:s3:::", name, "(/.*)?$"]) | ||
regex.match(pattern, value) | ||
} { | ||
is_array(value) | ||
s3.matches_bucket_name_or_id(bucket, value[_]) | ||
} | ||
|
||
event_selector_applies_to_bucket(event_selector, bucket) { | ||
data_resource := event_selector.DataResources[_] | ||
data_resource.Type == "AWS::S3::Object" | ||
value := data_resource.Values[_] | ||
data_resource_value_matches_bucket(value, bucket) | ||
} |
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,31 @@ | ||
# Copyright 2020-2021 Fugue, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
package fugue.cfn.lambda_library | ||
|
||
matches_function_name_or_id(function, value) { | ||
value == function.id | ||
} { | ||
value == function.FunctionName | ||
} | ||
|
||
function_name_matches_function(function, function_name) { | ||
matches_function_name_or_id(function, function_name) | ||
} { | ||
is_string(function_name) | ||
parts := split(function_name, ":") | ||
matches_function_name_or_id(function, parts[_]) | ||
} { | ||
is_array(function_name) | ||
matches_function_name_or_id(function, function_name[_]) | ||
} |
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,66 @@ | ||
# Copyright 2020-2021 Fugue, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
package cfn.nacl_library | ||
|
||
import data.fugue | ||
|
||
nacl_entries = fugue.resources("AWS::EC2::NetworkAclEntry") | ||
nacl_ingress_by_id = {nacl_id: entries | | ||
nacl_id = nacl_entries[_].NetworkAclId | ||
entries = [entry | | ||
entry = nacl_entries[_] | ||
entry.NetworkAclId == nacl_id | ||
object.get(entry, "Egress", false) == false | ||
] | ||
} | ||
|
||
# Returns true if the NACL entry has an all-zero CIDR. | ||
nacl_entry_zero_cidr(entry) { | ||
entry.CidrBlock == "0.0.0.0/0" | ||
} { | ||
entry.Ipv6CidrBlock == "::/0" | ||
} | ||
|
||
# Returns true if the NACL entry includes the given port | ||
nacl_entry_includes_port(entry, port) { | ||
entry.Protocol == -1 | ||
} { | ||
entry.PortRange.From == 0 | ||
entry.PortRange.To == 0 | ||
} { | ||
entry.PortRange.From <= port | ||
entry.PortRange.To >= port | ||
} | ||
|
||
# Check if there is a NACL entry that allows the given port from an all-zero | ||
# CIDR. | ||
nacl_ingress_zero_cidr_to_port(nacl_id, port) { | ||
entries := [entry | | ||
entry = nacl_ingress_by_id[nacl_id][_] | ||
nacl_entry_zero_cidr(entry) | ||
nacl_entry_includes_port(entry, port) | ||
] | ||
|
||
allows := [entry.RuleNumber | entry = entries[_]; entry.RuleAction == "allow"] | ||
denies := [entry.RuleNumber | entry = entries[_]; entry.RuleAction == "deny"] | ||
|
||
allow_precedes_denies(allows, denies) | ||
} | ||
|
||
allow_precedes_denies(allows, denies) { | ||
_ = allows[_] | ||
count(denies) == 0 | ||
} { | ||
min(allows) < min(denies) | ||
} |
Oops, something went wrong.