cloudflare / cloudflare/cloudflared
💡Automatically update DNS records when new service is added
- Dominant language
- Go
- Stars
- 15.6k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the feature you'd like**
When adding a new service (available locally on `service.internal`) to Cloudflared tunnel (with UUID ``) so that `foo.example.com` resolves to that service, two steps are required:
* Update the local Cloudflared daemon's config, mapping `hostname: foo.example.com` to `service: service.internal`
* [Publish a CNAME record](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/routing-to-tunnel/dns/) so that `foo.example.com` maps to `.cfargotunnel.com`
The first step is naturally achieved by updating the configuration and restarting the daemon. However, I couldn't find a way to automate the second step. In particular, the `cloudflare/cloudflared` [image](https://hub.docker.com/r/cloudflare/cloudflared) does not appear to contain any tools (like [`yq`](https://github.com/mikefarah/yq), `awk`, or Python) which could be used to parse the config file to generate the appropriate `cloudflared tunnel route dns ` calls per-service.
This feature would be either:
* A flag on `cloudflared tunnel run` (like `--update-dns`) which results in updates to the DNS records (if hosted on Cloudflare) before the Tunnel starts.
* An execution mode for `cloudflared tunnel route dns ` which results in per-service calls for all services defined for that tunnel.
**Describe alternatives you've considered**
As described in [this blog post](https://blog.scubbo.org/posts/cloudflare-tunnel-dns/), I've created a Docker image for myself which can do the "_parse Cloudflared config file, make_ `cloudflared tunnel route dns ` _calls_" logic itself as an `initContainer` on a Kubernetes deployment. If and when I publish this image to Docker Hub, other users could use it in their own setups.
**Additional context**
I recognize that this feature would result in some extra traffic to Cloudflare's DNS services, since every deployment of a Tunnel would result in updates for every service it fronts. Some of this traffic could be mitigated by implementing a check to only make DNS-update calls for records that don't currently exist. I would guess, though, that this extra traffic (which would only be incurred for users who actually enable this feature) would be inconsequential against Cloudflare's overall traffic, since tunnel re-deployment rate is probably(?) pretty low.
Given that this feature wouldn't involve much new logic and would just be plumbing existing logic into a new command flag, I'd be happy to take a stab at implementing this feature if it's considered helpful. I've done some Go tutorials but have never used it professionally.
Contributor guide
Assessment
This issue has not been assessed yet.