Skip to content

Commit 8538b60

Browse files
authored
Add support for passing private auditors (#5)
1 parent ce76d51 commit 8538b60

File tree

7 files changed

+68
-1
lines changed

7 files changed

+68
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ Custom config file (passed to [parliament](https://github.com/duo-labs/parliamen
3131

3232
**Default:** ''
3333

34+
### private_auditors
35+
Private auditors path (passed to [parliament](https://github.com/duo-labs/parliament)).
36+
37+
**Required:** False
38+
39+
**Default:** ''
40+
3441
## Example usage
3542
### Without specifying a path
3643
```

iam-lint

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ POLICY_FILE_SUFFIX=${2:-"json"}
2424

2525
PARLIAMENT_MINIMUM_SEVERITY=${INPUT_MINIMUM_SEVERITY:-}
2626
PARLIAMENT_CONFIG=${INPUT_CONFIG:-}
27+
PARLIAMENT_PRIVATE_AUDITORS=${INPUT_PRIVATE_AUDITORS:-}
2728

2829
POLICY_FILES={}
2930
PARLIAMENT_ARGS=()
@@ -38,6 +39,11 @@ if [[ -n "${PARLIAMENT_CONFIG}" ]]; then
3839
PARLIAMENT_ARGS+=("${PARLIAMENT_CONFIG}")
3940
fi
4041

42+
if [[ -n "${PARLIAMENT_PRIVATE_AUDITORS}" ]]; then
43+
PARLIAMENT_ARGS+=("--private_auditors")
44+
PARLIAMENT_ARGS+=("${PARLIAMENT_PRIVATE_AUDITORS}")
45+
fi
46+
4147
PARLIAMENT_VERSION="$(python -c 'import pkg_resources; print(pkg_resources.get_distribution("parliament").version)')"
4248

4349
printf "Policy dir path: %s\n" "${POLICY_DIR_PATH}"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SENSITIVE_BUCKET_ACCESS:
2+
title: Sensitive bucket access
3+
description: Allows read access to an important S3 bucket
4+
severity: MEDIUM
5+
group: CUSTOM
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from parliament import is_arn_match, expand_action
2+
3+
4+
def audit(policy):
5+
action_resources = {}
6+
for action in expand_action("s3:*"):
7+
# Iterates through a list of containing elements such as
8+
# {'service': 's3', 'action': 'GetObject'}
9+
action_name = "{}:{}".format(action["service"], action["action"])
10+
action_resources[action_name] = policy.get_allowed_resources(
11+
action["service"], action["action"]
12+
)
13+
14+
for action_name in action_resources:
15+
resources = action_resources[action_name]
16+
for r in resources:
17+
if is_arn_match("object", "arn:aws:s3:::secretbucket*", r) or is_arn_match(
18+
"object", "arn:aws:s3:::othersecretbucket*", r
19+
):
20+
policy.add_finding(
21+
"SENSITIVE_BUCKET_ACCESS",
22+
location={"action": action_name, "resource": r},
23+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": {
4+
"Effect": "Allow",
5+
"Action": "s3:GetObject",
6+
"Resource": "arn:aws:s3:::secretbucket/*"
7+
}
8+
}

tests/tests.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ROOT=$(cd $(dirname $0)/../ >/dev/null; pwd)
55
TESTS_DIR="${ROOT}/tests"
66
TEST_POLICY_DIR="${ROOT}/tests/test_policies"
77
TEST_CONFIG_DIR="${ROOT}/tests/test_configs"
8+
TEST_PRIVATE_AUDITORS_DIR="${ROOT}/tests/private_auditors"
89

910
oneTimeSetUp() {
1011
cd ${ROOT}
@@ -46,10 +47,26 @@ testArgumentsConfig() {
4647
"[ ${RC} -eq 1 ]"
4748
assertTrue "--config custom_config.yml not in output" \
4849
"[ $(echo ${OUTPUT} | grep -c -- "--config /config_override.yaml") -eq 1 ]"
49-
assertTrue "config severity override didn't work" \
50+
assertTrue "config severity override didn't work as expected" \
5051
"[ $(echo ${OUTPUT} | grep -c "HIGH - Unknown action") -eq 1 ]"
5152
}
5253

54+
testArgumentsPrivateAuditors() {
55+
OUTPUT="$(docker run -e INPUT_PRIVATE_AUDITORS=private_auditors \
56+
-e INPUT_CONFIG=private_auditors/config_override.yaml \
57+
-v ${TEST_POLICY_DIR}/private_auditors:/src \
58+
-v ${TEST_PRIVATE_AUDITORS_DIR}:/private_auditors \
59+
iam-lint /src)"
60+
RC=$?
61+
62+
assertTrue "iam-lint exited with a different return code than expected: ${RC}" \
63+
"[ ${RC} -eq 1 ]"
64+
assertTrue "--private_auditors private_auditors not in output" \
65+
"[ $(echo ${OUTPUT} | grep -c -- "--private_auditors private_auditors") -eq 1 ]"
66+
assertTrue "private_auditors didn't work as expected" \
67+
"[ $(echo ${OUTPUT} | grep -c "MEDIUM - Sensitive bucket access") -eq 1 ]"
68+
}
69+
5370
#
5471
# Lint functionality tests
5572
#

0 commit comments

Comments
 (0)