|
| 1 | +# CVE Notifier Setup Guide |
| 2 | + |
| 3 | +## Quick Start |
| 4 | + |
| 5 | +The CVE notification system has been implemented in three components: |
| 6 | + |
| 7 | +1. **notify.py** - Python script that queries the database, enriches with Grype data, and sends Teams notifications |
| 8 | +2. **action.yml** - GitHub Action wrapper around notify.py |
| 9 | +3. **cd-notify-new-cves.yml** - Scheduled workflow that runs daily at 10:00 UTC (in another repo). |
| 10 | + |
| 11 | +## Files Created |
| 12 | + |
| 13 | +``` |
| 14 | +common-github-actions/ |
| 15 | +├── .github/ |
| 16 | +│ ├── actions/ |
| 17 | +│ │ └── notify-new-cves/ |
| 18 | +│ │ ├── action.yml # Action definition |
| 19 | +│ │ ├── notify.py # Core notification script |
| 20 | +│ │ └── README.md # Detailed documentation |
| 21 | +│ └── workflows/ |
| 22 | +│ └── cd-notify-new-cves.yml # Daily scheduled workflow |
| 23 | +``` |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | + |
| 27 | +### 1. Create GitHub Secrets |
| 28 | + |
| 29 | +Add these secrets to the `chef/chef-vuln-scan-orchestrator` repository (or at org level): |
| 30 | + |
| 31 | +| Secret Name | Description | How to Get It | |
| 32 | +|------------|-------------|---------------| |
| 33 | +| `DATABASE_URL_RO` | Postgres connection string (read-only user) | From your RDS instance or infrastructure team | |
| 34 | +| `TEAMS_WEBHOOK_URL` | Teams incoming webhook URL | Create in Teams: Channel → Connectors → Incoming Webhook | |
| 35 | +| `DATA_REPO_TOKEN` | PAT for chef-vuln-scan-data | Should already exist (used by scan workflows) | |
| 36 | + |
| 37 | +**Note**: The notification workflow only performs `SELECT` queries on `scan_runs`, `native_cve_details`, and `native_scan_results`. No write operations are performed—you can use a dedicated read-only database user for security. |
| 38 | + |
| 39 | +#### Database URL Format |
| 40 | + |
| 41 | +PostgreSQL connection string format: |
| 42 | +- Scheme: `postgresql` |
| 43 | +- Format: `<scheme>://<username>:<password>@<hostname>:<port>/<database>` |
| 44 | +- Default port: `5432` |
| 45 | + |
| 46 | +Replace the angle-bracketed placeholders with your actual connection details. |
| 47 | + |
| 48 | +#### Teams Webhook URL |
| 49 | +1. In Microsoft Teams, go to the channel where you want notifications |
| 50 | +2. Click the `...` menu → Connectors → Incoming Webhook |
| 51 | +3. Name: "Chef CVE Alerts" (or similar) |
| 52 | +4. Upload an icon (optional) |
| 53 | +5. Click "Create" |
| 54 | +6. Copy the webhook URL (starts with `https://progress.webhook.office.com/...`) |
| 55 | +7. Add as GitHub secret |
| 56 | + |
| 57 | +### 2. Verify Database Schema |
| 58 | + |
| 59 | +Ensure your database has the latest migrations applied: |
| 60 | +```bash |
| 61 | +cd chef-vuln-scan-db |
| 62 | +./scripts/migrate.sh |
| 63 | +``` |
| 64 | + |
| 65 | +Required tables: |
| 66 | +- `scan_runs` (stores run metadata) |
| 67 | +- `native_cve_details` (stores individual CVE findings) |
| 68 | +- `native_scan_results` (stores scan result aggregates) |
| 69 | + |
| 70 | +### 3. Verify Data Repository Access |
| 71 | + |
| 72 | +The workflow checks out `chef/chef-vuln-scan-data` using `DATA_REPO_TOKEN`. Verify this secret has read access. |
| 73 | + |
| 74 | +## Testing |
| 75 | + |
| 76 | +### Dry Run (Recommended First Step) |
| 77 | + |
| 78 | +1. Go to the [chef-vuln-scan-orchestrator](https://github.com/chef/chef-vuln-scan-orchestrator) repo |
| 79 | +2. Navigate to Actions → Notify New CVEs |
| 80 | +3. Click "Run workflow" |
| 81 | +4. Set `dry-run` to `true` |
| 82 | +5. Set `severities` to `Critical` (or `Critical,High` for testing) |
| 83 | +6. Click "Run workflow" |
| 84 | + |
| 85 | +This will: |
| 86 | +- Query the database |
| 87 | +- Enrich findings with Grype data |
| 88 | +- Print the Teams card payload to the Actions log |
| 89 | +- **NOT** send any actual notifications |
| 90 | + |
| 91 | +Review the output to ensure: |
| 92 | +- CVEs are being detected correctly |
| 93 | +- Enrichment finds the Grype match data |
| 94 | +- Card formatting looks good |
| 95 | + |
| 96 | +### Test with Injected CVE |
| 97 | + |
| 98 | +If you want to test without waiting for a real CVE, inject a test row: |
| 99 | + |
| 100 | +```sql |
| 101 | +-- Connect to your database |
| 102 | +psql $DATABASE_URL |
| 103 | + |
| 104 | +-- Insert a test CVE |
| 105 | +INSERT INTO native_cve_details ( |
| 106 | + scan_mode, product, channel, download_site, |
| 107 | + cve_id, severity, package_name, package_version, |
| 108 | + fix_available, fix_version, |
| 109 | + first_observed_at, last_seen_at |
| 110 | +) VALUES ( |
| 111 | + 'native', 'chef', 'stable', 'commercial', |
| 112 | + 'CVE-2025-TEST', 'Critical', 'test-package', '1.0.0', |
| 113 | + false, NULL, |
| 114 | + NOW(), NOW() |
| 115 | +) ON CONFLICT DO NOTHING; |
| 116 | + |
| 117 | +-- Verify it was inserted |
| 118 | +SELECT * FROM native_cve_details WHERE cve_id = 'CVE-2025-TEST'; |
| 119 | +``` |
| 120 | + |
| 121 | +Then run a dry-run workflow. You should see the test CVE in the output. |
| 122 | + |
| 123 | +**Important**: Clean up the test row after testing: |
| 124 | +```sql |
| 125 | +DELETE FROM native_cve_details WHERE cve_id = 'CVE-2025-TEST'; |
| 126 | +``` |
| 127 | + |
| 128 | +### Live Test |
| 129 | + |
| 130 | +Once dry-run looks good: |
| 131 | + |
| 132 | +1. Run workflow again with `dry-run` set to `false` |
| 133 | +2. Check your Teams channel for the notification |
| 134 | +3. Verify the card displays correctly |
| 135 | +4. Click through the reference links to ensure they work |
| 136 | + |
| 137 | +### Verify No False Positives |
| 138 | + |
| 139 | +Run the workflow again immediately (or the next day when no new CVEs exist). It should: |
| 140 | +- Find 0 new CVEs |
| 141 | +- Print: "No new CVEs detected — no notifications to send" |
| 142 | +- **NOT** send any Teams messages |
| 143 | + |
| 144 | +## Production Schedule |
| 145 | + |
| 146 | +The workflow (located in `chef-vuln-scan-orchestrator/.github/workflows/notify-new-cves.yml`) can be enabled to run automatically daily at **10:00 UTC** by uncommenting the schedule: |
| 147 | + |
| 148 | +```yaml |
| 149 | +schedule: |
| 150 | + - cron: '0 10 * * *' |
| 151 | +``` |
| 152 | +
|
| 153 | +This is 3 hours after the nightly scans complete (~07:00 UTC), providing buffer time. |
| 154 | +
|
| 155 | +The schedule is commented out by default to allow testing with manual runs first. |
| 156 | +
|
| 157 | +## Customization |
| 158 | +
|
| 159 | +### Change Severity Threshold |
| 160 | +
|
| 161 | +Edit the workflow file to notify on High severity as well: |
| 162 | +```yaml |
| 163 | +severities: Critical,High |
| 164 | +``` |
| 165 | +
|
| 166 | +Or run manually with custom severities via workflow_dispatch. |
| 167 | +
|
| 168 | +### Add Email Notifications |
| 169 | +
|
| 170 | +The dispatcher pattern makes this easy: |
| 171 | +
|
| 172 | +1. Add email configuration as a secret (JSON with SMTP settings) |
| 173 | +2. Implement `send_email_notification()` in notify.py |
| 174 | +3. Add email logic to `dispatch_notifications()` |
| 175 | +4. Add input to action.yml and workflow |
| 176 | + |
| 177 | +### Add Jira Integration |
| 178 | + |
| 179 | +Similar pattern: |
| 180 | + |
| 181 | +1. Add Jira credentials as secrets |
| 182 | +2. Implement `create_jira_issues()` in notify.py |
| 183 | +3. Add to dispatcher |
| 184 | +4. Configure in action.yml/workflow |
| 185 | + |
| 186 | +## Monitoring |
| 187 | + |
| 188 | +### Check Workflow Runs |
| 189 | + |
| 190 | +- Go to [chef-vuln-scan-orchestrator Actions](https://github.com/chef/chef-vuln-scan-orchestrator/actions) |
| 191 | +- Select "Notify New CVEs" workflow |
| 192 | +- Review recent runs for failures |
| 193 | +- Check logs for warnings about missing Grype matches |
| 194 | + |
| 195 | +### Common Issues |
| 196 | + |
| 197 | +**No CVEs found but expecting some:** |
| 198 | +- Check database: `SELECT * FROM native_cve_details WHERE first_observed_at >= NOW() - INTERVAL '25 hours'` |
| 199 | +- Verify scan workflows are running and inserting data |
| 200 | +- Check `last_seen_at` values are recent |
| 201 | + |
| 202 | +**Grype match not found:** |
| 203 | +- Verify chef-vuln-scan-data repo has the grype.latest.json files |
| 204 | +- Check the file path pattern matches: `{scan_mode}/{product}/{channel}/{download_site}/**/scanners/grype.latest.json` |
| 205 | +- Look for warning in Actions log: "Could not find Grype match for..." |
| 206 | + |
| 207 | +**Teams notification not arriving:** |
| 208 | +- Verify webhook URL is correct |
| 209 | +- Check Teams webhook hasn't been deleted/disabled |
| 210 | +- Look for HTTP error in Actions log |
| 211 | +- Test webhook manually with curl |
| 212 | + |
| 213 | +**Database connection fails:** |
| 214 | +- Verify DATABASE_URL_RO secret is correct |
| 215 | +- Check database is accessible from GitHub Actions runners (security groups/firewalls) |
| 216 | +- Ensure the read-only user has SELECT permissions on the required tables |
| 217 | + |
| 218 | +## Architecture |
| 219 | + |
| 220 | +``` |
| 221 | +┌─────────────────────────────────────────────────────────────┐ |
| 222 | +│ GitHub Actions: cd-notify-new-cves.yml │ |
| 223 | +│ Schedule: Daily at 10:00 UTC │ |
| 224 | +└─────────────────────────────────────────────────────────────┘ |
| 225 | + │ |
| 226 | + ▼ |
| 227 | +┌─────────────────────────────────────────────────────────────┐ |
| 228 | +│ Action: notify-new-cves │ |
| 229 | +│ ┌─────────────────────────────────────────────────────┐ │ |
| 230 | +│ │ notify.py │ │ |
| 231 | +│ │ 1. Query Postgres for new CVEs (first_observed_at) │ │ |
| 232 | +│ │ 2. Enrich with Grype match from chef-vuln-scan-data│ │ |
| 233 | +│ │ 3. Format as Teams Adaptive Card │ │ |
| 234 | +│ │ 4. Send to webhook (or dry-run) │ │ |
| 235 | +│ └─────────────────────────────────────────────────────┘ │ |
| 236 | +└─────────────────────────────────────────────────────────────┘ |
| 237 | + │ |
| 238 | + ▼ |
| 239 | + ┌──────────────┐ |
| 240 | + │ Microsoft │ |
| 241 | + │ Teams │ |
| 242 | + │ Channel │ |
| 243 | + └──────────────┘ |
| 244 | +``` |
| 245 | +
|
| 246 | +## Next Steps |
| 247 | +
|
| 248 | +1. ✅ Create GitHub secrets (DATABASE_URL_RO, TEAMS_WEBHOOK_URL) |
| 249 | +2. ✅ Run dry-run test |
| 250 | +3. ✅ Inject test CVE and verify detection |
| 251 | +4. ✅ Run live test (send one notification to Teams) |
| 252 | +5. ✅ Monitor first scheduled run at 10:00 UTC tomorrow |
| 253 | +6. ⏳ Consider adding High severity notifications |
| 254 | +7. ⏳ Extend to Habitat scans (requires habitat_cve_details query) |
| 255 | +8. ⏳ Add email/Jira channels as needed |
0 commit comments