Advanced Options: GitHub Actions
Scan Modes
By default, the action tries to autodetect everything. This can fail in more complicated setups (such as monorepos). Safety Action supports 3 scan modes, which can be mixed and matched depending on your exact project structure.
Scanning a built Docker image
Safety Action can scan into any Docker image that exists on the action runner. This is most useful when you're using GitHub workflows to build and publish Docker images as part of your pipeline.
To use this mode, set scan
to docker
. You can also specify an image to scan using docker-image
. This mode requires /bin/sh
to be present in the image you're scanning, as well as the command python -m pip list --format=freeze
to be runnable:
YAML
Scanning the workflow environment
Safety Action can scan your current workflow environment. This is most useful when you're also using actions/setup-python
and perhaps packaging up a wheel, or running more complex builds using setup.py
.
This type of scan is also the most comprehensive and secure since it most accurately scans the real-world system that you are deploying into production. Python dependency installations are often not deterministic, and even then, the outcome can change across even slightly different versions of Python or the underlying system details.
To use this mode, set thescan
to env
. No options are available - if pythonLocation
has been set by actions/setup-python
, this Python environment will automatically be scanned, otherwise the environment of the worker image (eg, ubuntu-latest
will be scanned):
YAML
Environment scans are still completely configurable using Safety CLI: Policy file, or via GitHub Action variables.
Scanning a requirements file
Safety Action can scan a requirements.txt
or Poetry / Pipfile lockfile in your repo. Scanning a file is not recommended unless you're using a lock file that specifies all dependencies, and are confident that no other packages are installed in the environment.
To use this mode, set scan
to file
. You can also specify a path to the requirements file to scan using requirements
:
YAML
Running without failing the pipeline
It's possible to run the Safety action, without failing the pipeline if a vulnerability is found, but checking this status in a next step:
YAML
Action options
Option | Default | Required? | Description |
---|---|---|---|
| N/A | Yes | Your PyUp API key |
|
| No | Scan mode to use. One of |
| Autodetects the last built, tagged image on the runner | No | Tag or hash of the Docker Image to scan. |
|
| No | Path of requirements file to scan |
| No | No | By default, Safety will exit with a non-zero exit code if it detects any vulnerabilities. Set this to non-empty value to not error out. |
| 'screen' | No | Output format for returned data. One of |
| '' | No | Any additional CLI arguments to pass to |
Last updated