-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cloudflare_tunnel requires secret (unnecessarily for remotely-managed tunnels) #3355
Comments
Terraform debug log detected ✅ |
The secret is necessary for remotely managed tunnels. It is passed through to cloudflared as an argument (--token) at runtime. (In a local configured tunnel it is pulled from the configuration file). It is presented by cloudflared to the edge in the form of the "token" which includes the account tag, tunnel id, and the secret (base 64 encoded). A full setup looks like this: My secret is
To create the token, we base64 encode this:
(Where a = Account Tag (referenced as Account_ID above), T = tunnel Id, and S = the base64 encoded secret.) To this:
Finally run cloudflared like this:
A secret is necessary, in fact that's how an instance of cloudflared validates against the edge and is allowed to serve this particular tunnel. The API docs note:
I think the above could be more clear, but I'd argue against that it "explicitly notes that the secret is only used for a 'locally-managed tunnel,'" In the Terraform Docs, it is clear that is a required parameter: https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/tunnel#secret |
After creation, the generated secret is available inside the base64-encoded JSON object returned by the So, I don't see any reason to require Fixing this would also make resolving cloudflare/cf-terraforming#573 trivial and would move the privileged tunnel secret to the state file instead of leaving it exposed in the resource definition. |
Confirmation
Terraform and Cloudflare provider version
OpenTofu v1.7.2
registry.opentofu.org/cloudflare/cloudflare v4.34.0
Affected resource(s)
Terraform configuration files
Link to debug output
https://gist.github.com/alecglassford/b53de65c9b5f84fd6fce3ab87f4d6325
Panic output
No response
Expected output
Receive a plan to create a remotely-managed Cloudflare Tunnel
Actual output
Steps to reproduce
main.tf
with the configuration from a preceding section (⬆️), substituting an appropriate API token and account ID.tofu init
(orterraform init
).tofu plan
(orterraform plan
).Additional factoids
cloudflare_tunnel
treats thesecret
attribute as required, even whenconfig_src
iscloudflare
:terraform-provider-cloudflare/internal/sdkv2provider/schema_cloudflare_tunnel.go
Lines 25 to 27 in f9c666f
terraform-provider-cloudflare/docs/resources/tunnel.md
Line 32 in f9c666f
However, when
config_src
iscloudflare
, the resource is a remotely-managed tunnel, andsecret
serves no purpose1 (Please correct me if I'm wrong!)Indeed, the Cloudflare API does not treat the equivalent
tunnel_secret
field as required when you create a remotely-managed tunnel using the API: https://developers.cloudflare.com/api/operations/cloudflare-tunnel-create-a-cloudflare-tunnelThis API documentation explicitly notes that the secret is only used for a "locally-managed tunnel," and it is possible to successfully use this API endpoint with
config_src
set tocloudflare
and notunnel_secret
2Therefore
secret
should not be required on thecloudflare_tunnel
Terraform resource, to be consistent with the Cloudflare API.References
No response
Footnotes
"A remotely-managed tunnel only requires the tunnel token to run. Anyone with access to the token will be able to run the tunnel. " — https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/configure-tunnels/remote-management/#tunnel-permissions (the tunnel secret is not used in any later context, only the tunnel token) ↩
When you do this, the API result seems to contain an a tunnel secret generated by Cloudflare, but—as mentioned in the preceding footnote—there does not seem to be a reason to ever use this value again for a remotely-managed tunnel. ↩
The text was updated successfully, but these errors were encountered: