Skip to content

Commit

Permalink
add detection of ELF security features
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
  • Loading branch information
wagoodman committed Jan 12, 2024
1 parent b0ab75f commit 8bce64f
Show file tree
Hide file tree
Showing 33 changed files with 1,041 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/validations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jobs:
- name: Bootstrap environment
uses: ./.github/actions/bootstrap

- name: Restore file executable test-fixture cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2
with:
path: syft/file/cataloger/executable/test-fixtures/bin
key: ${{ runner.os }}-unit-file-executable-cache-${{ hashFiles( 'syft/file/cataloger/executable/test-fixtures/cache.fingerprint' ) }}

- name: Restore Java test-fixture cache
uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c #v3.3.3
with:
Expand Down
14 changes: 9 additions & 5 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ tasks:
fingerprints:
desc: Generate test fixture fingerprints
generates:
- syft/file/cataloger/executable/test-fixtures/cache.fingerprint
- test/integration/test-fixtures/cache.fingerprint
- syft/pkg/cataloger/binary/test-fixtures/cache.fingerprint
- syft/pkg/cataloger/java/test-fixtures/java-builds/cache.fingerprint
Expand All @@ -274,17 +275,19 @@ tasks:
- test/install/cache.fingerprint
- test/cli/test-fixtures/cache.fingerprint
cmds:
# for EXECUTABLE unit test fixtures
- "cd syft/file/cataloger/executable/test-fixtures && make cache.fingerprint"
# for IMAGE integration test fixtures
- "cd test/integration/test-fixtures && make cache.fingerprint"
# for BINARY test fixtures
# for BINARY unit test fixtures
- "cd syft/pkg/cataloger/binary/test-fixtures && make cache.fingerprint"
# for JAVA BUILD test fixtures
# for JAVA BUILD unit test fixtures
- "cd syft/pkg/cataloger/java/test-fixtures/java-builds && make cache.fingerprint"
# for GO BINARY test fixtures
# for GO BINARY unit test fixtures
- "cd syft/pkg/cataloger/golang/test-fixtures/archs && make binaries.fingerprint"
# for RPM test fixtures
# for RPM unit test fixtures
- "cd syft/pkg/cataloger/redhat/test-fixtures && make rpms.fingerprint"
# for Kernel test fixtures
# for Kernel unit test fixtures
- "cd syft/pkg/cataloger/kernel/test-fixtures && make cache.fingerprint"
# for INSTALL integration test fixtures
- "cd test/install && make cache.fingerprint"
Expand All @@ -294,6 +297,7 @@ tasks:
fixtures:
desc: Generate test fixtures
cmds:
- "cd syft/file/cataloger/executable/test-fixtures && make"
- "cd syft/pkg/cataloger/java/test-fixtures/java-builds && make"
- "cd syft/pkg/cataloger/redhat/test-fixtures && make"
- "cd syft/pkg/cataloger/binary/test-fixtures && make"
Expand Down
5 changes: 5 additions & 0 deletions cmd/syft/cli/options/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package options

import (
"fmt"
"github.com/anchore/syft/syft/file/cataloger/executable"
"sort"
"strings"

Expand Down Expand Up @@ -112,6 +113,10 @@ func (cfg Catalog) ToFilesConfig() filecataloging.Config {
Globs: cfg.File.Content.Globs,
SkipFilesAboveSize: cfg.File.Content.SkipFilesAboveSize,
},
Executable: executable.Config{
MIMETypes: executable.DefaultConfig().MIMETypes,
Globs: cfg.File.Executable.Globs,
},
}
}

Expand Down
12 changes: 10 additions & 2 deletions cmd/syft/cli/options/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
)

type fileConfig struct {
Metadata fileMetadata `yaml:"metadata" json:"metadata" mapstructure:"metadata"`
Content fileContent `yaml:"content" json:"content" mapstructure:"content"`
Metadata fileMetadata `yaml:"metadata" json:"metadata" mapstructure:"metadata"`
Content fileContent `yaml:"content" json:"content" mapstructure:"content"`
Executable fileExecutable `yaml:"executable" json:"executable" mapstructure:"executable"`
}

