grafana.go 3.0 KB

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