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