Skip to content

Commit 9978670

Browse files
adishagarwalagarwaladishsethvargo
authored
Add code for analyze-code-security-scc action (#2)
Adding code for analyze-code-security-scc action. Currently intergration tests, unit tests are not added, will add those later. --------- Co-authored-by: Adish Agarwal <[email protected]> Co-authored-by: Seth Vargo <[email protected]>
1 parent 5042435 commit 9978670

24 files changed

+4246
-1
lines changed

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
plugins: ['@typescript-eslint'],
5+
extends: [
6+
'eslint:recommended',
7+
'plugin:@typescript-eslint/eslint-recommended',
8+
'plugin:@typescript-eslint/recommended',
9+
'plugin:prettier/recommended',
10+
],
11+
12+
rules: {
13+
'@typescript-eslint/no-explicit-any': 'off',
14+
},
15+
};

.github/dependabot.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
version: 2
16+
updates:
17+
- package-ecosystem: 'npm'
18+
directory: '/'
19+
rebase-strategy: 'disabled'
20+
schedule:
21+
interval: 'daily'
22+
commit-message:
23+
prefix: 'security: '
24+
open-pull-requests-limit: 0 # only check security updates
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: 'Draft release'
16+
17+
on:
18+
workflow_dispatch:
19+
inputs:
20+
version_strategy:
21+
description: 'Version strategy: The strategy to used to update the version based on semantic versioning (more info at https://semver.org/).'
22+
required: true
23+
default: 'patch'
24+
type: 'choice'
25+
options:
26+
- 'major'
27+
- 'minor'
28+
- 'patch'
29+
30+
jobs:
31+
draft-release:
32+
name: 'Draft release'
33+
uses: 'google-github-actions/.github/.github/workflows/draft-release.yml@v0'
34+
with:
35+
version_strategy: '${{ github.event.inputs.version_strategy }}'
36+
# secrets must be explicitly passed to reusable workflows https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/reusing-workflows#using-inputs-and-secrets-in-a-reusable-workflow
37+
secrets:
38+
ACTIONS_BOT_TOKEN: '${{ secrets.ACTIONS_BOT_TOKEN }}'

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: 'Release'
16+
17+
on:
18+
push:
19+
branches:
20+
- 'main'
21+
- 'release/**/*'
22+
23+
jobs:
24+
release:
25+
if: "startsWith(github.event.head_commit.message, 'Release: v')"
26+
name: 'Release'
27+
uses: 'google-github-actions/.github/.github/workflows/release.yml@v0'

.github/workflows/test.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: 'Test'
16+
17+
on:
18+
push:
19+
branches:
20+
- 'main'
21+
- 'release/**/*'
22+
pull_request:
23+
branches:
24+
- 'main'
25+
- 'release/**/*'
26+
workflow_dispatch:
27+
28+
concurrency:
29+
group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}'
30+
cancel-in-progress: true
31+
32+
defaults:
33+
run:
34+
shell: 'bash'
35+
36+
jobs:
37+
unit:
38+
name: 'unit'
39+
runs-on: 'ubuntu-latest'
40+
41+
steps:
42+
- uses: 'actions/checkout@v4'
43+
44+
- uses: 'actions/setup-node@v4'
45+
with:
46+
node-version: '20.x'
47+
48+
- name: 'npm build'
49+
run: 'npm ci && npm run build'
50+
51+
- name: 'npm lint'
52+
run: 'npm run lint'
53+
54+
- name: 'npm test'
55+
run: 'npm run test'
56+
57+
## TODO : Add functionality specific test

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
node_modules/
2+
runner/
3+
4+
# Rest of the file pulled from https://github.com/github/gitignore/blob/main/Node.gitignore
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# TypeScript v1 declaration files
30+
typings/
31+
32+
# TypeScript cache
33+
*.tsbuildinfo
34+
35+
# Optional npm cache directory
36+
.npm
37+
38+
# Optional eslint cache
39+
.eslintcache
40+
41+
# Optional REPL history
42+
.node_repl_history
43+
44+
# Output of 'npm pack'
45+
*.tgz

.prettierrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
arrowParens: 'always',
3+
bracketSpacing: true,
4+
endOfLine: 'auto',
5+
jsxSingleQuote: true,
6+
printWidth: 100,
7+
quoteProps: 'consistent',
8+
semi: true,
9+
singleQuote: true,
10+
tabWidth: 2,
11+
trailingComma: 'all',
12+
useTabs: false,
13+
};

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Changelog
2+
Changelogs for each release are located on the [releases page](https://github.com/google-github-actions/analyze-code-security-scc/releases).

README.md

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,129 @@
1-
# analyze-code-security-scc
1+
# analyze-code-security-scc
2+
3+
## Description
4+
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.
7+
8+
## Prerequisites
9+
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.
14+
15+
- This action runs using Node 20. If you are using self-hosted GitHub Actions
16+
runners, you must use a [runner
17+
version](https://github.com/actions/virtual-environments) that supports this
18+
version or newer.
19+
20+
## Usage
21+
22+
```yaml
23+
jobs:
24+
job_id:
25+
permissions:
26+
contents: 'read'
27+
id-token: 'write'
28+
29+
steps:
30+
- id: 'auth'
31+
uses: 'google-github-actions/auth@v2'
32+
with:
33+
workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
34+
service_account: '[email protected]'
35+
36+
- id: 'analyze-code-security-scc'
37+
uses: 'google-github-actions/analyze-code-security-scc@v1'
38+
with:
39+
organization_id: '123456789'
40+
scan_file_ref: './tf_plan.json'
41+
iac_type: 'terraform'
42+
iac_version: '1.0.0'
43+
scan_timeout: '1m'
44+
ignore_violations: false
45+
failure_criteria: 'High:1,Medium:1,Low:1,Operator:or'
46+
fail_silently: true
47+
48+
- if: ${{ steps.analyze-code-security-scc.outputs.iac_scan_result_sarif_path != '' }}
49+
uses: 'actions/upload-artifact@v4'
50+
with:
51+
name: 'sarif'
52+
path: '${{ steps.analyze-code-security-scc.outputs.iac_scan_result_sarif_path }}'
53+
```
54+
55+
## Inputs
56+
57+
- `organization_id`: (Required) ID of the Google Cloud organization which owns
58+
resources under modification.
59+
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'.
63+
64+
- `iac_type`: (Required) IaC template type. Currently only Terraform is
65+
supported.
66+
67+
- `iac_version`: (Required) IaC template version. Examples: '1.6.6', '1.6.5'.
68+
69+
- `scan_timeout`: (Optional) Max time upto which action should run, should be
70+
between '1m' and '10m'. Default: 1m.
71+
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.
76+
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.
83+
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".
85+
86+
- `fail_silently`: (Optional) If set to true, workflow will not fail in case
87+
of any internal error including invalid credentials and plugin dependency
88+
failure. Note: Action will always fail in case of any input validation
89+
failure. Default: false.
90+
91+
## Outputs
92+
93+
- `iac_scan_result`: Security Scan Result. One of:
94+
95+
1. `passed` - no violations found or the `failure_criteria` was not
96+
satisfied.
97+
2. `failed` - `failure_criteria` was satisfied.
98+
3. `error` - Action ran into execution error, generally due to
99+
misconfiguration or invalid credentials.
100+
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.
103+
104+
## Authorization
105+
106+
Use [google-github-actions/auth](https://github.com/google-github-actions/auth)
107+
to authenticate the action. You can use [Workload Identity Federation][wif] or
108+
traditional [Service Account Key JSON][sa] authentication.
109+
110+
```yaml
111+
jobs:
112+
job_id:
113+
permissions:
114+
contents: 'read'
115+
id-token: 'write'
116+
117+
steps:
118+
- id: 'auth'
119+
uses: 'google-github-actions/auth@v2'
120+
with:
121+
workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
122+
service_account: '[email protected]'
123+
124+
- id: 'analyze-code-security-scc'
125+
uses: 'google-github-actions/analyze-code-security-scc@v1'
126+
```
127+
128+
[sa]: https://cloud.google.com/iam/docs/creating-managing-service-accounts
129+
[wif]: https://cloud.google.com/iam/docs/workload-identity-federation

0 commit comments

Comments
 (0)