|
| 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 | +} |
0 commit comments