|
| 1 | +# Auto Dismiss Dependabot Alerts |
| 2 | + |
| 3 | +A GitHub composite action to automatically dismiss Dependabot alerts based on manifest paths using glob patterns. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +This action can be used in a workflow to automatically dismiss Dependabot alerts for specific manifest paths. This is particularly useful for repositories with dependencies that are not directly used in production or for which vulnerabilities may not be relevant. |
| 8 | + |
| 9 | +### Example Workflow |
| 10 | + |
| 11 | +Create a workflow file (e.g., `.github/workflows/auto-dismiss-dependabot-alerts.yml`) with the following content: |
| 12 | + |
| 13 | +<!-- x-release-please-start-version --> |
| 14 | + |
| 15 | +```yaml |
| 16 | +name: Auto Dismiss Dependabot Alerts |
| 17 | + |
| 18 | +on: |
| 19 | + # Run daily to dismiss new alerts |
| 20 | + schedule: |
| 21 | + - cron: "0 0 * * *" |
| 22 | + |
| 23 | + # Allow manual triggering |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +jobs: |
| 27 | + auto-dismiss: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + permissions: |
| 30 | + id-token: write |
| 31 | + contents: read |
| 32 | + steps: |
| 33 | + - name: Checkout repository |
| 34 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 35 | + |
| 36 | + # Get GitHub App token with Dependabot alerts permissions |
| 37 | + - name: Retrieve GitHub App secrets |
| 38 | + id: get-secrets |
| 39 | + uses: grafana/shared-workflows/actions/[email protected] |
| 40 | + with: |
| 41 | + common_secrets: | |
| 42 | + DEPENDABOT_AUTO_TRIAGE_APP_ID=dependabot-auto-triage:app-id |
| 43 | + DEPENDABOT_AUTO_TRIAGE_APP_PRIVATE_KEY=dependabot-auto-triage:private-key |
| 44 | +
|
| 45 | + - name: Generate token |
| 46 | + id: generate-token |
| 47 | + uses: actions/create-github-app-token@3ff1caaa28b64c9cc276ce0a02e2ff584f3900c5 # v2.0.2 |
| 48 | + with: |
| 49 | + app-id: ${{ env.DEPENDABOT_AUTO_TRIAGE_APP_ID }} |
| 50 | + private-key: ${{ env.DEPENDABOT_AUTO_TRIAGE_APP_PRIVATE_KEY }} |
| 51 | + |
| 52 | + # Use the token with the auto-triage action |
| 53 | + - name: Auto Dismiss Dependabot Alerts |
| 54 | + uses: grafana/shared-workflows/actions/[email protected] |
| 55 | + with: |
| 56 | + token: ${{ steps.generate-token.outputs.token }} |
| 57 | + paths: | |
| 58 | + terraform/modules/**/*.json |
| 59 | + docker/vendor/** |
| 60 | + ksonnet/lib/argo-workflows/charts/**/*.json |
| 61 | + dismissal-reason: "not_used" |
| 62 | + dismissal-comment: "These dependencies are not used in production and pose no risk" |
| 63 | +``` |
| 64 | +
|
| 65 | +<!-- x-release-please-end-version --> |
| 66 | +
|
| 67 | +### Inputs |
| 68 | +
|
| 69 | +| Name | Description | Required | Default | |
| 70 | +| ------------------- | ----------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------- | |
| 71 | +| `token` | GitHub token with permissions to dismiss alerts | Yes | N/A | |
| 72 | +| `alert-types` | Comma-separated list of alert types to dismiss | No | `dependency` | |
| 73 | +| `paths` | Multi-line list of glob patterns to match manifest paths to dismiss | Yes | N/A | |
| 74 | +| `dismissal-comment` | Default comment to add when dismissing alerts | No | `Auto-dismissed based on manifest path configuration` | |
| 75 | +| `dismissal-reason` | Default reason for dismissal (options: `fix_started`, `inaccurate`, `no_bandwidth`, `not_used`, `tolerable_risk`) | No | `not_used` | |
| 76 | + |
| 77 | +### How It Works |
| 78 | + |
| 79 | +1. The action fetches all open Dependabot alerts for the repository |
| 80 | +2. For each alert, it checks if the manifest path matches any of the provided glob patterns |
| 81 | +3. If the path matches a pattern, it dismisses the alert with the specified reason and comment |
| 82 | + |
| 83 | +### Glob Pattern Syntax |
| 84 | + |
| 85 | +The action uses [minimatch](https://github.com/isaacs/minimatch) for glob pattern matching. Some common patterns: |
| 86 | + |
| 87 | +- `**/*.json` - Match all JSON files in any directory |
| 88 | +- `terraform/modules/**` - Match all files in terraform/modules and subdirectories |
| 89 | +- `docker/vendor/**/package-lock.json` - Match all package-lock.json files in docker/vendor and subdirectories |
| 90 | +- `ksonnet/lib/*/charts/**` - Match all files in any charts subdirectory under ksonnet/lib/\*/ |
| 91 | + |
| 92 | +### Permissions |
| 93 | + |
| 94 | +Due to API limitations, accessing and dismissing Dependabot alerts requires a GitHub App token with specific permissions. The standard `GITHUB_TOKEN` does not have sufficient access to the Dependabot API, even when `security-events: write` permissions are specified. |
| 95 | + |
| 96 | +#### GitHub App Requirements |
| 97 | + |
| 98 | +To use this action, you need: |
| 99 | + |
| 100 | +1. A GitHub App with the following permissions: |
| 101 | + |
| 102 | + - Repository permissions: |
| 103 | + - **Dependabot alerts**: Read & Write |
| 104 | + |
| 105 | +2. The GitHub App needs to be installed on your repository or organization |
| 106 | + |
| 107 | +3. The App ID and private key should be stored securely (e.g., in Vault) |
| 108 | + |
| 109 | +The example workflow above demonstrates using the `actions/create-github-app-token` action to generate a token with the required permissions. |
| 110 | + |
| 111 | +If you're experiencing "Resource not accessible by integration" errors, this indicates that the token being used doesn't have the necessary permissions to access the Dependabot API. |
| 112 | + |
| 113 | +## License |
| 114 | + |
| 115 | +This action is licensed under the same license as the parent repository. |
0 commit comments