From 35cb9f86989e0acc0bf52c058ed054b05b5625a2 Mon Sep 17 00:00:00 2001 From: tovernaar123 <56041037+tovernaar123@users.noreply.github.com> Date: Mon, 28 Dec 2020 03:40:28 +0100 Subject: [PATCH] Add bind_address option (#349) Add option to set the IP address the master server binds its HTTP and HTTPS ports to. --- docs/configuration.md | 11 +++++++++++ packages/lib/config/definitions.js | 7 +++++++ packages/master/master.js | 5 +++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 4e71f8e8..4951fe5d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -32,6 +32,17 @@ of this and master.http_port needs to be set to a port. Defaults to 8443. +### master.bind_address + +IP address to bind the HTTP and HTTPS ports on. Useful to limit which +interface to accept connections from. If set to null the unspecified +IPv6 address will be used, which on most systems means it will also +listen on the unspecified IPv4 address and accept connections from all +interfaces. + +Defaults to null. + + ### master.external_address External address the master server is accessible on. Currently only diff --git a/packages/lib/config/definitions.js b/packages/lib/config/definitions.js index d15406ce..2d342b9b 100644 --- a/packages/lib/config/definitions.js +++ b/packages/lib/config/definitions.js @@ -33,6 +33,13 @@ MasterGroup.define({ optional: true, initial_value: 8443, }); +MasterGroup.define({ + name: "bind_address", + title: "Bind Address", + description: "IP address to bind the HTTP and HTTPS ports on.", + type: "string", + optional: true, +}); MasterGroup.define({ name: "external_address", title: "External Address", diff --git a/packages/master/master.js b/packages/master/master.js index f511e05e..c2c2b0f7 100755 --- a/packages/master/master.js +++ b/packages/master/master.js @@ -1943,6 +1943,7 @@ async function startServer() { // Make sure we're actually going to listen on a port let httpPort = masterConfig.get("master.http_port"); let httpsPort = masterConfig.get("master.https_port"); + let bindAddress = masterConfig.get("master.bind_address") || ""; if (!httpPort && !httpsPort) { logger.fatal("Error: at least one of http_port and https_port must be configured"); process.exit(1); @@ -1980,7 +1981,7 @@ async function startServer() { // Only start listening for connections after all plugins have loaded if (httpPort) { httpServer = new (require("http").Server)(app); - await listen(httpServer, httpPort); + await listen(httpServer, httpPort, bindAddress); logger.info(`Listening for HTTP on port ${httpServer.address().port}`); } @@ -2000,7 +2001,7 @@ async function startServer() { key: privateKey, cert: certificate, }, app); - await listen(httpsServer, httpsPort); + await listen(httpsServer, httpsPort, bindAddress); logger.info(`Listening for HTTPS on port ${httpsServer.address().port}`); } }