Agenda: dns-acl-tsig-transfer-security.txt

File dns-acl-tsig-transfer-security.txt, 7.8 KB (added by admin, 6 years ago)
Line 
1BIND TRANSFER SECURITY
2----------------------
3
4We're going to limit zone transfer of your zones so that only
5your secondary/slave nameservers are allowed to request copies
6of the zones.
7
8Note: if the instructor group (for example, group 0) is providing slave
9(secondary) service for your domain, then the "partner" referred below
10is the instructor responsible for group 0.
11
12ACL based security
13------------------
14
15To start with, we'll enable IP based ACLs -- on the AUTH1 host:
16
171. Start by editing /etc/namedb/named.conf, and in the "options" section,
18   let's define who is allowed to transfer your zone.
19
20   allow-transfer { 127.0.0.1; ::1; YOUR_OWN_IP; myslaves; };
21
22   ... replace "YOUR_OWN_IP" with the IP of your machine :)
23
24   Now we need to define the ACL "myslaves".  To do so, AFTER the options
25   section (find the '};' symbol at the end of the section), add something
26   similar to this:
27
28   (If the slave for your "MYTLD" domain is auth1.grp25, for example)
29
30acl myslaves { 10.20.25.1; 10.20.X.2; }; // ACL with IP of Group25 master
31
32        This means "myslaves is an ACL consisting of the IP 10.20.25.1,
33        and your NSD secondary 10.20.25.2.
34
35        NOTE: remember to enter the correct values! You must write the IP
36        of the machine who is your secondary in the class - remember !
37
382. Restart named
39
40        $ sudo service named restart
41
423. Make sure that you didn't break the zone transfer, by asking your
43   slave partner to run a zone transfer against YOUR machine.
44
45   From their server:
46
47   $ dig @auth1.grpX.dns.nsrc.org MYTLD axfr
48
49   Make sure that it still works.
50
514. Now try and ask someone else in the class whose server is NOT in the
52   ACL to try the same axfr command as above.
53
54   Q: Do they succeed ?
55
56   Q: What do you see in the logs in /etc/namedb/log/general ?
57      What do you see in the logs in /etc/namedb/log/transfers ?
58
59TSIG KEY based security
60-----------------------
61
62Instead of using IP addresses, we'll now be using cryptographic keys
63to authenticate zone transfer -- this uses TSIG, a mechanism by which
64the communication between the master and slave server will be authenticated
65using this key.
66
671. Run:
68
69        $ cd /tmp/
70        $ sudo dnssec-keygen -a HMAC-MD5 -b 128 -n HOST mydomain.key
71
72        You will see something similar to this:
73
74Kmydomain.key.+157+32373   (the last number will change)
75
76        Two files have been created:
77
78        $ ls -l K*
79
80Kmydomain.key.+157+32373.key
81Kmydomain.key.+157+32373.private
82
832. View the contents of the private key
84
85        $ cat Kmydomain.key.+157+32373.private
86
87        You will see something similar to:
88
89Private-key-format: v1.2
90Algorithm: 157 (HMAC_MD5)
91Key: tHTRSKKrmyGmPnzNCf2IRA==
92Bits: AAA=
93
94        ... the "Key:" is the important bit here, so copy
95        "tHTRSKKrmyGmPnzNCf2IRA==", but of course not the one above, the one
96        in YOUR file :)
97
98        We will use this in the next steps.
99
1003.  Modify your named.conf
101
102        $ cd /etc/namedb/
103
104        Edit the file, and change the allow-transfer statement, so that it looks
105        like this:
106
107options {
108        ...
109        allow-transfer { 127.0.0.1; ::1; };  // myslaves is removed!
110        ...
111};
112
113        Note: We have removed "myslaves"
114
115        Now, after the options (or at the bottom of the file), add a new
116        declaration for the key
117
118key "mydomain-key" {
119        algorithm hmac-md5;
120        secret "tHTRSKKrmyGmPnzNCf2IRA=="; // Your REAL key goes here!
121
122};
123
124        Change the definition for your zone:
125
126zone "MYTLD" {
127        type master;
128        file "/etc/namedb/master/mytld";
129
130        allow-transfer { key mydomain-key; };   // <-- Add this!
131};
132
133As you can see above, we've added an "allow-transfer" statement
134allowing transfer of the zone for holders of the "mydomain-key".
135
136Note: the allow-transfer is now placed INSIDE the zone definition,
137and not globally inside the options section -- BIND can control zone
138transfer either globally, or by zone. We could have chosen to allow
139transfers GLOBALLY (for all zones), by leaving the allow-transfer
140statement in the main "options" section.
141
1424. Restart named
143
144        $ sudo service named restart
145
1465. Try and make a zone transfer from ANOTER machine -- ask your neighbors to do:
147
148        $ dig @10.20.XX.1 MYTLD axfr
149
150        Look at /etc/namedb/log/general and /etc/namedb/log/transfers
151
152        Q: What do you notice ?
153
1546. Then, ask them to try again with the key:
155
156        $ dig @10.20.XX.1 axfr mydomain -y mydomain-key:tHTRSKKrmyGmPnzNCf2IRA==
157
158        Q: what happens now ?
159
160        Check the logs again, especially /etc/namedb/log/transfers
161
162
1637. On your partner's SLAVE host (your secondary - again, this may be
164   the instructor if they are providing secondary service for your
165   domain).
166
167        Start by asking your partner to delete their copy of your zone:
168
169        - Have them remove the zone from /etc/namedb/slave/MYTLD --
170          remember, this is on the machine of your SLAVE partner:
171
172        $ sudo rm /etc/namedb/slave/MYTLD
173
174        - Ask them to restart named
175       
176        $ sudo service named restart
177
178        Check with them that the zone is gone AND that their server wasn't
179        able to reload it.
180
181        Q: What do you see in the MASTER (auth1) logs (transfers and general) ?
182
183        Q: What do you see in the SLAVE logs (transfers and general) ?
184
1858. Still on the SLAVE (if the instructor is providing secondary service,
186   they will perform this part)
187
188Find the statement for the zone:
189
190zone "MYTLD" {
191        type slave;
192        masters { 10.20.XX.1; };
193        file "slave/mydomain.dns";
194};
195
196... and add the key, and a statement to tell which key to use
197when talking to "10.20.XX.1" (the master):
198
199key mydomain-key {
200        algorithm hmac-md5;
201        secret "tHTRSKKrmyGmPnzNCf2IRA==";
202};
203server 10.20.XX.1 {             // here you put the IP of YOUR master
204        keys { mydomain-key; };
205};
206
2079. Restart named
208
209        $ sudo service named restart
210
211        On the SLAVE server:
212
213        Q: Is the zone "MYTLD" back in the slave/ directory ?
214
215        Q: What do you see in the MASTER (auth1) logs (transfers and general) ?
216
217        Q: What do you see in the SLAVE logs (transfers and general) ?
218
219        Can you see a general benefit from using keys instead of IP ACLs ?
220
221Optional section if you are running a secondary yourself:
222
22310. Now, do the same for your NSD "auth2" server
224
225        ... since you have disabled IP ACLs, your AUTH NSD server is not
226        able to get the zone!
227
228        Read the NSD manual page (man nsd.conf) if you are in doubt about
229        how to specify the key format in NSD for zone transfers. Update
230        update the "zone:" definition for MYTLD, so that it now uses
231        a KEY instead of NOKEY to transfer the zone from your MASTER (auth1).
232
233        After, you will need to run "nsdc restart".  Does the zone get
234        transferred ?  Remember to check the logs on the MASTER (auth1) as
235        well!
236
237Optional section if you are using Swatch to monitor the logs:
238
23911. If you set up Swatch in a previous exercise, make it complain if it
240   sees a forbidden zone transfer:
241
242        Edit /usr/local/etc/swatch.conf, and add a new section -- remember
243        to use TAB for the space at the beginning of the lines:
244
245- - - - - - - - - - - - - - -  cut below - - - - - - - - - - - - - -
246
247
248watchfor /client ([0-9.:]+)\D\d+: zone transfer '(.*)\/.XFR\/IN' denied$/
249        mail=sysadm,subject=Denied AXFR for zone '$2' from $1
250        threshold type=limit,count=1,seconds=600
251
252- - - - - - - - - - - - - - -  cut above - - - - - - - - - - - - - -
253
25412. Kill Swatch
255
256        $ ps ax | grep swatch
257
258        Find the process ID (the number on the left), and run kill on it:
259
260        $ sudo kill PID_OF_SWATCH
261
262        Restart swatch (switch to root temporarily using the sudo -s command)
263
264        $ sudo -s
265        # /usr/local/bin/swatch -c /usr/local/etc/swatch.conf --tail-file=/etc/namedb/log/general --daemon
266        # exit
267        $
268
269
270        Note: Why are we telling swatch to look at the "general" log file ?
271
272        If you remember from the previous logging lab, we configured BIND
273        to log the security category into the general channel definition.
274        Therefore, we need to monitor the /etc/namedb/log/general file.
275
27613. Re-run the zone transfer as in step 4 (from another machine) and see if
277   you receive a mail to the arm user when that happens.:
278
279        $ mutt -f /var/mail/sysadm
280
281   Try again 2 more times to do AXFR within a minute.
282
283   Q: How many mails did you receive? Why?
284