Compare commits

..
12 Commits
Author SHA1 Message Date
Zachary Rice 5d81c650e8 Merge pull request #104 from zricethezav/comments
Comments
2018-10-06 19:31:14 -05:00
zach rice 0726209172 maintenance 2018-10-06 19:27:54 -05:00
zach rice bfec8aca51 working on better comments 2018-10-05 22:55:19 -05:00
Zachary Rice a9b30edb06 Resource fix (#103)
* bumping version
2018-10-04 10:11:52 -05:00
Zachary Rice cc6d698e63 Resource fix (#102)
* no more dangling goroutines
2018-10-04 09:47:18 -05:00
Zachary Rice 2ba97d0fa3 fixing audit repo bug (#101)
* fixing audit repo bug

* bumping version
2018-10-02 12:34:05 -05:00
Zachary Rice d299b5aa7f Exitcode (#100)
* additional exit code, some more cleaning

* bump version
2018-10-02 09:52:18 -05:00
Zachary Rice 0a209b60a5 typo 2018-10-02 07:59:11 -05:00
Zachary Rice fe8c6271f2 panic plan (#99) 2018-10-01 22:44:25 -05:00
zach rice 42fb085684 pls contribute 2018-10-01 21:54:31 -05:00
Zachary Rice 3faec00bf9 Max go (#98)
* default max go, cleaning up for orgs

* bump changelog

* bumping version
2018-10-01 21:21:19 -05:00
Zachary Rice 93669f1ee8 Csv (#96)
* refactoring github audits, adding csv support

* working on tests

* test passing

* bumping version

* updating readme
2018-09-29 22:11:40 -05:00
7 changed files with 732 additions and 435 deletions

No files matched your search

+33
View File
@@ -1,6 +1,39 @@
CHANGELOG CHANGELOG
========= =========
1.7.3
-----
- style points
1.7.2
-----
- Fixing dangling goroutines, removing channel messaging
1.7.1
-----
- Fixing bug where single repos were not being audited
1.7.0
-----
- Exit code == 2 on error
- Cleaning up some logs
- Removing some unreachable code
1.6.1
-----
- Recover from panic when diffing
1.6.0
-----
- Default maximum goroutines spawned is number of cores your cpu run with. See benchmarks in wiki.
- Cleanup after each repo audit for organizations rather than waiting for the entire organization to complete. Eliminates risk of running out of disk space.
1.5.0
-----
- Support for CSV reporting
- Refactoring github user/owner audits
1.4.0 1.4.0
----- -----
- Support for single commit repos - Support for single commit repos
+20
View File
@@ -0,0 +1,20 @@
# Contributing Guidelines
The gitleaks project is under [GNU General Public License v3.0](LICENSE.md) and accepts
contributions via GitHub pull requests.
## How to Contribute
Open a PR. Give the PR a descriptive title. Add some comments describing whats the purpose of the PR.
__BUT before you do that!__
Make sure you pass this list of requirements.
- You've ran `go fmt`.
- You've ran `golint`.
- Your Go changes are confined to `gitleaks_test.go` and `main.go`. This is subject to change as the project evolves. Stylistically, I like having a single go file considering the size of this project (its tiny).
- You've added test cases for your changes.
- You've updated [the changelog](CHANGELOG.md).
- Your tests pass.
+6 -2
View File
@@ -4,13 +4,12 @@ test:
go get github.com/golang/lint/golint go get github.com/golang/lint/golint
go fmt go fmt
golint golint
go test --race -cover go test --race --cover -run=Test$
deploy: deploy:
@echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin @echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
docker build -f Dockerfile -t $(REPO):$(TAG) . docker build -f Dockerfile -t $(REPO):$(TAG) .
echo "Pushing $(REPO):$(COMMIT) $(REPO):$(TAG)" echo "Pushing $(REPO):$(COMMIT) $(REPO):$(TAG)"
docker push $(REPO) docker push $(REPO)
build-all: build-all:
rm -rf build rm -rf build
mkdir build mkdir build
@@ -21,3 +20,8 @@ build-all:
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips" env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips"
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips" env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips"
env GOOS="darwin" GOARCH="amd64" go build -o "build/gitleaks-darwin-amd64" env GOOS="darwin" GOARCH="amd64" go build -o "build/gitleaks-darwin-amd64"
benchmark:
go test -run=Benchmark -bench=. -benchtime=5s
benchmark-fast:
go test -bench=BenchmarkAuditLeakRepo -run=BenchmarkAuditLeakRepo$
+3 -1
View File
@@ -43,6 +43,7 @@ Application Options:
-l, --log= log level -l, --log= log level
-v, --verbose Show verbose output from gitleaks audit -v, --verbose Show verbose output from gitleaks audit
--report= path to write report file --report= path to write report file
--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
@@ -51,8 +52,9 @@ Help Options:
``` ```
#### Exit Codes #### Exit Codes
``` ```
1: leaks present
0: no leaks 0: no leaks
1: leaks present
2: error encountered
``` ```
#### Additional Examples and Explanations #### Additional Examples and Explanations
+1 -1
View File
@@ -23,7 +23,7 @@ regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
[whitelist] [whitelist]
regexes = [ regexes = [
"AKIA.*", # "AKIA.*EXAMPLE",
] ]
files = [ files = [
"(.*?)(jpg|gif|doc|pdf|bin|go)$" "(.*?)(jpg|gif|doc|pdf|bin|go)$"
+262 -41
View File
@@ -56,6 +56,35 @@ regexes= [
] ]
` `
var benchmarkRepo *RepoDescriptor
var benchmarkLeaksRepo *RepoDescriptor
func getBenchmarkLeaksRepo() *RepoDescriptor {
if benchmarkLeaksRepo != nil {
return benchmarkLeaksRepo
}
leaksR, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: "https://github.com/gitleakstest/gronit.git",
})
benchmarkLeaksRepo = &RepoDescriptor{
repository: leaksR,
}
return benchmarkLeaksRepo
}
func getBenchmarkRepo() *RepoDescriptor {
if benchmarkRepo != nil {
return benchmarkRepo
}
bmRepo, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: "https://github.com/apple/swift-package-manager.git",
})
benchmarkRepo = &RepoDescriptor{
repository: bmRepo,
}
return benchmarkRepo
}
func TestGetRepo(t *testing.T) { func TestGetRepo(t *testing.T) {
var err error var err error
dir, err = ioutil.TempDir("", "gitleaksTestRepo") dir, err = ioutil.TempDir("", "gitleaksTestRepo")
@@ -128,7 +157,7 @@ func TestGetRepo(t *testing.T) {
g.Describe("TestGetRepo", func() { g.Describe("TestGetRepo", func() {
g.It(test.description, func() { g.It(test.description, func() {
opts = test.testOpts opts = test.testOpts
_, err := getRepo() _, err := cloneRepo()
if err != nil { if err != nil {
g.Assert(err.Error()).Equal(test.expectedErrMsg) g.Assert(err.Error()).Equal(test.expectedErrMsg)
} }
@@ -136,9 +165,10 @@ func TestGetRepo(t *testing.T) {
}) })
} }
} }
func TestRun(t *testing.T) {
func TestGetOwnerRepo(t *testing.T) { err := loadToml()
var err error configsDir := testTomlLoader()
defer os.RemoveAll(configsDir)
dir, err = ioutil.TempDir("", "gitleaksTestOwner") dir, err = ioutil.TempDir("", "gitleaksTestOwner")
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
@@ -155,14 +185,14 @@ func TestGetOwnerRepo(t *testing.T) {
testOpts Options testOpts Options
description string description string
expectedErrMsg string expectedErrMsg string
numRepos int numLeaks int
}{ }{
{ {
testOpts: Options{ testOpts: Options{
GithubUser: "gitleakstest", GithubUser: "gitleakstest",
}, },
description: "test github user", description: "test github user",
numRepos: 2, numLeaks: 2,
expectedErrMsg: "", expectedErrMsg: "",
}, },
{ {
@@ -171,7 +201,7 @@ func TestGetOwnerRepo(t *testing.T) {
Disk: true, Disk: true,
}, },
description: "test github user on disk ", description: "test github user on disk ",
numRepos: 2, numLeaks: 2,
expectedErrMsg: "", expectedErrMsg: "",
}, },
{ {
@@ -179,56 +209,71 @@ func TestGetOwnerRepo(t *testing.T) {
GithubOrg: "gitleakstestorg", GithubOrg: "gitleakstestorg",
}, },
description: "test github org", description: "test github org",
numRepos: 2, numLeaks: 2,
expectedErrMsg: "", expectedErrMsg: "",
}, },
{
testOpts: Options{
OwnerPath: dir,
},
description: "test plain clone remote repo",
numRepos: 2,
expectedErrMsg: "",
},
{
testOpts: Options{
GithubOrg: "gitleakstestorg",
IncludePrivate: true,
},
description: "test private org no ssh",
numRepos: 0,
expectedErrMsg: "no ssh auth available",
},
{ {
testOpts: Options{ testOpts: Options{
GithubOrg: "gitleakstestorg", GithubOrg: "gitleakstestorg",
Disk: true, Disk: true,
}, },
description: "test org on disk", description: "test org on disk",
numRepos: 2, numLeaks: 2,
expectedErrMsg: "",
},
{
testOpts: Options{
OwnerPath: dir,
},
description: "test owner path",
numLeaks: 2,
expectedErrMsg: "", expectedErrMsg: "",
}, },
{ {
testOpts: Options{ testOpts: Options{
GithubOrg: "gitleakstestorg", GithubOrg: "gitleakstestorg",
IncludePrivate: true, IncludePrivate: true,
Disk: true, SSHKey: "reallyreallyreallyreallywrongpath",
}, },
description: "test private org on disk no ssh", description: "test private org no ssh",
numRepos: 0, numLeaks: 0,
expectedErrMsg: "no ssh auth available", expectedErrMsg: "unable to generate ssh key: open reallyreallyreallyreallywrongpath: no such file or directory",
},
{
testOpts: Options{
Repo: "https://github.com/gitleakstest/gronit.git",
},
description: "test leak",
numLeaks: 2,
expectedErrMsg: "",
},
{
testOpts: Options{
Repo: "https://github.com/gitleakstest/h1domains.git",
},
description: "test clean",
numLeaks: 0,
expectedErrMsg: "",
},
{
testOpts: Options{
Repo: "https://github.com/gitleakstest/empty.git",
},
description: "test empty",
numLeaks: 0,
expectedErrMsg: "reference not found",
}, },
} }
g := goblin.Goblin(t) g := goblin.Goblin(t)
for _, test := range tests { for _, test := range tests {
g.Describe("TestGetOwnerRepo", func() { g.Describe("TestRun", func() {
g.It(test.description, func() { g.It(test.description, func() {
opts = test.testOpts opts = test.testOpts
repos, err := getOwnerRepos() leaks, err := run()
if err != nil { if err != nil {
g.Assert(err.Error()).Equal(test.expectedErrMsg) g.Assert(err.Error()).Equal(test.expectedErrMsg)
} }
g.Assert(len(repos)).Equal(test.numRepos) g.Assert(len(leaks)).Equal(test.numLeaks)
}) })
}) })
} }
@@ -236,7 +281,8 @@ func TestGetOwnerRepo(t *testing.T) {
func TestWriteReport(t *testing.T) { func TestWriteReport(t *testing.T) {
tmpDir, _ := ioutil.TempDir("", "reportDir") tmpDir, _ := ioutil.TempDir("", "reportDir")
reportFile := path.Join(tmpDir, "report.json") reportJSON := path.Join(tmpDir, "report.json")
reportCSV := path.Join(tmpDir, "report.csv")
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
leaks := []Leak{ leaks := []Leak{
{ {
@@ -260,11 +306,21 @@ func TestWriteReport(t *testing.T) {
}{ }{
{ {
leaks: leaks, leaks: leaks,
reportFile: reportFile, reportFile: reportJSON,
fileName: "report.json", fileName: "report.json",
description: "can we write a file", description: "can we write a file",
testOpts: Options{ testOpts: Options{
Report: reportFile, Report: reportJSON,
},
},
{
leaks: leaks,
reportFile: reportCSV,
fileName: "report.csv",
description: "can we write a file",
testOpts: Options{
Report: reportCSV,
CSV: true,
}, },
}, },
} }
@@ -300,26 +356,34 @@ func TestAuditRepo(t *testing.T) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
leaksRepo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{ leaksR, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: "https://github.com/gitleakstest/gronit.git", URL: "https://github.com/gitleakstest/gronit.git",
}) })
if err != nil { if err != nil {
panic(err) panic(err)
} }
leaksRepo := &RepoDescriptor{
repository: leaksR,
name: "gronit",
}
cleanRepo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{ cleanR, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: "https://github.com/gitleakstest/h1domains.git", URL: "https://github.com/gitleakstest/h1domains.git",
}) })
if err != nil { if err != nil {
panic(err) panic(err)
} }
cleanRepo := &RepoDescriptor{
repository: cleanR,
name: "h1domains",
}
var tests = []struct { var tests = []struct {
testOpts Options testOpts Options
description string description string
expectedErrMsg string expectedErrMsg string
numLeaks int numLeaks int
repo *git.Repository repo *RepoDescriptor
whiteListFiles []*regexp.Regexp whiteListFiles []*regexp.Regexp
whiteListCommits map[string]bool whiteListCommits map[string]bool
whiteListBranches []string whiteListBranches []string
@@ -336,7 +400,7 @@ func TestAuditRepo(t *testing.T) {
description: "two leaks present limit goroutines", description: "two leaks present limit goroutines",
numLeaks: 2, numLeaks: 2,
testOpts: Options{ testOpts: Options{
MaxGoRoutines: 2, MaxGoRoutines: 4,
}, },
}, },
{ {
@@ -483,7 +547,7 @@ func TestAuditRepo(t *testing.T) {
loadToml() loadToml()
} }
leaks, err = auditRepo(test.repo) leaks, err = auditGitRepo(test.repo)
if opts.Redact { if opts.Redact {
g.Assert(leaks[0].Offender).Equal("REDACTED") g.Assert(leaks[0].Offender).Equal("REDACTED")
@@ -669,3 +733,160 @@ func TestLoadToml(t *testing.T) {
}) })
} }
} }
func BenchmarkAuditRepo1Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 1
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditRepo2Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 2
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditRepo4Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 4
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditRepo8Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 8
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditRepo10Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 10
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditRepo100Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 100
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditRepo1000Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 1000
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditRepo10000Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 10000
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditRepo100000Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 100000
benchmarkRepo = getBenchmarkRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo1Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 1
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo2Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 2
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo4Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 4
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo8Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 8
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo10Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 10
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo100Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 100
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo1000Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 1000
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo10000Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 10000
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
func BenchmarkAuditLeakRepo100000Proc(b *testing.B) {
loadToml()
opts.MaxGoRoutines = 100000
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
for n := 0; n < b.N; n++ {
auditGitRepo(benchmarkRepo)
}
}
+407 -390
View File
File diff suppressed because it is too large. Load diff