{"record":{"id":"e9a988d447cfaa82","repo":"ipfs/kubo","slug":"cannot-rename-key-with-name-self","errorCode":null,"errorMessage":"cannot rename key with name 'self'","messagePattern":"cannot rename key with name 'self'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/coreapi/key.go","lineNumber":186,"sourceCode":"\treturn out, nil\n}\n\n// Rename renames `oldName` to `newName`. Returns the key and whether another\n// key was overwritten, or an error.\nfunc (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, opts ...caopts.KeyRenameOption) (coreiface.Key, bool, error) {\n\t_, span := tracing.Span(ctx, \"CoreAPI.KeyAPI\", \"Rename\", trace.WithAttributes(attribute.String(\"oldname\", oldName), attribute.String(\"newname\", newName)))\n\tdefer span.End()\n\n\toptions, err := caopts.KeyRenameOptions(opts...)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tspan.SetAttributes(attribute.Bool(\"force\", options.Force))\n\n\tks := api.repo.Keystore()\n\n\tif oldName == \"self\" {\n\t\treturn nil, false, errors.New(\"cannot rename key with name 'self'\")\n\t}\n\n\tif newName == \"self\" {\n\t\treturn nil, false, errors.New(\"cannot overwrite key with name 'self'\")\n\t}\n\n\toldKey, err := ks.Get(oldName)\n\tif err != nil {\n\t\treturn nil, false, fmt.Errorf(\"no key named %s was found\", oldName)\n\t}\n\n\tpubKey := oldKey.GetPublic()\n\n\tpid, err := peer.IDFromPublicKey(pubKey)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/coreapi/key.go#L168-L204","documentation":"Fired by CoreAPI.Rename when renaming a key to or involving the reserved name 'self'. The 'self' key is the node's identity peer key and cannot be a rename target; this validation guard rejects such requests before touching the keystore.","triggerScenarios":"KeyAPI.Rename(ctx, \"self\", newName, opts...) or `ipfs key rename self <newname>`.","commonSituations":"Scripts iterating over all keys (including 'self' from `key list`) and renaming them; users trying to move their identity key to a new name.","solutions":["Rename a regular key instead; export it with 'ipfs key export' if you need it under another identity","To change the node identity, re-initialize the repo with 'ipfs init'"],"exampleFix":"// before\nfor _, k := range keys {\n    api.Key().Rename(ctx, k.Name(), newName)\n}\n// after\nfor _, k := range keys {\n    if k.Name() == \"self\" {\n        continue\n    }\n    api.Key().Rename(ctx, k.Name(), newName)\n}","handlingStrategy":"validation","validationCode":"if oldName == \"self\" {\n    return errors.New(\"cannot rename the identity key; pick another key\")\n}","typeGuard":"func isReservedKeyName(n string) bool { return n == \"self\" }","tryCatchPattern":"ok, overwritten, err := api.Key().Rename(ctx, oldName, newName, opts...)\nif err != nil && strings.Contains(err.Error(), \"rename key with name 'self'\") {\n    return errSelfRename // skip and continue in bulk-rename loops\n}","preventionTips":["Filter 'self' out of key lists before bulk renames","Never attempt to rename the identity alias","Validate user-supplied source names against reserved names"],"tags":["keystore","keys","validation"],"backgroundTag":"reserved-key-name","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"}