kubernetes/kops · error

can not find home directory

Error message

can not find home directory

What it means

OpenstackConfig.filename resolves which config file to read: OPENSTACK_CREDENTIAL_FILE if set, otherwise $HOME/.openstack/config. If the env var is unset and homedir.HomeDir() returns an empty string, it cannot locate any config and returns this error.

Source

Thrown at util/pkg/vfs/swiftfs.go:111

	client, err := openstack.NewObjectStorageV1(pc, endpointOpt)
	if err != nil {
		return nil, fmt.Errorf("error building swift client: %v", err)
	}
	return client, nil
}

type OpenstackConfig struct{}

func (OpenstackConfig) filename() (string, error) {
	name := os.Getenv("OPENSTACK_CREDENTIAL_FILE")
	if name != "" {
		klog.V(2).Infof("using openstack config found in $OPENSTACK_CREDENTIAL_FILE: %s", name)
		return name, nil
	}

	homeDir := homedir.HomeDir()
	if homeDir == "" {
		return "", fmt.Errorf("can not find home directory")
	}
	f := filepath.Join(homeDir, ".openstack", "config")
	klog.V(2).Infof("using openstack config found in %s", f)
	return f, nil
}

func (oc OpenstackConfig) getSection(name string, items []string) (map[string]string, error) {
	filename, err := oc.filename()
	if err != nil {
		return nil, err
	}
	config, err := ini.Load(filename)
	if err != nil {
		return nil, fmt.Errorf("error loading config file: %v", err)
	}
	section, err := config.GetSection(name)
	if err != nil {
		return nil, fmt.Errorf("error getting section of %s: %v", name, err)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Set OPENSTACK_CREDENTIAL_FILE to the absolute path of your openstack config file.
  2. Set HOME to a directory containing .openstack/config (e.g. export HOME=/root).
  3. Create ~/.openstack/config with the required credentials/region.
  4. For services, hardcode the credential file path in the unit/container environment.

Example fix

// before
export HOME=
// after
export HOME=/root
export OPENSTACK_CREDENTIAL_FILE=/etc/kops/openstack/config
Defensive patterns

Strategy: validation

Validate before calling

// Guarantee a config source exists before relying on OpenstackConfig
if os.Getenv("OPENSTACK_CREDENTIAL_FILE") == "" && os.Getenv("HOME") == "" {
	return errors.New("set OPENSTACK_CREDENTIAL_FILE or HOME; no home directory resolvable")
}
if _, err := os.Stat(configPath); err != nil {
	return fmt.Errorf("openstack config not found at %s: %w", configPath, err)
}

Prevention

When it happens

Trigger: getSection (via GetRegion, GetServiceConfig, getCredentialFromFile) when OPENSTACK_CREDENTIAL_FILE is unset and the process runs with no resolvable home directory (HOME unset, running as a system service with no passwd entry, empty container env).

Common situations: Running kops from a CI container or systemd unit with HOME unset, running as a non-login user, or a stripped-down environment where os.UserHomeDir fails.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/5a59c3122b27be0b. Report an issue: GitHub.