{"record":{"id":"f4688a7f443a859b","repo":"ipfs/kubo","slug":"cannot-import-key-with-name-self","errorCode":null,"errorMessage":"cannot import key with name 'self'","messagePattern":"cannot import key with name 'self'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/keystore.go","lineNumber":466,"sourceCode":"\n  $ openssl genpkey -algorithm ED25519 > ed25519.pem\n  $ ipfs key import test-openssl -f pem-pkcs8-cleartext ed25519.pem\n`,\n\t},\n\tOptions: []cmds.Option{\n\t\tke.OptionIPNSBase,\n\t\tcmds.StringOption(keyFormatOptionName, \"f\", \"The format of the private key to import, libp2p-protobuf-cleartext or pem-pkcs8-cleartext.\").WithDefault(keyFormatLibp2pCleartextOption),\n\t\tcmds.BoolOption(keyAllowAnyTypeOptionName, \"Allow importing any key type.\").WithDefault(false),\n\t},\n\tArguments: []cmds.Argument{\n\t\tcmds.StringArg(\"name\", true, false, \"name to associate with key in keychain\"),\n\t\tcmds.FileArg(\"key\", true, false, \"key provided by generate or export\"),\n\t},\n\tRun: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {\n\t\tname := req.Arguments[0]\n\n\t\tif name == \"self\" {\n\t\t\treturn fmt.Errorf(\"cannot import key with name 'self'\")\n\t\t}\n\n\t\tkeyEnc, err := ke.KeyEncoderFromString(req.Options[ke.OptionIPNSBase.Name()].(string))\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tfile, err := cmdenv.GetFileArg(req.Files.Entries())\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer file.Close()\n\n\t\tdata, err := io.ReadAll(file)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/keystore.go#L448-L484","documentation":"`ipfs key import` refuses the reserved name 'self', which in IPNS refers to the node's own identity key (the peer's private key). Importing a key under that name would shadow or conflict with the node identity, so it is unconditionally rejected as input validation. Choose any other name for the imported key.","triggerScenarios":"`ipfs key import self <file>` or a script parameterizing the key name whose value happens to be 'self'. Also `ipfs key gen self` is rejected the same way.","commonSituations":"Batch-import scripts iterating a name list that contains 'self'; users wanting to replace their identity key via import (unsupported — use init or a different node); variable interpolation producing an empty-then-default 'self'.","solutions":["Use a different name: `ipfs key import mykey <file>`","Sanitize the name argument in scripts (reject 'self' before calling)","If the goal was to replace the node identity, that is not supported via key import — re-run `ipfs init` with the desired key or use the repo's identity swap tooling","List existing names with `ipfs key list` to pick a non-conflicting one"],"exampleFix":"// before\nipfs key import self ed25519.pem\n// after\nipfs key import my-openssl-key ed25519.pem","handlingStrategy":"validation","validationCode":"if name == \"self\":\n    raise ValueError(\"key name 'self' is reserved for the node identity; choose another name\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate key names in scripts against a reserved list ('self') before import","Sanitize user-supplied names passed to `ipfs key import`","Remember `ipfs key gen self` is likewise rejected"],"tags":["cli","keystore","ipns","validation"],"backgroundTag":"reserved-name-conflict","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"}