Skip to content

Commit

Permalink
Merge pull request containers#5159 from nalind/case-insensitive-tee-t…
Browse files Browse the repository at this point in the history
…ypes

Make TEE types case-insensitive
  • Loading branch information
openshift-merge-bot[bot] authored Nov 16, 2023
2 parents 12acfaf + 4f3876d commit e2c8519
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 1 addition & 2 deletions cmd/buildah/mkcw.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"

"github.com/containers/buildah"
"github.com/containers/buildah/define"
"github.com/containers/buildah/pkg/parse"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -46,7 +45,7 @@ func init() {
Short: "Convert a conventional image to a confidential workload image",
Long: mkcwDescription,
RunE: func(cmd *cobra.Command, args []string) error {
options.TeeType = define.TeeType(teeType)
options.TeeType = parse.TeeType(teeType)
return mkcwCmd(cmd, args, options)
},
Example: `buildah mkcw localhost/repository:typical localhost/repository:cw`,
Expand Down
2 changes: 1 addition & 1 deletion internal/tmpdir/tmpdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
)

// GetTempDir returns base for a temporary directory on host.
// GetTempDir returns the path of the preferred temporary directory on the host.
func GetTempDir() string {
if tmpdir, ok := os.LookupEnv("TMPDIR"); ok {
abs, err := filepath.Abs(tmpdir)
Expand Down
8 changes: 7 additions & 1 deletion pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ func GetBuildOutput(buildOutput string) (define.BuildOutputOption, error) {
return define.BuildOutputOption{Path: path, IsDir: isDir, IsStdout: isStdout}, nil
}

// TeeType parses a string value and returns a TeeType
func TeeType(teeType string) define.TeeType {
return define.TeeType(strings.ToLower(teeType))
}

// GetConfidentialWorkloadOptions parses a confidential workload settings
// argument, which controls both whether or not we produce an image that
// expects to be run using krun, and how we handle things like encrypting
Expand All @@ -647,7 +652,7 @@ func GetConfidentialWorkloadOptions(arg string) (define.ConfidentialWorkloadOpti
var err error
switch {
case strings.HasPrefix(option, "type="):
options.TeeType = define.TeeType(strings.ToLower(strings.TrimPrefix(option, "type=")))
options.TeeType = TeeType(strings.TrimPrefix(option, "type="))
switch options.TeeType {
case define.SEV, define.SNP, mkcwtypes.SEV_NO_ES:
default:
Expand Down Expand Up @@ -1065,6 +1070,7 @@ func isValidDeviceMode(mode string) bool {
return true
}

// GetTempDir returns the path of the preferred temporary directory on the host.
func GetTempDir() string {
return tmpdir.GetTempDir()
}
Expand Down
8 changes: 7 additions & 1 deletion tests/mkcw.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ function mkcw_check_image() {
_prefetch busybox

echo -n mkcw-convert > "$TEST_SCRATCH_DIR"/key
run_buildah mkcw --ignore-attestation-errors --passphrase=mkcw-convert busybox busybox-cw
run_buildah mkcw --ignore-attestation-errors --type snp --passphrase=mkcw-convert busybox busybox-cw
mkcw_check_image busybox-cw
run_buildah mkcw --ignore-attestation-errors --type SNP --passphrase=mkcw-convert busybox busybox-cw
mkcw_check_image busybox-cw
}

Expand All @@ -66,6 +68,8 @@ function mkcw_check_image() {
ctrID="$output"
run_buildah commit --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=SEV,ignore_attestation_errors,passphrase="mkcw commit" "$ctrID"
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)
run_buildah commit --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=sev,ignore_attestation_errors,passphrase="mkcw commit" "$ctrID"
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)
}

@test "mkcw build" {
Expand All @@ -79,4 +83,6 @@ function mkcw_check_image() {
echo -n "mkcw build" > "$TEST_SCRATCH_DIR"/key
run_buildah build --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=SEV,ignore_attestation_errors,passphrase="mkcw build" -f bud/env/Dockerfile.check-env bud/env
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)
run_buildah build --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=sev,ignore_attestation_errors,passphrase="mkcw build" -f bud/env/Dockerfile.check-env bud/env
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)
}

0 comments on commit e2c8519

Please sign in to comment.