grafana.go 3.0 KB

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