This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Add .gopass-audit-ignore support to ignore secrets from audits (…
…gopasspw#2822) * [feat] Add .gopass-audit-ignore support to ignore secrets from audits This PR adds a new exclude file that is used during gopass audit to ignore entries from auditing. The file itself is using RE2 syntax. Fixes gopasspw#2806 Signed-off-by: Dominik Schulz <[email protected]> * Add some documentation Signed-off-by: Dominik Schulz <[email protected]> --------- Signed-off-by: Dominik Schulz <[email protected]>
- Loading branch information
1 parent
9edbf30
commit 0562045
Showing
3 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package audit | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/gopasspw/gopass/pkg/debug" | ||
) | ||
|
||
type res []*regexp.Regexp | ||
|
||
func (r res) Matches(s string) bool { | ||
for _, re := range r { | ||
if re.MatchString(s) { | ||
debug.Log("Matched %s against %s", s, re.String()) | ||
|
||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
// FilterExcludes filters the given list of secrets against the given exclude patterns (RE2 syntax). | ||
func FilterExcludes(excludes string, in []string) []string { | ||
debug.Log("Filtering %d secrets against %d exclude patterns", len(in), strings.Count(excludes, "\n")) | ||
|
||
res := make(res, 0, 10) | ||
for _, line := range strings.Split(excludes, "\n") { | ||
line = strings.TrimSpace(line) | ||
if line == "" { | ||
continue | ||
} | ||
if strings.HasPrefix(line, "#") { | ||
continue | ||
} | ||
re, err := regexp.Compile(line) | ||
if err != nil { | ||
debug.Log("failed to compile exclude pattern %q: %s", line, err) | ||
|
||
continue | ||
} | ||
debug.Log("Adding exclude pattern %q", re.String()) | ||
res = append(res, re) | ||
} | ||
|
||
// shortcut if we have no excludes | ||
if len(res) < 1 { | ||
return in | ||
} | ||
|
||
// check all secrets against all excludes | ||
out := make([]string, 0, len(in)) | ||
for _, s := range in { | ||
if res.Matches(s) { | ||
continue | ||
} | ||
out = append(out, s) | ||
} | ||
|
||
return out | ||
} |