GithubHelp home page GithubHelp logo

build_bind's Introduction

build_bind

This is the module that will enable the ability to extract and build BIND DNS server configurations from the database. It will output the configuration text that would normally be located in something like /etc/bind/named.conf or similar.

Install

  • If you have not already, run the following command echo '/opt/ona' > /etc/onabase. This assumes you installed ONA into /opt/ona
  • Ensure you have the following prerequisites installed:
    • A BIND DNS server. It is not required to be on the same host as the ONA system.
    • sendEmail for notification messages. Download here or use the package from your distribution.
    • A functioning dcm.pl install on your DHCP server.
  • Download the archive and place it in your $ONABASE/www/local/plugins directory, the directory must be named build_bind
  • Make the plugin directory owned by your webserver user I.E.: chown -R www-data /opt/ona/www/local/plugins/build_bind
  • From within the GUI, click Plugins->Manage Plugins while logged in as an admin user
  • Click the install icon for the plugin which should be listed by the plugin name
  • Follow any instructions it prompts you with.
  • Install the $ONABASE/www/local/plugins/build_bind/build_bind script on your DNS server. It is suggested to place it in /opt/ona/bin
  • Modify the variables at the top of the build_bind script to suit your environment.

Usage

At least one host within ONA should be defined as a DNS server for whatever domains you expect it to be responsible for. The install process above should have also created a system configuration variable called "build_dns_type" with a value of "bind".

You should now see the configuration being built real time in the web interface each time you select the server host and view its DNS server display page.

This now also exposes the dcm.pl module called build_bind_conf and build_bind_domain. These will be used by the build_bind script to extract the configuration. It is also used by the web interface to generate configuration data.

There are a few configuration options in the build script that should be examined. Edit the file /opt/ona/bin/build_bind and adjust the following options as needed:

# this will default to placing data files in /opt/ona/etc/bind, you can update the following for your system as needed
# for things like chroot jails etc
ONA_PATH="${ONABASE}/etc/bind"

# Get the local hosts FQDN.  It will be an assumption!! that it is the same as the hostname in ONA
# Also, the use of hostname -f can vary from system type to system type.  be aware!
SRV_FQDN="$(hostname -f)"

# Path to the dcm.pl command.  Also include any options that might be needed
DCM_PATH="${ONABASE}/bin/dcm.pl"

# Define path for curl binary requires if pulling templates from remote web server
CURL_PATH="/usr/bin/curl"

# Specify a URL to a directory located on a web server containing domain based
# footers with additional DNS records to be appended to respective DNS zones.
# Using this method footer files don't have to be manually synced between
# name servers. The remote path can be located on the web server that also
# provided for the OpenNetAdmin instance.
#
# It is highly recommended to use HTTPS (SSL/TLS) for transport security but
# at least ip address based access control e.g. using a htaccess file.
# When using http basic authentication you can embed the user credentials
# within the URI like this:
#
# # e.g. FOOTER_URL="https://USERNAME:[email protected]/zone_footers"
FOOTER_URL="https://USER:[email protected]/zone_footers" # no trailing slash

# The command used to check the configuration syntax prior to restarting the daemon
CHECKCOMMAND="named-checkconf -z"

# The command used to restart bind
# two options would be standard init.d or something like RNDC if it is configured
# in your environment
SYSTEMINIT="/etc/init.d/named reload"

# Email settings for config_archive to send status information to (diffs etc)
MAIL_SERVER=mail.example.com            # name or IP of the mail server to use
MAIL_FROM=ona-build_dhcpd@${SRV_FQDN}   # email address to use in the from field
[email protected]          # email address(es) to send our notifications to

Most BIND servers default to using /etc/bind/named.conf or similar as their config. You should make this a symbolic link to /opt/ona/etc/bind/named.conf.ona or do an include of this config file in your main named.conf.

On some systems you may need to add the ONA related files to your apparmor or similar security tool.

