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
12 changes: 10 additions & 2 deletions bin/contributor-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,12 @@ function hubRegistryURLFor(hiveURL) {
// (vanity hosts). Returns the registry's dashboardUrl as a wss:// contribute
// URL, or null when the registry does not know the hive or lists the same
// host we just failed on (so the retry would be identical).
//
// Only an https dashboardUrl under the hub's own spoke domain is followed.
// dashboardUrl is reported by each spoke in its heartbeat, so the registry can
// list any host; the relay dials the result with the contributor's token and
// runs whatever that host hands it, which must stay with hosts the hub fronts.
// Entries elsewhere are skipped, never redialed.
function currentHiveURLFromRegistry(hiveURL, registry) {
let u;
try { u = new URL(String(hiveURL || '').trim()); } catch (_) { return null; }
Expand All @@ -1465,10 +1471,12 @@ function currentHiveURLFromRegistry(hiveURL, registry) {
if (!h || typeof h !== 'object' || typeof h.dashboardUrl !== 'string') continue;
let d;
try { d = new URL(h.dashboardUrl); } catch (_) { continue; }
const dHost = d.hostname.toLowerCase();
const dHost = d.hostname.toLowerCase().replace(/\.$/, '');
if (h.id !== label && dHost.split('.')[0] !== label) continue;
if (d.protocol !== 'https:' || !dHost.endsWith('.' + DEFAULT_HUB_SPOKE_DOMAIN)) continue;
if (dHost === host) return null;
d.protocol = d.protocol === 'http:' ? 'ws:' : 'wss:';
d.hostname = dHost;
d.protocol = 'wss:';
d.pathname = '/contribute';
d.search = '';
d.hash = '';
Expand Down
6 changes: 6 additions & 0 deletions bin/contributor-relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15348,7 +15348,10 @@ test('tls-mismatch: hub registry lookup is only for hosted hives, and resolves b

const registry = { hives: [
{ id: 'hosted-available-oke-11-placeholder-r05x', dashboardUrl: 'https://hosted-kubestellar-hive-ojv6.hive.hivecommons.dev' },
{ id: 'hosted-other', dashboardUrl: 'https://hosted-plain.relay.example' },
{ id: 'hosted-plain', dashboardUrl: 'https://hosted-plain.hive.hivecommons.dev' },
{ id: 'hosted-clear', dashboardUrl: 'http://hosted-clear.hive.hivecommons.dev' },
{ id: 'hosted-lookalike', dashboardUrl: 'https://hosted-lookalike.hive.hivecommons.dev.relay.example' },
{ id: 'bad', dashboardUrl: 'not a url' },
null, 'junk',
] };
Expand All @@ -15357,6 +15360,9 @@ test('tls-mismatch: hub registry lookup is only for hosted hives, and resolves b
{ name: 'by vanity label', url: 'wss://hosted-kubestellar-hive-ojv6.old.example/contribute', want: 'wss://hosted-kubestellar-hive-ojv6.hive.hivecommons.dev/contribute' },
{ name: 'same host already — no identical retry', url: 'wss://hosted-plain.hive.hivecommons.dev/contribute', want: null },
{ name: 'unknown hive', url: 'wss://hosted-nope.hive.example/contribute', want: null },
{ name: 'entry outside the hub spoke domain is not followed', url: 'wss://hosted-other.hive.example/contribute', want: null },
{ name: 'plain-http entry is not followed', url: 'wss://hosted-clear.hive.example/contribute', want: null },
{ name: 'spoke-domain lookalike is not followed', url: 'wss://hosted-lookalike.hive.example/contribute', want: null },
{ name: 'no registry', url: 'wss://hosted-plain.hive.example/contribute', registry: null, want: null },
{ name: 'registry without hives array', url: 'wss://hosted-plain.hive.example/contribute', registry: { hives: 'x' }, want: null },
];
Expand Down
1 change: 1 addition & 0 deletions changelog.d/fixed-relay-relocation-host.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The contributor relay's one-shot hub-registry relocation (after a certificate hostname mismatch) now follows only an `https://` entry under the hub's own spoke domain; registry entries naming any other host, a plain-http URL, or a spoke-domain lookalike are skipped and the hub stays parked with the existing remediation line.
Loading