GPG Signing & Audit Trails
You are entering advanced security and compliance training where you'll implement cryptographic commit signing, establish audit trails, and ensure enterprise-grade security for critical software development environments.
Commander, securing version control in enterprise environments is like implementing security protocols for classified space missions. Just as spacecraft systems require cryptographic authentication, secure communications, and complete audit trails for every command and data transmission, your Git repositories need robust security measures that verify identity, ensure data integrity, and maintain comprehensive compliance records.
You'll master Git Security & Compliance and Cryptographic Commit Verification - the advanced security protocols that enable organizations to meet stringent regulatory requirements, implement zero-trust development environments, and maintain complete audit trails for software supply chain security. From GPG key management to compliance automation, you'll build expertise in securing enterprise development workflows.
GPG (GNU Privacy Guard) provides cryptographic signing capabilities that ensure commit authenticity and integrity. Enterprise environments rely on GPG signatures to verify that commits originate from authenticated developers and haven't been tampered with during transmission or storage.
GPG key pair uniquely identifies developer with cryptographic proof
Private key creates digital signature for commit content and metadata
Public key verifies signature authenticity and detects tampering
Verified commits provide non-repudiable audit trail for compliance
# Generate new GPG key with enterprise specifications
gpg --full-generate-key
# Interactive prompts:
# 1. Key type: (1) RSA and RSA (default)
# 2. Key size: 4096 (enterprise standard)
# 3. Expiration: 2y (24 months for enterprise rotation)
# 4. Real name: John Doe
# 5. Email: john.doe@company.com (use corporate email)
# 6. Comment: Enterprise Development Key 2025
# 7. Passphrase: Use strong, unique passphrase
# Alternative: Non-interactive key generation
gpg --batch --full-generate-key <
# List GPG keys to get Key ID
gpg --list-secret-keys --keyid-format=long
# Example output:
# sec rsa4096/ABC123DEF456 2025-01-01 [SC] [expires: 2027-01-01]
# 1234567890ABCDEF1234567890ABCDEF12345678
# uid [ultimate] John Doe (Enterprise Development Key 2025)
# ssb rsa4096/456DEF789ABC 2025-01-01 [E] [expires: 2027-01-01]
# Configure Git to use GPG key (use the Key ID: ABC123DEF456)
git config --global user.signingkey ABC123DEF456
# Enable commit signing by default
git config --global commit.gpgsign true
# Enable tag signing by default
git config --global tag.gpgsign true
# Configure GPG program (if needed)
git config --global gpg.program gpg
# Create test commit with signature
echo "Security test" > test-security.txt
git add test-security.txt
git commit -m "test: verify GPG signing configuration"
# Verify commit signature
git log --show-signature -1
# Expected output shows:
# gpg: Signature made [date] using RSA key ID ABC123DEF456
# gpg: Good signature from "John Doe (Enterprise Development Key 2025) "
# Create signed tag
git tag -s v1.0.0-security-test -m "Security test tag with GPG signature"
# Verify tag signature
git tag -v v1.0.0-security-test
Deploy internal GPG key server for enterprise key distribution and management
# Configure internal key server
gpg --keyserver keyserver.company.com --send-keys ABC123DEF456
# Import keys from enterprise server
gpg --keyserver keyserver.company.com --recv-keys ABC123DEF456
# Search for team member keys
gpg --keyserver keyserver.company.com --search-keys john.doe@company.com
Establish trust relationships between team members through key signing
# Sign colleague's key after verification
gpg --sign-key colleague@company.com
# List signatures on key
gpg --list-signatures john.doe@company.com
# Check trust level
gpg --edit-key john.doe@company.com trust
Implement regular key rotation policies for enhanced security
# GPG Agent configuration for enterprise use
default-cache-ttl 28800 # 8 hours
max-cache-ttl 86400 # 24 hours
pinentry-program /usr/bin/pinentry-curses
# Security settings
no-grab
no-allow-external-cache
enable-ssh-support
# Logging for audit purposes
log-file /var/log/gpg-agent.log
debug-level basic
# Enterprise GPG configuration
keyserver hkps://keyserver.company.com
keyserver-options auto-key-retrieve
keyserver-options honor-keyserver-url
# Crypto preferences (strongest algorithms)
personal-digest-preferences SHA512 SHA384 SHA256
personal-cipher-preferences AES256 AES192 AES
personal-compress-preferences ZLIB BZIP2 ZIP
# Security settings
require-cross-certification
no-symkey-cache
throw-keyids
trust-model tofu+pgp
# Display preferences for audit
keyid-format 0xlong
with-fingerprint
list-options show-uid-validity
verify-options show-uid-validity
Signed commits provide cryptographic proof of authorship and integrity, essential for enterprise environments requiring supply chain security, regulatory compliance, and non-repudiation guarantees.
# Sign individual commit
git commit -S -m "feat: implement user authentication with OAuth2"
# Sign commit with specific key
git commit -S -u ABC123DEF456 -m "fix: resolve security vulnerability in login"
# Amend existing commit with signature
git commit --amend -S --no-edit
# Create signed merge commit
git merge feature-branch -S -m "merge: integrate authentication feature"
# Enable automatic commit signing globally
git config --global commit.gpgsign true
# Enable automatic tag signing
git config --global tag.gpgsign true
# Per-repository signing (overrides global)
git config commit.gpgsign true
# Disable signing for specific commit (when global signing enabled)
git commit --no-gpg-sign -m "docs: update README"
# Create signed tag
git tag -s v2.1.0 -m "Release version 2.1.0 with security enhancements"
# Create signed tag with detailed message
git tag -s v2.1.1 -F release-notes.txt
# List tags with signature information
git tag -v v2.1.0
# Verify all tags
git tag -l | xargs -I {} git tag -v {}
# Show signature status for recent commits
git log --show-signature -10
# Show signature status with custom format
git log --pretty="format:%h %G? %aN %s" -10
# Signature status codes:
# G = Good signature from known key
# B = Bad signature
# U = Good signature from unknown key
# X = Good signature that has expired
# Y = Good signature made by expired key
# R = Good signature made by revoked key
# E = Cannot check signature (missing key)
# Verify specific commit
git verify-commit HEAD
git verify-commit abc1234
# Show only verified commits
git log --show-signature | grep -B5 -A5 "Good signature"
# Verify specific tag
git verify-tag v2.1.0
# Show tag with signature details
git show --show-signature v2.1.0
# List all tags with verification status
for tag in $(git tag -l); do
echo "Verifying $tag:"
git verify-tag $tag 2>&1 | head -1
echo ""
done
# Verify tag during checkout
git checkout v2.1.0
git verify-tag HEAD
All commits to protected branches must be signed
#!/bin/bash
# pre-receive hook to enforce signed commits
while read oldrev newrev refname; do
# Check if pushing to protected branch
if [[ $refname == "refs/heads/main" ]]; then
# Verify all commits are signed
git rev-list $oldrev..$newrev | while read commit; do
if ! git verify-commit $commit > /dev/null 2>&1; then
echo "Error: Commit $commit is not signed"
exit 1
fi
done
fi
done
Automated verification in CI/CD pipelines
# GitHub Actions workflow
name: Security Verification
on: [push, pull_request]
jobs:
verify-signatures:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Import GPG keys
run: |
gpg --keyserver keyserver.company.com --recv-keys ${{ secrets.TRUSTED_KEYS }}
- name: Verify commit signatures
run: |
git log --format="%H" origin/main..HEAD | while read commit; do
if ! git verify-commit $commit; then
echo "::error::Unsigned commit found: $commit"
exit 1
fi
done
Enterprise compliance requires comprehensive audit trails, automated reporting, and adherence to regulatory frameworks. Git repositories must maintain detailed logs of all activities for security audits and compliance verification.
System and Organization Controls - Trust service criteria for security, availability, and confidentiality
# SOC 2 audit log generation
git log --format="%H|%an|%ae|%ad|%s|%G?" --date=iso-strict > soc2-commit-audit.log
# Access control audit
git log --format="%H|%an|%ae|%ad" --grep="access\|permission\|role" > access-changes.log
Payment Card Industry Data Security Standard - Requirements for payment card data protection
Health Insurance Portability and Accountability Act - Healthcare data protection requirements
#!/bin/bash
# Enterprise compliance reporting script
REPORT_DATE=$(date +%Y-%m-%d)
REPORT_DIR="compliance-reports/$REPORT_DATE"
mkdir -p "$REPORT_DIR"
# Signature verification report
echo "=== GPG Signature Compliance Report ===" > "$REPORT_DIR/signature-report.txt"
echo "Report Date: $REPORT_DATE" >> "$REPORT_DIR/signature-report.txt"
echo "" >> "$REPORT_DIR/signature-report.txt"
# Check last 30 days of commits
git log --since="30 days ago" --format="%H|%an|%ae|%ad|%G?" --date=iso-strict > temp-commits.log
# Count signature status
TOTAL_COMMITS=$(wc -l < temp-commits.log)
SIGNED_COMMITS=$(grep -c "|G$" temp-commits.log)
UNSIGNED_COMMITS=$(grep -c "|N$" temp-commits.log)
BAD_SIGNATURE=$(grep -c "|B$" temp-commits.log)
echo "Total Commits (30 days): $TOTAL_COMMITS" >> "$REPORT_DIR/signature-report.txt"
echo "Signed Commits: $SIGNED_COMMITS ($(( SIGNED_COMMITS * 100 / TOTAL_COMMITS ))%)" >> "$REPORT_DIR/signature-report.txt"
echo "Unsigned Commits: $UNSIGNED_COMMITS" >> "$REPORT_DIR/signature-report.txt"
echo "Bad Signatures: $BAD_SIGNATURE" >> "$REPORT_DIR/signature-report.txt"
# Detailed unsigned commits
if [ $UNSIGNED_COMMITS -gt 0 ]; then
echo "" >> "$REPORT_DIR/signature-report.txt"
echo "=== UNSIGNED COMMITS (COMPLIANCE VIOLATION) ===" >> "$REPORT_DIR/signature-report.txt"
grep "|N$" temp-commits.log >> "$REPORT_DIR/signature-report.txt"
fi
# Access pattern analysis
echo "=== Access Pattern Analysis ===" > "$REPORT_DIR/access-report.txt"
git log --since="30 days ago" --format="%an|%ae|%ad" --date=iso-strict | \
sort | uniq -c | sort -nr >> "$REPORT_DIR/access-report.txt"
# Security events
echo "=== Security-Related Changes ===" > "$REPORT_DIR/security-events.txt"
git log --since="30 days ago" --grep="security\|auth\|login\|password\|token\|credential" \
--format="%H|%an|%ad|%s" --date=iso-strict >> "$REPORT_DIR/security-events.txt"
rm temp-commits.log
echo "Compliance reports generated in $REPORT_DIR"
#!/bin/bash
# Real-time security monitoring
# Check for unsigned commits in last hour
UNSIGNED_RECENT=$(git log --since="1 hour ago" --format="%H|%an|%G?" | grep "|N$" | wc -l)
if [ $UNSIGNED_RECENT -gt 0 ]; then
# Send alert to security team
curl -X POST "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK" \
-H 'Content-type: application/json' \
--data '{
"text": "🚨 SECURITY ALERT: '"$UNSIGNED_RECENT"' unsigned commits detected in repository",
"channel": "#security-alerts",
"username": "Git Security Monitor"
}'
# Log security event
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ)|UNSIGNED_COMMIT_ALERT|$UNSIGNED_RECENT commits" >> /var/log/git-security.log
fi
# Check for suspicious access patterns
FAILED_AUTHS=$(grep "authentication failure" /var/log/auth.log | tail -n 100 | wc -l)
if [ $FAILED_AUTHS -gt 10 ]; then
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ)|SUSPICIOUS_ACCESS|$FAILED_AUTHS failed attempts" >> /var/log/git-security.log
fi
Comprehensive security requires automated scanning for vulnerabilities, secrets, and compliance violations integrated into development workflows and continuous monitoring systems.
Prevent sensitive information from entering version control
Real-time secret detection with policy enforcement
High-entropy string and credential pattern detection
Yelp's baseline and scanning tool for secrets
# .pre-commit-config.yaml
repos:
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
exclude: package.lock.json
- repo: https://github.com/trufflesecurity/trufflehog
rev: v3.63.2
hooks:
- id: trufflehog
name: TruffleHog
description: Detect secrets in your data.
entry: bash -c 'trufflehog git file://. --since-commit HEAD --only-verified --fail'
Analyze source code for security vulnerabilities and quality issues
Comprehensive code quality and security analysis
GitHub's semantic code analysis engine
Fast, customizable static analysis rules
# .github/workflows/security-scan.yml
name: Security Analysis
on: [push, pull_request]
jobs:
codeql:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: github/codeql-action/init@v2
with:
languages: javascript, python
- uses: github/codeql-action/autobuild@v2
- uses: github/codeql-action/analyze@v2
semgrep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: returntocorp/semgrep-action@v1
with:
config: >-
p/security-audit
p/secrets
Identify vulnerabilities in third-party dependencies and licenses
Vulnerability scanning for dependencies and containers
Open-source dependency vulnerability scanner
Free license and vulnerability scanner
#!/bin/bash
# Dependency security scan script
echo "Starting dependency security scan..."
# Node.js dependencies
if [ -f "package.json" ]; then
echo "Scanning npm dependencies..."
npm audit --audit-level=moderate
# Snyk scanning
npx snyk test --severity-threshold=high
fi
# Python dependencies
if [ -f "requirements.txt" ]; then
echo "Scanning Python dependencies..."
safety check -r requirements.txt
# pip-audit scanning
pip-audit -r requirements.txt
fi
# License compliance check
echo "Checking license compliance..."
license-checker --onlyAllow 'MIT;Apache-2.0;BSD-3-Clause;ISC' --summary