Now that it is installed you should be able to execute /opt/ona/bin/build_bind as root. This will build a configuration file from the data in ONA, test its syntax, and place it into the file /opt/ona/etc/bind/named.conf.ona. When the test is ran it will process configurations built from the database that are stored in /opt/ona/etc/bind. If it is successful it will restart the BIND server using the init program defined in the SYSTEMINIT config variable. Also set the value of CHECKCOMMAND to somethine like named-config -z to test the configuration before restarting.

Once you have a successful rebuild of your configuration, you can then put the /opt/ona/bin/build_bind build script into a cron that runs at whatever interval you see as appropriate for your environment. I would suggest at least 2 times a day all the way down to once every 15 minutes. Remember, you can always run it on demand if needed. You will need to run it as root since it needs to restart the daemon.

Many modern linux systems use the /etc/cron.d method. You can put ONA related cron jobs into this directory. As an example you can create a file called /etc/cron.d/ona with the following content:

# Please store only OpenNetAdmin related cron entries here.
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/:/opt/ona/bin

# Rebuild BIND configuration file and restart daemon every hour
0 * * * * root /opt/ona/bin/build_bind > /dev/null 2>&1

Configuration (version 1.6+)

Since version 1.6 the configuration is no longer embedded within the build_bind script itself. Instead it uses a separate config file expected at ${ONABASE}/etc/build_bind.conf.

Simply copy the sample config build_bind.conf.sample to etc/ within your base folder and adjust its parameters to fit your needs. However, it is also possible to provide a custom config using the -c <PATH>/CONFIG option.

Fetching Zone Footers from Remote Web Server

ONA does not yet support DNS records to be placed within DNS zones as long as those aren't handled through ONA itself. For instance, as of the moment it is not possible to add records for mail servers (MX) or canonical names (CNAMES) that are pointing to external servers. Creating local zone records for such email servers is one way to work around this limitation. However, it's fairly inconvenient especially when facing the fact that addresses for MX servers of large providers like Google are operated using volatile ip pools.

The reason why this wasn't fixed within ONA yet? It is related to the current database design. Matt explains it in the following threads:

Non ONA managed CNAMES (external DNS references) opennetadmin/ona#70

Adding remote host or CNAME - DNS import http://opennetadmin.com/forum_archive/4/t-65.html

To overcome this limitation for the moment, one can use zone footers in order to add necessary DNS records per zone e.g. using a script that's executed right after zones were generated by the build_bind script.

At the moment build_dns tries to implement this using so called 'remote footers'. By simply specifying the -t option build_dns can look for domain specific footers within a directory on a remote web server. Once a match was found the content of the footer file will be automatically appended to the local zone of the respective domain.

This approach allows for footers to be kept centrally without the need to manually synchronize them across servers. E.g. in order to add the global mail exchange servers of Google to the zone file of example.com do the following:

[root@ona ~]# cd /var/www/html/ona/
[root@ona ona]# mkdir zone_footers
[root@ona ona]# cat <<'HERE' > zone_footers/example.com.footer
; MX Records
@   1800    IN  MX  10  aspmx.l.google.com
@   1800    IN  MX  20  alt1.aspmx.l.google.com
@   1800    IN  MX  30  alt2.aspmx.l.google.com
@   1800    IN  MX  40  aspmx2.googlemail.com
@   1800    IN  MX  50  aspmx3.googlemail.com
HERE

In this example we're deploying the footers on the web server that is also hosting our ONA instance. This way one can re-use the .htpasswd file that's used to protect access to the dcm.php script. You do restrict access to your dcm.php script, don't you?

A bit out of scope but here's a snippet for a httpd virtual host containing the directives required to secure your installation including the footers folder:

<Files dcm.php>
  Order deny,allow
  # name server ip address
  allow from 10.238.13.8
  allow from localhost

  AuthUserFile /opt/ona/www/.htpasswd
  AuthName "dcm access"
  AuthType basic
  Require valid-user
</Files>

