Secrets Management Guide¶
This document outlines how API keys and other secrets are managed in the data-sources-manager project.
Local Development¶
For local development, secrets are stored in a .env
file in the root directory. This file is not committed to the repository.
Example .env
file:
NVD_API_KEY=your_nvd_api_key_here
ALIENVAULT_OTX_API_KEY=your_otx_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
GOOGLE_API_KEY=your_google_api_key_here
Validating API Keys¶
Use the included validation tool to verify your API keys are working:
CI/CD Environment¶
For GitHub Actions and other CI/CD environments, secrets should be stored as GitHub Secrets and accessed as environment variables.
Setting up GitHub Secrets¶
- Navigate to your repository on GitHub
- Go to Settings → Secrets and variables → Actions
- Click "New repository secret"
- Add each API key with the same name as in your local
.env
file
Using Secrets in GitHub Actions¶
In your workflow files (.github/workflows/*.yml
), you can access the secrets like this:
jobs:
update-sources:
runs-on: ubuntu-latest
env:
NVD_API_KEY: ${{ secrets.NVD_API_KEY }}
ALIENVAULT_OTX_API_KEY: ${{ secrets.ALIENVAULT_OTX_API_KEY }}
steps:
- uses: actions/checkout@v3
- name: Run update
run: python tools/fetch_sources.py
Adding New Secrets¶
When adding new API keys or other secrets:
- Update the
.env.sample
file with the new variable name (but not the value) - Add validation in
tools/validate_api_keys.py
if appropriate - Update the documentation in
docs/API_KEYS.md
- Add the secret to GitHub Secrets for CI/CD workflows
Security Best Practices¶
- Never commit secrets to the repository
- Rotate API keys periodically
- Use least privilege when creating API keys
- Audit access to secrets regularly
- Revoke compromised keys immediately
Troubleshooting¶
If you encounter issues with API keys:
- Verify the key is correctly copied (no extra spaces or characters)
- Run the validation tool to check if the key is valid
- Check the API provider's documentation for any rate limits or restrictions
- Regenerate the key if necessary