Skip to content

Commit 5499c77

Browse files
author
Dalton
committed
AUTH-2975 don't check /etc on windows
1 parent 292a7f0 commit 5499c77

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

cmd/cloudflared/config/configuration.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ var (
2626

2727
// Launchd doesn't set root env variables, so there is default
2828
// Windows default config dir was ~/cloudflare-warp in documentation; let's keep it compatible
29-
DefaultConfigDirs = []string{"~/.cloudflared", "~/.cloudflare-warp", "~/cloudflare-warp", "/etc/cloudflared", DefaultUnixConfigLocation}
29+
defaultUserConfigDirs = []string{"~/.cloudflared", "~/.cloudflare-warp", "~/cloudflare-warp"}
30+
defaultNixConfigDirs = []string{"/etc/cloudflared", DefaultUnixConfigLocation}
3031
)
3132

3233
const DefaultCredentialFile = "cert.pem"
@@ -63,6 +64,16 @@ func DefaultConfigPath() string {
6364
return filepath.Join(dir, DefaultConfigFiles[0])
6465
}
6566

67+
// DefaultConfigSearchDirectories returns the default folder locations of the config
68+
func DefaultConfigSearchDirectories() []string {
69+
dirs := make([]string, len(defaultUserConfigDirs))
70+
copy(dirs, defaultUserConfigDirs)
71+
if runtime.GOOS != "windows" {
72+
dirs = append(dirs, defaultNixConfigDirs...)
73+
}
74+
return dirs
75+
}
76+
6677
// FileExists checks to see if a file exist at the provided path.
6778
func FileExists(path string) (bool, error) {
6879
f, err := os.Open(path)
@@ -86,10 +97,10 @@ func FindInputSourceContext(context *cli.Context) (altsrc.InputSourceContext, er
8697
}
8798

8899
// FindDefaultConfigPath returns the first path that contains a config file.
89-
// If none of the combination of DefaultConfigDirs and DefaultConfigFiles
100+
// If none of the combination of DefaultConfigSearchDirectories() and DefaultConfigFiles
90101
// contains a config file, return empty string.
91102
func FindDefaultConfigPath() string {
92-
for _, configDir := range DefaultConfigDirs {
103+
for _, configDir := range DefaultConfigSearchDirectories() {
93104
for _, configFile := range DefaultConfigFiles {
94105
dirPath, err := homedir.Expand(configDir)
95106
if err != nil {

cmd/cloudflared/path/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// GenerateFilePathFromURL will return a filepath for given access application url
1515
func GenerateFilePathFromURL(url *url.URL, suffix string) (string, error) {
16-
configPath, err := homedir.Expand(config.DefaultConfigDirs[0])
16+
configPath, err := homedir.Expand(config.DefaultConfigSearchDirectories()[0])
1717
if err != nil {
1818
return "", err
1919
}

cmd/cloudflared/tunnel/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func StartServer(c *cli.Context, version string, shutdownC, graceShutdownC chan
254254
dnsReadySignal := make(chan struct{})
255255

256256
if c.String("config") == "" {
257-
logger.Infof("Cannot determine default configuration path. No file %v in %v", config.DefaultConfigFiles, config.DefaultConfigDirs)
257+
logger.Infof("Cannot determine default configuration path. No file %v in %v", config.DefaultConfigFiles, config.DefaultConfigSearchDirectories())
258258
}
259259

260260
if c.IsSet("trace-output") {
@@ -499,7 +499,7 @@ func Before(c *cli.Context) error {
499499
}
500500

501501
if c.String("config") == "" {
502-
logger.Debugf("Cannot determine default configuration path. No file %v in %v", config.DefaultConfigFiles, config.DefaultConfigDirs)
502+
logger.Debugf("Cannot determine default configuration path. No file %v in %v", config.DefaultConfigFiles, config.DefaultConfigSearchDirectories())
503503
}
504504
inputSource, err := config.FindInputSourceContext(c)
505505
if err != nil {

cmd/cloudflared/tunnel/configuration.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ var (
3434
argumentsUrl = developerPortal + "/reference/arguments/"
3535
)
3636

37-
// returns the first path that contains a cert.pem file. If none of the DefaultConfigDirs
37+
// returns the first path that contains a cert.pem file. If none of the DefaultConfigSearchDirectories
3838
// contains a cert.pem file, return empty string
3939
func findDefaultOriginCertPath() string {
40-
for _, defaultConfigDir := range config.DefaultConfigDirs {
40+
for _, defaultConfigDir := range config.DefaultConfigSearchDirectories() {
4141
originCertPath, _ := homedir.Expand(filepath.Join(defaultConfigDir, config.DefaultCredentialFile))
4242
if ok, _ := config.FileExists(originCertPath); ok {
4343
return originCertPath
@@ -95,7 +95,7 @@ func dnsProxyStandAlone(c *cli.Context) bool {
9595
func findOriginCert(c *cli.Context, logger logger.Service) (string, error) {
9696
originCertPath := c.String("origincert")
9797
if originCertPath == "" {
98-
logger.Infof("Cannot determine default origin certificate path. No file %s in %v", config.DefaultCredentialFile, config.DefaultConfigDirs)
98+
logger.Infof("Cannot determine default origin certificate path. No file %s in %v", config.DefaultCredentialFile, config.DefaultConfigSearchDirectories())
9999
if isRunningFromTerminal() {
100100
logger.Errorf("You need to specify the origin certificate path with --origincert option, or set TUNNEL_ORIGIN_CERT environment variable. See %s for more information.", argumentsUrl)
101101
return "", fmt.Errorf("Client didn't specify origincert path when running from terminal")

cmd/cloudflared/tunnel/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func login(c *cli.Context) error {
5151
}
5252

5353
func checkForExistingCert() (string, bool, error) {
54-
configPath, err := homedir.Expand(config.DefaultConfigDirs[0])
54+
configPath, err := homedir.Expand(config.DefaultConfigSearchDirectories()[0])
5555
if err != nil {
5656
return "", false, err
5757
}

cmd/cloudflared/tunnel/subcommand_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (sc *subcommandContext) tunnelCredentialsPath(tunnelID uuid.UUID) (string,
125125
}
126126

127127
// Last resort look under default config directories
128-
for _, configDir := range config.DefaultConfigDirs {
128+
for _, configDir := range config.DefaultConfigSearchDirectories() {
129129
if filePath, err := tunnelFilePath(tunnelID, configDir); err == nil {
130130
if validFilePath(filePath) {
131131
return filePath, nil

0 commit comments

Comments
 (0)