check-trufflehog.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # check-trufflehog.sh - Scan repository for secrets
  12. set -euo pipefail
  13. cd "$(dirname "$0")/../../../.."
  14. . misc/shlib/shlib.bash
  15. if ! trufflehog --version >/dev/null 2>/dev/null; then
  16. echo "lint: trufflehog is not installed"
  17. echo "hint: refer to https://github.com/trufflesecurity/trufflehog?tab=readme-ov-file#floppy_disk-installation for install instructions"
  18. exit 1
  19. fi
  20. git ls-files -z | grep -zv '^misc/shlib/shlib\.bash$' | xargs -0 trufflehog --no-fail --no-update --no-verification --json filesystem | trufflehog_jq_filter_files > trufflehog.log
  21. try test ! -s trufflehog.log
  22. if try_last_failed; then
  23. printf "%s\n" "lint: $(red error:) new secrets found"
  24. printf "%s\n" "lint: $(green hint:) don't check in secrets and revoke them immediately"
  25. printf "%s\n" "lint: $(green hint:) mark false positives in misc/shlib/shlib.bash's trufflehog_jq_filter_(files|common)"
  26. fi
  27. jq -c -r '. | "\(.SourceMetadata.Data.Filesystem.file):\(.SourceMetadata.Data.Filesystem.line): Secret found: \(.Raw)"' trufflehog.log
  28. rm -f trufflehog.log
  29. try_status_report