| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package rules
- import (
- regexp "github.com/wasilibs/go-re2"
- "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
- "github.com/zricethezav/gitleaks/v8/config"
- "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
- )
- // TODO this one could probably use some work
- func GCPServiceAccount() *config.Rule {
- // define rule
- r := config.Rule{
- Description: "Google (GCP) Service-account",
- RuleID: "gcp-service-account",
- Regex: regexp.MustCompile(`\"type\": \"service_account\"`),
- Keywords: []string{`\"type\": \"service_account\"`},
- }
- // validate
- tps := []string{
- `"type": "service_account"`,
- }
- return utils.Validate(r, tps, nil)
- }
- func GCPAPIKey() *config.Rule {
- // define rule
- r := config.Rule{
- RuleID: "gcp-api-key",
- Description: "Uncovered a GCP API key, which could lead to unauthorized access to Google Cloud services and data breaches.",
- Regex: utils.GenerateUniqueTokenRegex(`AIza[\w-]{35}`, false),
- Entropy: 3.0,
- Keywords: []string{
- "AIza",
- },
- }
- // validate
- tps := utils.GenerateSampleSecrets("gcp", secrets.NewSecret(`AIza[\w-]{35}`))
- tps = append(tps,
- // non-word character at end
- `AIzaSyNHxIf32IQ1a1yjl3ZJIqKZqzLAK1XhDk-`, // gitleaks:allow
- )
- fps := []string{
- `GWw4hjABFzZCGiRpmlDyDdo87Jn9BN9THUA47muVRNunLxsa82tMAdvmrhOqNkRKiYMEAFbTJAIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDq`, // text boundary start
- `AIzaTesb6Tscfcni8vIpWZqNCXFDFslJtVSvFDqabcd123`, // text boundary end
- `apiKey: "AIzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`, // not enough entropy
- `AIZASYCO2CXRMC9ELSKLHLHRMBSWDEVEDZTLO2O`, // incorrect case
- }
- return utils.Validate(r, tps, fps)
- }
|