File: uruk-rc.5

package info (click to toggle)
uruk 20190121-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,188 kB
  • sloc: sh: 1,852; makefile: 151; xml: 51
file content (592 lines) | stat: -rw-r--r-- 13,090 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
.\" Copyright (c) 2019 Joost van Baal-Ilić <joostvb-uruk@mdcc\&.cx>
.TH "uruk-rc" 5 "21 јан 2019" "uruk-rc 20190121" "FILE FORMATS "
.po 2m
.de ZI
.\" Zoem Indent/Itemize macro I.
.br
'in +\\$1
.nr xa 0
.nr xa -\\$1
.nr xb \\$1
.nr xb -\\w'\\$2'
\h'|\\n(xau'\\$2\h'\\n(xbu'\\
..
.de ZJ
.br
.\" Zoem Indent/Itemize macro II.
'in +\\$1
'in +\\$2
.nr xa 0
.nr xa -\\$2
.nr xa -\\w'\\$3'
.nr xb \\$2
\h'|\\n(xau'\\$3\h'\\n(xbu'\\
..
.if n .ll -2m
.am SH
.ie n .in 4m
.el .in 8m
..
.SH NAME
uruk-rc \- uruk resource file, defining access policy
.SH SYNOPSIS

\fC/etc/uruk/rc\fP
.SH DESCRIPTION
\fIrc\fP is a shell script snippet, sourced in \fBuruk\fP by /bin/sh\&.

\fIrc\fP lists IP addresses, allowed to use services\&.
.SH EXAMPLES

\fBdefault\fP
.br
The simplest valid \fIrc\fP file is the empty file\&. This \fIrc\fP file blocks all TCP
and UDP connection attempts to services on our host: this is the default
behaviour\&.

\fBsimplest\fP
.br
The simplest \fIrc\fP file which does allow traffic to our services looks like e\&.g\&.:

.di ZV
.in 0
.nf \fC
 interfaces=eth0

 ips_eth0=default
 ip_eth0_default=192\&.168\&.26\&.27
 net_eth0_default=192\&.168\&.0\&.0/16

 ip6_eth0_default=2001:db8::1/64
 net6_eth0_default=2001:db8::/32

 services_eth0_default_tcp=local
 ports_eth0_default_tcp_local="0:65535"
 sources_eth0_default_tcp_local="0\&.0\&.0\&.0/0 ::/0"

 services_eth0_default_udp=local
 ports_eth0_default_udp_local="0:65535"
 sources_eth0_default_udp_local="0\&.0\&.0\&.0/0"
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

This \fIrc\fP file allows all IPv4 and IPv6 UDP and TCP traffic from publicly routable IPs to
eth0\&'s IP\&.

\fBrealistic\fP
.br
If you\&'d like to block traffic on wlan0 and allow traffic to ssh on your
wired interface, and don\&'t like to explicitly set your IPs in \fIrc\fP:

.di ZV
.in 0
.nf \fC
 # list of interfaces you\&'d like uruk to protect
 interfaces=eth0 wlan0

 # set variables ip{,6}_eth0_default and net{,6}_eth0_default
 \&. /lib/uruk/init/autodetect-ips
 
 # names for eth0\&'s 2 IPv4 addresses
 ips_eth0="default dhcp"

 # allow access to our sshd on eth0\&'s primary IP on tcp port 443
 # from anywhere
 services_eth0_default_tcp=ssh
 ports_eth0_default_tcp_ssh=443
 sources_eth0_default_tcp_ssh="0\&.0\&.0\&.0/0 ::/0"
 
 # we get a static IPv4 via dhcp
 ip_eth0_dhcp=10\&.0\&.0\&.3
 net_eth0_dhcp=10\&./8

 services_eth0_dhcp_tcp=http
 ports_eth0_dhcp_tcp_http=http
 sources_eth0_dhcp_tcp_http=$net_eth0_dhcp

 # we leave services_wlan0_default_{tcp,udp} unset: don\&'t allow any
 # incoming connections on wlan0\&'s default IP 
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

