summaryrefslogtreecommitdiff
path: root/taler-exchange-setup-guide.rst
blob: 1d6e0b20f38cd78ee94eb8188b381d3cf9580487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
..
  This file is part of GNU Taler.

  Copyright (C) 2021 Taler Systems SA

  GNU Taler is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 2.1, or (at your option) any later version.

  GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>

  @author Florian Dold

GNU Taler Exchange Setup Guide
##############################

This setup guide walks a system administrator through all steps required to
install an exchange and check that it is functional.  For more background,
please read the Operator Manual.


System Requirements
===================

This guide assumes that you are running Ubuntu 20.04 (Focal Fossa).

We recommend the setup of offline signing keys to be done on a second machine that
does not have internet access.

In the guide, we mark commands that are supposed to be executed on the online
exchange machine as `[root@exchange-online]#` / `[$user@exchange-online]$` and commands for the offline
machine as `[root@exchange-offline]#` /`[$user@exchange-offline]$`.  It is possible to do the entire setup
on one machine, but we do not recommend this for security reasons.

Installation
============

To install the exchange, first make sure that your system is up-to-date
and that the ``gnupg`` package has been installed.

.. code-block:: shell-session

  [root@exchange-online]# apt-get update
  [root@exchange-online]# apt-get upgrade
  [root@exchange-online]# apt-get install -y gnupg

Next, add the ``focal-fossa`` apt repository provided by Taler Systems S.A. to
your package sources:

.. code-block:: shell-session

  [root@exchange-online]# cat > /etc/apt/sources.list.d/taler.list <<EOF
  deb https://deb.taler.net/apt/ubuntu focal-fossa main
  EOF

Before installing Taler packages, you need to add the Taler Systems S.A. package
signing key to your list of trusted keys and update the package index:

.. code-block:: shell-session

  [root@exchange-online]# wget -O - https://taler.net/taler-systems.gpg.key | apt-key add -
  [root@exchange-online]# apt-get update

Finally, the required packages can be installed:


.. code-block:: shell-session

  [root@exchange-online]# apt-get install -y nginx postgresql
  [root@exchange-online]# apt-get install -y taler-exchange taler-exchange-offline
  [root@exchange-online]# apt-get install -y taler-merchant taler-wallet-cli

When asked about using dbconfig to configure the merchant's database,
select ``yes``.

By default, all installed services will be disabled.  You need to enable
and start them later.

While ``taler-merchant`` and ``taler-wallet`` are not required to operate an
exchange, they are useful for testing.


Configuration Basics
====================

The configuration for all Taler components uses a single configuration file
as entry point: ``/etc/taler/taler.conf``.

System defaults are automatically loaded from files in
``/usr/share/taler/config.d``.  These default files should never be modified.

The default configuration ``taler.conf`` configuration file also includes all
configuration files in ``/etc/taler/conf.d``.  The settings from files in
``conf.d`` are only relevant to particular components of Taler, while
``taler.conf`` contains settings that affect all components.


The directory ``/etc/taler/secrets`` contains configuration file snippets with
values that should only be readable to certain users.  They are included with the ``@inline-secret@``
directive and should end with ``.secret.conf``.

To view the entire configuration annotated with the source of each configuration option, you
can use the ``taler-config`` helper:

.. code-block:: shell-session

  [root@exchange-online]# taler-config --diagnostics
  < ... annotated, full configuration ... >

.. warning::

  While ``taler-config`` also supports rewriting configuration files, we strongly
  recommend to edit configuration files manually, as ``taler-config`` does not
  preserve comments and, by default, rewrites ``/etc/taler/taler.conf``.


Services, users, groups and file system hierarchy
=================================================

The *taler-exchange-httpd* package will create several system users
to compartmentalize different parts of the system:

  * taler-exchange-httpd: the user that runs the HTTP daemon with the core business logic
  * taler-exchange-secmod-rsa: the user that manages the RSA private online signing keys
  * taler-exchange-secmod-eddsa: the user that manages the EdDSA private online signing keys
  * taler-exchange-closer: a helper process that closes reserves
  * taler-exchange-aggregator: a helper process that aggregates deposits into larger wire transfer requests
  * taler-exchange-wire: the user that performs wire transfers with the bank
  * postgres: the user running the Postgres database (from *postgres* package)
  * www-data: the user running the frontend HTTPS service with the TLS keys (from *nginx* package)

