Skip to content

Optional scoped API keys#79

Merged
mholt merged 4 commits into
caddy-dns:masterfrom
aliask:optional-scoped-api-keys
Jun 10, 2024
Merged

Optional scoped API keys#79
mholt merged 4 commits into
caddy-dns:masterfrom
aliask:optional-scoped-api-keys

Conversation

@aliask
Copy link
Copy Markdown
Contributor

@aliask aliask commented Jun 9, 2024

Overview

This PR allows for a second API token to be optionally configured, used for fetching info about the Zones in Cloudflare.

The change is backwards compatible with existing configs - if the Zone API token is not provided, the regular API token is used for all requests.

Why

The /zones API endpoint requires that the entire token be scoped globally, which then means that the DNS edit permission must also be scoped globally. This prevents the use of a single API token to perform DNS updates to be restricted to a single zone in a multi-zone account.

By splitting the token out, this global scoped token can be left as read-only, and the DNS read/write token can be scoped to a single Zone.

I believe this should address #2 (at least the original issue, I think there might be a separate issue being discussed in the comments)

Testing

I've written some small tests for this module which can be run with go test. I believe these tests cover the old Caddyfile syntax as well as the updated one with two tokens.

TODO

  • If libdns/cloudflare gets a release tag then go.mod can be updated to target this instead of the manual git SHA
  • Actual real-world tests with old configs to ensure that nothing breaks

aliask added 4 commits May 31, 2024 23:43
Rather than having a single API key which must be scoped for editing
DNS for all zones, allow separation - one for Zone.list() and one
for actually editing the records on the specified Zone
Copy link
Copy Markdown
Contributor

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent -- thanks so much for improving this module!

@mholt mholt merged commit d11ac0b into caddy-dns:master Jun 10, 2024
@mholt mholt mentioned this pull request Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants