Compare commits

...
9 Commits
Author SHA1 Message Date
zricethezav db08fc0564 actually bump version in code >.< 2018-11-18 08:43:05 -06:00
zricethezav dbb6d4cc5f including camayas changes in version bump 2018-11-18 08:42:32 -06:00
Zachary Rice d0f44da4c2 Merge pull request #151 from AdamKobi/add_support_for_tokens
Add support for tokens
2018-11-18 08:39:17 -06:00
Zachary Rice cb6b01cc5d Merge pull request #149 from camaya/fix-files-whitelist-github-prs
Fix files whitelisting when checking Github PRs
2018-11-18 08:36:47 -06:00
Adam Kobi 392d79b9e2 added changes to changelog 2018-11-15 19:04:51 +02:00
Adam Kobi f8e609d4bf added case for when using oauth token for both listing and cloning repos 2018-11-15 17:58:54 +02:00
Zachary Rice 573bf46fd1 grammar not my best subject 2018-11-13 20:01:44 -06:00
Zachary Rice d65592bbcc Update to readme 2018-11-13 19:57:52 -06:00
Cristhian Amaya 169a137e7f Fix files whitelisting when checking Github PRs
Files whitelisting code was not executed when running the tool against a
Github PR so the config was ignored.

To avoid duplication, the whitelist files check has been moved to the `inspect`
function which is always executed.
2018-11-13 11:54:25 +01:00
5 changed files with 62 additions and 21 deletions

No files matched your search

