openwrt / openwrt/packages

ddns-scripts: Add Cloudflare Zero Trust

Open
#21,507 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Makefile
Stars
4.6k
Forks
4k
Avg merge
3d 12h
Merged PRs (30d)
134

Description

Recently Cloudflare has created a service similar to OpenDNS where by configuring your public IP you can set DNS filters, get metrics, etc.

To set your public IP it can be done via API, but as the IP has to be in the body of the request it cannot be done with a custom provider.

This is a sample request:

curl -X PUT \
  'https://api.cloudflare.com/client/v4/accounts/[account_id]/gateway/locations/[location_id]' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer yourtoken" \
  --data '{
    "client_default": true,
    "ecs_support": false,
    "name": "An arbitrary name",
    "networks": [
        { "network": "X.X.X.X/32" }
    ]}'

The fields client_default and ecs_support are optional and default to false.

To obtain the location_id you can make this request:

curl https://api.cloudflare.com/client/v4/accounts/[account_id]/gateway/locations \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer yourtoken"

Which responds something like this:

{
  "result": [
    {
      "id": "this_is_the_location_id",
      "name": "Location Name",
      "networks": [
        {
          "network": "X.X.X.X/32",
          "id": "network_id"
        }
      ],
      "policy_ids": [],
      "ip": "ip:v6::00",
      "doh_subdomain": "id",
      "anonymized_logs_enabled": false,
      "ipv4_destination": null,
      "ipv4_destination_backup": null,
      "client_default": true,
      "ecs_support": false,
      "created_at": "2023-07-07T08:18:18Z",
      "updated_at": "2023-07-07T08:27:06Z"
    }
  ],
  "success": true,
  "errors": [],
  "messages": []
}

When you make the update request, if everything has been correct, you should get a response similar to this one:

{
  "result": {
    "id": "this_is_the_location_id",
    "name": "Location Name",
    "policy_ids": [],
    "ip": "ip:v6::00",
    "doh_subdomain": "id",
    "anonymized_logs_enabled": false,
    "ipv4_destination": null,
    "ipv4_destination_backup": null,
    "client_default": true,
    "ecs_support": false,
    "created_at": "2023-07-07T08:18:18Z",
    "updated_at": "2023-07-07T09:13:33Z",
    "networks": [
      {
        "network": "X.X.X.X/32",
        "id": "network_id"
      }
    ],
    "linked_policies": []
  },
  "success": true,
  "errors": [],
  "messages": []
}

These requests are documented here:

As I see it, it would be necessary to be able to configure the following:

  • user_token: It is created in the Cloudflare administration panel.
  • account_id: It is obtained when you enter to configure any domain in Cloudflare.
  • location_id: It is obtained by making the API request documented above.
  • location_name: This is an arbitrary text chosen by the user to name the location and appear with that name in the dashboards.
  • client_default (boolean): Must set to true if the location is the default one (default false).
  • ecs_support (boolean): Set if the location needs to resolve EDNS queries (default false).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the ddns-scripts provider definitions and the entry point for providers that require an HTTP API request. Use the Cloudflare locations list and update endpoints described in the issue, then verify that the configurable token, account, location, and boolean fields produce the requested network update. The issue names no tests or repository files, so identify the relevant validation path before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
api, cloud, networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.