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