mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67454d109e | ||
|
|
ce603c73b4 | ||
|
|
55218fc8f8 |
No files matched your search
@@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.8.0
|
||||||
|
-----
|
||||||
|
- whitelist repos
|
||||||
|
- sample config option
|
||||||
|
|
||||||
1.7.3
|
1.7.3
|
||||||
-----
|
-----
|
||||||
- style points
|
- style points
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ Application Options:
|
|||||||
--csv report output to csv
|
--csv report output to csv
|
||||||
--redact redact secrets from log messages and report
|
--redact redact secrets from log messages and report
|
||||||
--version version number
|
--version version number
|
||||||
|
--sample-config prints a sample config file
|
||||||
|
|
||||||
Help Options:
|
Help Options:
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
|
|||||||
+47
-2
@@ -56,6 +56,17 @@ regexes= [
|
|||||||
]
|
]
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testWhitelistRepo = `
|
||||||
|
[[regexes]]
|
||||||
|
description = "AWS"
|
||||||
|
regex = '''AKIA[0-9A-Z]{16}'''
|
||||||
|
|
||||||
|
[whitelist]
|
||||||
|
repos = [
|
||||||
|
"gronit",
|
||||||
|
]
|
||||||
|
`
|
||||||
|
|
||||||
var benchmarkRepo *RepoDescriptor
|
var benchmarkRepo *RepoDescriptor
|
||||||
var benchmarkLeaksRepo *RepoDescriptor
|
var benchmarkLeaksRepo *RepoDescriptor
|
||||||
|
|
||||||
@@ -166,9 +177,8 @@ func TestGetRepo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestRun(t *testing.T) {
|
func TestRun(t *testing.T) {
|
||||||
err := loadToml()
|
var err error
|
||||||
configsDir := testTomlLoader()
|
configsDir := testTomlLoader()
|
||||||
defer os.RemoveAll(configsDir)
|
|
||||||
|
|
||||||
dir, err = ioutil.TempDir("", "gitleaksTestOwner")
|
dir, err = ioutil.TempDir("", "gitleaksTestOwner")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
@@ -185,7 +195,9 @@ func TestRun(t *testing.T) {
|
|||||||
testOpts Options
|
testOpts Options
|
||||||
description string
|
description string
|
||||||
expectedErrMsg string
|
expectedErrMsg string
|
||||||
|
whiteListRepos []string
|
||||||
numLeaks int
|
numLeaks int
|
||||||
|
configPath string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
@@ -263,11 +275,23 @@ func TestRun(t *testing.T) {
|
|||||||
numLeaks: 0,
|
numLeaks: 0,
|
||||||
expectedErrMsg: "reference not found",
|
expectedErrMsg: "reference not found",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testOpts: Options{
|
||||||
|
GithubOrg: "gitleakstestorg",
|
||||||
|
},
|
||||||
|
description: "test github org",
|
||||||
|
numLeaks: 0,
|
||||||
|
expectedErrMsg: "",
|
||||||
|
configPath: path.Join(configsDir, "repo"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
g := goblin.Goblin(t)
|
g := goblin.Goblin(t)
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
g.Describe("TestRun", func() {
|
g.Describe("TestRun", func() {
|
||||||
g.It(test.description, func() {
|
g.It(test.description, func() {
|
||||||
|
if test.configPath != "" {
|
||||||
|
os.Setenv("GITLEAKS_CONFIG", test.configPath)
|
||||||
|
}
|
||||||
opts = test.testOpts
|
opts = test.testOpts
|
||||||
leaks, err := run()
|
leaks, err := run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -344,6 +368,7 @@ func testTomlLoader() string {
|
|||||||
ioutil.WriteFile(path.Join(tmpDir, "branch"), []byte(testWhitelistBranch), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "branch"), []byte(testWhitelistBranch), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
|
||||||
|
ioutil.WriteFile(path.Join(tmpDir, "repo"), []byte(testWhitelistRepo), 0644)
|
||||||
return tmpDir
|
return tmpDir
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,6 +412,7 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
whiteListFiles []*regexp.Regexp
|
whiteListFiles []*regexp.Regexp
|
||||||
whiteListCommits map[string]bool
|
whiteListCommits map[string]bool
|
||||||
whiteListBranches []string
|
whiteListBranches []string
|
||||||
|
whiteListRepos []string
|
||||||
whiteListRegexes []*regexp.Regexp
|
whiteListRegexes []*regexp.Regexp
|
||||||
configPath string
|
configPath string
|
||||||
}{
|
}{
|
||||||
@@ -511,6 +537,20 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
configPath: path.Join(configsDir, "commit"),
|
configPath: path.Join(configsDir, "commit"),
|
||||||
numLeaks: 2,
|
numLeaks: 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
repo: leaksRepo,
|
||||||
|
description: "audit whitelist repo",
|
||||||
|
numLeaks: 0,
|
||||||
|
whiteListRepos: []string{
|
||||||
|
"gronit",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
repo: leaksRepo,
|
||||||
|
description: "toml whitelist repo",
|
||||||
|
numLeaks: 0,
|
||||||
|
configPath: path.Join(configsDir, "repo"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
whiteListCommits = make(map[string]bool)
|
whiteListCommits = make(map[string]bool)
|
||||||
@@ -540,6 +580,11 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
whiteListRegexes = nil
|
whiteListRegexes = nil
|
||||||
}
|
}
|
||||||
|
if test.whiteListRepos != nil {
|
||||||
|
whiteListRepos = test.whiteListRepos
|
||||||
|
} else {
|
||||||
|
whiteListRepos = nil
|
||||||
|
}
|
||||||
|
|
||||||
// config paths
|
// config paths
|
||||||
if test.configPath != "" {
|
if test.configPath != "" {
|
||||||
|
|||||||
@@ -90,12 +90,13 @@ type Options struct {
|
|||||||
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
||||||
|
|
||||||
// Output options
|
// Output options
|
||||||
Log string `short:"l" long:"log" description:"log level"`
|
Log string `short:"l" long:"log" description:"log level"`
|
||||||
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from gitleaks audit"`
|
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from gitleaks audit"`
|
||||||
Report string `long:"report" description:"path to write report file"`
|
Report string `long:"report" description:"path to write report file"`
|
||||||
CSV bool `long:"csv" description:"report output to csv"`
|
CSV bool `long:"csv" description:"report output to csv"`
|
||||||
Redact bool `long:"redact" description:"redact secrets from log messages and report"`
|
Redact bool `long:"redact" description:"redact secrets from log messages and report"`
|
||||||
Version bool `long:"version" description:"version number"`
|
Version bool `long:"version" description:"version number"`
|
||||||
|
SampleConfig bool `long:"sample-config" description:"prints a sample config file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config struct for regexes matching and whitelisting
|
// Config struct for regexes matching and whitelisting
|
||||||
@@ -109,6 +110,7 @@ type Config struct {
|
|||||||
Regexes []string
|
Regexes []string
|
||||||
Commits []string
|
Commits []string
|
||||||
Branches []string
|
Branches []string
|
||||||
|
Repos []string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,10 +123,16 @@ type gitDiff struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultGithubURL = "https://api.github.com/"
|
const defaultGithubURL = "https://api.github.com/"
|
||||||
const version = "1.7.3"
|
const version = "1.8.0"
|
||||||
const errExit = 2
|
const errExit = 2
|
||||||
const leakExit = 1
|
const leakExit = 1
|
||||||
const defaultConfig = `
|
const defaultConfig = `
|
||||||
|
# This is a sample config file for gitleaks. You can configure gitleaks what to search for and what to whitelist.
|
||||||
|
# The output you are seeing here is the default gitleaks config. If GITLEAKS_CONFIG environment variable
|
||||||
|
# is set, gitleaks will load configurations from that path. If option --config-path is set, gitleaks will load
|
||||||
|
# configurations from that path. Gitleaks does not whitelist anything by default.
|
||||||
|
|
||||||
|
|
||||||
title = "gitleaks config"
|
title = "gitleaks config"
|
||||||
# add regexes to the regex table
|
# add regexes to the regex table
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
@@ -150,7 +158,6 @@ description = "Twitter"
|
|||||||
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
||||||
|
|
||||||
[whitelist]
|
[whitelist]
|
||||||
|
|
||||||
#regexes = [
|
#regexes = [
|
||||||
# "AKAIMYFAKEAWKKEY",
|
# "AKAIMYFAKEAWKKEY",
|
||||||
#]
|
#]
|
||||||
@@ -167,6 +174,10 @@ regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
|||||||
#branches = [
|
#branches = [
|
||||||
# "dev/STUPDIFKNFEATURE"
|
# "dev/STUPDIFKNFEATURE"
|
||||||
#]
|
#]
|
||||||
|
|
||||||
|
#repos = [
|
||||||
|
# "someYugeRepoWeKnowIsCLEAR"
|
||||||
|
#]
|
||||||
`
|
`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -177,6 +188,7 @@ var (
|
|||||||
whiteListFiles []*regexp.Regexp
|
whiteListFiles []*regexp.Regexp
|
||||||
whiteListCommits map[string]bool
|
whiteListCommits map[string]bool
|
||||||
whiteListBranches []string
|
whiteListBranches []string
|
||||||
|
whiteListRepos []string
|
||||||
fileDiffRegex *regexp.Regexp
|
fileDiffRegex *regexp.Regexp
|
||||||
sshAuth *ssh.PublicKeys
|
sshAuth *ssh.PublicKeys
|
||||||
dir string
|
dir string
|
||||||
@@ -196,6 +208,10 @@ func main() {
|
|||||||
fmt.Println(version)
|
fmt.Println(version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
if opts.SampleConfig {
|
||||||
|
fmt.Println(defaultConfig)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
leaks, err := run()
|
leaks, err := run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@@ -354,6 +370,11 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
err error
|
err error
|
||||||
leaks []Leak
|
leaks []Leak
|
||||||
)
|
)
|
||||||
|
for _, repoName := range whiteListRepos {
|
||||||
|
if repoName == repo.name {
|
||||||
|
return nil, fmt.Errorf("skipping %s, whitelisted", repoName)
|
||||||
|
}
|
||||||
|
}
|
||||||
ref, err := repo.repository.Head()
|
ref, err := repo.repository.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return leaks, err
|
return leaks, err
|
||||||
@@ -694,6 +715,11 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
|||||||
repo *git.Repository
|
repo *git.Repository
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
for _, repoName := range whiteListRepos {
|
||||||
|
if repoName == *githubRepo.Name {
|
||||||
|
return nil, fmt.Errorf("skipping %s, whitelisted", repoName)
|
||||||
|
}
|
||||||
|
}
|
||||||
log.Infof("cloning: %s", *githubRepo.Name)
|
log.Infof("cloning: %s", *githubRepo.Name)
|
||||||
if opts.Disk {
|
if opts.Disk {
|
||||||
ownerDir, err := ioutil.TempDir(dir, opts.GithubUser)
|
ownerDir, err := ioutil.TempDir(dir, opts.GithubUser)
|
||||||
@@ -878,6 +904,7 @@ func loadToml() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
whiteListBranches = config.Whitelist.Branches
|
whiteListBranches = config.Whitelist.Branches
|
||||||
|
whiteListRepos = config.Whitelist.Repos
|
||||||
whiteListCommits = make(map[string]bool)
|
whiteListCommits = make(map[string]bool)
|
||||||
for _, commit := range config.Whitelist.Commits {
|
for _, commit := range config.Whitelist.Commits {
|
||||||
whiteListCommits[commit] = true
|
whiteListCommits[commit] = true
|
||||||
|
|||||||
Reference in new issue
Block a user