Webhook icon
Schedule icon
WorkingDirectory icon
Clone icon
Commands icon
Docker icon
Switch icon
SlackIncomingWebhook icon
Fail icon
Log icon

Audit Git-crypt Secret Encryption and Header Integrity Gate

Audit git-crypt repositories in Kestra to detect unencrypted plaintext secrets, verify cryptographic magic headers, and gate pull requests before merge.

Categories
Infrastructure

Automate continuous security verification for GitOps repositories using git-crypt. This workflow audits .gitattributes configuration, scans tracked files for binary cryptographic magic headers (\x00GITCRYPT\x00), identifies exposed sensitive files matching credential patterns, and blocks CI/CD pull request merges before plaintext leaks reach production branches.

How it works

  1. Trigger on Webhook or Schedule: The workflow executes on pull request or push webhook events triggered by Git hosting providers (GitHub, GitLab, Bitbucket), or periodically via a weekly cron schedule.
  2. Isolated Repository Checkout: The WorkingDirectory and git.Clone tasks clone the target repository branch inside an ephemeral workspace using a secure deploy token.
  3. Cryptographic Header & Attributes Verification: The Commands task runs an isolated container that parses .gitattributes for filter=git-crypt diff=git-crypt rules, scans repository files against sensitive credential patterns (*.env, *.pem, *.key, *secret*), and reads the first 10 raw bytes of each secret file to ensure the standard 10-byte git-crypt magic header is present.
  4. Metric Aggregation: Structured JSON telemetry (audit_status, scanned_files_count, encrypted_files_count, plaintext_leaks_count, untracked_sensitive_count) is emitted via Kestra output variables.
  5. Conditional Gate & Alerting: The Switch task evaluates audit_status. If plaintext secrets or unencrypted files are detected, an incident payload is posted to Slack and the workflow invokes execution.Fail to fail the gate. If all secret files are encrypted and verified, the workflow logs clean compliance metrics.

What you get

  • Zero-Trust GitOps Secret Enforcement: Prevents accidental commits of plaintext .env, private keys, and API tokens by enforcing encryption at the pre-merge stage.
  • Cryptographic Header Validation: Distinguishes between files that are genuinely encrypted on disk and unencrypted files falsely matched by stale .gitattributes.
  • Automated Pull Request Blocking: Halts pipeline execution when secret leaks or untracked sensitive patterns are detected, preventing unauthorized merges.
  • Real-Time Slack Incident Alerts: Delivers rich Slack notifications detailing exposed files and actionable remediation instructions for developers.
  • Tamper-Evident Audit Trails: Centralizes cryptographic compliance logs across repositories in Kestra for security audit readiness.

Who it's for

  • DevSecOps Engineers: Enforcing secret encryption policies across distributed GitOps and Terraform repositories.
  • Platform Engineers: Preventing credential leakage in shared infrastructure codebases.
  • Security Auditors: Validating that all repository secrets meet cryptographic encryption standards at rest.

Why orchestrate this with Kestra

  • Declarative Pipeline Definition: Manage security gates and CI/CD validation workflows as declarative code alongside infrastructure definitions.
  • Containerized Isolation: Run audit checks in hardened, ephemeral Docker containers without installing git-crypt or GPG dependencies on host runners.
  • Granular Flow Control: Route workflow execution based on audit severity (CRITICAL_PLAINTEXT_SECRET_LEAK vs UNTRACKED_SECRET_PATTERN_EXPOSED) with native Switch and Fail plugins.
  • Secure Credential Injection: Inject repository deploy tokens and Slack webhook URLs securely using Kestra's encrypted secret store without exposing credentials in pipeline logs.

Prerequisites

  • A Git repository containing infrastructure or application code configured with or migrating to git-crypt.
  • A container runtime (Docker or Kubernetes) available to Kestra task runners.
  • A Slack incoming webhook configured for your security operations channel.

Secrets

  • GIT_DEPLOY_TOKEN: A Git personal access token or deploy token with read access to clone the repository.
  • SLACK_WEBHOOK_URL: The incoming webhook URL for your Slack alerting channel.
  • WEBHOOK_SECRET_KEY: A shared HMAC authentication secret to secure the Kestra webhook trigger against unauthorized calls.

Quick start

  1. Configure Secrets: Add GIT_DEPLOY_TOKEN, SLACK_WEBHOOK_URL, and WEBHOOK_SECRET_KEY in the Kestra UI under Administration > Secrets.
  2. Set Inputs: Provide your Git repository URL, target branch, and comma-separated sensitive file glob patterns in the flow inputs.
  3. Run Manual Test: Execute the flow manually from the Kestra UI with a test branch to verify that .gitattributes and magic headers are inspected correctly.
  4. Configure Webhook: Set up a webhook in GitHub or GitLab pointing to the Kestra webhook trigger URL to automatically audit every incoming pull request.

How to extend

  • Automated PR Commenting: Add a github.issues.CreateComment task to post the exact git-crypt remediation command directly onto the pull request.
  • GPG Recipient Key Auditing: Inspect .git-crypt/keys/default/0/ to verify that all GPG public keys belong to active team members and revoke stale keys.
  • SIEM & PagerDuty Escalation: Route critical plaintext leaks to PagerDuty or an enterprise SIEM (Splunk, Elastic, Datadog) for high-priority triage.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.