esl / MongooseIM

MongooseIM is Erlang Solutions' robust, scalable and efficient XMPP server, aimed at large installations. Specifically designed for enterprise purposes, it is fault-tolerant and can utilise the resources of multiple clustered machines.
Other
1.67k stars 427 forks source link

Unable to connect to (local) MongooseIM instance running in docker #3487

Closed larshei closed 2 years ago

larshei commented 2 years ago

MongooseIM version: latest docker (5.0.0)

For a mobile app with chat I have been running a mongooseim instance in a docker container. The app did not connect to mongooseim directly. Instead, it communicated with my app server, which would then use the admin API to send messages in mongooseim.

I would like to have the mobile app connect to the mongooseim instance directly. However, I cannot figure out how to connect.

My docker instance is running with the following config:

[general]
  loglevel = "all"
  hosts = ["mymongooseim.com"]
  default_server_domain = "mymongooseim.com"
  language = "en"

[auth]
  methods = ["dummy"]

  [auth.dummy]

I tried to setup gajim, but somehow that didn't work on my Mac (some stuff seems to be missing). Right now, I am using profanity.

I tried to connect with

/connect me@mymongooseim.com server 127.0.0.1 tls disable port 5222

but immediately get a Login failed after entering the password. Using different combinations with hosts and _default_serverdomain set to localhost or 127.0.0.1 did not change the result.

I tried to connect to an instance running in EC2 (also using docker), using a similar /connect command. At first I forgot to open the port in AWS, so the connection attempt took 5 seconds and then failed. After opening the port, it fails "immediately" (as in: feels instant in the console).

Neither my local nor my server setup produce any log message with log level set to "debug".

I was wondering if I cannot log in because the user is not registered and tried to register one, but it seems mongooseimctl is not available in the docker image. Is that correct? Should there be any log messages for a log in attempt? Am I forgetting something in the config? Is there a trick I do not know when using the docker image?

larshei commented 2 years ago

but it seems mongooseimctl is not available in the docker image

I just had to use the full path /usr/lib/mongooseim/bin/mongooseimctl. However, now I am back to some problems that I apparantly already had half a year ago.

arcusfelis commented 2 years ago

