universal-cloudflared: keep CF_* secrets out of cloudflared's environment - #1167
Merged
thespad merged 1 commit intoAug 31, 2026
Conversation
cloudflared logs its whole environment at INFO on startup and only redacts variables named TUNNEL_*, so CF_TUNNEL_PASSWORD, CF_API_TOKEN and CF_REMOTE_MANAGE_TOKEN are written verbatim to docker logs. The setup step has already written the tunnel credentials file and referenced it from config.yml, so cloudflared authenticates from that and no longer needs these values in its environment. Strip them at exec. The guards are unaffected as they run before the exec, and --token still receives its value because bash expands it before env removes it.
Author
|
btw - I think your CI is currently broken. |
thespad
approved these changes
Aug 31, 2026
Member
|
It's not broken per se, it just fails for 3rd party PRs since they changed the restrictions on pull_request_target because Github's workflow approvals system is busted. |
thespad
merged commit Aug 31, 2026
818d0a7
into
linuxserver:universal-cloudflared
2 of 3 checks passed
Author
|
Brilliant, thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
cloudflaredlogs its entire environment at INFO level on startup. It redactssecrets, but only for variables whose names begin with
TUNNEL_(plus known secretflags such as
--token). This mod's variables are namedCF_TUNNEL_PASSWORD,CF_API_TOKENandCF_REMOTE_MANAGE_TOKEN, so they fall outside that filter and arewritten to the container log verbatim:
This change strips those three variables from cloudflared's environment at
exectime in
svc-mod-universal-cloudflared/run.They are not needed by that point.
init-mod-universal-cloudflared-setuphas alreadyderived
TunnelSecretfromCF_TUNNEL_PASSWORD, written/etc/cloudflared/${CF_TUNNEL_ID}.json, and emittedcredentials-file: /etc/cloudflared/${CF_TUNNEL_ID}.jsonintoconfig.yml—so cloudflared authenticates from the credentials file, not the environment.
The existing guards are unaffected because they are evaluated before the
exec, and--token ${CF_REMOTE_MANAGE_TOKEN}still receives its value because bash expands itbefore
envremoves it from the child's environment.Benefits of this PR and context:
The tunnel secret is currently readable by anyone who can run
docker logson thecontainer, or through any log viewer pointed at it, and it persists for as long as
the log history is kept. Users have no way to avoid this short of lowering
loglevel, which also suppresses normal connection and registration logging andbrings the secret straight back for anyone who raises the level again to debug.
Two alternatives were considered and rejected:
logleveltowarn— hides the dump but loses useful logging, andonly masks the problem.
TUNNEL_*so cloudflared's own scrubber catchesthem — cleaner in principle, but a breaking change for every existing user.
How Has This Been Tested?
Tested on a running
lscr.io/linuxserver/swagcontainer with this mod enabled(cloudflared 2026.8.2, named tunnel authenticating from the credentials file), by
replacing the live service script under
/runand restarting only that s6 servicewith
s6-svc -r.Variables appearing in cloudflared's startup environment dump:
CF_TUNNEL_CONFIG,CF_TUNNEL_NAME,CF_TUNNEL_PASSWORD,TUNNEL_ORIGIN_CERTCF_TUNNEL_CONFIG,CF_TUNNEL_NAME,TUNNEL_ORIGIN_CERTThe tunnel re-registered all four QUIC connections normally and the proxied hostnames
continued to serve (HTTP 200).
bash -npasses on the modified script.Only the
CF_TUNNEL_*/CF_API_TOKENbranch was exercised; I do not have aCF_REMOTE_MANAGE_TOKENsetup to test the first branch, though the change there isidentical in form.
Source / References:
loglevelis the only logging control; there is nooption to suppress the environment dump):
https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/configure-tunnels/run-parameters/
TUNNEL_*environment variables and known secretflags, which is why the
CF_*names are not covered.