route53-cron

by mariomeyer

Helm chartv0.1.1App 0.1.0Verified publisher

Dynamic DNS simple updater for AWS Route 53 on top of AWS CLI image

About this chart

Route 53 Dynamic DNS Cronjob Image

This is a Docker image built on top of AWS CLI to enable Dynamic DNS entries via CrobJobs on Kubernetes

The implementation is a simple bash script that will get your public IP and update a DNS entry with an A registry with your current IP.

AWS Policy

For minimal security risk, it's recommended that you create a policy on AWS that only allows the user to update DNS records. It's also recommended that you create a user that only has this policy attached to it, so no other AWS resource is exposed to this code.

Policy Example

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "route53:ChangeResourceRecordSets",
            "Resource": "arn:aws:route53:::hostedzone/*"
        }
    ]
}

AWS CLI Execution

cat > policy.json <<< EOF
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "route53:ChangeResourceRecordSets",
            "Resource": "arn:aws:route53:::hostedzone/*"
        }
    ]
}
EOF

aws iam create-policy \
    --policy-name R53-edit-domains \
    --policy-document file://policy

export AWS_POLICY=aws iam list-policies --output text --query 'Policies[?PolicyName==`R53-edit-domains`].Arn'

aws iam create-user \
    --user-name dns-updater

aws iam attach-user-policy \
    --policy-arn ${AWS_POLICY} \
    --user-name dns-updater

aws iam create-access-key \
    --user-name dns-updater

Copy the AccessKeyId and SecretAccessKey outputed by the last command, those will be needed for running the container securely.

Running

Docker

docker run \
  -e AWS_ZONE_ID=<zone_id> \
  -e AWS_ACCESS_KEY_ID=<access_key_id> \
  -e AWS_SECRET_ACCESS_KEY=<secret_access_key> \
  -e UPDATE_HOST=<host to update> \
  --rm -it mariomeyer/route53-cron:latest

Kubernetes CronJob

Example yaml for CronJob running every 30 minutes:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: route53-dns-updater
spec:
  schedule: '*/30 * * * *'
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: docker.io/mariomeyer/route53-cron
            imagePullPolicy: IfNotPresent
            env:
              - name: AWS_ZONE_ID
                value: <zone_id>
              - name: AWS_ACCESS_KEY_ID
                value: <access_key_id>
              - name: AWS_SECRET_ACCESS_KEY
                value: <secret_access_key>
              - name: UPDATE_HOST
                value: <host to update>
          restartPolicy: OnFailure

Helm Chart

You can also install it on a Kubernetes Cluster using helm charts:

helm repo add meyercharts https://mariomeyer.github.io/repo
helm install my-route53-cron meyercharts/route53-cron

Your configuration can be done on a values.yaml file in this format:

# Default values for route53-cron.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

image:
  repository: docker.io/mariomeyer/route53-cron
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: ""

aws:
  accessKeyId: 
  secretAccessKey: 
  zoneId: 
  host: 

schedule: "*/30 * * * *"

nodeSelector: {}

Deploy route53-cron with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has route53-cron on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartroute53-cron is pinned at v0.1.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply