gcp.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package rules
  2. import (
  3. regexp "github.com/wasilibs/go-re2"
  4. "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
  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[\w-]{35}`, false),
  29. Entropy: 3.0,
  30. Keywords: []string{
  31. "AIza",
  32. },
  33. }
  34. // validate
  35. tps := utils.GenerateSampleSecrets("gcp", secrets.NewSecret(`AIza[\w-]{35}`))
  36. tps = append(tps,
  37. // non-word character at end
  38. `AIzaSyNHxIf32IQ1a1yjl3ZJIqKZqzLAK1XhDk-`, // gitleaks:allow
  39. )
  40. fps := []string{
  41. `GWw4hjABFzZCGiRpmlDyDdo87Jn9BN9THUA47muVRNunLxsa82tMAdvmrhOqNkRKiYMEAFbTJAIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDq`, // text boundary start
  42. `AIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDqabcd123`, // text boundary end
  43. `apiKey: "AIzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`, // not enough entropy
  44. `AIZASYCO2CXRMC9ELSKLHLHRMBSWDEVEDZTLO2O`, // incorrect case
  45. }
  46. return utils.Validate(r, tps, fps)
  47. }