View | Details | Raw Unified | Return to bug 37553
Collapse All | Expand All

(-)a/branches/ucs-4.0/ucs-4.0-0/services/univention-bind/bind-acl.py (+94 lines)
Line 0    Link Here 
1
#!/usr/bin/python2.7
2
# -*- coding: utf-8 -*-
3
"""
4
Univention BIND listener script
5
"""
6
# Copyright 2015 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
__package__ = ''  # workaround for PEP 366
34
import ldap
35
import listener
36
import ipaddr
37
import subprocess
38
39
name = 'bind-acl'
40
description = 'Update BIND ACLs'
41
filter = '(objectClass=univentionNetworkClass)'
42
attributes = ['univentionNetmask', 'univentionNetwork']
43
44
ACL_CONF_FILE = "/var/lib/bind/network-acls.conf"
45
RNDC_BIN = "/usr/sbin/rndc"
46
47
conf = {
48
	'ldapserver': None,
49
	'ldapport': 7389,
50
	'basedn': None,
51
	'binddn': None,
52
	'bindpw': None,
53
}
54
55
56
def setdata(key, value):
57
	conf[key] = value
58
59
60
def handler(dn, new, old):
61
	ldap_uri = "ldap://%(ldapserver)s:%(ldapport)d" % conf
62
	ldap_con = ldap.initialize(ldap_uri)
63
	ldap_con.bind_s(conf['binddn'], conf['bindpw'])
64
	networks = set()
65
	for dn, values in ldap_con.search_s(conf['basedn'], ldap.SCOPE_SUBTREE, filter, attributes):
66
		network = ipaddr.IPNetwork('%s/%s' % (
67
			values['univentionNetwork'][0],
68
			values['univentionNetmask'][0],
69
		))
70
		networks.add(network.masked())
71
72
	listener.setuid(0)
73
	try:
74
		with open(ACL_CONF_FILE, 'w') as acl:
75
			print >> acl, '# THIS FILE IS GENERATED BY bind-acl.py'
76
			print >> acl, 'acl ucs_networks {'
77
			print >> acl, '\tlocalhost;'
78
			for network in networks:
79
				print >> acl, '\t%s;' % (network,)
80
			print >> acl, '};'
81
		subprocess.call(('rndc', '-p', '953', 'reconfig'))
82
	finally:
83
		listener.unsetuid()
84
85
86
if __name__ == '__main__':
87
	from univention.config_registry import ConfigRegistry
88
	ucr = ConfigRegistry()
89
	ucr.load()
90
	setdata('ldapserver', ucr['ldap/server/name'])
91
	setdata('basedn', ucr['ldap/base'])
92
	setdata('binddn', ucr['ldap/hostdn'])
93
	setdata('bindpw', open('/etc/machine.secret', 'r').read())
94
	handler('', None, None)
(-)a/branches/ucs-4.0/ucs-4.0-0/services/univention-bind/conffiles/etc/bind/named.conf.proxy (-5 / +10 lines)
 Lines 1-15    Link Here 
