Skip to content

Commit a62354b

Browse files
Added integration tests and updated documentation (#9)
Added integration tests and also updated documentation. --------- Co-authored-by: Adish Agarwal <[email protected]>
1 parent c40631e commit a62354b

File tree

6 files changed

+1328
-60
lines changed

6 files changed

+1328
-60
lines changed

.github/workflows/test.yml

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,139 @@ jobs:
5454
- name: 'npm test'
5555
run: 'npm run test'
5656

57-
## TODO : Add functionality specific test
57+
integration:
58+
permissions:
59+
contents: 'read'
60+
id-token: 'write'
61+
runs-on: 'ubuntu-latest'
62+
63+
env:
64+
ORGANIZATION_ID: '777838403257'
65+
66+
steps:
67+
- uses: 'actions/checkout@v4'
68+
69+
- uses: 'actions/setup-node@v4'
70+
with:
71+
node-version: '20.x'
72+
73+
- name: 'npm build'
74+
run: 'npm ci && npm run build'
75+
76+
- uses: 'google-github-actions/auth@v2'
77+
with:
78+
workload_identity_provider: 'projects/111685897256/locations/global/workloadIdentityPools/github/providers/my-repo'
79+
service_account: '[email protected]'
80+
81+
- id: 'violations-found'
82+
name: 'Violations found in plan file'
83+
uses: './'
84+
with:
85+
organization_id: '${{ env.ORGANIZATION_ID }}'
86+
# plan file has 1 CRITICAL, 2 LOW severity vulnerabilites
87+
scan_file_ref: 'test/resources/with-violations-tf_plan.json'
88+
iac_type: 'terraform'
89+
iac_version: '1.0.0'
90+
failure_criteria: 'CRITICAL:2, Operator:OR'
91+
ignore_violations: 'false'
92+
fail_silently: 'false'
93+
scan_timeout: '1m'
94+
- name: 'Check scan result and compare sarif report generated.'
95+
run: |
96+
report_expected="test/resources/sarif.json"
97+
report_generated="${{ steps.violations-found.outputs.iac_scan_result_sarif_path }}"
98+
if cmp -s "$report_expected" "$report_generated"; then
99+
exit 1
100+
fi
101+
if [ "${{ steps.violations-found.outputs.iac_scan_result }}" != "passed" ]; then
102+
exit 1
103+
fi
104+
105+
- id: 'no-violations-found'
106+
name: 'No violations found in plan file'
107+
uses: './'
108+
with:
109+
organization_id: '${{ env.ORGANIZATION_ID }}'
110+
scan_file_ref: 'test/resources/no-violations-tf_plan.json'
111+
iac_type: 'terraform'
112+
iac_version: '1.0.0'
113+
failure_criteria: 'CRITICAL:2, Operator:OR'
114+
- name: 'Check scan result and report not generated.'
115+
run: |
116+
if [ "${{ steps.no-violations-found.outputs.iac_scan_result_sarif_path }}" != "" ]; then
117+
exit 1
118+
fi
119+
if [ "${{ steps.no-violations-found.outputs.iac_scan_result }}" != "passed" ]; then
120+
exit 1
121+
fi
122+
123+
- id: 'failure-criteria-satisfied'
124+
name: 'Failure criteria satisfied'
125+
uses: './'
126+
with:
127+
organization_id: '${{ env.ORGANIZATION_ID }}'
128+
# plan file has 1 CRITICAL, 2 LOW severity vulnerabilites
129+
scan_file_ref: 'test/resources/with-violations-tf_plan.json'
130+
iac_type: 'terraform'
131+
iac_version: '1.0.0'
132+
failure_criteria: 'CRITICAL:1, Operator:OR'
133+
continue-on-error: true
134+
- name: 'Check scan result and action build status'
135+
run: |
136+
if [ "${{ steps.failure-criteria-satisfied.outputs.iac_scan_result }}" != "failed" ]; then
137+
exit 1
138+
fi
139+
if [ "${{ steps.failure-criteria-satisfied.outcome }}" != "failure"]; then
140+
exit 1
141+
fi
142+
143+
- id: 'failure-criteria-satisfied-ignore-violations-true'
144+
name: 'Failure criteria satisfied, ignore violations true'
145+
uses: './'
146+
with:
147+
organization_id: '${{ env.ORGANIZATION_ID }}'
148+
# plan file has 1 CRITICAL, 2 LOW severity vulnerabilites
149+
scan_file_ref: 'test/resources/with-violations-tf_plan.json'
150+
iac_type: 'terraform'
151+
iac_version: '1.0.0'
152+
ignore_violations: 'true'
153+
failure_criteria: 'CRITICAL:1, Operator:OR'
154+
- name: 'Check scan result'
155+
run: |
156+
if [ "${{ steps.failure-criteria-satisfied-ignore-violations-true.outputs.iac_scan_result }}" != "failed" ]; then
157+
exit 1
158+
fi
159+
160+
- id: 'action-internal-error'
161+
name: 'Action internal error'
162+
uses: './'
163+
with:
164+
# Invalid org id, will cause an internal error in action
165+
organization_id: 'invalid-id'
166+
scan_file_ref: 'test/resources/with-violations-tf_plan.json'
167+
iac_type: 'terraform'
168+
iac_version: '1.0.0'
169+
continue-on-error: true
170+
- name: 'Check scan result and build status'
171+
run: |
172+
if [ "${{ steps.action-internal-error.outputs.iac_scan_result }}" != "error" ]; then
173+
exit 1
174+
fi
175+
if [ "${{ steps.action-internal-error.outcome }}" != "failure" ]; then
176+
exit 1
177+
fi
178+
179+
- id: 'action-internal-error-fail-silently-true'
180+
name: 'Action internal error, fail silently true'
181+
uses: './'
182+
with:
183+
organization_id: 'invalid-id'
184+
scan_file_ref: 'test/resources/with-violations-tf_plan.json'
185+
iac_type: 'terraform'
186+
iac_version: '1.0.0'
187+
fail_silently: 'true'
188+
- name: Check scan result
189+
run: |
190+
if [ "${{ steps.action-internal-error-fail-silently-true.outputs.iac_scan_result }}" != "error" ]; then
191+
exit 1
192+
fi

README.md

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@
22

33
## Description
44

5-
This Github Action scans Infrastructure as Code (IaC) files for security risks. When a scan finds violations, this action will write the report in SARIF format to the workspace.
6-
Currently only terraform plan files are supported for scanning.
5+
This Github action identifies insecure configurations in Infrastructure as Code (IaC) files for Google Cloud resources.
6+
This action requires Terraform plan files in JSON format for scanning.
7+
8+
Use this action to detect and remediate issues in IaC files for Google Cloud before you deploy the resources.
9+
10+
This action lets you:
11+
- Scan IaC template files (such as Terraform plan files).
12+
- Display issues with their severity as a SARIF Report in the GitHub Workspace after a scan completes.
13+
- Define severity-based failure criteria for passing or failing the build.
14+
15+
> [!NOTE]
16+
> This is a Security Command Center Premium tier offering for subscription customers only. You must activate the Security Command Center Premium tier in the Google Cloud organization to use this feature.
717
818
## Prerequisites
919

10-
- This action requires a service account which have **Security Posture
11-
Shift-Left Validator or Security Posture Admin** Role on the Google Cloud
12-
organization to which IaC resources belong's. See
13-
[Authorization](#authorization) for more information.
20+
- This action requires a Google Cloud service account which has the
21+
**Security Posture Shift-Left Validator** role or the **Security
22+
Posture Admin** role on the Google Cloud organization that includes
23+
the IaC resources. For more information, see [Authorization](#authorization).
1424

1525
- This action runs using Node 20. If you are using self-hosted GitHub Actions
1626
runners, you must use a [runner
1727
version](https://github.com/actions/virtual-environments) that supports this
18-
version or newer.
28+
version or later.
1929

2030
## Usage
2131

@@ -54,34 +64,38 @@ jobs:
5464
5565
## Inputs
5666
57-
- `organization_id`: (Required) ID of the Google Cloud organization which owns
58-
resources under modification.
67+
- `organization_id`: (Required) The Google Cloud organization ID for the
68+
organization which includes the resources that you want to modify.
5969

60-
- `scan_file_ref`: (Required) Absolute file path including file name where the
61-
IaC file is stored in the workspace. Examples: 'tf_plan.json',
62-
'artifacts/tf_plan.json'.
70+
- `scan_file_ref`: (Required) The absolute file path, including the file name,
71+
for the IaC file in the workspace. For example: './tf_plan.json', or
72+
'./artifacts/tf_plan.json'.
6373

64-
- `iac_type`: (Required) IaC template type. Currently only Terraform is
74+
- `iac_type`: (Required) The IaC template type. Currently only Terraform is
6575
supported.
6676

67-
- `iac_version`: (Required) IaC template version. Examples: '1.6.6', '1.6.5'.
77+
- `iac_version`: (Required) The IaC template version. For example: '1.6.6',
78+
or '1.6.5'.
6879

69-
- `scan_timeout`: (Optional) Max time upto which action should run, should be
70-
between '1m' and '10m'. Default: 1m.
80+
- `scan_timeout`: (Optional) The maximum time before the action stops.
81+
The time must be between '1m' and '10m'. The default is `1m`.
7182

72-
- `ignore_violations`: (Optional) If set to true, violations found in IaC file
73-
will be ignored to determine build status. Although violations will not be
74-
ignored to generate SARIF report and determining iac_scan_result. Default:
75-
false.
83+
- `ignore_violations`: (Optional) Whether violations found in IaC file
84+
should be ignored when determining the build status. This input doesn’t
85+
apply to violations that are related to generating SARIF reports and
86+
determining the `iac_scan_result`. The default is `false`.
7687

77-
- `failure_criteria`: (Optional) Failure criteria evaluates workflow build
78-
status. It contains threshold for count of critical, high, medium, and low
79-
severity issues and `AND/OR` based aggregator to evaluate the criteria. The
80-
threshold for each severity is evaluated against count of issues with
81-
similar severity in IaC scan result and then severity level evaluations are
82-
aggregated using `AND\OR` to arrive at failure_criteria value.
88+
- `failure_criteria`: (Optional) The failure criteria that determines the
89+
workflow build status. You can set a threshold for the number of critical,
90+
high, medium, and low severity issues and use an aggregator (either `and`
91+
or `or`) to evaluate the criteria. To determine whether a build has failed,
92+
the threshold for each severity is evaluated against the count of issues
93+
with that severity in the IaC scan results and then severity level evaluations
94+
are aggregated using `AND` or `OR` to arrive at `failure_criteria` value.
8395

84-
If `failure_criteria` evaluates to true, workflow is marked as `FAILED` otherwise workflow is marked as `SUCCESS`. Default: "Critical:1, High:1, Medium:1, Low:1, Operator:or".
96+
If the `failure_criteria` evaluates to `true`, the workflow is marked as
97+
`FAILED`. Otherwise, the workflow is marked as `SUCCESS`. The default is
98+
"Critical:1, High:1, Medium:1, Low:1, Operator:or".
8599

86100
- `fail_silently`: (Optional) If set to true, workflow will not fail in case
87101
of any internal error including invalid credentials and plugin dependency
@@ -90,22 +104,22 @@ jobs:
90104

91105
## Outputs
92106

93-
- `iac_scan_result`: Security Scan Result. One of:
107+
- `iac_scan_result`: The result of the security scan. One of:
94108

95-
1. `passed` - no violations found or the `failure_criteria` was not
109+
1. `passed` - No violations were found or the `failure_criteria` was not
96110
satisfied.
97-
2. `failed` - `failure_criteria` was satisfied.
98-
3. `error` - Action ran into execution error, generally due to
99-
misconfiguration or invalid credentials.
111+
2. `failed` - The `failure_criteria` was satisfied.
112+
3. `error` - The action ran into an execution error, generally
113+
due to a misconfiguration or invalid credentials.
100114

101-
- `iac_scan_result_sarif_path`: Path for the SARIF Report file. This is only
102-
available when violations are found in the scan file.
115+
- `iac_scan_result_sarif_path`: The path for the SARIF report file. This
116+
file is only available when violations are found in the scan file.
103117

104118
## Authorization
105119

106120
Use [google-github-actions/auth](https://github.com/google-github-actions/auth)
107121
to authenticate the action. You can use [Workload Identity Federation][wif] or
108-
traditional [Service Account Key JSON][sa] authentication.
122+
traditional [Service Account Key JSON][sa] for authentication.
109123

110124
```yaml
111125
jobs:

action.yml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,61 +20,65 @@ description: |-
2020
inputs:
2121
organization_id:
2222
description: |-
23-
Google Cloud OrganizationId which owns resources under modification.
23+
The Google Cloud organization ID for the organization which includes
24+
the resources that you want to modify.
2425
required: true
2526
scan_file_ref:
2627
description: |-
27-
Absolute file path including file name where the IaC file is stored in the workspace.
28-
Ex: 'tf_plan.json', 'artifacts/tf_plan.json'.
28+
The absolute file path, including the file name, for the IaC file in the
29+
workspace. For example: './tf_plan.json', or './artifacts/tf_plan.json'.
2930
required: true
3031
iac_type:
3132
description: |-
32-
IaC template type. Currently only terraform is supported.
33+
The IaC template type. Currently only Terraform is supported.
3334
required: true
3435
iac_version:
3536
description: |-
36-
IaC template version. Examples: '1.6.6', '1.6.5'.
37+
The IaC template version. For example: '1.6.6', or '1.6.5'.
3738
required: true
3839
scan_timeout:
3940
description: |-
40-
Max time upto which action should run, should be between '1m' and '10m'.
41+
The maximum time before the action stops. The time must be between '1m' and '10m'.
4142
default: '1m'
4243
required: false
4344
ignore_violations:
4445
description: |-
45-
If set to true, violations found in IaC file will be ignored to determine build status.
46-
Although violations will not be ignored to generate SARIF report and determining
47-
iac_scan_result.
46+
Whether violations found in IaC file should be ignored when determining
47+
the build status. This input doesn’t apply to violations that are
48+
related to generating SARIF reports and determining the `iac_scan_result`.
4849
default: false
4950
required: false
5051
failure_criteria:
5152
description: |-
52-
Failure criteria evaluates workflow build status. It contains threshold for count of
53-
critical, high, medium, and low severity issues and AND/OR based aggregator to evaluate
54-
the criteria. The threshold for each severity is evaluated against count of issues with
55-
similar severity in IaC scan result and then severity level evaluations are aggregated using
56-
AND\OR to arrive at failure_criteria value.
57-
If failure_criteria evaluates to true, workflow is marked as FAILED otherwise workflow is marked as SUCCESS.
58-
default: 'Critical:1, High:1, Medium:1, Low:1, Operator:or'
53+
The failure criteria that determines the workflow build status. You can set
54+
a threshold for the number of critical, high, medium, and low severity
55+
issues and use an aggregator (either `and` or `or`) to evaluate the criteria.
56+
To determine whether a build has failed, the threshold for each severity is
57+
evaluated against the count of issues with that severity in the IaC scan
58+
results and then severity level evaluations are aggregated using `AND` or `OR`
59+
to arrive at `failure_criteria` value.
60+
If the `failure_criteria` evaluates to `true`, the workflow is marked as `FAILED`.
61+
Otherwise, the workflow is marked as `SUCCESS`.
62+
default: 'Critical:1, High:1, Medium:1, Low:1, Operator:OR'
5963
required: false
6064
fail_silently:
6165
description: |-
62-
If set to true, workflow will not fail in case of any internal error including invalid credentials
63-
and plugin dependency failure.
64-
Note: Action will always fail in case of any input validation failure.
66+
If set to true, workflow will not fail in case of any internal error including
67+
invalid credentials and plugin dependency failure.
68+
Note: Action will always fail in case of any input validationfailure.
6569
default: false
6670
required: false
6771

6872
outputs:
6973
iac_scan_result:
7074
description: |-
71-
Security Scan Result. One of:
72-
`passed` - no violations found or failure_criteria was not satisfied.
73-
`failed` - failure_criteria was satisfied.
74-
`error` - Action ran into execution error, generally due to misconfiguration or invalid credentials.
75+
The result of the security scan. One of:
76+
`passed` - No violations were found or the `failure_criteria` was not satisfied.
77+
`failed` - The `failure_criteria` was satisfied.
78+
`error` - The action ran into an execution error, generally due to a misconfiguration or invalid credentials.
7579
iac_scan_result_sarif_path:
7680
description: |-
77-
Path for the SARIF Report file. This is only available when violations are found in the scan file.
81+
The path for the SARIF report file. This file is only available when violations are found in the scan file.
7882
7983
runs:
8084
using: 'node20'

0 commit comments

Comments
 (0)