gcp.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package rules
  2. import (
  3. "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
  4. "regexp"
  5. "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
  6. "github.com/zricethezav/gitleaks/v8/config"
  7. )
  8. // TODO this one could probably use some work
  9. func GCPServiceAccount() *config.Rule {
  10. // define rule
  11. r := config.Rule{
  12. Description: "Google (GCP) Service-account",
  13. RuleID: "gcp-service-account",
  14. Regex: regexp.MustCompile(`\"type\": \"service_account\"`),
  15. Keywords: []string{`\"type\": \"service_account\"`},
  16. }
  17. // validate
  18. tps := []string{
  19. `"type": "service_account"`,
  20. }
  21. return utils.Validate(r, tps, nil)
  22. }
  23. func GCPAPIKey() *config.Rule {
  24. // define rule
  25. r := config.Rule{
  26. RuleID: "gcp-api-key",
  27. Description: "Uncovered a GCP API key, which could lead to unauthorized access to Google Cloud services and data breaches.",
  28. Regex: utils.GenerateUniqueTokenRegex(`AIza[0-9A-Za-z\\-_]{35}`, true),
  29. Keywords: []string{
  30. "AIza",
  31. },
  32. }
  33. // validate
  34. tps := []string{
  35. utils.GenerateSampleSecret("gcp", secrets.NewSecret(`AIza[0-9A-Za-z\\-_]{35}`)),
  36. }
  37. return utils.Validate(r, tps, nil)
  38. }