Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/cryptosctl/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,10 @@ func writeImageStatus(w io.Writer, s *nodev1.ImageStatus, format string) error {
}

_, err := fmt.Fprintf(w,
"Running version: %s\nRunning image: %s\nNext boot image: %s\nPrevious image: %s\nReboot pending: %s\n",
s.GetRunningVersion(), s.GetRunningSha256(), s.GetActiveSha256(), previous, pending)
"Running version: %s\nRunning image: %s\nNext boot image: %s\nPrevious image: %s\nReboot pending: %s\n"+
"Upgrade anchor: %s\nAnchor SHA-256: %s\n",
s.GetRunningVersion(), s.GetRunningSha256(), s.GetActiveSha256(), previous, pending,
s.GetUpgradeAnchorSubject(), s.GetUpgradeAnchorSha256())

return err
}
19 changes: 19 additions & 0 deletions cmd/cryptosctl/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (r *recordingUpgrader) Status(context.Context) (*nodev1.ImageStatus, error)
RebootPending: false,
RunningSha256: "abcd",
RunningVersion: "v1.2.3",

UpgradeAnchorSubject: "CN=Example Release",
UpgradeAnchorSha256: "feedface",
}, nil
}

Expand Down Expand Up @@ -189,6 +192,22 @@ func TestImageStatus_ReportsTheRunningImage(t *testing.T) {
}
}

func TestImageStatus_ShowsTheUpgradeAnchor(t *testing.T) {
ts := startImageServer(t, &recordingUpgrader{})

for _, format := range []string{"human", "json", "yaml"} {
out, err := ts.run(t, "image", "status", "-o", format)
if err != nil {
t.Fatalf("image status -o %s: %v (out=%s)", format, err, out)
}
for _, want := range []string{"CN=Example Release", "feedface"} {
if !strings.Contains(out, want) {
t.Errorf("-o %s output is missing %q: %s", format, want, out)
}
}
}
}

func TestImageRollback_CallsTheNode(t *testing.T) {
up := &recordingUpgrader{}
ts := startImageServer(t, up)
Expand Down
4 changes: 4 additions & 0 deletions docs/image-sign.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ A node installed from an image you signed this way takes signed in-place
upgrades: any later image you sign with the same key can be staged onto it
with `cryptosctl image stage`.

To check which anchor a running node trusts, run `cryptosctl image status`: it
prints the anchor's subject and SHA-256, which you can compare with the
certificate you signed with.

It signs an unsigned ISO the same way, so you can install from a signed ISO
without rebuilding it; see [Sign an ISO](#sign-an-iso).

Expand Down
506 changes: 267 additions & 239 deletions gen/go/cryptos/node/v1/node.pb.go

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions internal/init/imageupgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,18 @@ func (u *nodeImageUpgrader) Status(_ context.Context) (*nodev1.ImageStatus, erro
}

func (u *nodeImageUpgrader) imageStatus(st imageupgrade.Status) *nodev1.ImageStatus {
// Release is the upgrade anchor: the certificate an incoming image must be
// signed by. newImageUpgrader refuses a nil one.
anchor := sha256.Sum256(u.opts.Release.Raw)

return &nodev1.ImageStatus{
ActiveSha256: st.ActiveDigest,
PreviousSha256: st.PreviousDigest,
RebootPending: st.ActiveDigest != u.opts.Running,
RunningSha256: u.opts.Running,
RunningVersion: u.opts.Version,
ActiveSha256: st.ActiveDigest,
PreviousSha256: st.PreviousDigest,
RebootPending: st.ActiveDigest != u.opts.Running,
RunningSha256: u.opts.Running,
RunningVersion: u.opts.Version,
UpgradeAnchorSubject: u.opts.Release.Subject.String(),
UpgradeAnchorSha256: hex.EncodeToString(anchor[:]),
}
}

Expand Down
21 changes: 21 additions & 0 deletions internal/init/imageupgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,27 @@ func TestUpgrader_StatusOnAnUnupgradedNode(t *testing.T) {
}
}

// Status names the upgrade anchor the node checks images against, so an
// operator can prove which certificate a node trusts without staging an image.
func TestUpgrader_StatusReportsTheUpgradeAnchor(t *testing.T) {
rel := newReleaseKey(t)
old := []byte("the running image")
esp := newESPDir(t, old)
u := newTestUpgrader(t, esp, rel, old, func() { t.Fatal("must not reboot") })

st, err := u.Status(context.Background())
if err != nil {
t.Fatalf("Status: %v", err)
}
sum := sha256.Sum256(rel.cert.Raw)
if got, want := st.GetUpgradeAnchorSha256(), hex.EncodeToString(sum[:]); got != want {
t.Errorf("upgrade_anchor_sha256 = %q, want %q", got, want)
}
if got, want := st.GetUpgradeAnchorSubject(), rel.cert.Subject.String(); got != want {
t.Errorf("upgrade_anchor_subject = %q, want %q", got, want)
}
}

// A build with no release certificate must refuse to construct an upgrader, so
// the RPCs are Unimplemented rather than silently accepting any image.
func TestNewImageUpgrader_RequiresARelease(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions proto/cryptos/node/v1/node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -704,4 +704,11 @@ message ImageStatus {
// running_version is the CryptOS version string baked into the running image,
// which is what an operator actually recognises.
string running_version = 5;
// upgrade_anchor_subject is the subject of the certificate the running image
// checks an incoming image's signature against (its upgrade anchor).
string upgrade_anchor_subject = 6;
// upgrade_anchor_sha256 is the SHA-256 of that certificate's DER encoding,
// hex encoded, so an operator can compare it with the certificate they
// signed with.
string upgrade_anchor_sha256 = 7;
}
Loading