diff --git a/ChangeLog b/ChangeLog index 0e284ba33..071b52c94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-04-17 Badlop + * doc/guide.tex: Document new ejabberdctl option. New section that + documents AccessCommands. (EJAB-910) + * doc/guide.html: Likewise + * src/ejabberd_ctl.erl: New option to require auth in ejabberdctl and restrict what commands and arguments can execute (EJAB-910) * src/ejabberd_config.erl: Likewise diff --git a/doc/guide.html b/doc/guide.html index a51a02a42..7b8d5dd00 100644 --- a/doc/guide.html +++ b/doc/guide.html @@ -165,48 +165,53 @@ BLOCKQUOTE.figure DIV.center DIV.center HR{display:none;} -
  • Chapter 5  Securing ejabberd +
  • 4.2  ejabberd Commands -
  • Chapter 6  Clustering +
  • 4.3  Web Admin +
  • 4.4  Ad-hoc Commands +
  • 4.5  Change Computer Hostname +
  • +
  • Chapter 5  Securing ejabberd +
  • Chapter 6  Clustering -
  • 6.2  Clustering Setup -
  • 6.3  Service Load-Balancing +6.1  How it Works -
  • -
  • Chapter 7  Debugging +
  • 6.2  Clustering Setup +
  • 6.3  Service Load-Balancing -
  • Appendix A  Internationalization and Localization -
  • Appendix B  Release Notes -
  • Appendix C  Acknowledgements -
  • Appendix D  Copyright Information +
  • +
  • Chapter 7  Debugging + +
  • Appendix A  Internationalization and Localization +
  • Appendix B  Release Notes +
  • Appendix C  Acknowledgements +
  • Appendix D  Copyright Information
  • Chapter 1  Introduction

    ejabberd is a free and open source instant messaging server written in Erlang.

    ejabberd is cross-platform, distributed, fault-tolerant, and based on open standards to achieve real-time communication.

    ejabberd is designed to be a rock-solid and feature rich XMPP server.

    ejabberd is suitable for small deployments, whether they need to be scalable or not, as well as extremely big deployments.

    @@ -795,7 +800,7 @@ and also allows plain connections for old clients.
  • Port 5269 listens for s2s connections with STARTTLS. The socket is set for IPv6 instead of IPv4.
  • Port 5280 listens for HTTP requests, and serves the HTTP Poll service.
  • Port 5281 listens for HTTP requests, and serves the Web Admin using HTTPS as explained in -section 4.2. The socket only listens connections to the IP address 127.0.0.1. +section 4.3. The socket only listens connections to the IP address 127.0.0.1.
  • {hosts, ["example.com", "example.org", "example.net"]}.
     {listen,
      [
    @@ -839,7 +844,7 @@ only two servers can connect: "jabber.example.org" and "example.com".
     
  • Port 5280 is serving the Web Admin and the HTTP Polling service in all the IPv4 addresses. Note that it is also possible to serve them on different ports. The second -example in section 4.2 shows how exactly this can be done. +example in section 4.3 shows how exactly this can be done.
  • All users except for the administrators have a traffic of limit 1,000 Bytes/second
  • The @@ -2953,9 +2958,19 @@ The default value is true. the processing discipline for Software Version (jabber:iq:version) IQ queries (see section 3.3.2).

    Chapter 4  Managing an ejabberd Server

    -

    4.1  ejabberdctl

    -

    4.1.1  Commands

    The ejabberdctl command line administration script allows to start, stop and perform -many other administrative tasks in a local or remote ejabberd server.

    When ejabberdctl is executed without any parameter, +

    4.1  ejabberdctl

    With the ejabberdctl command line administration script +you can execute ejabberdctl commands (described in the next section, 4.1.1) +and also many general ejabberd commands (described in section 4.2). +This means you can start, stop and perform many other administrative tasks +in a local or remote ejabberd server (by providing the argument --node NODENAME).

    The ejabberdctl script can be configured in the file ejabberdctl.cfg. +This file includes detailed information about each configurable option. See section 4.1.2.

    The ejabberdctl script returns a numerical status code. +Success is represented by 0, +error is represented by 1, +and other codes may be used for specific results. +This can be used by other scripts to determine automatically +if a command succeeded or failed, +for example using: echo $?

    +

    4.1.1  ejabberdctl Commands

    When ejabberdctl is executed without any parameter, it displays the available options. If there isn’t an ejabberd server running, the available parameters are:

    @@ -2963,45 +2978,34 @@ the available parameters are:
    debug
    Attach an Erlang shell to an already existing ejabberd server. This allows to execute commands interactively in the ejabberd server.
    live
    Start ejabberd in live mode: the shell keeps attached to the started server, showing log messages and allowing to execute interactive commands.

    If there is an ejabberd server running in the system, -ejabberdctl shows all the available commands in that server. -The more interesting ones are: +ejabberdctl shows the ejabberdctl commands described bellow +and all the ejabberd commands available in that server (see 4.2.1).

    The ejabberdctl commands are:

    help
    Get help about ejabberdctl or any available command. Try ejabberdctl help help.
    status
    Check the status of the ejabberd server. -
    stop
    Stop the ejabberd server which is running in the machine. -
    reopen-log
    Reopen the log files after they were renamed. -If the old files were not renamed before calling this command, -they are automatically renamed to "*-old.log". See section 7.1. -
    backup ejabberd.backup
    -Store internal Mnesia database to a binary backup file. -
    restore ejabberd.backup
    -Restore immediately from a binary backup file the internal Mnesia database. -This will consume quite some memory for big servers. -
    install-fallback ejabberd.backup
    -The binary backup file is installed as fallback: -it will be used to restore the database at the next ejabberd start. -Similar to restore, but requires less memory. -
    dump ejabberd.dump
    -Dump internal Mnesia database to a text file dump. -
    load ejabberd.dump
    -Restore immediately from a text file dump. -This is not recommended for big databases, as it will consume much time, -memory and processor. In that case it’s preferable to use backup and install-fallback. -
    import-file, import-dir
    -These options can be used to migrate from other Jabber/XMPP servers. There -exist tutorials to migrate from other software to ejabberd. -
    delete-expired-messages
    This option can be used to delete old messages -in offline storage. This might be useful when the number of offline messages -is very high. -

    The ejabberdctl script also allows the argument --node NODENAME. -This allows to administer a remote node.

    The ejabberdctl script can be configured in the file ejabberdctl.cfg. -This file includes detailed information about each configurable option.

    The ejabberdctl script returns a numerical status code. -Success is represented by 0, -error is represented by 1, -and other codes may be used for specific results. -This can be used by other scripts to determine automatically -if a command succeeded or failed, -for example using: echo $?

    +
    stop
    Stop the ejabberd server. +
    restart
    Restart the ejabberd server. +
    mnesia
    Get information about the Mnesia database. +

    The ejabberdctl script can be restricted to require authentication +and execute some ejabberd commands; see 4.2.2. +Add the option to the file ejabberd.cfg. +In this example there is no restriction: +

    {ejabberdctl_access_commands, []}.
    +

    If account robot1@example.org is registered in ejabberd with password abcdef +(which MD5 is E8B501798950FC58AAD83C8C14978E), +and ejabberd.cfg contains this setting: +

    {hosts, ["example.org"]}.
    +{acl, bots, {user, "robot1", "example.org"}}.
    +{access, ctlaccess, [{allow, bots}]}.
    +{ejabberdctl_access_commands, [ {ctlaccess, [registered_users, register], []} ]}.
    +

    then you can do this in the shell: +

    $ ejabberdctl registered_users example.org
    +Error: no_auth_provided
    +$ ejabberdctl --auth robot1 example.org E8B501798950FC58AAD83C8C14978E registered_users example.org
    +robot1
    +testuser1
    +testuser2
    +

    4.1.2  Erlang Runtime System

    ejabberd is an Erlang/OTP application that runs inside an Erlang runtime system. This system is configured using environment variables and command line parameters. The ejabberdctl administration script uses many of those possibilities. @@ -3070,8 +3074,102 @@ Starts the Erlang system detached from the system console. Open an Erlang shell in a remote Erlang node.

    Note that some characters need to be escaped when used in shell scripts, for instance " and {}. -You can find other options in the Erlang manual page (erl -man erl).

    -

    4.2  Web Admin

    +You can find other options in the Erlang manual page (erl -man erl).

    +

    4.2  ejabberd Commands

    An ejabberd command is an abstract function identified by a name, +with a defined number and type of calling arguments and type of result +that is registered in the ejabberd_commands service. +Those commands can be defined in any Erlang module and executed using any valid frontend.

    ejabberd includes a frontend to execute ejabberd commands: the script ejabberdctl. +Other known frontends that can be installed to execute ejabberd commands in different ways are: +ejabberd_xmlrpc (XML-RPC service), +mod_rest (HTTP POST service), +mod_shcommands (ejabberd WebAdmin page).

    +

    4.2.1  List of ejabberd Commands

    ejabberd includes a few ejabberd Commands by default. +When more modules are installed, new commands may be available in the frontends.

    The easiest way to get a list of the available commands, and get help for them is to use +the ejabberdctl script: +

    $ ejabberdctl help
    +Usage: ejabberdctl [--node nodename] [--auth user host password] command [options]
    +
    +Available commands in this ejabberd node:
    +  backup file                  Store the database to backup file
    +  connected_users              List all established sessions
    +  connected_users_number       Get the number of established sessions
    +  delete_expired_messages      Delete expired offline messages from database
    +  delete_old_messages days     Delete offline messages older than DAYS
    +  ...
    +

    The more interesting ones are: +

    +reopen-log
    Reopen the log files after they were renamed. +If the old files were not renamed before calling this command, +they are automatically renamed to "*-old.log". See section 7.1. +
    backup ejabberd.backup
    +Store internal Mnesia database to a binary backup file. +
    restore ejabberd.backup
    +Restore immediately from a binary backup file the internal Mnesia database. +This will consume quite some memory for big servers. +
    install-fallback ejabberd.backup
    +The binary backup file is installed as fallback: +it will be used to restore the database at the next ejabberd start. +Similar to restore, but requires less memory. +
    dump ejabberd.dump
    +Dump internal Mnesia database to a text file dump. +
    load ejabberd.dump
    +Restore immediately from a text file dump. +This is not recommended for big databases, as it will consume much time, +memory and processor. In that case it’s preferable to use backup and install-fallback. +
    import-file, import-dir
    +These options can be used to migrate from other Jabber/XMPP servers. There +exist tutorials to migrate from other software to ejabberd. +
    delete-expired-messages
    This option can be used to delete old messages +in offline storage. This might be useful when the number of offline messages +is very high. +

    +

    4.2.2  Restrict Execution with AccessCommands

    The frontends can be configured to restrict access to certain commands. +In that case, authentication information must be provided. +In each frontend the AccessCommands option is defined +in a different place. But in all cases the option syntax is the same: +

    AccessCommands = [ {Access, CommandNames, Arguments} ]
    +Access = atom()
    +CommandNames = all | [CommandName]
    +CommandName = atom()
    +Arguments = [{ArgumentName, ArgumentValue}]
    +ArgumentName = atom()
    +ArgumentValue = any()
    +

    The default value is to not define any restriction: []. +If at least one restriction is defined, then the frontend expects +that authentication information is provided when executing a command. +The authentication information is Username, Hostname and Password of a local Jabber account +that has permission to execute the corresponding command. +This means that the account must be registered in the local ejabberd, +because the information will be verified. +It is possible to provide the plaintext password or its MD5 sum.

    When one or several access restrictions are defined and the +authentication information is provided, +each restriction is verified until one matches completely: +the account matches the Access rule, +the command name is listed in CommandNames, +and the provided arguments do not contradict Arguments.

    As an example to understand the syntax, let’s suppose those options: +

    {hosts, ["example.org"]}.
    +{acl, bots, {user, "robot1", "example.org"}}.
    +{access, commaccess, [{allow, bots}]}.
    +

    This list of access restrictions allows only robot1@example.org to execute all commands: +

    [{commaccess, all, []}]
    +

    See another list of restrictions (the corresponding ACL and ACCESS are not shown): +

    [
    + %% This bot can execute all commands:
    + {bot, all, []},
    + %% This bot can only execute the command 'dump'. No argument restriction:
    + {bot_backups, [dump], []}
    + %% This bot can execute all commands,
    + %% but if a 'host' argument is provided, it must be "example.org":
    + {bot_all_example, all, [{host, "example.org"}]},
    + %% This bot can only execute the command 'register',
    + %% and if argument 'host' is provided, it must be "example.org":
    + {bot_reg_example, [register], [{host, "example.org"}]},
    + %% This bot can execute the commands 'register' and 'unregister',
    + %% if argument host is provided, it must be "test.org":
    + {_bot_reg_test, [register, unregister], [{host, "test.org"}]}
    +]
    +

    +

    4.3  Web Admin

    The ejabberd Web Admin allows to administer most of ejabberd using a web browser.

    This feature is enabled by default: a ejabberd_http listener with the option web_admin (see section 3.1.3) is included in the listening ports. Then you can open @@ -3143,13 +3241,13 @@ The file is searched by default in The directory of the documentation can be specified in the environment variable EJABBERD_DOC_PATH. See section 4.1.2.

    -

    4.3  Ad-hoc Commands

    If you enable mod_configure and mod_adhoc, +

    4.4  Ad-hoc Commands

    If you enable mod_configure and mod_adhoc, you can perform several administrative tasks in ejabberd with a Jabber client. The client must support Ad-Hoc Commands (XEP-0050), and you must login in the Jabber server with an account with proper privileges.

    -

    4.4  Change Computer Hostname

    ejabberd uses the distributed Mnesia database. +

    4.5  Change Computer Hostname

    ejabberd uses the distributed Mnesia database. Being distributed, Mnesia enforces consistency of its file, so it stores the name of the Erlang node in it (see section 5.4). The name of an Erlang node includes the hostname of the computer. @@ -3165,8 +3263,8 @@ you must follow these instructions: For example:

    ejabberdctl restore /tmp/ejabberd-oldhost.backup
     
  • -

    Chapter 5  Securing ejabberd

    -

    5.1  Firewall Settings

    +

    Chapter 5  Securing ejabberd

    +

    5.1  Firewall Settings

    You need to take the following TCP ports in mind when configuring your firewall:


    @@ -3177,7 +3275,7 @@ you must follow these instructions:
    PortDescription
    port rangeUsed for connections between Erlang nodes. This range is configurable (see section 5.2).

    -

    5.2  epmd

    epmd (Erlang Port Mapper Daemon) +

    5.2  epmd

    epmd (Erlang Port Mapper Daemon) is a small name server included in Erlang/OTP and used by Erlang programs when establishing distributed Erlang communications. ejabberd needs epmd to use ejabberdctl and also when clustering ejabberd nodes. @@ -3202,7 +3300,7 @@ but can be configured in the file ejabberdctl.cfg. The Erlang command-line parameter used internally is, for example:

    erl ... -kernel inet_dist_listen_min 4370 inet_dist_listen_max 4375
     

    -

    5.3  Erlang Cookie

    The Erlang cookie is a string with numbers and letters. +

    5.3  Erlang Cookie

    The Erlang cookie is a string with numbers and letters. An Erlang node reads the cookie at startup from the command-line parameter -setcookie. If not indicated, the cookie is read from the cookie file $HOME/.erlang.cookie. If this file does not exist, it is created immediately with a random cookie. @@ -3216,7 +3314,7 @@ to prevent unauthorized access or intrusion to an Erlang node. The communication between Erlang nodes are not encrypted, so the cookie could be read sniffing the traffic on the network. The recommended way to secure the Erlang node is to block the port 4369.

    -

    5.4  Erlang Node Name

    An Erlang node may have a node name. +

    5.4  Erlang Node Name

    An Erlang node may have a node name. The name can be short (if indicated with the command-line parameter -sname) or long (if indicated with the parameter -name). Starting an Erlang node with -sname limits the communication between Erlang nodes to the LAN.

    Using the option -sname instead of -name is a simple method @@ -3225,7 +3323,7 @@ However, it is not ultimately effective to prevent access to the Erlang node, because it may be possible to fake the fact that you are on another network using a modified version of Erlang epmd. The recommended way to secure the Erlang node is to block the port 4369.

    -

    5.5  Securing Sensible Files

    ejabberd stores sensible data in the file system either in plain text or binary files. +

    5.5  Securing Sensible Files

    ejabberd stores sensible data in the file system either in plain text or binary files. The file system permissions should be set to only allow the proper user to read, write and execute those files and directories.

    ejabberd configuration file: /etc/ejabberd/ejabberd.cfg
    @@ -3245,9 +3343,9 @@ so it is preferable to secure the whole /var/lib/ejabberd/ directory.
    Erlang cookie file: /var/lib/ejabberd/.erlang.cookie
    See section 5.3.

    -

    Chapter 6  Clustering

    +

    Chapter 6  Clustering

    -

    6.1  How it Works

    +

    6.1  How it Works

    A Jabber domain is served by one or more ejabberd nodes. These nodes can be run on different machines that are connected via a network. They all must have the ability to connect to port 4369 of all another nodes, and must @@ -3261,29 +3359,29 @@ router,

  • session manager,
  • s2s manager.
  • -

    6.1.1  Router

    +

    6.1.1  Router

    This module is the main router of Jabber packets on each node. It routes them based on their destination’s domains. It uses a global routing table. The domain of the packet’s destination is searched in the routing table, and if it is found, the packet is routed to the appropriate process. If not, it is sent to the s2s manager.

    -

    6.1.2  Local Router

    +

    6.1.2  Local Router

    This module routes packets which have a destination domain equal to one of this server’s host names. If the destination JID has a non-empty user part, it is routed to the session manager, otherwise it is processed depending on its content.

    -

    6.1.3  Session Manager

    +

    6.1.3  Session Manager

    This module routes packets to local users. It looks up to which user resource a packet must be sent via a presence table. Then the packet is either routed to the appropriate c2s process, or stored in offline storage, or bounced back.

    -

    6.1.4  s2s Manager

    +

    6.1.4  s2s Manager

    This module routes packets to other Jabber servers. First, it checks if an opened s2s connection from the domain of the packet’s source to the domain of the packet’s destination exists. If that is the case, the s2s manager routes the packet to the process serving this connection, otherwise a new connection is opened.

    -

    6.2  Clustering Setup

    +

    6.2  Clustering Setup

    Suppose you already configured ejabberd on one machine named (first), and you need to setup another one to make an ejabberd cluster. Then do following steps:

    1. @@ -3321,10 +3419,10 @@ and ‘access’ options because they will be taken from enabled only on one machine in the cluster.

    You can repeat these steps for other machines supposed to serve this domain.

    -

    6.3  Service Load-Balancing

    +

    6.3  Service Load-Balancing

    -

    6.3.1  Components Load-Balancing

    -

    6.3.2  Domain Load-Balancing Algorithm

    +

    6.3.1  Components Load-Balancing

    +

    6.3.2  Domain Load-Balancing Algorithm

    ejabberd includes an algorithm to load balance the components that are plugged on an ejabberd cluster. It means that you can plug one or several instances of the same component on each ejabberd cluster and that the traffic will be automatically distributed.

    The default distribution algorithm try to deliver to a local instance of a component. If several local instances are available, one instance is chosen randomly. If no instance is available locally, one instance is chosen randomly among the remote component instances.

    If you need a different behaviour, you can change the load balancing behaviour with the option domain_balancing. The syntax of the option is the following:

    {domain_balancing, "component.example.com", <balancing_criterium>}.
     

    Several balancing criteria are available: