This guide explains how to test the GPG commit signature verification feature in a Docker environment.
# Build and start Gogs with PostgreSQL
docker-compose -f docker-compose.test.yml up --build -d
# Wait for services to be healthy (about 60 seconds)
docker-compose -f docker-compose.test.yml ps
# Check logs
docker-compose -f docker-compose.test.yml logs -f gogs
http://localhost:10080http://localhost:10080/10022gpg --full-generate-key
Follow the prompts:
# List your keys
gpg --list-secret-keys --keyid-format LONG
# Export the public key (replace YOUR_KEY_ID)
gpg --armor --export YOUR_KEY_ID > my-gpg-key.asc
# View the key
cat my-gpg-key.asc
# Set your API token
export GOGS_TOKEN="your_api_token_here"
# Add the GPG key
curl -X POST \
-H "Authorization: token $GOGS_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"armored_public_key\": \"$(cat my-gpg-key.asc | sed ':a;N;$!ba;s/\n/\\n/g')\"}" \
http://localhost:10080/api/v1/user/gpg_keys
# List your GPG keys
curl -H "Authorization: token $GOGS_TOKEN" \
http://localhost:10080/api/v1/user/gpg_keys
Expected response:
[
{
"id": 1,
"key_id": "1234567890ABCDEF",
"fingerprint": "ABCD1234567890ABCDEF1234567890ABCDEF1234",
"public_key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n...",
"emails": ["your.email@example.com"],
"can_sign": true,
"can_encrypt_comms": true,
"can_encrypt_storage": true,
"can_certify": true,
"created": "2025-11-01T22:00:00Z"
}
]
# Configure Git to use your GPG key
git config --global user.signingkey YOUR_KEY_ID
git config --global commit.gpgsign true
# Verify configuration
git config --global --get user.signingkey
git config --global --get commit.gpgsign
# Create a test repository via API
curl -X POST \
-H "Authorization: token $GOGS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"gpg-test","description":"Testing GPG verification","private":false}' \
http://localhost:10080/api/v1/user/repos
# Clone the repository
git clone http://localhost:10080/your-username/gpg-test.git
cd gpg-test
# Create a file
echo "# GPG Test" > README.md
# Commit with GPG signature
git add README.md
git commit -m "Initial commit - signed with GPG"
# Verify the signature locally
git log --show-signature
# Push to Gogs
git push origin main
Access the Gogs container and test signature verification:
# Access Gogs container
docker exec -it gogs-test /bin/bash
# Inside the container, use the gogs CLI or database query
# (This is a manual verification step for testing)
# Or use psql to check the database
docker exec -it gogs-test-postgres psql -U gogs -d gogs -c "SELECT * FROM gpg_key;"
curl -H "Authorization: token $GOGS_TOKEN" \
http://localhost:10080/api/v1/user/gpg_keys | jq
curl -H "Authorization: token $GOGS_TOKEN" \
http://localhost:10080/api/v1/user/gpg_keys/1 | jq
curl -X DELETE \
-H "Authorization: token $GOGS_TOKEN" \
http://localhost:10080/api/v1/user/gpg_keys/1
# Check logs
docker-compose -f docker-compose.test.yml logs gogs
docker-compose -f docker-compose.test.yml logs postgres
# Restart services
docker-compose -f docker-compose.test.yml restart
# Check database
docker exec -it gogs-test-postgres psql -U gogs -d gogs -c "\dt"
# Should see gpg_key table
docker exec -it gogs-test-postgres psql -U gogs -d gogs -c "\d gpg_key"
# Validate the key format
gpg --show-keys my-gpg-key.asc
# Check for proper armor format
head -1 my-gpg-key.asc # Should be: -----BEGIN PGP PUBLIC KEY BLOCK-----
tail -1 my-gpg-key.asc # Should be: -----END PGP PUBLIC KEY BLOCK-----
# Use your Gogs username and password (or token)
git config credential.helper store
git push origin main
# Enter username and password when prompted
# Stop and remove containers
docker-compose -f docker-compose.test.yml down
# Remove volumes (WARNING: deletes all data)
docker-compose -f docker-compose.test.yml down -v
# Remove test repository
rm -rf gpg-test
The gpg_key table should have these columns:
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'gpg_key';
Expected columns:
Create a test script to verify commit signatures:
# Inside the Gogs container
docker exec -it gogs-test /bin/bash
# Create a test Go file
cat > /tmp/test_verify.go <<'EOF'
package main
import (
"context"
"fmt"
"gogs.io/gogs/internal/database"
"gogs.io/gogs/internal/gpgutil"
)
func main() {
// This is a placeholder - actual implementation would need proper setup
fmt.Println("Testing GPG verification...")
commitContent := `tree abc123
parent def456
author John Doe <john@example.com> 1234567890 +0000
committer John Doe <john@example.com> 1234567890 +0000
gpgsig -----BEGIN PGP SIGNATURE-----
iQIzBAABCAAdFiEE...
-----END PGP SIGNATURE-----
Initial commit
`
signature, payload, hasSig := gpgutil.ExtractSignature(commitContent)
fmt.Printf("Has signature: %v\n", hasSig)
fmt.Printf("Signature length: %d\n", len(signature))
fmt.Printf("Payload length: %d\n", len(payload))
}
EOF