.. note::

   The *taler-merchant-httpd* package additionally creates a taler-merchant-httpd user
   to runs the HTTP daemon with the merchant business logic.


The exchange setup uses the following system groups:

  * taler-exchange-db: group for all Taler users with direct database access, specifically taler-exchange-httpd, taler-exchange-wire, taler-exchange-closer and taler-exchange-aggregator
  * taler-exchange-secmod: FIXME: how is this used right now?
  * taler-exchange-offline: FIXME: how is this used right now?


The package will deploy systemd service files in
``/usr/lib/systemd/system/`` for the various components:

  * taler-exchange-aggregator.service: FIXME - explain
  * taler-exchange-closer.service: FIXME - explain
  * taler-exchange-httpd.service: FIXME - explain
  * taler-exchange-httpd.socket: FIXME - explain
  * taler-exchange-secmod-eddsa.service: FIXME - explain
  * taler-exchange-secmod-rsa.service: FIXME - explain
  * taler-exchange.target: FIXME - explain
  * taler-exchange-transfer.service: FIXME - explain
  * taler-exchange-wirewatch.service: FIXME - explain


(FIXME: Explain the Debian package users, groups and locations. -- anything missing?)



Basic Setup: Currency and Denominations
=======================================

A Taler exchange only supports a single currency.  The currency
and the smallest currency unit supported by the bank system
must be specified in ``/etc/taler/taler.conf``.

.. code-block:: ini
  :caption: /etc/taler/taler.conf

   [taler]
   CURRENCY = EUR
   CURRENCY_ROUND_UNIT = EUR:0.01

   # ... rest of file ...

.. warning::

   When editing ``/etc/taler/taler.conf``, take care to not accidentally remove
   the @inline-matching@ directive to include the configuration files in ``conf.d``.

Next, the electronic cash denominations that the exchange offers must be
specified.  The ``taler-wallet-cli`` has a helper command that generates a
reasonable denomination structure.

.. code-block:: shell-session

  taler-wallet-cli deployment gen-coin-config --currency EUR > /etc/taler/conf.d/exchange-coins.conf

.. note::

   FIXME: change tool to not take currency from configuration, but instead
   to accept unit currency as the argument; (i.e. EUR:0.0025). Also take
   another argument for how many denominations to generate (2^XX). Finally,
   do use the unit currency as the default deposit fee.

You can manually review and edit the generated configuration file. The main
change that is possibly required is updating the various fees.


Wire Gateway Setup
==================

The Taler Wire Gateway is an API that connects the Taler exchange to
the underlying core banking system.

LibEuFin is an implementation of the Wire Gateway API for the EBICS.
Please follow the setup instructions in ??? to set up a Taler Wire Gateway with
LibEuFin for an EBICS bank account.

The exchange must be configured with the right settings to
access the Taler Wire Gateway.  An exchange can be configured
to use multiple bank accounts by using multiple Wire Gateways.
Typically only one Wire Gateway is used.

A Taler Wire Gateway is configured in a configuration section that follows the
pattern ``exchange-account-$id``, where ``$id`` is an internal identifier for
the bank account accessed with the Wire Gateway. The configuration file
``/etc/taler/conf.d/exchange-system.conf`` by default loads the section
``exchange-account-1`` from the secret file
``/etc/taler/secrets/exchange-accounts.secret.conf``.


.. code-block:: ini
  :caption: /etc/taler/secrets/exchange-accounts.secret.conf

  [exchange-account-1]
  enable_credit = yes
  enable_debit = yes

  # LibEuFin expects basic auth
  wire_gateway_auth_method = basic

  # username and password set in LibEuFin
  username = ...
  password = ...

  # base URL of the wire gateway set up with LibEuFin
  wire_gateway_url = ...

  # Account identifier in the form of an RFC-8905 payto:// URI
  # For SEPA, looks like payto://sepa/$IBAN
  payto_uri =

The Wire Gateway configuration can be tested with the following command:

.. code-block:: shell-session

   [root@exchange-online]# taler-exchange-wire-gateway-client \
     --section exchange-account-1 --debit-history
   [root@exchange-online]# taler-exchange-wire-gateway-client \
     --section exchange-account-1 --credit-history



Exchange Database Setup
=======================

