{"record":{"id":"000b07d57b0a8d81","repo":"kubernetes/kops","slug":"could-not-find-user-q","errorCode":null,"errorMessage":"could not find user %q","messagePattern":"could not find user %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kubeconfig/kubecfg_builder.go","lineNumber":156,"sourceCode":"\t\tif usingAuthPlugin {\n\t\t\tauthInfo.Exec = &clientcmdapi.ExecConfig{\n\t\t\t\tAPIVersion: \"client.authentication.k8s.io/v1beta1\",\n\t\t\t\tCommand:    b.AuthenticationExec[0],\n\t\t\t\tArgs:       b.AuthenticationExec[1:],\n\t\t\t}\n\n\t\t\thaveUserInfo = true\n\t\t}\n\n\t\tif haveUserInfo {\n\t\t\tif config.AuthInfos == nil {\n\t\t\t\tconfig.AuthInfos = make(map[string]*clientcmdapi.AuthInfo)\n\t\t\t}\n\t\t\tconfig.AuthInfos[b.Context] = authInfo\n\t\t}\n\t} else if b.User != \"\" {\n\t\tif config.AuthInfos[b.User] == nil {\n\t\t\treturn fmt.Errorf(\"could not find user %q\", b.User)\n\t\t}\n\t\thaveUserInfo = true\n\t}\n\n\t// If we have a bearer token, also create a credential entry with basic auth\n\t// so that it is easy to discover the basic auth password for your cluster\n\t// to use in a web browser.\n\tif b.KubeUser != \"\" && b.KubePassword != \"\" {\n\t\tname := b.Context + \"-basic-auth\"\n\t\tauthInfo := config.AuthInfos[name]\n\t\tif authInfo == nil {\n\t\t\tauthInfo = clientcmdapi.NewAuthInfo()\n\t\t}\n\n\t\tauthInfo.Username = b.KubeUser\n\t\tauthInfo.Password = b.KubePassword\n\n\t\tif config.AuthInfos == nil {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/kubeconfig/kubecfg_builder.go#L138-L174","documentation":"WriteKubecfg builds a kubeconfig and, when the builder's User field is set but KubeUser/ClientCert paths are not taken, requires that the user entry already exist in the existing kubeconfig AuthInfos map. If no AuthInfo named b.User is present in the config being modified, this error is returned and the kubeconfig is not written. It protects against writing a context that references a dangling user credential.","triggerScenarios":"Calling WriteKubecfg with KubeconfigBuilder.User set to a name that does not exist in the current kubeconfig's auth-infos, while KubeUser/KubePassword and ClientCert/ClientKey are empty so the inline-credential branch is skipped.","commonSituations":"Running `kops export kubecfg`/`update kubecfg` against a cluster whose admin user entry was deleted or renamed in ~/.kube/config; stale KUBECONFIG pointing at a config without the expected user; typo'd user name.","solutions":["Regenerate the user entry (e.g. `kops export kubecfg --name <cluster>`), which re-creates the AuthInfo","Check `kubectl config get-users` and ensure the user named in the error exists in the file referenced by $KUBECONFIG","Create the user manually with `kubectl config set-credentials <user> ...` before retrying","Verify KUBECONFIG env var points at the intended kubeconfig file"],"exampleFix":"// before (stale kubeconfig, user 'admin.mycluster' missing)\nbuilder.User = \"admin.mycluster\"\nerr := builder.WriteKubecfg(configAccess)\n// after: re-export so the user entry is recreated\n// kops export kubecfg --name mycluster.k8s.local","handlingStrategy":"validation","validationCode":"func userExists(kubeconfigPath, user string) (bool, error) {\n\tcfg, err := clientcmd.LoadFromFile(kubeconfigPath)\n\tif err != nil { return false, err }\n\t_, ok := cfg.AuthInfos[user]\n\treturn ok, nil\n}\n","typeGuard":null,"tryCatchPattern":"if err := builder.WriteKubecfg(access); err != nil {\n\tif strings.Contains(err.Error(), \"could not find user\") {\n\t\t// regenerate credentials: kops export kubecfg --name <cluster>\n\t\treturn regenerateKubecfg(clusterName)\n\t}\n\treturn err\n}\n","preventionTips":["Run `kubectl config get-users` before writing kubeconfig entries","Keep $KUBECONFIG pointing at the file kops manages","Re-export kubecfg after cluster credential rotation","Don't hand-delete user entries from ~/.kube/config"],"tags":["kubeconfig","authentication","go"],"backgroundTag":"kubeconfig-user-not-found","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}