From 179af699a9a47457ceba5dcbdcbe616f9dab0b84 Mon Sep 17 00:00:00 2001 From: Rohan Mukherjee Date: Thu, 27 Feb 2025 01:42:56 +0530 Subject: [PATCH] fix: expand home directory for credentials file The documentation does not specify that the `credentials-file` field in `config.yaml` needs to be an absolute path. If you add a relative path with a `~`, it throw as error that the file is not found. However, this iis a confusing error for the user as the file at the path exists, it is just that `os.Stat` failed because it could not expand the `~`. This commit fixes the above issue by running a `homedir.Expand` on the `credentials-file` path in the `credentialFinder` function. --- cmd/cloudflared/tunnel/subcommand_context.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/cloudflared/tunnel/subcommand_context.go b/cmd/cloudflared/tunnel/subcommand_context.go index 553cb83b..99403141 100644 --- a/cmd/cloudflared/tunnel/subcommand_context.go +++ b/cmd/cloudflared/tunnel/subcommand_context.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/google/uuid" + "github.com/mitchellh/go-homedir" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/urfave/cli/v2" @@ -54,7 +55,12 @@ func newSubcommandContext(c *cli.Context) (*subcommandContext, error) { // Returns something that can find the given tunnel's credentials file. func (sc *subcommandContext) credentialFinder(tunnelID uuid.UUID) CredFinder { if path := sc.c.String(CredFileFlag); path != "" { - return newStaticPath(path, sc.fs) + // Expand path if CredFileFlag contains `~` + absPath, err := homedir.Expand(path) + if err != nil { + return newStaticPath(path, sc.fs) + } + return newStaticPath(absPath, sc.fs) } return newSearchByID(tunnelID, sc.c, sc.log, sc.fs) }