From 6861a113d2faa9f0b9fb7304741428d8baab2583 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Mon, 10 Aug 2026 23:54:05 -0400 Subject: [PATCH] fix(directory): unify the Directory's site slug with the multi-site replication identity Two previously-unrelated "site slug" concepts existed: the Directory catalog's site Resource (site.slug, what group names and the resource tree actually use -- e.g. "E2E Site" / site_e2e) vs. site_config.js's siteSlug (the multi-site replication identity shown on the Multi-Site modal's "Local Site Slug" row, sourced only from a separately-set SITE_SLUG env var). Nothing ever kept them in sync -- a real deployment could show a real site name in the Directory tree and the literal "site-default" fallback on the Multi-Site modal for the exact same node, which is exactly what a live demo of the modal surfaced. Synced at the source: POST /resources now sets site_config's siteSlug to match, the moment this node's own site Resource is first created (bootstrap.js's initial call). Only for a still-default master -- never overwrites a real multi-site identity a join/promote has already established, and never touches a spoke's identity (the master's to assign via registration, not this node's own resource creation to decide). Verified against a real running container via docker-compose.multisite-e2e.yml's existing site-creation step. --- nodejs/routes/api_directory_admin.js | 19 +++++++++++++++++++ test/multisite_join_e2e.js | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/nodejs/routes/api_directory_admin.js b/nodejs/routes/api_directory_admin.js index 60049f7..55ae8b8 100644 --- a/nodejs/routes/api_directory_admin.js +++ b/nodejs/routes/api_directory_admin.js @@ -365,6 +365,25 @@ router.post('/resources', async (req, res, next) => { const ancestorSite = await Resource.findAncestorSiteSlug(r.id); if (r.kind === 'site') { await ensureSiteGroups(r.slug, req.user.dn, r.name, r.id); + // Two previously-unrelated "site slug" concepts: this Resource's own + // slug (the Directory catalog's site container -- what every group + // name and the resource tree actually use) vs. site_config.js's + // siteSlug (the multi-site replication identity shown on the + // Multi-Site modal, sourced only from a separately-set SITE_SLUG env + // var). They coincidentally share the name "site slug" but nothing + // ever kept them in sync -- a real deployment could show "E2E Site" + // in the Directory tree and "site-default" on the Multi-Site modal + // for the exact same node. Sync them here, the moment this node's own + // site Resource is created (bootstrap.js's first call), so there's + // one real identity instead of two that can drift apart. Only for a + // still-default master: never overwrite a real multi-site identity a + // join/promote has already established, and a spoke's replication + // identity is the master's to assign, not this node's own resource + // creation to decide. + const cfg = siteConfig.get(); + if (cfg.isMaster && cfg.siteSlug === 'site-default') { + siteConfig.save({ siteSlug: r.slug }); + } } else if (gKind && ancestorSite) { await ensureSiteGroups(ancestorSite, req.user.dn, r.name); // backfill site tier if missing await provisionResourceGroups(r, gKind, ancestorSite, req.user.dn); diff --git a/test/multisite_join_e2e.js b/test/multisite_join_e2e.js index c3a64b3..f6062f3 100644 --- a/test/multisite_join_e2e.js +++ b/test/multisite_join_e2e.js @@ -172,6 +172,12 @@ async function main() { }); if (siteRes.status !== 200) fail(`seeding pre-join site on master failed: ${siteRes.status} ${JSON.stringify(siteRes.body)}`); + step('Verifying the Directory site Resource\'s slug synced into the multi-site replication identity'); + const { body: masterCfgAfterSite } = await api(MASTER_URL, '/api/site/config', { token: masterToken }); + if (masterCfgAfterSite.config.siteSlug !== 'site_e2e') { + fail(`expected site_config's siteSlug to sync to the new site Resource's slug (site_e2e), got ${JSON.stringify(masterCfgAfterSite.config.siteSlug)}`); + } + const seedRes = await api(MASTER_URL, '/api/directory-admin/resources', { method: 'POST', token: masterToken,