Package: octodns
DNS as code - Tools for managing DNS across multiple providersIn the vein ofinfrastructure as
codeoctoDNS provides a set of tools & patterns that make it easy to manage your DNS records across multiple providers. The resulting config can live in a repository and bedeployedjust like the rest of your code, maintaining a clear history and using your existing review & workflow.The architecture is pluggable and the tooling is flexible to make it applicable to a wide variety of use-cases. Effort has been made to make adding new providers as easy as possible. In the simple case that involves writing of a singleclassand a couple hundred lines of code, most of which is translating between the provider's schema and octoDNS's. More on some of the ways we use it and how to go about extending it below and in the/docs directory.Table of ContentsGetting startedWorkspaceInstalling a specific commit SHAConfigDynamic Zone ConfigStatic Zone ConfigGeneral Configuration ConceptsQuick Example RecordNoopMaking changesWorkflowBootstrapping config filesProvidersUpdating to use extracted providersSourcesNotesProcessorsAutomatic PTR generationCompatibility and Compliancelenientstrict_supportsConfiguringstrict_supportsCustom Sources and ProvidersOther UsesSyncing between providersDynamic sourcesContributingGetting helpRelated Projects and ResourcesLicenseAuthorsGetting startedWorkspaceRunning through the following commands will install the latest release of octoDNS and set up a place for your config files to live. To determine if provider specific requirements are necessary see theproviders tablebelow.$mkdirdns$cddns$python-mvenvenv...$sourceenv/bin/activate#provider-specific-requirementswouldbethingslike:octodns-route53octodns-azure$pipinstalloctodns<provider-specific-requirements>$mkdirconfigInstalling a specific commit SHAIf you'd like to install a version that has not yet been released in a repeatable/safe manner you can do the following. In general octoDNS is fairly stable in between releases thanks to the plan and apply process, but care should be taken regardless.$pipinstall-egit+https://git@github.com/octodns/octodns.git@<SHA>#egg=octodnsConfigWe start by creating a config file to tell octoDNS about our providers and the zone(s) we want it to manage. Below we're setting up aYamlProviderto source records from our config files and both aRoute53ProviderandDynProviderto serve as the targets for those records. You can have any number of zones set up and any number of sources of data and targets for records for each. You can also have multiple config files, that make use of separate accounts and each manage a distinct set of zones. A good example of this this might be./config/staging.yaml&./config/production.yaml. We'll focus on aconfig/production.yaml.Dynamic Zone ConfigoctoDNS supports dynamically building the list of zones it will work with when source providers support it. The most common use of this would be withYamlProviderand a single dynamic entry to in effect use the files that exist in the provider's directory as the source of truth. Other providers may support thelist_zonesmethod and be available to populate zones dynamically as well. This can be especially useful when usingoctodns-dumpto create an initial setup from an existing provider.An example config would look something like:providers:
config:
class: octodns.provider.yaml.YamlProvider
directory: ./config
default_ttl: 3600
enforce_order: True
ns:
class: octodns_ns1.Ns1Provider
api_key: env/NS1_API_KEY
route53:
class: octodns_route53.Route53Provider
access_key_id: env/AWS_ACCESS_KEY_ID
secret_access_key: env/AWS_SECRET_ACCESS_KEYzones:This is a dynamic zone config. The source(s), hereconfig, will bequeried for a list of zone names and each will dynamically be set up tomatch the dynamic entry.'*':
sources:
- config
targets:
- ns1
- route53Static Zone ConfigIn cases where finer grained control is desired and the configuration of individual zones varieszonescan be an explicit list with each configured zone listed along with its specific setup. As exemplified belowaliaszones can be useful when two zones are exact copies of each other, with the same configuration and records. YAML anchors are also helpful to avoid duplication where zones share config, but not records.manager:
include_meta: True
max_workers: 2providers:
config:
class: octodns.provider.yaml.YamlProvider
directory: ./config
default_ttl: 3600
enforce_order: True
ns:
class: octodns_ns1.Ns1Provider
api_key: env/NS1_API_KEY
route53:
class: octodns_route53.Route53Provider
access_key_id: env/AWS_ACCESS_KEY_ID
secret_access_key: env/AWS_SECRET_ACCESS_KEYzones:
example.com.: &dual_target
sources:
- config
targets:
- ns1
- route53these have the same setup as example.com., but will have their own filesin the configuration directory for records.third.tv.: *dual_target
fourth.tv.: *dual_targetexample.net.:
# example.net. is an exact copy of example.com., there will not be an
# example.net.yaml file in the config directory asaliasincludes
# duplicating the records of the aliased zone along with its config.
alias: example.com.other.com.:
lenient: True
sources:
- config
targets:
- ns1General Configuration Conceptsclassis a special key that tells octoDNS what python class should be loaded. Any other keys will be passed as configuration values to that provider. In general any sensitive or frequently rotated values should come from environmental variables. When octoDNS sees a value that starts withenv/it will look for that value in the process's environment and pass the result along.Further information can be found in thedocstringof each source and provider class.Theinclude_metakey in themanagersection of the config controls the creation of a TXT record at the root of a zone that is managed by octoDNS. If set toTrue, octoDNS will create a TXT record for the root of the zone with the valueprovider=<target-provider>. If not specified, the default value forinclude_metaisFalse.Themax_workerskey in themanagersection of the config enables threading to parallelize the planning portion of the sync.Quick Example RecordNow that we have something to tell octoDNS about our providers & zones we need to tell it about our records. We'll keep it simple for now and just create a singleArecord at the top-level of the domain.config/example.com.yaml'':
ttl: 60
type: A
values:
- 1.2.3.4
- 1.2.3.5Further information can be found inRecords Documentation.NoopWe're ready to do a dry-run with our new setup to see what changes it would make. Since we're pretending here we'll act like there are no existing records forexample.com.in our accounts on either provider.$octodns-sync--config-file=./config/production.yaml...********************************************************************************* example.com.********************************************************************************* route53 (Route53Provider)*   Create <ARecord A 60, example.com., [u'1.2.3.4', '1.2.3.5']>*   Summary: Creates=1, Updates=0, Deletes=0, Existing Records=0* dyn (DynProvider)*   Create <ARecord A 60, example.com., [u'1.2.3.4', '1.2.3.5']>*   Summary: Creates=1, Updates=0, Deletes=0, Existing Records=0********************************************************************************...There will be other logging information presented on the screen, but successful runs of sync will always end with a summary like the above for any providers & zones with changes. If there are no changes a message saying so will be printed instead. Above we're creating a new zone in both providers so they show the same change, but that doesn't always have to be the case. If, to start, one of them had a different state, you would see the changes octoDNS intends to make to sync them up.Making changesWARNING: octoDNS assumes ownership of any domain you point it to. When you tell it to act it will do whatever is necessary to try and match up states including deleting any unexpected records. Be careful when playing around with octoDNS. It's best to experiment with a fake zone or one without any data that matters until you're comfortable with the system.Now it's time to tell octoDNS to make things happen. We'll invoke it again with the same options and add a--doiton the end to tell it this time we actually want it to try and make the specified changes.$octodns-sync--config-file=./config/production.yaml--doit...The output here would be the same as before with a few more log lines at the end as it makes the actual changes. After which the config in Route53 and Dyn should match what's in the yaml file.WorkflowIn the above case we manually ran octoDNS from the command line. That works and it's better than heading into the provider GUIs and making changes by clicking around, but octoDNS is designed to be run as part of a deploy process. The implementation details are well beyond the scope of this README, but here is an example of the workflow we use at GitHub. It follows the wayGitHub itself is branch deployed.The first step is to create a PR with your changes.Assuming the code tests and config validation statuses are green the next step is to do a noop deploy and verify that the changes octoDNS plans to make are the ones you expect.After that comes a set of reviews. One from a teammate who should have full context on what you're trying to accomplish and visibility into the changes you're making to do it. The other is from a member of the team here at GitHub that owns DNS, mostly as a sanity check and to make sure that best practices are being followed. As much of that as possible is baked intooctodns-validate.After the reviews it's time to branch deploy the change.If that goes smoothly, you again see the expected changes, and verify them withdigand/oroctodns-reportyou're good to hit the merge button. If there are problems you can quickly do a.deploy dns/mainto go back to the previous state.Bootstrapping config filesVery few situations will involve starting with a blank slate which is why there's tooling built in to pull existing data out of providers into a matching config file.$octodns-dump--config-file=config/production.yaml--output-dir=tmp/example.com.route532017-03-15T13:33:34  INFO  Manager __init__: config_file=tmp/production.yaml2017-03-15T13:33:34  INFO  Manager dump: zone=example.com., sources=('route53',)2017-03-15T13:33:36  INFO  Route53Provider[route53] populate:   found 64 records2017-03-15T13:33:36  INFO  YamlProvider[dump] plan: desired=example.com.2017-03-15T13:33:36  INFO  YamlProvider[dump] plan:   Creates=64, Updates=0, Deletes=0, Existing Records=02017-03-15T13:33:36  INFO  YamlProvider[dump] apply: making changesThe above command pulled the existing data out of Route53 and placed the results intotmp/example.com.yaml. That file can be inspected and moved intoconfig/to become the new source. If things are working as designed a subsequent noop sync should show zero changes.Note that aDynamic Zone Configand be really powerful in combination withoctodns-dumpallowing you to quickly create a set of octoDNS zone files for all the zones configured in your sources.$octodns-dump--config-file=config/production.yaml--output-dir=tmp/'*'route53...It is important to review anyWARNINGlog lines printed out during anoctodns-dumpinvocation as it will give you information about records that aren't supported fully or at all by octoDNS and thus won't be exact matches or included in the dumps. Generally records that cannot be converted are either of a type that octoDNS does not support or those that include "dynamic" functionality that doesn't match octoDNS's behaviors.ProvidersThe table below lists the providers octoDNS supports. They are maintained in their own repositories and released as independent modules.ProviderModuleNotesAkamai Edge DNSoctodns_edgednsAmazon Route 53octodns_route53Azure DNSoctodns_azureBIND, AXFR, RFC-2136octodns_bindCloudflare DNSoctodns_cloudflareConstellixoctodns_constellixDigitalOceanoctodns_digitaloceanDNS Made Easyoctodns_dnsmadeeasyDNSimpleoctodns_dnsimpleDyn(deprecated)octodns_dyneasyDNSoctodns_easydnsEdgeCenter DNSoctodns_edgecenter/etc/hostsoctodns_etchostsGandioctodns_gandiG-Core Labs DNSoctodns_gcoreGoogle Cloud DNSoctodns_googlecloudHetzner DNSoctodns_hetznerMythic Beasts DNSoctodns_mythicbeastsNS1octodns_ns1OVHcloud DNSoctodns_ovhPowerDNSoctodns_powerdnsRackspaceoctodns_rackspaceScalewayoctodns_scalewaySelecteloctodns_selectelSPF Value Managementoctodns_spfTransIPoctodns_transipUltraDNSoctodns_ultraYamlProviderbuilt-inSupports all record types and core functionalityUpdating to use extracted providersInclude the extracted module in your python environment, e.g. if using Route53 that would require adding theoctodns_route53module to your requirements.txt, setup.py, or similar.Update theclassvalue for your provider to the new path, e.g. again for Route53 that would be replacingoctodns.provider.route53.Route53Providerwithoctodns_route53.Route53ProviderThe module required and provider class path for extracted providers can be found in the table above.SourcesSimilar to providers, but can only serve to populate records into a zone, cannot be synced to.SourceRecord SupportDynamicNotesEnvVarSourceTXTNoread-only environment variable injectionAxfrSourceA, AAAA, CAA, CNAME, LOC, MX, NS, PTR, SPF, SRV, TXTNoread-onlyZoneFileSourceA, AAAA, CAA, CNAME, MX, NS, PTR, SPF, SRV, TXTNoread-onlyTinyDnsFileSourceA, CNAME, MX, NS, PTRNoread-onlyNotesALIAS support varies a lot from provider to provider care should be taken to verify that your needs are met in detail.Dyn's UI doesn't allow editing or view of TTL, but the API accepts and stores the value provided, this value does not appear to be used when servedDnsimple's uses the configured TTL when serving things through the ALIAS, there's also a secondary TXT record created alongside the ALIAS that octoDNS ignoresoctoDNS itself supports non-ASCII character sets, but in testing Cloudflare is the only provider where that is currently functional end-to-end. Others have failures either in the client libraries or API callsProcessorsProcessorDescriptionAcmeMangingProcessorUseful when processes external to octoDNS are managing acme challenge DNS records, e.g. LetsEncryptAutoArpaSeeAutomatic PTR generationbelowExcludeRootNsChangesFilter that errors or warns on planned root/APEX NS records changes.IgnoreRootNsFilterFilter that IGNORES root/APEX NS records and prevents octoDNS from trying to manage them (where supported.)MetaProcessorAdds a special meta record with timing, UUID, providers, and/or version to aid in debugging and monitoring.NameAllowlistFilterFilter that ONLY manages records that match specified naming patterns, all others will be ignoredNameRejectlistFilterFilter that IGNORES records that match specified naming patterns, all others will be managedValueAllowlistFilterFilter that ONLY manages records that match specified value patterns based onrdata_text, all others will be ignoredValueRejectlistFilterFilter that IGNORES records that match specified value patterns based onrdata_text, all others will be managedOwnershipProcessorProcessor that implements ownership in octoDNS so that it can manage only the records in a zone in sources and will ignore all others.SpfDnsLookupProcessorProcessor that checks SPF values for violations of DNS query limitsTtlRestrictionFilterProcessor that restricts the allow TTL values to a specified range or list of specific valuesTypeAllowlistFilterFilter that ONLY manages records of specified types, all others will be ignoredTypeRejectlistFilterFilter that IGNORES records of specified types, all others will be managedoctodns-spfSPF Value Management for octoDNSAutomatic PTR generationoctoDNS supports automatically generating PTR records from theA/AAAArecords it manages. For more information see theauto-arpa documentation.Compatibility and Compliancelenientlenientmostly focuses on the details ofRecords and standards compliance. When set totrueoctoDNS will allow non-compliant configurations & values where possible. For example CNAME values that don't end with a., label length restrictions, and invalid geo codes ondynamicrecords. When in lenient mode octoDNS will log validation problems atWARNINGand try and continue with the configuration or source data as it exists. SeeLeniencefor more information on the concept and how it can be configured.strict_supportsstrict_supportsis aProviderlevel parameter that comes into play when a provider has been asked to create a record that it is unable to support. The simplest case of this would be record type, e.g.SSHFPnot being supported byAzureProvider. If such a record is passed to anAzureProvideras a target the provider will take action based on thestrict_supports. Whentrueit will throw an exception saying that it's unable to create the record, when set tofalseit will log atWARNINGwith information about what it's unable to do and how it is attempting to work around it. Other examples of things that cannot be supported would bedynamicrecords on a provider that only supports simple or the lack of support for specific geos in a provider, e.g. Route53Provider does not supportNA-CA-*.It is worth noting that these errors will happen during the plan phase of things so that problems will be visible without having to make changes.This concept is currently a work in progress and only partially implemented. While work is on-goingstrict_supportswill default tofalse. Once the work is considered complete & ready the default will change totrueas it's a much safer and less surprising default as what you configure is what you'll get unless an error is thrown telling you why it cannot be done. You will then have the choice to explicitly request that things continue with work-arounds withstrict_supportsset tofalse. In the meantime it is encouraged that you manually configure the parameter totruein your provider configs.Configuringstrict_supportsThestrict_supportsparameter is available on all providers and can be configured in YAML as follows:providers:
someprovider:
class: whatever.TheProvider
...
strict_supports: trueCustom Sources and ProvidersYou can check out thesourceandproviderdirectory to see what's currently supported. Sources act as a source of record information. AxfrSource and TinyDnsFileSource are currently the only OSS sources, though we have several others internally that are specific to our environment. These include something to pull host data fromgPaneland a similar provider that sources information about our network gear to create bothA&PTRrecords for their interfaces. Things that might make good OSS sources might include anElbSourcethat pulls information aboutAWS Elastic Load Balancersand dynamically createsCNAMEs for them, orEc2Sourcethat pulls instance information so that records can be created for hosts similar to how ourGPanelProviderworks.Most of the things included in octoDNS are providers, the obvious difference being that they can serve as both sources and targets of data. We'd really like to see this list grow over time so if you use an unsupported provider then PRs are welcome. The existing providers should serve as reasonable examples. Those that have no GeoDNS support are relatively straightforward. Unfortunately most of the APIs involved to do GeoDNS style traffic management are complex and somewhat inconsistent so adding support for that function would be nice, but is optional and best done in a separate pass.Theclasskey in the providers config section can be used to point to arbitrary classes in the python path so internal or 3rd party providers can easily be included with no coordination beyond getting them into PYTHONPATH, most likely installed into the virtualenv with octoDNS.For examples of building third-party sources and providers, seeRelated Projects & Resources.Other UsesSyncing between providersWhile the primary use-case is to sync a set of yaml config files up to one or more DNS providers, octoDNS has been built in such a way that you can easily source and target things arbitrarily. As a quick example the config below would syncgithubtest.net.from Route53 to Dyn.providers:
route53:
class: octodns.provider.route53.Route53Provider
access_key_id: env/AWS_ACCESS_KEY_ID
secret_access_key: env/AWS_SECRET_ACCESS_KEY
dyn:
class: octodns.provider.dyn.DynProvider
customer: env/DYN_CUSTOMER
username: env/DYN_USERNAME
password: env/DYN_PASSWORDzones:githubtest.net.:
sources:
- route53
targets:
- dynDynamic sourcesInternally we use custom sources to create records based on dynamic data that changes frequently without direct human intervention. An example of that might look something like the following. For hosts this mechanism is janitorial, run periodically, making sure the correct records exist as long as the host is alive and ensuring they are removed after the host is destroyed. The host provisioning and destruction processes do the actual work to create and destroy the records.providers:
gpanel-site:
class: github.octodns.source.gpanel.GPanelProvider
host: 'gpanel.site.github.foo'
token: env/GPANEL_SITE_TOKEN
powerdns-site:
class: octodns.provider.powerdns.PowerDnsProvider
host: 'internal-dns.site.github.foo'
api_key: env/POWERDNS_SITE_API_KEYzones:hosts.site.github.foo.:
sources:
- gpanel-site
targets:
- powerdns-siteContributingPlease see ourcontributing documentif you would like to participate!Getting helpIf you have a problem or suggestion, pleaseopen an issuein this repository, and we will do our best to help. Please note that this project adheres to theContributor Covenant Code of Conduct.Related Projects and ResourcesGitHub Action:octoDNS-SyncNixOS Integration:NixOS-DNSSample Implementations.See how others are using ithackclub/dnskubernetes/k8s.io:/dnsg0v-network/domainsjekyll/dnsCustom Sources & Providers.octodns/octodns-ddns: A simple Dynamic DNS source.doddo/octodns-lexicon: UseLexiconproviders as octoDNS providers.asyncon/octoblox:Infobloxprovider.sukiyaki/octodns-netbox:NetBoxsource.jcollie/octodns-netbox-dns:NetBox-DNS Pluginprovider.kompetenzbolzen/octodns-custom-provider: zonefile provider & phpIPAM source.Financial-Times/octodns-fastly: An octoDNS source for Fastly.Resources.Article:Visualising DNS records with Neo4j+ codeVideo:FOSDEM 2019 - DNS as code with octodnsGitHub Blog:Enabling DNS split authority with octoDNSTutorial:How To Deploy and Manage Your DNS using octoDNS on Ubuntu 18.04Cloudflare Blog:Improving the Resiliency of Our Infrastructure DNS ZoneIf you know of any other resources, please do let us know!LicenseoctoDNS is licensed under theMIT license.The MIT license grant is not for GitHub's trademarks, which include the logo designs. GitHub reserves all trademark and copyright rights in and to all GitHub trademarks. GitHub's logos include, for instance, the stylized designs that include "logo" in the file title in the following folder:https://github.com/octodns/octodns/tree/main/docs/logos/GitHub® and its stylized versions and the Invertocat mark are GitHub's Trademarks or registered Trademarks. When using GitHub's logos, be sure to follow the GitHub logo guidelines.AuthorsoctoDNS was designed and authored byRoss McFarlandandJoe Williams. Seehttps://github.com/octodns/octodns/graphs/contributorsfor a complete list of people who've contributed.