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
1 change: 1 addition & 0 deletions changelog.d/added-customer-match-key-provisioning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Hub-hosted spokes now receive the per-hive customer match key (`HIVE_CUSTOMER_MATCH_KEY`), so the customers hub import can work once enabled; default behaviour is unchanged.
4 changes: 4 additions & 0 deletions src/docs/design/customers-hub-consent.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ constants for size and rate; none of this is final until phase 2.
hub. The hub's per-person consent decides what arrives; the switch only says
this hive asks. The help text states that the request carries hashed GitHub
logins of confirmed customers and nothing else.
- **Match key provisioning.** Hub-hosted spokes receive the per-hive match key
as `HIVE_CUSTOMER_MATCH_KEY` from the hub (provisioning and the per-hive env
reconcile, current master generation). Self-service (`byo-`) hives hold no
master and get no provisioning, so they cannot use the hub import in v1.

## Revocation

Expand Down
2 changes: 2 additions & 0 deletions src/pkg/hub/hub_generations_f19_wiring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestRotationReachesDesiredPerHiveEnv(t *testing.T) {
EnvHeartbeatKey: derivePerHiveKey(newSecret, infoHeartbeatKey, hiveID),
EnvTerminalKey: derivePerHiveKey(newSecret, infoTerminalKey, hiveID),
EnvInviteKey: derivePerHiveKey(newSecret, infoInviteKey, hiveID),
EnvCustomerMatchKey: customerMatchKey(newSecret, hiveID),
EnvSSOPublicKey: ssoPublicKeyFromSeed(deriveDomainKey(newSecret, infoSSOEd25519Seed)),
envSessionPublicKey: ssoPublicKeyFromSeed(deriveDomainKey(newSecret, infoSessionEd25519Seed)),
}
Expand Down Expand Up @@ -167,6 +168,7 @@ func rawMasterDerivation(master, hiveID string) map[string]string {
EnvHeartbeatKey: derivePerHiveKey(master, infoHeartbeatKey, hiveID),
EnvTerminalKey: derivePerHiveKey(master, infoTerminalKey, hiveID),
EnvInviteKey: derivePerHiveKey(master, infoInviteKey, hiveID),
EnvCustomerMatchKey: customerMatchKey(master, hiveID),
EnvSSOPublicKey: ssoPublicKeyFromSeed(deriveDomainKey(master, infoSSOEd25519Seed)),
envSessionPublicKey: ssoPublicKeyFromSeed(deriveDomainKey(master, infoSessionEd25519Seed)),
}
Expand Down
12 changes: 12 additions & 0 deletions src/pkg/hub/hub_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ func provisionInviteKey(hiveID string) string {
return derivePerHiveKey(provisionCurrentSecret(), infoInviteKey, hiveID)
}

// provisionCustomerMatchKey returns the PER-HIVE key a spoke salts GitHub login
// hashes with for the customers hub import, injected as HIVE_CUSTOMER_MATCH_KEY.
// It is customerMatchKey against the CURRENT generation, so a re-provisioned or
// reconciled spoke moves to the current key after a master rotation (the hub
// still accepts every live generation via customerMatchKeys). Hub-hosted spokes
// never hold the master, so without this the import has no key and stays inert.
func provisionCustomerMatchKey(hiveID string) string {
return customerMatchKey(provisionCurrentSecret(), hiveID)
}

// heartbeatKeyFor returns the per-hive heartbeat bearer the hub EXPECTS from
// hiveID. Mirror of provisionHeartbeatKey, resolved against the running hub's
// own master rather than the provisioning-time lookup.
Expand Down Expand Up @@ -354,6 +364,8 @@ const (
// both mints and verifies invite tokens with it, so it is symmetric; it exists
// so inviteSigningSecret() no longer has to read the raw master.
EnvInviteKey = "HIVE_INVITE_KEY"
// EnvCustomerMatchKey carries the per-hive customers hub import match key.
EnvCustomerMatchKey = "HIVE_CUSTOMER_MATCH_KEY"
)

