Skip to content

Commit

Permalink
Un-break system safety tests on Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
NullHypothesis committed Oct 12, 2024
1 parent 55908f0 commit 6795cbe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Binary file added cmd/.main_test.go.swp
Binary file not shown.
6 changes: 3 additions & 3 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestPages(t *testing.T) {
}

func TestReadyHandler(t *testing.T) {
defer stopSvc(startSvc(t, []string{"-wait-for-app"}))
defer stopSvc(startSvc(t, []string{"-insecure", "-wait-for-app"}))

cases := []struct {
name string
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestAttestation(t *testing.T) {
}

func TestHashes(t *testing.T) {
defer stopSvc(startSvc(t, []string{}))
defer stopSvc(startSvc(t, []string{"-insecure"}))

var (
hashes = new(attestation.Hashes)
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestReverseProxy(t *testing.T) {
},
))
defer srv.Close()
defer stopSvc(startSvc(t, []string{"-app-web-srv", srv.URL}))
defer stopSvc(startSvc(t, []string{"-insecure", "-app-web-srv", srv.URL}))

cases := []struct {
name string
Expand Down
21 changes: 18 additions & 3 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"
"errors"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -31,9 +32,9 @@ func Run(
appReady = make(chan struct{})
)

// Perform basic safety checks before starting.
if !system.HasSecureRNG() {
log.Fatal("Nitro hardware RNG is not in use.")
// Run basic safety checks before starting.
if err := checkSystemSafety(config); err != nil {
log.Fatalf("Failed safety check: %v", err)
}

// Initialize the enclave keys for enclave synchronization.
Expand All @@ -59,6 +60,20 @@ func Run(
log.Println("Exiting.")
}

func checkSystemSafety(config *config.Config) error {
if config.EnableTesting {
return nil
}

if !system.HasSecureRNG() {
return errors.New("system does not use desired RNG")
}
if !system.HasSecureKernelVersion() {
return errors.New("system does not have minimum desired kernel version")
}
return nil
}

func startAllWebSrvs(
ctx context.Context,
waitForApp bool,
Expand Down
Binary file added internal/system/.system_linux.go.swp
Binary file not shown.

0 comments on commit 6795cbe

Please sign in to comment.