The access credentials for the exchange's database are configured in
``/etc/taler/secrets/exchange-db.secret.conf``.  Currently, only postgres is
supported as a database backend.

The following users must have access to the exchange database:

* taler-exchange-httpd
* taler-exchange-wire
* taler-exchange-aggregator
* taler-exchange-closer

These users are all in the taler-exchange-db group, and the
``exchange-db.secret.conf`` is should already be only readable by users in
this group.

To create a database for the Taler exchange on the local system, run:

.. code-block:: shell-session

  [root@exchange-onlie]# su - postgres
  [postgres@exchange-online]# createuser taler-exchange-httpd
  [postgres@exchange-online]# createuser taler-exchange-wire
  [postgres@exchange-online]# createuser taler-exchange-aggregator
  [postgres@exchange-online]# createuser taler-exchange-closer
  [postgres@exchange-online]# createdb -O taler-exchange-httpd taler-exchange
  [postgres@exchange-online]# exit

This will create a ``taler-exchange`` database owned by the
``taler-exchange-httpd`` user.  We will use that user later to perform
database maintenance operations.

Next, we need to grant the other accounts limited access:

.. code-block:: shell-session

  [root@exchange-onlie]# echo 'GRANT SELECT,INSERT,UPDATE ON ALL TABLES IN SCHEMA public TO "taler-exchange-aggregator";' \
    | sudo -u taler-exchange-httpd psql taler-exchange
  [root@exchange-onlie]# echo 'GRANT SELECT,INSERT,UPDATE ON ALL TABLES IN SCHEMA public TO "taler-exchange-closer";' \
    | sudo -u taler-exchange-httpd psql taler-exchange
  [root@exchange-onlie]# echo 'GRANT SELECT,INSERT,UPDATE ON ALL TABLES IN SCHEMA public TO "taler-exchange-wire";' \
    | sudo -u taler-exchange-httpd psql taler-exchange


Assuming the above database setup, the database credentials to configure
in the configuration file would simply be:

.. code-block:: ini
  :caption: /etc/taler/secrets/exchange-db.secret.conf

  [exchangedb-postgres]
  CONFIG=postgres:///taler-exchange


If the database is run on a different host, please follow the instructions
from the Postgres manual for configuring remote access.

After configuring the database credentials, the exchange database needs
to be initialized with the following command:

.. code-block:: shell-session

  [root@exchange-online]# sudo -u taler-exchange-httpd taler-exchange-dbinit


Offline Signing Setup
=====================

The offline signing keys of the exchange should be stored on a different machine.
The responsibilities of this offline signing machine are:

* generation of the exchange's offline master signing key
* secure storage of the exchange's offline master signing key
* generation of certificates (signed with the offline master signing key) that will be imported by the exchange


.. code-block:: shell-session

  [root@exchange-online]# sudo -u taler-exchange-offline taler-exchange-offline setup
  < ... prints the exchange master public key >

The public key printed as the output of this command should must be put into the configuration
of the online machine:

.. code-block:: ini
  :caption: /etc/taler/conf.d/exchange-business.conf

   [exchange]
   MASTER_PUBLIC_KEY = YE6Q6TR1ED...

   # ... rest of file ...


Exchange Web service / API Setup
================================

By default, the ``taler-exchange-httpd`` service listens for HTTP connections
on a UNIX domain socket.  To make the service publicly available, a reverse
proxy such as nginx should be used.  We strongly recommend to configure nginx
to use TLS.

The public URL that the exchange will be served under should
be put in ``/etc/taler/conf.d/exchange-business.conf`` configuration file.

.. code-block:: ini
  :caption: /etc/taler/conf.d/exchange-business.conf

   [exchange]
   BASE_URL = https://example.com/

   # ... rest of file ...

The ``taler-exchange`` package ships with a sample configuration that can be
enabled in nginx:

.. code-block:: shell-session

  [root@exchange-online]# cp /etc/nginx/sites-available/taler-exchange /etc/nginx/sites-enabled/
  [root@exchange-online]# vim /etc/nginx/sites-enabled/taler-exchange
  < ... customize configuration ... >
  [root@exchange-online]# systemctl reload nginx


The exchange HTTP service can now be started:

.. code-block:: shell-session

  [root@exchange-online]# systemctl start taler-exchange.service
  [root@exchange-online]# export BASE_URL=$(taler-config -s exchange -o base_url)
  [root@exchange-online]# curl ${BASE_URL}management/keys


