cloudflared-mirror/cmd/cloudflared
Rohan Mukherjee 6dc8ed710e
fix: expand home directory for credentials file
## Issue

The [documentation for creating a tunnel's configuration
file](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-local-tunnel/#4-create-a-configuration-file)
does not specify that the `credentials-file` field in `config.yml` needs
to be an absolute path.

A user (E.G. me 🤦) might add a path like `~/.cloudflared/<uuid>.json`
and wonder why the `cloudflared tunnel run` command is throwing a
credentials file not found error. Although one might consider it
intuitive, it's not a fair assumption as a lot of CLI tools allow file
paths with `~` for specifying files.

P.S. The tunnel ID in the following snippet is not a real tunnel ID, I
just generated it.
```
url: http://localhost:8000
tunnel: 958a1ef6-ff8c-4455-825a-5aed91242135
credentials-file: ~/.cloudflared/958a1ef6-ff8c-4455-825a-5aed91242135.json
```

Furthermore, the error has a confusing message for the user as the file
at the logged path actually exists, it is just that `os.Stat` failed
because it could not expand the `~`.

## Solution

This commit fixes the above issue by running a `homedir.Expand` on the
`credentials-file` path in the `credentialFinder` function.
2025-04-01 17:54:57 +01:00
..
access TUN-9101: Don't ignore errors on `cloudflared access ssh` 2025-03-17 18:42:19 +00:00
cliutil TUN-8914: Create a flags module to group all cloudflared cli flags 2025-02-06 03:30:27 -08:00
flags TUN-8960: Connect to FED API GW based on the OriginCert's endpoint 2025-02-25 17:13:33 +00:00
proxydns TUN-6963: Refactor Metrics service setup 2022-11-22 11:35:48 +00:00
tail TUN-8960: Connect to FED API GW based on the OriginCert's endpoint 2025-02-25 17:13:33 +00:00
tunnel fix: expand home directory for credentials file 2025-04-01 17:54:57 +01:00
updater Fix broken links in `cmd/cloudflared/*.go` related to running tunnel as a service 2025-04-01 17:45:59 +01:00
app_forward_service.go TUN-4067: Reformat code for consistent import order, grouping, and fix formatting. Added goimports target to the Makefile to make this easier in the future. 2021-03-24 10:53:29 -05:00
app_resolver_service.go TUN-4067: Reformat code for consistent import order, grouping, and fix formatting. Added goimports target to the Makefile to make this easier in the future. 2021-03-24 10:53:29 -05:00
app_service.go TUN-4067: Reformat code for consistent import order, grouping, and fix formatting. Added goimports target to the Makefile to make this easier in the future. 2021-03-24 10:53:29 -05:00
common_service.go TUN-5679: Add support for service install using Tunnel Token 2022-03-03 18:59:03 +00:00
generic_service.go feat: emit explicit errors for the `service` command on unsupported OSes 2025-04-01 17:48:20 +01:00
linux_service.go Update linux_service.go 2024-03-06 10:29:55 +00:00
macos_service.go Fix broken links in `cmd/cloudflared/*.go` related to running tunnel as a service 2025-04-01 17:45:59 +01:00
main.go TUN-8914: Create a flags module to group all cloudflared cli flags 2025-02-06 03:30:27 -08:00
service_template.go TUN-7590: Remove usages of ioutil 2023-07-17 19:08:38 +00:00
windows_service.go Fix broken links in `cmd/cloudflared/*.go` related to running tunnel as a service 2025-04-01 17:45:59 +01:00