@@ -255,6 +255,7 @@ var (
255
255
huggingfaceIncludePrs = huggingfaceScan .Flag ("include-prs" , "Include pull requests in scan." ).Bool ()
256
256
257
257
stdinInputScan = cli .Command ("stdin" , "Find credentials from stdin." )
258
+ multiScanScan = cli .Command ("multi-scan" , "Find credentials in multiple sources defined in configuration." )
258
259
259
260
analyzeCmd = analyzer .Command (cli )
260
261
usingTUI = false
@@ -515,7 +516,8 @@ func run(state overseer.State) {
515
516
verificationCacheMetrics := verificationcache.InMemoryMetrics {}
516
517
517
518
engConf := engine.Config {
518
- Concurrency : * concurrency ,
519
+ Concurrency : * concurrency ,
520
+ ConfiguredSources : conf .Sources ,
519
521
// The engine must always be configured with the list of
520
522
// default detectors, which can be further filtered by the
521
523
// user. The filters are applied by the engine and are only
@@ -540,6 +542,16 @@ func run(state overseer.State) {
540
542
engConf .VerificationResultCache = simple .NewCache [detectors.Result ]()
541
543
}
542
544
545
+ // Check that there are no sources defined for non-scan subcommands. If
546
+ // there are, return an error as it is ambiguous what the user is
547
+ // trying to do.
548
+ if cmd != multiScanScan .FullCommand () && len (conf .Sources ) > 0 {
549
+ logFatal (
550
+ fmt .Errorf ("ambiguous configuration" ),
551
+ "sources should only be defined in configuration for the 'multi-scan' command" ,
552
+ )
553
+ }
554
+
543
555
if * compareDetectionStrategies {
544
556
if err := compareScans (ctx , cmd , engConf ); err != nil {
545
557
logFatal (err , "error comparing detection strategies" )
@@ -702,7 +714,7 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
702
714
}
703
715
}()
704
716
705
- var ref sources.JobProgressRef
717
+ var refs [] sources.JobProgressRef
706
718
switch cmd {
707
719
case gitScan .FullCommand ():
708
720
gitCfg := sources.GitConfig {
@@ -715,8 +727,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
715
727
Bare : * gitScanBare ,
716
728
ExcludeGlobs : * gitScanExcludeGlobs ,
717
729
}
718
- if ref , err = eng .ScanGit (ctx , gitCfg ); err != nil {
730
+ if ref , err : = eng .ScanGit (ctx , gitCfg ); err != nil {
719
731
return scanMetrics , fmt .Errorf ("failed to scan Git: %v" , err )
732
+ } else {
733
+ refs = []sources.JobProgressRef {ref }
720
734
}
721
735
case githubScan .FullCommand ():
722
736
filter , err := common .FilterFromFiles (* githubScanIncludePaths , * githubScanExcludePaths )
@@ -745,8 +759,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
745
759
Filter : filter ,
746
760
AuthInUrl : * githubAuthInUrl ,
747
761
}
748
- if ref , err = eng .ScanGitHub (ctx , cfg ); err != nil {
762
+ if ref , err : = eng .ScanGitHub (ctx , cfg ); err != nil {
749
763
return scanMetrics , fmt .Errorf ("failed to scan Github: %v" , err )
764
+ } else {
765
+ refs = []sources.JobProgressRef {ref }
750
766
}
751
767
case githubExperimentalScan .FullCommand ():
752
768
cfg := sources.GitHubExperimentalConfig {
@@ -756,8 +772,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
756
772
CollisionThreshold : * githubExperimentalCollisionThreshold ,
757
773
DeleteCachedData : * githubExperimentalDeleteCache ,
758
774
}
759
- if ref , err = eng .ScanGitHubExperimental (ctx , cfg ); err != nil {
775
+ if ref , err : = eng .ScanGitHubExperimental (ctx , cfg ); err != nil {
760
776
return scanMetrics , fmt .Errorf ("failed to scan using Github Experimental: %v" , err )
777
+ } else {
778
+ refs = []sources.JobProgressRef {ref }
761
779
}
762
780
case gitlabScan .FullCommand ():
763
781
filter , err := common .FilterFromFiles (* gitlabScanIncludePaths , * gitlabScanExcludePaths )
@@ -774,8 +792,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
774
792
Filter : filter ,
775
793
AuthInUrl : * gitlabAuthInUrl ,
776
794
}
777
- if ref , err = eng .ScanGitLab (ctx , cfg ); err != nil {
795
+ if ref , err : = eng .ScanGitLab (ctx , cfg ); err != nil {
778
796
return scanMetrics , fmt .Errorf ("failed to scan GitLab: %v" , err )
797
+ } else {
798
+ refs = []sources.JobProgressRef {ref }
779
799
}
780
800
case filesystemScan .FullCommand ():
781
801
if len (* filesystemDirectories ) > 0 {
@@ -789,8 +809,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
789
809
IncludePathsFile : * filesystemScanIncludePaths ,
790
810
ExcludePathsFile : * filesystemScanExcludePaths ,
791
811
}
792
- if ref , err = eng .ScanFileSystem (ctx , cfg ); err != nil {
812
+ if ref , err : = eng .ScanFileSystem (ctx , cfg ); err != nil {
793
813
return scanMetrics , fmt .Errorf ("failed to scan filesystem: %v" , err )
814
+ } else {
815
+ refs = []sources.JobProgressRef {ref }
794
816
}
795
817
case s3Scan .FullCommand ():
796
818
cfg := sources.S3Config {
@@ -803,8 +825,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
803
825
CloudCred : * s3ScanCloudEnv ,
804
826
MaxObjectSize : int64 (* s3ScanMaxObjectSize ),
805
827
}
806
- if ref , err = eng .ScanS3 (ctx , cfg ); err != nil {
828
+ if ref , err : = eng .ScanS3 (ctx , cfg ); err != nil {
807
829
return scanMetrics , fmt .Errorf ("failed to scan S3: %v" , err )
830
+ } else {
831
+ refs = []sources.JobProgressRef {ref }
808
832
}
809
833
case syslogScan .FullCommand ():
810
834
cfg := sources.SyslogConfig {
@@ -815,16 +839,22 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
815
839
KeyPath : * syslogTLSKey ,
816
840
Concurrency : * concurrency ,
817
841
}
818
- if ref , err = eng .ScanSyslog (ctx , cfg ); err != nil {
842
+ if ref , err : = eng .ScanSyslog (ctx , cfg ); err != nil {
819
843
return scanMetrics , fmt .Errorf ("failed to scan syslog: %v" , err )
844
+ } else {
845
+ refs = []sources.JobProgressRef {ref }
820
846
}
821
847
case circleCiScan .FullCommand ():
822
- if ref , err = eng .ScanCircleCI (ctx , * circleCiScanToken ); err != nil {
848
+ if ref , err : = eng .ScanCircleCI (ctx , * circleCiScanToken ); err != nil {
823
849
return scanMetrics , fmt .Errorf ("failed to scan CircleCI: %v" , err )
850
+ } else {
851
+ refs = []sources.JobProgressRef {ref }
824
852
}
825
853
case travisCiScan .FullCommand ():
826
- if ref , err = eng .ScanTravisCI (ctx , * travisCiScanToken ); err != nil {
854
+ if ref , err : = eng .ScanTravisCI (ctx , * travisCiScanToken ); err != nil {
827
855
return scanMetrics , fmt .Errorf ("failed to scan TravisCI: %v" , err )
856
+ } else {
857
+ refs = []sources.JobProgressRef {ref }
828
858
}
829
859
case gcsScan .FullCommand ():
830
860
cfg := sources.GCSConfig {
@@ -840,17 +870,21 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
840
870
Concurrency : * concurrency ,
841
871
MaxObjectSize : int64 (* gcsMaxObjectSize ),
842
872
}
843
- if ref , err = eng .ScanGCS (ctx , cfg ); err != nil {
873
+ if ref , err : = eng .ScanGCS (ctx , cfg ); err != nil {
844
874
return scanMetrics , fmt .Errorf ("failed to scan GCS: %v" , err )
875
+ } else {
876
+ refs = []sources.JobProgressRef {ref }
845
877
}
846
878
case dockerScan .FullCommand ():
847
879
cfg := sources.DockerConfig {
848
880
BearerToken : * dockerScanToken ,
849
881
Images : * dockerScanImages ,
850
882
UseDockerKeychain : * dockerScanToken == "" ,
851
883
}
852
- if ref , err = eng .ScanDocker (ctx , cfg ); err != nil {
884
+ if ref , err : = eng .ScanDocker (ctx , cfg ); err != nil {
853
885
return scanMetrics , fmt .Errorf ("failed to scan Docker: %v" , err )
886
+ } else {
887
+ refs = []sources.JobProgressRef {ref }
854
888
}
855
889
case postmanScan .FullCommand ():
856
890
// handle deprecated flag
@@ -886,8 +920,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
886
920
WorkspacePaths : * postmanWorkspacePaths ,
887
921
EnvironmentPaths : * postmanEnvironmentPaths ,
888
922
}
889
- if ref , err = eng .ScanPostman (ctx , cfg ); err != nil {
923
+ if ref , err : = eng .ScanPostman (ctx , cfg ); err != nil {
890
924
return scanMetrics , fmt .Errorf ("failed to scan Postman: %v" , err )
925
+ } else {
926
+ refs = []sources.JobProgressRef {ref }
891
927
}
892
928
case elasticsearchScan .FullCommand ():
893
929
cfg := sources.ElasticsearchConfig {
@@ -902,8 +938,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
902
938
SinceTimestamp : * elasticsearchSinceTimestamp ,
903
939
BestEffortScan : * elasticsearchBestEffortScan ,
904
940
}
905
- if ref , err = eng .ScanElasticsearch (ctx , cfg ); err != nil {
941
+ if ref , err : = eng .ScanElasticsearch (ctx , cfg ); err != nil {
906
942
return scanMetrics , fmt .Errorf ("failed to scan Elasticsearch: %v" , err )
943
+ } else {
944
+ refs = []sources.JobProgressRef {ref }
907
945
}
908
946
case jenkinsScan .FullCommand ():
909
947
cfg := engine.JenkinsConfig {
@@ -912,8 +950,10 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
912
950
Username : * jenkinsUsername ,
913
951
Password : * jenkinsPassword ,
914
952
}
915
- if ref , err = eng .ScanJenkins (ctx , cfg ); err != nil {
953
+ if ref , err : = eng .ScanJenkins (ctx , cfg ); err != nil {
916
954
return scanMetrics , fmt .Errorf ("failed to scan Jenkins: %v" , err )
955
+ } else {
956
+ refs = []sources.JobProgressRef {ref }
917
957
}
918
958
case huggingfaceScan .FullCommand ():
919
959
if * huggingfaceEndpoint != "" {
@@ -945,13 +985,26 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
945
985
IncludePrs : * huggingfaceIncludePrs ,
946
986
Concurrency : * concurrency ,
947
987
}
948
- if ref , err = eng .ScanHuggingface (ctx , cfg ); err != nil {
988
+ if ref , err : = eng .ScanHuggingface (ctx , cfg ); err != nil {
949
989
return scanMetrics , fmt .Errorf ("failed to scan HuggingFace: %v" , err )
990
+ } else {
991
+ refs = []sources.JobProgressRef {ref }
992
+ }
993
+ case multiScanScan .FullCommand ():
994
+ if * configFilename == "" {
995
+ return scanMetrics , fmt .Errorf ("missing required flag: --config" )
996
+ }
997
+ if rs , err := eng .ScanConfig (ctx , cfg .ConfiguredSources ... ); err != nil {
998
+ return scanMetrics , fmt .Errorf ("failed to scan via config: %w" , err )
999
+ } else {
1000
+ refs = rs
950
1001
}
951
1002
case stdinInputScan .FullCommand ():
952
1003
cfg := sources.StdinConfig {}
953
- if ref , err = eng .ScanStdinInput (ctx , cfg ); err != nil {
1004
+ if ref , err : = eng .ScanStdinInput (ctx , cfg ); err != nil {
954
1005
return scanMetrics , fmt .Errorf ("failed to scan stdin input: %v" , err )
1006
+ } else {
1007
+ refs = []sources.JobProgressRef {ref }
955
1008
}
956
1009
default :
957
1010
return scanMetrics , fmt .Errorf ("invalid command: %s" , cmd )
@@ -962,13 +1015,19 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
962
1015
return scanMetrics , fmt .Errorf ("engine failed to finish execution: %v" , err )
963
1016
}
964
1017
965
- // Print any errors reported during the scan.
966
- if errs := ref .Snapshot ().Errors ; len (errs ) > 0 {
967
- errMsgs := make ([]string , len (errs ))
968
- for i := 0 ; i < len (errs ); i ++ {
969
- errMsgs [i ] = errs [i ].Error ()
1018
+ // Print any non-fatal errors reported during the scan.
1019
+ for _ , ref := range refs {
1020
+ if errs := ref .Snapshot ().Errors ; len (errs ) > 0 {
1021
+ errMsgs := make ([]string , len (errs ))
1022
+ for i := 0 ; i < len (errs ); i ++ {
1023
+ errMsgs [i ] = errs [i ].Error ()
1024
+ }
1025
+ ctx .Logger ().Error (nil , "encountered errors during scan" ,
1026
+ "job" , ref .JobID ,
1027
+ "source_name" , ref .SourceName ,
1028
+ "errors" , errMsgs ,
1029
+ )
970
1030
}
971
- ctx .Logger ().Error (nil , "encountered errors during scan" , "errors" , errMsgs )
972
1031
}
973
1032
974
1033
if * printAvgDetectorTime {
0 commit comments