gcp.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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[\w-]{35}`, false),
  29. Entropy: 3.0,
  30. Keywords: []string{
  31. "AIza",
  32. },
  33. }
  34. // validate
  35. tps := []string{
  36. utils.GenerateSampleSecret("gcp", secrets.NewSecret(`AIza[\w-]{35}`)),
  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. }