LoadConfigFileCheckDuplicate is the same as the above function but also checks for duplicate attributes TODO (HCL_DUP_KEYS_DEPRECATION): keep only ParseConfig once deprecation is complete
(path string)
| 613 | // LoadConfigFileCheckDuplicate is the same as the above function but also checks for duplicate attributes |
| 614 | // TODO (HCL_DUP_KEYS_DEPRECATION): keep only ParseConfig once deprecation is complete |
| 615 | func LoadConfigFileCheckDuplicate(path string) (cfg *Config, duplicate bool, err error) { |
| 616 | // Open the file |
| 617 | f, err := os.Open(path) |
| 618 | if err != nil { |
| 619 | return nil, false, err |
| 620 | } |
| 621 | defer f.Close() |
| 622 | // Read the file |
| 623 | d, err := io.ReadAll(f) |
| 624 | if err != nil { |
| 625 | return nil, false, err |
| 626 | } |
| 627 | |
| 628 | conf, duplicate, err := ParseConfigCheckDuplicate(string(d), path) |
| 629 | if err != nil { |
| 630 | return nil, duplicate, err |
| 631 | } |
| 632 | |
| 633 | var enableFilePermissionsCheck bool |
| 634 | if enableFilePermissionsCheckEnv := os.Getenv(consts.VaultEnableFilePermissionsCheckEnv); enableFilePermissionsCheckEnv != "" { |
| 635 | var err error |
| 636 | enableFilePermissionsCheck, err = strconv.ParseBool(enableFilePermissionsCheckEnv) |
| 637 | if err != nil { |
| 638 | return nil, duplicate, errors.New("Error parsing the environment variable VAULT_ENABLE_FILE_PERMISSIONS_CHECK") |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | if enableFilePermissionsCheck { |
| 643 | // check permissions of the config file |
| 644 | err = osutil.OwnerPermissionsMatchFile(f, 0, 0) |
| 645 | if err != nil { |
| 646 | return nil, duplicate, err |
| 647 | } |
| 648 | // check permissions of the plugin directory |
| 649 | if conf.PluginDirectory != "" { |
| 650 | |
| 651 | err = osutil.OwnerPermissionsMatch(conf.PluginDirectory, conf.PluginFileUid, conf.PluginFilePermissions) |
| 652 | if err != nil { |
| 653 | return nil, duplicate, err |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | return conf, duplicate, nil |
| 658 | } |
| 659 | |
| 660 | func ParseConfig(d, source string) (*Config, error) { |
| 661 | cfg, _, err := ParseConfigCheckDuplicate(d, source) |
no test coverage detected
searching dependent graphs…