Compare commits

...
22 Commits
Author SHA1 Message Date
Zachary Rice 7c988c927d Merge pull request #107 from camaya/feature/add-entropy-checks
Add option to check string entropy
2018-10-09 18:46:21 -05:00
zach rice bde9af44ea merging, adding comments, updating flag description 2018-10-09 18:42:09 -05:00
Zachary Rice eee4d05642 Merge pull request #108 from camaya/fix-commit-option
Fix commit option
2018-10-09 16:18:54 -05:00
Cristhian Amaya 9144594d77 Fix commit option
The --commit option was being ignored becase the Close() function doesn't stop
the iterator.
According to the documentation:
https://godoc.org/gopkg.in/src-d/go-git.v4/plumbing/object#FileIter.ForEach
an ErrStop error should be send to stop it.
2018-10-09 16:49:16 +02:00
Cristhian Amaya 1cb15242fd Add option to check string entropy
Strings with high entropy have a good probability of being a secret.
2018-10-08 16:08:04 +02:00
Zachary Rice 08498600d1 Merge pull request #106 from zricethezav/exclude-fork
exclude fork
2018-10-07 18:42:42 -05:00
zach rice 88c0c7779b exclude fork 2018-10-07 18:39:17 -05:00
Zachary Rice 67454d109e Merge pull request #105 from zricethezav/wlrepo
Wlrepo
2018-10-07 18:26:18 -05:00
zach rice ce603c73b4 sample config opt 2018-10-07 18:19:43 -05:00
zach rice 55218fc8f8 whitelist repos 2018-10-07 18:09:10 -05:00
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 922 additions and 457 deletions

No files matched your search

