]> git.sur5r.net Git - bacula/docs/blob - docs/manual/security.tex
Update
[bacula/docs] / docs / manual / security.tex
1 %%
2 %%
3
4 \section*{Bacula Security Issues}
5 \label{_ChapterStart14}
6 \index[general]{Bacula Security Issues}
7 \index[general]{Security}
8 \index[general]{Issues!Bacula Security}
9 \addcontentsline{toc}{section}{Bacula Security Issues}
10
11 \begin{itemize}
12 \item Security means being able to restore your files, so read the 
13    \ilink{Critical Items Chapter}{Critical} of this manual.
14 \item The Clients ({\bf bacula-fd}) must run as root to be able to access  all
15    the system files. 
16 \item It is not necessary to run the Director as root. 
17 \item It is not necessary to run the Storage daemon as root, but you  must
18    ensure that it can open the tape drives, which are often restricted to root
19    access by default. In addition, if you do not run the Storage daemon as root,
20    it will not be able to automatically set your tape drive parameters on most
21    OSes since these functions, unfortunately require root access.
22 \item You should restrict access to the Bacula configuration files,  so that
23    the passwords are not world-readable. The {\bf Bacula}  daemons are password
24    protected using CRAM-MD5 (i.e. the password is not  sent across the network).
25    This will ensure that not everyone  can access the daemons. It is a reasonably
26    good protection, but  can be cracked by experts. 
27 \item If you are using the recommended ports 9101, 9102, and 9103, you  will
28    probably want to protect these ports from external access  using a firewall
29    and/or using tcp wrappers ({\bf etc/hosts.allow}).  
30 \item By default, all data that is sent across the network is unencrypted.
31    However, Bacula does support TLS (transport layer security) and can
32    encrypt transmitted data.  Please read the
33    \ilink{TLS (SSL) Communications Encryption}{CommEncryption}
34    section of this manual.
35 \item You should ensure that the Bacula working directories are  readable and
36    writable only by the Bacula daemons. 
37 \item If you are using {\bf MySQL} it is not necessary for it to  run with
38    {\bf root} permission. 
39 \item The default Bacula {\bf grant-mysql-permissions} script  grants all
40    permissions to use the MySQL database without a  password. If you want
41    security, please tighten this up! 
42 \item Don't forget that Bacula is a network program, so anyone anywhere  on
43    the network with the console program and the Director's password  can access
44    Bacula and the backed up data. 
45 \item You can restrict what IP addresses Bacula will bind to by using the 
46    appropriate {\bf DirAddress}, {\bf FDAddress}, or {\bf SDAddress}  records in
47    the respective daemon configuration files. 
48 \item Be aware that if you are backing up your database using the default
49    script, if you have a password on your database, it will be passed as
50    a command line option to that script, and any user will be able to see
51    this information. If you want it to be secure, you will need to pass it
52    by an environment variable or a secure file.
53 \end{itemize}
54
55
56 \subsection*{Backward Compatibility}
57 \index[general]{Backward Compatibility}
58 \addcontentsline{toc}{subsection}{Backward Compatibility}
59 One of the major goals of Bacula is to ensure that you can restore
60 tapes (I'll use the word tape to include disk Volumes) that you wrote years
61 ago.  This means that each new version of Bacula should be able to read old
62 format tapes. The first problem you will have is to ensure that the 
63 hardware is still working some years down the road, and the second
64 problem will be to ensure that the media will still be good, then 
65 your OS must be able to interface to the device, and finally Bacula
66 must be able to recognize old formats.  All the problems except the
67 last are ones that we cannot solve, but by careful planning you can.
68
69 Since the very beginning of Bacula (January 2000) until today (December
70 2005), there have been two major Bacula tape formats.  The second format
71 was introduced in version 1.27 in November of 2002, and it has not
72 changed since then.  In principle, Bacula can still read the original
73 format, but I haven't tried it lately so who knows ...
74
75 Though the tape format is fixed, the kinds of data that we can put on the
76 tapes are extensible, and that is how we added new features
77 such as ACLs, Win32 data, encrypted data, ...  Obviously, an older
78 version of Bacula would not know how to read these newer data streams,
79 but each newer version of Bacula should know how to read all the 
80 older streams.
81
82 If you want to be 100% sure that you can read old tapes, you
83 should:
84
85 1. Try reading old tapes from time to time -- e.g. at least once
86 a year.
87
88 2. Keep statically linked copies of every version of Bacula that you use
89 in production then if for some reason, we botch up old tape compatibility, you
90 can always pull out an old copy of Bacula ...
91
92 The second point is probably overkill but if you want to be sure, it may
93 save you someday.
94
95
96
97 \label{wrappers}
98 \subsection*{Configuring and Testing TCP Wrappers}
99 \index[general]{Configuring and Testing TCP Wrappers}
100 \index[general]{TCP Wrappers}
101 \index[general]{Wrappers!TCP}
102 \index[general]{libwrappers}
103 \addcontentsline{toc}{subsection}{Configuring and Testing TCP Wrappers}
104
105 TCP Wrappers are implemented if you turn them on when configuring
106 ({\bf ./configure \verb:--:with-tcp-wrappers}). 
107 With this code enabled, you may control who may access your
108 daemons.  This control is done by modifying the file: {\bf
109 /etc/hosts.allow}.  The program name that {\bf Bacula} uses when
110 applying these access restrictions is the name you specify in the
111 daemon configuration file (see below for examples).
112 You must not use the {\bf twist} option in your {\bf
113 /etc/hosts.allow} or it will terminate the Bacula daemon when a
114 connection is refused.
115
116 The exact name of the package you need loaded to build with TCP wrappers
117 depends on the system.  For example,
118 on SuSE, the TCP wrappers libraries needed to link Bacula are
119 contained in the tcpd-devel package. On RedHat the package is named
120 tcp\_wrappers.
121
122 Dan Langille has provided the following information on configuring and
123 testing TCP wrappers with Bacula. 
124
125 If you read hosts\_options(5), you will see an option called twist. This
126 option replaces the current process by an instance of the specified shell
127 command. Typically, something like this is used: 
128
129 \footnotesize
130 \begin{verbatim}
131 ALL : ALL \
132  : severity auth.info \
133  : twist /bin/echo "You are not welcome to use %d from %h."
134 \end{verbatim}
135 \normalsize
136
137 The libwrap code tries to avoid {\bf twist} if it runs in a resident process,
138 but that test will not protect the first hosts\_access() call. This will
139 result in the process (e.g. bacula-fd, bacula-sd, bacula-dir) being terminated
140 if the first connection to their port results in the twist option being
141 invoked. The potential, and I stress potential, exists for an attacker to
142 prevent the daemons from running. This situation is eliminated if your
143 /etc/hosts.allow file contains an appropriate rule set. The following example
144 is sufficient: 
145
146 \footnotesize
147 \begin{verbatim}
148 undef-fd : localhost : allow
149 undef-sd : localhost : allow
150 undef-dir : localhost : allow
151 undef-fd : ALL : deny
152 undef-sd : ALL : deny
153 undef-dir : ALL : deny
154 \end{verbatim}
155 \normalsize
156
157 You must adjust the names to be the same as the Name directives found
158 in each of the daemon configuration files. They are, in general, not the
159 same as the binary daemon names. It is not possible to use the 
160 daemon names because multiple daemons may be running on the same machine
161 but with different configurations.
162
163 In these examples, the Director is undef-dir, the
164 Storage Daemon is undef-sd, and the File Daemon is undef-fd. Adjust to suit
165 your situation. The above example rules assume that the SD, FD, and DIR all
166 reside on the same box. If you have a remote FD client, then the following
167 rule set on the remote client will suffice: 
168
169 \footnotesize
170 \begin{verbatim}
171 undef-fd : director.example.org : allow
172 undef-fd : ALL : deny
173 \end{verbatim}
174 \normalsize
175
176 where director.example.org is the host which will be contacting the client
177 (ie. the box on which the Bacula Director daemon runs). The use of "ALL :
178 deny" ensures that the twist option (if present) is not invoked. To properly
179 test your configuration, start the daemon(s), then attempt to connect from an
180 IP address which should be able to connect. You should see something like
181 this: 
182
183 \footnotesize
184 \begin{verbatim}
185 $ telnet undef 9103
186 Trying 192.168.0.56...
187 Connected to undef.example.org.
188 Escape character is '^]'.
189 Connection closed by foreign host.
190 $
191 \end{verbatim}
192 \normalsize
193
194 This is the correct response. If you see this: 
195
196 \footnotesize
197 \begin{verbatim}
198 $ telnet undef 9103
199 Trying 192.168.0.56...
200 Connected to undef.example.org.
201 Escape character is '^]'.
202 You are not welcome to use undef-sd from xeon.example.org.
203 Connection closed by foreign host.
204 $
205 \end{verbatim}
206 \normalsize
207
208 then twist has been invoked and your configuration is not correct and you need
209 to add the deny statement. It is important to note that your testing must
210 include restarting the daemons after each connection attempt. You can also
211 tcpdchk(8) and tcpdmatch(8) to validate your /etc/hosts.allow rules. Here is a
212 simple test using tcpdmatch: 
213
214 \footnotesize
215 \begin{verbatim}
216 $ tcpdmatch undef-dir xeon.example.org
217 warning: undef-dir: no such process name in /etc/inetd.conf
218 client: hostname xeon.example.org
219 client: address 192.168.0.18
220 server: process undef-dir
221 matched: /etc/hosts.allow line 40
222 option: allow
223 access: granted
224 \end{verbatim}
225 \normalsize
226
227 If you are running Bacula as a standalone daemon, the warning above can be
228 safely ignored. Here is an example which indicates that your rules are missing
229 a deny statement and the twist option has been invoked. 
230
231 \footnotesize
232 \begin{verbatim}
233 $ tcpdmatch undef-dir 10.0.0.1
234 warning: undef-dir: no such process name in /etc/inetd.conf
235 client: address 10.0.0.1
236 server: process undef-dir
237 matched: /etc/hosts.allow line 91
238 option: severity auth.info
239 option: twist /bin/echo "You are not welcome to use
240   undef-dir from 10.0.0.1."
241 access: delegated
242 \end{verbatim}
243 \normalsize
244
245 \subsection*{Running as non-root}
246 \index[general]{Running as non-root }
247 \addcontentsline{toc}{subsection}{Running as non-root}
248
249 Security advice from Dan Langille: 
250
251 It is a good idea to run daemons with the lowest possible privileges.  In
252 other words, if you can, don't run applications as root which do  not have to
253 be root.  The Storage Daemon and the Director Daemon do not need to be root.
254 The  File Daemon needs to be root in order to access all files on your system.
255 In order to run as non-root, you need to create a user and a group.  Choosing
256 {\tt bacula} as both the user name and the group name sounds like a good idea
257 to me.  
258
259 The FreeBSD port creates this user and group for you (actually, as I  write
260 this, the port doesn't do that, but it soon will). Here is what those  entries
261 looked like on my FreeBSD laptop: 
262
263 \footnotesize
264 \begin{verbatim}
265 bacula:*:1002:1002::0:0:Bacula Daemon:/var/db/bacula:/sbin/nologin
266 \end{verbatim}
267 \normalsize
268
269 I used vipw to create this entry. I selected a User ID and Group ID  of 1002
270 as they were unused on my system.  
271
272 I also created a group in /etc/group:  
273
274 \footnotesize
275 \begin{verbatim}
276 bacula:*:1002:
277 \end{verbatim}
278 \normalsize
279
280 The bacula user (as opposed to the Bacula daemon) will have a home  directory
281 of {\tt /var/db/bacula} which is the  default location for the Bacula
282 database.  
283
284 Now that you have both a bacula user and a bacula group, you can  secure the
285 bacula home directory by issuing this command: 
286
287 \footnotesize
288 \begin{verbatim}
289 chown -R bacula:bacula /var/db/bacula/
290 \end{verbatim}
291 \normalsize
292
293 This ensures that only the bacula user can access this directory.  It also
294 means that if we run the Director and the Storage daemon  as bacula, those
295 daemons also have restricted access. This would not be  the case if they were
296 running as root.  
297
298 It is important to note that the storage daemon actually needs  to be in the
299 operator group for normal access to tape drives etc (at  least on a FreeBSD
300 system, that's how things are set up by default)  Such devices are normally
301 chown root:operator. It is easier and less  error prone  to make Bacula a
302 member of that group than it is to play around  with system permissions. 
303
304 Starting the Bacula daemons 
305
306 To start the bacula daemons on a FreeBSD system, issue the following command: 
307
308 \footnotesize
309 \begin{verbatim}
310 /usr/local/etc/rc.d/bacula.sh start
311 \end{verbatim}
312 \normalsize
313
314 To confirm they are all running: 
315
316 \footnotesize
317 \begin{verbatim}
318 $ ps auwx | grep bacula
319 root\ 63416\ 0.0\ 0.3\ 2040 1172\ ??\ Ss\ 4:09PM 0:00.01
320     /usr/local/sbin/bacula-sd -v -c /usr/local/etc/bacula-sd.conf
321 root\ 63418\ 0.0\ 0.3\ 1856 1036\ ??\ Ss\ 4:09PM 0:00.00
322     /usr/local/sbin/bacula-fd -v -c /usr/local/etc/bacula-fd.conf
323 root\ 63422\ 0.0\ 0.4\ 2360 1440\ ??\ Ss\ 4:09PM 0:00.00
324     /usr/local/sbin/bacula-dir -v -c /usr/local/etc/bacula-dir.conf
325 \end{verbatim}
326 \normalsize