.. note::

   At this point, the exchange service not yet fully operational.


To check whether the exchange is running correctly under the advertise
base URL, run:

.. code-block:: shell-session

  [root@exchange-online]# export BASE_URL=$(taler-config -s exchange -o base_url)
  [root@exchange-online]# curl ${BASE_URL}management/keys


Offline Signing Procedure
=========================

The exchange HTTP service should be running now, but is not yet completely
operational.  To make the exchange HTTP service operational, the following
steps involving the offline signing machine must be completed:

1. The public keys of various online keys used by the exchange service are exported
   via a management HTTP API
2. The offline signing system validates this request and signs it.
   Additionally, the offline signing system signs policy messages
   to configure the exchange's bank accounts and associated fees.
3. The messages generated by the offline signing system are uploaded
   to via the management API of the exchange HTTP service.


.. code-block:: shell-session

  [root@exchange-online]# taler-exchange-offline \
    download > sig-request.json

  [root@exchange-offline]# taler-exchange-offline \
    sign < sig-request.json > sig-response.json
  [root@exchange-offline]# taler-exchange-offline \
    enable-account payto://sepa/$IBAN > acct-response.json
  [root@exchange-offline]# taler-exchange-offline \
    enable-account wire-fee 2021 sepa EUR:0 EUR:0 > fee-response.json

  [root@exchange-online]# taler-exchange-offline upload < sig-response.json
  [root@exchange-online]# taler-exchange-offline upload < acct-response.json
  [root@exchange-online]# taler-exchange-offline upload < fee-response.json




Testing and Troubleshooting
===========================

The following shell session illustrates how the wallet can be used to withdraw
electronic cash from the exchange and subsequently spend it.  For these steps,
a merchant backend is not required, as the wallet acts as a merchant.


.. code-block:: shell-session

  # This will now output a payto URI that money needs to be sent to in order to allow withdrawal
  # of taler coins
  $ taler-wallet-cli advanced withdraw-manually --exchange $EXCHANGE_URL --amount EUR:10.50

  # Show the status of the manual withdrawal operation
  $ taler-wallet-cli transactions

  #
  # At this point, a bank transfer to the exchange's bank account
  # needs to be made with the correct subject / remittance information
  # as instructed by the wallet after the first step.
  #

  # Check whether the exchange received an incoming bank transfer
  [root@exchange-online]# taler-exchangewire-gateway-client --section exchange-account-1 --credit-history

  # Once the transfer has been made, try completing the withdrawal
  $ taler-wallet-cli run-pending

  # Check status of transactions and show balance
  $ taler-wallet-cli transactions
  $ taler-wallet-cli balance

  # Now, directly deposit coins with the exchange into a target account
  # (Usually, a payment is made via a merchant.  The wallet provides
  # this functionality for testing.)
  $ taler-wallet-cli deposit create EUR:5 payto://sepa/$IBAN

  # Check if transaction was successful.
  # (If not, fix issue with exchange and run "run-pending" command again)
  $ taler-wallet-cli transactions

  # The wallet can also track if the exchange wired the money to the merchant account.
  # The "deposit group id" can be found in the output of the transactions list.
  $ taler-wallet-cli deposit track $DEPOSIT_GROUP_ID

  # Check whether the exchange sent an outgoing transfer
  [root@exchange-online]# taler-exchangewire-gateway-client --section exchange-account-1 --debit-history

  # After enough time has passed, the money should arrive at the specified IBAN


FIXMEs
======

* we need to make sure that after every step there is some command
  that can be executed to make sure the previous step succeeded /
  the admin is on the right track.
* We should describe the systemd services that need to be running
* we should have some summary with the inventory of services that should be running
* how do we know what offline signing steps are still required?  We don't have
  a tool for that ...
* when multiple TWGs are configured, which one will be used by the taler-exchange-transfer?
* we should have some tooling to show the current configuration state of the exchange,
  which then tells the admin what to do next (sign keys, configure account, configure wire fee),
  based on the /management and /keys / /wire APIs
* On Ubuntu focal fossa, I get the following warning on "apt update", are we doing something wrong?

  N: Skipping acquire of configured file 'main/binary-i386/Packages' as
  repository 'https://deb.taler.net/apt/ubuntu focal-fossa InRelease' doesn't
  support architecture 'i386'