Skip to content

Commit 0cbe852

Browse files
Merge pull request #4960 from nalind/mkcw
Produce confidential workload images
2 parents 25473ec + 4f3abf9 commit 0cbe852

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+8872
-20
lines changed

Makefile

+15-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ LIBSECCOMP_COMMIT := release-2.3
3939

4040
EXTRA_LDFLAGS ?=
4141
BUILDAH_LDFLAGS := $(GO_LDFLAGS) '-X main.GitCommit=$(GIT_COMMIT) -X main.buildInfo=$(SOURCE_DATE_EPOCH) -X main.cniVersion=$(CNI_COMMIT) $(EXTRA_LDFLAGS)'
42-
SOURCES=*.go imagebuildah/*.go bind/*.go chroot/*.go copier/*.go define/*.go docker/*.go internal/parse/*.go internal/source/*.go internal/util/*.go manifests/*.go pkg/chrootuser/*.go pkg/cli/*.go pkg/completion/*.go pkg/formats/*.go pkg/overlay/*.go pkg/parse/*.go pkg/rusage/*.go pkg/sshagent/*.go pkg/umask/*.go pkg/util/*.go util/*.go
42+
SOURCES=*.go imagebuildah/*.go bind/*.go chroot/*.go copier/*.go define/*.go docker/*.go internal/mkcw/*.go internal/mkcw/types/*.go internal/parse/*.go internal/source/*.go internal/util/*.go manifests/*.go pkg/chrootuser/*.go pkg/cli/*.go pkg/completion/*.go pkg/formats/*.go pkg/overlay/*.go pkg/parse/*.go pkg/rusage/*.go pkg/sshagent/*.go pkg/umask/*.go pkg/util/*.go util/*.go
4343

4444
LINTFLAGS ?=
4545

@@ -69,9 +69,22 @@ static:
6969
mkdir -p ./bin
7070
cp -rfp ./result/bin/* ./bin/
7171

72-
bin/buildah: $(SOURCES) cmd/buildah/*.go
72+
bin/buildah: $(SOURCES) cmd/buildah/*.go internal/mkcw/embed/entrypoint.gz
7373
$(GO_BUILD) $(BUILDAH_LDFLAGS) $(GO_GCFLAGS) "$(GOGCFLAGS)" -o $@ $(BUILDFLAGS) ./cmd/buildah
7474

75+
ifneq ($(shell as --version | grep x86_64),)
76+
internal/mkcw/embed/entrypoint: internal/mkcw/embed/entrypoint.s
77+
$(AS) -o $(patsubst %.s,%.o,$^) $^
78+
$(LD) -o $@ $(patsubst %.s,%.o,$^)
79+
strip $@
80+
else
81+
.PHONY: internal/mkcw/embed/entrypoint
82+
endif
83+
84+
internal/mkcw/embed/entrypoint.gz: internal/mkcw/embed/entrypoint
85+
$(RM) $@
86+
gzip -k $^
87+
7588
.PHONY: buildah
7689
buildah: bin/buildah
7790

buildah.go

+5
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,11 @@ type ImportFromImageOptions struct {
386386
SystemContext *types.SystemContext
387387
}
388388

389+
// ConfidentialWorkloadOptions encapsulates options which control whether or not
390+
// we output an image whose rootfs contains a LUKS-compatibly-encrypted disk image
391+
// instead of the usual rootfs contents.
392+
type ConfidentialWorkloadOptions = define.ConfidentialWorkloadOptions
393+
389394
// NewBuilder creates a new build container.
390395
func NewBuilder(ctx context.Context, store storage.Store, options BuilderOptions) (*Builder, error) {
391396
if options.CommonBuildOpts == nil {

buildah_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ import (
1414
)
1515

1616
func TestMain(m *testing.M) {
17+
var logLevel string
1718
debug := false
1819
if InitReexec() {
1920
return
2021
}
2122
flag.BoolVar(&debug, "debug", false, "turn on debug logging")
23+
flag.StringVar(&logLevel, "log-level", "error", "log level")
2224
flag.Parse()
23-
logrus.SetLevel(logrus.ErrorLevel)
24-
if debug {
25-
logrus.SetLevel(logrus.DebugLevel)
25+
level, err := logrus.ParseLevel(logLevel)
26+
if err != nil {
27+
logrus.Fatalf("error parsing log level %q: %v", logLevel, err)
2628
}
29+
if debug && level < logrus.DebugLevel {
30+
level = logrus.DebugLevel
31+
}
32+
logrus.SetLevel(level)
2733
os.Exit(m.Run())
2834
}
2935

cmd/buildah/commit.go

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type commitInputOptions struct {
2727
blobCache string
2828
certDir string
2929
creds string
30+
cwOptions string
3031
disableCompression bool
3132
format string
3233
iidfile string
@@ -87,6 +88,7 @@ func commitListFlagSet(cmd *cobra.Command, opts *commitInputOptions) {
8788
_ = cmd.RegisterFlagCompletionFunc("cert-dir", completion.AutocompleteDefault)
8889
flags.StringVar(&opts.creds, "creds", "", "use `[username[:password]]` for accessing the registry")
8990
_ = cmd.RegisterFlagCompletionFunc("creds", completion.AutocompleteNone)
91+
flags.StringVar(&opts.cwOptions, "cw", "", "confidential workload `options`")
9092
flags.BoolVarP(&opts.disableCompression, "disable-compression", "D", true, "don't compress layers")
9193
flags.StringVarP(&opts.format, "format", "f", defaultFormat(), "`format` of the image manifest and metadata")
9294
_ = cmd.RegisterFlagCompletionFunc("format", completion.AutocompleteNone)
@@ -239,6 +241,14 @@ func commitCmd(c *cobra.Command, args []string, iopts commitInputOptions) error
239241
options.HistoryTimestamp = &timestamp
240242
}
241243

244+
if iopts.cwOptions != "" {
245+
confidentialWorkloadOptions, err := parse.GetConfidentialWorkloadOptions(iopts.cwOptions)
246+
if err != nil {
247+
return fmt.Errorf("parsing --cw arguments: %w", err)
248+
}
249+
options.ConfidentialWorkloadOptions = confidentialWorkloadOptions
250+
}
251+
242252
if exclusiveFlags > 1 {
243253
return errors.New("can not use more then one timestamp option at at time")
244254
}

cmd/buildah/common.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ func Tail(a []string) []string {
224224
return []string{}
225225
}
226226

227-
// UsageTemplate returns the usage template for podman commands
228-
// This blocks the displaying of the global options. The main podman
227+
// UsageTemplate returns the usage template for buildah commands
228+
// This blocks the displaying of the global options. The main buildah
229229
// command should not use this.
230230
func UsageTemplate() string {
231231
return `Usage:{{if .Runnable}}

cmd/buildah/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func init() {
104104
rootCmd.PersistentFlags().StringSliceVar(&globalFlagResults.UserNSUID, "userns-uid-map", []string{}, "default `ctrID:hostID:length` UID mapping to use")
105105
rootCmd.PersistentFlags().StringSliceVar(&globalFlagResults.UserNSGID, "userns-gid-map", []string{}, "default `ctrID:hostID:length` GID mapping to use")
106106
rootCmd.PersistentFlags().StringVar(&globalFlagResults.DefaultMountsFile, "default-mounts-file", "", "path to default mounts file")
107-
rootCmd.PersistentFlags().StringVar(&globalFlagResults.LogLevel, logLevel, "warn", `The log level to be used. Either "trace", "debug", "info", "warn", "error", "fatal", or "panic".`)
107+
rootCmd.PersistentFlags().StringVar(&globalFlagResults.LogLevel, logLevel, "warn", `the log level to be used, one of "trace", "debug", "info", "warn", "error", "fatal", or "panic"`)
108108
rootCmd.PersistentFlags().StringVar(&globalFlagResults.CPUProfile, "cpu-profile", "", "`file` to write CPU profile")
109109
rootCmd.PersistentFlags().StringVar(&globalFlagResults.MemoryProfile, "memory-profile", "", "`file` to write memory profile")
110110

cmd/buildah/mkcw.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/containers/buildah"
8+
"github.com/containers/buildah/define"
9+
"github.com/containers/buildah/pkg/parse"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
func mkcwCmd(c *cobra.Command, args []string, options buildah.CWConvertImageOptions) error {
14+
ctx := getContext()
15+
16+
systemContext, err := parse.SystemContextFromOptions(c)
17+
if err != nil {
18+
return err
19+
}
20+
21+
if options.AttestationURL == "" && options.DiskEncryptionPassphrase == "" {
22+
return fmt.Errorf("neither --attestation-url nor --passphrase flags provided, disk would not be decryptable")
23+
}
24+
25+
store, err := getStore(c)
26+
if err != nil {
27+
return err
28+
}
29+
30+
options.InputImage = args[0]
31+
options.Tag = args[1]
32+
options.ReportWriter = os.Stderr
33+
imageID, _, _, err := buildah.CWConvertImage(ctx, systemContext, store, options)
34+
if err == nil {
35+
fmt.Printf("%s\n", imageID)
36+
}
37+
return err
38+
}
39+
40+
func init() {
41+
var teeType string
42+
var options buildah.CWConvertImageOptions
43+
mkcwDescription := `Convert a conventional image to a confidential workload image.`
44+
mkcwCommand := &cobra.Command{
45+
Use: "mkcw",
46+
Short: "Convert a conventional image to a confidential workload image",
47+
Long: mkcwDescription,
48+
RunE: func(cmd *cobra.Command, args []string) error {
49+
options.TeeType = define.TeeType(teeType)
50+
return mkcwCmd(cmd, args, options)
51+
},
52+
Example: `buildah mkcw localhost/repository:typical localhost/repository:cw`,
53+
Args: cobra.ExactArgs(2),
54+
}
55+
mkcwCommand.SetUsageTemplate(UsageTemplate())
56+
rootCmd.AddCommand(mkcwCommand)
57+
flags := mkcwCommand.Flags()
58+
flags.SetInterspersed(false)
59+
60+
flags.StringVarP(&teeType, "type", "t", "", "TEE (trusted execution environment) type: SEV,SNP (default: SNP)")
61+
flags.StringVarP(&options.AttestationURL, "attestation-url", "u", "", "attestation server URL")
62+
flags.StringVarP(&options.BaseImage, "base-image", "b", "", "alternate base image (default: scratch)")
63+
flags.StringVarP(&options.DiskEncryptionPassphrase, "passphrase", "p", "", "disk encryption passphrase")
64+
flags.IntVarP(&options.CPUs, "cpus", "c", 0, "number of CPUs to expect")
65+
flags.IntVarP(&options.Memory, "memory", "m", 0, "amount of memory to expect (MB)")
66+
flags.StringVarP(&options.WorkloadID, "workload-id", "w", "", "workload ID")
67+
flags.StringVarP(&options.Slop, "slop", "s", "25%", "extra space needed for converting a container rootfs to a disk image")
68+
flags.StringVarP(&options.FirmwareLibrary, "firmware-library", "f", "", "location of libkrunfw-sev.so")
69+
flags.BoolVarP(&options.IgnoreAttestationErrors, "ignore-attestation-errors", "", false, "ignore attestation errors")
70+
if err := flags.MarkHidden("ignore-attestation-errors"); err != nil {
71+
panic(fmt.Sprintf("error marking ignore-attestation-errors as hidden: %v", err))
72+
}
73+
flags.String("signature-policy", "", "`pathname` of signature policy file (not usually used)")
74+
if err := flags.MarkHidden("signature-policy"); err != nil {
75+
panic(fmt.Sprintf("error marking signature-policy as hidden: %v", err))
76+
}
77+
}

commit.go

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ type CommitOptions struct {
105105
// integers in the slice represent 0-indexed layer indices, with support for negative
106106
// indexing. i.e. 0 is the first layer, -1 is the last (top-most) layer.
107107
OciEncryptLayers *[]int
108+
// ConfidentialWorkloadOptions is used to force the output image's rootfs to contain a
109+
// LUKS-compatibly encrypted disk image (for use with krun) instead of the usual
110+
// contents of a rootfs.
111+
ConfidentialWorkloadOptions ConfidentialWorkloadOptions
108112
// UnsetEnvs is a list of environments to not add to final image.
109113
// Deprecated: use UnsetEnv() before committing instead.
110114
UnsetEnvs []string

0 commit comments

Comments
 (0)