Skip to content
Merged
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,24 @@ package:
# same as -s ; SYFT_PACKAGE_CATALOGER_SCOPE env var
scope: "squashed"

# enable specific language or ecosystem cataloger
# default: all catalogers are enabled by default
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: mentioning that all catalogers are enabled by default is a little misleading. There is still a selection of which catalogers to use based off of the source (dir scan or image scan)

# enable-cataloger:
# - "ruby-gemfile-cataloger"
# - "ruby-gemspec-cataloger"
# - "python-index-cataloger"
# - "python-package-cataloger"
# - "javascript-lock-cataloger"
# - "javascript-package-cataloger"
# - "php-composer-installed-cataloger"
# - "php-composer-lock-cataloger"
# - "dpkgdb-cataloger"
# - "rpmdb-cataloger"
# - "java-cataloger"
# - "apkdb-cataloger"
# - "go-module-binary-cataloger"
enable-cataloger:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since this takes multiple values it should probably be enable-catalogers


# cataloging file classifications is exposed through the power-user subcommand
file-classification:
cataloger:
Expand Down
7 changes: 7 additions & 0 deletions cmd/syft/cli/options/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func (o *PackagesOptions) AddFlags(cmd *cobra.Command, v *viper.Viper) error {
cmd.PersistentFlags().StringArrayVarP(&o.Exclude, "exclude", "", nil,
"exclude paths from being scanned using a glob expression")

cmd.PersistentFlags().StringArrayP("enable-cataloger", "", nil,
"enable specific language or ecosystem cataloger")

cmd.PersistentFlags().BoolVarP(&o.OverwriteExistingImage, "overwrite-existing-image", "", false,
"overwrite an existing image during the upload to Anchore Enterprise")

Expand All @@ -80,6 +83,10 @@ func bindPackageConfigOptions(flags *pflag.FlagSet, v *viper.Viper) error {
return err
}

if err := v.BindPFlag("package.enable-cataloger", flags.Lookup("enable-cataloger")); err != nil {
return err
}

if err := v.BindPFlag("output", flags.Lookup("output")); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/config/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type pkg struct {
Cataloger catalogerOptions `yaml:"cataloger" json:"cataloger" mapstructure:"cataloger"`
SearchUnindexedArchives bool `yaml:"search-unindexed-archives" json:"search-unindexed-archives" mapstructure:"search-unindexed-archives"`
SearchIndexedArchives bool `yaml:"search-indexed-archives" json:"search-indexed-archives" mapstructure:"search-indexed-archives"`
EnabledCatalogers []string `yaml:"enable-cataloger" json:"enable-cataloger" mapstructure:"enable-cataloger"`
}

func (cfg pkg) loadDefaultValues(v *viper.Viper) {
Expand All @@ -29,5 +30,6 @@ func (cfg pkg) ToConfig() cataloger.Config {
IncludeUnindexedArchives: cfg.SearchUnindexedArchives,
Scope: cfg.Cataloger.ScopeOpt,
},
EnabledCatalogers: cfg.EnabledCatalogers,
}
}
41 changes: 32 additions & 9 deletions syft/pkg/cataloger/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/anchore/syft/syft/pkg/cataloger/apkdb"
"github.com/anchore/syft/syft/pkg/cataloger/dart"
"github.com/anchore/syft/syft/pkg/cataloger/deb"
"github.com/anchore/syft/syft/pkg/cataloger/dotnet"
//"github.com/anchore/syft/syft/pkg/cataloger/dotnet"
"github.com/anchore/syft/syft/pkg/cataloger/golang"
"github.com/anchore/syft/syft/pkg/cataloger/java"
"github.com/anchore/syft/syft/pkg/cataloger/javascript"
Expand All @@ -35,7 +35,7 @@ type Cataloger interface {

// ImageCatalogers returns a slice of locally implemented catalogers that are fit for detecting installations of packages.
func ImageCatalogers(cfg Config) []Cataloger {
return []Cataloger{
return filterCatalogers([]Cataloger{
ruby.NewGemSpecCataloger(),
python.NewPythonPackageCataloger(),
php.NewPHPComposerInstalledCataloger(),
Expand All @@ -45,13 +45,13 @@ func ImageCatalogers(cfg Config) []Cataloger {
java.NewJavaCataloger(cfg.Java()),
apkdb.NewApkdbCataloger(),
golang.NewGoModuleBinaryCataloger(),
dotnet.NewDotnetDepsCataloger(),
}
//dotnet.NewDotnetDepsCataloger(),
}, cfg.EnabledCatalogers)
}

// DirectoryCatalogers returns a slice of locally implemented catalogers that are fit for detecting packages from index files (and select installations)
func DirectoryCatalogers(cfg Config) []Cataloger {
return []Cataloger{
return filterCatalogers([]Cataloger{
ruby.NewGemFileLockCataloger(),
python.NewPythonIndexCataloger(),
python.NewPythonPackageCataloger(),
Expand All @@ -65,13 +65,13 @@ func DirectoryCatalogers(cfg Config) []Cataloger {
golang.NewGoModFileCataloger(),
rust.NewCargoLockCataloger(),
dart.NewPubspecLockCataloger(),
dotnet.NewDotnetDepsCataloger(),
}
//dotnet.NewDotnetDepsCataloger(),
}, cfg.EnabledCatalogers)
}

// AllCatalogers returns all implemented catalogers
func AllCatalogers(cfg Config) []Cataloger {
return []Cataloger{
return filterCatalogers([]Cataloger{
ruby.NewGemFileLockCataloger(),
ruby.NewGemSpecCataloger(),
python.NewPythonIndexCataloger(),
Expand All @@ -86,6 +86,29 @@ func AllCatalogers(cfg Config) []Cataloger {
golang.NewGoModFileCataloger(),
rust.NewCargoLockCataloger(),
dart.NewPubspecLockCataloger(),
dotnet.NewDotnetDepsCataloger(),
//dotnet.NewDotnetDepsCataloger(),
}, cfg.EnabledCatalogers)
}

func filterCatalogers(catalogers []Cataloger, enabledCatalogers []string) []Cataloger {
// if enable-cataloger is not set, all applicable catalogers are enabled by default
if len(enabledCatalogers) == 0 {
return catalogers
}
var filteredCatalogers []Cataloger
for _, cataloger := range catalogers {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could add additional logic such that the string -cataloger is optional on each user-specified name, to be nicer to the user.

if contains(enabledCatalogers, cataloger.Name()) {
filteredCatalogers = append(filteredCatalogers, cataloger)
}
}
return filteredCatalogers
}

func contains(catalogers []string, str string) bool {
for _, cataloger := range catalogers {
if cataloger == str {
return true
}
}
return false
}
3 changes: 2 additions & 1 deletion syft/pkg/cataloger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
)

type Config struct {
Search SearchConfig
Search SearchConfig
EnabledCatalogers []string
}

func DefaultConfig() Config {
Expand Down