|
| 1 | +# NVD API Key Configuration |
| 2 | + |
| 3 | +## Problem |
| 4 | + |
| 5 | +OWASP dependency scans run **15-60+ minutes without an NVD API key**, vs **2-5 minutes with one**. |
| 6 | + |
| 7 | +Build warning: |
| 8 | + |
| 9 | +``` |
| 10 | +[WARNING] An NVD API Key was not provided - it is highly recommended to use |
| 11 | + an NVD API key as the update can take a VERY long time without an API Key |
| 12 | +``` |
| 13 | + |
| 14 | +## Solution |
| 15 | + |
| 16 | +### 1. Request NVD API Key |
| 17 | + |
| 18 | +Visit: https://nvd.nist.gov/developers/request-an-api-key (free, ~5 min) |
| 19 | + |
| 20 | +### 2. Add to Azure DevOps Library |
| 21 | + |
| 22 | +1. **Pipelines → Library** |
| 23 | +2. Find variable group: `stacks-java-module-parent` |
| 24 | +3. Add secret: |
| 25 | + - **Name**: `VULNERABILITY_SCAN_API_KEY` |
| 26 | + - **Value**: `<your-nvd-api-key>` |
| 27 | + - **Mark as secret**: ✅ |
| 28 | + |
| 29 | +### 3. Verify |
| 30 | + |
| 31 | +Queue a new build. Look for in logs: |
| 32 | + |
| 33 | +``` |
| 34 | +[INFO] Using NVD API Key to download latest vulnerability data ✅ |
| 35 | +``` |
| 36 | + |
| 37 | +## How It Works |
| 38 | + |
| 39 | +``` |
| 40 | +Azure DevOps Secret (VULNERABILITY_SCAN_API_KEY) |
| 41 | + ↓ |
| 42 | +Pipeline YAML (azure-pipelines-javaspring-deploy.yml) |
| 43 | + ↓ |
| 44 | +Variable Definition (azuredevops-vars.yml) |
| 45 | + ↓ |
| 46 | +Build Template (stacks-pipeline-templates) |
| 47 | + ↓ |
| 48 | +Environment Variable (NVD_API_KEY) |
| 49 | + ↓ |
| 50 | +Maven pom.xml |
| 51 | + ↓ |
| 52 | +OWASP Plugin → NVD API |
| 53 | +``` |
| 54 | + |
| 55 | +## Configuration Files |
| 56 | + |
| 57 | +| File | Line | Purpose | Status | |
| 58 | +| --------------------------------------- | ------- | ------------------------------------------- | ---------- | |
| 59 | +| `pom.xml` | 302 | `<nvdApiKey>${env.NVD_API_KEY}</nvdApiKey>` | ✅ Ready | |
| 60 | +| `azure-pipelines-javaspring-deploy.yml` | 50 | Load variable group | ✅ Ready | |
| 61 | +| `azure-pipelines-javaspring-deploy.yml` | 88 | Pass to template | ✅ Ready | |
| 62 | +| `azuredevops-vars.yml` | 104-106 | Map to secret | ✅ Ready | |
| 63 | +| Azure DevOps Library | — | **NEEDS SETUP** | ❌ Missing | |
| 64 | + |
| 65 | +## Local Development |
| 66 | + |
| 67 | +Run security scans locally with API key: |
| 68 | + |
| 69 | +```bash |
| 70 | +# Option 1: Environment Variable |
| 71 | +export NVD_API_KEY="your-api-key" |
| 72 | +./mvnw -P owasp-dependency-check clean verify |
| 73 | + |
| 74 | +# Option 2: Maven Property |
| 75 | +./mvnw -P owasp-dependency-check clean verify -Dnvd.api.key=your-api-key |
| 76 | + |
| 77 | +# Option 3: Maven Settings |
| 78 | +# Add to ~/.m2/settings.xml: <nvd.api.key>your-api-key</nvd.api.key> |
| 79 | +``` |
| 80 | + |
| 81 | +## Troubleshooting |
| 82 | + |
| 83 | +### Still Seeing Warning After Setup? |
| 84 | + |
| 85 | +1. Verify variable group name: must be **exactly** `stacks-java-module-parent` |
| 86 | +2. Verify secret name: must be **exactly** `VULNERABILITY_SCAN_API_KEY` |
| 87 | +3. Queue a new build (first build with secret may need explicit trigger) |
| 88 | +4. Wait 1-2 builds for Azure DevOps to propagate |
| 89 | + |
| 90 | +### API Key Not Working? |
| 91 | + |
| 92 | +1. Verify format: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` (valid UUID) |
| 93 | +2. Request new key: https://nvd.nist.gov/developers/request-an-api-key (old keys may expire) |
| 94 | +3. Check network: Build agent must reach `https://services.nvd.nist.gov/` |
| 95 | + |
| 96 | +### Rate Limiting? |
| 97 | + |
| 98 | +NVD API has rate limits. If you see rate limit errors, wait a few minutes and retry. |
| 99 | + |
| 100 | +## Performance Impact |
| 101 | + |
| 102 | +| Scenario | Scan Time | |
| 103 | +| --------------- | ----------------- | |
| 104 | +| Without API Key | 15-60+ min | |
| 105 | +| With API Key | 2-5 min | |
| 106 | +| **Speedup** | **10-50x faster** | |
| 107 | + |
| 108 | +## Security |
| 109 | + |
| 110 | +✅ **Best Practices**: |
| 111 | + |
| 112 | +- Secret stored encrypted in Azure DevOps Library |
| 113 | +- Automatically masked in build logs |
| 114 | +- Not stored in source code |
| 115 | +- Only accessible to authorized pipelines |
| 116 | + |
| 117 | +⚠️ **Never**: |
| 118 | + |
| 119 | +- Commit API key to Git |
| 120 | +- Put in plain text YAML |
| 121 | +- Log or print in builds |
| 122 | +- Share across organizations |
| 123 | + |
| 124 | +## References |
| 125 | + |
| 126 | +- [NVD API](https://nvd.nist.gov/developers/start-here) |
| 127 | +- [OWASP Dependency-Check](https://jeremylong.github.io/DependencyCheck_Plugin/) |
| 128 | +- [Azure DevOps Library](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/) |
| 129 | +- [Azure DevOps Secret Variables](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables) |
0 commit comments