|
1 | | -## Amazon Inspector for GitHub Actions |
| 1 | +# Vulnerability Scan GitHub Action for Amazon Inspector |
2 | 2 |
|
3 | 3 | Amazon Inspector is a vulnerability management service that scans AWS workloads and [CycloneDX SBOMs](https://cyclonedx.org/) for known software vulnerabilities. |
4 | 4 |
|
5 | | -Using this action, you can automatically scan supported artifacts with Amazon Inspector from your GitHub Actions workflows. |
| 5 | +This GitHub Action allows you to scan supported artifacts for software vulnerabilities using Amazon Inspector from your GitHub Actions workflows. |
| 6 | + |
| 7 | +An active AWS account is required to use this action. |
6 | 8 |
|
7 | 9 |
|
8 | 10 | ## Overview |
9 | 11 |
|
10 | | -Amazon Inspector for GitHub Actions can be used to detect software vulnerabilities in the following artifacts within your GitHub Actions workflows: |
| 12 | +This action works by first generating a CycloneDX software bill of materials (SBOM) for the provided artifact. |
| 13 | + |
| 14 | +The SBOM is then sent to Amazon Inspector; Inspector scans the provided SBOM for known vulnerabilities, and returns its results to the calling action. |
11 | 15 |
|
12 | | -1. Package dependencies |
| 16 | +This action can scan the following artifact types for software vulnerabilities: |
| 17 | + |
| 18 | +1. Repository files and directories |
13 | 19 | 2. Container images |
14 | 20 | 3. Compiled Go and Rust binaries |
15 | 21 | 4. Archives *(.zip, .tar, .tar.gz)* |
16 | 22 |
|
17 | | -This action is powered by the [Amazon Inspector SBOM Generator (inspector-sbomgen)](https://docs.aws.amazon.com/inspector/latest/user/sbom-generator.html). |
| 23 | +To learn more about this action's supported artifacts, please see our documentation here: [Amazon Inspector SBOM Generator (inspector-sbomgen)](https://docs.aws.amazon.com/inspector/latest/user/sbom-generator.html). |
| 24 | + |
18 | 25 |
|
19 | 26 | ## Prerequisites |
20 | 27 |
|
21 | 28 | 1. **Required:** You must have an active AWS account to use this action. Guidance on creating an AWS account is provided [here](https://docs.aws.amazon.com/inspector/latest/user/configure-cicd-account.html). |
22 | 29 |
|
23 | 30 | 2. **Required:** You must have read access to the **InspectorScan:ScanSbom** API. [See here for configuration instructions](https://docs.aws.amazon.com/inspector/latest/user/configure-cicd-account.html#cicd-iam-role). |
24 | 31 |
|
25 | | -3. **Required:** You must configure AWS authentication on GitHub. We recommend using [configure-aws-credentials](https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions) for this purpose. |
| 32 | +3. **Required:** You must configure AWS authentication for use in GitHub action workflows. We recommend using [configure-aws-credentials](https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions) for this purpose. |
26 | 33 |
|
27 | 34 | 4. **Required:** Create a GitHub Actions workflow if you do not already have one. Guidance on doing so is available [here](https://docs.github.com/en/actions/quickstart). |
28 | 35 |
|
29 | | -5. *Optional:* Configure container registry authentication if needed. GitHub Actions are available for this purpose including [Docker Login](https://github.com/marketplace/actions/docker-login). |
30 | | - |
31 | | -6. *Optional (strongly recommended):* Configure Dependabot to keep this action up to date. Guidance on doing so is available [here](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot#enabling-dependabot-version-updates-for-actions). Alternatively, consider creating automatic notifications for releases and security alerts by selecting the "watch" button and then "custom". |
| 36 | +5. **Required:** Configure Dependabot to keep this action up to date so you receive the latest bug fixes and security updates. Guidance on doing so is available [here](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot#enabling-dependabot-version-updates-for-actions). |
32 | 37 |
|
| 38 | +6. *Optional:* Configure container registry authentication if needed. GitHub Actions are available for this purpose including [Docker Login](https://github.com/marketplace/actions/docker-login). |
33 | 39 |
|
34 | 40 |
|
35 | 41 | ## Usage |
36 | 42 |
|
37 | | -The following examples demonstrate how to use this action: |
| 43 | +### Quick Start |
38 | 44 |
|
39 | | -- Copy and paste the provided YAML excerpts into your GitHub Actions workflow file. |
| 45 | +Perform the following steps to quickly add this action to your GitHub Actions pipeline: |
40 | 46 |
|
41 | | -- Modify the input options as needed. |
| 47 | +1. Create a new workflow file in your repository: |
42 | 48 |
|
| 49 | + ```bash |
| 50 | + # from your repository's root directory |
| 51 | + touch .github/workflows/invoke_inspector_scan.yml |
| 52 | + ``` |
43 | 53 |
|
44 | | -- See [here for example workflows](./.github/workflows/). |
| 54 | +2. Copy and paste the following YAML block into your workflow file. |
45 | 55 |
|
| 56 | + You will need to modify this workflow definition to suit your environment: |
46 | 57 |
|
47 | | -### 1. Scan Package Dependencies |
| 58 | + ```yaml |
| 59 | + TODO: paste me / link me |
| 60 | + ``` |
48 | 61 |
|
49 | | -This example will scan your repository contents for vulnerable software packages, based on contents from files such as requirements.txt. |
| 62 | +3. Save your workflow file then git commit / git push the workflow to GitHub. |
50 | 63 |
|
51 | | -```yaml |
52 | | -- name: Invoke Amazon Inspector Scan |
53 | | - uses: aws/amazon-inspector-github-actions-plugin@v1 |
54 | | - with: |
55 | | - artifact_type: 'repository' |
56 | | - artifact_path: './' # change this if you would like to scan a specific sub-directory, otherwise the entire repo will be scanned. |
57 | | -``` |
| 64 | +GitHub should automatically run your new workflow; review its results and make any needed changes to the input and output arguments. |
| 65 | + |
| 66 | + |
| 67 | +### Configuring Vulnerability Scan Outputs |
| 68 | + |
| 69 | +This action provides detailed Inspector scan findings in JSON, CSV, and markdown, plus, a CycloneDX software bill of materials in JSON. |
58 | 70 |
|
59 | | -- [*See here for more information on the types of package vulnerabilities this action can detect*](https://docs.aws.amazon.com/inspector/latest/user/sbom-generator.html). |
| 71 | +By default, this action will only display the number of vulnerabilities detected in the GitHub Actions job terminal; detailed findings are not shown. |
60 | 72 |
|
| 73 | +This is done so **you** can control how and where your vulnerability findings are presented and stored. |
61 | 74 |
|
62 | | -### 2. Scan Container Image |
| 75 | +The example below shows how to present this action's outputs in various locations and formats. |
63 | 76 |
|
64 | | -This example will scan a container image for vulnerable software packages. |
| 77 | +Exercise caution to ensure you do not accidentally post vulnerability information to untrusted viewers. |
65 | 78 |
|
66 | 79 | ```yaml |
67 | | -- name: Invoke Amazon Inspector Scan |
68 | | - uses: aws/amazon-inspector-github-actions-plugin@v1 |
| 80 | +- name: Scan container |
| 81 | + id: inspector |
| 82 | + uses: aws/vulnerability-scan-github-action-for-amazon-inspector@main |
69 | 83 | with: |
70 | 84 | artifact_type: 'container' |
71 | | - artifact_path: 'alpine:latest' # change this to the image you would like to scan |
72 | | -``` |
| 85 | + artifact_path: 'ubuntu:14.04' |
| 86 | +
|
| 87 | +# Display Inspector results in the GitHub Actions terminal |
| 88 | +- name: Display CycloneDX SBOM (JSON) |
| 89 | + run: cat ${{ steps.inspector.outputs.artifact_sbom }} |
| 90 | +
|
| 91 | +- name: Display Inspector vulnerability scan results (JSON) |
| 92 | + run: cat ${{ steps.inspector.outputs.inspector_scan_results }} |
73 | 93 |
|
74 | | -This action can scan containers exported as tarballs, locally built images, and images from remote registries. |
| 94 | +- name: Display Inspector vulnerability scan results (CSV) |
| 95 | + run: cat ${{ steps.inspector.outputs.inspector_scan_results_csv }} |
75 | 96 |
|
76 | | -For locally built images, this action only supports images built with Docker engine. |
77 | 97 |
|
78 | | -- [*See here for an example on building an image, scanning the image, and failing the build if vulnerabilities are detected*](./.github/workflows/container_local.yml). |
| 98 | +# Upload Inspector outputs as a .zip that can be downloaded |
| 99 | +# from the GitHub actions job summary page. |
| 100 | +- name: Upload Scan Results |
| 101 | + id: inspector |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + path: | |
| 105 | + ${{ steps.inspector.outputs.inspector_scan_results }} |
| 106 | + ${{ steps.inspector.outputs.inspector_scan_results_csv }} |
| 107 | + ${{ steps.inspector.outputs.artifact_sbom }} |
| 108 | +``` |
| 109 | +
|
| 110 | +### Configuring Vulnerability Thresholds |
79 | 111 |
|
| 112 | +This action allows the user to set vulnerability thresholds. |
80 | 113 |
|
81 | | -### 3. Scan Compiled Go or Rust Binary |
| 114 | +Vulnerability thresholds can be used to support custom logic, such as failing the workflow if any vulnerabilities are found. |
82 | 115 |
|
83 | | -This example will scan a compiled Go or Rust binary's package dependencies for vulnerabiliies. |
| 116 | +The example below shows how to set up vulnerability thresholds and fail the job when the threshold is exceeded: |
84 | 117 |
|
85 | 118 | ```yaml |
86 | 119 | - name: Invoke Amazon Inspector Scan |
87 | | - uses: aws/amazon-inspector-github-actions-plugin@v1 |
| 120 | + id: inspector |
| 121 | + uses: aws/vulnerability-scan-github-action-for-amazon-inspector@v1 |
88 | 122 | with: |
89 | | - artifact_type: 'binary' |
90 | | - artifact_path: './path/to/binary' # change this to your binary's filepath |
| 123 | + artifact_type: 'repository' |
| 124 | + artifact_path: './' |
| 125 | +
|
| 126 | + # set vulnerability thresholds; if the number of vulnerabilities |
| 127 | + # equals or exceeds any of the specified thresholds, this action |
| 128 | + # sets a flag, 'vulnerability_threshold_exceeded' to 1, else 0. |
| 129 | + # To ignore thresholds for a given severity, set its value to 0. |
| 130 | + # This example sets 'vulnerability_threshold_exceeded' flag if |
| 131 | + # one or more criticals, highs, or medium severity vulnerabilities |
| 132 | + # are found; lows and other type vulnerabilities are ignored |
| 133 | + # by this action when determining whether the threshold was |
| 134 | + # or was not exceeded. |
| 135 | + critical_threshold: 1 |
| 136 | + high_threshold: 1 |
| 137 | + medium_threshold: 1 |
| 138 | + low_threshold: 0 |
| 139 | + other_threshold: 0 |
| 140 | +
|
| 141 | +# Fail the job with 'exit 1' if vuln threshold flag is set |
| 142 | +- name: On vulnerability threshold exceeded |
| 143 | + run: exit ${{ steps.inspector.outputs.vulnerability_threshold_exceeded }} |
91 | 144 | ``` |
92 | 145 |
|
93 | | -### 4. Scan Archive |
| 146 | +### Build and Scan Container Images |
| 147 | +
|
| 148 | +This action supports a common use case that entails building a container image, scanning the built image for vulnerabilities, and optionally, failing the workflow before the image is deployed to a container registry or elsewhere. |
94 | 149 |
|
95 | | -This example will scan an archive for vulnerable software packages. The supported archive formats are **.zip**, **.tar**, and **.tar.gz**. |
| 150 | +We provide an example of this workflow below: |
96 | 151 |
|
97 | 152 | ```yaml |
98 | | -- name: Invoke Amazon Inspector Scan |
99 | | - uses: aws/amazon-inspector-github-actions-plugin@v1 |
100 | | - with: |
101 | | - artifact_type: 'archive' |
102 | | - artifact_path: './path/to/archive' # change this to your archive's filepath |
| 153 | +name: Build & Scan Container Image |
| 154 | +
|
| 155 | +on: [push] |
| 156 | +
|
| 157 | +jobs: |
| 158 | + build: |
| 159 | + name: Build docker image |
| 160 | + runs-on: ubuntu-latest |
| 161 | + environment: |
| 162 | + # change this to match your GitHub secrets environment |
| 163 | + name: plugin-development |
| 164 | +
|
| 165 | + steps: |
| 166 | + # checkout the repository containing our Dockerfile |
| 167 | + - name: Checkout this repository |
| 168 | + uses: actions/checkout@v4 |
| 169 | +
|
| 170 | + # Setup prerequisites for docker/build-push-action |
| 171 | + - name: Set up docker build prereqs (QEMU) |
| 172 | + uses: docker/setup-qemu-action@v3 |
| 173 | +
|
| 174 | + - name: Set up docker build prereqs (Buildx) |
| 175 | + uses: docker/setup-buildx-action@v3 |
| 176 | +
|
| 177 | + # build the image you wish to scan |
| 178 | + - name: Build Docker image |
| 179 | + uses: docker/build-push-action@v5 |
| 180 | + with: |
| 181 | + context: . |
| 182 | + file: ./Dockerfile |
| 183 | + push: false |
| 184 | + tags: app:latest |
| 185 | + load: true |
| 186 | +
|
| 187 | + # setup your AWS credentials |
| 188 | + - name: Configure AWS credentials |
| 189 | + uses: aws-actions/configure-aws-credentials@v4 |
| 190 | + with: |
| 191 | + aws-region: ${{ secrets.AWS_REGION }} |
| 192 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 193 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 194 | +
|
| 195 | + - name: Scan built image with Inspector |
| 196 | + uses: aws/amazon-inspector-github-actions-plugin@v1 |
| 197 | + id: inspector |
| 198 | + with: |
| 199 | + artifact_type: 'container' |
| 200 | + artifact_path: 'app:latest' # make sure this matches the image you built |
| 201 | + critical_threshold: 1 |
| 202 | + high_threshold: 1 |
| 203 | + medium_threshold: 1 |
| 204 | + low_threshold: 1 |
| 205 | + other_threshold: 1 |
| 206 | + # set additional arguments as needed |
| 207 | +
|
| 208 | + - name: Fail job if vulnerability threshold is exceeded |
| 209 | + run: exit ${{ steps.inspector.outputs.vulnerability_threshold_exceeded }} |
| 210 | +
|
| 211 | + # add any additional steps for deploying your image |
103 | 212 | ``` |
104 | 213 |
|
105 | | -## Action Inputs |
106 | 214 |
|
107 | | -The following input options can be added to this action to control its behavior. |
| 215 | +## Action Inputs and Outputs |
108 | 216 |
|
109 | | -See [action.yml](./action.yml) for more detail. |
| 217 | +The following input and output options are provided by this action; see [action.yml](./action.yml) for more detail. |
110 | 218 |
|
111 | 219 | | Option | Required | Description | |
112 | 220 | |---|---|---| |
@@ -137,6 +245,10 @@ The following outputs are set by this action: |
137 | 245 | | inspector_scan_results_csv | The filepath to the Inspector vulnerability scan in CSV format. | |
138 | 246 | | vulnerability_threshold_exceeded | This variable is set to 1 if any vulnerability threshold was exceeded, otherwise it is 0. | |
139 | 247 |
|
| 248 | +## Get Help |
| 249 | +
|
| 250 | +TODO: add me |
| 251 | +
|
140 | 252 | ## Security |
141 | 253 |
|
142 | 254 | See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. |
|
0 commit comments