Make config generation utils public (#1480)

* chore(generate): make utils public

* chore(generate): change validate log messages

* chore(generate): split functions into files

* chore(config): add warning for public funcs
This commit is contained in:
Richard Gomez authored and GitHub committed 2024-08-26 13:11:18 -05:00
1 parent 3be7faa1ff
commit bd81872eee
114 files changed
+862 -713

No files matched your search

+8 -7
View File
@@ -1,6 +1,7 @@
package rules
import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)
@@ -10,7 +11,7 @@ func VaultServiceToken() *config.Rule {
r := config.Rule{
RuleID: "vault-service-token",
Description: "Identified a Vault Service Token, potentially compromising infrastructure security and access to sensitive credentials.",
Regex: generateUniqueTokenRegex(`(?:hvs\.[\w-]{90,120}|s\.(?i:[a-z0-9]{24}))`, false),
Regex: utils.GenerateUniqueTokenRegex(`(?:hvs\.[\w-]{90,120}|s\.(?i:[a-z0-9]{24}))`, false),
Entropy: 3.5,
Keywords: []string{"hvs", "s."},
}
@@ -18,10 +19,10 @@ func VaultServiceToken() *config.Rule {
// validate
tps := []string{
// Old
generateSampleSecret("vault", "s."+secrets.NewSecret(alphaNumeric("24"))),
utils.GenerateSampleSecret("vault", "s."+secrets.NewSecret(utils.AlphaNumeric("24"))),
`token: s.ZC9Ecf4M5g9o34Q6RkzGsj0z`,
// New
generateSampleSecret("vault", "hvs."+secrets.NewSecret(alphaNumericExtendedShort("90"))),
utils.GenerateSampleSecret("vault", "hvs."+secrets.NewSecret(utils.AlphaNumericExtendedShort("90"))),
`-vaultToken hvs.CAESIP2jTxc9S2K7Z6CtcFWQv7-044m_oSsxnPE1H3nF89l3GiYKHGh2cy5sQmlIZVNyTWJNcDRsYWJpQjlhYjVlb1cQh6PL8wEYAg"`, // longer than 100 chars
}
fps := []string{
@@ -32,7 +33,7 @@ func VaultServiceToken() *config.Rule {
// New
`hvs.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`, // low entropy
}
return validate(r, tps, fps)
return utils.Validate(r, tps, fps)
}
func VaultBatchToken() *config.Rule {
@@ -40,13 +41,13 @@ func VaultBatchToken() *config.Rule {
r := config.Rule{
Description: "Detected a Vault Batch Token, risking unauthorized access to secret management services and sensitive data.",
RuleID: "vault-batch-token",
Regex: generateUniqueTokenRegex(`hvb\.[a-z0-9_-]{138,212}`, true),
Regex: utils.GenerateUniqueTokenRegex(`hvb\.[a-z0-9_-]{138,212}`, true),
Keywords: []string{"hvb"},
}
// validate
tps := []string{
generateSampleSecret("vault", "hvb."+secrets.NewSecret(alphaNumericExtendedShort("138"))),
utils.GenerateSampleSecret("vault", "hvb."+secrets.NewSecret(utils.AlphaNumericExtendedShort("138"))),
}
return validate(r, tps, nil)
return utils.Validate(r, tps, nil)
}