cloudflare-operator icon indicating copy to clipboard operation
cloudflare-operator copied to clipboard

Unable to delete a Tunnel with only API Token set

Open KAllan357 opened this issue 2 years ago • 1 comments

Hi,

Thanks for this tool! I've set it up and created a tunnel, but came across a potential edge case that I wanted to ask about:

INFO    No API token, or performing delete operation
ERROR    Trying to perform Delete request, or any other request with out APIToken, cannot find API Key or Email
github.com/adyanth/cloudflare-operator/controllers.CloudflareAPI.addAuthHeader
    /workspace/controllers/cloudflare_api.go:85
github.com/adyanth/cloudflare-operator/controllers.(*CloudflareAPI).DeleteCloudflareTunnel
    /workspace/controllers/cloudflare_api.go:157

I'm running version v0.10.0 and was wondering why the code was this way for deletes:

https://github.com/adyanth/cloudflare-operator/blob/v0.10.0/controllers/cloudflare_api.go#L157

It seems like Cloudflare's v4 API supports deleting an Argo Tunnel using the standard Bearer Auth - https://developers.cloudflare.com/api/operations/argo-tunnel-delete-an-argo-tunnel

I see this code was added in https://github.com/adyanth/cloudflare-operator/commit/f59f1532571654e5aef67154c27b9d39aae8968b - maybe Cloudflare changed their API since?

I locally tested this via curl and was successful: t

curl --request DELETE --url https://api.cloudflare.com/client/v4/accounts/xxxx/tunnels/abc123 -H "Authorization: Bearer <API Token>"
{"success":true ... }

KAllan357 avatar Mar 15 '23 02:03 KAllan357

Hey @KAllan357 thanks!

Regarding delete, iirc (it was quite some time ago), the API key does not work. Only the API token along with the email used to work and not the bearer token approach. I guess they have changed it since then. I will have to do that too. Thanks for pointing it out!

Also looks like the ArgoTunnel API is deprecated in favor of Cloudflare Tunnel API. Might as well change that too if they are compatible. Will get in to this probably in a couple of weeks. If you would like to contribute, feel free to do so!

Refs: https://developers.cloudflare.com/api/operations/cloudflare-tunnel-delete-a-cloudflare-tunnel https://developers.cloudflare.com/api/operations/argo-tunnel-delete-an-argo-tunnel

adyanth avatar Mar 15 '23 02:03 adyanth