feat(controller-peers-env-fallback): refuse an env-supplied peers list without the controller's own name (task 2.4)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
64d3429cd8
commit
9018980b08
3 changed files with 79 additions and 1 deletions
|
|
@ -495,6 +495,36 @@ int main(int argc, char* argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* Req 1.6: a list taken from the environment must name this
|
||||
* controller, or a stray variable would silently join it to a
|
||||
* cluster it is not part of. Refuse before the cert pre-flight and
|
||||
* any network activity. An explicit --peers keeps its existing
|
||||
* handling (the later refusal in cluster_open_listener()). */
|
||||
if (peers_from_env &&
|
||||
xce_peers_find_identity(&myconf.peers_cfg, arguments.myname) < 0) {
|
||||
char names[512];
|
||||
size_t used = 0;
|
||||
names[0] = '\0';
|
||||
for (int i = 0; i < myconf.peers_cfg.candidates_count; i++) {
|
||||
const xce_candidate_t* c = &myconf.peers_cfg.candidates[i];
|
||||
int n = snprintf(names + used, sizeof(names) - used, "%s%s",
|
||||
i > 0 ? ", " : "",
|
||||
c->name[0] != '\0' ? c->name : c->hostname);
|
||||
if (n < 0 || (size_t)n >= sizeof(names) - used) {
|
||||
names[used] = '\0'; /* drop the partial last name */
|
||||
break;
|
||||
}
|
||||
used += (size_t)n;
|
||||
}
|
||||
fprintf(stderr,
|
||||
"xce_controller: XCE_CONTROLLER_PEERS (%s) has no "
|
||||
"candidate named '%s'; pass --myname <one of: %s> or "
|
||||
"unset XCE_CONTROLLER_PEERS to run standalone\n",
|
||||
peers_str, arguments.myname, names);
|
||||
mylog_fini();
|
||||
return 1;
|
||||
}
|
||||
|
||||
strncpy(myconf.peers_cfg.identity, arguments.myname,
|
||||
sizeof(myconf.peers_cfg.identity) - 1);
|
||||
INFO("HA mode: %d controller candidates, identity=%s%s",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue