This feature allows users to sign their Git commits with GPG keys and verify the authenticity of commits.
Users can manage their GPG public keys through the API:
GET /api/v1/user/gpg_keysGET /api/v1/user/gpg_keys/:idPOST /api/v1/user/gpg_keysDELETE /api/v1/user/gpg_keys/:idTo add a GPG key via API:
curl -X POST \
-H "Authorization: token YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"armored_public_key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n...\n-----END PGP PUBLIC KEY BLOCK-----"}' \
https://your-gogs-instance.com/api/v1/user/gpg_keys
Commits signed with GPG can be verified against the user's imported GPG keys.
git commit -SThe verification process:
The gpg_key table stores user GPG keys:
id: Primary keyowner_id: User ID who owns the keykey_id: Short GPG key ID (16 characters)fingerprint: Full 40-character fingerprintcontent: ASCII-armored public keycan_sign: Whether the key can sign commitscan_encrypt: Whether the key can encrypt dataemails: JSON array of email addresses in the keycreated_unix: Creation timestampupdated_unix: Last update timestampexpired_unix: Expiration timestamp (0 if never expires)Database Layer (internal/database/gpg_keys.go):
GPGKey modelGPGKeysStore with CRUD operationsGPG Utilities (internal/gpgutil/gpg.go):
ParsePublicKey(): Parse and extract key informationVerifyCommitSignature(): Verify commit signaturesExtractSignature(): Extract signature from Git commit objectCreateKeyring(): Create OpenPGP keyring from keysAPI Endpoints (internal/route/api/v1/user/gpg_key.go):
Verification Service (internal/database/gpg_verification.go):
VerifyCommitSignature(): High-level verification methodThe database migration (v23) creates the gpg_key table automatically on startup.
The following features are planned but not yet implemented:
UI Components:
Additional Features:
curl -H "Authorization: token YOUR_API_TOKEN" \
https://your-gogs-instance.com/api/v1/user/gpg_keys
curl -H "Authorization: token YOUR_API_TOKEN" \
https://your-gogs-instance.com/api/v1/user/gpg_keys/1
curl -X DELETE \
-H "Authorization: token YOUR_API_TOKEN" \
https://your-gogs-instance.com/api/v1/user/gpg_keys/1
Generate a GPG key (if you don't have one):
gpg --full-generate-key
List your GPG keys:
gpg --list-secret-keys --keyid-format LONG
Export your public key:
gpg --armor --export YOUR_KEY_ID
Add the exported public key to Gogs via the API
Configure Git to use your GPG key:
git config --global user.signingkey YOUR_KEY_ID
git config --global commit.gpgsign true
With commit.gpgsign enabled, all commits will be signed automatically:
git commit -m "Your commit message"
Or sign a specific commit:
git commit -S -m "Signed commit message"
If verification fails with "no GPG keys found", ensure:
If verification fails with "signature verification failed":