Repository navigation
feat(access): add --pidfile support for access command (fixes #723) - #1764
Closed
MauroDruwel wants to merge 1 commit into
Closed
MauroDruwel wants to merge 1 commit into
MauroDruwel wants to merge 1 commit into
Conversation
Author
|
Closing as duplicate of #1599. |
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.
Summary
Fixes #723
Adds
--pidfilecommand-line flag (andTUNNEL_PIDFILEenvironment variable) support tocloudflared accessandcloudflared access tcp(including aliasesssh,rdp, andsmb).Problem & Motivation
When running
cloudflared access tcpas a background process or forwarder in automation scripts, Taskfiles, or CI pipelines (e.g. for forwarding SOCKS5, Kubernetes API, or Vault access), users currently have to resort to fragilepgrep/greppipelines to find and terminate the process during cleanup traps.cloudflared tunnelalready provides a--pidfileflag. Bringing parity tocloudflared accessenables clean process management and reliable shutdown (e.g.,pkill -F .cloudflared.pidorkill -15 $(cat .cloudflared.pid)).Changes
writePidFilelogic intocmd/cloudflared/cliutil/pidfile.go(cliutil.WritePidFile) supporting~homedir expansion, path cleaning, and structured error logging. Refactoredcmd/cloudflared/tunnel/cmd.goto use this shared utility to eliminate duplicate code.cfdflags.Pidfileconstant incmd/cloudflared/flags/flags.go.--pidfilewithTUNNEL_PIDFILEenv var oncloudflared accessand thetcpsubcommand incmd/cloudflared/access/cmd.go.cmd/cloudflared/access/carrier.go,cliutil.WritePidFileis called for both background forwarding listener mode (--url) and client stream proxy mode.Testing Plan
cmd/cloudflared/cliutil/pidfile_test.goverifying normal file creation withos.Getpid(), homedir~expansion, and graceful error handling on invalid paths.cmd/cloudflared/access/pidfile_test.goverifying--pidfileandTUNNEL_PIDFILEregistration acrossaccessandaccess tcp.go test -count=1oncliutil,access,tunnel, andcarrierpackages — all passed.cloudflared access tcp --hostname ... --url 127.0.0.1:23456 --pidfile /tmp/test.pidcreated the file with the exact running PID.cloudflared access --pidfile /tmp/test.pid tcp ....gofmt -s -l: clean (0 issues).go vet ./cmd/cloudflared/...: clean (0 issues).