-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathaction.yml
More file actions
153 lines (134 loc) · 4.78 KB
/
Copy pathaction.yml
File metadata and controls
153 lines (134 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: "cloud-audit - AWS Security Scanner"
description: "Scan your AWS account for security misconfigurations with attack chain detection, Terraform remediation, and SARIF output"
branding:
icon: shield
color: blue
inputs:
cloud-audit-version:
description: "Pin cloud-audit to a specific PyPI version (e.g. 2.3.0). Default matches the action's release tag for reproducible builds."
required: false
default: "2.3.0"
format:
description: "Output format: sarif, json, html, markdown"
required: false
default: "sarif"
output:
description: "Output file path"
required: false
default: "results.sarif"
regions:
description: "Comma-separated AWS regions to scan (empty = default region)"
required: false
default: ""
remediation:
description: "Show remediation details in console output"
required: false
default: "false"
fail-on-findings:
description: "Fail the workflow if security findings are detected"
required: false
default: "true"
diff-baseline:
description: "Path to a baseline scan JSON file for diff comparison"
required: false
default: ""
extra-args:
description: "Additional arguments passed to cloud-audit scan"
required: false
default: ""
runs:
using: "composite"
steps:
- name: Install cloud-audit
shell: bash
env:
CLOUD_AUDIT_VERSION: ${{ inputs.cloud-audit-version }}
run: |
if [ -z "$CLOUD_AUDIT_VERSION" ]; then
echo "::error::cloud-audit-version input must not be empty"
exit 2
fi
# Reject anything outside [0-9A-Za-z.+-] to prevent injection via pip spec
case "$CLOUD_AUDIT_VERSION" in
*[!0-9A-Za-z.+\-]*)
echo "::error::Refusing to install cloud-audit==$CLOUD_AUDIT_VERSION - illegal characters in version"
exit 2
;;
esac
pip install "cloud-audit==${CLOUD_AUDIT_VERSION}"
- name: Run cloud-audit scan
id: scan
shell: bash
env:
INPUT_FORMAT: ${{ inputs.format }}
INPUT_OUTPUT: ${{ inputs.output }}
INPUT_REGIONS: ${{ inputs.regions }}
INPUT_REMEDIATION: ${{ inputs.remediation }}
INPUT_FAIL_ON_FINDINGS: ${{ inputs.fail-on-findings }}
INPUT_EXTRA_ARGS: ${{ inputs.extra-args }}
run: |
set +e
ARGS=(--provider aws --format "$INPUT_FORMAT" --output "$INPUT_OUTPUT")
if [ -n "$INPUT_REGIONS" ]; then
ARGS+=(--regions "$INPUT_REGIONS")
fi
if [ "$INPUT_REMEDIATION" = "true" ]; then
ARGS+=(--remediation)
fi
# Word-split extra-args on whitespace into argv entries. The values stay in
# argv (not the shell), so a malicious workflow author can pass odd flags
# but cannot break out of the cloud-audit invocation.
if [ -n "$INPUT_EXTRA_ARGS" ]; then
read -r -a EXTRA <<< "$INPUT_EXTRA_ARGS"
ARGS+=("${EXTRA[@]}")
fi
cloud-audit scan "${ARGS[@]}"
EXIT_CODE=$?
echo "exit-code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
# Exit code 2 = scan error (always fail)
if [ $EXIT_CODE -eq 2 ]; then
echo "::error::cloud-audit scan failed with errors"
exit 2
fi
# Exit code 1 = findings detected
if [ $EXIT_CODE -eq 1 ]; then
if [ "$INPUT_FAIL_ON_FINDINGS" != "true" ]; then
echo "::warning::Security findings detected - see results for details"
exit 0
fi
exit 1
fi
exit 0
- name: Run cloud-audit diff
if: inputs.diff-baseline != ''
id: diff
shell: bash
env:
INPUT_FORMAT: ${{ inputs.format }}
INPUT_OUTPUT: ${{ inputs.output }}
INPUT_REGIONS: ${{ inputs.regions }}
INPUT_DIFF_BASELINE: ${{ inputs.diff-baseline }}
run: |
set +e
# For diff, we need a JSON scan. Re-run if the primary format was not JSON.
CURRENT_JSON="$INPUT_OUTPUT"
if [ "$INPUT_FORMAT" != "json" ]; then
CURRENT_JSON="current-scan.json"
DIFF_ARGS=(--provider aws --format json --output "$CURRENT_JSON")
if [ -n "$INPUT_REGIONS" ]; then
DIFF_ARGS+=(--regions "$INPUT_REGIONS")
fi
cloud-audit scan "${DIFF_ARGS[@]}" || true
fi
cloud-audit diff "$INPUT_DIFF_BASELINE" "$CURRENT_JSON"
EXIT_CODE=$?
echo "diff-exit-code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
if [ $EXIT_CODE -eq 1 ]; then
echo "::warning::New security findings detected compared to baseline"
fi
- name: Upload SARIF to GitHub Security tab
if: inputs.format == 'sarif' && always()
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: ${{ inputs.output }}
wait-for-processing: true