taler-docs

Documentation for GNU Taler components, APIs and protocols
Log | Files | Refs | README | LICENSE

taler-challenger-manual.rst (18959B)


      1 ..
      2   This file is part of GNU TALER.
      3 
      4   Copyright (C) 2023, 2024 Taler Systems SA
      5 
      6   TALER is free software; you can redistribute it and/or modify it under the
      7   terms of the GNU Affero General Public License as published by the Free Software
      8   Foundation; either version 3.0, or (at your option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     11   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     12   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     13 
     14   You should have received a copy of the GNU Affero General Public License along with
     15   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     16 
     17   @author Christian Grothoff
     18   @author Florian Dold
     19 
     20 Challenger Operator Manual
     21 ##########################
     22 
     23 Introduction
     24 ============
     25 
     26 About Challenger
     27 ----------------
     28 
     29 Challenger is an OAuth 2.0-compatible address validation service.
     30 By redirecting a user-agent to a Challenger service a client can
     31 have Challenger validate that the user is able to receive messages
     32 at a particular address and obtain that address via the ``/info``
     33 endpoint.
     34 
     35 
     36 About this manual
     37 -----------------
     38 
     39 This manual targets system administrators who want to install,
     40 operate or integrate a challenger service.  To report issues
     41 or learn about known limitations, please check our
     42 `bug tracker <https://bugs.taler.net>`__.
     43 
     44 
     45 Architecture overview
     46 ---------------------
     47 
     48 The following picture gives an overview of the Challenger
     49 architecture and the main interactions:
     50 
     51 .. image:: images/challenger.png
     52 
     53 Here, the *resource owner* is a user that is in control
     54 of some *address* at a messaging service. This could be
     55 an e-mail account, a mobile phone number (for SMS), or
     56 a physical mail address (using the post office as the
     57 messaging service).
     58 
     59 The *resource owner* makes some request that requires
     60 some *client* to be in need of address validation. The
     61 *client* is registered with the Challenger OAuth 2.0
     62 service and first authorizes an address validation to
     63 be initiated. The client then redirects the resource
     64 owner to the Challenger service. In step (2), the resource
     65 owner submits the address that they claim to own.
     66 
     67 The Challenger service then creates a TAN code and
     68 submits it to the given address via a configurable
     69 *helper script* that is specific to the type of address
     70 being validated. When the resource owner submits the
     71 correct TAN code in step (6), they are given a token
     72 that they can provide to the client. Using this token
     73 the client can then finally obtain the now validated
     74 address in step (8).
     75 
     76 Address data, TAN codes and meta-data such as the number
     77 of failed attempts to submit a TAN code are recorded
     78 in a Postgres database by the Challenger service.
     79 
     80 .. _ChallengerInstallation:
     81 
     82 Installation
     83 ============
     84 
     85 In this guide's shell-session fragments, the command prompt shows two pieces
     86 of information:
     87 
     88 * Who is performing the command
     89   (``$user`` vs ``root``, and ending character ``$`` vs ``#``).
     90 
     91 
     92 Installing from source
     93 ----------------------
     94 
     95 The following instructions will show how to install libgnunetutil and
     96 the core GNU Taler libraries from source.
     97 
     98 The package sources can be find in our
     99 `download directory <http://ftpmirror.gnu.org/taler/>`__.
    100 
    101 GNU Taler components version numbers follow the ``MAJOR.MINOR.MICRO`` format.
    102 The general rule for compatibility is that ``MAJOR`` and ``MINOR`` must match.
    103 Exceptions to this general rule are documented in the release notes.
    104 For example, Challenger 1.3.0 should be compatible with Taler exchange 1.4.x
    105 as the MAJOR version matches.  A MAJOR version of 0 indicates experimental
    106 development, and you are expected to always run all of the *latest* releases
    107 together (no compatibility guarantees).
    108 
    109 First, the following packages need to be installed before we can compile the
    110 backend:
    111 
    112 .. include:: frags/list-of-dependencies.rst
    113 
    114 .. include:: frags/installing-gnunet.rst
    115 
    116 .. include:: frags/install-before-check.rst
    117 
    118 There is no need to actually run a GNUnet peer or a Taler exchange to use
    119 Challenger -- all Challenger needs from GNUnet and Taler are a number of
    120 headers and libraries!
    121 
    122 .. include:: frags/installing-taler-exchange.rst
    123 
    124 
    125 .. include:: frags/installing-challenger.rst
    126 
    127 .. include:: frags/install-before-check.rst
    128 
    129 
    130 
    131 Installing the Challenger binary packages on Debian
    132 ---------------------------------------------------
    133 
    134 .. include:: frags/installing-debian.rst
    135 
    136 To install the Challenger, you can now simply run:
    137 
    138 .. code-block:: shell-session
    139 
    140    # apt install challenger
    141 
    142 Note that the package does not perform any configuration work except for
    143 setting up the various users and the systemd service scripts. You still must
    144 configure at least the database, HTTP reverse proxy (typically with TLS
    145 certificates) and the terms of service.
    146 
    147 Installing the GNU Taler binary packages on Trisquel
    148 ----------------------------------------------------
    149 
    150 .. include:: frags/installing-trisquel.rst
    151 
    152 Installing the GNU Taler binary packages on Ubuntu
    153 --------------------------------------------------
    154 
    155 .. include:: frags/installing-ubuntu.rst
    156 
    157 To install the Taler exchange, you can now simply run:
    158 
    159 .. code-block:: shell-session
    160 
    161    # apt install challenger
    162 
    163 Note that the package does not perform any configuration work except for
    164 setting up the various users and the systemd service scripts. You still must
    165 configure at least the database, HTTP reverse proxy (typically with TLS
    166 certificates), and the terms of service.
    167 
    168 
    169 Services, users, groups and file system hierarchy
    170 -------------------------------------------------
    171 
    172 The *challenger* package will use several system users
    173 to compartmentalize different parts of the system:
    174 
    175 * ``challenger-httpd``: runs the HTTP daemon with the core business logic.
    176 * ``postgres``: runs the PostgreSQL database (from *postgresql* package).
    177 * ``www-data``: runs the frontend HTTPS service with the TLS keys (from *nginx* package).
    178 
    179 The package will deploy systemd service files in
    180 ``/usr/lib/systemd/system/`` for Challenger:
    181 
    182 * ``challenger-httpd.service``: the Challenger logic with the public REST API.
    183 
    184 
    185 Configuration Fundamentals
    186 ==========================
    187 
    188 This chapter provides fundamental details about the exchange configuration.
    189 
    190 The configuration for all Taler components uses a single configuration file
    191 as entry point: ``/etc/challenger/challenger.conf``.
    192 
    193 System defaults are automatically loaded from files in
    194 ``/usr/share/challenger/config.d``.  These default files should never be modified.
    195 
    196 The default configuration ``challenger.conf`` configuration file also includes all
    197 configuration files in ``/etc/challenger/conf.d``.
    198 
    199 To view the entire configuration annotated with the source of each configuration option, you
    200 can use the ``challenger-config`` helper:
    201 
    202 
    203 .. code-block:: shell-session
    204 
    205   [root@exchange-online]# challenger-config --diagnostics
    206   < ... annotated, full configuration ... >
    207 
    208 .. warning::
    209 
    210   While ``challenger-config`` also supports rewriting configuration files, we strongly
    211   recommend to edit configuration files manually, as ``challenger-config`` does not
    212   preserve comments and, by default, rewrites ``/etc/challenger/challenger.conf``.
    213 
    214 .. include:: frags/configuration-format.rst
    215 
    216 
    217 Fundamental Setup: Address validation
    218 -------------------------------------
    219 
    220 Each challenger service is designed to validate one type of address. Possible
    221 address types include:
    222 
    223 * phone numbers (via SMS)
    224 * e-mail addresses (via SMTP)
    225 * mail addresses (via postal service)
    226 
    227 In principle, additional types of addresses can easily be added by extending
    228 the respective HTML and programs to send challenges to the new address type.
    229 
    230 To make different types of address validations possible, the Challenger
    231 configuration contains two configuration options.
    232 
    233 (1) The ``ADDRESS_TYPE`` configuration option informs Challenger about the
    234     type of address it is expected to validate. It is returned as part of
    235     the OAuth 2.0 ``/info`` endpoint to the client, and is typically also
    236     used when deciding how to render the HTML form for address entry that is
    237     shown to the user.
    238 
    239 (2) The ``AUTH_COMMAND`` configuration option specifies which command
    240     Challenger should run to send a challenge to an address. The value may
    241     include arguments separated by spaces; quoting and escaping are not
    242     supported. The actual address is appended as the final argument, while
    243     the text with the challenge is passed to standard input. The command
    244     should terminate with a status code of 0 on success.
    245 
    246 .. code-block:: ini
    247   :caption: /etc/challenger/challenger.conf
    248 
    249    [challenger]
    250    ADDRESS_TYPE = email
    251    AUTH_COMMAND = challenger-send-email.sh
    252    # ... rest of file ...
    253 
    254 Challenger comes with ``AUTH_COMMAND`` shell scripts for sending e-mail, SMS
    255 and postal mail. Note that for SMS and postal mail the Challenger scripts use
    256 third party services to actually send the SMS or print and mail the postal
    257 mail. These third parties naturally charge money for their services, and thus
    258 the Challenger administrator will need to add the respective credentials to
    259 the SMS and postal mail scripts before they can function.  In any case, these
    260 scripts should be primarily seen as *examples* on how to write authentication
    261 commands.
    262 
    263 .. note::
    264 
    265   We strongly welcome contributions for additional scripts with alternative
    266   providers or for new types of addresses.
    267 
    268 
    269 Legal conditions for using the service
    270 --------------------------------------
    271 
    272 .. include:: frags/legal.rst
    273 
    274 Database Configuration
    275 ----------------------
    276 
    277 The access credentials for the Challenger database are configured in
    278 ``/etc/challenger/challenger.conf``.  Currently, only PostgreSQL is
    279 supported as a database backend.
    280 
    281 .. note::
    282 
    283    The **challenger-dbconfig** tool can be used to automate the database
    284    setup. When using the Debian/Ubuntu packages, the user should already have
    285    been created, so you can just run the tool without any arguments and should
    286    have a working database configuration.  Subsequently, you should still run
    287    **taler-challenger-dbinit** as the ``challenger-httpd`` user to
    288    initialize the database schema.
    289 
    290 
    291 To create a database for Challenger on the local system, run:
    292 
    293 .. code-block:: shell-session
    294 
    295   [root@exchange-online]# su - postgres
    296   [postgres@exchange-online]# createuser challenger-httpd
    297   [postgres@exchange-online]# createdb -O challenger-httpd challenger
    298   [postgres@exchange-online]# exit
    299 
    300 This will create a ``challenger`` database owned by the ``taler-httpd`` user.
    301 We will use that user later to perform database maintenance operations.
    302 
    303 Assuming the above database setup, the database credentials to configure
    304 in the configuration file would simply be:
    305 
    306 .. code-block:: ini
    307   :caption: /etc/challenger/challenger.conf
    308 
    309   [challenger]
    310   DB = postgres
    311 
    312   [challenger-postgres]
    313   CONFIG = postgres:///challenger
    314 
    315 If the database is run on a different host, please follow the instructions
    316 from the PostgreSQL manual for configuring remote access.
    317 
    318 After configuring the database credentials, the Challenger database needs
    319 to be initialized with the following command:
    320 
    321 .. code-block:: shell-session
    322 
    323   [root@exchange-online]# sudo -u challenger-httpd challenger-dbinit
    324 
    325 .. note::
    326 
    327   To run this command, the user must have ``CREATE TABLE``, ``CREATE
    328   INDEX``, ``ALTER TABLE`` and (in the future possibly even) ``DROP TABLE``
    329   permissions.  Those permissions are only required for this step (which may
    330   have to be repeated when upgrading a deployment).  Afterwards, during
    331   normal operation, permissions to ``CREATE`` or ``ALTER`` tables are not
    332   required by Challenger and thus should not be granted.  For more
    333   information, see :doc:`manpages/challenger-dbinit.1`.
    334 
    335 
    336 Deployment
    337 ==========
    338 
    339 This chapter describes how to deploy Challenger once the basic installation
    340 and configuration are completed.
    341 
    342 .. _ChallengerServing:
    343 
    344 Serving
    345 -------
    346 
    347 The Challenger can serve HTTP over both TCP and UNIX domain socket.
    348 
    349 The following options are to be configured in the section ``[challenger]``:
    350 
    351 -  ``SERVE``: Must be set to ``tcp`` to serve HTTP over TCP, or ``unix`` to serve
    352    HTTP over a UNIX domain socket.
    353 
    354 -  ``PORT``: Set to the TCP port to listen on if ``SERVE`` is ``tcp``.
    355 
    356 -  ``UNIXPATH``: Set to the UNIX domain socket path to listen on if ``SERVE`` is
    357    ``unix``.
    358 
    359 - ``UNIXPATH_MODE``: Number giving the mode with the access permission mask
    360    for the ``UNIXPATH`` (i.e. 660 = ``rw-rw---``). Make sure to set it in such
    361    a way that your reverse proxy has permissions to access the UNIX domain
    362    socket.  The default (660) assumes that the reverse proxy is a member of
    363    the group under which the exchange HTTP server is running.
    364 
    365 .. _ChallengerReverseProxy:
    366 
    367 Reverse Proxy Setup
    368 -------------------
    369 
    370 By default, the ``challenger-httpd`` service listens for HTTP connections
    371 on a UNIX domain socket.  To make the service publicly available, a reverse
    372 proxy such as nginx should be used.  You must configure the reverse proxy
    373 to use TLS as this is required by OAuth 2.0.
    374 
    375 The ``challenger`` package ships with a sample configuration that can be
    376 enabled in nginx:
    377 
    378 .. code-block:: shell-session
    379 
    380   [root@exchange-online]# vim /etc/nginx/sites-available/challenger
    381   < ... customize configuration ... >
    382   [root@exchange-online]# ln -s /etc/nginx/sites-available/challenger \
    383                                 /etc/nginx/sites-enabled/challenger
    384   [root@exchange-online]# systemctl reload nginx
    385 
    386 
    387 Launching Challenger
    388 --------------------
    389 
    390 A running exchange requires starting the following processes:
    391 
    392 -   ``challenger-httpd`` (needs database access)
    393 
    394 The processes should be started via a hypervisor like
    395 ``systemd`` or ``gnunet-arm`` that automatically re-starts them should they
    396 have terminated unexpectedly.  Furthermore, the hypervisor
    397 *should* periodically re-start the service (say once per hour)
    398 to limit Postgres database memory utilization.
    399 
    400 .. note::
    401 
    402   The ``challenger-httpd`` does not ship with HTTPS enabled by default.
    403   It must thus be run behind an HTTPS reverse proxy that performs
    404   TLS termination on the same system.  Thus, it would typically be configured
    405   to listen on a UNIX domain socket.
    406 
    407 Given proper packaging, all of the above are realized via a simple systemd
    408 target. This enables Challenger to be properly started using a simple command:
    409 
    410 .. code-block:: shell-session
    411 
    412   # systemctl start challenger-httpd.service
    413 
    414 
    415 Authorizing clients
    416 -------------------
    417 
    418 Before clients can use Challenger, they must be explicitly configured. Each
    419 client is identified via its OAuth 2.0 REDIRECT URI.  Thus, a client must have
    420 exactly one REDIRECT URI. Challenger also does not allow multiple clients sharing the same REDIRECT URI.
    421 
    422 .. note::
    423 
    424   The OAuth 2.0 specification allows for a client to register
    425   zero or multiple REDIRECT URIs. However, zero is insecure
    426   as it creates an open redirector, and multiple REDIRECT URIs
    427   can trivially be implemented with Challenger by adding more
    428   clients.
    429 
    430 You can add or remove clients at any time; the Challenger service does not
    431 need to be running, but if it is you can still add or remove clients without
    432 restarting the service.  To add (or remove) a client, you must use the
    433 ``challenger-admin`` command:
    434 
    435 .. code-block:: shell-session
    436 
    437   # sudo -u challenger-httpd challenger-admin --add=$CLIENT_SECRET $CLIENT_REDIRECT_URI
    438 
    439 Here, ``$CLIENT_SECRET`` is the client secret of OAuth 2.0 which will be used in
    440 various parts of the protocol to authenticate the client. It must begin with the "secret-token:" prefix of RFC 8959.  The
    441 ``$CLIENT_REDIRECT_URI`` is the REDIRECT URI where the user-agent will be redirected to upon
    442 completion of the process.  The ``challenger-admin`` command will
    443 then output the *CLIENT_ID*, which will be a unique positive number.
    444 The first time you run the command, you will thus likely see:
    445 ``Client added. Client ID is: 1``.  This CLIENT_ID, the ``$CLIENT_SECRET``
    446 and the ``$CLIENT_REDIRECT_URI`` will form the foundation for the OAuth 2.0
    447 configuration.
    448 
    449 
    450 OAuth 2.0 integration
    451 ---------------------
    452 
    453 When integrating Challenger into an OAuth 2.0 process, you need to provide the
    454 three options from the previous section, but also the authorization, token and
    455 info endpoints.  For Challenger, these are ``/authorize``, ``/token`` and
    456 ``/info``.  However, the ``/authorize`` endpoint is special, as it is actually
    457 ``/authorize/$NONCE`` where ``$NONCE`` is a nonce that must be first requested
    458 by the client using the ``/setup/$CLIENT_ID`` endpoint!
    459 
    460 .. note::
    461 
    462   This extra step prevents user-agents from (ab)using the Challenger service
    463   to send challenges to addresses even when there is no authorized client
    464   that desires address validation. This is an important feature as address
    465   validation could be expensive.
    466 
    467 Thus, to generate the authorization URL, a client must first POST to
    468 ``/setup/$CLIENT_ID`` using their client secret in an ``Authorization: Bearer
    469 $CLIENT_SECRET`` HTTP header to obtain a fresh ``$NONCE``.  It is (optionally)
    470 possible to pass an address in the body of the ``/setup`` POST request. In
    471 this case, Challenger will pre-populate the address of the KYC form with the
    472 given body. Here, the format of the body is *address type*-specific.
    473 
    474 .. note::
    475 
    476   By passing a flag ``read_only: true`` editing of the address in the SPA can
    477   be disabled. However, the backend currently does not enforce this
    478   (see #9349).
    479 
    480 In the GNU Taler exchange configuration, this is indicated by appending
    481 ``#setup`` to the ``KYC_OAUTH2_AUTHORIZE_URL`` endpoint.  Be careful to quote
    482 the URL, as ``#`` is otherwise interpreted as the beginning of a comment by
    483 the configuration file syntax:
    484 
    485 .. code-block:: ini
    486   :caption: /etc/taler-exchange/conf.d/exchange-oauth2.conf
    487 
    488   [kyc-provider-example-oauth2]
    489   LOGIC = oauth2
    490   # (generic options omitted)
    491   KYC_OAUTH2_AUTHORIZE_URL = "https://challenger.example.com/authorize#setup"
    492   KYC_OAUTH2_TOKEN_URL = "https://challenger.example.com/token"
    493   KYC_OAUTH2_INFO_URL = "https://challenger.example.com/info"
    494   KYC_OAUTH2_CLIENT_ID = 1
    495   # Make sure to include the RFC 8959 prefix in "$SECRET"
    496   KYC_OAUTH2_CLIENT_SECRET = "$SECRET"
    497 
    498 
    499 
    500 Database management
    501 -------------------
    502 
    503 .. note::
    504 
    505   We advise to make good backups before experimenting with
    506   the database.
    507 
    508 To update the Challenger database after upgrading to a newer
    509 version of Challenger, you should simply re-run ``challenger-dbinit``.
    510 Without further options, this command is expected to preserve
    511 all data and only migrate the existing database to the latest
    512 schema:
    513 
    514 .. code-block:: console
    515 
    516    $ challenger-dbinit
    517 
    518 To delete stale data from the Challenger database, you can use
    519 garbage collection:
    520 
    521 .. code-block:: console
    522 
    523    $ challenger-dbinit --garbagecollect
    524 
    525 
    526 The Challenger database can be re-initialized using:
    527 
    528 .. code-block:: console
    529 
    530    $ challenger-dbinit --reset
    531 
    532 However, running this command will result in all data in the database
    533 being lost.