Skip to content
Closed
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
2 changes: 1 addition & 1 deletion docs-site/src/content/docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ A project's own accounts live under `/api/v1/projects/:id/gcp-service-accounts`

In the list (`GET /api/v1/runtime-brokers`, without `projectId`) and in `GET /api/v1/runtime-brokers/:id`, a Runtime Broker that runs in the process answering the request (the server's co-located Runtime Broker or one of its co-located flat instances) carries the read-only `hostedByThisServer: true`. The field is omitted for every other Runtime Broker. With several Hub replicas behind a load balancer, it describes the replica that answered.

The list (with or without `projectId`) and `GET /api/v1/runtime-brokers/:id` carry a read-only `versionStatus` on each Runtime Broker: `match`, `mismatch` or `unknown`, comparing the Runtime Broker's `version` with the Hub's version (see [Version mismatch](/scion/workstation/dashboard/#version-mismatch)). It is `unknown` when the Runtime Broker has not reported a version or when there is no single Hub version (no live Hub instance, or live instances running different versions), and it is omitted for plugin records. Both list responses also carry `hubVersion`, the Hub version compared with: the version every live Hub instance reports, `mixed` when they differ, or empty when it is unknown. A Runtime Broker reports its version (`version`, the release tag or the short commit) when it joins or registers, and in the optional `version` field of its heartbeat (`POST /api/v1/runtime-brokers/:id/heartbeat`). The heartbeat field is applied only on a heartbeat the Runtime Broker sends with its own credentials (not on a heartbeat sent by a user), and an omitted or empty value leaves the stored version unchanged. A co-located Runtime Broker records the server's version each time the server starts.
The list (with or without `projectId`) and `GET /api/v1/runtime-brokers/:id` carry a read-only `versionStatus` on each Runtime Broker: `match`, `mismatch` or `unknown`, comparing the Runtime Broker's `version` with the Hub's version (see [Version mismatch](/scion/workstation/dashboard/#version-mismatch)). It is `unknown` when the Runtime Broker has not reported a version or when there is no single Hub version (no live Hub instance, or live instances running different versions), and it is omitted for plugin records. Both list responses also carry `hubVersion`, the Hub version compared with: the version every live Hub instance reports, `mixed` when they differ, or empty when it is unknown. A Runtime Broker reports its version (`version`, the release tag or the short commit) when it joins or registers, and in the optional `version` field of its heartbeat (`POST /api/v1/runtime-brokers/:id/heartbeat`). The heartbeat field is applied only on a heartbeat the Runtime Broker sends with its own credentials (not on a heartbeat sent by a user). When a Runtime Broker's own heartbeat omits `version`, sends an empty value, or sends an unusable placeholder (`dev`), the Hub clears the stored version so the Runtime Broker shows as `unknown` rather than keeping a stale tag. A co-located Runtime Broker records the server's version each time the server starts.

#### Broker Settings (`/api/v1/runtime-brokers/:id/settings`)

Expand Down
4 changes: 2 additions & 2 deletions docs-site/src/content/docs/workstation/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ After a Hub upgrade, the **Brokers** page and the **Health** page show which Run
- **Version**: a Runtime Broker reports its build version when it joins or registers, and refreshes it with every heartbeat it sends with its own credentials. A co-located Runtime Broker that runs without its own credentials (for example under development authentication) records the server's version each time the server starts, so its version stays current without the heartbeat. The version is the release tag for a tagged build and the first 8 characters of the commit otherwise, the same form the Hub reports for itself.
- **Hub version**: the version every live Hub instance reports. While Hub instances run different versions (a rolling upgrade), there is no single Hub version, so every Runtime Broker is shown as unknown.
- **Match rule**: the two versions must be identical. There is no normalisation, so `1.2.0` and `v1.2.0` differ.
- **Needs attention**: an online Runtime Broker whose version differs adds a `broker_version_mismatch` warning to the Health page (it does not change the overall status) and counts for the **Needs attention** filter of the Brokers area. When the Hub has a single known version (not empty, `mixed`, or `unknown`), an online Runtime Broker whose version is empty or `unknown` adds a `broker_version_unknown` warning to the Health page (it does not change the overall status) and counts for the **Needs attention** filter of the Brokers area. Offline and pre-heartbeat Runtime Brokers stay excluded (an offline Runtime Broker keeps only its offline item), and when the Hub version itself is unknown or `mixed` during a rolling upgrade, no `broker_version_unknown` warning is added.
- **Needs attention**: an online Runtime Broker whose version differs adds a `broker_version_mismatch` warning to the Health page (it does not change the overall status) and counts for the **Needs attention** filter of the Brokers area. When the Hub has a single known version (not empty, `mixed`, or `unknown`), an online Runtime Broker whose version is empty, `unknown`, or `dev` adds a `broker_version_unknown` warning to the Health page (it does not change the overall status) and counts for the **Needs attention** filter of the Brokers area. Offline and pre-heartbeat Runtime Brokers stay excluded (an offline Runtime Broker keeps only its offline item), and when the Hub version itself is unknown or `mixed` during a rolling upgrade, no `broker_version_unknown` warning is added.
- The summary's runtime broker rows carry `version_status` (`match`, `mismatch` or `unknown`); the Runtime Broker list (with or without `projectId`) and `GET /api/v1/runtime-brokers/:id` carry `versionStatus`, and both list responses carry the compared `hubVersion` (see the [API reference](/scion/reference/api/#runtime-brokers-apiv1brokers)).

Known limitations:

- A Runtime Broker built from the same commit as the Hub, but one with a release tag and one without, is shown as different.
- A Runtime Broker older than this feature reports its version only when it joins, and an untagged one reports none (unknown). A Runtime Broker rolled back to such a build keeps showing the version its newer build last reported until it joins again.
- A Runtime Broker older than this feature reports its version only when it joins (and omits `version` on heartbeats), and an untagged or `dev` build reports no usable version. A Runtime Broker rolled back to such a build has its stored version cleared on its next heartbeat and shows as unknown (triggering `broker_version_unknown` when the Hub has a single known version).
- A locally modified build shows the version of the commit it was built from.

### Admin Management Suite
Expand Down
16 changes: 12 additions & 4 deletions pkg/hub/broker_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package hub
import (
"context"
"log/slog"
"strings"

"github.com/GoogleCloudPlatform/scion/pkg/store"
"github.com/GoogleCloudPlatform/scion/pkg/version"
Expand All @@ -41,11 +42,18 @@ func HubBuildToken() string {
return hubBuildToken()
}

// brokerVersionToken bounds a Runtime Broker supplied version the same way
// as hubBuildToken. It is applied when a version is stored and again when
// one is read, so rows stored before the bound existed are covered too.
// brokerVersionToken bounds and normalizes a Runtime Broker supplied version
// the same way as hubBuildToken. Whitespace-only, non-printable, and unusable
// placeholder tokens ("dev") normalize to "" so they are treated as unknown
// rather than compared as a real build token (ptone/scion#6382). It is applied
// when a version is stored and again when one is read, so rows stored before
// the normalization existed are covered too.
func brokerVersionToken(v string) string {
return boundedPrintable(v, hubInstanceMaxVersionBytes)
v = strings.TrimSpace(boundedPrintable(v, hubInstanceMaxVersionBytes))
if strings.EqualFold(v, "dev") {
return ""
}
return v
}

// brokerVersionStatus compares a Runtime Broker's stored version with the
Expand Down
119 changes: 100 additions & 19 deletions pkg/hub/broker_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func TestBrokerVersionStatus(t *testing.T) {
assert.Equal(t, "match", brokerVersionStatus("v1.2.0", "v1.2.0"))
assert.Equal(t, "mismatch", brokerVersionStatus("v1.3.0", "v1.2.0"))
assert.Equal(t, "unknown", brokerVersionStatus("v1.2.0", ""))
assert.Equal(t, "unknown", brokerVersionStatus("v1.2.0", "dev"))
assert.Equal(t, "unknown", brokerVersionStatus("v1.2.0", "DEV"))
assert.Equal(t, "unknown", brokerVersionStatus("v1.2.0", " "))
assert.Equal(t, "unknown", brokerVersionStatus("", "v1.2.0"), "no live hub instance")
assert.Equal(t, "unknown", brokerVersionStatus(HubVersionMixed, "v1.2.0"), "no single hub version during a rolling upgrade")
assert.Equal(t, "unknown", brokerVersionStatus(HubVersionMixed, HubVersionMixed))
Expand All @@ -97,6 +100,12 @@ func TestBrokerVersionToken_Bounded(t *testing.T) {
assert.Equal(t, strings.Repeat("v", hubInstanceMaxVersionBytes), brokerVersionToken(strings.Repeat("v", 200)))
assert.Equal(t, "v1.2.0", brokerVersionToken("v1.\n2.\x000"))
assert.Equal(t, "", brokerVersionToken(""))
assert.Equal(t, "", brokerVersionToken(" "))
assert.Equal(t, "", brokerVersionToken("\n\x00"))
assert.Equal(t, "", brokerVersionToken("dev"))
assert.Equal(t, "", brokerVersionToken("DEV"))
assert.Equal(t, "", brokerVersionToken(" dev "))
assert.Equal(t, "unknown", brokerVersionToken("unknown"))
assert.Equal(t, hubBuildToken(), HubBuildToken())
}

Expand Down Expand Up @@ -154,6 +163,7 @@ func TestHealthSummary_BrokerVersionUnknown(t *testing.T) {

createSummaryBroker(t, s, versionTestBroker("ver-unk-str", "unknown"))
createSummaryBroker(t, s, versionTestBroker("ver-unk-empty", ""))
createSummaryBroker(t, s, versionTestBroker("ver-unk-dev", "dev"))

offUnknown := versionTestBroker("ver-off-unk", "unknown")
offUnknown.Status = store.BrokerStatusOffline
Expand All @@ -166,7 +176,7 @@ func TestHealthSummary_BrokerVersionUnknown(t *testing.T) {
assert.Empty(t, versionItems(resp))

unknownItems := versionUnknownItems(resp)
require.Len(t, unknownItems, 2, "only the two online brokers with empty/unknown version get items: %+v", resp.Attention)
require.Len(t, unknownItems, 3, "only the three online brokers with empty/unknown/dev version get items: %+v", resp.Attention)
byID := map[string]HealthAttentionItem{}
for _, it := range unknownItems {
byID[it.Subject.ID] = it
Expand All @@ -181,6 +191,11 @@ func TestHealthSummary_BrokerVersionUnknown(t *testing.T) {
Subject: HealthAttentionSubject{Type: HealthSubjectBroker, ID: tid("ver-unk-empty"), Name: "ver-unk-empty"},
Message: "Runtime broker ver-unk-empty reports no version; cannot verify it matches the hub (v1.3.0)",
}, byID[tid("ver-unk-empty")])
assert.Equal(t, HealthAttentionItem{
Severity: HealthAttentionWarning, Kind: HealthAttentionBrokerVersionUnknown,
Subject: HealthAttentionSubject{Type: HealthSubjectBroker, ID: tid("ver-unk-dev"), Name: "ver-unk-dev"},
Message: "Runtime broker ver-unk-dev reports no version; cannot verify it matches the hub (v1.3.0)",
}, byID[tid("ver-unk-dev")])
assert.NotContains(t, byID, tid("ver-off-unk"))
assert.NotContains(t, byID, tid("ver-pre-hb"))
}
Expand Down Expand Up @@ -564,8 +579,9 @@ func TestHealthSummary_BrokerVersionBoundedOnRead(t *testing.T) {

// The heartbeat refreshes the stored version only from the broker itself:
// a self heartbeat replaces a stale join value, a version-only heartbeat is
// enough, an omitted or empty version keeps it, a user heartbeat never sets
// it, and the value is bounded.
// enough, an omitted, empty, non-printable or "dev" version clears the stored
// value (ptone/scion#6382), "unknown" replaces it with "unknown", a user
// heartbeat never sets or clears it, and the value is bounded.
func TestBrokerHeartbeat_Version(t *testing.T) {
srv, s := testServer(t)
ctx := context.Background()
Expand All @@ -582,34 +598,87 @@ func TestBrokerHeartbeat_Version(t *testing.T) {
assert.Equal(t, "v1.3.0", stored(), "a version-only self heartbeat replaces the stale value")

sendAsBroker(t, srv, id, map[string]interface{}{"status": "online"})
assert.Equal(t, "v1.3.0", stored(), "an omitted version keeps the stored one")
assert.Equal(t, "", stored(), "an omitted version clears the stored one")

sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "v1.3.0"})
assert.Equal(t, "v1.3.0", stored(), "a usable version replaces the cleared value")

sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": ""})
assert.Equal(t, "v1.3.0", stored(), "an empty version keeps the stored one")
assert.Equal(t, "", stored(), "an empty version clears the stored one")

sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "v1.3.0"})
sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "dev"})
assert.Equal(t, "", stored(), "a dev version clears the stored one")

sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "v1.3.0"})
sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "\n\x00"})
assert.Equal(t, "", stored(), "a version normalizing to empty clears the stored one")

sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "v1.3.0"})
sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "unknown"})
assert.Equal(t, "unknown", stored(), "an explicit unknown version replaces the stale value")

sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "v1.3.0"})
rec := doRequest(t, srv, http.MethodPost, "/api/v1/runtime-brokers/"+id+"/heartbeat",
map[string]interface{}{"status": "online", "version": "v9.9.9"})
require.Equal(t, http.StatusOK, rec.Code, rec.Body.String())
assert.Equal(t, "v1.3.0", stored(), "a user heartbeat never sets the version")

rec = doRequest(t, srv, http.MethodPost, "/api/v1/runtime-brokers/"+id+"/heartbeat",
map[string]interface{}{"status": "online"})
require.Equal(t, http.StatusOK, rec.Code, rec.Body.String())
assert.Equal(t, "v1.3.0", stored(), "a user heartbeat never clears the version")

sendAsBroker(t, srv, id, map[string]interface{}{"status": "online", "version": "v2\n" + strings.Repeat("z", 200)})
assert.Equal(t, "v2"+strings.Repeat("z", hubInstanceMaxVersionBytes-2), stored(), "bounded before it is stored")
}

// Rollback: a broker rolled back to a build without the heartbeat version
// keeps its last heartbeat-written token (omitted keeps); a re-join by that
// older build clears it to "" (unknown). Documented limitation.
func TestBrokerVersion_RollbackKeepsUntilRejoin(t *testing.T) {
f := newOwnedBrokerFixture(t, false, "ver-rollback")
setHubFleet(t, f.s, "v1.3.0")
sendAsBroker(t, f.srv, f.id, map[string]interface{}{"status": "online", "version": "v1.3.0"})
sendAsBroker(t, f.srv, f.id, map[string]interface{}{"status": "online"})
assert.Equal(t, "v1.3.0", f.row(t).Version, "an older heartbeat keeps the token")
// A stored old tag followed by a self heartbeat whose version is omitted,
// empty, or "dev" clears the stored value, turning a false
// broker_version_mismatch warning into a truthful broker_version_unknown
// warning (ptone/scion#6382, ptone/scion#7430). A subsequent heartbeat with a
// usable matching version restores match with no attention items.
func TestBrokerVersion_StaleClearedOnEmptyOrDevHeartbeat(t *testing.T) {
for _, tc := range []struct {
name string
body map[string]interface{}
}{
{"omitted", map[string]interface{}{"status": "online"}},
{"empty", map[string]interface{}{"status": "online", "version": ""}},
{"dev", map[string]interface{}{"status": "online", "version": "dev"}},
{"non-printable", map[string]interface{}{"status": "online", "version": "\n\x00"}},
} {
t.Run(tc.name, func(t *testing.T) {
f := newOwnedBrokerFixture(t, false, "ver-stale-"+tc.name)
setHubFleet(t, f.s, "v1.3.0")

// Start with a stale old tag: surfaces broker_version_mismatch.
sendAsBroker(t, f.srv, f.id, map[string]interface{}{"status": "online", "version": "nightly-20260928"})
assert.Equal(t, "nightly-20260928", f.row(t).Version)
resp, _ := getHealthSummary(t, f.srv)
require.Len(t, versionItems(resp), 1)
assert.Empty(t, versionUnknownItems(resp))

resp := f.reregister(t, func(r *CreateBrokerRegistrationRequest) { r.Force = true })
rec := doRequestNoAuthLoopback(t, f.srv, http.MethodPost, "/api/v1/brokers/join",
BrokerJoinRequest{BrokerID: f.id, JoinToken: resp.JoinToken, Hostname: "ver-rollback", Version: ""})
require.Equal(t, http.StatusOK, rec.Code, rec.Body.String())
assert.Equal(t, "", f.row(t).Version)
// Heartbeat with empty/omitted/dev clears the stored value.
sendAsBroker(t, f.srv, f.id, tc.body)
assert.Equal(t, "", f.row(t).Version)
resp, _ = getHealthSummary(t, f.srv)
rows := summaryBrokerByID(resp)
assert.Equal(t, "", rows[f.id].Version)
assert.Equal(t, "unknown", rows[f.id].VersionStatus)
assert.Empty(t, versionItems(resp), "no false mismatch item after clearing stale version")
require.Len(t, versionUnknownItems(resp), 1, "surfaces truthful broker_version_unknown warning")

// A usable version on a later heartbeat replaces the cleared value.
sendAsBroker(t, f.srv, f.id, map[string]interface{}{"status": "online", "version": "v1.3.0"})
assert.Equal(t, "v1.3.0", f.row(t).Version)
resp, _ = getHealthSummary(t, f.srv)
rows = summaryBrokerByID(resp)
assert.Equal(t, "match", rows[f.id].VersionStatus)
assert.Empty(t, versionItems(resp))
assert.Empty(t, versionUnknownItems(resp))
})
}
}

// Join always stores the sent version: an older untagged broker re-joining
Expand Down Expand Up @@ -644,6 +713,16 @@ func TestBrokerJoin_AlwaysStoresVersion(t *testing.T) {
assert.Empty(t, versionItems(resp))
require.Len(t, versionUnknownItems(resp), 1)

join("v1.2.0")
assert.Equal(t, "v1.2.0", f.row(t).Version)
join("dev")
assert.Equal(t, "", f.row(t).Version, "a dev version clears the stale token")
resp, _ = getHealthSummary(t, f.srv)
rows = summaryBrokerByID(resp)
assert.Equal(t, "unknown", rows[f.id].VersionStatus)
assert.Empty(t, versionItems(resp))
require.Len(t, versionUnknownItems(resp), 1)

join(strings.Repeat("j", 200))
assert.Equal(t, strings.Repeat("j", hubInstanceMaxVersionBytes), f.row(t).Version)
})
Expand Down Expand Up @@ -694,6 +773,8 @@ func TestRegisterProjectBroker_Version(t *testing.T) {
assert.Equal(t, "v1.2.0", stored())
register("3", "")
assert.Equal(t, "v1.2.0", stored(), "an empty version keeps the stored one")
register("4", "dev")
assert.Equal(t, "", stored(), "a dev version clears the stored one")
}

// The projectId-filtered list carries hubVersion and each broker's
Expand Down
Loading
Loading