\fBautodetect-ips\fP
.br
The script autodetect-ips --as used in the previous example-- looks for files
/etc/sysconfig/network-scripts/ifcfg-* (commonly found at e\&.g\&. Red Hat and
Fedora systems) and /etc/network/interfaces (as found at e\&.g\&. Debian and Ubuntu
systems), and, for each interface \fInic\fP, and each found IPv4 and IPv6
address and network, sets variables \fCip_\fP\fInic\fP\fC_default\fP,
\fCip6_\fP\fInic\fP\fC_default\fP, \fCnet_\fP\fInic\fP\fC_default\fP and
\fCnet6_\fP\fInic\fP\fC_default\fP \&. Then it calls ip(8) and adds any other found
\fInic\fP, \fCip\fP and \fCnet\fP triplets (for IPv4 and, for IPv6, only addresses
in scope "global")\&.

The script autodetect-ips is useful if you\&'d like to share your \fIrc\fP file among
different hosts\&.

\fBanother example\fP
.br
For an even more reasonable \fIrc\fP file, look at the well-commented example \fIrc\fP
file in \fC/usr/share/doc/uruk/examples/rc\fP\&.
.SH IPv4 AND IPv6

You can mix IPv4 and IPv6-addresses in sources_*\&. E\&.g\&.:

.di ZV
.in 0
.nf \fC
 ips_eth0=\&'default private\&'
 ip_eth0_default=1\&.2\&.3\&.4
 ip6_eth0_default=

 services_eth0_default_tcp=\&'mail local\&'

 sources_eth0_default_tcp_mail=\&'10\&.0\&.0\&.0/24 192\&.0\&.32\&.0/24 192\&.168\&.6\&.26\&'
 sources_eth0_default_tcp_local=\&'192\&.0\&.32\&.0/24 svejk\&.example\&.com 2001:db8::/32\&'

 ports_eth0_default_tcp_mail=smtp
 ports_eth0_default_tcp_local=\&'ssh ftp\&'
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

If svejk\&.example\&.com has both an IPv4 PTR record in DNS, as well as
an IPv6 PTR record, connection attempts from svejk to the ssh and ftp
TCP ports are allowed, via both IPv4 and IPv6\&.

Uruk used to require variables sources6_* to be set to support ip6tables\&.
Since uruk version 20140319 (The Alfama Release), this is no longer needed;
setting sources_* suffices\&. To be precise, the semantics since uruk version
20140319 is: 1) If both sources_* and sources6_* are defined (even if they\&'re
just empty), each is used for its respective address family\&. (This ensures
backwards compatibility\&.) 2) If sources6_* is undefined, sources_* is used for
both v4 and v6\&. 3) In either case, v4 literals in v6 context and v6 literals
in v4 context are silently (!) ignored\&.
.SH HOOKS
Uruk offers hooks for inserting your own code between iptables invocations\&.
Examples will show the usefulness of these hooks\&.

\fBallowing broadcasts\fP
.br
In \fIrc\fP, there is:

.di ZV
.in 0
.nf \fC
 rc_b=$etcdir/bootp
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

while the file \fCbootp\fP reads

.di ZV
.in 0
.nf \fC
 iptables \-A INPUT \-m state \-\-state NEW \-i eth0 \e
   \-\-protocol udp \-\-destination-port bootps \-j ACCEPT
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

\&.
This enables one to add rules for packets with broadcast addresses in their
destination\&. (Uruk has no support for this in its regular \fIrc\fP\&.)

\fBallowing non-matching returntraffic\fP
.br
In \fIrc\fP there is:

.di ZV
.in 0
.nf \fC
 rc_d=$etcdir/dns
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

while the file \fCdns\fP reads

.di ZV
.in 0
.nf \fC
  for source in 10\&.5\&.0\&.27 10\&.56\&.0\&.40
  do
    $iptables -A INPUT -i eth0 --protocol udp \e
      --source "$source" --source-port domain \e
      --destination "$ip_eth0" \e
      --destination-port 30000: -j ACCEPT
  done
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

