feat(generate): generate global (#1546)

This commit is contained in:
Richard Gomez authored and GitHub committed 2024-10-04 10:28:34 -05:00
1 parent f6e549901c
commit 82d737d851
6 files changed
+361 -499

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
package base
import (
"github.com/zricethezav/gitleaks/v8/config"
"regexp"
)
func CreateGlobalConfig() config.Config {
return config.Config{
Title: "gitleaks config",
Allowlist: config.Allowlist{
Description: "global allow lists",
Paths: []*regexp.Regexp{
regexp.MustCompile(`^gitleaks\.toml$`),
// Images
regexp.MustCompile(`(?i)\.(bmp|gif|jpe?g|svg|tiff?)$`),
regexp.MustCompile(`(.*?)(doc|docx|zip|xls|pdf|bin|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$`),
// ----------- Golang files -----------
regexp.MustCompile(`go\.(mod|sum|work(\.sum)?)$`),
regexp.MustCompile(`(^|/)vendor/modules\.txt$`),
regexp.MustCompile(`(^|/)vendor/(github\.com|golang\.org/x|google\.golang\.org|gopkg\.in|istio\.io|k8s\.io|sigs\.k8s\.io)/.*$`),
// ----------- Java files -----------
// Gradle
regexp.MustCompile(`(^|/)gradlew(\.bat)?$`),
regexp.MustCompile(`(^|/)gradle\.lockfile$`),
regexp.MustCompile(`(^|/)mvnw(\.cmd)?$`),
regexp.MustCompile(`(^|/)\.mvn/wrapper/MavenWrapperDownloader\.java$`),
// ----------- Node.js files -----------
// Dependencies and lock files.
regexp.MustCompile(`(^|/)node_modules/.*?$`),
regexp.MustCompile(`(^|/)package-lock\.json$`),
regexp.MustCompile(`(^|/)yarn\.lock$`),
regexp.MustCompile(`(^|/)pnpm-lock\.yaml$`),
regexp.MustCompile(`(^|/)npm-shrinkwrap\.json$`),
regexp.MustCompile(`(^|/)bower_components/.*?$`),
// ----------- Python files -----------
// Dependencies and lock files.
regexp.MustCompile(`(^|/)Pipfile\.lock$`),
regexp.MustCompile(`(^|/)poetry\.lock$`),
// Virtual environments
// env/lib/python3.7/site-packages/urllib3/util/url.py
regexp.MustCompile(`(?i)/?(v?env|virtualenv)/lib/.+$`),
// /python/3.7.4/Lib/site-packages/dask/bytes/tests/test_bytes_utils.py
// python/3.7.4/Lib/site-packages/fsspec/utils.py
// python/2.7.16.32/Lib/bsddb/test/test_dbenv.py
regexp.MustCompile(`(?i)/?python/[23](\.\d{1,2})+/lib/.+$`),
// python/lib/python3.8/site-packages/boto3/data/ec2/2016-04-01/resources-1.json
// python/lib/python3.8/site-packages/botocore/data/alexaforbusiness/2017-11-09/service-2.json
regexp.MustCompile(`(?i)/?python/lib/python[23](\.\d{1,2})+/.+$`),
// dist-info directory (https://py-pkgs.org/04-package-structure.html#building-sdists-and-wheels)
regexp.MustCompile(`(?i)(^|/)[a-z0-9_.]+-[0-9.]+\.dist-info/.+$`),
// ----------- Ruby files -----------
regexp.MustCompile(`(^|/)vendor/(bundle|ruby)/.*?$`),
regexp.MustCompile(`\.gem$`), // tar archive
// Misc
regexp.MustCompile(`verification-metadata.xml`),
regexp.MustCompile(`Database.refactorlog`),
//regexp.MustCompile(`vendor`),
},
},
}
}
+4 -1
View File
@@ -1,6 +1,7 @@
package main package main
import ( import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/base"
"os" "os"
"text/template" "text/template"
@@ -228,7 +229,9 @@ func main() {
log.Fatal().Err(err).Msg("Failed to create rules.toml") log.Fatal().Err(err).Msg("Failed to create rules.toml")
} }
if err = tmpl.Execute(f, config.Config{Rules: ruleLookUp}); err != nil { cfg := base.CreateGlobalConfig()
cfg.Rules = ruleLookUp
if err = tmpl.Execute(f, cfg); err != nil {
log.Fatal().Err(err).Msg("could not execute template") log.Fatal().Err(err).Msg("could not execute template")
} }
+17 -19
View File
@@ -8,24 +8,20 @@
# Rules instruct gitleaks on what should be considered a secret. # Rules instruct gitleaks on what should be considered a secret.
# Allowlists instruct gitleaks on what is allowed, i.e. not a secret. # Allowlists instruct gitleaks on what is allowed, i.e. not a secret.
title = "gitleaks config" title = "{{.Title}}"
[allowlist] [allowlist]
description = "global allow lists" description = "{{.Allowlist.Description}}"
paths = [ {{- with .Allowlist.RegexTarget }}
'''gitleaks.toml''', regexTarget = "{{ . }}"{{ end -}}
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe|gltf)$''', {{- with .Allowlist.Regexes }}
'''(go.mod|go.sum|go.work|go.work.sum)$''', regexes = [
'''gradle.lockfile''', {{ range $i, $regex := . }}'''{{ $regex }}''',{{ end }}
'''verification-metadata.xml''', ]{{ end }}
'''node_modules''', {{- with .Allowlist.Paths }}
'''package-lock.json''', paths = [{{ range $i, $path := . }}
'''yarn.lock''', '''{{ $path }}''',{{ end }}
'''pnpm-lock.yaml''', ]{{ end }}
'''poetry.lock''',
'''Database.refactorlog''',
'''vendor''',
]
{{ range $i, $rule := .Rules }}[[rules]] {{ range $i, $rule := .Rules }}[[rules]]
id = "{{$rule.RuleID}}" id = "{{$rule.RuleID}}"
@@ -38,9 +34,11 @@ secretGroup = {{ . }}{{ end -}}
{{- with $rule.Entropy }} {{- with $rule.Entropy }}
entropy = {{ . }}{{ end -}} entropy = {{ . }}{{ end -}}
{{- with $rule.Keywords }} {{- with $rule.Keywords }}
keywords = [ {{- if gt (len .) 1}}
{{ range $j, $keyword := . }}"{{ $keyword }}",{{ end }} keywords = [{{ range $j, $keyword := . }}
]{{ end }} "{{ $keyword }}",{{ end }}
]{{else}}
keywords = [{{ range $j, $keyword := . }}"{{ $keyword }}"{{ end }}]{{end}}{{ end }}
{{- with $rule.Tags }} {{- with $rule.Tags }}
tags = [ tags = [
{{ range $j, $tag := . }}"{{ $tag }}",{{ end }} {{ range $j, $tag := . }}"{{ $tag }}",{{ end }}
+5 -4
View File
@@ -6,6 +6,7 @@ package utils
import ( import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/base"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect" "github.com/zricethezav/gitleaks/v8/detect"
"strings" "strings"
@@ -82,8 +83,8 @@ func createSingleRuleDetector(r *config.Rule) *detect.Detector {
rules := map[string]config.Rule{ rules := map[string]config.Rule{
r.RuleID: *r, r.RuleID: *r,
} }
return detect.NewDetector(config.Config{ cfg := base.CreateGlobalConfig()
Rules: rules, cfg.Rules = rules
Keywords: uniqueKeywords, cfg.Keywords = uniqueKeywords
}) return detect.NewDetector(cfg)
} }
+1
View File
@@ -54,6 +54,7 @@ type ViperConfig struct {
// Config is a configuration struct that contains rules and an allowlist if present. // Config is a configuration struct that contains rules and an allowlist if present.
type Config struct { type Config struct {
Title string
Extend Extend Extend Extend
Path string Path string
Description string Description string
+265 -475
View File
File diff suppressed because it is too large. Load diff