|
| 1 | +# Dependabot Vulnerability Alerts Evidence Example Workflow |
| 2 | + |
| 3 | +The GitHub Actions workflow, named dependabot-evidence-example.yml, demonstrates how to automate the collection of Dependabot vulnerability alerts and attach them as signed evidence to a Docker image within JFrog Artifactory. |
| 4 | + |
| 5 | +## Overview |
| 6 | +The workflow builds a Docker image, fetches open Dependabot vulnerability alerts for the repository, pushes the Docker image to JFrog Artifactory, and attaches the Dependabot alerts as signed evidence to the Docker image package. This workflow's primary goal is to automate the collection of security scan results from Dependabot and associate them directly with the deployed artifact in Artifactory, enhancing traceability and compliance for security posture in your CI/CD pipeline. |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | +- JFrog CLI 2.65.0 or above (installed automatically in the workflow) |
| 10 | +- Artifactory configured as a Docker registry |
| 11 | +- GitHub repository variables: Configure the following variables in your GitHub repository settings |
| 12 | + (Settings > Secrets and variables > Actions > Variables) |
| 13 | + - `REGISTRY_DOMAIN` (Artifactory Docker registry domain, e.g. `mycompany.jfrog.io`) |
| 14 | + - `ARTIFACTORY_URL` (Artifactory base URL) |
| 15 | + - `TEST_PUB_KEY_ALIAS` (Key alias for verifying evidence) |
| 16 | +- GitHub repository secrets: Configure the following secrets in your GitHub repository settings |
| 17 | + (Settings > Secrets and variables > Actions > Repository secrets) |
| 18 | + - `ARTIFACTORY_ACCESS_TOKEN` (Artifactory access token) |
| 19 | + - `JF_USER` (Artifactory username) |
| 20 | + - `TEST_PRVT_KEY` (Private key for signing evidence) |
| 21 | + - `TOKEN_GIT` (A GitHub Token with "security_events: read" permission to access Dependabot alerts via the GitHub API) |
| 22 | + |
| 23 | +## Environment Variables Used |
| 24 | +- `REGISTRY_DOMAIN` - Docker registry domain |
| 25 | +- `REPO_NAME` - Docker repository name |
| 26 | +- `IMAGE_NAME` - Docker image name |
| 27 | +- `VERSION` - Image version |
| 28 | +- `BUILD_NAME` - Name for the build info |
| 29 | + |
| 30 | +## Workflow Steps |
| 31 | +1. **Checkout Repository** |
| 32 | + - Checks out the source code for the build context. |
| 33 | +2. **Setup JFrog CLI** |
| 34 | + - Install and Setup the JFrog CLI using the official GitHub Action. |
| 35 | +3. **Log in to Artifactory Docker Registry** |
| 36 | + - Authenticates Docker with Artifactory for pushing the image. |
| 37 | +4. **Set up Docker Buildx** |
| 38 | + - Prepares Docker Buildx for advanced build and push operations. |
| 39 | +5. **Build and Push Docker Image to Artifactory** |
| 40 | + - Builds the Docker image using the provided Dockerfile and tags it for the Artifactory registry. |
| 41 | + - Pushes the tagged Docker image to the Artifactory Docker registry using JFrog CLI. |
| 42 | +8. **Fetch Dependabot Vulnerability Snapshot** |
| 43 | + - Fetchs the snapshot of open Dependabot vulnerability alerts for the repository and outputs the results in JSON format. |
| 44 | +9. **Create Dependabot Evidence Using JFrog CLI** |
| 45 | + - Attaches the Dependabot vulnerability snapshot as signed evidence to the Docker image package in Artifactory. |
| 46 | + |
| 47 | +## Example Dependabot Vulnerability Alert Data |
| 48 | + |
| 49 | +The Fetch Dependabot Vulnerability Snapshot step retrieves Dependabot alerts and transforms them into a structured JSON format. |
| 50 | +- advisoryUrl: Link to the security advisory. |
| 51 | +- cveId: Common Vulnerabilities and Exposures identifier (e.g., CVE-2020-1734). |
| 52 | +- detectedAt: Timestamp when the vulnerability was detected. |
| 53 | +- ecosystem: The package ecosystem (e.g., pip). |
| 54 | +- ghsaId: GitHub Security Advisory ID (e.g., GHSA-h39q-95q5-9jfp). |
| 55 | +- packageName: The name of the vulnerable package (e.g., ansible). |
| 56 | +- patchedVersion: The version where the vulnerability is patched (e.g., 2.9.11, or N/A if not specified). |
| 57 | +- severity: The severity level (e.g., high, medium, low). |
| 58 | +- summary: A brief summary of the vulnerability. |
| 59 | +- vulnerableVersionRange: The version range affected by the vulnerability. |
| 60 | + |
| 61 | +## Key Commands Used |
| 62 | + |
| 63 | +- **Build and Push Docker Image to Artifactory** |
| 64 | + ```bash |
| 65 | + docker build -f ./examples/dependabot-alerts-example/Dockerfile . --tag $REGISTRY_DOMAIN/$REPO_NAME/$IMAGE_NAME:$VERSION |
| 66 | + jf rt docker-push $REGISTRY_DOMAIN/$REPO_NAME/$IMAGE_NAME:$VERSION $REPO_NAME --build-name=$BUILD_NAME --build-number=$VERSION |
| 67 | + ``` |
| 68 | +- **Fetch Dependabot Vulnerability Snapshot** |
| 69 | + ```bash |
| 70 | + gh api "repos/${OWNER}/${REPO}/dependabot/alerts?state=open" \ |
| 71 | + --jq '[.[] | |
| 72 | + { |
| 73 | + packageName: .dependency.package.name, |
| 74 | + ecosystem: .dependency.package.ecosystem, |
| 75 | + vulnerableVersionRange: .security_vulnerability.vulnerable_version_range, |
| 76 | + patchedVersion: (try .security_vulnerability.first_patched_version.identifier // "N/A"), |
| 77 | + severity: .security_vulnerability.severity, |
| 78 | + ghsaId: .security_advisory.ghsa_id, |
| 79 | + cveId: (.security_advisory.cve_id // "N/A"), |
| 80 | + advisoryUrl: .html_url, |
| 81 | + summary: .security_advisory.summary, |
| 82 | + detectedAt: .created_at |
| 83 | + } |
| 84 | + ]' > result.json |
| 85 | + |
| 86 | + jq -n --argjson data "$(cat result.json)" '{ data: $data }' > dependabot.json |
| 87 | + ``` |
| 88 | +- **Attach Evidence:** |
| 89 | + ```bash |
| 90 | + jf evd create \ |
| 91 | + --package-name $IMAGE_NAME \ |
| 92 | + --package-version $VERSION \ |
| 93 | + --package-repo-name $REPO_NAME \ |
| 94 | + --key "${{ secrets.TEST_PRVT_KEY }}" \ |
| 95 | + --key-alias ${{ vars.TEST_PUB_KEY_ALIAS }} \ |
| 96 | + --predicate ./dependabot.json \ |
| 97 | + --predicate-type http://Github.com/Dependabot/static-analysis |
| 98 | + ``` |
| 99 | + |
| 100 | +## References |
| 101 | +- [Dependabot Documentation](https://docs.github.com/en/rest/dependabot) |
| 102 | +- [JFrog Evidence Management](https://jfrog.com/help/r/jfrog-artifactory-documentation/evidence-management) |
| 103 | +- [JFrog CLI Documentation](https://jfrog.com/getcli/) |
| 104 | + |
0 commit comments