+5
View File
@@ -1,6 +1,11 @@
CHANGELOG CHANGELOG
========= =========
1.21.0
----
- added support for cloning repositories using github api
- auditing PRs now allows for whitelisting files
1.20.0 1.20.0
---- ----
- adding gitlab user and group support - adding gitlab user and group support
+9 -5
View File
@@ -105,11 +105,7 @@ The code return codes are:
2: error encountered 2: error encountered
``` ```
### GitLab ### Additional information
To audit public repositories for user on GitLab use `--gitlab-user=` and for group `--gitlab-org=`. For private repositories add `GITLAB_TOKEN` environment variable with your personal access token (is used to list all repositories via API) and set `--ssh-key=` to SSH key path (is used to clone repository).
If self hosted GitLab server add `GITLAB_URL` environment variable with your URL.
#### Additional information
* Additional documentation about how gitleaks functions can be found on the [wiki page](https://github.com/zricethezav/gitleaks/wiki) * Additional documentation about how gitleaks functions can be found on the [wiki page](https://github.com/zricethezav/gitleaks/wiki)
* The below links detail the various approaches to remediating unwanted data in git repos * The below links detail the various approaches to remediating unwanted data in git repos
* [Removing sensitive data from a repository (github.com)](https://help.github.com/articles/removing-sensitive-data-from-a-repository/) * [Removing sensitive data from a repository (github.com)](https://help.github.com/articles/removing-sensitive-data-from-a-repository/)
@@ -122,6 +118,14 @@ If self hosted GitLab server add `GITLAB_URL` environment variable with your URL
* How does gitleaks differ to Github token scanning? * How does gitleaks differ to Github token scanning?
* [Github recently announced](https://blog.github.com/2018-10-16-future-of-software/#github-token-scanning-for-public-repositories-public-beta) a new capability to their cloud platform that detects exposed credentials for a number of common services and platforms and automatically notifies the provider for revocation or similar action. Gitleaks provides a similar detection capability for non-Github cloud users, in which repositories can be easily audited and results provided in a number of formats. * [Github recently announced](https://blog.github.com/2018-10-16-future-of-software/#github-token-scanning-for-public-repositories-public-beta) a new capability to their cloud platform that detects exposed credentials for a number of common services and platforms and automatically notifies the provider for revocation or similar action. Gitleaks provides a similar detection capability for non-Github cloud users, in which repositories can be easily audited and results provided in a number of formats.
### Give Thanks
If using gitleaks has made you job easier consider donating to an organization, C-U at Home, that does vital work for those who most need it in the community of Champaign-Urbana, IL (my home).
From C-U at Home:
```C-U at Home is a grassroots, 501 c (3), faith-based homelessness ministry with facilities located in the Champaign-Urbana area. Due to our not-for-profit status, all gifts made to C-U at Home (both monetary and in-kind) are tax deductible. Our ministry is funded 100% by the community and we have made it a priority not to accept any state or federal funds. We feel that through community dollars, we can stay true to our mission. While our mission statement reads, “C-U at Home engages and mobilizes our community to house and support the most vulnerable homeless on their journey of healing and restoration,” our connection with those we serve goes much deeper.```
<b>Donate</b>: https://www.cuathome.us/give/
+20 -2
View File
@@ -14,6 +14,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"golang.org/x/oauth2" "golang.org/x/oauth2"
git "gopkg.in/src-d/go-git.v4" git "gopkg.in/src-d/go-git.v4"
gitHttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
"gopkg.in/src-d/go-git.v4/storage/memory" "gopkg.in/src-d/go-git.v4/storage/memory"
) )
@@ -177,6 +178,7 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
repo *git.Repository repo *git.Repository
err error err error
) )
githubToken := os.Getenv("GITHUB_TOKEN")
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)
} }
@@ -191,22 +193,38 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to generater owner temp dir: %v", err) return nil, fmt.Errorf("unable to generater owner temp dir: %v", err)
} }
if sshAuth != nil { if sshAuth != nil && githubToken == "" {
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{ repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
URL: *githubRepo.SSHURL, URL: *githubRepo.SSHURL,
Auth: sshAuth, Auth: sshAuth,
}) })
} else if githubToken != "" {
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
URL: *githubRepo.CloneURL,
Auth: &gitHttp.BasicAuth{
Username: "fakeUsername", // yes, this can be anything except an empty string
Password: githubToken,
},
})
} else { } else {
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{ repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
URL: *githubRepo.CloneURL, URL: *githubRepo.CloneURL,
}) })
} }
} else { } else {
if sshAuth != nil { if sshAuth != nil && githubToken == "" {
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{ repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: *githubRepo.SSHURL, URL: *githubRepo.SSHURL,
Auth: sshAuth, Auth: sshAuth,
}) })
} else if githubToken != "" {
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: *githubRepo.CloneURL,
Auth: &gitHttp.BasicAuth{
Username: "fakeUsername", // yes, this can be anything except an empty string
Password: githubToken,
},
})
} else { } else {
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{ repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: *githubRepo.CloneURL, URL: *githubRepo.CloneURL,
+18
View File
@@ -176,6 +176,7 @@ func TestRun(t *testing.T) {
description string description string
expectedErrMsg string expectedErrMsg string
whiteListRepos []string whiteListRepos []string
whiteListFiles []*regexp.Regexp
numLeaks int numLeaks int
configPath string configPath string
commitPerPage int commitPerPage int
@@ -298,6 +299,18 @@ func TestRun(t *testing.T) {
expectedErrMsg: "", expectedErrMsg: "",
commitPerPage: 1, commitPerPage: 1,
}, },
{
testOpts: Options{
GithubPR: "https://github.com/gitleakstest/gronit/pull/1",
},
description: "test github pr with whitelisted files",
numLeaks: 0,
expectedErrMsg: "",
commitPerPage: 1,
whiteListFiles: []*regexp.Regexp{
regexp.MustCompile("main.go"),
},
},
} }
g := goblin.Goblin(t) g := goblin.Goblin(t)
for _, test := range tests { for _, test := range tests {
@@ -309,6 +322,11 @@ func TestRun(t *testing.T) {
if test.commitPerPage != 0 { if test.commitPerPage != 0 {
githubPages = test.commitPerPage githubPages = test.commitPerPage
} }
if test.whiteListFiles != nil {
whiteListFiles = test.whiteListFiles
} else {
whiteListFiles = nil
}
opts = test.testOpts opts = test.testOpts
leaks, err := run() leaks, err := run()
if err != nil { if err != nil {
+10 -14
View File
@@ -130,7 +130,7 @@ type entropyRange struct {
} }
const defaultGithubURL = "https://api.github.com/" const defaultGithubURL = "https://api.github.com/"
const version = "1.20.0" const version = "1.21.0"
const errExit = 2 const errExit = 2
const leakExit = 1 const leakExit = 1
const defaultConfig = ` const defaultConfig = `
@@ -171,7 +171,7 @@ regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
[whitelist] [whitelist]
files = [ files = [
"(.*?)(jpg|gif|doc|pdf|bin)$" "(.*?)(jpg|gif|doc|pdf|bin)$"
] ]
#commits = [ #commits = [
# "BADHA5H1", # "BADHA5H1",
@@ -488,11 +488,6 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
if bin || err != nil { if bin || err != nil {
return nil return nil
} }
for _, re := range whiteListFiles {
if re.FindString(f.Name) != "" {
return nil
}
}
content, err := f.Contents() content, err := f.Contents()
if err != nil { if err != nil {
return nil return nil
@@ -560,12 +555,6 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
} else if to != nil { } else if to != nil {
filePath = to.Path() filePath = to.Path()
} }
for _, re := range whiteListFiles {
if re.FindString(filePath) != "" {
skipFile = true
break
}
}
if skipFile { if skipFile {
continue continue
} }
@@ -604,12 +593,19 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
// will skip lines that include a whitelisted regex. A list of leaks is returned. // will skip lines that include a whitelisted regex. A list of leaks is returned.
// If verbose mode (-v/--verbose) is set, then checkDiff will log leaks as they are discovered. // If verbose mode (-v/--verbose) is set, then checkDiff will log leaks as they are discovered.
func inspect(diff gitDiff) []Leak { func inspect(diff gitDiff) []Leak {
lines := strings.Split(diff.content, "\n")
var ( var (
leaks []Leak leaks []Leak
skipLine bool skipLine bool
) )
for _, re := range whiteListFiles {
if re.FindString(diff.filePath) != "" {
return leaks
}
}
lines := strings.Split(diff.content, "\n")
for _, line := range lines { for _, line := range lines {
skipLine = false skipLine = false
for leakType, re := range regexes { for leakType, re := range regexes {