From 082893c9f3aaab03990785802a539fa9be309280 Mon Sep 17 00:00:00 2001 From: Ryan O'Horo <10855297+ryanohoro@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:29:14 -0500 Subject: [PATCH] Add doublestar glob for postive patterns --- configs/go/fileshot/fileshot.yaml | 3 ++- go.mod | 1 + go.sum | 2 ++ src/go/cmd/strelka-fileshot/main.go | 4 ++-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/configs/go/fileshot/fileshot.yaml b/configs/go/fileshot/fileshot.yaml index 238c743a..d2eac288 100644 --- a/configs/go/fileshot/fileshot.yaml +++ b/configs/go/fileshot/fileshot.yaml @@ -25,7 +25,8 @@ files: patterns: positive: - '/glob/to/your/files/*' - # negative + - '/superglob/to/your/files/**' + # negative # Does not support doublestar ** # - '/*/badfiles/*' minsize: 1 # Limit minimum file size in bytes maxsize: 999999999 # Limit max file size in bytes diff --git a/go.mod b/go.mod index 141b4b57..7029d976 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( ) require ( + github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/natefinch/lumberjack v2.0.0+incompatible // indirect diff --git a/go.sum b/go.sum index cd8a281f..991a2aa6 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= +github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= diff --git a/src/go/cmd/strelka-fileshot/main.go b/src/go/cmd/strelka-fileshot/main.go index 85383f50..182f7579 100644 --- a/src/go/cmd/strelka-fileshot/main.go +++ b/src/go/cmd/strelka-fileshot/main.go @@ -22,8 +22,8 @@ import ( "github.com/target/strelka/src/go/pkg/rpc" "github.com/target/strelka/src/go/pkg/structs" + "github.com/bmatcuk/doublestar/v4" "github.com/gabriel-vasile/mimetype" - "google.golang.org/grpc" "gopkg.in/yaml.v2" ) @@ -478,7 +478,7 @@ func getFilePaths(conf structs.FileShot, verbose *bool, hashes []string) []strin } // Expand the pattern to a list of matching file paths - match, err := filepath.Glob(p) + match, err := doublestar.FilepathGlob(p) if err != nil { log.Printf("failed to glob pattern %s: %v", p, err) continue