Skip to content

Commit f84222b

Browse files
committed
This commit introduces two main changes to the config loading logic to prevent infinite loops.
First, it adds loop detection for the source_profile chain. This prevents aws-vault from crashing when a profile has a circular dependency on another profile via source_profile. Second, it removes the implicit inheritance of the default profile for all other profiles. This aligns aws-vault's behavior with the AWS CLI and prevents unexpected loops when the default profile has a source_profile set. This was causing a bug where aws-vault would fail to load a valid AWS config.
1 parent 694b901 commit f84222b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

vault/config.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,15 @@ type ConfigLoader struct {
274274
ActiveProfile string
275275

276276
visitedProfiles []string
277+
sourceChain map[string]bool
277278
}
278279

279280
func NewConfigLoader(baseConfig ProfileConfig, file *ConfigFile, activeProfile string) *ConfigLoader {
280281
return &ConfigLoader{
281282
BaseConfig: baseConfig,
282283
File: file,
283284
ActiveProfile: activeProfile,
285+
sourceChain: make(map[string]bool),
284286
}
285287
}
286288

@@ -405,11 +407,6 @@ func (cl *ConfigLoader) populateFromConfigFile(config *ProfileConfig, profileNam
405407
if err != nil {
406408
return err
407409
}
408-
} else if profileName != defaultSectionName {
409-
err := cl.populateFromConfigFile(config, defaultSectionName)
410-
if err != nil {
411-
return err
412-
}
413410
}
414411

415412
// Ignore source_profile if it recursively refers to the profile
@@ -516,6 +513,14 @@ func (cl *ConfigLoader) hydrateSourceConfig(config *ProfileConfig) error {
516513

517514
// GetProfileConfig loads the profile from the config file and environment variables into config
518515
func (cl *ConfigLoader) GetProfileConfig(profileName string) (*ProfileConfig, error) {
516+
if cl.sourceChain[profileName] {
517+
return nil, fmt.Errorf("Loop detected in source_profile chain for profile '%s'", profileName)
518+
}
519+
cl.sourceChain[profileName] = true
520+
defer func() {
521+
delete(cl.sourceChain, profileName)
522+
}()
523+
519524
config := cl.BaseConfig
520525
config.ProfileName = profileName
521526
cl.populateFromEnv(&config)

0 commit comments

Comments
 (0)