hashicorp.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package rules
  2. import (
  3. "fmt"
  4. "regexp"
  5. "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
  6. "github.com/zricethezav/gitleaks/v8/config"
  7. )
  8. func Hashicorp() *config.Rule {
  9. // define rule
  10. r := config.Rule{
  11. Description: "Uncovered a HashiCorp Terraform user/org API token, which may lead to unauthorized infrastructure management and security breaches.",
  12. RuleID: "hashicorp-tf-api-token",
  13. Regex: regexp.MustCompile(`(?i)[a-z0-9]{14}\.atlasv1\.[a-z0-9\-_=]{60,70}`),
  14. Keywords: []string{"atlasv1"},
  15. }
  16. // validate
  17. tps := []string{
  18. generateSampleSecret("hashicorpToken", secrets.NewSecret(hex("14"))+".atlasv1."+secrets.NewSecret(alphaNumericExtended("60,70"))),
  19. }
  20. return validate(r, tps, nil)
  21. }
  22. func HashicorpField() *config.Rule {
  23. keywords := []string{"administrator_login_password", "password"}
  24. // define rule
  25. r := config.Rule{
  26. Description: "Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches.",
  27. RuleID: "hashicorp-tf-password",
  28. Regex: generateSemiGenericRegex(keywords, fmt.Sprintf(`"%s"`, alphaNumericExtended("8,20")), true),
  29. Keywords: keywords,
  30. }
  31. tps := []string{
  32. // Example from: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/sql_server.html
  33. "administrator_login_password = " + `"thisIsDog11"`,
  34. // https://registry.terraform.io/providers/petoju/mysql/latest/docs
  35. "password = " + `"rootpasswd"`,
  36. }
  37. fps := []string{
  38. "administrator_login_password = var.db_password",
  39. `password = "${aws_db_instance.default.password}"`,
  40. }
  41. return validate(r, tps, fps)
  42. }