mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 06:56:40 +01:00
Add secrets search capability (#367)
* add initial secrets cataloger Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update ETUI elements with new catalogers (file metadata, digests, and secrets) Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update secrets cataloger to read full contents into memory for searching Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * quick prototype of parallelization secret regex search Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * quick prototype with single aggregated regex Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * quick prototype for secret search line-by-line Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * quick prototype hybrid secrets search Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add secrets cataloger with line strategy Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * adjust verbiage towards SearchResults instead of Secrets + add tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update json schema with secrets cataloger results Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * address PR comments Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update readme with secrets config options Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * ensure file catalogers call AllLocations once Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
+12
-4
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/anchore/syft/internal"
|
||||
|
||||
@@ -97,13 +98,20 @@ func powerUserExecWorker(userInput string) <-chan error {
|
||||
ApplicationConfig: *appConfig,
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
for _, task := range tasks {
|
||||
if err = task(&analysisResults, src); err != nil {
|
||||
errs <- err
|
||||
return
|
||||
}
|
||||
wg.Add(1)
|
||||
go func(task powerUserTask) {
|
||||
defer wg.Done()
|
||||
if err = task(&analysisResults, src); err != nil {
|
||||
errs <- err
|
||||
return
|
||||
}
|
||||
}(task)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
bus.Publish(partybus.Event{
|
||||
Type: event.PresenterReady,
|
||||
Value: poweruser.NewJSONPresenter(analysisResults),
|
||||
|
||||
+35
-2
@@ -18,7 +18,8 @@ func powerUserTasks() ([]powerUserTask, error) {
|
||||
generators := []func() (powerUserTask, error){
|
||||
catalogPackagesTask,
|
||||
catalogFileMetadataTask,
|
||||
catalogFileDigestTask,
|
||||
catalogFileDigestsTask,
|
||||
catalogSecretsTask,
|
||||
}
|
||||
|
||||
for _, generator := range generators {
|
||||
@@ -78,7 +79,7 @@ func catalogFileMetadataTask() (powerUserTask, error) {
|
||||
return task, nil
|
||||
}
|
||||
|
||||
func catalogFileDigestTask() (powerUserTask, error) {
|
||||
func catalogFileDigestsTask() (powerUserTask, error) {
|
||||
if !appConfig.FileMetadata.Cataloger.Enabled {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -123,3 +124,35 @@ func catalogFileDigestTask() (powerUserTask, error) {
|
||||
|
||||
return task, nil
|
||||
}
|
||||
|
||||
func catalogSecretsTask() (powerUserTask, error) {
|
||||
if !appConfig.Secrets.Cataloger.Enabled {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
patterns, err := file.GenerateSearchPatterns(file.DefaultSecretsPatterns, appConfig.Secrets.AdditionalPatterns, appConfig.Secrets.ExcludePatternNames)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
secretsCataloger, err := file.NewSecretsCataloger(patterns, appConfig.Secrets.RevealValues, appConfig.Secrets.SkipFilesAboveSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
task := func(results *poweruser.JSONDocumentConfig, src source.Source) error {
|
||||
resolver, err := src.FileResolver(appConfig.Secrets.Cataloger.ScopeOpt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := secretsCataloger.Catalog(resolver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
results.Secrets = result
|
||||
return nil
|
||||
}
|
||||
|
||||
return task, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user