diff --git a/appservice/appservice.go b/appservice/appservice.go index e52db2c2..3a1c4677 100644 --- a/appservice/appservice.go +++ b/appservice/appservice.go @@ -82,7 +82,9 @@ func SetupAppServiceAPIComponent( Cfg: base.Cfg, } - appserviceQueryAPI.SetupHTTP(http.DefaultServeMux) + if base.EnableHTTPAPIs { + appserviceQueryAPI.SetupHTTP(http.DefaultServeMux) + } consumer := consumers.NewOutputRoomEventConsumer( base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB, diff --git a/cmd/dendrite-appservice-server/main.go b/cmd/dendrite-appservice-server/main.go index 91ca707e..faf9ade3 100644 --- a/cmd/dendrite-appservice-server/main.go +++ b/cmd/dendrite-appservice-server/main.go @@ -22,7 +22,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI") + base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI", true) defer base.Close() // nolint: errcheck accountDB := base.CreateAccountsDB() diff --git a/cmd/dendrite-client-api-server/main.go b/cmd/dendrite-client-api-server/main.go index 1ce66db2..d4ab9e42 100644 --- a/cmd/dendrite-client-api-server/main.go +++ b/cmd/dendrite-client-api-server/main.go @@ -26,7 +26,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "ClientAPI") + base := basecomponent.NewBaseDendrite(cfg, "ClientAPI", true) defer base.Close() // nolint: errcheck accountDB := base.CreateAccountsDB() diff --git a/cmd/dendrite-demo-libp2p/p2pdendrite.go b/cmd/dendrite-demo-libp2p/p2pdendrite.go index a9db3b39..831b5d7f 100644 --- a/cmd/dendrite-demo-libp2p/p2pdendrite.go +++ b/cmd/dendrite-demo-libp2p/p2pdendrite.go @@ -54,7 +54,7 @@ type P2PDendrite struct { // The componentName is used for logging purposes, and should be a friendly name // of the component running, e.g. SyncAPI. func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite { - baseDendrite := basecomponent.NewBaseDendrite(cfg, componentName) + baseDendrite := basecomponent.NewBaseDendrite(cfg, componentName, false) ctx, cancel := context.WithCancel(context.Background()) diff --git a/cmd/dendrite-edu-server/main.go b/cmd/dendrite-edu-server/main.go index a4511f1b..98b05e64 100644 --- a/cmd/dendrite-edu-server/main.go +++ b/cmd/dendrite-edu-server/main.go @@ -23,7 +23,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "EDUServerAPI") + base := basecomponent.NewBaseDendrite(cfg, "EDUServerAPI", true) defer func() { if err := base.Close(); err != nil { logrus.WithError(err).Warn("BaseDendrite close failed") diff --git a/cmd/dendrite-federation-api-server/main.go b/cmd/dendrite-federation-api-server/main.go index d829326a..b3757020 100644 --- a/cmd/dendrite-federation-api-server/main.go +++ b/cmd/dendrite-federation-api-server/main.go @@ -25,7 +25,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "FederationAPI") + base := basecomponent.NewBaseDendrite(cfg, "FederationAPI", true) defer base.Close() // nolint: errcheck accountDB := base.CreateAccountsDB() diff --git a/cmd/dendrite-federation-sender-server/main.go b/cmd/dendrite-federation-sender-server/main.go index 0daac1bc..c9bf6688 100644 --- a/cmd/dendrite-federation-sender-server/main.go +++ b/cmd/dendrite-federation-sender-server/main.go @@ -22,7 +22,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "FederationSender") + base := basecomponent.NewBaseDendrite(cfg, "FederationSender", true) defer base.Close() // nolint: errcheck federation := base.CreateFederationClient() diff --git a/cmd/dendrite-key-server/main.go b/cmd/dendrite-key-server/main.go index 5b2166d9..aca666fa 100644 --- a/cmd/dendrite-key-server/main.go +++ b/cmd/dendrite-key-server/main.go @@ -21,7 +21,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "KeyServer") + base := basecomponent.NewBaseDendrite(cfg, "KeyServer", true) defer base.Close() // nolint: errcheck accountDB := base.CreateAccountsDB() diff --git a/cmd/dendrite-media-api-server/main.go b/cmd/dendrite-media-api-server/main.go index a818db73..cfb32173 100644 --- a/cmd/dendrite-media-api-server/main.go +++ b/cmd/dendrite-media-api-server/main.go @@ -21,7 +21,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "MediaAPI") + base := basecomponent.NewBaseDendrite(cfg, "MediaAPI", true) defer base.Close() // nolint: errcheck deviceDB := base.CreateDeviceDB() diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index f2261061..23959152 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -41,15 +41,16 @@ import ( ) var ( - httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server") - httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server") - certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS") - keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS") + httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server") + httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server") + certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS") + keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS") + enableHTTPAPIs = flag.Bool("api", false, "Expose internal HTTP APIs in monolith mode") ) func main() { cfg := basecomponent.ParseMonolithFlags() - base := basecomponent.NewBaseDendrite(cfg, "Monolith") + base := basecomponent.NewBaseDendrite(cfg, "Monolith", *enableHTTPAPIs) defer base.Close() // nolint: errcheck accountDB := base.CreateAccountsDB() diff --git a/cmd/dendrite-public-rooms-api-server/main.go b/cmd/dendrite-public-rooms-api-server/main.go index c3b49f4f..0eb2fcb5 100644 --- a/cmd/dendrite-public-rooms-api-server/main.go +++ b/cmd/dendrite-public-rooms-api-server/main.go @@ -23,7 +23,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "PublicRoomsAPI") + base := basecomponent.NewBaseDendrite(cfg, "PublicRoomsAPI", true) defer base.Close() // nolint: errcheck deviceDB := base.CreateDeviceDB() diff --git a/cmd/dendrite-room-server/main.go b/cmd/dendrite-room-server/main.go index 17246844..4d450bd4 100644 --- a/cmd/dendrite-room-server/main.go +++ b/cmd/dendrite-room-server/main.go @@ -22,7 +22,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI") + base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI", true) defer base.Close() // nolint: errcheck keyDB := base.CreateKeyDB() federation := base.CreateFederationClient() diff --git a/cmd/dendrite-sync-api-server/main.go b/cmd/dendrite-sync-api-server/main.go index 259447af..7aadd6a7 100644 --- a/cmd/dendrite-sync-api-server/main.go +++ b/cmd/dendrite-sync-api-server/main.go @@ -21,7 +21,7 @@ import ( func main() { cfg := basecomponent.ParseFlags() - base := basecomponent.NewBaseDendrite(cfg, "SyncAPI") + base := basecomponent.NewBaseDendrite(cfg, "SyncAPI", true) defer base.Close() // nolint: errcheck deviceDB := base.CreateDeviceDB() diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 5b7ed480..75fe2361 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -108,7 +108,7 @@ func main() { if err := cfg.Derive(); err != nil { logrus.Fatalf("Failed to derive values from config: %s", err) } - base := basecomponent.NewBaseDendrite(cfg, "Monolith") + base := basecomponent.NewBaseDendrite(cfg, "Monolith", false) defer base.Close() // nolint: errcheck accountDB := base.CreateAccountsDB() diff --git a/common/basecomponent/base.go b/common/basecomponent/base.go index 4342e25a..234de5e7 100644 --- a/common/basecomponent/base.go +++ b/common/basecomponent/base.go @@ -58,6 +58,7 @@ type BaseDendrite struct { // APIMux should be used to register new public matrix api endpoints APIMux *mux.Router + EnableHTTPAPIs bool httpClient *http.Client Cfg *config.Dendrite ImmutableCache caching.ImmutableCache @@ -71,7 +72,7 @@ const HTTPClientTimeout = time.Second * 30 // NewBaseDendrite creates a new instance to be used by a component. // The componentName is used for logging purposes, and should be a friendly name // of the compontent running, e.g. "SyncAPI" -func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite { +func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs bool) *BaseDendrite { common.SetupStdLogging() common.SetupHookLogging(cfg.Logging, componentName) common.SetupPprof() @@ -96,6 +97,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite { return &BaseDendrite{ componentName: componentName, + EnableHTTPAPIs: enableHTTPAPIs, tracerCloser: closer, Cfg: cfg, ImmutableCache: cache, diff --git a/eduserver/eduserver.go b/eduserver/eduserver.go index 8ddd2c52..2a209364 100644 --- a/eduserver/eduserver.go +++ b/eduserver/eduserver.go @@ -35,6 +35,9 @@ func SetupEDUServerComponent( OutputTypingEventTopic: string(base.Cfg.Kafka.Topics.OutputTypingEvent), } - inputAPI.SetupHTTP(http.DefaultServeMux) + if base.EnableHTTPAPIs { + inputAPI.SetupHTTP(http.DefaultServeMux) + } + return inputAPI } diff --git a/federationsender/federationsender.go b/federationsender/federationsender.go index 8e2f256d..9c151a8d 100644 --- a/federationsender/federationsender.go +++ b/federationsender/federationsender.go @@ -71,7 +71,10 @@ func SetupFederationSenderComponent( federationSenderDB, base.Cfg, roomserverProducer, federation, keyRing, statistics, ) - queryAPI.SetupHTTP(http.DefaultServeMux) + + if base.EnableHTTPAPIs { + queryAPI.SetupHTTP(http.DefaultServeMux) + } return queryAPI } diff --git a/roomserver/roomserver.go b/roomserver/roomserver.go index 450da5bb..aa5d223e 100644 --- a/roomserver/roomserver.go +++ b/roomserver/roomserver.go @@ -51,7 +51,9 @@ func SetupRoomServerComponent( KeyRing: keyRing, } - internalAPI.SetupHTTP(http.DefaultServeMux) + if base.EnableHTTPAPIs { + internalAPI.SetupHTTP(http.DefaultServeMux) + } return &internalAPI }