taler-challenger-manual.rst (18893B)
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 2.1, 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 a 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 actual 241 address is given to this subcommand as the first argument (``$1``), 242 while the text with the challenge is passed to standard input. 243 The subcommand should terminate with a status code of 0 on success. 244 245 .. code-block:: ini 246 :caption: /etc/challenger/challenger.conf 247 248 [challenger] 249 ADDRESS_TYPE = email 250 AUTH_COMMAND = challenger-send-email.sh 251 # ... rest of file ... 252 253 Challenger comes with ``AUTH_COMMAND`` shell scripts for sending e-mail, SMS 254 and postal mail. Note that for SMS and postal mail the Challenger scripts uses 255 third party services to actually send the SMS or print and mail the postal 256 mail. These third parties naturally charge money for their services, and thus 257 the Challenger administrator will need to add the respective credentials to 258 the SMS and postal mail scripts before they can function. In any case, these 259 scripts should be primarily seen as *examples* on how to write authentication 260 commands. 261 262 .. note:: 263 264 We strongly welcome contributions for additional scripts with alternative 265 providers or for new types of addresses. 266 267 268 Legal conditions for using the service 269 -------------------------------------- 270 271 .. include:: frags/legal.rst 272 273 Database Configuration 274 ---------------------- 275 276 The access credentials for the Challenger database are configured in 277 ``/etc/challenger/challenger.conf``. Currently, only PostgreSQL is 278 supported as a database backend. 279 280 .. note:: 281 282 The **challenger-dbconfig** tool can be used to automate the database 283 setup. When using the Debian/Ubuntu packages, the user should already have 284 been created, so you can just run the tool without any arguments and should 285 have a working database configuration. Subsequently, you should still run 286 **taler-challenger-dbinit** as the ``challenger-httpd`` user to 287 initialize the database schema. 288 289 290 To create a database for Challenger on the local system, run: 291 292 .. code-block:: shell-session 293 294 [root@exchange-online]# su - postgres 295 [postgres@exchange-online]# createuser challenger-httpd 296 [postgres@exchange-online]# createdb -O challenger-httpd challenger 297 [postgres@exchange-online]# exit 298 299 This will create a ``challenger`` database owned by the ``taler-httpd`` user. 300 We will use that user later to perform database maintenance operations. 301 302 Assuming the above database setup, the database credentials to configure 303 in the configuration file would simply be: 304 305 .. code-block:: ini 306 :caption: /etc/challenger/challenger.conf 307 308 [challenger] 309 DB = postgres 310 311 [challenger-postgres] 312 CONFIG = postgres:///challenger 313 314 If the database is run on a different host, please follow the instructions 315 from the PostgreSQL manual for configuring remote access. 316 317 After configuring the database credentials, the Challenger database needs 318 to be initialized with the following command: 319 320 .. code-block:: shell-session 321 322 [root@exchange-online]# sudo -u challenger-httpd challenger-dbinit 323 324 .. note:: 325 326 To run this command, the user must have ``CREATE TABLE``, ``CREATE 327 INDEX``, ``ALTER TABLE`` and (in the future possibly even) ``DROP TABLE`` 328 permissions. Those permissions are only required for this step (which may 329 have to be repeated when upgrading a deployment). Afterwards, during 330 normal operation, permissions to ``CREATE`` or ``ALTER`` tables are not 331 required by Challenger and thus should not be granted. For more 332 information, see :doc:`manpages/challenger-dbinit.1`. 333 334 335 Deployment 336 ========== 337 338 This chapter describes how to deploy Challenger once the basic installation 339 and configuration are completed. 340 341 .. _ChallengerServing: 342 343 Serving 344 ------- 345 346 The Challenger can serve HTTP over both TCP and UNIX domain socket. 347 348 The following options are to be configured in the section ``[challenger]``: 349 350 - ``SERVE``: Must be set to ``tcp`` to serve HTTP over TCP, or ``unix`` to serve 351 HTTP over a UNIX domain socket. 352 353 - ``PORT``: Set to the TCP port to listen on if ``SERVE`` is ``tcp``. 354 355 - ``UNIXPATH``: Set to the UNIX domain socket path to listen on if ``SERVE`` is 356 ``unix``. 357 358 - ``UNIXPATH_MODE``: Number giving the mode with the access permission mask 359 for the ``UNIXPATH`` (i.e. 660 = ``rw-rw---``). Make sure to set it in such 360 a way that your reverse proxy has permissions to access the UNIX domain 361 socket. The default (660) assumes that the reverse proxy is a member of 362 the group under which the exchange HTTP server is running. 363 364 .. _ChallengerReverseProxy: 365 366 Reverse Proxy Setup 367 ------------------- 368 369 By default, the ``challenger-httpd`` service listens for HTTP connections 370 on a UNIX domain socket. To make the service publicly available, a reverse 371 proxy such as nginx should be used. You must configure the reverse proxy 372 to use TLS as this is required by OAuth 2.0. 373 374 The ``challenger`` package ships with a sample configuration that can be 375 enabled in nginx: 376 377 .. code-block:: shell-session 378 379 [root@exchange-online]# vim /etc/nginx/sites-available/challenger 380 < ... customize configuration ... > 381 [root@exchange-online]# ln -s /etc/nginx/sites-available/challenger \ 382 /etc/nginx/sites-enabled/challenger 383 [root@exchange-online]# systemctl reload nginx 384 385 386 Launching Challenger 387 -------------------- 388 389 A running exchange requires starting the following processes: 390 391 - ``challenger-httpd`` (needs database access) 392 393 The processes should be started via a hypervisor like 394 ``systemd`` or ``gnunet-arm`` that automatically re-starts them should they 395 have terminated unexpectedly. Furthermore, the hypervisor 396 *should* periodically re-start the service (say once per hour) 397 to limit Postgres database memory utilization. 398 399 .. note:: 400 401 The ``challenger-httpd`` does not ship with HTTPS enabled by default. 402 It must thus be run behind an HTTPS reverse proxy that performs 403 TLS termination on the same system. Thus, it would typically be configured 404 to listen on a UNIX domain socket. 405 406 Given proper packaging, all of the above are realized via a simple systemd 407 target. This enables Challenger to be properly started using a simple command: 408 409 .. code-block:: shell-session 410 411 # systemctl start challenger-httpd.service 412 413 414 Authorizing clients 415 ------------------- 416 417 Before clients can use Challenger, they must be explicitly configured. Each 418 client is identified via its OAuth 2.0 REDIRECT URI. Thus, a client must have 419 exactly one REDIRECT URI. Challenger also does not allow multiple clients sharing the same REDIRECT URI. 420 421 .. note:: 422 423 The OAuth 2.0 specification allows for a client to register 424 zero or multiple REDIRECT URIs. However, zero is insecure 425 as it creates an open redirector, and multiple REDIRECT URIs 426 can trivially be implemented with Challenger by adding more 427 clients. 428 429 You can add or remove clients at any time; the Challenger service does not 430 need to be running, but if it is you can still add or remove clients without 431 restarting the service. To add (or remove) a client, you must use the 432 ``challenger-admin`` command: 433 434 .. code-block:: shell-session 435 436 # sudo -u challenger-httpd challenger-admin --add=$CLIENT_SECRET $CLIENT_REDIRECT_URI 437 438 Here, ``$CLIENT_SECRET`` is the client secret of OAuth 2.0 which will be used in 439 various parts of the protocol to authenticate the client. It must begin with the "secret-token:" prefix of RFC 8959. The 440 ``$CLIENT_REDIRECT_URI`` is the REDIRECT URI where the user-agent will be redirected to upon 441 completion of the process. The ``challenger-admin`` command will 442 then output the *CLIENT_ID*, which will be a unique positive number. 443 The first time you run the command, you will thus likely see: 444 ``Client added. Client ID is: 1``. This CLIENT_ID, the ``$CLIENT_SECRET`` 445 and the ``$CLIENT_REDIRECT_URI`` will form the foundation for the OAuth 2.0 446 configuration. 447 448 449 OAuth 2.0 integration 450 --------------------- 451 452 When integrating Challenger into an OAuth 2.0 process, you need to provide the 453 three options from the previous section, but also the authorization, token and 454 info endpoints. For Challenger, these are ``/authorize``, ``/token`` and 455 ``/info``. However, the ``/authorize`` endpoint is special, as it is actually 456 ``/authorize/$NONCE`` where ``$NONCE`` is a nonce that must be first requested 457 by the client using the ``/setup/$CLIENT_ID`` endpoint! 458 459 .. note:: 460 461 This extra step prevents user-agents from (ab)using the Challenger service 462 to send challenges to addresses even when there is no authorized client 463 that desires address validation. This is an important feature as address 464 validation could be expensive. 465 466 Thus, to generate the authorization URL, a client must first POST to 467 ``/setup/$CLIENT_ID`` using their client secret in an ``Authorization: Bearer 468 $CLIENT_SECRET`` HTTP header to obtain a fresh ``$NONCE``. It is (optionally) 469 possible to pass an address in the body of the ``/setup`` POST request. In 470 this case, Challenger will pre-populate the address of the KYC form with the 471 given body. Here, the format of the body is *address type*-specific. 472 473 .. note:: 474 475 By passing a flag ``read_only: true`` editing of the address in the SPA can 476 be disabled. However, the backend currently does not enforce this 477 (see #9349). 478 479 In the GNU Taler exchange configuration, this is indicated by appending 480 ``#setup`` to the ``KYC_OAUTH2_AUTHORIZE_URL`` endpoint. Be careful to quote 481 the URL, as ``#`` is otherwise interpreted as the beginning of a comment by 482 the configuration file syntax: 483 484 .. code-block:: ini 485 :caption: /etc/taler-exchange/conf.d/exchange-oauth2.conf 486 487 [kyc-provider-example-oauth2] 488 LOGIC = oauth2 489 # (generic options omitted) 490 KYC_OAUTH2_AUTHORIZE_URL = "https://challenger.example.com/authorize#setup" 491 KYC_OAUTH2_TOKEN_URL = "https://challenger.example.com/token" 492 KYC_OAUTH2_INFO_URL = "https://challenger.example.com/info" 493 KYC_OAUTH2_CLIENT_ID = 1 494 # Make sure to include the RFC 8959 prefix in "$SECRET" 495 KYC_OAUTH2_CLIENT_SECRET = "$SECRET" 496 497 498 499 Database management 500 ------------------- 501 502 .. note:: 503 504 We advise to make good backups before experimenting with 505 the database. 506 507 To update the Challenger database after upgrading to a newer 508 version of Challenger, you should simply re-run ``challenger-dbinit``. 509 Without further options, this command is expected to preserve 510 all data and only migrate the existing database to the latest 511 schema: 512 513 .. code-block:: console 514 515 $ challenger-dbinit 516 517 To delete stale data from the Challenger database, you can use 518 garbage collection: 519 520 .. code-block:: console 521 522 $ challenger-dbinit --garbagecollect 523 524 525 The Challenger database can be re-initialized using: 526 527 .. code-block:: console 528 529 $ challenger-dbinit --reset 530 531 However, running this command will result in all data in the database 532 being lost.