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

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