type fileMetadata struct {
Expand All @@ -22,6 +23,10 @@ type fileContent struct {
Globs []string `yaml:"globs" json:"globs" mapstructure:"globs"`
}

type fileExecutable struct {
Globs []string `yaml:"globs" json:"globs" mapstructure:"globs"`
}

func defaultFileConfig() fileConfig {
return fileConfig{
Metadata: fileMetadata{
Expand All @@ -31,6 +36,9 @@ func defaultFileConfig() fileConfig {
Content: fileContent{
SkipFilesAboveSize: 250 * intFile.KB,
},
Executable: fileExecutable{
Globs: nil,
},
}
}

Expand Down
22 changes: 22 additions & 0 deletions internal/task/file_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto"
"fmt"
"github.com/anchore/syft/syft/file/cataloger/executable"

"github.com/anchore/syft/internal/sbomsync"
"github.com/anchore/syft/syft/artifact"
Expand Down Expand Up @@ -100,6 +101,27 @@ func NewFileContentCatalogerTask(cfg filecontent.Config) Task {
return NewTask("file-content-cataloger", fn)
}

func NewExecutableCatalogerTask(cfg executable.Config) Task {
cat := executable.NewCataloger(cfg)

fn := func(ctx context.Context, resolver file.Resolver, builder sbomsync.Builder) error {
accessor := builder.(sbomsync.Accessor)

result, err := cat.Catalog(resolver)
if err != nil {
return err
}

accessor.WriteToSBOM(func(sbom *sbom.SBOM) {
sbom.Artifacts.Executables = result
})

return nil
}

return NewTask("file-executable-cataloger", fn)
}

// TODO: this should be replaced with a fix that allows passing a coordinate or location iterator to the cataloger
// Today internal to both cataloger this functions differently: a slice of coordinates vs a channel of locations
func coordinatesForSelection(selection file.Selection, accessor sbomsync.Accessor) ([]file.Coordinates, bool) {
Expand Down
15 changes: 9 additions & 6 deletions syft/cataloging/filecataloging/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto"
"encoding/json"
"fmt"
"github.com/anchore/syft/syft/file/cataloger/executable"
"strings"

intFile "github.com/anchore/syft/internal/file"
Expand All @@ -13,9 +14,10 @@ import (
)

type Config struct {
Selection file.Selection `yaml:"selection" json:"selection" mapstructure:"selection"`
Hashers []crypto.Hash `yaml:"hashers" json:"hashers" mapstructure:"hashers"`
Content filecontent.Config `yaml:"content" json:"content" mapstructure:"content"`
Selection file.Selection `yaml:"selection" json:"selection" mapstructure:"selection"`
Hashers []crypto.Hash `yaml:"hashers" json:"hashers" mapstructure:"hashers"`
Content filecontent.Config `yaml:"content" json:"content" mapstructure:"content"`
Executable executable.Config `yaml:"executable" json:"executable" mapstructure:"executable"`
}

type configMarshaledForm struct {
Expand All @@ -30,9 +32,10 @@ func DefaultConfig() Config {
log.WithFields("error", err).Warn("unable to create file hashers")
}
return Config{
Selection: file.FilesOwnedByPackageSelection,
Hashers: hashers,
Content: filecontent.DefaultConfig(),
Selection: file.FilesOwnedByPackageSelection,
Hashers: hashers,
Content: filecontent.DefaultConfig(),
Executable: executable.DefaultConfig(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions syft/create_sbom_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func (c *CreateSBOMConfig) fileTasks() []task.Task {
if t := task.NewFileContentCatalogerTask(c.Files.Content); t != nil {
tsks = append(tsks, t)
}
if t := task.NewExecutableCatalogerTask(c.Files.Executable); t != nil {
tsks = append(tsks, t)
}

return tsks
}
Expand Down
Loading

0 comments on commit 8bce64f

Please # to comment.