Files
dependency-review-action/README.md

184 lines
15 KiB
Markdown
Raw Normal View History

2022-03-31 18:31:39 +02:00
# dependency-review-action
This action scans your pull requests for dependency changes, and will
2024-02-19 16:38:15 +01:00
raise an error if any vulnerabilities or invalid licenses are being introduced. The action is supported by an [API endpoint](https://docs.github.com/rest/dependency-graph/dependency-review) that diffs the dependencies between any two revisions on your default branch.
2022-04-06 16:00:03 -04:00
2022-06-15 09:32:17 -04:00
The action is available for all public repositories, as well as private repositories that have GitHub Advanced Security licensed.
2022-03-31 18:31:39 +02:00
2022-11-10 19:51:20 -05:00
You can see the results on the job logs:
<img width="850" alt="GitHub workflow run log showing Dependency Review job output" src="https://user-images.githubusercontent.com/2161/161042286-b22d7dd3-13cb-458d-8744-ce70ed9bf562.png">
2022-03-31 18:31:39 +02:00
2022-11-10 19:51:20 -05:00
or on the job summary:
<img width="850" alt="GitHub job summary showing Dependency Review output" src="https://github.com/actions/dependency-review-action/assets/2161/42fbed1d-64a7-42bf-9b05-c416bc67493f">
2022-03-31 18:31:39 +02:00
## Installation
**Please keep in mind that you need a [GitHub Advanced Security](https://docs.github.com/enterprise-cloud@latest/get-started/learning-about-github/about-github-advanced-security) license if you're running this action on private repositories.**
2022-08-03 11:22:48 +02:00
2022-03-31 18:31:39 +02:00
1. Add a new YAML workflow to your `.github/workflows` folder:
```yaml
name: 'Dependency Review'
on: [pull_request]
permissions:
contents: read
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4
2022-03-31 18:31:39 +02:00
- name: 'Dependency Review'
2024-01-18 14:23:52 +01:00
uses: actions/dependency-review-action@v4
2022-03-31 18:31:39 +02:00
```
2022-08-03 11:22:48 +02:00
### GitHub Enterprise Server
Make sure
2022-08-03 11:22:48 +02:00
[GitHub Advanced
Security](https://docs.github.com/enterprise-server@3.8/admin/code-security/managing-github-advanced-security-for-your-enterprise/enabling-github-advanced-security-for-your-enterprise)
2022-08-03 11:22:48 +02:00
and [GitHub
Connect](https://docs.github.com/enterprise-server@3.8/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect)
2023-07-19 16:26:44 +02:00
are enabled, and that you have installed the [dependency-review-action](https://github.com/actions/dependency-review-action) on the server.
2022-08-03 11:22:48 +02:00
You can use the same workflow as above, replacing the `runs-on` value
with the label of any of your runners (the default label
is `self-hosted`):
```yaml
# ...
jobs:
dependency-review:
runs-on: self-hosted
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4
2022-08-03 11:22:48 +02:00
- name: 'Dependency Review'
2024-01-18 14:23:52 +01:00
uses: actions/dependency-review-action@v4
2022-08-03 11:22:48 +02:00
```
2022-05-13 08:11:58 +02:00
2022-11-10 19:51:20 -05:00
## Configuration options
2022-11-11 11:26:05 +01:00
Configure this action by either inlining these options in your workflow file, or by using an external configuration file. All configuration options are optional.
| Option | Usage | Possible values | Default value |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------- |
| `fail-on-severity` | Defines the threshold for the level of severity. The action will fail on any pull requests that introduce vulnerabilities of the specified severity level or higher. | `low`, `moderate`, `high`, `critical` | `low` |
| `allow-licenses`\* | Contains a list of allowed licenses. The action will fail on pull requests that introduce dependencies with licenses that do not match the list. | Any [SPDX-compliant identifier(s)](https://spdx.org/licenses/) | none |
| `deny-licenses`\* | Contains a list of prohibited licenses. The action will fail on pull requests that introduce dependencies with licenses that match the list. | Any [SPDX-compliant identifier(s)](https://spdx.org/licenses/) | none |
| `fail-on-scopes` | Contains a list of strings of the build environments you want to support. The action will fail on pull requests that introduce vulnerabilities in the scopes that match the list. | `runtime`, `development`, `unknown` | `runtime` |
| `allow-ghsas` | Contains a list of GitHub Advisory Database IDs that can be skipped during detection. | Any GHSAs from the [GitHub Advisory Database](https://github.com/advisories) | none |
| `license-check` | Enable or disable the license check performed by the action. | `true`, `false` | `true` |
| `vulnerability-check` | Enable or disable the vulnerability check performed by the action. | `true`, `false` | `true` |
| `allow-dependencies-licenses`\* | Contains a list of packages that will be excluded from license checks. | Any package(s) in [purl](https://github.com/package-url/purl-spec) format | none |
| `base-ref`/`head-ref` | Provide custom git references for the git base/head when performing the comparison check. This is only used for event types other than `pull_request` and `pull_request_target`. | Any valid git ref(s) in your project | none |
| `comment-summary-in-pr` | Enable or disable reporting the review summary as a comment in the pull request. If enabled, you must give the workflow or job permission `pull-requests: write`. | `always`, `on-failure`, `never` | `never` |
| `deny-packages` | Any number of packages to block in a PR. | Package(s) in [purl](https://github.com/package-url/purl-spec) format | empty |
| `deny-groups` | Any number of groups (namespaces) to block in a PR. | Namespace(s) in [purl](https://github.com/package-url/purl-spec) format (no package name, no version number) | empty |
| `retry-on-snapshot-warnings`\* | Enable or disable retrying the action every 10 seconds while waiting for dependency submission actions to complete. | `true`, `false` | `false` |
| `retry-on-snapshot-warnings-timeout`\* | Maximum amount of time (in seconds) to retry the action while waiting for dependency submission actions to complete. | Any positive integer | 120 |
| `warn-only`+ | When set to `true`, the action will log all vulnerabilities as warnings regardless of the severity, and the action will complete with a `success` status. This overrides the `fail-on-severity` option. | `true`, `false` | `false` |
2024-03-08 01:29:53 +00:00
| `show-openssf-scorecard-levels` | When set to `true`, the action will output information about all the known OpenSSF Scorecard scores for the dependencies changed in this pull request. | `true`, `false` | `true` |
| `warn-on-openssf-scorecard-level` | When `show-openssf-scorecard-levels` is set to `true`, this option lets you configure the threshold for when a score is considered too low and gets a :warning: warning in the CI. | Any positive integer | 3 |
2023-03-08 15:44:01 +01:00
\*not supported for use with GitHub Enterprise Server
+when `warn-only` is set to `true`, all vulnerabilities, independently of the severity, will be reported as warnings and the action will not fail.
### Inline Configuration
You can pass options to the Dependency Review GitHub Action using your workflow file.
2022-11-10 19:51:20 -05:00
#### Example
2022-06-14 12:24:27 +02:00
```yaml
name: 'Dependency Review'
on: [pull_request]
permissions:
contents: read
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4
2022-06-14 12:24:27 +02:00
- name: Dependency Review
2024-01-18 14:23:52 +01:00
uses: actions/dependency-review-action@v4
2022-06-14 12:24:27 +02:00
with:
fail-on-severity: moderate
2022-06-14 12:24:27 +02:00
# Use comma-separated names to pass list arguments:
deny-licenses: LGPL-2.0, BSD-2-Clause
```
2022-11-10 19:51:20 -05:00
### Configuration File
2022-06-14 12:24:27 +02:00
2022-11-11 11:26:05 +01:00
You can use an external configuration file to specify the settings for this action. It can be a local file or a file in an external repository. Refer to the following options for the specification.
2022-06-14 12:24:27 +02:00
| Option | Usage | Possible values |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `config-file` | A path to a file in the current repository or an external repository. Use this syntax for external files: `OWNER/REPOSITORY/FILENAME@BRANCH` | **Local file**: `./.github/dependency-review-config.yml` <br> **External repo**: `github/octorepo/dependency-review-config.yml@main` |
| `external-repo-token` | Specifies a token for fetching the configuration file. It is required if the file resides in a private external repository and for all GitHub Enterprise Server repositories. Create a token in [developer settings](https://github.com/settings/tokens). | Any token with `read` permissions to the repository hosting the config file. |
2022-06-14 12:24:27 +02:00
2022-11-10 19:51:20 -05:00
#### Example
2022-06-14 12:24:27 +02:00
2022-11-10 19:51:20 -05:00
Start by specifying that you will be using an external configuration file:
```yaml
- name: Dependency Review
2024-01-18 14:23:52 +01:00
uses: actions/dependency-review-action@v4
with:
2022-11-10 19:51:20 -05:00
config-file: './.github/dependency-review-config.yml'
```
2023-04-06 21:42:26 +02:00
And then create the file in the path you just specified. Please note
that the **option names in external files use underscores instead of dashes**:
2022-06-14 12:24:27 +02:00
```yaml
2023-04-06 17:59:34 +02:00
fail_on_severity: 'critical'
allow_licenses:
2022-11-10 19:51:20 -05:00
- 'GPL-3.0'
- 'BSD-3-Clause'
- 'MIT'
2022-06-14 12:24:27 +02:00
```
2023-04-06 10:49:30 +02:00
For more examples of how to use this action and its configuration options, see the [examples](docs/examples.md) page.
### Considerations
2022-06-14 12:24:27 +02:00
2023-07-19 13:05:42 +02:00
- Checking for licenses is not supported on Enterprise Server as the API does not return license information.
2022-11-10 19:51:20 -05:00
- The action will only accept one of the two `license` parameters; an error will be raised if you provide both.
- We don't have license information for all of your dependents. If we can't detect the license for a dependency **we will inform you, but the action won't fail**.
2022-06-14 22:32:34 -04:00
## Blocking pull requests
The Dependency Review GitHub Action check will only block a pull request from being merged if the repository owner has required the check to pass before merging. For more information, see the [documentation on protected branches](https://docs.github.com/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches#require-status-checks-before-merging).
2022-06-14 22:32:34 -04:00
2024-02-18 21:15:15 -05:00
## Outputs
2024-03-02 05:09:49 +01:00
- `comment-content` is generated with the same content as would be present in a Dependency Review Action comment.
2024-03-04 18:52:57 +01:00
- `dependency-changes` holds all dependency changes in a JSON format. The following outputs are subsets of `dependency-changes` filtered based on the configuration:
- `vulnerable-changes` holds information about dependency changes with vulnerable dependencies in a JSON format.
- `invalid-license-changes` holds information about invalid or non-compliant license dependency changes in a JSON format.
- `denied-changes` holds information about denied dependency changes in a JSON format.
2024-02-18 21:15:15 -05:00
2024-03-04 18:58:48 +01:00
> [!NOTE]
> Action outputs are unicode strings [with a 1MB size limit](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-docker-container-and-javascript-actions).
2024-03-04 18:58:48 +01:00
2022-03-31 18:31:39 +02:00
## Getting help
2022-11-10 19:51:20 -05:00
If you have bug reports, questions or suggestions please [create a new issue](https://github.com/actions/dependency-review-action/issues/new/choose).
2022-03-31 18:31:39 +02:00
## Contributing
2022-11-10 19:51:20 -05:00
We are grateful for any contributions made to this project. Please read [CONTRIBUTING.MD](https://github.com/actions/dependency-review-action/blob/main/CONTRIBUTING.md) to get started.
2022-03-31 18:31:39 +02:00
## License
2022-03-31 18:31:39 +02:00
This project is released under the [MIT License](https://github.com/actions/dependency-review-action/blob/main/LICENSE).