File tree Expand file tree Collapse file tree 7 files changed +68
-1
lines changed
test_policies/private_auditors Expand file tree Collapse file tree 7 files changed +68
-1
lines changed Original file line number Diff line number Diff line change
1
+ __pycache__
Original file line number Diff line number Diff line change @@ -31,6 +31,13 @@ Custom config file (passed to [parliament](https://github.com/duo-labs/parliamen
31
31
32
32
** Default:** ''
33
33
34
+ ### private_auditors
35
+ Private auditors path (passed to [ parliament] ( https://github.com/duo-labs/parliament ) ).
36
+
37
+ ** Required:** False
38
+
39
+ ** Default:** ''
40
+
34
41
## Example usage
35
42
### Without specifying a path
36
43
```
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ POLICY_FILE_SUFFIX=${2:-"json"}
24
24
25
25
PARLIAMENT_MINIMUM_SEVERITY=${INPUT_MINIMUM_SEVERITY:- }
26
26
PARLIAMENT_CONFIG=${INPUT_CONFIG:- }
27
+ PARLIAMENT_PRIVATE_AUDITORS=${INPUT_PRIVATE_AUDITORS:- }
27
28
28
29
POLICY_FILES={}
29
30
PARLIAMENT_ARGS=()
@@ -38,6 +39,11 @@ if [[ -n "${PARLIAMENT_CONFIG}" ]]; then
38
39
PARLIAMENT_ARGS+=(" ${PARLIAMENT_CONFIG} " )
39
40
fi
40
41
42
+ if [[ -n " ${PARLIAMENT_PRIVATE_AUDITORS} " ]]; then
43
+ PARLIAMENT_ARGS+=(" --private_auditors" )
44
+ PARLIAMENT_ARGS+=(" ${PARLIAMENT_PRIVATE_AUDITORS} " )
45
+ fi
46
+
41
47
PARLIAMENT_VERSION=" $( python -c ' import pkg_resources; print(pkg_resources.get_distribution("parliament").version)' ) "
42
48
43
49
printf " Policy dir path: %s\n" " ${POLICY_DIR_PATH} "
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
+ )
Original file line number Diff line number Diff line change
1
+ {
2
+ "Version" : " 2012-10-17" ,
3
+ "Statement" : {
4
+ "Effect" : " Allow" ,
5
+ "Action" : " s3:GetObject" ,
6
+ "Resource" : " arn:aws:s3:::secretbucket/*"
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ ROOT=$(cd $(dirname $0)/../ >/dev/null; pwd)
5
5
TESTS_DIR=" ${ROOT} /tests"
6
6
TEST_POLICY_DIR=" ${ROOT} /tests/test_policies"
7
7
TEST_CONFIG_DIR=" ${ROOT} /tests/test_configs"
8
+ TEST_PRIVATE_AUDITORS_DIR=" ${ROOT} /tests/private_auditors"
8
9
9
10
oneTimeSetUp () {
10
11
cd ${ROOT}
@@ -46,10 +47,26 @@ testArgumentsConfig() {
46
47
" [ ${RC} -eq 1 ]"
47
48
assertTrue " --config custom_config.yml not in output" \
48
49
" [ $( 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 " \
50
51
" [ $( echo ${OUTPUT} | grep -c " HIGH - Unknown action" ) -eq 1 ]"
51
52
}
52
53
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
+
53
70
#
54
71
# Lint functionality tests
55
72
#
You can’t perform that action at this time.
0 commit comments