Skip to content

Commit f9c7800

Browse files
committed
add sbom flags on server side for podman-remote
Signed-off-by: Alex Guidi <[email protected]>
1 parent 0a5530d commit f9c7800

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

pkg/api/handlers/compat/images_build.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"os"
1313
"path/filepath"
14+
"slices"
1415
"strconv"
1516
"strings"
1617
"syscall"
@@ -172,6 +173,13 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
172173
UnsetEnvs []string `schema:"unsetenv"`
173174
UnsetLabels []string `schema:"unsetlabel"`
174175
Volumes []string `schema:"volume"`
176+
SBOMOutput string `schema:"sbom-output"`
177+
SBOMPURLOutput string `schema:"sbom-purl-output"`
178+
ImageSBOMOutput string `schema:"sbom-image-output"`
179+
ImageSBOMPURLOutput string `schema:"sbom-image-purl-output"`
180+
ImageSBOM string `schema:"sbom-scanner-image"`
181+
SBOMCommands string `schema:"sbom-scanner-command"`
182+
SBOMMergeStrategy string `schema:"sbom-merge-strategy"`
175183
}{
176184
Dockerfile: "Dockerfile",
177185
IdentityLabel: true,
@@ -694,6 +702,46 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
694702
}
695703
}
696704

705+
var sbomScanOptions []buildahDefine.SBOMScanOptions
706+
if query.ImageSBOM != "" ||
707+
query.SBOMOutput != "" ||
708+
query.ImageSBOMOutput != "" ||
709+
query.SBOMPURLOutput != "" ||
710+
query.ImageSBOMPURLOutput != "" ||
711+
query.SBOMCommands != "" ||
712+
query.SBOMMergeStrategy != "" {
713+
sbomScanOption := &buildahDefine.SBOMScanOptions{
714+
SBOMOutput: query.SBOMOutput,
715+
PURLOutput: query.SBOMPURLOutput,
716+
ImageSBOMOutput: query.ImageSBOMOutput,
717+
ImagePURLOutput: query.ImageSBOMPURLOutput,
718+
Image: query.ImageSBOM,
719+
MergeStrategy: buildahDefine.SBOMMergeStrategy(query.SBOMMergeStrategy),
720+
PullPolicy: pullPolicy,
721+
}
722+
723+
if _, found := r.URL.Query()["sbom-scanner-command"]; found {
724+
var m = []string{}
725+
if err := json.Unmarshal([]byte(query.SBOMCommands), &m); err != nil {
726+
utils.BadRequest(w, "sbom-scanner-command", query.SBOMCommands, err)
727+
return
728+
}
729+
sbomScanOption.Commands = m
730+
}
731+
732+
if !slices.Contains(sbomScanOption.ContextDir, contextDirectory) {
733+
sbomScanOption.ContextDir = append(sbomScanOption.ContextDir, contextDirectory)
734+
}
735+
736+
for _, abc := range additionalBuildContexts {
737+
if !abc.IsURL && !abc.IsImage {
738+
sbomScanOption.ContextDir = append(sbomScanOption.ContextDir, abc.Value)
739+
}
740+
}
741+
742+
sbomScanOptions = append(sbomScanOptions, *sbomScanOption)
743+
}
744+
697745
buildOptions := buildahDefine.BuildOptions{
698746
AddCapabilities: addCaps,
699747
AdditionalBuildContexts: additionalBuildContexts,
@@ -774,6 +822,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
774822
Target: query.Target,
775823
UnsetEnvs: query.UnsetEnvs,
776824
UnsetLabels: query.UnsetLabels,
825+
SBOMScanOptions: sbomScanOptions,
777826
}
778827

779828
platforms := query.Platform

pkg/bindings/images/build.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,42 @@ func Build(ctx context.Context, containerFiles []string, options types.BuildOpti
489489
stdout = options.Out
490490
}
491491

492+
if len(options.SBOMScanOptions) > 0 {
493+
for _, sbomScanOpts := range options.SBOMScanOptions {
494+
if sbomScanOpts.SBOMOutput != "" {
495+
params.Set("sbom-output", sbomScanOpts.SBOMOutput)
496+
}
497+
498+
if sbomScanOpts.PURLOutput != "" {
499+
params.Set("sbom-purl-output", sbomScanOpts.PURLOutput)
500+
}
501+
502+
if sbomScanOpts.ImageSBOMOutput != "" {
503+
params.Set("sbom-image-output", sbomScanOpts.ImageSBOMOutput)
504+
}
505+
506+
if sbomScanOpts.ImagePURLOutput != "" {
507+
params.Set("sbom-image-purl-output", sbomScanOpts.ImagePURLOutput)
508+
}
509+
510+
if sbomScanOpts.Image != "" {
511+
params.Set("sbom-scanner-image", sbomScanOpts.Image)
512+
}
513+
514+
if commands := sbomScanOpts.Commands; len(commands) > 0 {
515+
c, err := jsoniter.MarshalToString(commands)
516+
if err != nil {
517+
return nil, err
518+
}
519+
params.Add("sbom-scanner-command", c)
520+
}
521+
522+
if sbomScanOpts.MergeStrategy != "" {
523+
params.Set("sbom-merge-strategy", string(sbomScanOpts.MergeStrategy))
524+
}
525+
}
526+
}
527+
492528
contextDir, err = filepath.Abs(options.ContextDirectory)
493529
if err != nil {
494530
logrus.Errorf("Cannot find absolute path of %v: %v", options.ContextDirectory, err)

0 commit comments

Comments
 (0)