mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-03 16:04:50 -04:00
Add config option to use non-default manhole password and keys (#10643)
This commit is contained in:
parent
b298de780a
commit
6e895366ea
9 changed files with 161 additions and 17 deletions
|
@ -25,11 +25,14 @@ import attr
|
|||
import yaml
|
||||
from netaddr import AddrFormatError, IPNetwork, IPSet
|
||||
|
||||
from twisted.conch.ssh.keys import Key
|
||||
|
||||
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS
|
||||
from synapse.util.module_loader import load_module
|
||||
from synapse.util.stringutils import parse_and_validate_server_name
|
||||
|
||||
from ._base import Config, ConfigError
|
||||
from ._util import validate_config
|
||||
|
||||
logger = logging.Logger(__name__)
|
||||
|
||||
|
@ -216,6 +219,16 @@ class ListenerConfig:
|
|||
http_options = attr.ib(type=Optional[HttpListenerConfig], default=None)
|
||||
|
||||
|
||||
@attr.s(frozen=True)
|
||||
class ManholeConfig:
|
||||
"""Object describing the configuration of the manhole"""
|
||||
|
||||
username = attr.ib(type=str, validator=attr.validators.instance_of(str))
|
||||
password = attr.ib(type=str, validator=attr.validators.instance_of(str))
|
||||
priv_key = attr.ib(type=Optional[Key])
|
||||
pub_key = attr.ib(type=Optional[Key])
|
||||
|
||||
|
||||
class ServerConfig(Config):
|
||||
section = "server"
|
||||
|
||||
|
@ -649,6 +662,41 @@ class ServerConfig(Config):
|
|||
)
|
||||
)
|
||||
|
||||
manhole_settings = config.get("manhole_settings") or {}
|
||||
validate_config(
|
||||
_MANHOLE_SETTINGS_SCHEMA, manhole_settings, ("manhole_settings",)
|
||||
)
|
||||
|
||||
manhole_username = manhole_settings.get("username", "matrix")
|
||||
manhole_password = manhole_settings.get("password", "rabbithole")
|
||||
manhole_priv_key_path = manhole_settings.get("ssh_priv_key_path")
|
||||
manhole_pub_key_path = manhole_settings.get("ssh_pub_key_path")
|
||||
|
||||
manhole_priv_key = None
|
||||
if manhole_priv_key_path is not None:
|
||||
try:
|
||||
manhole_priv_key = Key.fromFile(manhole_priv_key_path)
|
||||
except Exception as e:
|
||||
raise ConfigError(
|
||||
f"Failed to read manhole private key file {manhole_priv_key_path}"
|
||||
) from e
|
||||
|
||||
manhole_pub_key = None
|
||||
if manhole_pub_key_path is not None:
|
||||
try:
|
||||
manhole_pub_key = Key.fromFile(manhole_pub_key_path)
|
||||
except Exception as e:
|
||||
raise ConfigError(
|
||||
f"Failed to read manhole public key file {manhole_pub_key_path}"
|
||||
) from e
|
||||
|
||||
self.manhole_settings = ManholeConfig(
|
||||
username=manhole_username,
|
||||
password=manhole_password,
|
||||
priv_key=manhole_priv_key,
|
||||
pub_key=manhole_pub_key,
|
||||
)
|
||||
|
||||
metrics_port = config.get("metrics_port")
|
||||
if metrics_port:
|
||||
logger.warning(METRICS_PORT_WARNING)
|
||||
|
@ -715,7 +763,7 @@ class ServerConfig(Config):
|
|||
if not isinstance(templates_config, dict):
|
||||
raise ConfigError("The 'templates' section must be a dictionary")
|
||||
|
||||
self.custom_template_directory = templates_config.get(
|
||||
self.custom_template_directory: Optional[str] = templates_config.get(
|
||||
"custom_template_directory"
|
||||
)
|
||||
if self.custom_template_directory is not None and not isinstance(
|
||||
|
@ -727,7 +775,13 @@ class ServerConfig(Config):
|
|||
return any(listener.tls for listener in self.listeners)
|
||||
|
||||
def generate_config_section(
|
||||
self, server_name, data_dir_path, open_private_ports, listeners, **kwargs
|
||||
self,
|
||||
server_name,
|
||||
data_dir_path,
|
||||
open_private_ports,
|
||||
listeners,
|
||||
config_dir_path,
|
||||
**kwargs,
|
||||
):
|
||||
ip_range_blacklist = "\n".join(
|
||||
" # - '%s'" % ip for ip in DEFAULT_IP_RANGE_BLACKLIST
|
||||
|
@ -1068,6 +1122,24 @@ class ServerConfig(Config):
|
|||
# bind_addresses: ['::1', '127.0.0.1']
|
||||
# type: manhole
|
||||
|
||||
# Connection settings for the manhole
|
||||
#
|
||||
manhole_settings:
|
||||
# The username for the manhole. This defaults to 'matrix'.
|
||||
#
|
||||
#username: manhole
|
||||
|
||||
# The password for the manhole. This defaults to 'rabbithole'.
|
||||
#
|
||||
#password: mypassword
|
||||
|
||||
# The private and public SSH key pair used to encrypt the manhole traffic.
|
||||
# If these are left unset, then hardcoded and non-secret keys are used,
|
||||
# which could allow traffic to be intercepted if sent over a public network.
|
||||
#
|
||||
#ssh_priv_key_path: %(config_dir_path)s/id_rsa
|
||||
#ssh_pub_key_path: %(config_dir_path)s/id_rsa.pub
|
||||
|
||||
# Forward extremities can build up in a room due to networking delays between
|
||||
# homeservers. Once this happens in a large room, calculation of the state of
|
||||
# that room can become quite expensive. To mitigate this, once the number of
|
||||
|
@ -1436,3 +1508,14 @@ def _warn_if_webclient_configured(listeners: Iterable[ListenerConfig]) -> None:
|
|||
if name == "webclient":
|
||||
logger.warning(NO_MORE_WEB_CLIENT_WARNING)
|
||||
return
|
||||
|
||||
|
||||
_MANHOLE_SETTINGS_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {"type": "string"},
|
||||
"password": {"type": "string"},
|
||||
"ssh_priv_key_path": {"type": "string"},
|
||||
"ssh_pub_key_path": {"type": "string"},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue