taler-docs

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

taler-auditor-manual.rst (44236B)


      1 ..
      2   This file is part of GNU TALER.
      3 
      4   Copyright (C) 2019-2021 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 
     19 
     20 Auditor Operator Manual
     21 #######################
     22 
     23 Introduction
     24 ============
     25 
     26 This manual is an early draft that still needs significant editing work
     27 to become readable.
     28 
     29 About GNU Taler
     30 ---------------
     31 
     32 .. include:: frags/about-taler.rst
     33 
     34 
     35 About this manual
     36 -----------------
     37 
     38 This tutorial targets exchange operators, auditors and governments
     39 who want to run the auditor to verify that a GNU Taler exchange is
     40 operating correctly.
     41 
     42 
     43 Organizational prerequisites
     44 ----------------------------
     45 
     46 Operating a GNU Taler auditor means that you (henceforth: auditor) have a
     47 business relationship with (or regulatory authority over) a GNU Taler exchange
     48 operator (henceforth: exchange).  Your objective is to verify that the
     49 exchange is operating correctly, and if not to alert the exchange, the
     50 state or even the public about any misbehavior to limit financial losses
     51 to other parties.
     52 
     53 To perform this duty, you will need at least (read-only) access to the bank
     54 transactions of the exchange, as well as a continuously synchronized replica
     55 of the exchange's database.  The general assumption for running the auditor
     56 is that this is done on a separate system controlled by the auditor. After
     57 all, the goal is to detect nerfarious activity of the exchange operator,
     58 which cannot be effectively done on a machine controlled by the exchange
     59 operator.
     60 
     61 For this, every auditor needs to operate a PostgreSQL database.  The data
     62 collected will include sensitive information about Taler users, including
     63 withdrawals made by consumers and income received by merchants.  As a result,
     64 the auditor is expected to provide high confidentiality for the database.  In
     65 general, the auditor does not have to offer high-availability: the exchange
     66 operator can continue operations without the auditor, and the auditor can
     67 catch up with it later when the auditor's systems are restored. However, of
     68 course any downtime would provide a window of opportunity for fraud and should
     69 thus be minimized.  Finally, the auditor's copy of the exchange's database can
     70 be useful as a backup to the exchange in case the exchange experiences a loss
     71 of its own copies. Thus, business agreements between auditor and exchanges may
     72 include availability requirements as well.
     73 
     74 Then, with the software provided, auditors can verify the cryptographic proofs
     75 collected by the exchange and detect if any improper bank transactions have been
     76 made.  There are additional tasks which an auditor should perform.  While this
     77 manual only focuses on the audit of the exchange's database and wire transfers
     78 with the existing tools, a proper auditor should also perform the following
     79 tasks:
     80 
     81 - security audit of the source code
     82 - audit of the operational procedures of the exchange
     83 - audit of the physical security of the deployment
     84 - background check of the individuals operating the exchange
     85 - verification that the exchange properly implements the ``/link`` protocol
     86   (feature yet to be implemented in common Taler wallets)
     87 - verification that the exchange properly reports coins issued during
     88   the refresh protocol (by irregularly refreshing coins withdrawn by
     89   the auditor and comparing against the exchange's database --- the
     90   code required to support this is not yet implemented)
     91 
     92 
     93 Architecture overview
     94 ---------------------
     95 
     96 Taler is a pure payment system, not a new crypto-currency. As such, it
     97 operates in a traditional banking context. In particular, this means that in
     98 order to receive funds via Taler, the merchant must have a regular bank
     99 account, and payments can be executed in ordinary currencies such as USD or
    100 EUR. Similarly, the exchange must interact with a bank. The bank of the
    101 exchange holds the exchange’s funds in an escrow account.  As a result,
    102 exchanges operate in a regulated environment, and auditors provide a crucial
    103 oversight function.
    104 
    105 Auditors should generally be independent third parties that verify that the
    106 exchange operates correctly.  However, an exchange is likely to also run the
    107 auditing logic, as it is also used to calculate the exchange’s profits, risk
    108 and liabilities.  Furthermore, it's usually a good idea to not only rely on
    109 third parties to verify one's own work.
    110 
    111 The Taler software stack for an auditor consists of the following
    112 components:
    113 
    114 -  DBMS: PostgreSQL
    115 
    116    The auditor requires a DBMS to store a local copy of the transaction history for
    117    the Taler exchange, as well as for its own internal bookkeeping and checkpointing.
    118    The DBMS is assumed to be able to assure the auditor of the database invariants (foreign
    119    key, uniqueness, length restrictions).  Should the exported data from the exchange
    120    fail to be imported due to constraint violations, this is an immediate serious
    121    concern that must be addressed manually.  The software only verifies the content
    122    of a well-formed exchange database (well-formed with respect to SQL).
    123    For now, the GNU Taler reference implementation
    124    only supports PostgreSQL, but the code could be easily extended to
    125    support another DBMS.
    126 
    127 -  The auditor Web service
    128 
    129    The auditor is expected to provide a public Web service. At this REST API,
    130    merchants can (probabilistically) provide deposit confirmations, allowing
    131    the auditor to detect if an exchange is underreporting deposits.
    132 
    133    In the future, the Web service should be extended to allow customers and
    134    merchants to automatically upload cryptographic proof of other violations
    135    of the specification by the exchange.  However, for now it is assumed that
    136    the respective cryptographic proofs are reported and verified manually ---
    137    as with a well-behaved exchange this should obviously be a rare event.
    138 
    139    The main binary of this component is the ``taler-auditor-httpd``.
    140 
    141 -  The (main) auditor
    142 
    143    The main auditor logic checks the various signatures, totals up the
    144    amounts and checks for arithmetic inconsistencies. It also
    145    computes the expected bank balance, revenue and risk exposure of the
    146    exchange operator. The main script of this component is the ``taler-auditor``.
    147    This script invokes several helper binaries sequentially. Production
    148    users may want to modify the script to run those binaries in parallel,
    149    possibly using different privileges (as only the ``taler-helper-auditor-wire``
    150    needs access to the wire gateway).
    151 
    152    The ``taler-helper-auditor-wire`` auditor verifies that the bank
    153    transactions performed by the exchange
    154    were done properly.  This component must have access to the bank account
    155    of the exchange, as well as to a copy of the exchange's database.
    156 
    157    The ``taler-auditor`` script invokes the various helpers, each generating
    158    a JSON report. It then invokes the ``taler-helper-auditor-render.py``
    159    script to combine those JSON files with a Jinja2 template into a
    160    LaTeX report.  Finally, ``pdflatex`` is used to generate a PDF report.
    161 
    162    The resulting report includes performance data, reports on hard violations
    163    (resulting in financial losses) and reports on soft violations (such as the
    164    exchange not performing certain operations in a timely fashion).  The
    165    report also includes figures on the losses of violations. Careful reading
    166    of the report is required, as not every detail in the report is necessarily
    167    indicative of a problem.
    168 
    169 
    170 Installation
    171 ============
    172 
    173 Installing from source
    174 ----------------------
    175 
    176 Please install the following packages before proceeding with the
    177 exchange compilation.
    178 
    179 - Python3 module ``jinja2``
    180 
    181 .. include:: frags/list-of-dependencies.rst
    182 
    183 -  GNU Taler exchange (from `download directory <http://ftpmirror.gnu.org/taler/>`__,
    184    see `release announcement <https://mail.gnu.org/archive/cgi-bin/namazu.cgi?query=taler&idxname=info-gnu&max=20&result=normal&sort=date:late>`__)
    185 
    186 Except for the last two, these are available in most GNU/Linux
    187 distributions and should just be installed using the respective package
    188 manager.
    189 
    190 The following instructions will show how to install libgnunetutil and
    191 the exchange (which includes the code for the auditor).
    192 
    193 .. include:: frags/installing-gnunet.rst
    194 
    195 .. include:: frags/installing-taler-exchange.rst
    196 
    197 .. include:: frags/install-before-check.rst
    198 
    199 
    200 Installing the GNU Taler binary packages on Debian
    201 --------------------------------------------------
    202 
    203 .. include:: frags/installing-debian.rst
    204 
    205 To install the Taler auditor, you can now simply run:
    206 
    207 .. code-block:: console
    208 
    209    # apt install -t sid taler-auditor
    210 
    211 For the auditor, you must manually configure access to the exchange database,
    212 the HTTP reverse proxy (typically with TLS certificates) and offline signing.
    213 
    214 Sample configuration files for the HTTP reverse proxy can be found in
    215 ``/etc/taler-auditor/``.
    216 
    217 
    218 Installing the GNU Taler binary packages on Ubuntu
    219 --------------------------------------------------
    220 
    221 .. include:: frags/installing-ubuntu.rst
    222 
    223 To install the Taler exchange, you can now simply run:
    224 
    225 .. code-block:: console
    226 
    227    # apt install -t focal-fossa taler-auditor
    228 
    229 For the auditor, you must manually configure access to the exchange database,
    230 the HTTP reverse proxy (typically with TLS certificates) and offline signing.
    231 
    232 Sample configuration files for the HTTP reverse proxy can be found in
    233 ``/etc/taler-auditor/``.
    234 
    235 System setup
    236 ============
    237 
    238 UNIX accounts
    239 -------------
    240 
    241 For maximum security, you should setup multiple different users (possibly
    242 on different machines) to run Taler auditor components. While it is possible
    243 to skip some of these entirely, or to run all of them as the same user, this
    244 is not recommended for security.  The recommended set of users includes:
    245 
    246   * auditor --- runs the main auditing process and HTTP backend
    247   * sync --- synchronizes the ingres database with the production database
    248   * helper --- runs taler-auditor-offline download and upload commands
    249   * auditor-ingres --- imports database from exchange production system
    250   * auditor-wire --- imports wire transfer data from bank production system
    251   * offline --- manages the offline key, on a separate *offline* machine
    252 
    253 It is suggested that you setup the first five users on the target system(s)
    254 using:
    255 
    256 .. code-block:: console
    257 
    258    # add-user --disabled-password $USERNAME
    259 
    260 Additionally, there are two canonical system users of relevance (which your
    261 distribution would typically create for you):
    262 
    263   * www-data --- runs the HTTPS frontend (usually nginx or Apache)
    264   * postgres --- runs the PostgreSQL database
    265 
    266 
    267 Databases and users
    268 -------------------
    269 
    270 We recommend using the following databases for the auditor:
    271 
    272   * exchange-ingres --- synchronized exchange database over the network
    273   * exchange-production --- local copy of exchange database with trusted schema
    274   * auditor --- auditor production database with current state of the audit
    275   * libeufin --- local state of the auditor-wire tool for the bank transfer data import
    276 
    277 As the *postgres* user, you can create these databases using:
    278 
    279 .. code-block:: console
    280 
    281    # As the 'postgres' user:
    282    $ createdb -O auditor-ingres exchange-ingres
    283    $ createdb -O sync exchange-production
    284    $ createdb -O auditor auditor
    285    $ createdb -O auditor-wire libeufin
    286 
    287 This will ensure that the correct users have write-access to their
    288 respective database.  Next, you need to grant read-only access to
    289 some users to databases owned by other users:
    290 
    291 .. code-block:: console
    292 
    293    # As the 'auditor-ingres' user:
    294    $ echo 'GRANT SELECT ON ALL TABLES IN SCHEMA public TO sync;' | psql exchange-ingres
    295    # As the 'sync' user:
    296    $ echo 'GRANT SELECT ON ALL TABLES IN SCHEMA public TO auditor;' | psql exchange-production
    297    # As the 'auditor-wire' user:
    298    $ echo 'GRANT SELECT ON ALL TABLES IN SCHEMA public TO auditor;' | psql libeufin
    299 
    300 
    301 Configuration
    302 =============
    303 
    304 The auditor's configuration works the same way as the configuration of other
    305 Taler components.
    306 This section discusses configuration options related to the auditor.
    307 
    308 
    309 .. include:: frags/configuration-format.rst
    310 
    311 
    312 .. _SetupBaseUrl:
    313 
    314 Initial configuration
    315 ---------------------
    316 
    317 You need to tell the Taler auditor configuration where the
    318 REST API of the auditor will be available to the public:
    319 
    320 .. code-block:: ini
    321 
    322    # Both for the 'offline' *and* the 'auditor' user:
    323    [auditor]
    324    BASE_URL = https://auditor.example.com/
    325 
    326 The ``helper`` user that is used to download information from the exchange
    327 needs to know details about the exchange. Similarly, the ``offline`` user
    328 needs to check signatures signed with the exchange's offline key. Hence, you
    329 need to obtain the ``MASTER_PUBLIC_KEY`` from the exchange operator (they need
    330 to run ``taler-exchange-offline setup``) and the REST endpoint of the exchange
    331 and configure these:
    332 
    333 .. code-block:: ini
    334 
    335    # As the 'helper' and 'offline' users:
    336    [exchange]
    337    BASE_URL = https://exchange.example.com/
    338    MASTER_PUBLIC_KEY = $SOMELONGBASE32VALUEHERE
    339 
    340 
    341 .. _AuditorKeys:
    342 
    343 Keys
    344 ----
    345 
    346 The auditor works with one signing key to certify that it is auditing
    347 a particular exchange's denomination keys.  This key can and should
    348 be kept *offline* (and backed up adequately). As with the exchange's
    349 offline key, it is only used for a few cryptographic signatures and
    350 thus the respective code can be run on modest hardware, like a
    351 Raspberry Pi.
    352 
    353 The following values are to be configured in the section ``[auditor]``:
    354 
    355 -  ``AUDITOR_PRIV_FILE``: Path to the auditor’s private key file.
    356 
    357 Note that the default value here should be fine and there is no clear
    358 need to change it.  What you do need to do as the ``offine`` user
    359 is to extract the public key:
    360 
    361 .. code-block:: console
    362 
    363    # As the 'offline' user:
    364    $ taler-auditor-offline setup
    365 
    366 This public key must then be provided in the configuration file
    367 of the ``auditor`` user in the ``[auditor]]`` configuration section:
    368 
    369 -  ``PUBLIC_KEY``: Public key of the auditor, in Base32 encoding.
    370    Set from value printed by ``taler-auditor-offline setup``.
    371 
    372 You can set this configuration value using:
    373 
    374 .. code-block:: ini
    375 
    376    # As the 'auditor' and 'helper' users:
    377    [auditor]
    378    PUBLIC_KEY = $SOMELONGBASE32VALUEHERE
    379 
    380 
    381 .. _AuditorServing:
    382 
    383 Configuring the auditor's REST endpoint
    384 ---------------------------------------
    385 
    386 The auditor can serve HTTP over both TCP and UNIX domain socket.
    387 
    388 The following values are to be configured in the section ``[auditor]``:
    389 
    390 -  ``serve``: must be set to ``tcp`` to serve HTTP over TCP, or ``unix`` to serve
    391    HTTP over a UNIX domain socket
    392 
    393 -  ``port``: Set to the TCP port to listen on if ``serve`` is ``tcp``.
    394 
    395 -  ``unixpath``: set to the UNIX domain socket path to listen on if ``serve`` is
    396    ``unix``
    397 
    398 -  ``unixpath_mode``: number giving the mode with the access permission MASK
    399    for ``unixpath`` (i.e. 660 = ``rw-rw----``).
    400 
    401 
    402 .. _AuditorBank-account:
    403 
    404 Bank account
    405 ------------
    406 
    407 Bank accounts for the auditor (user ``auditor-wire``) are configured in
    408 exactly the same way as bank accounts for the exchange. See the exchange (and
    409 LibEuFin) documentation for details.
    410 
    411 .. _AuditorDatabaseConfiguration:
    412 
    413 Database
    414 --------
    415 
    416 The option ``DB`` under section ``[auditor]`` gets the DB backend’s name the
    417 exchange is going to use. So far, only ``DB = postgres`` is supported. After
    418 choosing the backend, it is mandatory to supply the connection string
    419 (namely, the database name). This is possible in two ways:
    420 
    421 -  via an environment variable: ``TALER_AUDITORDB_POSTGRES_CONFIG``.
    422 
    423 -  via configuration option ``CONFIG``, under section ``[auditordb-$BACKEND]``.
    424    For example, the demo exchange is configured as follows:
    425 
    426    .. code-block:: ini
    427 
    428       [auditor]
    429       ...
    430       DB = postgres
    431       ...
    432 
    433       [auditordb-postgres]
    434       CONFIG = postgres:///auditordemo
    435 
    436 If an exchange runs its own auditor, it may use the same database for
    437 the auditor and the exchange itself.
    438 
    439 The ``taler-auditor-dbinit`` tool is used to initialize the auditor's
    440 tables. After running this tool, the rights to CREATE or DROP tables
    441 are no longer required and should be removed.
    442 
    443 
    444 Both the ``taler-auditor-httpd`` and the ``taler-auditor`` (and its helpers)
    445 also need (read-only) access to a (recent, current, synchronized) copy of the
    446 exchange's database.  The configuration options are the same that are also
    447 used when configuring the exchange' database:
    448 
    449   .. code-block:: ini
    450 
    451      [exchange]
    452      ...
    453      DB = postgres
    454      ...
    455 
    456      [exchangedb-postgres]
    457      CONFIG = postgres:///exchangedemo
    458 
    459 
    460 Legal conditions for using the service
    461 --------------------------------------
    462 
    463 .. include:: frags/legal.rst
    464 
    465 
    466 .. _AuditorDeployment:
    467 
    468 Deployment
    469 ==========
    470 
    471 .. _Wallets:
    472 
    473 Before GNU Taler wallets will happily interact with an exchange, the
    474 respective auditor's public key (as obtained via ``taler-auditor-offline
    475 setup`` from the ``offline`` user) must be added under the respective currency
    476 to the wallet.  This is usually expected to be hard-coded into the Taler
    477 wallet.
    478 
    479 Users can also manually add auditors for a particular currency via a
    480 Web page offering the respective pairing.
    481 
    482 FIXME-DOLD: explain how that Web page works, once it works...
    483 
    484 
    485 .. _AuditorExchange:
    486 
    487 Exchange
    488 --------
    489 
    490 The exchange operator must use the ``taler-exchange-offline`` tool to add the
    491 auditor's public key, base URL and (business) name to the list of approved
    492 auditors of the exchange. For details, see :ref:`Auditor-configuration` in the
    493 exchange operator manual.
    494 
    495 
    496 .. _SigningDenominations:
    497 
    498 Signing Denominations
    499 ---------------------
    500 
    501 .. index:: maintenance
    502 
    503 These steps must be performed *regularly* whenever the exchange is
    504 deploying new denomination keys. After the exchange operator
    505 has signed new keys using the ``taler-exchange-offline`` tool,
    506 each auditor should run:
    507 
    508 .. code-block:: console
    509 
    510    # As the 'helper' user:
    511    $ taler-auditor-offline download > input.json
    512 
    513 to import the latest set of denomination keys. The key data should then be
    514 copied to the offline system and there be inspected using:
    515 
    516 .. code-block:: console
    517 
    518    # As the 'offline' user:
    519    $ taler-auditor-offline show < input.json
    520 
    521 and compared with the data the exchange operator saw when doing the offline
    522 signature. This process should involve directly the humans operating both
    523 systems and may require them to establish a trustworthy connection. The
    524 details how the auditor communicates with the exchange operator are a business
    525 process that is outside of the scope of this document.
    526 
    527 Note that the ``input.json`` does not contain any confidential data.  However,
    528 signing the wrong keys would be fatal in that it may allow an illegitimate
    529 exchange to convince users that it is a trustworthy operator and subsequently
    530 betray the user's trust that is anchored in the existence of a trustworthy
    531 auditor.
    532 
    533 Given the verified JSON input, the auditor can then sign it (typically
    534 on its offline system) using:
    535 
    536 .. code-block:: console
    537 
    538    # As the 'offline' user:
    539    $ taler-auditor-offline sign < input.json > output.json
    540 
    541 The resulting ``output.json`` should then be copied to an online system,
    542 and from there uploaded to the exchange using:
    543 
    544 .. code-block:: console
    545 
    546    # As the 'helper' user:
    547    $ taler-auditor-offline upload < output.json
    548 
    549 The contents of ``output.json`` can again be public and require no special
    550 handling.
    551 
    552 If the auditor has been correctly added, the exchange’s ``/keys``
    553 response will contain an entry in the ``auditors`` array mentioning the
    554 auditor’s URL.
    555 
    556 Commands, like ``taler-auditor-offline``, that support the ``-l LOGFILE``
    557 command-line option, send logging output to standard error by default.
    558 
    559 
    560 .. _AuditorDatabaseInitialization:
    561 
    562 Database
    563 --------
    564 
    565 The next key step for the auditor is to configure replication of the
    566 *exchange*'s database in-house. This should be performed in two steps
    567 as illustrated in the following figure:
    568 
    569 .. image:: images/replication.png
    570 
    571 First, the exchange should use standard PostgreSQL replication features to
    572 enable the auditor to obtain a full copy of the exchange's database.
    573 Second, the auditor should make a "trusted" local copy, ensuring that it
    574 never replicates malicious changes using ``taler-auditor-sync``. Both
    575 of these steps are described in more detail below.
    576 
    577 We note that as a result of these steps, the auditor will have three
    578 databases: its own production primary database (as configured in
    579 ``auditordb-postgres``), its on production copy of the exchange's database
    580 (``exchangedb-postgress``), and a third, untrusted "ingres" copy of the
    581 exchange database.  The untrusted database should run as a separate PostgreSQL
    582 instance and is only accessed via ``taler-auditor-sync`` and the replication
    583 mechanism driven by the exchange operator.
    584 
    585 
    586 Ingres replication of the exchange production database
    587 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    588 
    589 Ingres operation should be done using the ``auditor-ingres`` user --- or
    590 depending on the setup parts of the operation may be done by the ``postgres``
    591 user directly.
    592 
    593 The full copy can be obtained in various ways with PostgreSQL.  It is
    594 possible to use log shipping with streaming replication as described
    595 in https://www.postgresql.org/docs/13/warm-standby.html, or to use
    596 logical replication, as described in
    597 https://www.postgresql.org/docs/13/logical-replication.html. We note
    598 that asynchronous replication should suffice.
    599 
    600 The resulting auditor database should be treated as read-only on the auditor
    601 side.  The ``taler-exchange-dbinit`` tool can be used to setup the schema, or
    602 the schema can be replicated using PostgreSQL's standard mechanisms. The same
    603 applies for schema upgrades: if logical replication is used (which does not
    604 replicate schema changes), ``taler-exchange-dbinit`` can be used to migrate
    605 the schema(s) in both the ingres and production copies of the exchange's
    606 database as well.
    607 
    608 On the exchange side, a database user must be created that has the right
    609 to perform database replication. This is done using:
    610 
    611 .. code-block:: console
    612 
    613    # As the 'postgres' user of the exchange:
    614    $ createuser --replication egress
    615    $ echo "ALTER ROLE egress WITH PASSWORD '$PASSWORD'; | psql
    616    $ echo "CREATE PUBLICATION $NAME FOR ALL TABLES;" | psql taler-exchange
    617 
    618 The exchange must share the password of the publication with the auditor. A
    619 good ``$NAME`` relates to the auditor's business unit name.  A secure tunnel
    620 must be setup between the exchange and the auditor, for example using SSH or
    621 Wireguard.
    622 
    623 It is also necessary to edit ``main.cf`` of the exchange and on the auditor
    624 side to enable logical replication.  If an exchange has multiple auditors, it
    625 should setup multiple ``egress`` accounts.  The exchange must ensure that
    626 the following lines are in the ``main.cf`` PostgreSQL configuration (the port
    627 may differ) to enable replication over the network:
    628 
    629 .. code-block::
    630 
    631    listen_addresses='*'
    632    port = 5432
    633    wal_level= logical
    634 
    635 Equally, the auditor must configure logical replication in the ``main.cf``
    636 PostgreSQL configuration:
    637 
    638 .. code-block::
    639 
    640    wal_level= logical
    641 
    642 Next, the ``postgres`` user of the auditor's system must first initialize the
    643 local tables:
    644 
    645 .. code-block:: ini
    646 
    647    # Configure database:
    648    [exchange]
    649    DB = "postgres"
    650    [exchangedb-postgres]
    651    CONFIG = "postgres:///taler-ingress"
    652 
    653 .. code-block:: console
    654 
    655    # As the 'ingress' user of the exchange:
    656    $ taler-exchange-dbinit
    657 
    658 To complete the replication, the ``postgres`` user of the auditor's
    659 system must subscribe:
    660 
    661 .. code-block:: console
    662 
    663    # As the 'postgres' user of the exchange:
    664    $ createuser --replication egress
    665    $ echo "ALTER ROLE egress WITH PASSWORD '$PASSWORD'; | psql
    666    $ echo "CREATE PUBLICATION $NAME FOR ALL TABLES;" | psql taler-exchange
    667 
    668 
    669 For details, we refer to the PostgreSQL manual.
    670 
    671 .. note::
    672 
    673    Depending on the replication method used, the exchange may perform
    674    unexpected changes to the schema or perform ``UPDATE``, ``DELETE`` or
    675    ``DROP`` operations on the tables.  Hence, the auditor cannot rely upon the
    676    exchange's primary copy to respect schema constraints, especially as we
    677    have to presume that the exchange could act maliciously.  Furthermore, it
    678    is unclear to what degree PostgreSQL database replication mechanisms are
    679    robust against a malicious master database.  Thus, the auditor should
    680    isolate its primary copy of the exchange database, including the PostgreSQL
    681    process, from its actual operational data.
    682 
    683 
    684 Safe replication of the ingres database into the auditor production database
    685 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    686 
    687 Using ``taler-auditor-sync`` as the ``sync`` user, the auditor should
    688 make a second "safe" copy of the exchange's ingres database.
    689 ``taler-auditor-sync`` basically reads from one exchange database and inserts
    690 all records found into a second exchange database. If the source database
    691 violates invariants, the tool halts with an error. This way, records violating
    692 invariants are never even copied, and in particular schema changes and
    693 deletions or updates are not propagated into the auditor's production
    694 database.
    695 
    696 While ``taler-auditor-sync`` could in theory be run directly against the
    697 exchange's production system, this is likely a bad idea due to the high
    698 latency from the network between auditor and exchange operator. Thus, we
    699 recommend first making an "untrusted" ingress copy of the exchange's
    700 production database using standard PostgreSQL tooling, and then using
    701 ``taler-auditor-sync`` to create a second "safe" copy.  The "safe" copy used
    702 by the production system should also run under a different UID.
    703 
    704 Before ``taler-auditor-sync`` can be used, the target database must be
    705 initialized with the exchange schema using ``taler-exchange-dbinit``.
    706 Note that running ``taler-auditor-sync`` requires the use of two
    707 configuration files, one specifying the options for accessing the source
    708 database, and a second with the options for accessing the destination
    709 database.  In both cases, likely only the ``[exchangedb]/CONFIG`` option
    710 needs to be changed.
    711 
    712 To run ``taler-auditor-sync``, you must first configure two configuration
    713 files that identify the source and destination databases:
    714 
    715 .. code-block:: ini
    716 
    717    # src.conf
    718    [exchangedb]
    719    CONFIG = "postgres:///auditor-ingres/"
    720 
    721 .. code-block:: ini
    722 
    723    # dst.conf
    724    [exchangedb]
    725    CONFIG = "postgres:///auditor/"
    726 
    727 Now you should be able to launch the synchronization process. You can run
    728 the process via systemd in the background. For a first one-off test, you should
    729 use the ``-t`` option which will cause the process to terminate once the two
    730 databases are synchronized:
    731 
    732 .. code-block:: console
    733 
    734    # As the 'sync' user:
    735    $ taler-auditor-sync -s src.conf -d dst.cfg -t
    736 
    737 When the exchange performs garbage collection to ``DELETE`` obsolete records,
    738 this change should be automatically replicated to the auditors untrusted
    739 ingress database.  However, as ``taler-auditor-sync`` tries to be "safe",
    740 it will not replicate those deletions to the auditor's production database.
    741 Thus, it is necessary to (occasonally) run ``taler-exchange-dbinit -g`` on
    742 the auditor's production database to garbage collect old data in the
    743 auditor's production copy.  We note that this does not have to be done
    744 at the same time when the exchange runs its garbage collection.
    745 
    746 
    747 
    748 
    749 .. _Operation:
    750 
    751 Operation
    752 =========
    753 
    754 .. _Web service:
    755 
    756 Web service
    757 -----------
    758 
    759 The ``taler-auditor-httpd`` runs the required REST API for the auditor.  The
    760 service must have ``INSERT`` (and ``SELECT``) rights on the
    761 ``deposit_confirmations`` table in the auditor's database.  We expect that in
    762 future versions additional rights may be required.
    763 
    764 For now, we recommend simply running the ``taler-auditor-httpd`` under the
    765 ``auditor`` user. However, it is also possible (and might be more secure) to
    766 create a separate user with more restrictive permissions for this purpose.
    767 
    768 As the ``taler-auditor-httpd`` does not include HTTPS-support, it is
    769 advisable to run it behind a reverse proxy that offers TLS termination.
    770 
    771 
    772 .. _Audit:
    773 
    774 Audit
    775 -----
    776 
    777 Performing an audit is done by invoking the ``taler-auditor`` shell script as
    778 the ``auditor`` user.
    779 
    780 The shell script invokes the various helper processes. For additional
    781 performance and security, one may want to run the various helpers individually
    782 and with the respective minimal set of access rights (only
    783 ``taler-helper-auditor-wire`` needs the credentials to query the bank for wire
    784 transfers, alas if ``auditor-wire`` is used to talk to the bank, this issue is
    785 already addressed).  The shell script combines the final JSON outputs of the
    786 various helpers using the ``taler-helper-auditor-render.py`` script into the
    787 TeX report.  Regardless, the simplest way to obtain a report is to run:
    788 
    789 .. code-block:: console
    790 
    791    $ taler-audit
    792 
    793 This generates a file ``auditor-report.pdf`` (in a temporary directory created
    794 for this purpose) with all of the issues found and the financial assessment of
    795 the exchange.  The exact filename will be output to the console upon
    796 completion.
    797 
    798 We note that ``taler-audit`` by default runs in incremental mode. As a result,
    799 running the commands again will only check the database entries that have been
    800 added since the last run.
    801 
    802 You can use ``taler-auditor-dbinit -r`` to force a full check since the
    803 beginning of time. However, as this may require excessive time and
    804 interactions with the bank (which may not even have the wire transfer records
    805 anymore), this is not recommended in a production setup.
    806 
    807 
    808 Reading the report
    809 ------------------
    810 
    811 The auditor's report needs to be read carefully, as it includes
    812 several categories of failures of different severity:
    813 
    814 - Delayed operations, where an operation was expected to have
    815   happened, but did not happen yet, possibly because of a
    816   disagreement in system time or overloading of the system.
    817   These failures only require action if the delays are
    818   significant.
    819 
    820 - Inconsistencies in the data that have no clear financial
    821   impact.
    822 
    823 - Inconsistencies in the data that show that the exchange
    824   experienced an unexpected financial loss (such as accepting a coin for
    825   deposit with an invalid signature).
    826 
    827 - Inconsistencies in the data that show that the exchange
    828   caused some other party to experience a financial loss (such as not wiring
    829   the correct amount to a merchant).
    830 
    831 - Configuration issues (such was wire fees unavailable).
    832 
    833 
    834 .. _AuditorDatabaseUpgrades:
    835 
    836 Database upgrades
    837 -----------------
    838 
    839 To upgrade the database between Taler versions can be done by running:
    840 
    841 .. code-block:: console
    842 
    843    $ taler-auditor-dbinit
    844    $ taler-exchange-dbinit
    845 
    846 In any case, it is recommended that exchange and auditor coordinate closely
    847 during schema-changing database upgrades as without coordination the database
    848 replication or ``taler-auditor-sync`` will likely experience problematic
    849 failures.  In general, we recommend:
    850 
    851   * halting the exchange business logic,
    852   * allowing the replication and ``taler-auditor-sync`` to complete
    853     (see also the **-t** option of ``taler-auditor-sync``)
    854   * completing a ``taler-audit`` run against the old schema
    855   * migrating the exchange schema (``taler-exchange-dbinit``) of
    856     the master database, possibly the ingres database and the
    857     auditor's production copy
    858   * migrating the auditor database (``taler-auditor-dbinit``)
    859   * resuming database replication between the exchange's master
    860     database and the auditor's ingres copy
    861   * resuming ``taler-auditor-sync``
    862   * resuming the regular exchange and auditor business logic
    863 
    864 Regardless, the above is merely the general rule. Please review the specific
    865 release notes to ensure this procedure is correct for the specific upgrade.
    866 
    867 
    868 Database reset
    869 ---------------
    870 
    871 The auditor database can be reset using:
    872 
    873 .. code-block:: console
    874 
    875    $ taler-auditor-dbinit -R
    876 
    877 However, running this command will result in all data in the database being
    878 *lost*. Thus, doing so may result in significant commputation (and bandwidth
    879 consumption with the bank) when the auditor is next launched, as it will
    880 re-download and re-verify all historic transactions. Hence this should not be
    881 done in a production system.
    882 
    883 
    884 .. _AuditorRevocations:
    885 
    886 Revocations
    887 -----------
    888 
    889 When an auditor detects that the private key of a denomination key pair has
    890 been compromised, one important step is to revoke the denomination key.  The
    891 exchange operator includes the details on how to revoke a denomination key, so
    892 the auditor should only have to report (and possibly enforce) this step.
    893 For more information, see :ref:`Revocations` in the exchange operator manual.
    894 
    895 If all denominations of an exchange are revoked, the exchange includes logic
    896 to wire back all returned funds to the bank accounts from which they
    897 originate.  If some denominations remain operational, wallets will generally
    898 exchange old coins of revoked denominations for new coins -- while providing
    899 additional information to demonstrate that these coins were not forged from
    900 the compromised private key but obtained via a legitimate withdraw operation.
    901 
    902 
    903 Failures
    904 --------
    905 
    906 Most audit failures are handled by the auditor's regular reporting functionality,
    907 creating a (hopefully descriptive) PDF report detailing the problems found.
    908 
    909 However, there is one category of errors where this is not possible, which
    910 concerns arithmetic overflows for amounts. Taler's specification limits amount
    911 values to at most 2^52. If, during the auditor's calculations, amounts are
    912 encountered that exceed this threshold, the auditor will not generate a regular
    913 report, but instead write a log statement explaining where the problem happened
    914 and exit with a status code of *42*.
    915 
    916 The most common expected case when this happens is a corrupted database. This
    917 could be because the exchange is actively malicious, or more likely due to
    918 some data corruption.  The audit cannot continue until the corruption has been
    919 addressed. If it is not possible to restore a fully *correct* version of the
    920 database, the suggestion is to replace the corrupted (and likely very large)
    921 amounts with zero (Note: this does not apply to the value of denominations or
    922 fees, here it is crucial that the correct amounts are restored). While an
    923 amount of zero would be incorrect, the auditing logic should be able to do its
    924 calculations with zero instead.
    925 
    926 After patching the database, the audit can
    927 be restarted. A full reset is not required, as the audit transaction is aborted
    928 when the auditor exits with code *42*.  After restarting, the resulting audit
    929 report is likely to indicates errors relating to the corrupted fields (such as
    930 invalid signatures, arithmetic errors by the exchange, etc.), but at least the
    931 loss/gain calculations will be meaningful and actually indicative of the scope
    932 of the error created by the corrupted data.
    933 
    934 
    935 
    936 Auditor implementation guide
    937 ============================
    938 
    939 The auditor implementation is split into five main processes, called
    940 ``taler-helper-auditor-XXX``.  The split was done to realize the principle of
    941 least privilege and to enable independent logic to be possibly run in
    942 parallel.  Only the taler-wire-auditor must have (read-only) access to the
    943 exchange's bank account, the other components only need access to the
    944 database.
    945 
    946 All auditor subsystems basically start their audit from a certain transaction
    947 index (``BIG SERIAL``) in the auditor database which identifies where the last
    948 audit concluded. They then check that the transactions claimed in the
    949 exchange's database match up internally, including the cryptographic
    950 signatures and also with respect to amounts adding up. The auditor also
    951 calculates the exchange's profits and expected bank balances.  Once all
    952 existing transactions are processed, the auditor processes store the current
    953 checkpoint in its database and generate a JSON report.
    954 
    955 The ``taler-auditor`` shell script calls the five helpers and then
    956 uses Jinja2 with a TeX template to convert the five individual
    957 JSON reports into LaTeX and then into PDF.
    958 
    959 
    960 The auditor's database
    961 ----------------------
    962 
    963 The database scheme used by the exchange looks as follows:
    964 
    965 .. image:: images/auditor-db.png
    966 
    967 
    968 Invariants checked by the auditor
    969 ---------------------------------
    970 
    971 The auditor verifies a large number of invariants that must hold for a Taler
    972 exchange.  One objective in the design of the auditor was to check each
    973 invariant only once, both to minimize cost and to avoid duplicate reporting of
    974 problems where possible. As a result, not every invariant is checked in every
    975 pass where it might seem applicable.
    976 
    977 
    978 
    979 Invariants checked by the taler-helper-auditor-aggregation
    980 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    981 
    982 This is from CodeBlau's analysis. A proper write-up is pending.
    983 CodeBlau reports the following checks:
    984 
    985 - arithmetic inconsistencies
    986 
    987   - disagreement in fee for deposit between auditor and exchange db
    988 
    989   - disagreement in fee for melt between auditor and exchange db
    990 
    991   - disagreement in fee for refund between auditor and exchange db
    992 
    993   - aggregation of fee is negative
    994 
    995   - aggregation (contribution): Expected coin contributions differ:
    996     coin value without fee, total deposit without refunds
    997 
    998   - wire out fee is negative
    999 
   1000 - coin arithmetic inconsistencies
   1001 
   1002   - refund (merchant) is negative
   1003 
   1004   - refund (balance) is negative
   1005 
   1006   - spend > value
   1007 
   1008 - coin denomination signature invalid
   1009 
   1010 - start date before previous end date
   1011 
   1012 - end date after next start date
   1013 
   1014 - wire out inconsistencies in amount
   1015 
   1016 - row inconsistencies
   1017 
   1018   - wire account given is malformed
   1019 
   1020   - h(wire) does not match wire
   1021 
   1022   - failed to compute hash of given wire data
   1023 
   1024   - database contains wrong hash code for wire details
   1025 
   1026   - no transaction history for coin claimed in aggregation
   1027 
   1028   - could not get coin details for coin claimed in aggregation
   1029 
   1030   - could not find denomination key for coin claimed in aggregation
   1031 
   1032   - coin denomination signature invalid
   1033 
   1034   - target of outgoing wire transfer do not match hash of wire from deposit
   1035 
   1036   - date given in aggregate does not match wire transfer date
   1037 
   1038   - wire fee signature invalid at given time
   1039 
   1040   - specified wire address lacks method
   1041 
   1042   - wire fee unavailable for given time
   1043 
   1044 
   1045 Invariants checked by the taler-helper-auditor-coins
   1046 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   1047 
   1048 This is from CodeBlau's analysis. A proper write-up is pending.
   1049 CodeBlau reports the following checks:
   1050 
   1051 - check that all denominations used by the exchange have been signed using
   1052   this auditor's key. All denominations encountered in the database that
   1053   this auditor did not officially sign for are reported (but still included
   1054   in the audit as they obviously may impact the exchange's bank balance).
   1055   Depending on the business situation, this may be normal (say if an exchange
   1056   is changing auditors and newer denominations are no longer supported until
   1057   their end-of-life by the current auditor).
   1058 
   1059 - emergency on denomination over loss
   1060 
   1061   - value of coins deposited exceed value of coins issued
   1062 
   1063 - emergency on number of coins, num mismatch
   1064 
   1065 - arithmetic inconsistencies
   1066 
   1067   - melt contribution vs. fee
   1068 
   1069   - melt (cost)
   1070 
   1071   - refund fee
   1072 
   1073 - row inconsistencies
   1074 
   1075   - revocation signature invalid
   1076 
   1077   - denomination key not found
   1078 
   1079   - denomination key for fresh coin unknown to auditor
   1080 
   1081   - denomination key for dirty coin unknown to auditor
   1082 
   1083   - denomination key for deposited coin unknown to auditor
   1084 
   1085 - coin validity in known_coin, by checking denomination signatures
   1086 
   1087 - coin validity in melt, by checking signatures
   1088 
   1089 - refresh hanging, zero reveals (harmless)
   1090 
   1091 - verify deposit signature
   1092 
   1093 - verify refund signature
   1094 
   1095 - recoup, check coin
   1096 
   1097 - recoup, check signature
   1098 
   1099 - recoup, denomination not revoked
   1100 
   1101 
   1102 
   1103 Invariants checked by the taler-helper-auditor-deposits
   1104 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   1105 
   1106 This tool verifies that the deposit confirmations reported by merchants
   1107 directly to the auditor are also included in the database duplicated from the
   1108 exchange at the auditor.  This is to ensure that the exchange cannot defraud
   1109 merchants by simply not reporting deposits to the auditor.
   1110 
   1111 
   1112 Invariants checked by the taler-helper-auditor-reserves
   1113 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   1114 
   1115 This is from CodeBlau's analysis. A proper write-up is pending.
   1116 CodeBlau reports the following checks:
   1117 
   1118 - report arithmetic inconsistency
   1119 
   1120   - closing aggregation fee
   1121 
   1122   - global escrow balance
   1123 
   1124 - denomination key validity withdraw inconsistencies
   1125 
   1126 - bad signature losses in withdraw
   1127 
   1128 - bad signature losses in recoup
   1129 
   1130 - bad signature losses in recoup-master
   1131 
   1132 - reserve balance, insufficient, losses and gains
   1133 
   1134 - reserve balance, summary wrong
   1135 
   1136 - reserve not closed after expiration time
   1137 
   1138 - could not determine closing fee / closing-fee unavailable
   1139 
   1140 - denomination key not found for withdraw
   1141 
   1142 - denomination key not in revocation set for recoup
   1143 
   1144 - target account not verified, auditor does not know reserve
   1145 
   1146 - target account does not match origin account
   1147 
   1148 
   1149 Invariants checked by the taler-helper-auditor-wire
   1150 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   1151 
   1152 This auditor is special in that it is the only pass that is required to have
   1153 *read-only* access to the exchange's bank account (privilege separation).  Its
   1154 main role is to verify that the wire transfers in the exchange's database and
   1155 those reported by the bank are identical.
   1156 
   1157 This is from CodeBlau's analysis. A proper write-up is pending.
   1158 CodeBlau reports the following checks:
   1159 
   1160 - check pending
   1161 
   1162 - wire missing
   1163 
   1164 - execution date mismatch
   1165 
   1166 - wire out consistency
   1167 
   1168 - wire transfer not made (yet?)
   1169 
   1170 - receiver account mismatch
   1171 
   1172 - wire amount does not match
   1173 
   1174 - justification for wire transfer not found
   1175 
   1176 - duplicate subject hash
   1177 
   1178 - duplicate wire offset
   1179 
   1180 - incoming wire transfer claimed by exchange not found
   1181 
   1182 - wire subject does not match
   1183 
   1184 - wire amount does not match
   1185 
   1186 - debit account url does not match
   1187 
   1188 - execution date mismatch
   1189 
   1190 - closing fee above total amount
   1191 
   1192 
   1193 
   1194 
   1195 
   1196 Testing the auditor
   1197 -------------------
   1198 
   1199 The main objective of the auditor is to detect inconsistencies. Thus, the
   1200 ``test-auditor.sh`` script deliberately introduces various inconsistencies into
   1201 a synthetic exchange database.  For this, an "normal" exchange database is
   1202 first generated using the ``taler-wallet-cli``.  Then, various fields or rows
   1203 of that database are manipulated, and the auditor is let loose on the modified
   1204 database.  Afterwards, the test verifies that the JSON contains values
   1205 indicating that the auditor found the inconsistencies.  The script also
   1206 verifies that template expansion and LaTeX run work for the JSON output,
   1207 but it does not verify the correctness of the final PDF.
   1208 
   1209 The ``test-auditor.sh`` script is written to maximize code coverage: it should
   1210 cover as many code paths as possible in both the exchange and the auditor.  It
   1211 should also ideally create all interesting possible variations of the exchange
   1212 database fields (within the constraints of the database schema).
   1213 
   1214 In general, ``test-auditor.sh`` runs the tests against an "old" database where
   1215 some transactions are past the due-date (and hence the aggregator would trigger
   1216 wire transfers), as well as a freshly generated exchange database where the
   1217 auditor would not perform any transfers.  Auditor interactions can be made
   1218 before or after the aggregator, depending on what is being tested.
   1219 
   1220 The current script also rudimentarily tests the auditor's resume logic,
   1221 by re-starting the auditor once against a database that the auditor has
   1222 already seen.
   1223 
   1224 
   1225 The ``test-revocation.sh`` script performs tests related to the handling of
   1226 key revocations.
   1227 
   1228 The ``test-sync.sh`` script performs tests related to the ``taler-auditor-sync``
   1229 tool.
   1230 
   1231 .. TODO
   1232 
   1233    More extensive auditor testing where additional transactions
   1234    have been made against the database when the audit is being resumed
   1235    should be done in the future.