Skip to content

Commit 6cc56db

Browse files
committed
add sbom flags on server side for podman-remote
1 parent 36ba42e commit 6cc56db

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

pkg/api/handlers/compat/images_build.go

+41
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"
@@ -171,6 +172,13 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
171172
UnsetEnvs []string `schema:"unsetenv"`
172173
UnsetLabels []string `schema:"unsetlabel"`
173174
Volumes []string `schema:"volume"`
175+
SBOMOutput string `schema:"sbom-output"`
176+
SBOMPURLOutput string `schema:"sbom-purl-output"`
177+
ImageSBOMOutput string `schema:"sbom-image-output"`
178+
ImageSBOMPURLOutput string `schema:"sbom-image-purl-output"`
179+
ImageSBOM string `schema:"sbom-scanner-image"`
180+
SBOMCommands []string `schema:"sbom-scanner-command"`
181+
SBOMMergeStrategy string `schema:"sbom-merge-strategy"`
174182
}{
175183
Dockerfile: "Dockerfile",
176184
IdentityLabel: true,
@@ -693,6 +701,38 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
693701
}
694702
}
695703

704+
var sbomScanOptions []buildahDefine.SBOMScanOptions
705+
if query.ImageSBOM != "" ||
706+
query.SBOMOutput != "" ||
707+
query.ImageSBOMOutput != "" ||
708+
query.SBOMPURLOutput != "" ||
709+
query.ImageSBOMPURLOutput != "" ||
710+
len(query.SBOMCommands) > 0 ||
711+
query.SBOMMergeStrategy != "" {
712+
sbomScanOption := &buildahDefine.SBOMScanOptions{
713+
SBOMOutput: query.SBOMOutput,
714+
PURLOutput: query.SBOMPURLOutput,
715+
ImageSBOMOutput: query.ImageSBOMOutput,
716+
ImagePURLOutput: query.ImageSBOMPURLOutput,
717+
Image: query.ImageSBOM,
718+
Commands: query.SBOMCommands,
719+
MergeStrategy: buildahDefine.SBOMMergeStrategy(query.SBOMMergeStrategy),
720+
PullPolicy: pullPolicy,
721+
}
722+
723+
if !slices.Contains(sbomScanOption.ContextDir, contextDirectory) {
724+
sbomScanOption.ContextDir = append(sbomScanOption.ContextDir, contextDirectory)
725+
}
726+
727+
for _, abc := range additionalBuildContexts {
728+
if !abc.IsURL && !abc.IsImage {
729+
sbomScanOption.ContextDir = append(sbomScanOption.ContextDir, abc.Value)
730+
}
731+
}
732+
733+
sbomScanOptions = append(sbomScanOptions, *sbomScanOption)
734+
}
735+
696736
buildOptions := buildahDefine.BuildOptions{
697737
AddCapabilities: addCaps,
698738
AdditionalBuildContexts: additionalBuildContexts,
@@ -772,6 +812,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
772812
Target: query.Target,
773813
UnsetEnvs: query.UnsetEnvs,
774814
UnsetLabels: query.UnsetLabels,
815+
SBOMScanOptions: sbomScanOptions,
775816
}
776817

777818
platforms := query.Platform

pkg/bindings/images/build.go

+36
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,42 @@ func Build(ctx context.Context, containerFiles []string, options types.BuildOpti
483483
stdout = options.Out
484484
}
485485

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

0 commit comments

Comments
 (0)