1
@%@UCRWARNING=# @%@
1
@%@UCRWARNING=# @%@
2
2
3
3
4
controls{
4
controls {
5
        inet 127.0.0.1
5
        inet 127.0.0.1
6
        allow { @%@dns/master/address@%@; };
6
        allow { @%@dns/master/address@%@; };
7
};			
7
};
8
9
include "/var/lib/bind/network-acls.conf";
10
8
options {
11
options {
9
    directory "/var/cache/bind";
12
	directory "/var/cache/bind";
10
@!@
13
@!@
11
dns_allow_query = configRegistry.get('dns/allow/query')
14
NETWORK_ACL = 'ucs_networks'
12
dns_allow_query_cache = configRegistry.get('dns/allow/query/cache')
15
dns_allow_query = configRegistry.get('dns/allow/query', NETWORK_ACL)
16
dns_allow_query_cache = configRegistry.get('dns/allow/query/cache', NETWORK_ACL)
13
dns_allow_transfer = configRegistry.get('dns/allow/transfer')
17
dns_allow_transfer = configRegistry.get('dns/allow/transfer')
14
18
15
if dns_allow_query:
19
if dns_allow_query:
 Lines 25-30   if configRegistry.is_true('dns/ipv6', True ): Link Here 
25
	val = 'any'
29
	val = 'any'
26
print '\tlisten-on-v6 { %s; };' % val
30
print '\tlisten-on-v6 { %s; };' % val
27
@!@};
31
@!@};
32
28
logging {
33
logging {
29
	category lame-servers { null; };
34
	category lame-servers { null; };
30
	category default{ default_syslog; };
35
	category default{ default_syslog; };
(-)a/branches/ucs-4.0/ucs-4.0-0/services/univention-bind/conffiles/etc/bind/named.conf.samba4 (-7 / +9 lines)
 Lines 1-14    Link Here 
1
@%@UCRWARNING=# @%@
1
@%@UCRWARNING=# @%@
2
2
3
controls{
3
controls {
4
        inet 127.0.0.1
4
        inet 127.0.0.1
5
        allow { @%@dns/master/address@%@; };
5
        allow { @%@dns/master/address@%@; };
6
};			
6
};
7
8
include "/var/lib/bind/network-acls.conf";
9
7
options {
10
options {
8
        tkey-gssapi-keytab "/var/lib/samba/private/dns.keytab";
11
	tkey-gssapi-keytab "/var/lib/samba/private/dns.keytab";
9
@!@
12
@!@
10
dns_allow_query = configRegistry.get('dns/allow/query')
13
NETWORK_ACL = 'ucs_networks'
11
dns_allow_query_cache = configRegistry.get('dns/allow/query/cache')
14
dns_allow_query = configRegistry.get('dns/allow/query', NETWORK_ACL)
15
dns_allow_query_cache = configRegistry.get('dns/allow/query/cache', NETWORK_ACL)
12
dns_allow_transfer = configRegistry.get('dns/allow/transfer')
16
dns_allow_transfer = configRegistry.get('dns/allow/transfer')
13
17
14
if dns_allow_query:
18
if dns_allow_query:
 Lines 32-38   logging { Link Here 
32
	};
36
	};
33
};
37
};
34
38
35
36
@!@
39
@!@
37
if configRegistry.get('dns/forwarder1') or configRegistry.get('dns/forwarder2') or configRegistry.get('dns/forwarder3'):
40
if configRegistry.get('dns/forwarder1') or configRegistry.get('dns/forwarder2') or configRegistry.get('dns/forwarder3'):
38
	print '\n# Found a forwarder in ucr variables, using forwarder in zone ".".'
41
	print '\n# Found a forwarder in ucr variables, using forwarder in zone ".".'
 Lines 100-103   print '''dlz "samba4.zone" { Link Here 
100
@!@
103
@!@
101
104
102
include "/etc/bind/local.conf.samba4";
105
include "/etc/bind/local.conf.samba4";
103
(-)a/branches/ucs-4.0/ucs-4.0-0/services/univention-bind/debian/changelog (+6 lines)
 Lines 1-3    Link Here 
1
univention-bind (9.0.5-1) unstable; urgency=low
2
3
  * Bug #37553: Add ACL list to prevent Open DNS Resolver
4
5
 -- Philipp Hahn <hahn@univention.de>  Thu, 15 Jan 2015 14:22:30 +0100
6
1
univention-bind (9.0.4-1) unstable; urgency=low
7
univention-bind (9.0.4-1) unstable; urgency=low
2
8
3
  * If no dns/forwarder is set, use the nameserver variables as forwarder
9
  * If no dns/forwarder is set, use the nameserver variables as forwarder
(-)a/branches/ucs-4.0/ucs-4.0-0/services/univention-bind/debian/univention-bind.dirs (-5 lines)
 Lines 1-9    Link Here 
1
usr/lib/univention-directory-listener/system
2
usr/lib/univention-install/
3
etc/bind
4
etc/runit/univention-bind
1
etc/runit/univention-bind
5
etc/runit/univention-bind-proxy
2
etc/runit/univention-bind-proxy
6
etc/runit/univention-bind-samba4
3
etc/runit/univention-bind-samba4
7
etc/init.d
8
usr/share/univention-bind/
9
var/cache/univention-bind-proxy
4
var/cache/univention-bind-proxy
(-)a/branches/ucs-4.0/ucs-4.0-0/services/univention-bind/debian/univention-bind.install (+1 lines)
 Lines 1-4    Link Here 
1
bind.py usr/lib/univention-directory-listener/system
1
bind.py usr/lib/univention-directory-listener/system
2
bind-acl.py	usr/lib/univention-directory-listener/system/
2
05univention-bind.inst usr/lib/univention-install
3
05univention-bind.inst usr/lib/univention-install
3
etc/bind/db.root.fake etc/bind
4
etc/bind/db.root.fake etc/bind
4
90univention-bind-post.inst usr/lib/univention-install
5
90univention-bind-post.inst usr/lib/univention-install
(-)a/branches/ucs-4.0/ucs-4.0-0/services/univention-bind/debian/univention-bind.postinst (-6 / +6 lines)
 Lines 32-48    Link Here 
32
32
33
. /usr/share/univention-lib/all.sh
33
. /usr/share/univention-lib/all.sh
34
34
35
touch /var/lib/bind/network-acls.conf
36
35
#DEBHELPER#
37
#DEBHELPER#
36
38
37
# configure firewall
39
# configure firewall
38
ucr set security/packetfilter/package/univention-bind/udp/53/all=ACCEPT \
40
ucr set security/packetfilter/package/univention-bind/udp/53/all=ACCEPT \
39
        security/packetfilter/package/univention-bind/tcp/53/all=ACCEPT \
41
        security/packetfilter/package/univention-bind/tcp/53/all=ACCEPT \
40
		security/packetfilter/package/univention-bind/udp/7777/all=ACCEPT \
41
		security/packetfilter/package/univention-bind/tcp/7777/all=ACCEPT \
42
		security/packetfilter/package/univention-bind/udp/53/all/en="DNS proxy" \
42
		security/packetfilter/package/univention-bind/udp/53/all/en="DNS proxy" \
43
        security/packetfilter/package/univention-bind/tcp/53/all/en="DNS proxy" \
43
        security/packetfilter/package/univention-bind/tcp/53/all/en="DNS proxy" \
44
		security/packetfilter/package/univention-bind/udp/7777/all/en="DNS server" \
44
		security/packetfilter/package/univention-bind/udp/7777/all/en="Backend DNS server" \
45
		security/packetfilter/package/univention-bind/tcp/7777/all/en="DNS server"
45
		security/packetfilter/package/univention-bind/tcp/7777/all/en="Backend DNS server"
46
[ -x "/etc/init.d/univention-firewall" ] && invoke-rc.d univention-firewall restart
46
[ -x "/etc/init.d/univention-firewall" ] && invoke-rc.d univention-firewall restart
47
47
48
chmod g+w /etc/bind
48
chmod g+w /etc/bind
 Lines 51-57   chmod g+w /etc/bind/* Link Here 
51
univention-config-registry set 'bind/autostart?yes' \
51
univention-config-registry set 'bind/autostart?yes' \
52
                               'dns/ipv6?yes' \
52
                               'dns/ipv6?yes' \
53
                               'nameserver/external?false' \
53
                               'nameserver/external?false' \
54
                               'dns/allow/query?any' \
54
                               'dns/allow/query?ucs_networks' \
55
                               'dns/allow/query/cache?ucs_networks' \
55
                               'dns/allow/transfer?any' \
56
                               'dns/allow/transfer?any' \
56
                               'dns/dlz/debug/level?0' \
57
                               'dns/dlz/debug/level?0' \
57
                               'dns/debug/level?0'
58
                               'dns/debug/level?0'
58
- 

Return to bug 37553