This repository manages the Ministry of Justice DNS records using octoDNS. It provides a streamlined, code-based approach to DNS management, ensuring consistency and enabling version control for our DNS records.
- π MoJ DNS Management
.
βββ .github/ # GitHub Actions workflows
βββ bin/ # Contains various scripts to operate this repository
βββ hostedzones/ # DNS zone files
βββ .gitignore
βββ .github_pages # Domains and subdomains that are delegated to GitHub Pages
βββ LICENSE
βββ Makefile
βββ README.md
βββ config.yaml # octoDNS configuration
βββ requirements.txt # Python dependencies
-
DNS records are stored as YAML files in the
hostedzones/
directory. Each file represents a single hosted zone and contains all records for that zone. -
Changes are proposed via Pull Requests.
-
A CI/CD pipeline runs
octodns-sync
in dry-run mode for each PR, allowing for review of proposed changes. -
Upon merging to the
main
branch, changes are automatically applied to our Route53 hosted zones.
The config.yaml
file is set up dynamically to encompass all hosted zones in the mojdsd AWS account (An AWS account owned by Operations Engineering). We use the lenient
option due to historical non-uniform record creation.
- Pull Requests: Triggers a dry-run of
octodns-sync
to preview changes. - Merge to
main
: Applies changes to Route53 usingoctodns-sync --doit
. Changes typically take about 2 minutes to propagate.
The AWS IAM user required for the pipelines in this repository is not created or managed within this repository. Instead, it is provisioned and maintained in the main operations-engineering repository.
This approach centralises our IAM user management and ensures that the DNS management system uses credentials that are consistently managed alongside our other operational resources.
This project requires AWS credentials to interact with Route53. The Makefile will attempt to use AWS credentials from the following sources, in order:
- Environment variables (
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
) - AWS CLI configuration
If neither of these sources provides valid credentials, commands that require AWS access will fail with an error message.
To set your AWS credentials, you can either:
-
Export them as environment variables:
export AWS_ACCESS_KEY_ID=your_access_key_id export AWS_SECRET_ACCESS_KEY=your_secret_access_key
-
Configure them using the AWS CLI:
aws configure
Ensure your AWS credentials have the necessary permissions to manage Route53 hosted zones.
-
Clone this repository:
git clone https://github.com/ministryofjustice/dns.git cd dns
-
Install dependencies:
make install
-
Create a new branch for your changes:
git checkout -b your-branch-name
-
Edit the appropriate zone file:
make edit-zone zone=example.com
This will open the zone file in your default editor. If the file doesn't exist, it will be created.
-
Ensure changes are made in alphabetical order within the file.
-
Validate your changes:
π Note: This may look a little messy, but you're looking for errors rather than warnings.
make validate-zones
-
Perform a dry-run to see what changes would be made:
make sync-dry-run
-
If you want to compare your local changes with the live configuration:
make compare-zone zone=example.com
-
Commit your changes and create a Pull Request:
git add . git commit -m "Your descriptive commit message" git push origin your-branch-name
-
Create a Pull Request on GitHub.
Example of adding a new A record to example.com.yaml
:
---
'':
type: A
values:
- 192.0.2.1
api:
type: CNAME
value: api.example.net.
# New record (note alphabetical order)
blog:
type: A
values:
- 203.0.113.10
www:
type: CNAME
value: example.com.
To view the current live configuration for a zone:
make dump-zone zone=example.com
This will dump the current Route53 configuration for example.com
to a file in the tmp/
directory.
If you need to apply changes locally (which should be done with extreme caution), you can use:
make sync-apply
This will apply all pending changes to Route53. Always perform a make sync-dry-run
first to review the changes that will be made.
This repository includes a Makefile to simplify common operations. You can use the following commands:
make # Show help message with available commands
make help # Same as above, shows help message
make install # Set up the Python environment
make edit-zone zone=<zone> # Edit a hosted zone file
make validate-zones # Validate all zone files
make sync-dry-run # Perform a dry-run sync for all zones
make sync-apply # Apply changes to all zones
make list-zones # List all zones
make dump-zone zone=<zone> # Dump the current live configuration for a zone
make compare-zone zone=<zone> # Compare a zone file with its live configuration
make clean # Clean up generated files
make print-github-delegations # Print GitHub Pages delegations
To see a full list of available commands and their descriptions, simply run make
or make help
.
This repository includes functionality to identify DNS records associated with GitHub Pages. These delegations are automatically identified and logged, and a Pull Request is created weekly if changes are detected.
A GitHub Action runs every Sunday at midnight (UTC) to identify GitHub Pages delegations across the DNS records. If any changes are detected in the delegations, a Pull Request is automatically created with the updated .github_pages
file. This file lists all GitHub Pages delegations in the format <record>.<hostedzone>
.
To manually identify GitHub Pages delegations, you can use the following Makefile command:
make print_github_delegation
This command outputs the current list of GitHub Pages delegations in the .github_pages file.
The .github_pages file contains entries in the format <record>.<hostedzone>
. For example:
cjsm.justice.gov.uk
hmpps-architecture-blueprint.service.justice.gov.uk
runbooks.operations-engineering.service.justice.gov.uk
If you need to update the GitHub Pages records manually:
- Run the following command to identify changes:
make print-github-delegations
- Commit and push any changes to the .github_pages file:
git add .github_pages
git commit -m "Update GitHub Pages delegations"
git push
This project is licensed under the MIT License - see the LICENSE file for details.