|
| 1 | +# Setting Up GitHub Secrets for Integration Tests |
| 2 | + |
| 3 | +## ⚠️ IMPORTANT SECURITY NOTICE |
| 4 | + |
| 5 | +**NEVER commit API keys or secrets directly to your repository!** Always use GitHub Secrets for sensitive information. |
| 6 | + |
| 7 | +## Required Secrets |
| 8 | + |
| 9 | +To run the Integration tests in GitHub Actions, you need to configure the following secrets: |
| 10 | + |
| 11 | +### 1. NUTRIENT_API_KEY (Required) |
| 12 | +Your Nutrient DWS Processor API key for running integration tests. |
| 13 | + |
| 14 | +### 2. NPM_TOKEN (Optional) |
| 15 | +Required only if you want to automatically publish to NPM. |
| 16 | + |
| 17 | +### 3. SNYK_TOKEN (Optional) |
| 18 | +Required only if you want to run Snyk security scans. |
| 19 | + |
| 20 | +## How to Add Secrets |
| 21 | + |
| 22 | +1. Go to your repository on GitHub |
| 23 | +2. Click on **Settings** (you need admin access) |
| 24 | +3. In the left sidebar, click **Secrets and variables** → **Actions** |
| 25 | +4. Click **New repository secret** |
| 26 | +5. Add each secret: |
| 27 | + - Name: `NUTRIENT_API_KEY` |
| 28 | + - Value: Your API key (without quotes) |
| 29 | + - Click **Add secret** |
| 30 | + |
| 31 | +## Security Best Practices |
| 32 | + |
| 33 | +### 1. Rotate API Keys Regularly |
| 34 | +- Create a schedule to rotate your API keys every 90 days |
| 35 | +- Update the GitHub secret when you rotate keys |
| 36 | + |
| 37 | +### 2. Use Scoped API Keys |
| 38 | +- If possible, use API keys with limited scope for testing |
| 39 | +- Never use production API keys for testing |
| 40 | + |
| 41 | +### 3. Monitor Usage |
| 42 | +- Regularly check your API key usage |
| 43 | +- Set up alerts for unusual activity |
| 44 | + |
| 45 | +### 4. Restrict Secret Access |
| 46 | +- GitHub secrets are only available to workflows running on your repository |
| 47 | +- They are not exposed to pull requests from forks |
| 48 | +- Integration tests only run on: |
| 49 | + - Pushes to main branch |
| 50 | + - Pull requests from the same repository |
| 51 | + |
| 52 | +### 5. Environment-Specific Keys |
| 53 | +Consider using different API keys for different environments: |
| 54 | + |
| 55 | +```yaml |
| 56 | +# In your workflow |
| 57 | +env: |
| 58 | + NUTRIENT_API_KEY: ${{ github.ref == 'refs/heads/main' && secrets.NUTRIENT_API_KEY_PROD || secrets.NUTRIENT_API_KEY_DEV }} |
| 59 | +``` |
| 60 | +
|
| 61 | +## Workflow Security Features |
| 62 | +
|
| 63 | +Our GitHub Actions workflows include several security features: |
| 64 | +
|
| 65 | +1. **Secret Scanning**: Automatically checks for hardcoded secrets |
| 66 | +2. **Dependency Scanning**: Checks for vulnerable dependencies |
| 67 | +3. **Code Scanning**: Uses CodeQL to find security vulnerabilities |
| 68 | +4. **Limited Integration Execution**: Integration tests only run on trusted sources |
| 69 | +
|
| 70 | +## Local Development |
| 71 | +
|
| 72 | +For local development, use environment variables: |
| 73 | +
|
| 74 | +```bash |
| 75 | +# Create a .env file (already in .gitignore) |
| 76 | +echo "NUTRIENT_API_KEY=your_api_key_here" > .env |
| 77 | + |
| 78 | +# Run integration tests locally |
| 79 | +source .env |
| 80 | +npm run test:integration |
| 81 | +``` |
| 82 | + |
| 83 | +## Troubleshooting |
| 84 | + |
| 85 | +### Integration Tests Not Running |
| 86 | +- Check that the secret is properly set in GitHub |
| 87 | +- Verify the secret name matches exactly: `NUTRIENT_API_KEY` |
| 88 | +- Check the workflow logs for authentication errors |
| 89 | + |
| 90 | +### Authentication Errors |
| 91 | +- Ensure the API key is valid and active |
| 92 | +- Check that the API key has the necessary permissions |
| 93 | +- Verify the API key format (no extra spaces or quotes) |
| 94 | + |
| 95 | +## Emergency Response |
| 96 | + |
| 97 | +If an API key is accidentally exposed: |
| 98 | + |
| 99 | +1. **Immediately revoke the exposed key** in your Nutrient dashboard |
| 100 | +2. **Generate a new API key** |
| 101 | +3. **Update the GitHub secret** with the new key |
| 102 | +4. **Check logs** for any unauthorized usage |
| 103 | +5. **Run security scan** to ensure no other secrets are exposed |
| 104 | + |
| 105 | +## Questions? |
| 106 | + |
| 107 | +If you have questions about security or need help setting up secrets, please open an issue (without including any sensitive information). |
0 commit comments