This allows one to allow (return)traffic, disregarding the state\&. (Uruk has no
support for this in its regular \fIrc\fP\&.)

\fBallowing NAT\fP
.br
In \fIrc\fP there is:

.di ZV
.in 0
.nf \fC
 rc_a=${etcdir}/nat
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

while the file \fCnat\fP reads

.di ZV
.in 0
.nf \fC
  $iptables -t nat -A POSTROUTING \e
    --out-interface eth0 -j SNAT \e
    --to-source $ip_eth0
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

This allows Network Address Translation\&. However, beware! Like all extensive
use of hooks, this will break the \fBuruk-save\fP script\&. If you make sure your
active iptables rules are wiped, and invoke \fBuruk\fP manually to load new rules,
you\&'re safe\&. Using the init script with its default settings is safe too\&.

\fBallowing IPv6 tunneling\fP
.br
In \fIrc\fP there is:

.di ZV
.in 0
.nf \fC
 rc_b=${etcdir}/proto_41
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

while the file \fCproto_41\fP reads

.di ZV
.in 0
.nf \fC
 $iptables -A INPUT -i ppp0 --protocol 41 --destination $ip_ppp0 -j ACCEPT
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

This allows IP protocol 41, typically used for this kind of tunneling\&.

\fBallowing any traffic on an interface\fP
.br
In \fIrc\fP there is:

.di ZV
.in 0
.nf \fC
 interfaces_unprotect="lo eth2"
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

This allows any traffic on \fCeth2\fP (and on \fClo\fP, the default), including
any ICMP packets and packets from any source address\&.

