]> git.sur5r.net Git - bacula/docs/blob - docs/manual-fr/stunnel.tex
- Litle fix
[bacula/docs] / docs / manual-fr / stunnel.tex
1 %%
2 %%
3
4 \section*{Using Bacula to Encrypt Communications to Clients}
5 \label{_ChapterStart6}
6 \index[general]{Clients!Using Bacula to Encrypt Communications to }
7 \index[general]{Using Bacula to Encrypt Communications to Clients }
8 \addcontentsline{toc}{section}{Using Bacula to Encrypt Communications to
9 Clients}
10
11 At the current time, Bacula does not have built-in communications encryption.
12 However, without too much effort, it is possible to encrypt the communications
13 between any of the daemons. This chapter will show you how to use {\bf
14 stunnel} to encrypt communications to your client programs. We assume the
15 Director and the Storage daemon are running on one machine that will be called
16 {\bf server} and the Client or File daemon is running on a different machine
17 called {\bf client}. Although the details may be slightly different, the same
18 principles apply whether you are encrypting between Unix, Linux, or Win32
19 machines. This example was developed between two Linux machines running
20 stunnel version 4.04-4 on a Red Hat Enterprise 3.0 system. 
21
22 \subsection*{Communications Ports Used}
23 \index[general]{Used!Communications Ports }
24 \index[general]{Communications Ports Used }
25 \addcontentsline{toc}{subsection}{Communications Ports Used}
26
27 First, you must know that with the standard Bacula configuration, the Director
28 will contact the File daemon on port 9102. The File daemon then contacts the
29 Storage daemon using the address and port parameters supplied by the Director.
30 The standard port used will be 9103. This in the typical server/client view of
31 the world, the File daemon is a server to the Director (i.e. listens for the
32 Director to contact it), and the Storage daemon is a server to the File
33 daemon. 
34
35 \subsection*{Encryption}
36 \index[general]{Encryption }
37 \addcontentsline{toc}{subsection}{Encryption}
38
39 The encryption is accomplished between the Director and the File daemon by
40 using an stunnel on the Director's machine (server) to encrypt the data and to
41 contact a stunnel on the File daemon's machine (client), which decrypts the
42 data and passes it to the client. 
43
44 Between the File daemon and the Storage daemon, we use an stunnel on the File
45 daemon's machine to encrypt the data and another stunnel on the Storage
46 daemon's machine to decrypt the data. 
47
48 As a consequence, there are actually four copies of stunnel running, two on
49 server and two on client. This may sound a bit complicated, but it really
50 isn't. To accomplish this, we will need to construct four separate conf files
51 for stunnel, and we will need to make some minor modifications to the
52 Director's conf file. None of the other conf files need to be changed. 
53
54 \subsection*{A Picture}
55 \index[general]{Picture }
56 \addcontentsline{toc}{subsection}{Picture}
57
58 Since pictures usually help a lot, here is an overview of what we will be
59 doing. Don't worry about all the details of the port numbers and such for the
60 moment. 
61
62 \footnotesize
63 \begin{verbatim}
64   File daemon (client):
65                  stunnel-fd1.conf
66                    |===========|
67   Port 29102  >----| Stunnel 1 |-----> Port 9102
68                    |===========|
69                  stunnel-fd2.conf
70                    |===========|
71   Port 9103   >----| Stunnel 2 |-----> server:29103
72                    |===========|
73   Director (server):
74                  stunnel-dir.conf
75                    |===========|
76   Port 29102  >----| Stunnel 3 |-----> client:29102
77                    |===========|
78                  stunnel-sd.conf
79                    |===========|
80   Port 29103  >----| Stunnel 4 |-----> 9103
81                    |===========|
82 \end{verbatim}
83 \normalsize
84
85 \subsection*{Certificates}
86 \index[general]{Certificates }
87 \addcontentsline{toc}{subsection}{Certificates}
88
89 In order for stunnel to function as a server, which it does in our diagram for
90 Stunnel 1 and Stunnel 4, you must have a certificate and the key. It is
91 possible to keep the two in separate files, but normally, you keep them in one
92 single .pem file. You may create this certificate yourself in which case, it
93 will be self-signed, or you may have it signed by a CA. 
94
95 If you want your clients to verify that the server is in fact valid (Stunnel 2
96 and Stunnel 3), you will need to have the server certificates signed by a CA
97 (Certificate Authority), and you will need to have the CA's public certificate
98 (contains the CA's public key). 
99
100 Having a CA signed certificate is {\bf highly} recommended if you are using
101 your client across the Internet, otherwise you are exposed to the man in the
102 middle attack and hence loss of your data. 
103
104 See below for how to create a self-signed certificate. 
105
106 \subsection*{Securing the Data Channel}
107 \index[general]{Channel!Securing the Data }
108 \index[general]{Securing the Data Channel }
109 \addcontentsline{toc}{subsection}{Securing the Data Channel}
110
111 To simplify things a bit, let's for the moment consider only the data channel.
112 That is the connection between the File daemon and the Storage daemon, which
113 takes place on port 9103. In fact, in a minimalist solution, this is the only
114 connection needs to be encrypted, because it is the one that transports your
115 data. The connection between the Director and the File daemon is simply a
116 control channel used to start the job and get the job status. 
117
118 Normally the File daemon will contact the Storage daemon on port 9103
119 (supplied by the Director), so we need a stunnel that listens on port 9103 on
120 the File daemon's machine, encrypts the data and sends it to the Storage
121 daemon. This is depicted by Stunnel 2 above. Note that this stunnel is
122 listening on port 9103 and sending to server:29103. We use port 29103 on the
123 server because if we sent the data to port 9103, it would go directly to the
124 Storage daemon, which doesn't understand encrypted data. On the server
125 machine, we run Stunnel 4, which listens on port 29103, decrypts the data and
126 sends it to the Storage daemon, which is listening on port 9103. 
127
128 \subsection*{Modification of bacula-dir.conf for the Data Channel}
129 \index[general]{Modification of bacula-dir.conf for the Data Channel }
130 \index[general]{Channel!Modification of bacula-dir.conf for the Data }
131 \addcontentsline{toc}{subsection}{Modification of bacula-dir.conf for the Data
132 Channel}
133
134 The Storage resource of the bacula-dir.conf normally looks something like the
135 following: 
136
137 \footnotesize
138 \begin{verbatim}
139 Storage {
140   Name = File
141   Address = server
142   SDPort = 9103
143   Password = storage_password
144   Device = File
145   Media Type = File
146 }
147 \end{verbatim}
148 \normalsize
149
150 Notice that this is running on the server machine, and it points the File
151 daemon back to server:9103, which is where our Storage daemon is listening. We
152 modify this to be: 
153
154 \footnotesize
155 \begin{verbatim}
156 Storage {
157   Name = File
158   Address = localhost
159   SDPort = 9103
160   Password = storage_password
161   Device = File
162   Media Type = File
163 }
164 \end{verbatim}
165 \normalsize
166
167 This causes the File daemon to send the data to the stunnel running on
168 localhost (the client machine). We could have used client as the address as
169 well. 
170
171 \subsection*{config Files for stunnel to Encrypt the Data Channel}
172 \index[general]{Config Files for stunnel to Encrypt the Data Channel }
173 \index[general]{Channel!config Files for stunnel to Encrypt the Data }
174 \addcontentsline{toc}{subsection}{config Files for stunnel to Encrypt the Data
175 Channel}
176
177 In the diagram above, we see above Stunnel 2 that we stunnel-fd2.conf on
178 client. A pretty much minimal config file would look like the following: 
179
180 \footnotesize
181 \begin{verbatim}
182 client = yes
183 [29103]
184 accept = localhost:9103
185 connect = server:29103
186 \end{verbatim}
187 \normalsize
188
189 The above config file does encrypt the data but it does not require a
190 certificate, so it is subject to the man in the middle attack. The file I
191 actually used, stunnel-fd2.conf, looked like this: 
192
193 \footnotesize
194 \begin{verbatim}
195 #
196 # Stunnel conf for Bacula client -> SD
197 #
198 pid = /home/kern/bacula/bin/working/stunnel.pid
199 #
200 # A cert is not mandatory here. If verify=2, a
201 #  cert signed by a CA must be specified, and
202 #  either CAfile or CApath must point to the CA's
203 #  cert
204 #
205 cert = /home/kern/stunnel/stunnel.pem
206 CAfile = /home/kern/ssl/cacert.pem
207 verify = 2
208 client = yes
209 # debug = 7
210 # foreground = yes
211 [29103]
212 accept = localhost:9103
213 connect = server:29103
214 \end{verbatim}
215 \normalsize
216
217 You will notice that I specified a pid file location because I ran stunnel
218 under my own userid so I could not use the default, which requires root
219 permission. I also specified a certificate that I have as well as verify level
220 2 so that the certificate is required and verified, and I must supply the
221 location of the CA (Certificate Authority) certificate so that the stunnel
222 certificate can be verified. Finally, you will see that there are two lines
223 commented out, which when enabled, produce a lot of nice debug info in the
224 command window. 
225
226 If you do not have a signed certificate (stunnel.pem), you need to delete the
227 cert, CAfile, and verify lines. 
228
229 Note that the stunnel.pem, is actually a private key and a certificate in a
230 single file. These two can be kept and specified individually, but keeping
231 them in one file is more convenient. 
232
233 The config file, stunnel-sd.conf, needed for Stunnel 4 on the server machine
234 is: 
235
236 \footnotesize
237 \begin{verbatim}
238 #
239 # Bacula stunnel conf for Storage daemon
240 #
241 pid = /home/kern/bacula/bin/working/stunnel.pid
242 #
243 # A cert is mandatory here, it may be self signed
244 #  If it is self signed, the client may not use
245 #  verify
246 #
247 cert   = /home/kern/stunnel/stunnel.pem
248 client = no
249 # debug = 7
250 # foreground = yes
251 [29103]
252 accept = 29103
253 connect = 9103
254 \end{verbatim}
255 \normalsize
256
257 \subsection*{Starting and Testing the Data Encryption}
258 \index[general]{Starting and Testing the Data Encryption }
259 \index[general]{Encryption!Starting and Testing the Data }
260 \addcontentsline{toc}{subsection}{Starting and Testing the Data Encryption}
261
262 It will most likely be the simplest to implement the Data Channel encryption
263 in the following order: 
264
265 \begin{itemize}
266 \item Setup and run Bacula backing up some data on your  client machine
267    without encryption.  
268 \item Stop Bacula.  
269 \item Modify the Storage resource in the Director's conf  file.  
270 \item Start Bacula  
271 \item Start stunnel on the server with:  
272
273    \footnotesize
274 \begin{verbatim}
275      stunnel stunnel-sd.conf
276   
277 \end{verbatim}
278 \normalsize
279
280 \item Start stunnel on the client with:  
281
282    \footnotesize
283 \begin{verbatim}
284     stunnel stunnel-fd2.conf
285   
286 \end{verbatim}
287 \normalsize
288
289 \item Run a job.  
290 \item If it doesn't work, turn debug on in both stunnel conf files,  restart
291    the stunnels, rerun the job, repeat until it works. 
292    \end{itemize}
293
294 \subsection*{Encrypting the Control Channel}
295 \index[general]{Channel!Encrypting the Control }
296 \index[general]{Encrypting the Control Channel }
297 \addcontentsline{toc}{subsection}{Encrypting the Control Channel}
298
299 The Job control channel is between the Director and the File daemon, and as
300 mentioned above, it is not really necessary to encrypt, but it is good
301 practice to encrypt it as well. The two stunnels that are used in this case
302 will be Stunnel 1 and Stunnel 3 in the diagram above. Stunnel 3 on the server
303 might normally listen on port 9102, but if you have a local File daemon, this
304 will not work, so we make it listen on port 29102. It then sends the data to
305 client:29102. Again we use port 29102 so that the stunnel on the client
306 machine can decrypt the data before passing it on to port 9102 where the File
307 daemon is listening. 
308
309 \subsection*{Modification of bacula-dir.conf for the Control Channel}
310 \index[general]{Channel!Modification of bacula-dir.conf for the Control }
311 \index[general]{Modification of bacula-dir.conf for the Control Channel }
312 \addcontentsline{toc}{subsection}{Modification of bacula-dir.conf for the
313 Control Channel}
314
315 We need to modify the standard Client resource, which would normally look
316 something like: 
317
318 \footnotesize
319 \begin{verbatim}
320 Client {
321   Name = client-fd
322   Address = client
323   FDPort = 9102
324   Catalog = BackupDB
325   Password = "xxx"
326 }
327 \end{verbatim}
328 \normalsize
329
330 to be: 
331
332 \footnotesize
333 \begin{verbatim}
334 Client {
335   Name = client-fd
336   Address = localhost
337   FDPort = 29102
338   Catalog = BackupDB
339   Password = "xxx"
340 }
341 \end{verbatim}
342 \normalsize
343
344 This will cause the Director to send the control information to
345 localhost:29102 instead of directly to the client. 
346
347 \subsection*{config Files for stunnel to Encrypt the Control Channel}
348 \index[general]{Config Files for stunnel to Encrypt the Control Channel }
349 \index[general]{Channel!config Files for stunnel to Encrypt the Control }
350 \addcontentsline{toc}{subsection}{config Files for stunnel to Encrypt the
351 Control Channel}
352
353 The stunnel config file, stunnel-dir.conf, for the Director's machine would
354 look like the following: 
355
356 \footnotesize
357 \begin{verbatim}
358 #
359 # Bacula stunnel conf for the Directory to contact a client
360 #
361 pid = /home/kern/bacula/bin/working/stunnel.pid
362 #
363 # A cert is not mandatory here. If verify=2, a
364 #  cert signed by a CA must be specified, and
365 #  either CAfile or CApath must point to the CA's
366 #  cert
367 #
368 cert   = /home/kern/stunnel/stunnel.pem
369 CAfile = /home/kern/ssl/cacert.pem
370 verify = 2
371 client = yes
372 # debug = 7
373 # foreground = yes
374 [29102]
375 accept = localhost:29102
376 connect = client:29102
377 \end{verbatim}
378 \normalsize
379
380 and the config file, stunnel-fd1.conf, needed to run stunnel on the Client
381 would be: 
382
383 \footnotesize
384 \begin{verbatim}
385 #
386 # Bacula stunnel conf for the Directory to contact a client
387 #
388 pid = /home/kern/bacula/bin/working/stunnel.pid
389 #
390 # A cert is not mandatory here. If verify=2, a
391 #  cert signed by a CA must be specified, and
392 #  either CAfile or CApath must point to the CA's
393 #  cert
394 #
395 cert   = /home/kern/stunnel/stunnel.pem
396 CAfile = /home/kern/ssl/cacert.pem
397 verify = 2
398 client = yes
399 # debug = 7
400 # foreground = yes
401 [29102]
402 accept = localhost:29102
403 connect = client:29102
404 \end{verbatim}
405 \normalsize
406
407 \subsection*{Starting and Testing the Control Channel}
408 \index[general]{Starting and Testing the Control Channel }
409 \index[general]{Channel!Starting and Testing the Control }
410 \addcontentsline{toc}{subsection}{Starting and Testing the Control Channel}
411
412 It will most likely be the simplest to implement the Control Channel
413 encryption in the following order: 
414
415 \begin{itemize}
416 \item Stop Bacula.  
417 \item Modify the Client resource in the Director's conf  file.  
418 \item Start Bacula  
419 \item Start stunnel on the server with:  
420
421    \footnotesize
422 \begin{verbatim}
423      stunnel stunnel-dir.conf
424   
425 \end{verbatim}
426 \normalsize
427
428 \item Start stunnel on the client with:  
429
430    \footnotesize
431 \begin{verbatim}
432     stunnel stunnel-fd1.conf
433   
434 \end{verbatim}
435 \normalsize
436
437 \item Run a job.  
438 \item If it doesn't work, turn debug on in both stunnel conf files,  restart
439    the stunnels, rerun the job, repeat until it works. 
440    \end{itemize}
441
442 \subsection*{Using stunnel to Encrypt to a Second Client}
443 \index[general]{Using stunnel to Encrypt to a Second Client }
444 \index[general]{Client!Using stunnel to Encrypt to a Second }
445 \addcontentsline{toc}{subsection}{Using stunnel to Encrypt to a Second Client}
446
447 On the client machine, you can just duplicate the setup that you have on the
448 first client file for file and it should work fine. 
449
450 In the bacula-dir.conf file, you will want to create a second client pretty
451 much identical to how you did for the first one, but the port number must be
452 unique. We previously used: 
453
454 \footnotesize
455 \begin{verbatim}
456 Client {
457   Name = client-fd
458   Address = localhost
459   FDPort = 29102
460   Catalog = BackupDB
461   Password = "xxx"
462 }
463 \end{verbatim}
464 \normalsize
465
466 so for the second client, we will, of course, have a different name, and we
467 will also need a different port. Remember that we used port 29103 for the
468 Storage daemon, so for the second client, we can use port 29104, and the
469 Client resource would look like: 
470
471 \footnotesize
472 \begin{verbatim}
473 Client {
474   Name = client2-fd
475   Address = localhost
476   FDPort = 29104
477   Catalog = BackupDB
478   Password = "yyy"
479 }
480 \end{verbatim}
481 \normalsize
482
483 Now, fortunately, we do not need a third stunnel to on the Director's machine,
484 we can just add the new port to the config file, stunnel-dir.conf, to make: 
485
486 \footnotesize
487 \begin{verbatim}
488 #
489 # Bacula stunnel conf for the Directory to contact a client
490 #
491 pid = /home/kern/bacula/bin/working/stunnel.pid
492 #
493 # A cert is not mandatory here. If verify=2, a
494 #  cert signed by a CA must be specified, and
495 #  either CAfile or CApath must point to the CA's
496 #  cert
497 #
498 cert   = /home/kern/stunnel/stunnel.pem
499 CAfile = /home/kern/ssl/cacert.pem
500 verify = 2
501 client = yes
502 # debug = 7
503 # foreground = yes
504 [29102]
505 accept = localhost:29102
506 connect = client:29102
507 [29104]
508 accept = localhost:29102
509 connect = client2:29102
510 \end{verbatim}
511 \normalsize
512
513 There are no changes necessary to the Storage daemon or the other stunnel so
514 that this new client can talk to our Storage daemon. 
515
516 \subsection*{Creating a Self-signed Certificate}
517 \index[general]{Creating a Self-signed Certificate }
518 \index[general]{Certificate!Creating a Self-signed }
519 \addcontentsline{toc}{subsection}{Creating a Self-signed Certificate}
520
521 You may create a self-signed certificate for use with stunnel that will permit
522 you to make it function, but will now allow certificate validation. The .pem
523 file containing both the certificate and the key can be made with the
524 following, which I put in a file named {\bf makepem}: 
525
526 \footnotesize
527 \begin{verbatim}
528 #!/bin/sh
529 #
530 # Simple shell script to make a .pem file that can be used
531 # with stunnel and Bacula
532 #
533 OPENSSL=openssl
534    umask 77
535    PEM1=`/bin/mktemp openssl.XXXXXX`
536    PEM2=`/bin/mktemp openssl.XXXXXX`
537    ${OPENSSL} req -newkey rsa:1024 -keyout $PEM1 -nodes \
538        -x509 -days 365 -out $PEM2
539    cat $PEM1 > stunnel.pem
540    echo ""   >>stunnel.pem
541    cat $PEM2 >>stunnel.pem
542    rm $PEM1 $PEM2
543 \end{verbatim}
544 \normalsize
545
546 The above script will ask you a number of questions. You may simply answer
547 each of them by entering a return, or if you wish you may enter your own data.
548
549
550 \subsection*{Getting a CA Signed Certificate}
551 \index[general]{Certificate!Getting a CA Signed }
552 \index[general]{Getting a CA Signed Certificate }
553 \addcontentsline{toc}{subsection}{Getting a CA Signed Certificate}
554
555 The process of getting a certificate that is signed by a CA is quite a bit
556 more complicated. You can purchase one from quite a number of PKI vendors, but
557 that is not at all necessary for use with Bacula. To get a CA signed
558 certificate, you will either need to find a friend that has setup his own CA
559 or to become a CA yourself, and thus you can sign all your own certificates.
560 The book OpenSSL by John Viega, Matt Mesier \& Pravir Chandra from O'Reilly
561 explains how to do it, or you can read the documentation provided in the
562 Open-source PKI Book project at Source Forge: 
563 \elink{
564 http://ospkibook.sourceforge.net/docs/OSPKI-2.4.7/OSPKI-html/ospki-book.htm}
565 {http://ospkibook.sourceforge.net/docs/OSPKI-2.4.7/OSPKI-html/ospki-book.htm}.
566 Note, this link may change. 
567
568 \subsection*{Using ssh to Secure the Communications}
569 \index[general]{Communications!Using ssh to Secure the }
570 \index[general]{Using ssh to Secure the Communications }
571 \addcontentsline{toc}{subsection}{Using ssh to Secure the Communications}
572
573 Please see the script {\bf ssh-tunnel.sh} in the {\bf examples} directory. It
574 was contributed by Stephan Holl.