|
| 1 | +# Agent GPG Commit Signing |
| 2 | + |
| 3 | +This guide covers GPG commit signing for Flowspec agents, enabling cryptographic verification of agent-generated commits. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Flowspec agents can generate their own GPG keys and sign commits to provide: |
| 8 | +- **Cryptographic verification** of agent authorship |
| 9 | +- **Non-repudiation** - proof that commits came from the agent |
| 10 | +- **Trust chains** - link agent commits to their originating workflow |
| 11 | +- **Audit trails** - track which agent made which changes |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +### 1. Set Up GPG Signing |
| 16 | + |
| 17 | +```bash |
| 18 | +# Generate agent GPG key and configure git |
| 19 | +flowspec gpg setup |
| 20 | + |
| 21 | +# Output: |
| 22 | +# ✓ GPG key generated |
| 23 | +# ✓ Git configured for signing |
| 24 | +# |
| 25 | +# Fingerprint: A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 |
| 26 | +``` |
| 27 | + |
| 28 | +### 2. Verify Status |
| 29 | + |
| 30 | +```bash |
| 31 | +# Check GPG signing status |
| 32 | +flowspec gpg status |
| 33 | + |
| 34 | +# Output: |
| 35 | +# ┌─ Agent GPG Signing Status ─┐ |
| 36 | +# │ Status Configured │ |
| 37 | +# │ Fingerprint A1B2C3... │ |
| 38 | +# │ Git Signing Enabled │ |
| 39 | +# └─────────────────────────────┘ |
| 40 | +``` |
| 41 | + |
| 42 | +### 3. Make Signed Commits |
| 43 | + |
| 44 | +Once configured, all commits in the repository will be automatically signed by the agent: |
| 45 | + |
| 46 | +```bash |
| 47 | +git commit -m "feat: add new feature" |
| 48 | +# Commit is automatically signed with agent's GPG key |
| 49 | +``` |
| 50 | + |
| 51 | +## Commands |
| 52 | + |
| 53 | +### `flowspec gpg setup` |
| 54 | + |
| 55 | +Generate a new GPG key and configure git for commit signing. |
| 56 | + |
| 57 | +```bash |
| 58 | +# Set up in current repository |
| 59 | +flowspec gpg setup |
| 60 | + |
| 61 | +# Set up in specific repository |
| 62 | +flowspec gpg setup --project-root /path/to/repo |
| 63 | + |
| 64 | +# Force key regeneration |
| 65 | +flowspec gpg setup --force |
| 66 | +``` |
| 67 | + |
| 68 | +**What it does:** |
| 69 | +1. Generates a 4096-bit RSA GPG key for "Flowspec Agent <agent@flowspec.local>" |
| 70 | +2. Stores the key fingerprint in the system keyring |
| 71 | +3. Configures local git settings: |
| 72 | + - `user.signingkey`: agent's GPG fingerprint |
| 73 | + - `commit.gpgsign`: true |
| 74 | + |
| 75 | +### `flowspec gpg status` |
| 76 | + |
| 77 | +Show current GPG signing configuration and status. |
| 78 | + |
| 79 | +```bash |
| 80 | +# Check status in current repository |
| 81 | +flowspec gpg status |
| 82 | + |
| 83 | +# Check status with detailed key information |
| 84 | +flowspec gpg status --verbose |
| 85 | + |
| 86 | +# Check status in specific repository |
| 87 | +flowspec gpg status --project-root /path/to/repo |
| 88 | +``` |
| 89 | + |
| 90 | +**Output includes:** |
| 91 | +- Configuration status (configured/not configured) |
| 92 | +- GPG key fingerprint |
| 93 | +- Git signing status (enabled/disabled) |
| 94 | +- Key creation date (with `--verbose`) |
| 95 | +- Key identity (with `--verbose`) |
| 96 | + |
| 97 | +### `flowspec gpg rotate` |
| 98 | + |
| 99 | +Rotate the agent's GPG key (delete old key, generate new key). |
| 100 | + |
| 101 | +```bash |
| 102 | +# Rotate key (with confirmation prompt) |
| 103 | +flowspec gpg rotate |
| 104 | + |
| 105 | +# Rotate key without confirmation |
| 106 | +flowspec gpg rotate --yes |
| 107 | + |
| 108 | +# Rotate key for specific repository |
| 109 | +flowspec gpg rotate --project-root /path/to/repo |
| 110 | +``` |
| 111 | + |
| 112 | +**When to rotate:** |
| 113 | +- Regular security practice (e.g., annually) |
| 114 | +- Key compromise or suspected compromise |
| 115 | +- Agent role change or re-provisioning |
| 116 | +- Compliance requirements |
| 117 | + |
| 118 | +**Warning:** Rotating a key does not re-sign historical commits. Old commits will still reference the old key fingerprint. |
| 119 | + |
| 120 | +## Key Management |
| 121 | + |
| 122 | +### Key Storage |
| 123 | + |
| 124 | +- **GPG Keychain**: Keys are stored in the user's GPG keychain (`~/.gnupg/`) |
| 125 | +- **Fingerprint**: The key fingerprint is stored in the system keyring for quick retrieval |
| 126 | +- **Service Name**: `flowspec-agent-gpg` |
| 127 | +- **Username**: `agent-key-fingerprint` |
| 128 | + |
| 129 | +### Key Properties |
| 130 | + |
| 131 | +``` |
| 132 | +Name: Flowspec Agent |
| 133 | +Email: agent@flowspec.local |
| 134 | +Type: RSA |
| 135 | +Length: 4096 bits |
| 136 | +Expiration: None (does not expire) |
| 137 | +``` |
| 138 | + |
| 139 | +### Security Considerations |
| 140 | + |
| 141 | +1. **No Passphrase**: Agent keys are generated without a passphrase for automated signing |
| 142 | +2. **Local Storage**: Keys are stored locally on the agent's system |
| 143 | +3. **Per-User**: Each user account has its own agent key |
| 144 | +4. **Repository Config**: Git signing is configured per-repository (local config) |
| 145 | + |
| 146 | +## Git Configuration |
| 147 | + |
| 148 | +GPG signing modifies local git configuration: |
| 149 | + |
| 150 | +```bash |
| 151 | +# View current configuration |
| 152 | +git config --local user.signingkey |
| 153 | +git config --local commit.gpgsign |
| 154 | + |
| 155 | +# Manual configuration (not recommended - use 'flowspec gpg setup') |
| 156 | +git config --local user.signingkey A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 |
| 157 | +git config --local commit.gpgsign true |
| 158 | +``` |
| 159 | + |
| 160 | +## Checking GPG Status |
| 161 | + |
| 162 | +Use the GPG-specific commands to inspect signing configuration: |
| 163 | + |
| 164 | +```bash |
| 165 | +# Check GPG signing status |
| 166 | +flowspec gpg status |
| 167 | + |
| 168 | +# Check with detailed key information |
| 169 | +flowspec gpg status --verbose |
| 170 | +``` |
| 171 | + |
| 172 | +## Verifying Signed Commits |
| 173 | + |
| 174 | +### On GitHub |
| 175 | + |
| 176 | +GitHub automatically verifies GPG-signed commits if the public key is uploaded: |
| 177 | + |
| 178 | +1. Export the agent's public key using the exact fingerprint from `flowspec gpg status`: |
| 179 | + ```bash |
| 180 | + # Replace with the fingerprint shown by `flowspec gpg status` |
| 181 | + gpg --armor --export A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 > agent-key.asc |
| 182 | + ``` |
| 183 | + |
| 184 | +2. Add the key to GitHub: |
| 185 | + - Go to Settings → SSH and GPG keys → New GPG key |
| 186 | + - Paste the contents of `agent-key.asc` |
| 187 | + |
| 188 | +3. Signed commits will show a "Verified" badge |
| 189 | + |
| 190 | +### Locally |
| 191 | + |
| 192 | +```bash |
| 193 | +# Verify a signed commit |
| 194 | +git log --show-signature -1 |
| 195 | + |
| 196 | +# Output: |
| 197 | +# commit abc123def456... |
| 198 | +# gpg: Signature made Thu Apr 3 12:34:56 2025 UTC |
| 199 | +# gpg: using RSA key A1B2C3D4E5F6A7B8C9D0... |
| 200 | +# gpg: Good signature from "Flowspec Agent <agent@flowspec.local>" |
| 201 | +``` |
| 202 | + |
| 203 | +## Key Rotation Workflow |
| 204 | + |
| 205 | +Key rotation is important for security best practices: |
| 206 | + |
| 207 | +```bash |
| 208 | +# 1. Rotate the key |
| 209 | +flowspec gpg rotate --yes |
| 210 | + |
| 211 | +# Output: |
| 212 | +# Old fingerprint: A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 |
| 213 | +# New fingerprint: F0E9D8C7B6A5F4E3D2C1B0A9F8E7D6C5B4A3F2E1 |
| 214 | + |
| 215 | +# 2. Export new public key (use the new fingerprint from the output above) |
| 216 | +gpg --armor --export F0E9D8C7B6A5F4E3D2C1B0A9F8E7D6C5B4A3F2E1 > agent-key-new.asc |
| 217 | + |
| 218 | +# 3. Update GitHub/GitLab with new key |
| 219 | + |
| 220 | +# 4. (Optional) Sign a rotation commit |
| 221 | +git commit --allow-empty -m "chore: rotate agent GPG key |
| 222 | +
|
| 223 | +Previous key: A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 |
| 224 | +New key: F0E9D8C7B6A5F4E3D2C1B0A9F8E7D6C5B4A3F2E1 |
| 225 | +
|
| 226 | +Signed-off-by: Flowspec Agent <agent@flowspec.local>" |
| 227 | +``` |
| 228 | + |
| 229 | +### Rotation Schedule Recommendations |
| 230 | + |
| 231 | +| Environment | Rotation Frequency | Rationale | |
| 232 | +|-------------|-------------------|-----------| |
| 233 | +| Development | Annually | Low risk, convenience | |
| 234 | +| Staging | Quarterly | Moderate risk | |
| 235 | +| Production | Monthly | High security requirements | |
| 236 | +| Compromised | Immediately | Security incident | |
| 237 | + |
| 238 | +## Troubleshooting |
| 239 | + |
| 240 | +### GPG Not Found |
| 241 | + |
| 242 | +``` |
| 243 | +Error: GPG not found. Please install gnupg. |
| 244 | +``` |
| 245 | + |
| 246 | +**Solution:** Install GPG: |
| 247 | +```bash |
| 248 | +# Ubuntu/Debian |
| 249 | +sudo apt install gnupg |
| 250 | + |
| 251 | +# macOS |
| 252 | +brew install gnupg |
| 253 | + |
| 254 | +# Fedora/RHEL |
| 255 | +sudo dnf install gnupg |
| 256 | +``` |
| 257 | + |
| 258 | +### Git Not a Repository |
| 259 | + |
| 260 | +``` |
| 261 | +Error: Not a git repository: /path/to/dir |
| 262 | +``` |
| 263 | + |
| 264 | +**Solution:** Run `flowspec gpg setup` inside a git repository or specify `--project-root`: |
| 265 | +```bash |
| 266 | +cd /path/to/repo |
| 267 | +flowspec gpg setup |
| 268 | +``` |
| 269 | + |
| 270 | +### Commits Not Signed |
| 271 | + |
| 272 | +**Symptoms:** Commits don't show "Verified" badge |
| 273 | + |
| 274 | +**Diagnosis:** |
| 275 | +```bash |
| 276 | +# Check git config |
| 277 | +git config --local commit.gpgsign |
| 278 | +# Should output: true |
| 279 | + |
| 280 | +git config --local user.signingkey |
| 281 | +# Should output: your fingerprint |
| 282 | + |
| 283 | +# Check GPG key exists |
| 284 | +gpg --list-keys agent@flowspec.local |
| 285 | +``` |
| 286 | + |
| 287 | +**Solution:** |
| 288 | +```bash |
| 289 | +# Reconfigure signing |
| 290 | +flowspec gpg setup |
| 291 | +``` |
| 292 | + |
| 293 | +### Keyring Access Error |
| 294 | + |
| 295 | +``` |
| 296 | +Error: Failed to store fingerprint in keyring: ... |
| 297 | +``` |
| 298 | + |
| 299 | +**Solution:** Ensure the system keyring is accessible. On Linux, you may need to install and configure a keyring backend: |
| 300 | +```bash |
| 301 | +sudo apt install gnome-keyring # Ubuntu/Debian |
| 302 | +# or |
| 303 | +sudo dnf install gnome-keyring # Fedora/RHEL |
| 304 | +``` |
| 305 | + |
| 306 | +## Advanced Usage |
| 307 | + |
| 308 | +### Multiple Repositories |
| 309 | + |
| 310 | +Each repository requires its own `flowspec gpg setup` to enable signing. The same agent key is used across all repositories: |
| 311 | + |
| 312 | +```bash |
| 313 | +# Repository A |
| 314 | +cd /path/to/repo-a |
| 315 | +flowspec gpg setup |
| 316 | + |
| 317 | +# Repository B |
| 318 | +cd /path/to/repo-b |
| 319 | +flowspec gpg setup |
| 320 | + |
| 321 | +# Both repos use the same agent key, but each has local git config |
| 322 | +``` |
| 323 | + |
| 324 | +### Disable Signing for a Repository |
| 325 | + |
| 326 | +```bash |
| 327 | +# Disable automatic signing |
| 328 | +git config --local commit.gpgsign false |
| 329 | + |
| 330 | +# Or unset the config |
| 331 | +git config --local --unset commit.gpgsign |
| 332 | +git config --local --unset user.signingkey |
| 333 | +``` |
| 334 | + |
| 335 | +### Export Public Key for Distribution |
| 336 | + |
| 337 | +```bash |
| 338 | +# First, get the exact fingerprint from flowspec |
| 339 | +flowspec gpg status |
| 340 | + |
| 341 | +# Use the specific fingerprint in export commands |
| 342 | +# Replace A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 with your actual fingerprint |
| 343 | + |
| 344 | +# Export ASCII-armored public key |
| 345 | +gpg --armor --export A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 > agent-public-key.asc |
| 346 | + |
| 347 | +# Export binary public key |
| 348 | +gpg --export A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 > agent-public-key.gpg |
| 349 | + |
| 350 | +# Show fingerprint details |
| 351 | +gpg --fingerprint A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 |
| 352 | +``` |
| 353 | + |
| 354 | +### Manual Key Deletion |
| 355 | + |
| 356 | +```bash |
| 357 | +# Look up the key fingerprint |
| 358 | +flowspec gpg status |
| 359 | + |
| 360 | +# Delete secret and public key by fingerprint |
| 361 | +gpg --delete-secret-and-public-key A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6E7F8A9B0 |
| 362 | + |
| 363 | +# Delete fingerprint from keyring |
| 364 | +# (This is handled automatically by 'flowspec gpg rotate') |
| 365 | +``` |
| 366 | + |
| 367 | +## Security Best Practices |
| 368 | + |
| 369 | +1. **Regular Rotation**: Rotate agent keys on a schedule appropriate for your security requirements |
| 370 | +2. **Key Backup**: Consider backing up the private key to a secure location (encrypted) |
| 371 | +3. **Audit Logs**: Monitor telemetry for signing activity |
| 372 | +4. **Access Control**: Restrict access to the agent's keyring and GPG directory |
| 373 | +5. **Verification**: Regularly verify that commits are being signed correctly |
| 374 | +6. **Incident Response**: Have a plan for key rotation in case of compromise |
| 375 | + |
| 376 | +## Related Documentation |
| 377 | + |
| 378 | +- [Telemetry Guide](./telemetry-guide.md) - Telemetry integration with GPG fingerprints |
| 379 | +- [Security Workflow](./security-workflow.md) - Security scanning and compliance |
| 380 | +- [Git Hooks](../reference/git-hooks.md) - Custom hooks for commit signing |
| 381 | + |
| 382 | +## References |
| 383 | + |
| 384 | +- [GPG Manual](https://www.gnupg.org/documentation/manuals/gnupg/) |
| 385 | +- [Git Signing Documentation](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work) |
| 386 | +- [GitHub GPG Verification](https://docs.github.com/en/authentication/managing-commit-signature-verification) |
0 commit comments