// spokeDomainKey resolves a domain sub-key for spoke-side code. It prefers the
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/hub/perhive_env_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ func TestDesiredPerHiveEnvUsesCurrentNotPrevious(t *testing.T) {
EnvHeartbeatKey: derivePerHiveKey(perHiveGenSecretB, infoHeartbeatKey, hiveID),
EnvTerminalKey: derivePerHiveKey(perHiveGenSecretB, infoTerminalKey, hiveID),
EnvInviteKey: derivePerHiveKey(perHiveGenSecretB, infoInviteKey, hiveID),
EnvCustomerMatchKey: customerMatchKey(perHiveGenSecretB, hiveID),
EnvSSOPublicKey: ssoPublicKeyFromSeed(deriveDomainKey(perHiveGenSecretB, infoSSOEd25519Seed)),
envSessionPublicKey: ssoPublicKeyFromSeed(deriveDomainKey(perHiveGenSecretB, infoSessionEd25519Seed)),
}
fromPrevious := map[string]string{
EnvHeartbeatKey: derivePerHiveKey(perHiveGenSecretA, infoHeartbeatKey, hiveID),
EnvTerminalKey: derivePerHiveKey(perHiveGenSecretA, infoTerminalKey, hiveID),
EnvInviteKey: derivePerHiveKey(perHiveGenSecretA, infoInviteKey, hiveID),
EnvCustomerMatchKey: customerMatchKey(perHiveGenSecretA, hiveID),
EnvSSOPublicKey: ssoPublicKeyFromSeed(deriveDomainKey(perHiveGenSecretA, infoSSOEd25519Seed)),
envSessionPublicKey: ssoPublicKeyFromSeed(deriveDomainKey(perHiveGenSecretA, infoSessionEd25519Seed)),
}
Expand Down Expand Up @@ -113,6 +115,9 @@ func TestDesiredPerHiveEnvUsesCurrentNotPrevious(t *testing.T) {
if provisionInviteKey(hiveID) != fromCurrent[EnvInviteKey] {
t.Error("provisionInviteKey did not follow the current generation")
}
if provisionCustomerMatchKey(hiveID) != fromCurrent[EnvCustomerMatchKey] {
t.Error("provisionCustomerMatchKey did not follow the current generation")
}
if provisionSessionPublicKey() != fromCurrent[envSessionPublicKey] {
t.Error("provisionSessionPublicKey did not follow the current generation")
}
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/hub/perhive_env_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func desiredPerHiveEnv(hiveID string) map[string]string {
// Without it in this list a rotation would also never converge the
// invite key, leaving it derived from a generation the hub has retired.
EnvInviteKey: provisionInviteKey(hiveID),
// The customers hub import match key. Hub-hosted spokes never hold the
// master, so this is how they obtain it; reconciled so a rotation
// converges it to the current generation.
EnvCustomerMatchKey: provisionCustomerMatchKey(hiveID),
// HIVE_SESSION_KEY is deliberately ABSENT (audit #3234 N2 follow-up).
// RESIDUAL-2 made it per-hive as defence-in-depth, but every lane that
// ever verified against it — F1 (Go legacy cookie lane), N3 (terminal
Expand Down Expand Up @@ -188,6 +192,7 @@ func perHiveEnvNames() []string {
EnvHeartbeatKey,
EnvTerminalKey,
EnvInviteKey,
EnvCustomerMatchKey,
EnvSSOPublicKey,
envSessionPublicKey,
}
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/hub/perhive_env_reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func TestDesiredPerHiveEnvMatchesProvisioningTemplate(t *testing.T) {
envSessionPublicKey: provisionSessionPublicKey(),
EnvTerminalKey: provisionTerminalKey(hiveID),
EnvInviteKey: provisionInviteKey(hiveID),
// Issue #19246: the injected key equals customerMatchKey(currentMaster, hive).
EnvCustomerMatchKey: customerMatchKey(provisionCurrentSecret(), hiveID),
}
for name, v := range expect {
if v == "" {
Expand All @@ -93,6 +95,9 @@ func TestDesiredPerHiveEnvMatchesProvisioningTemplate(t *testing.T) {
if other[EnvInviteKey] == want[EnvInviteKey] {
t.Error("invite key is identical across hives — not per-hive")
}
if other[EnvCustomerMatchKey] == want[EnvCustomerMatchKey] {
t.Error("customer match key is identical across hives — not per-hive")
}
}

// TestSessionKeyIsPermanentlyRemoved covers the issue #3234 removal: unlike
Expand Down
6 changes: 6 additions & 0 deletions src/pkg/hub/saas_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -2669,6 +2669,8 @@ func provisionHive(h *SaaSHive, req *CreateHiveRequest, cluster *ClusterConfig,
// injected it no longer does. Minted and verified on the same spoke, so
// symmetric; per-hive so an invite link cannot travel between tenants.
"InviteKey": provisionInviteKey(h.ID),
// Per-hive customers hub import match key (HIVE_CUSTOMER_MATCH_KEY).
"CustomerMatchKey": provisionCustomerMatchKey(h.ID),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing renders the template with this field. A typo between this map key and {{.CustomerMatchKey}} at line 3689 would be a template error at provision time, not a test failure. A small render test asserting HIVE_CUSTOMER_MATCH_KEY appears with provisionCustomerMatchKey(h.ID) would close it. Suggestion, not a defect.

// Cluster-aware fields.
"HubPublicURL": hubPublicURL(),
"ClusterID": cluster.ID,
Expand Down Expand Up @@ -3682,6 +3684,10 @@ spec:
# in-flight invite links. Nothing else is affected.
- name: HIVE_INVITE_KEY
value: "{{.InviteKey}}"
# The per-hive customers hub import match key. Spokes never hold the
# master, so the hub hands them this derived key instead.
- name: HIVE_CUSTOMER_MATCH_KEY
value: "{{.CustomerMatchKey}}"
{{- if .IsNginxIngress}}
# HIVE_INGRESS_AUTHZ tells the Node proxy that an nginx ingress
# auth-proxy sits IN FRONT of this pod and per-hive-authorizes every
Expand Down
Loading