Skip to content

Commit

Permalink
cli: derive runtime class name from launch digest
Browse files Browse the repository at this point in the history
  • Loading branch information
davidweisse committed Jun 24, 2024
1 parent 1b6ea63 commit f75335c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
5 changes: 5 additions & 0 deletions cli/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"context"
_ "embed"
"fmt"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -43,6 +44,10 @@ var (
DefaultCoordinatorPolicyHash = ""
)

func runtimeHandler(digest string) string {
return fmt.Sprintf("contrast-cc-%s", digest[:32])
}

func cachedir(subdir string) (string, error) {
dir := os.Getenv(cacheDirEnv)
if dir == "" {
Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,14 @@ func injectServiceMesh(resources []any) error {
}

func runtimeClassNamePatcher() func(*applycorev1.PodSpecApplyConfiguration) *applycorev1.PodSpecApplyConfiguration {
handler := runtimeHandler(manifest.TrustedMeasurement)
return func(spec *applycorev1.PodSpecApplyConfiguration) *applycorev1.PodSpecApplyConfiguration {
if spec.RuntimeClassName == nil || *spec.RuntimeClassName == runtimeHandler {
if spec.RuntimeClassName == nil || *spec.RuntimeClassName == handler {
return spec
}

if strings.HasPrefix(*spec.RuntimeClassName, "contrast-cc") || *spec.RuntimeClassName == "kata-cc-isolation" {
spec.RuntimeClassName = &runtimeHandler
spec.RuntimeClassName = &handler
}
return spec
}
Expand Down
6 changes: 2 additions & 4 deletions cli/cmd/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
package cmd

import (
"github.com/edgelesssys/contrast/internal/manifest"
"github.com/spf13/cobra"
)

// This value is injected at build time.
var runtimeHandler = "contrast-cc"

// NewRuntimeCmd creates the contrast runtime subcommand.
func NewRuntimeCmd() *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -28,5 +26,5 @@ have the runtimeClassName set to the value returned by this command.
}

func runRuntime(cmd *cobra.Command, _ []string) {
cmd.Println(runtimeHandler)
cmd.Println(runtimeHandler(manifest.TrustedMeasurement))
}
7 changes: 3 additions & 4 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"text/tabwriter"

"github.com/edgelesssys/contrast/cli/cmd"
"github.com/edgelesssys/contrast/internal/manifest"
"github.com/spf13/cobra"
)

Expand All @@ -30,8 +31,6 @@ func execute() error {

var (
version = "0.0.0-dev"
runtimeHandler = "contrast-cc"
launchDigest = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
genpolicyVersion = "0.0.0-dev"
)

Expand All @@ -40,8 +39,8 @@ func newRootCmd() *cobra.Command {
var versionsBuilder strings.Builder
versionsWriter := tabwriter.NewWriter(&versionsBuilder, 0, 0, 4, ' ', 0)
fmt.Fprintf(versionsWriter, "%s\n\n", version)
fmt.Fprintf(versionsWriter, "\truntime handler:\t%s\n", runtimeHandler)
fmt.Fprintf(versionsWriter, "\tlaunch digest:\t%s\n", launchDigest)
fmt.Fprintf(versionsWriter, "\truntime handler:\tcontrast-cc-%s\n", manifest.TrustedMeasurement[:32])
fmt.Fprintf(versionsWriter, "\tlaunch digest:\t%s\n", manifest.TrustedMeasurement)
fmt.Fprintf(versionsWriter, "\tgenpolicy version:\t%s\n", genpolicyVersion)
fmt.Fprintf(versionsWriter, "\timage versions:\n")
imageReplacements := strings.Trim(string(cmd.ReleaseImageReplacements), "\n")
Expand Down
4 changes: 2 additions & 2 deletions internal/manifest/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package manifest

// This value is injected at build time.
var trustedMeasurement = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
var TrustedMeasurement = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

// Default returns a default manifest.
func Default() Manifest {
Expand All @@ -18,7 +18,7 @@ func Default() Manifest {
MicrocodeVersion: 115,
},
},
TrustedMeasurement: HexString(trustedMeasurement),
TrustedMeasurement: HexString(TrustedMeasurement),
},
}
}
4 changes: 0 additions & 4 deletions packages/by-name/contrast/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ let
ldflags = [
"-s"
"-X github.com/edgelesssys/contrast/internal/manifest.trustedMeasurement=${launchDigest}"
"-X github.com/edgelesssys/contrast/cli/cmd.runtimeHandler=${runtimeHandler}"
"-X github.com/edgelesssys/contrast/internal/kuberesource.runtimeHandler=${runtimeHandler}"
];

Expand Down Expand Up @@ -78,11 +77,8 @@ buildGoModule rec {
"-s"
"-w"
"-X main.version=v${version}"
"-X main.runtimeHandler=${runtimeHandler}"
"-X main.launchDigest=${launchDigest}"
"-X main.genpolicyVersion=${genpolicy.version}"
"-X github.com/edgelesssys/contrast/internal/manifest.trustedMeasurement=${launchDigest}"
"-X github.com/edgelesssys/contrast/cli/cmd.runtimeHandler=${runtimeHandler}"
"-X github.com/edgelesssys/contrast/internal/kuberesource.runtimeHandler=${runtimeHandler}"
];

Expand Down

0 comments on commit f75335c

Please sign in to comment.