+45
View File
@@ -1,6 +1,51 @@
CHANGELOG
=========
1.10.0
-----
- Add entropy option
1.9.0
-----
- exclude fork option
1.8.0
-----
- whitelist repos
- sample config option
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
-----
- 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 fmt
golint
go test --race -cover
go test --race --cover -run=Test$
deploy:
@echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
docker build -f Dockerfile -t $(REPO):$(TAG) .
echo "Pushing $(REPO):$(COMMIT) $(REPO):$(TAG)"
docker push $(REPO)
build-all:
rm -rf 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="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$
+4 -1
View File
@@ -43,16 +43,19 @@ Application Options:
-l, --log= log level
-v, --verbose Show verbose output from gitleaks audit
--report= path to write report file
--csv report output to csv
--redact redact secrets from log messages and report
--version version number
--sample-config prints a sample config file
Help Options:
-h, --help Show this help message
```
#### Exit Codes
```
1: leaks present
0: no leaks
1: leaks present
2: error encountered
```
#### Additional Examples and Explanations
+1 -1
View File
@@ -23,7 +23,7 @@ regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
[whitelist]
regexes = [
"AKIA.*",
# "AKIA.*EXAMPLE",
]
files = [
"(.*?)(jpg|gif|doc|pdf|bin|go)$"
+339 -40
View File
@@ -56,6 +56,46 @@ regexes= [
]
`
const testWhitelistRepo = `
[[regexes]]
description = "AWS"
regex = '''AKIA[0-9A-Z]{16}'''
[whitelist]
repos = [
"gronit",
]
`
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) {
var err error
dir, err = ioutil.TempDir("", "gitleaksTestRepo")
@@ -128,7 +168,7 @@ func TestGetRepo(t *testing.T) {
g.Describe("TestGetRepo", func() {
g.It(test.description, func() {
opts = test.testOpts
_, err := getRepo()
_, err := cloneRepo()
if err != nil {
g.Assert(err.Error()).Equal(test.expectedErrMsg)
}
@@ -136,9 +176,9 @@ func TestGetRepo(t *testing.T) {
})
}
}
func TestGetOwnerRepo(t *testing.T) {
func TestRun(t *testing.T) {
var err error
configsDir := testTomlLoader()
dir, err = ioutil.TempDir("", "gitleaksTestOwner")
defer os.RemoveAll(dir)
@@ -155,14 +195,16 @@ func TestGetOwnerRepo(t *testing.T) {
testOpts Options
description string
expectedErrMsg string
numRepos int
whiteListRepos []string
numLeaks int
configPath string
}{
{
testOpts: Options{
GithubUser: "gitleakstest",
},
description: "test github user",
numRepos: 2,
numLeaks: 2,
expectedErrMsg: "",
},
{
@@ -171,7 +213,7 @@ func TestGetOwnerRepo(t *testing.T) {
Disk: true,
},
description: "test github user on disk ",
numRepos: 2,
numLeaks: 2,
expectedErrMsg: "",
},
{
@@ -179,56 +221,92 @@ func TestGetOwnerRepo(t *testing.T) {
GithubOrg: "gitleakstestorg",
},
description: "test github org",
numRepos: 2,
numLeaks: 2,
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{
GithubOrg: "gitleakstestorg",
Disk: true,
},
description: "test org on disk",
numRepos: 2,
numLeaks: 2,
expectedErrMsg: "",
},
{
testOpts: Options{
OwnerPath: dir,
},
description: "test owner path",
numLeaks: 2,
expectedErrMsg: "",
},
{
testOpts: Options{
GithubOrg: "gitleakstestorg",
IncludePrivate: true,
Disk: true,
SSHKey: "reallyreallyreallyreallywrongpath",
},
description: "test private org on disk no ssh",
numRepos: 0,
expectedErrMsg: "no ssh auth available",
description: "test private org no ssh",
numLeaks: 0,
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",
},
{
testOpts: Options{
GithubOrg: "gitleakstestorg",
},
description: "test github org, whitelist repo",
numLeaks: 0,
expectedErrMsg: "",
configPath: path.Join(configsDir, "repo"),
},
{
testOpts: Options{
GithubOrg: "gitleakstestorg",
ExcludeForks: true,
},
description: "test github org, exclude forks",
numLeaks: 0,
expectedErrMsg: "",
},
}
g := goblin.Goblin(t)
for _, test := range tests {
g.Describe("TestGetOwnerRepo", func() {
g.Describe("TestRun", func() {
g.It(test.description, func() {
if test.configPath != "" {
os.Setenv("GITLEAKS_CONFIG", test.configPath)
}
opts = test.testOpts
repos, err := getOwnerRepos()
leaks, err := run()
if err != nil {
g.Assert(err.Error()).Equal(test.expectedErrMsg)
}
g.Assert(len(repos)).Equal(test.numRepos)
g.Assert(len(leaks)).Equal(test.numLeaks)
})
})
}
@@ -236,7 +314,8 @@ func TestGetOwnerRepo(t *testing.T) {
func TestWriteReport(t *testing.T) {
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)
leaks := []Leak{
{
@@ -260,11 +339,21 @@ func TestWriteReport(t *testing.T) {
}{
{
leaks: leaks,
reportFile: reportFile,
reportFile: reportJSON,
fileName: "report.json",
description: "can we write a file",
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,
},
},
}
@@ -288,6 +377,7 @@ func testTomlLoader() string {
ioutil.WriteFile(path.Join(tmpDir, "branch"), []byte(testWhitelistBranch), 0644)
ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
ioutil.WriteFile(path.Join(tmpDir, "repo"), []byte(testWhitelistRepo), 0644)
return tmpDir
}
@@ -300,29 +390,38 @@ func TestAuditRepo(t *testing.T) {
if err != nil {
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",
})
if err != nil {
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",
})
if err != nil {
panic(err)
}
cleanRepo := &RepoDescriptor{
repository: cleanR,
name: "h1domains",
}
var tests = []struct {
testOpts Options
description string
expectedErrMsg string
numLeaks int
repo *git.Repository
repo *RepoDescriptor
whiteListFiles []*regexp.Regexp
whiteListCommits map[string]bool
whiteListBranches []string
whiteListRepos []string
whiteListRegexes []*regexp.Regexp
configPath string
}{
@@ -336,7 +435,7 @@ func TestAuditRepo(t *testing.T) {
description: "two leaks present limit goroutines",
numLeaks: 2,
testOpts: Options{
MaxGoRoutines: 2,
MaxGoRoutines: 4,
},
},
{
@@ -447,6 +546,36 @@ func TestAuditRepo(t *testing.T) {
configPath: path.Join(configsDir, "commit"),
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"),
},
{
repo: leaksRepo,
description: "leaks present with entropy",
testOpts: Options{
Entropy: 4.7,
},
numLeaks: 7,
},
{
repo: leaksRepo,
description: "Audit until specific commit",
numLeaks: 1,
testOpts: Options{
Commit: "f6839959b7bbdcd23008f1fb16f797f35bcd3a0c",
},
},
}
whiteListCommits = make(map[string]bool)
@@ -476,6 +605,11 @@ func TestAuditRepo(t *testing.T) {
} else {
whiteListRegexes = nil
}
if test.whiteListRepos != nil {
whiteListRepos = test.whiteListRepos
} else {
whiteListRepos = nil
}
// config paths
if test.configPath != "" {
@@ -483,7 +617,7 @@ func TestAuditRepo(t *testing.T) {
loadToml()
}
leaks, err = auditRepo(test.repo)
leaks, err = auditGitRepo(test.repo)
if opts.Redact {
g.Assert(leaks[0].Offender).Equal("REDACTED")
@@ -568,6 +702,14 @@ func TestOptionGuard(t *testing.T) {
description: "single search regex gaurd",
expectedErrMsg: "",
},
{
testOpts: Options{
GithubOrg: "fakeOrg",
Entropy: 9,
},
description: "Invalid entropy level guard",
expectedErrMsg: "The maximum level of entropy is 8",
},
}
g := goblin.Goblin(t)
for _, test := range tests {
@@ -669,3 +811,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)
}
}
+507 -413
View File
File diff suppressed because it is too large. Load diff