grafana.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. )
  7. func GrafanaApiKey() *config.Rule {
  8. // define rule
  9. r := config.Rule{
  10. RuleID: "grafana-api-key",
  11. Description: "Identified a Grafana API key, which could compromise monitoring dashboards and sensitive data analytics.",
  12. Regex: utils.GenerateUniqueTokenRegex(`eyJrIjoi[A-Za-z0-9]{70,400}={0,3}`, true),
  13. Entropy: 3,
  14. Keywords: []string{"eyJrIjoi"},
  15. }
  16. // validate
  17. tps := utils.GenerateSampleSecrets("grafana-api-key", "eyJrIjoi"+secrets.NewSecret(utils.AlphaNumeric("70")))
  18. return utils.Validate(r, tps, nil)
  19. }
  20. func GrafanaCloudApiToken() *config.Rule {
  21. // define rule
  22. r := config.Rule{
  23. RuleID: "grafana-cloud-api-token",
  24. Description: "Found a Grafana cloud API token, risking unauthorized access to cloud-based monitoring services and data exposure.",
  25. Regex: utils.GenerateUniqueTokenRegex(`glc_[A-Za-z0-9+/]{32,400}={0,3}`, true),
  26. Entropy: 3,
  27. Keywords: []string{"glc_"},
  28. }
  29. // validate
  30. tps := utils.GenerateSampleSecrets("grafana-cloud-api-token", "glc_"+secrets.NewSecret(utils.AlphaNumeric("32")))
  31. tps = append(tps,
  32. utils.GenerateSampleSecret("grafana-cloud-api-token",
  33. "glc_"+
  34. secrets.NewSecret(utils.AlphaNumeric("32"))),
  35. `loki_key: glc_eyJvIjoiNzQ0NTg3IiwibiI7InN0YWlrLTQ3NTgzMC1obC13cml0ZS1oYW5kc29uJG9raSIsImsiOiI4M2w3cmdYUlBoMTUyMW1lMU023nl5UDUiLCJtIjp7IOIiOiJ1cyJ9fQ==`,
  36. // TODO:
  37. //` loki:
  38. //endpoint: https://322137:glc_eyJvIjoiNzQ0NTg3IiwibiI7InN0YWlrLTQ3NTgzMC1obC13cml0ZS1oYW5kc29uJG9raSIsImsiOiI4M2w3cmdYUlBoMTUyMW1lMU023nl5UDUiLCJtIjp7IOIiOiJ1cyJ9fQ==@logs-prod4.grafana.net/loki/api/v1/push`,
  39. )
  40. fps := []string{
  41. // Low entropy.
  42. `glc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,
  43. ` API_KEY="glc_111111111111111111111111111111111111111111="`,
  44. // Invalid.
  45. `static void GLC_CreateLightmapTextureArray(void);
  46. static void GLC_CreateLightmapTexturesIndividual(void);
  47. void GLC_UploadLightmap(int textureUnit, int lightmapnum);`,
  48. `// Alias models
  49. void GLC_StateBeginUnderwaterAliasModelCaustics(texture_ref base_texture, texture_ref caustics_texture)
  50. {`,
  51. }
  52. return utils.Validate(r, tps, fps)
  53. }
  54. func GrafanaServiceAccountToken() *config.Rule {
  55. // define rule
  56. r := config.Rule{
  57. RuleID: "grafana-service-account-token",
  58. Description: "Discovered a Grafana service account token, posing a risk of compromised monitoring services and data integrity.",
  59. Regex: utils.GenerateUniqueTokenRegex(`glsa_[A-Za-z0-9]{32}_[A-Fa-f0-9]{8}`, true),
  60. Entropy: 3,
  61. Keywords: []string{"glsa_"},
  62. }
  63. // validate
  64. tps := utils.GenerateSampleSecrets("grafana-service-account-token", "glsa_"+secrets.NewSecret(utils.AlphaNumeric("32"))+"_"+secrets.NewSecret(utils.Hex("8")))
  65. tps = append(tps,
  66. `'Authorization': 'Bearer glsa_pITqMOBIfNH2KL4PkXJqmTyQl0D9QGxF_486f63e1'`,
  67. )
  68. fps := []string{
  69. "glsa_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_AAAAAAAA",
  70. }
  71. return utils.Validate(r, tps, fps)
  72. }