ok, dummy would authorize anyone with any password (it's for testing after all). Your config file looks small. MongooseIM requires listeners to be configured, so you can connect somewhere.

i.e. here is a config example we use for testing, you can learn something useful from there (also, careful, you probably don't need all of that, it is just an example for the listeners section and how to configure rdbms backend, the more info is in docs):

[general]
  loglevel = "warning"
  hosts = ["localhost", "anonymous.localhost", "localhost.bis"]
  host_types = ["test type", "dummy auth", "anonymous"]
  default_server_domain = "localhost"
  registration_timeout = "infinity"
  language = "en"
  all_metrics_are_global = false
  sm_backend = "mnesia"
  max_fsm_queue = 1000

[[listen.http]]
  port = 5280
  transport.num_acceptors = 10
  transport.max_connections = 1024

  [[listen.http.handlers.mod_bosh]]
    host = "_"
    path = "/http-bind"

  [[listen.http.handlers.mod_websockets]]
    host = "_"
    path = "/ws-xmpp"

    [listen.http.handlers.mod_websockets.service]
      access = "all"
      shaper_rule = "fast"
      password = "secret"

[[listen.http]]
  port = 5285
  transport.num_acceptors = 10
  transport.max_connections = 1024
  tls.certfile = "priv/ssl/fake_cert.pem"
  tls.keyfile = "priv/ssl/fake_key.pem"
  tls.password =  ""

  [[listen.http.handlers.mod_bosh]]
    host = "_"
    path = "/http-bind"

  [[listen.http.handlers.mod_websockets]]
    host = "_"
    path = "/ws-xmpp"

[[listen.http]]
  ip_address = "127.0.0.1"
  port = 8088
  transport.num_acceptors = 10
  transport.max_connections = 1024

  [[listen.http.handlers.mongoose_api_admin]]
    host = "localhost"
    path = "/api"
  [[listen.http.handlers.mongoose_domain_handler]]
    host = "localhost"
    path = "/api"

[[listen.http]]
  port = 8089
  transport.num_acceptors = 10
  transport.max_connections = 1024
  protocol.compress = true
  tls.certfile = "priv/ssl/fake_cert.pem"
  tls.keyfile = "priv/ssl/fake_key.pem"
  tls.password =  ""

  [[listen.http.handlers.lasse_handler]]
    host = "_"
    path = "/api/sse"
    module = "mongoose_client_api_sse"

  [[listen.http.handlers.mongoose_client_api_messages]]
    host = "_"
    path = "/api/messages/[:with]"

  [[listen.http.handlers.mongoose_client_api_contacts]]
    host = "_"
    path = "/api/contacts/[:jid]"

  [[listen.http.handlers.mongoose_client_api_rooms]]
    host = "_"
    path = "/api/rooms/[:id]"

  [[listen.http.handlers.mongoose_client_api_rooms_config]]
    host = "_"
    path = "/api/rooms/[:id]/config"

  [[listen.http.handlers.mongoose_client_api_rooms_users]]
    host = "_"
    path = "/api/rooms/:id/users/[:user]"

  [[listen.http.handlers.mongoose_client_api_rooms_messages]]
    host = "_"
    path = "/api/rooms/[:id]/messages"

  [[listen.http.handlers.cowboy_swagger_redirect_handler]]
    host = "_"
    path = "/api-docs"

  [[listen.http.handlers.cowboy_swagger_json_handler]]
    host = "_"
    path = "/api-docs/swagger.json"

  [[listen.http.handlers.cowboy_static]]
    host = "_"
    path = "/api-docs/[...]"
    type = "priv_dir"
    app = "cowboy_swagger"
    content_path = "swagger"

[[listen.http]]
  ip_address = "127.0.0.1"
  port = 5551
  transport.num_acceptors = 10
  transport.max_connections = 1024

  [[listen.http.handlers.mongoose_graphql_cowboy_handler]]
    host = "localhost"
    path = "/api/graphql"
    schema_endpoint = "admin"
    username = "admin"
    password = "secret"

[[listen.http]]
  ip_address = "0.0.0.0"
  port = 5561
  transport.num_acceptors = 10
  transport.max_connections = 1024

  [[listen.http.handlers.mongoose_graphql_cowboy_handler]]
    host = "_"
    path = "/api/graphql"
    schema_endpoint = "user"

[[listen.http]]
  ip_address = "127.0.0.1"
  port = 5288
  transport.num_acceptors = 10
  transport.max_connections = 1024

  [[listen.http.handlers.mongoose_api]]
    host = "localhost"
    path = "/api"
    handlers = ["mongoose_api_metrics", "mongoose_api_users"]

[[listen.c2s]]
  port = 5222
  zlib = 10_000
  access = "c2s"
  shaper = "c2s_shaper"
  max_stanza_size = 65536
  tls.certfile = "priv/ssl/fake_server.pem"
  tls.mode = "starttls"
  tls.dhfile = "priv/ssl/fake_dh_server.pem"

[[listen.c2s]]
  port = 5223
  zlib = 4096
  access = "c2s"
  shaper = "c2s_shaper"
  max_stanza_size = 65536

[[listen.s2s]]
  port = 5269
  shaper = "s2s_shaper"
  max_stanza_size = 131072
  tls.dhfile = "priv/ssl/fake_dh_server.pem"

[[listen.service]]
  port = 8888
  access = "all"
  shaper_rule = "fast"
  ip_address = "127.0.0.1"
  password = "secret"

[[listen.service]]
  port = 8666
  access = "all"
  conflict_behaviour = "kick_old"
  shaper_rule = "fast"
  ip_address = "127.0.0.1"
  password = "secret"

[[listen.service]]
  port = 8189
  access = "all"
  hidden_components = true
  shaper_rule = "fast"
  ip_address = "127.0.0.1"
  password = "secret"

[auth]
  methods = ["rdbms"]
  password.format = "scram"
  password.hash = ["sha256"]
  scram_iterations = 64
  sasl_external = ["standard"]

[outgoing_pools.redis.global_distrib]
  scope = "global"
  workers = 10
[outgoing_pools.rdbms.default]
  scope = "global"
  workers = 5
  connection.driver = "pgsql"
  connection.host = "localhost"
  connection.database = "ejabberd"
  connection.username = "ejabberd"
  connection.password = "mongooseim_secret"
  connection.tls.required = true
  connection.tls.verify_peer = true
  connection.tls.cacertfile = "priv/ssl/cacert.pem"
  connection.tls.server_name_indication = false

[services.service_admin_extra]
  submods = ["node", "accounts", "sessions", "vcard", "gdpr", "upload",
             "roster", "last", "private", "stanza", "stats", "domain"]

[services.service_mongoose_system_metrics]
  initial_report = 300_000
  periodic_report = 10_800_000

[services.service_domain_db]

[modules.mod_adhoc]

[modules.mod_amp]

[modules.mod_disco]
  users_can_see_hidden_services = false

[modules.mod_commands]

[modules.mod_cache_users]
  time_to_live = 2
  number_of_segments = 5

[modules.mod_muc_commands]

[modules.mod_muc_light_commands]

[modules.mod_stream_management]

[modules.mod_register]
  welcome_message = {body = "", subject = ""}
  ip_access = [
    {address = "127.0.0.0/8", policy = "allow"},
    {address = "0.0.0.0/0", policy = "deny"}
  ]
  access = "register"

[modules.mod_roster]
  backend = "rdbms"

[modules.mod_sic]

[modules.mod_vcard]
  backend = "rdbms"
  host = "vjud.@HOST@"

[modules.mod_bosh]

[modules.mod_carboncopy]

[shaper.normal]
  max_rate = 1000

[shaper.fast]
  max_rate = 50_000

[shaper.mam_shaper]
  max_rate = 1

[shaper.mam_global_shaper]
  max_rate = 1000

[acl]
  local = [
    {user_regexp = ""}
  ]

[access]
  max_user_sessions = [
    {acl = "all", value = 10}
  ]

  max_user_offline_messages = [
    {acl = "admin", value = 5000},
    {acl = "all", value = 100}
  ]

  local = [
    {acl = "local", value = "allow"}
  ]

  c2s = [
    {acl = "blocked", value = "deny"},
    {acl = "all", value = "allow"}
  ]

  c2s_shaper = [
    {acl = "admin", value = "none"},
    {acl = "all", value = "normal"}
  ]

  s2s_shaper = [
    {acl = "all", value = "fast"}
  ]

  muc_admin = [
    {acl = "admin", value = "allow"}
  ]

  muc_create = [
    {acl = "local", value = "allow"}
  ]

  muc = [
    {acl = "all", value = "allow"}
  ]

  register = [
    {acl = "all", value = "allow"}
  ]

  mam_set_prefs = [
    {acl = "all", value = "default"}
  ]

  mam_get_prefs = [
    {acl = "all", value = "default"}
  ]

  mam_lookup_messages = [
    {acl = "all", value = "default"}
  ]

  mam_set_prefs_shaper = [
    {acl = "all", value = "mam_shaper"}
  ]

  mam_get_prefs_shaper = [
    {acl = "all", value = "mam_shaper"}
  ]

  mam_lookup_messages_shaper = [
    {acl = "all", value = "mam_shaper"}
  ]

  mam_set_prefs_global_shaper = [
    {acl = "all", value = "mam_global_shaper"}
  ]

  mam_get_prefs_global_shaper = [
    {acl = "all", value = "mam_global_shaper"}
  ]

  mam_lookup_messages_global_shaper = [
    {acl = "all", value = "mam_global_shaper"}
  ]

[s2s]
  use_starttls = "optional"
  certfile = "priv/ssl/fake_server.pem"
  default_policy = "allow"
  outgoing.port = 5299

  [[s2s.address]]
    host = "fed1"
    ip_address = "127.0.0.1"

[[host_config]]
  host = "anonymous.localhost"

  [host_config.auth]
    methods = ["anonymous"]
    anonymous.allow_multiple_connections = true
    anonymous.protocol = "both"

[[host_config]]
  host_type = "anonymous"
  modules = { }

  [host_config.auth]
    methods = ["anonymous"]
    anonymous.allow_multiple_connections = true
    anonymous.protocol = "both"

[[host_config]]
  host_type = "dummy auth"

  auth.methods = ["dummy"]
  auth.dummy.base_time = 1
  auth.dummy.variance = 5

  modules = {}
larshei commented 2 years ago

Thanks for the example. Very helpful. The listener was missing.