{"record":{"id":"5a59c3122b27be0b","repo":"kubernetes/kops","slug":"can-not-find-home-directory","errorCode":null,"errorMessage":"can not find home directory","messagePattern":"can not find home directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/swiftfs.go","lineNumber":111,"sourceCode":"\tclient, err := openstack.NewObjectStorageV1(pc, endpointOpt)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error building swift client: %v\", err)\n\t}\n\treturn client, nil\n}\n\ntype OpenstackConfig struct{}\n\nfunc (OpenstackConfig) filename() (string, error) {\n\tname := os.Getenv(\"OPENSTACK_CREDENTIAL_FILE\")\n\tif name != \"\" {\n\t\tklog.V(2).Infof(\"using openstack config found in $OPENSTACK_CREDENTIAL_FILE: %s\", name)\n\t\treturn name, nil\n\t}\n\n\thomeDir := homedir.HomeDir()\n\tif homeDir == \"\" {\n\t\treturn \"\", fmt.Errorf(\"can not find home directory\")\n\t}\n\tf := filepath.Join(homeDir, \".openstack\", \"config\")\n\tklog.V(2).Infof(\"using openstack config found in %s\", f)\n\treturn f, nil\n}\n\nfunc (oc OpenstackConfig) getSection(name string, items []string) (map[string]string, error) {\n\tfilename, err := oc.filename()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tconfig, err := ini.Load(filename)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error loading config file: %v\", err)\n\t}\n\tsection, err := config.GetSection(name)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting section of %s: %v\", name, err)","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/swiftfs.go#L93-L129","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set OPENSTACK_CREDENTIAL_FILE to the absolute path of your openstack config file.","Set HOME to a directory containing .openstack/config (e.g. export HOME=/root).","Create ~/.openstack/config with the required credentials/region.","For services, hardcode the credential file path in the unit/container environment."],"exampleFix":"// before\nexport HOME=\n// after\nexport HOME=/root\nexport OPENSTACK_CREDENTIAL_FILE=/etc/kops/openstack/config","handlingStrategy":"validation","validationCode":"// Guarantee a config source exists before relying on OpenstackConfig\nif os.Getenv(\"OPENSTACK_CREDENTIAL_FILE\") == \"\" && os.Getenv(\"HOME\") == \"\" {\n\treturn errors.New(\"set OPENSTACK_CREDENTIAL_FILE or HOME; no home directory resolvable\")\n}\nif _, err := os.Stat(configPath); err != nil {\n\treturn fmt.Errorf(\"openstack config not found at %s: %w\", configPath, err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set OPENSTACK_CREDENTIAL_FILE explicitly in containers and systemd units","Never rely on HOME being set in CI runners","Ship the config file into the image/container at a fixed path","Check `echo $HOME` resolves when debugging service environments"],"tags":["openstack","config","home-directory","environment"],"backgroundTag":"missing-home-directory","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}