Giter Club home page Giter Club logo

gcloud-dynamic-dns's Introduction

GCloud Dynamic DNS

originally based on dynamic-cloud-dns

Updated and verified to work with Ubiquiti UDMP gateway

This is a Google Cloud function that will update the records hosted in Cloud DNS.

If neither an IPv4 nor an IPv6 address is provided, the source address of the request is used.

Configuration

Service Account

It is advisable to run the gcloud function under a service account with specific permissions. Create a custom role

with the following permissions

dns.changes.create
dns.changes.get
dns.managedZones.list
dns.resourceRecordSets.create
dns.resourceRecordSets.delete
dns.resourceRecordSets.list
dns.resourceRecordSets.update

Settings are loaded from environment variables

Config Description
DNS_ZONE The Google Cloud DNS Zone name/id in which the records reside.
USE_TOKEN Indicates whether to use the token on the query parameter. If not set will use password from the Authorization headers
SECRET_TOKEN A secret token, used to authenticate users.
ALLOWED_HOSTS A list of hosts that callers are allowed to update. May include "*" to allow all hosts.
TTL Time to live for records in seconds.

Under the dynamic dns section of the UDMP controller settings

Add an entry with the following settings

Settings Value
Service dyndns
Hostname The hostname you want to update
Username Any value to satisfy the req
Password The password that matches what is set in the function SECRET_TOKEN env variable
Server {cloud-function-address}/updateHost?host=%h&ipv4=%i&extra=
Replace {cloud-function-address} with the cloud function address. You can find that in the deploy output as part of the url setting. It usually follows the pattern <REGION>-<PROJECT ID>.cloudfunctions.net
The "extra=" can be left blank because on some UniFi controllers the hostname gets appended

Deploy to Google Cloud Functions

  • Create an initial A record exist for the host you want to update, or the function will fail
  • Setup Google Cloud Functions
  • Install the gcloud CLI tool
  • Authenticate: gcloud auth login
  • create a file .env.yaml that contains the environment variables listed in the Configuration section
DNS_ZONE: "zone id"
SECRET_TOKEN: "some secret
ALLOWED_HOSTS: "*"
TTL: "10"

To create the initial version of the function run the command (substituting the service account value)

gcloud functions deploy updateHost --source . --runtime nodejs12 \
    --trigger-http --allow-unauthenticated --max-instances=1 \
    --service-account=<service-account> \
    --env-vars-file=.env.yaml 

You can run npm run deploy to update the existing function

Testing with UDMP

You can test it with the UDMP by ssh in and running the command

/usr/sbin/inadyn -n -s -C -f /run/inadyn.conf -1 -l debug --foreground

This will show the HTTP requests and responses.

License

See LICENSE for more details.

gcloud-dynamic-dns's People

Contributors

derhally avatar

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.