<Location "/zone_footers">
  Order deny,allow
  # name server ip address
  allow from 10.238.13.8
  allow from localhost

  Options Indexes MultiViews FollowSymLinks
  AllowOverride All

  AuthUserFile /opt/ona/www/.htpasswd
  AuthName "footer access"
  AuthType basic
  Require valid-user
</Location>

Create a separate account for authenticating access to the footers directory (the username reflects within the web server log file).

[root@ona ona]# htpasswd /opt/ona/www/.htpasswd footers
New password: *******
Re-type new password: ******* 
Adding password for user footers

On the name server you should now be able to fetch the footer for zone example.com we've created earlier:

[root@ns01 ~]# curl -s --output example.com.footer https://footers:[email protected]/zone_footers/example.com.footer
[root@ns01 ~]# cat example.com.footer
<MX RECORDS..>

Lets run build_bind with the -t option and see what happens:

[root@ns01 ~]# /opt/ona/bin/build_bind -t
Sep 30 22:51:17 [ONA:build_bind]: INFO => Building BIND DNS config for ns01.example.com...
Sep 30 22:51:23 [ONA:build_bind]: INFO => Scanning for footers on remote server ...
Sep 30 22:51:23 [ONA:build_bind]: INFO => Found a match for zone example.com.. appending.
Sep 30 22:51:26 [ONA:build_bind]: INFO => Testing new config files for SYNTAX only...
[...]
Sep 30 23:01:37 [ONA:build_bind]: INFO => Completed BIND configuration
extraction and daemon reload.

[root@ns01 ~]# tail -6 /var/named/zone_data/named-example.com 
; MX Records
@   1800    IN  MX  10  aspmx.l.google.com
@   1800    IN  MX  20  alt1.aspmx.l.google.com
@   1800    IN  MX  30  alt2.aspmx.l.google.com
@   1800    IN  MX  40  aspmx2.googlemail.com
@   1800    IN  MX  50  aspmx3.googlemail.com

Hint: It is highly recommended to implement transport security by using TLS. In a medium scale deployment w/o a proper way of distributing security certificates it almost always makes sense to use certs issued by a public CA. It is furthermore recommended to use a platform that delivers support for Perfect Forward Secrecy such as Apache 2.4 as part of CentOS 7.

build_bind's People

Contributors

8191 avatar mattpascoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

build_bind's Issues

Master seems currently unusable

Hi,

just tried to download and install build_bind, but seems the master is currently not usable.
in the webservers ona-access.log, I see:
192.168.0.52 - - [08/Nov/2015:21:10:15 +0800] "POST / HTTP/1.1" 200 1933 "http://ona/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
192.168.0.52 - - [08/Nov/2015:21:10:15 +0800] "POST / HTTP/1.1" 500 267 "http://ona/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"

in ona-error.log:
[Sun Nov 08 21:10:15.518891 2015] [authz_core:debug] [pid 26373] mod_authz_core.c(809): [client 192.168.0.52:50965] AH01626: authorization result of Require all granted: granted, referer: http://ona/
[Sun Nov 08 21:10:15.518947 2015] [authz_core:debug] [pid 26373] mod_authz_core.c(809): [client 192.168.0.52:50965] AH01626: authorization result of : granted, referer: http://ona/
[Sun Nov 08 21:10:15.519195 2015] [authz_core:debug] [pid 26373] mod_authz_core.c(809): [client 192.168.0.52:50965] AH01626: authorization result of Require all granted: granted, referer: http://ona/
[Sun Nov 08 21:10:15.519206 2015] [authz_core:debug] [pid 26373] mod_authz_core.c(809): [client 192.168.0.52:50965] AH01626: authorization result of : granted, referer: http://ona/
[Sun Nov 08 21:10:15.519695 2015] [:error] [pid 26373] [client 192.168.0.52:50965] PHP Notice: Array to string conversion in /fs/nysa/ona/www/include/functions_general.inc.php on line 7, referer: http://ona/
[Sun Nov 08 21:10:15.696443 2015] [deflate:debug] [pid 26373] mod_deflate.c(855): [client 192.168.0.52:50965] AH01384: Zlib: Compressed 5768 to 1582 : URL /index.php, referer: http://ona/
[Sun Nov 08 21:10:15.710962 2015] [authz_core:debug] [pid 26373] mod_authz_core.c(809): [client 192.168.0.52:50965] AH01626: authorization result of Require all granted: granted, referer: http://ona/
[Sun Nov 08 21:10:15.710993 2015] [authz_core:debug] [pid 26373] mod_authz_core.c(809): [client 192.168.0.52:50965] AH01626: authorization result of : granted, referer: http://ona/
[Sun Nov 08 21:10:15.711159 2015] [authz_core:debug] [pid 26373] mod_authz_core.c(809): [client 192.168.0.52:50965] AH01626: authorization result of Require all granted: granted, referer: http://ona/
[Sun Nov 08 21:10:15.711165 2015] [authz_core:debug] [pid 26373] mod_authz_core.c(809): [client 192.168.0.52:50965] AH01626: authorization result of : granted, referer: http://ona/
[Sun Nov 08 21:10:15.711587 2015] [:error] [pid 26373] [client 192.168.0.52:50965] PHP Notice: Array to string conversion in /fs/nysa/ona/www/include/functions_general.inc.php on line 7, referer: http://ona/

This happens when I try to "manage plugins" - the website displays an error code 500.

Please let me know if I can provide more data here. Installaton of build_isc_dhcp worked somethly a few minutes earlier.

When I remove the plugin again, everythings fine

DNS Views

build_bind_domain ignores the dns-view and merges all records together.

Bug with bind reload

Hi!

I just found a little typo in the build_bind script. Nothing serious, unless you want to reload your 'bind' configuration.

Line 219:
if ! $SYSTEMINT

Should be (missing 'I')
if ! $SYSTEMINIT

Thanks

MySQL 8 issue on plugin activation

Likely similar to the ona MySQL 8* issue.

Installing database updates:
 ERROR => SQL statements failed:
Incorrect integer value: '' for column 'id' at row 1

 Unable to automatically process SQL statements
      Please try again, or add the following SQL statements manually:
        
insert into users (id, username, password, level) values ('', 'sys_build', '638c0b71a1677183e7840ae6b5b646a2', 0 ) on duplicate key update username='sys_build';

insert into sys_config (name, value, description, field_validation_rule, failed_rule_text, editable, deleteable) values ('build_dns_type', 'bind', 'DNS build type', '', '', 1, 1) on duplicate key update value='bind';

Generate glue records

If NS server is not part of actual zone, a sticky record should be added, if the A record of the NS part is known to ONA.

Reverse lookups on RFC1918 addresses

For others who wonder why forward lookups work but reverse ones don't. Add this to your /etc/bind/named.conf.options under the options section:

        // Fix reverse lookups for hosts on RFC1918 addresses
        empty-zones-enable no;

Bind9 defaults to yes and will thus override any PTR records set through ONA.

forward zone breaks build_bind

Splitting off some domains to another platform and now bind configs fail to build.

root@unifipi:/opt/ona# bin/build_bind -t
Sep 30 23:56:53 [ONA:build_bind]: INFO => Building BIND DNS config for ona1.gc...
Sep 30 23:56:58 [ONA:build_bind]: INFO => Scanning for footers on remote server ...
Sep 30 23:56:58 [ONA:build_bind]: INFO => Testing new config files for SYNTAX only...
/etc/bind/named.conf.options:55: option 'dnssec-enable' is obsolete and should be removed 
/opt/ona/etc/bind/named.conf.ona:47: missing ';' before 'zone'
/opt/ona/etc/bind/named.conf.ona:65: missing ';' before 'zone'
/etc/bind/named.conf:11: missing ';' before 'include'
Sep 30 23:56:58 [ONA:build_bind]: ERROR => The resulting config files contain one or more syntax errors.

