Skip to content

Commit 84f07ab

Browse files
authored
Don't use default CA file if profile does not exist (#2366)
When using elastic-package with environment variables with a profile without a configured stack, avoid using the default CA certificate file if it neither exists.
1 parent aa149de commit 84f07ab

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

internal/stack/config.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func configPath(profile *profile.Profile) string {
4343
return profile.Path(ProfileStackPath, configFileName)
4444
}
4545

46-
func defaultConfig(profile *profile.Profile) Config {
46+
func defaultConfig() Config {
4747
return Config{
4848
Provider: DefaultProvider,
4949

@@ -52,14 +52,19 @@ func defaultConfig(profile *profile.Profile) Config {
5252
ElasticsearchUsername: elasticsearchUsername,
5353
ElasticsearchPassword: elasticsearchPassword,
5454
KibanaHost: "https://127.0.0.1:5601",
55-
CACertFile: profile.Path(CACertificateFile),
5655
}
5756
}
5857

5958
func LoadConfig(profile *profile.Profile) (Config, error) {
6059
d, err := os.ReadFile(configPath(profile))
6160
if errors.Is(err, os.ErrNotExist) {
62-
return defaultConfig(profile), nil
61+
config := defaultConfig()
62+
caCertFile := profile.Path(CACertificateFile)
63+
// Use CA file in the profile only if it exists.
64+
if _, err := os.Stat(caCertFile); err == nil {
65+
config.CACertFile = caCertFile
66+
}
67+
return config, nil
6368
}
6469
if err != nil {
6570
return Config{}, fmt.Errorf("failed to read stack config: %w", err)

0 commit comments

Comments
 (0)