ggshield Documentation

repository·main·Indexed 24 days ago

https://github.com/gitguardian/ggshield

ggshield is a CLI application designed to detect over 500 types of secrets in local environments, repositories, Docker images, and PyPI packages. It integrates with GitGuardian's public API to provide secure scanning without storing secrets or files on their dashboard. The tool supports installation via official scripts, Homebrew, Chocolatey, and pipx/pip, and can be integrated with AI coding assistants like Cursor, Claude Code, Copilot Chat, and Codex.

Tokens
20.1K
Snippets
30
Records
143
Agent score
81%

What's inside ggshield

  1. Understand the GGShield architecture and dependency layers

    main

    GGShield is structured into distinct layers to maintain separation of concerns. The architecture follows a strict hierarchy enforced by import-linter. When extending or modifying the codebase, you must adhere to these import rules:

    1. cmd (Top Layer): Implements CLI commands (e.g., ggshield secret scan path is located in cmd.secret.scan.path). These modules can import from verticals, core, utils, and py-gitguardian.
    2. verticals: Contains code specific to a single vertical. These modules can only import from core, utils, and py-gitguardian.
    3. core: Contains basic modules used by both verticals and cmd. These can only import from utils and py-gitguardian.
    4. utils: Contains generic, reusable code. These modules cannot import from any other ggshield modules or from py-gitguardian to ensure they remain generic.

    Note: All API interactions with the GitGuardian REST API should be implemented via the py-gitguardian package.

  2. Create a GitHub Enterprise Server (GHES) pre-receive hook environment

    main

    Use the create-ghe-environment script to create a GHES pre-receive hook environment containing GGShield.

    Requirements:

    • Docker: Must be installed on your machine.
    • Architecture: The script must be run on the same machine architecture as the target GHES server where the environment will be uploaded.

    For more details on GHES pre-receive hooks, refer to the official GitHub Enterprise Server documentation.

  3. Update dependencies in GGShield

    main

    To update a specific dependency within the GGShield project, follow these steps:

    1. Update the dependency version in pyproject.toml.
    2. Apply any necessary code changes required by the new version.
    3. Update the lock file by running uv lock --upgrade-package <dependency>.
    4. File a Pull Request.
    uv lock --upgrade-package <dependency>
  4. Configure Windows signing for ggshield MSI packages

    main

    To build signed Windows MSI packages, you must have the .NET SDK and the WiX CLI tool installed (dotnet tool install --global wix --version 5.0.2).

    Required Environment Variables:

    • $WINDOWS_CERT_FINGERPRINT: The thumbprint of the certificate.
    • $SM_API_KEY: DigiCert API token.
    • $SM_HOST: The DigiCert host.
    • $SM_CLIENT_CERT_FILE: Path to the signing user authentication certificate.
    • $SM_CLIENT_CERT_PASSWORD: Password for the signing user authentication certificate.

    PATH Requirements: Your $PATH must include the directories for:

    1. signtool.exe (from Microsoft).
    2. smctl.exe (provided by DigiCert, typically in C:\Program Files\DigiCert\DigiCert Keylocker Tools).

    Installation Tip: You can use the provided helper script to install DigiCert tools: scripts/build-os-packages/install-keylocker-tools (Note: $SM_API_KEY must be set for this to work, and $PATH must already include the smctl.exe path).

  5. Run the Hashicorp Vault test server

    main

    For testing purposes related to ggshield check-secret-manager hashicorp-vault, you can run a local Hashicorp Vault instance using a provided helper script. This server runs on the default Vault port 8200 and includes pre-populated test data and specific tokens designed to avoid triggering ggshield scans.

    Server Details:

    • Port: 8200
    • Web UI: http://127.0.0.1:8200
    • Pre-populated KV Mounts:
      • secret_v1 (version 1)
      • secret (version 2)
    • Available Tokens:
      • my_vault_token: Root token with all rights.
      • restricted_token: Token with the default policy (cannot read KV mounts; useful for testing error handling).
  6. Uninstall ggshield

    main

    To remove the standalone installation created by the scripts, use the corresponding uninstaller. Note that these uninstallers only remove the files created by the scripts and do not touch installations made via other package managers (like brew or apt).

    Linux / macOS

    curl -sSfL \
      https://raw.githubusercontent.com/GitGuardian/ggshield/main/scripts/install/uninstall.sh | bash

    Windows (PowerShell)

    irm https://raw.githubusercontent.com/GitGuardian/ggshield/main/scripts/install/uninstall.ps1 | iex

    Purge configuration and data

    By default, the uninstaller does not remove configuration, cache, or data. To perform a complete removal including ~/.gitguardian.yaml, plugins, and scan DBs, use the --purge (Linux/macOS) or -Purge (Windows) flag.

    Non-interactive usage (CI/CD): You must pass -y or --yes to avoid prompts in non-interactive environments.

    Example (Linux/macOS):

    curl -sSfL \
      https://raw.githubusercontent.com/GitGuardian/ggshield/main/scripts/install/uninstall.sh | \
      bash -s -- --purge -y
  7. Use an unreleased version of py-gitguardian in CI

    main

    To ensure changes in an unreleased version of py-gitguardian pass in Continuous Integration (CI), you must point the dependency to a specific git commit using a git+https URL in pyproject.toml and update the lock file.

    1. Update the pygitguardian entry in pyproject.toml to use a git URL with a specific commit hash:
    dependencies = [
        (...)
        "pygitguardian @ git+https://github.com/GitGuardian/py-gitguardian.git@<commit_hash>"
        (...)
    ]
    1. Update the lock file using uv:
    uv lock --upgrade-package pygitguardian
    dependencies = [
        (...)
        # TODO: replace this with a real version number as soon as a new version of
        # py-gitguardian is out
        "pygitguardian @ git+https://github.com/GitGuardian/py-gitguardian.git@cfa919cff68cc4d3ca40bf2bb8a6f245fca786"
        (...)
    ]
  8. Install ggshield using the recommended script

    main

    The quickest way to install ggshield is via the official installation scripts. These scripts support options like --instance (to specify a custom GitGuardian instance) and --plugin (to install a plugin).

    For EU workspaces or self-hosted instances, set the GITGUARDIAN_INSTANCE environment variable before running the script.

    Linux / macOS:

    curl -sSfL \
      https://raw.githubusercontent.com/GitGuardian/ggshield/main/scripts/install/install.sh | bash

    Windows (PowerShell):

    irm https://raw.githubusercontent.com/GitGuardian/ggshield/main/scripts/install/install.ps1 | iex

    Windows (using curl):

    curl.exe -sSL https://raw.githubusercontent.com/GitGuardian/ggshield/main/scripts/install/install.ps1 | powershell -NoProfile -ExecutionPolicy Bypass -Command -
    curl -sSfL \
      https://raw.githubusercontent.com/GitGuardian/ggshield/main/scripts/install/install.sh | bash
  9. Setup your development environment

    main

    To set up a development environment for ggshield, follow these steps:

    1. Install uv.
    2. Install the pre-commit framework.
    3. Fork and clone the repository.
    4. Install development packages and create the environment using uv:
      uv sync --all-groups
      source .venv/bin/activate
    5. Install the pre-commit hooks:
      pre-commit install
      pre-commit install --hook-type commit-msg
    uv sync --all-groups
    source .venv/bin/activate
    pre-commit install
    pre-commit install --hook-type commit-msg
  10. Use an unreleased version of py-gitguardian locally

    main

    If you are developing changes in py-gitguardian and want to test them within ggshield on your local machine, you can install your local checkout in editable mode. This only needs to be done once; subsequent changes in your py-gitguardian directory will be immediately reflected in ggshield.

    1. Activate the ggshield virtual environment.
    2. Run pip install -e pointing to your local py-gitguardian checkout.
    pip install -e path/to/your/py-gitguardian/checkout
  11. Authenticate ggshield with GitGuardian

    main

    To use ggshield, you must authenticate against GitGuardian servers.

    Option 1: Automated Login (Recommended) Use the ggshield auth login command to automatically provision a personal access token and configure it on your local workstation.

    ggshield auth login

    Option 2: Manual Setup Create a personal access token manually and store it in the GITGUARDIAN_API_KEY environment variable.

    ggshield auth login