Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding metadata prefix option to signing #15

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/providers/scanner/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
"log"
"os"
"strings"
"time"
)

Expand Down Expand Up @@ -131,8 +132,12 @@ func (s *OpenStackScannerClient) CheckResults() error {
}

// TagImage Tags the image with the passed or failed property.
func (s *OpenStackScannerClient) TagImage() error {
err := s.imageClient.TagImage(s.Img.Properties, s.Img.ID, s.MetaTag, "security_scan")
func (s *OpenStackScannerClient) TagImage(metadataPrefix string) error {
tag := "security_scan"
if metadataPrefix != "" {
tag = strings.Join([]string{metadataPrefix, tag}, ":")
}
err := s.imageClient.TagImage(s.Img.Properties, s.Img.ID, s.MetaTag, tag)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/providers/scanner/openstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func TestCheckResults(t *testing.T) {
}

func TestTagImage(t *testing.T) {

//c := mock.MockOpenStackComputeClient{}
//i := mock.MockOpenStackImageClient{}
//n := mock.MockOpenStackNetworkClient{}
//ss3 := mock.MockS3Interface{}
//s := NewOpenStackScanner(&c, &i, &n, ss3, trivy.HIGH, &images.Image{})
}

func TestUploadResultsToS3(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/provisoner/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ func (s *OpenStackScanProvisioner) Prepare() error {
var err error
o := s.Opts

o.OpenStackFlags.FlavorName = o.FlavorName
if o.ScanFlavorName != "" {
o.OpenStackFlags.FlavorName = o.ScanFlavorName
}

cloudProvider := ostack.NewCloudsProvider(o.OpenStackFlags.CloudName)

Expand Down Expand Up @@ -302,7 +304,7 @@ func (s *OpenStackScanProvisioner) scanServer(sc *scanner.OpenStackScannerClient

// If the image is not set to auto delete, tag the image with the check result.
if !o.AutoDeleteImage {
err = sc.TagImage()
err = sc.TagImage(s.Opts.OpenStackCoreFlags.MetadataPrefix)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/flags/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ScanOptions struct {
ScanSingleOptions
ScanMultipleOptions

ScanFlavorName string
AutoDeleteImage bool
SkipCVECheck bool
MaxSeverityScore float64
Expand Down Expand Up @@ -66,6 +67,7 @@ func (o *ScanOptions) SetOptionsFromViper() {
}

func (o *ScanOptions) AddFlags(cmd *cobra.Command) {
StringVarWithViper(cmd, &o.ScanFlavorName, viperScanPrefix, "flavor-name", "", "--DEPRECATED-- USE THE CONFIG FILE. The flavor to use for the scan. This overrides the one supplied by the openstack config.")
BoolVarWithViper(cmd, &o.AutoDeleteImage, viperScanPrefix, "auto-delete-image", false, "--DEPRECATED-- USE THE CONFIG FILE. If true, the image will be deleted if a vulnerability check does not succeed - recommended when building new images.")
BoolVarWithViper(cmd, &o.SkipCVECheck, viperScanPrefix, "skip-cve-check", false, "--DEPRECATED-- USE THE CONFIG FILE. If true, the image will be allowed even if a vulnerability is detected.")
Float64VarWithViper(cmd, &o.MaxSeverityScore, viperScanPrefix, "max-severity-score", 7.0, "--DEPRECATED-- USE THE CONFIG FILE. Can be anything from 0.1 to 10.0. Anything equal to or above this value will cause a failure. (Unless skip-cve-check is supplied)")
Expand Down
Loading