From 8c2abf33e5ce4f21505c5d55808708eb26458e99 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 9 May 2023 12:20:23 +0200 Subject: [PATCH 1/2] add debug switch for antivirus Signed-off-by: Christian Richter --- services/antivirus/pkg/config/config.go | 2 ++ services/antivirus/pkg/scanners/scanners.go | 10 ++++----- services/antivirus/pkg/service/service.go | 23 ++++++++++++++++++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/services/antivirus/pkg/config/config.go b/services/antivirus/pkg/config/config.go index f92680bfe..b313760bf 100644 --- a/services/antivirus/pkg/config/config.go +++ b/services/antivirus/pkg/config/config.go @@ -19,6 +19,8 @@ type Config struct { MaxScanSize string `yaml:"max-scan-size" env:"ANTIVIRUS_MAX_SCAN_SIZE" desc:"The maximum scan size the virusscanner can handle. Only this many bytes of a file will be scanned. 0 means unlimited and is the default. Usable common abbreviations: [KB, KiB, GB, GiB, TB, TiB, PB, PiB, EB, EiB], example: 2GB."` Context context.Context `yaml:"-" json:"-"` + + DebugScanOutcome string `yaml:"-" env:"ANTIVIRUS_DEBUG_SCAN_OUTCOME" desc:"A predefined outcome for virus scanning, FOR DEBUG PURPOSES ONLY! (example values: \"found,infected\")"` } // Service defines the available service configuration. diff --git a/services/antivirus/pkg/scanners/scanners.go b/services/antivirus/pkg/scanners/scanners.go index ef2fe4648..b3257c2f9 100644 --- a/services/antivirus/pkg/scanners/scanners.go +++ b/services/antivirus/pkg/scanners/scanners.go @@ -21,14 +21,14 @@ type Scanner interface { } // New returns a new scanner from config -func New(c config.Scanner) (Scanner, error) { - switch c.Type { +func New(c *config.Config) (Scanner, error) { + switch c.Scanner.Type { default: - return nil, fmt.Errorf("unknown av scanner: '%s'", c.Type) + return nil, fmt.Errorf("unknown av scanner: '%s'", c.Scanner.Type) case "clamav": - return NewClamAV(c.ClamAV.Socket), nil + return NewClamAV(c.Scanner.ClamAV.Socket), nil case "icap": - return NewICAP(c.ICAP.URL, c.ICAP.Service, time.Duration(c.ICAP.Timeout)*time.Second) + return NewICAP(c.Scanner.ICAP.URL, c.Scanner.ICAP.Service, time.Duration(c.Scanner.ICAP.Timeout)*time.Second) } } diff --git a/services/antivirus/pkg/service/service.go b/services/antivirus/pkg/service/service.go index cc29e6c51..09952d903 100644 --- a/services/antivirus/pkg/service/service.go +++ b/services/antivirus/pkg/service/service.go @@ -30,7 +30,7 @@ func NewAntivirus(c *config.Config, l log.Logger) (Antivirus, error) { av := Antivirus{c: c, l: l, client: rhttp.GetHTTPClient(rhttp.Insecure(true))} var err error - av.s, err = scanners.New(c.Scanner) + av.s, err = scanners.New(c) if err != nil { return av, err } @@ -102,6 +102,27 @@ func (av Antivirus) Run() error { continue } + if av.c.DebugScanOutcome != "" { + av.l.Warn().Str("antivir, clamav", ">>>>>>> ANTIVIRUS_DEBUG_SCAN_OUTCOME IS SET NO ACTUAL VIRUS SCAN IS PERFORMED!") + if err := events.Publish(stream, events.PostprocessingStepFinished{ + FinishedStep: events.PPStepAntivirus, + Outcome: events.PostprocessingOutcome(av.c.DebugScanOutcome), + UploadID: ev.UploadID, + ExecutingUser: ev.ExecutingUser, + Filename: ev.Filename, + Result: events.VirusscanResult{ + Infected: true, + Description: "DEBUG: forced outcome", + Scandate: time.Now(), + ResourceID: ev.ResourceID, + ErrorMsg: "DEBUG: forced outcome", + }, + }); err != nil { + av.l.Fatal().Err(err).Str("uploadid", ev.UploadID).Interface("resourceID", ev.ResourceID).Msg("cannot publish events - exiting") + return err + } + } + av.l.Debug().Str("uploadid", ev.UploadID).Str("filename", ev.Filename).Msg("Starting virus scan.") var errmsg string res, err := av.process(ev) From 645f2b24236ac7ed1a475883b5fc426375e986dc Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 9 May 2023 15:43:49 +0200 Subject: [PATCH 2/2] Add debug env var for av Co-authored-by: Julian Koberg Signed-off-by: Christian Richter --- changelog/unreleased/add-debug-result-for-av.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/add-debug-result-for-av.md diff --git a/changelog/unreleased/add-debug-result-for-av.md b/changelog/unreleased/add-debug-result-for-av.md new file mode 100644 index 000000000..43bc72021 --- /dev/null +++ b/changelog/unreleased/add-debug-result-for-av.md @@ -0,0 +1,5 @@ +Enhancement: Add specific result to antivirus for debugging + +We added the ability to define a specific result for the virus scanner via env-var (ANTIVIRUS_DEBUG_SCAN_OUTCOME) + +https://github.com/owncloud/ocis/pull/6265 \ No newline at end of file