Skip to content

Commit

Permalink
Add support for passing private auditors (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0l authored Feb 18, 2020
1 parent ce76d51 commit 8538b60
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Custom config file (passed to [parliament](https://github.com/duo-labs/parliamen

**Default:** ''

### private_auditors
Private auditors path (passed to [parliament](https://github.com/duo-labs/parliament)).

**Required:** False

**Default:** ''

## Example usage
### Without specifying a path
```
Expand Down
6 changes: 6 additions & 0 deletions iam-lint
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ POLICY_FILE_SUFFIX=${2:-"json"}

PARLIAMENT_MINIMUM_SEVERITY=${INPUT_MINIMUM_SEVERITY:-}
PARLIAMENT_CONFIG=${INPUT_CONFIG:-}
PARLIAMENT_PRIVATE_AUDITORS=${INPUT_PRIVATE_AUDITORS:-}

POLICY_FILES={}
PARLIAMENT_ARGS=()
Expand All @@ -38,6 +39,11 @@ if [[ -n "${PARLIAMENT_CONFIG}" ]]; then
PARLIAMENT_ARGS+=("${PARLIAMENT_CONFIG}")
fi

if [[ -n "${PARLIAMENT_PRIVATE_AUDITORS}" ]]; then
PARLIAMENT_ARGS+=("--private_auditors")
PARLIAMENT_ARGS+=("${PARLIAMENT_PRIVATE_AUDITORS}")
fi

PARLIAMENT_VERSION="$(python -c 'import pkg_resources; print(pkg_resources.get_distribution("parliament").version)')"

printf "Policy dir path: %s\n" "${POLICY_DIR_PATH}"
Expand Down
5 changes: 5 additions & 0 deletions tests/private_auditors/config_override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SENSITIVE_BUCKET_ACCESS:
title: Sensitive bucket access
description: Allows read access to an important S3 bucket
severity: MEDIUM
group: CUSTOM
23 changes: 23 additions & 0 deletions tests/private_auditors/sensitive_bucket_access.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from parliament import is_arn_match, expand_action


def audit(policy):
action_resources = {}
for action in expand_action("s3:*"):
# Iterates through a list of containing elements such as
# {'service': 's3', 'action': 'GetObject'}
action_name = "{}:{}".format(action["service"], action["action"])
action_resources[action_name] = policy.get_allowed_resources(
action["service"], action["action"]
)

for action_name in action_resources:
resources = action_resources[action_name]
for r in resources:
if is_arn_match("object", "arn:aws:s3:::secretbucket*", r) or is_arn_match(
"object", "arn:aws:s3:::othersecretbucket*", r
):
policy.add_finding(
"SENSITIVE_BUCKET_ACCESS",
location={"action": action_name, "resource": r},
)
8 changes: 8 additions & 0 deletions tests/test_policies/private_auditors/policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::secretbucket/*"
}
}
19 changes: 18 additions & 1 deletion tests/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ROOT=$(cd $(dirname $0)/../ >/dev/null; pwd)
TESTS_DIR="${ROOT}/tests"
TEST_POLICY_DIR="${ROOT}/tests/test_policies"
TEST_CONFIG_DIR="${ROOT}/tests/test_configs"
TEST_PRIVATE_AUDITORS_DIR="${ROOT}/tests/private_auditors"

oneTimeSetUp() {
cd ${ROOT}
Expand Down Expand Up @@ -46,10 +47,26 @@ testArgumentsConfig() {
"[ ${RC} -eq 1 ]"
assertTrue "--config custom_config.yml not in output" \
"[ $(echo ${OUTPUT} | grep -c -- "--config /config_override.yaml") -eq 1 ]"
assertTrue "config severity override didn't work" \
assertTrue "config severity override didn't work as expected" \
"[ $(echo ${OUTPUT} | grep -c "HIGH - Unknown action") -eq 1 ]"
}

testArgumentsPrivateAuditors() {
OUTPUT="$(docker run -e INPUT_PRIVATE_AUDITORS=private_auditors \
-e INPUT_CONFIG=private_auditors/config_override.yaml \
-v ${TEST_POLICY_DIR}/private_auditors:/src \
-v ${TEST_PRIVATE_AUDITORS_DIR}:/private_auditors \
iam-lint /src)"
RC=$?

assertTrue "iam-lint exited with a different return code than expected: ${RC}" \
"[ ${RC} -eq 1 ]"
assertTrue "--private_auditors private_auditors not in output" \
"[ $(echo ${OUTPUT} | grep -c -- "--private_auditors private_auditors") -eq 1 ]"
assertTrue "private_auditors didn't work as expected" \
"[ $(echo ${OUTPUT} | grep -c "MEDIUM - Sensitive bucket access") -eq 1 ]"
}

#
# Lint functionality tests
#
Expand Down

0 comments on commit 8538b60

Please sign in to comment.