opt/ona/etc/bind/named.conf.ona:47: missing ';' before 'zone' <<< shown below.

...
zone "mm.eu" in {
  type forward;
  file "/opt/ona/etc/bind/zone_data/named-mm.eu";}
zone "254.31.172.in-addr.arpa" in {
  type master;
  file "/opt/ona/etc/bind/zone_data/named-254.31.172.in-addr.arpa";
};
...

It looks like some line feeds and a ";" are missing. I have three forwards defined and they all suffer the same issue after the zone definition.

Remove linebreaks from notes/comments

Notes on hosts get expanded to "; " in the bind output. Line breaks are just outputted as line breaks, which breaks the syntax of the bind zonefile.

email bypass

The script should allow users to disable the email sends if desired.

check that MAIL_TO is empty or not. If its empty, dont send an email

Allow for a local config

Currently if you modify the email settings or the system init or other variables at the top of the build script, they will be overridden the next time you do an update to the plugin. We should add a . include reference to a local config file if it exists that will override anything set in the main script.

Support zone options

This is a companion issue that implements the build_bind half of opennetadmin/ona#38.

It needs to take the new DB column and place it verbatim into the zone configuration section.

Timezone issue with newer PHP versions

I just updated my RedHat Enterprise Linux server 6 ONA server to the latest version of PHP (5.3.3-22.el6), using the latest ONA and build_bind 1.5

I keep having the following errors fill up the apache error log, and it seems unhappy about something in the build_bind module.


PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Jayapura' for 'CST/9.0/no DST' instead in /opt/ona/www/modules/build/build_bind.inc.php on line 394

I'm having to flush my logs out or it'll fill my /var to capacity, and tune PHP to show less errors.

I figure you can probably fix the issue though.

Bind9 forward named-* files are truncated after 76 lines when generated through an apache2 proxy

Let‘s assume you are running ONA (commit opennetadmin/ona@0ab7fd7 ) on an Apache2 server on port 8666 and this is again proxied via another apache server 1 with the configuration:

<Location /ona>
    RequestHeader unset Accept-Encoding
    ProxyPreserveHost on

    AddOutputFilterByType SUBSTITUTE text/html
    Substitute "s|http://server.example.org/ona|https://server.example.org/ona|ni"

    ProxyPassReverse /
</Location>


ProxyPass /ona http://127.0.0.1:8666/ona/
ProxyPassReverse /ona http://127.0.0.1:8666/ona/
ProxyRequests Off

And dcm.pl is configured to use:

url         => https://server.example.org/ona/dcm.php

Afterwards, the script build_bind at commit 5924d5c is run which builds a bind9 /opt/ona/etc/bind/zone_data/named-sub.example.org zone file, then the file named-sub.example.org is truncated after 76 lines. Of course you need at least 66 entries (first 10 lines are zone file header) for sub.example.org, so that you can see that the file is truncated. The 76 lines of the file are completely correct, just the rest is missing.
This error does not affect reverse lookup files, i.e. named-*.ip6.arpa or named-*.in-addr.arpa files; they are complete and can exceed 76 lines.
I have no idea why exactly 76 lines, but the number seems to be constant and not changing.

When I remove the proxy, i.e. configure dcm.pl to use:

url         => http://127.0.0.1:8666/ona/dcm.php

then named-sub.example.org is complete and does exceed 76 lines, so the problem arises really by using the proxy. I did not observe any other problems with the proxy.

When you read until this point and think, this cannot be and is wired behavior, especially the 76 lines, then I agree. But I had this problem already ~2 years ago, forgot it meanwhile, and configured now a server again with a proxy and the same problem occurs, so I can reproduce it on a second machine.
By the way, The apache proxy is just nice, I have no issues to run build_bind directly on http://127.0.0.1:8666/ona/ , just want to document the problem here.

1: When you wonder whey I am doing this, the first Apache server is running in a docker container.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.