Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Gitleaks Implementation Analysis

Decision: Complementary Implementation

After analyzing your existing secret detection setup, I determined that gitleaks and detect-secrets serve complementary purposes and should both be used:

Current Setup: detect-secrets

  • Excellent baseline management with .secrets.baseline
  • Pattern-based detection with extensive plugins
  • File-focused scanning with comprehensive exclusions
  • Mature allowlisting for ongoing projects

New Addition: gitleaks

  • Git-aware detection - analyzes commit history
  • High-performance scanning - faster for large repositories
  • Specialized Git patterns - catches secrets in Git metadata
  • Different detection algorithms - complementary to detect-secrets

Implementation Details

1. Workflow Configuration (.github/workflows/gitleaks.yml)

name: Git Secrets Detection
on:
  pull_request:
    types: [opened, synchronize, reopened]
  push:
    branches: [main, master, develop]

jobs:
  gitleaks:
    name: Git Secrets with gitleaks
    runs-on: [self-hosted, type-cpx31, image-x86-app-docker-ce]
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v5
        with:
          fetch-depth: 0  # Full history for git analysis
      - name: Run gitleaks
        uses: reviewdog/action-gitleaks@1458857b76107d28d5ebab788230c0d0e23f76ad # v1.7.2
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-review
          level: warning
          fail_level: none
          filter_mode: added
          gitleaks_flags: --no-git

2. Custom Configuration (.gitleaks.toml)

Created a HungryHub-specific configuration that:

Custom Rules

  • HungryHub API Keys: Detects company-specific API key patterns
  • JWT Secrets: Identifies JWT signing keys
  • Database URLs: Catches database connection strings

Smart Allowlisting

  • Development Files: .env, .secret_env, configuration files
  • Test Data: Test files, specs, examples
  • Build Artifacts: Lock files, compiled assets, vendor directories
  • Secure Storage: Existing credential directories
  • Detection Baselines: .secrets.baseline file exclusion

Production Findings

Successfully reduced false positives from 317 to 2 real issues:

  1. Google Maps API key in locationComponent.vue
  2. Google Maps API key in BookingLanding.vue

These are legitimate security concerns that should be moved to environment variables.

Benefits of Dual Approach

detect-secrets (File-based)

  • Ongoing Management: Baseline tracks approved findings
  • Plugin Ecosystem: Extensive pattern library
  • Development Workflow: Integrates well with code reviews

gitleaks (Git-aware)

  • Historical Analysis: Scans entire Git history
  • Performance: Faster scanning for large repositories
  • Git Integration: Understands Git-specific contexts
  • Commit Analysis: Detects secrets in commit messages/metadata

Workflow Comparison

ToolFocusStrengthsUse Case
detect-secretsFile contentBaseline management, extensive pluginsOngoing development, file-based scanning
gitleaksGit repositorySpeed, Git-awareness, history analysisRepository analysis, Git-specific patterns

Testing Results

Act Validation

YAML Syntax: Both workflows validated successfully
Workflow Structure: Proper reviewdog integration
Tool Functionality: gitleaks 8.28.0 working correctly

Local Testing

Configuration: .gitleaks.toml properly filters false positives
Real Findings: Successfully identified 2 genuine security issues
Performance: Scanned 22MB in 2.5 seconds

Maintenance

Updating Gitleaks Rules

Edit .gitleaks.toml to:

  • Add new allowlist patterns for false positives
  • Create custom rules for company-specific secrets
  • Adjust sensitivity based on findings

Managing Findings

  1. Real Secrets: Remove from code, rotate if exposed, add to environment variables
  2. False Positives: Add patterns to allowlist in .gitleaks.toml
  3. Development Secrets: Ensure they’re in excluded paths

Action Updates

Update the action periodically for security:

uses: reviewdog/action-gitleaks@[new-commit-sha] # vX.X.X

Security Impact

This implementation significantly enhances your security posture by:

  1. Dual Coverage: Two different detection approaches catch different types of secrets
  2. Git History Protection: gitleaks scans historical commits
  3. Real-time Detection: Both tools run on every PR
  4. Actionable Results: Clear identification of legitimate security issues
  5. Low Noise: Smart filtering reduces false positive overhead

The combination of detect-secrets and gitleaks provides comprehensive secret detection coverage while maintaining a clean, actionable workflow for your development team.