\fBusing multiple hooks at one entry point in the main uruk process\fP
.br
In case rc_a, rc_b, \&.\&.\&. , or rc_i does not have a file as its value, but a
directory, all files matching "$rc_x"/*\&.rc will get sourced\&. This helps
configuration management in complex situations involving lots of uruk
configuration files for lots of hosts\&.

See the section "THE GORY DETAILS: uruk INTERNALS" in \fBuruk(8)\fP
(or the \fBuruk\fP source) to find out which hook (there are hooks rc_a, rc_b, \&.\&.\&. ,
rc_i) to use\&.
.SH NETWORK INTERFACES WITH MULTIPLE IP ADDRESSES
Uruk supports situations where a network interface has more than one IP address
attached\&. Variables \fCips_\fP\fInic\fP and \fCbcasts_\fP\fInic\fP are used for
this\&.

If \fCips_\fP\fInic\fP is set, e\&.g\&. like

.di ZV
.in 0
.nf \fC
 ips_eth0="ip0 ip1 ip2"
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

we assume multiple (three in this example) IPs are assigned to \fCeth0\fP\&. If
this variable is not set only one IP is supported on \fCeth0\fP\&.

In multiple-IP mode, IP addresses are listed as e\&.g\&.

.di ZV
.in 0
.nf \fC
 ip_eth0_ip0="137\&.56\&.247\&.16"
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

(If you\&'re used to the Linux ifconfig(8) output, you could use the name \fCip\fP
for \fCeth0\fP, and \fCip0\fP for \fCeth0:0\fP\&.)
The \fIports\fP, \fIservices\fP and \fIsources\fP variables look like
e\&.g\&.

.di ZV
.in 0
.nf \fC
 services_eth0_ip2_tcp=local
 ports_eth0_ip2_tcp_local=smtp
 sources_eth0_ip2_tcp_local=$localnet
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

and, similarly,

.di ZV
.in 0
.nf \fC
 net_eth0_ip1=192\&.168\&.0\&.0/16
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

Furthermore, for dropping broadcast packets, specify e\&.g\&.

.di ZV
.in 0
.nf \fC
 bcasts_eth0="ip0 ip2"     # yes, possibly a subset of ips_eth0
 bcast_eth0_ip0="10\&.0\&.0\&.255"
 bcast_eth0_ip2="10\&.0\&.255\&.255"
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

As an additional feature, if you have multiple IP addresses that all need
to get the same rules, you can assign them to a single name:

.di ZV
.in 0
.nf \fC
 ip_eth0_ip0="137\&.56\&.247\&.16 137\&.56\&.247\&.17 137\&.56\&.247\&.18"
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

.SH LOGGING AND DEBUGGING
Uruk has support for logging network packets, and for debugging the uruk
script\&.

\fBLogging\fP
.br
By default, uruk logs denied packets\&. This is adjustable using the
\fIloglevel\fP variable\&. The settings are:

.ZI 2m "\(bu"
\&
.br
"zero": be silent; do not log any packet\&. \fIrc\fP file features \fCloglevel=10\fP\&.
.in -2m
.ZI 2m "\(bu"
\&
.br
"low": log denied packets, which are targeted at one of our IPs\&.
\fIrc\fP file features \fCloglevel=30\fP\&.
.in -2m
.ZI 2m "\(bu"
\&
.br
"medium": log denied non-broadcast packets\&. This is the default:
\fIloglevel\fP is unset or \fIrc\fP file features \fCloglevel=50\fP\&.
.in -2m
.ZI 2m "\(bu"
\&
.br
"fascist": log all packets\&. \fIrc\fP file features \fCloglevel=90\fP\&.
.in -2m

\fBDebugging\fP
.br
To debug the \fBuruk\fP script, invoke uruk as

.di ZV
.in 0
.nf \fC
 sh -x /sbin/uruk
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

this shows what is done, along with executing it\&. (Like an uruk \&'-v\&' option\&.)

If you\&'d rather prefer not to execute, but just watch what would\&'ve been done,
invoke uruk as

.di ZV
.in 0
.nf \fC
 URUK_IPTABLES=\&'echo iptables\&' URUK_IP6TABLES=\&'echo ip6tables\&' uruk
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

(Like an uruk \&'-n\&' option\&.) If you have this statement set, you can run \fBuruk\fP
under a non-priviliged user account\&.

If you\&'d like to test a new \fIrc\fP file before installing it, run something like:

.di ZV
.in 0
.nf \fC

  URUK_CONFIG=/path/to/new/uruk/rc/file uruk
.fi \fR
.in
.di
.ne \n(dnu
.nf \fC
.ZV
.fi \fR

Of course, all these tweaks can be combined\&.
.SH VARIABLES
The uruk script honors the following variables in \fIrc\fP files:

.ZI 2m "\(bu"
\&
.br
"version" Uruk version compatibility of this \fIrc\fP file
.in -2m
.ZI 2m "\(bu"
\&
.br
"loglevel"
.in -2m
.ZI 2m "\(bu"
\&
.br
"iptables" Full pathname of iptables executable\&.
.in -2m
.ZI 2m "\(bu"
\&
.br
"ip6tables" Full pathname of ip6tables executable\&.
.in -2m
.ZI 2m "\(bu"
\&
.br
"interfaces" List of network interfaces\&.
.in -2m
More variables are available\&. For now, you\&'ll have to take a look at the
example \fIrc\fP file in \fC/usr/share/doc/uruk/examples/rc\fP for more details\&.
.SH ENVIRONMENT VARIABLES
See \fBuruk(8)\fP for a list of honored environment variables\&.
.SH FILES
\fC/etc/uruk/rc\fP
.SH SEE ALSO
A well-commented example \fIrc\fP file is in \fC/usr/share/doc/uruk/examples/rc\fP\&.
And see \fBuruk(8)\fP, \fBuruk-save(8)\fP\&.
.SH COPYRIGHT
Copyright (C) 2005, 2007, 2008, 2010, 2011, 2012, 2013 Joost van Baal-Ilić <joostvb-uruk@mdcc\&.cx>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version\&.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\&. See the
GNU General Public License for more details\&.

You should have received a copy of the GNU General Public License along
with this program\&. If not, see http://www\&.gnu\&.org/licenses/\&.
.SH AUTHOR
Joost van Baal-Ilić <joostvb-uruk@mdcc\&.cx>