From 12034a71c5a252316d74b9c541df0c06828b9021 Mon Sep 17 00:00:00 2001 From: Richard Gomez <32133502+rgmz@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:49:34 -0400 Subject: [PATCH] refactor(config): temporarily switch to [rules.allowlist] (#1573) --- cmd/generate/config/rules/config.tmpl | 28 +++++++++++++++++++++++++- cmd/generate/config/rules/sumologic.go | 3 --- config/gitleaks.toml | 24 +++++++++------------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/cmd/generate/config/rules/config.tmpl b/cmd/generate/config/rules/config.tmpl index 98bef19d..cd6656a5 100644 --- a/cmd/generate/config/rules/config.tmpl +++ b/cmd/generate/config/rules/config.tmpl @@ -43,6 +43,32 @@ keywords = [{{ range $j, $keyword := . }}"{{ $keyword }}"{{ end }}]{{end}}{{ end tags = [ {{ range $j, $tag := . }}"{{ $tag }}",{{ end }} ]{{ end }} + +{{- /* + * Use [rules.allowlist] for a while, allow people to catch up with the new syntax. + * TODO: Remove this a few major versions after 8.21.0 + * https://github.com/gitleaks/gitleaks/issues/1571 + */}} +{{- if eq (len $rule.Allowlists) 1 }}{{ with index $rule.Allowlists 0}}{{ if or .Regexes .Paths .Commits .StopWords }} +# NOTE: Gitleaks >= v8.21.0 should use [[rules.allowlists] instead. +[rules.allowlist] +{{ with .MatchCondition }}condition = "{{ . }}" +{{ end -}} +{{- with .Commits }}commits = [ + {{ range $j, $commit := . }}"{{ $commit }}",{{ end }} +]{{ end }} +{{- with .Paths }}paths = [ + {{ range $j, $path := . }}'''{{ $path }}''',{{ end }} +]{{ end }} +{{- with .RegexTarget }}regexTarget = "{{ . }}" +{{ end -}} +{{- with .Regexes }}regexes = [{{ range $i, $regex := . }} + '''{{ $regex }}''',{{ end }} +]{{ end }} +{{- with .StopWords }}stopwords = [{{ range $j, $stopword := . }} + "{{ $stopword }}",{{ end }} +]{{ end }}{{ end }}{{ end }} +{{ else }} {{ with $rule.Allowlists }}{{ range $i, $allowlist := . }}{{ if or $allowlist.Regexes $allowlist.Paths $allowlist.Commits $allowlist.StopWords }} [[rules.allowlists]] {{ with $allowlist.MatchCondition }}condition = "{{ . }}" @@ -61,5 +87,5 @@ tags = [ {{- with $allowlist.StopWords }}stopwords = [{{ range $j, $stopword := . }} "{{ $stopword }}",{{ end }} ]{{ end }}{{ end }}{{ end }} -{{ end }} +{{ end }}{{ end }} {{ end -}} diff --git a/cmd/generate/config/rules/sumologic.go b/cmd/generate/config/rules/sumologic.go index 67b225d0..16e779dd 100644 --- a/cmd/generate/config/rules/sumologic.go +++ b/cmd/generate/config/rules/sumologic.go @@ -26,9 +26,6 @@ func SumoLogicAccessID() *config.Rule { RegexTarget: "line", Regexes: []*regexp.Regexp{regexp.MustCompile(`sumOf`)}, }, - { - Paths: []*regexp.Regexp{regexp.MustCompile(`tests/.+$`)}, - }, }, } diff --git a/config/gitleaks.toml b/config/gitleaks.toml index eb400004..21f92ffb 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -480,8 +480,8 @@ keywords = [ "auth", "access", ] - -[[rules.allowlists]] +# NOTE: Gitleaks >= v8.21.0 should use [[rules.allowlists] instead. +[rules.allowlist] stopwords = [ "000000", "aaaaaa", @@ -2168,8 +2168,8 @@ description = "Possible Kubernetes Secret detected, posing a risk of leaking cre regex = '''(?i)(?:\bkind:[ \t]*["']?secret["']?(?:.|\s){0,200}?\bdata:(?:.|\s){0,100}?\s+([\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:["']?[a-z0-9]{10,}={0,3}["']?|\{\{[ \t\w"|$:=,.-]+}}|""|''))|\bdata:(?:.|\s){0,100}?\s+([\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:["']?[a-z0-9]{10,}={0,3}["']?|\{\{[ \t\w"|$:=,.-]+}}|""|''))(?:.|\s){0,200}?\bkind:[ \t]*["']?secret["']?)''' path = '''(?i)\.ya?ml$''' keywords = ["secret"] - -[[rules.allowlists]] +# NOTE: Gitleaks >= v8.21.0 should use [[rules.allowlists] instead. +[rules.allowlist] regexes = [ '''[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')''', ] @@ -2354,8 +2354,8 @@ regex = '''(?i)' path = '''(?i)nuget\.config$''' entropy = 1 keywords = ["|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}(su[a-zA-Z0-9]{12})(?:['|\"|\n|\r|\s|\x60|;]|$)''' entropy = 3 keywords = ["sumo"] - -[[rules.allowlists]] +# NOTE: Gitleaks >= v8.21.0 should use [[rules.allowlists] instead. +[rules.allowlist] regexTarget = "line" regexes = [ '''sumOf''', ] -[[rules.allowlists]] -paths = [ - '''tests/.+$''', -] [[rules]] id = "sumologic-access-token" @@ -2777,8 +2773,8 @@ keywords = [ "hvs", "s.", ] - -[[rules.allowlists]] +# NOTE: Gitleaks >= v8.21.0 should use [[rules.allowlists] instead. +[rules.allowlist] regexes = [ '''s\.[A-Za-z]{24}''', ]