{"record":{"id":"e463682066e5c095","repo":"ipfs/kubo","slug":"setting-private-key-with-api-is-not-supported","errorCode":null,"errorMessage":"setting private key with API is not supported","messagePattern":"setting private key with API is not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/config.go","lineNumber":657,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"failed to decode PrivKey: %w\", err)\n\t}\n\tid, err := peer.IDFromPrivateKey(pk)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to derive PeerID from PrivKey: %w\", err)\n\t}\n\treturn id, nil\n}\n\nfunc replaceConfig(r repo.Repo, file io.Reader) error {\n\tvar newCfg config.Config\n\tif err := json.NewDecoder(file).Decode(&newCfg); err != nil {\n\t\treturn errors.New(\"failed to decode file as config\")\n\t}\n\n\t// Handle Identity.PrivKey (secret)\n\n\tif len(newCfg.Identity.PrivKey) != 0 {\n\t\treturn errors.New(\"setting private key with API is not supported\")\n\t}\n\n\tkeyF, err := getConfig(r, config.PrivKeySelector)\n\tif err != nil {\n\t\treturn errors.New(\"failed to get PrivKey\")\n\t}\n\n\tpkstr, ok := keyF.Value.(string)\n\tif !ok {\n\t\treturn errors.New(\"private key in config was not a string\")\n\t}\n\n\tnewCfg.Identity.PrivKey = pkstr\n\tid, err := nodePeerID(r)\n\tif err != nil {\n\t\treturn err\n\t}\n\tnewCfg.Identity.PeerID = id.String()","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/config.go#L639-L675","documentation":"replaceConfig guard for 'ipfs config replace': the supplied replacement config file contains a non-empty Identity.PrivKey. Writing a private key through the API is forbidden (secret-exfiltration risk); the daemon's existing key is preserved instead.","triggerScenarios":"Thrown at core/commands/config.go:657 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the PrivKey field from the replacement file before 'ipfs config replace'","Copy the config file manually on the host if a key migration is truly intended"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}