hashicorp_vault.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package rules
  2. import (
  3. "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
  4. "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. "regexp"
  7. )
  8. func VaultServiceToken() *config.Rule {
  9. // define rule
  10. r := config.Rule{
  11. RuleID: "vault-service-token",
  12. Description: "Identified a Vault Service Token, potentially compromising infrastructure security and access to sensitive credentials.",
  13. Regex: utils.GenerateUniqueTokenRegex(`(?:hvs\.[\w-]{90,120}|s\.(?i:[a-z0-9]{24}))`, false),
  14. Entropy: 3.5,
  15. Keywords: []string{"hvs", "s."},
  16. Allowlists: []config.Allowlist{
  17. {
  18. Regexes: []*regexp.Regexp{
  19. // https://github.com/gitleaks/gitleaks/issues/1490#issuecomment-2334166357
  20. regexp.MustCompile(`s\.[A-Za-z]{24}`),
  21. },
  22. },
  23. },
  24. }
  25. // validate
  26. tps := []string{
  27. // Old
  28. utils.GenerateSampleSecret("vault", "s."+secrets.NewSecret(utils.AlphaNumeric("24"))),
  29. `token: s.ZC9Ecf4M5g9o34Q6RkzGsj0z`,
  30. // New
  31. utils.GenerateSampleSecret("vault", "hvs."+secrets.NewSecret(utils.AlphaNumericExtendedShort("90"))),
  32. `-vaultToken hvs.CAESIP2jTxc9S2K7Z6CtcFWQv7-044m_oSsxnPE1H3nF89l3GiYKHGh2cy5sQmlIZVNyTWJNcDRsYWJpQjlhYjVlb1cQh6PL8wEYAg"`, // longer than 100 chars
  33. }
  34. fps := []string{
  35. // Old
  36. ` credentials: new AWS.SharedIniFileCredentials({ profile: '<YOUR_PROFILE>' })`, // word boundary start
  37. `INFO 4 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean`, // word boundary end
  38. `s.xxxxxxxxxxxxxxxxxxxxxxxx`, // low entropy
  39. `s.THISSTRINGISALLUPPERCASE`, // uppercase
  40. `s.thisstringisalllowercase`, // lowercase
  41. `s.AcceptanceTimeoutSeconds `, // pascal-case
  42. `s.makeKubeConfigController = args`, // camel-case
  43. // New
  44. `hvs.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`, // low entropy
  45. }
  46. return utils.Validate(r, tps, fps)
  47. }
  48. func VaultBatchToken() *config.Rule {
  49. // define rule
  50. r := config.Rule{
  51. Description: "Detected a Vault Batch Token, risking unauthorized access to secret management services and sensitive data.",
  52. RuleID: "vault-batch-token",
  53. Regex: utils.GenerateUniqueTokenRegex(`hvb\.[a-z0-9_-]{138,212}`, true),
  54. Keywords: []string{"hvb"},
  55. }
  56. // validate
  57. tps := []string{
  58. utils.GenerateSampleSecret("vault", "hvb."+secrets.NewSecret(utils.AlphaNumericExtendedShort("138"))),
  59. }
  60. return utils.Validate(r, tps, nil)
  61. }