-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[13501] Continue security scanning but highlight missing images (#524)
* [13501] Continue scanning but highlight missing images * Add changelog * Test update for expected error * Remove extra addition to markdown * Re-order imports * Only add debug instructions once * Changelog to v0.24.9 * Fix issue link in changelog * Rename param to something more generic * Update comment * Add missing image to test suite * Fix Apply in predicate; add additional test cases * Add ability to output would-be github issues to local files * s/ioutil/os for ReadFile * Extract to fileutils * Revert exported function signature; unexport error * Recoverable and Unrecoverable errors * Move directory setup higher in call chain * Callout scanning pre-releases in Changelog * Refactor to IssueWriter interface * Reformat imports * Empty; trigger tests * Clarifying GetPrerelease in predicate * Update predicate_test * Add comments; update interface assertion var name * Unfocus test * Add unit tests for Unrecoverable vs Recoverable errors * Update comment; remove unused struct field * Remove param from function call * resolvesIssue: false in changelog * Update changelog description * Add DescribeTable entry back * More accurate log line
- Loading branch information
Showing
16 changed files
with
309 additions
and
45 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
changelog/v0.25.0/13501-report-missing-images-in-scan.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
changelog: | ||
- type: NEW_FEATURE | ||
issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/13499 | ||
description: > | ||
Scanner includes an optional Additional Context section on reported vulnerabilities. | ||
resolvesIssue: false | ||
- type: BREAKING_CHANGE | ||
issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/13499 | ||
description: > | ||
Create `IssueWriter` interface with implementations as `NoopWriter`, `GithubIssueWriter`, and `LocalIssueWriter`. | ||
resolvesIssue: false | ||
- type: FIX | ||
issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/13501 | ||
description: > | ||
Scanner continues to scan remaining images if one image cannot be found. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package fileutils | ||
|
||
import "os" | ||
|
||
func ReadFileString(filename string) (string, error) { | ||
contents, err := os.ReadFile(filename) | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(contents), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package issuewriter | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/go-github/v32/github" | ||
) | ||
|
||
// IssueWriter writes the generated contents of a scan to a location, either a file on the local filesystem | ||
// or a GitHub issue. | ||
type IssueWriter interface { | ||
// Write writes `contents`, the results of a scan of the images in `release`, to a location | ||
// designated by the implementation. | ||
Write(ctx context.Context, release *github.RepositoryRelease, contents string) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package issuewriter | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
"github.com/google/go-github/v32/github" | ||
) | ||
|
||
// LocalIssueWriter writes the scan results to a file on the local file system. | ||
type LocalIssueWriter struct { | ||
// The directory in which to create files | ||
outputDir string | ||
} | ||
|
||
var _ IssueWriter = &LocalIssueWriter{} | ||
|
||
func NewLocalIssueWriter(outputDir string) (IssueWriter, error) { | ||
// Set up the directory structure for local output | ||
err := os.MkdirAll(outputDir, os.ModePerm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &LocalIssueWriter{ | ||
outputDir: outputDir, | ||
}, nil | ||
} | ||
|
||
func (l *LocalIssueWriter) Write(_ context.Context, release *github.RepositoryRelease, contents string) error { | ||
version, err := semver.NewVersion(release.GetTagName()) | ||
if err != nil { | ||
return err | ||
} | ||
filename := path.Join(l.outputDir, version.String()+".md") | ||
f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = fmt.Fprintf(f, contents) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package issuewriter | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/go-github/v32/github" | ||
) | ||
|
||
// NoopWriter provides a no-op implementation of the IssueWriter interface, used when the | ||
// specified scan action is `none`. | ||
type NoopWriter struct{} | ||
|
||
var _ IssueWriter = &NoopWriter{} | ||
|
||
func NewNoopWriter() IssueWriter { | ||
return &NoopWriter{} | ||
} | ||
|
||
func (n *NoopWriter) Write(_ context.Context, _ *github.RepositoryRelease, _ string) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.