|
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