Merge pull request #123 from zricethezav/update/whitelist-repo

whitelist repo update
This commit is contained in:
Zachary Rice authored and GitHub committed 2018-10-23 16:38:17 -05:00
commit 87d916fc24
4 files changed
+29 -12

No files matched your search

+5
View File
@@ -1,6 +1,11 @@
CHANGELOG CHANGELOG
========= =========
1.15.0
----
- Whitelist repos use regex now
- Whitelist repo check before clone
1.14.0 1.14.0
---- ----
- Entropy Range support in gitleaks config - Entropy Range support in gitleaks config
+3 -3
View File
@@ -188,9 +188,9 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
if opts.ExcludeForks && githubRepo.GetFork() { if opts.ExcludeForks && githubRepo.GetFork() {
return nil, fmt.Errorf("skipping %s, excluding forks", *githubRepo.Name) return nil, fmt.Errorf("skipping %s, excluding forks", *githubRepo.Name)
} }
for _, repoName := range whiteListRepos { for _, re := range whiteListRepos {
if repoName == *githubRepo.Name { if re.FindString(*githubRepo.Name) != "" {
return nil, fmt.Errorf("skipping %s, whitelisted", repoName) return nil, fmt.Errorf("skipping %s, whitelisted", *githubRepo.Name)
} }
} }
log.Infof("cloning: %s", *githubRepo.Name) log.Infof("cloning: %s", *githubRepo.Name)
+3 -3
View File
@@ -493,7 +493,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 whiteListRepos []*regexp.Regexp
whiteListRegexes []*regexp.Regexp whiteListRegexes []*regexp.Regexp
configPath string configPath string
}{ }{
@@ -618,8 +618,8 @@ func TestAuditRepo(t *testing.T) {
repo: leaksRepo, repo: leaksRepo,
description: "audit whitelist repo", description: "audit whitelist repo",
numLeaks: 0, numLeaks: 0,
whiteListRepos: []string{ whiteListRepos: []*regexp.Regexp{
"gronit", regexp.MustCompile("gronit"),
}, },
}, },
{ {
+18 -6
View File
@@ -137,7 +137,7 @@ type entropyRange struct {
} }
const defaultGithubURL = "https://api.github.com/" const defaultGithubURL = "https://api.github.com/"
const version = "1.14.0" const version = "1.15.0"
const errExit = 2 const errExit = 2
const leakExit = 1 const leakExit = 1
const defaultConfig = ` const defaultConfig = `
@@ -208,7 +208,7 @@ var (
whiteListFiles []*regexp.Regexp whiteListFiles []*regexp.Regexp
whiteListCommits map[string]bool whiteListCommits map[string]bool
whiteListBranches []string whiteListBranches []string
whiteListRepos []string whiteListRepos []*regexp.Regexp
entropyRanges []entropyRange entropyRanges []entropyRange
fileDiffRegex *regexp.Regexp fileDiffRegex *regexp.Regexp
sshAuth *ssh.PublicKeys sshAuth *ssh.PublicKeys
@@ -250,6 +250,10 @@ func main() {
now := time.Now() now := time.Now()
leaks, err := run() leaks, err := run()
if err != nil { if err != nil {
if strings.Contains(err.Error(), "whitelisted") {
log.Info(err.Error())
os.Exit(0)
}
log.Error(err) log.Error(err)
os.Exit(errExit) os.Exit(errExit)
} }
@@ -359,6 +363,12 @@ func cloneRepo() (*RepoDescriptor, error) {
err error err error
repo *git.Repository repo *git.Repository
) )
// check if whitelist
for _, re := range whiteListRepos {
if re.FindString(opts.Repo) != "" {
return nil, fmt.Errorf("skipping %s, whitelisted", opts.Repo)
}
}
if opts.Disk { if opts.Disk {
log.Infof("cloning %s", opts.Repo) log.Infof("cloning %s", opts.Repo)
cloneTarget := fmt.Sprintf("%s/%x", dir, md5.Sum([]byte(fmt.Sprintf("%s%s", opts.GithubUser, opts.Repo)))) cloneTarget := fmt.Sprintf("%s/%x", dir, md5.Sum([]byte(fmt.Sprintf("%s%s", opts.GithubUser, opts.Repo))))
@@ -409,9 +419,9 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
err error err error
leaks []Leak leaks []Leak
) )
for _, repoName := range whiteListRepos { for _, re := range whiteListRepos {
if repoName == repo.name { if re.FindString(repo.name) != "" {
return nil, fmt.Errorf("skipping %s, whitelisted", repoName) return leaks, fmt.Errorf("skipping %s, whitelisted", repo.name)
} }
} }
ref, err := repo.repository.Head() ref, err := repo.repository.Head()
@@ -857,7 +867,6 @@ 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
@@ -868,6 +877,9 @@ func loadToml() error {
for _, regex := range config.Whitelist.Regexes { for _, regex := range config.Whitelist.Regexes {
whiteListRegexes = append(whiteListRegexes, regexp.MustCompile(regex)) whiteListRegexes = append(whiteListRegexes, regexp.MustCompile(regex))
} }
for _, regex := range config.Whitelist.Repos {
whiteListRepos = append(whiteListRepos, regexp.MustCompile(regex))
}
return nil return nil
} }