ipfs/kubo · error
cannot rename key with name 'self'
Error message
cannot rename key with name 'self'
What it means
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.
Source
Thrown at core/coreapi/key.go:186
return out, nil
}
// Rename renames `oldName` to `newName`. Returns the key and whether another
// key was overwritten, or an error.
func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, opts ...caopts.KeyRenameOption) (coreiface.Key, bool, error) {
_, span := tracing.Span(ctx, "CoreAPI.KeyAPI", "Rename", trace.WithAttributes(attribute.String("oldname", oldName), attribute.String("newname", newName)))
defer span.End()
options, err := caopts.KeyRenameOptions(opts...)
if err != nil {
return nil, false, err
}
span.SetAttributes(attribute.Bool("force", options.Force))
ks := api.repo.Keystore()
if oldName == "self" {
return nil, false, errors.New("cannot rename key with name 'self'")
}
if newName == "self" {
return nil, false, errors.New("cannot overwrite key with name 'self'")
}
oldKey, err := ks.Get(oldName)
if err != nil {
return nil, false, fmt.Errorf("no key named %s was found", oldName)
}
pubKey := oldKey.GetPublic()
pid, err := peer.IDFromPublicKey(pubKey)
if err != nil {
return nil, false, err
}
View on GitHub (pinned to 329838acdf)
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'
Example fix
// before
for _, k := range keys {
api.Key().Rename(ctx, k.Name(), newName)
}
// after
for _, k := range keys {
if k.Name() == "self" {
continue
}
api.Key().Rename(ctx, k.Name(), newName)
} Defensive patterns
Strategy: validation
Validate before calling
if oldName == "self" {
return errors.New("cannot rename the identity key; pick another key")
} Type guard
func isReservedKeyName(n string) bool { return n == "self" } Try / catch
ok, overwritten, err := api.Key().Rename(ctx, oldName, newName, opts...)
if err != nil && strings.Contains(err.Error(), "rename key with name 'self'") {
return errSelfRename // skip and continue in bulk-rename loops
} Prevention
- Filter 'self' out of key lists before bulk renames
- Never attempt to rename the identity alias
- Validate user-supplied source names against reserved names
When it happens
Trigger: KeyAPI.Rename(ctx, "self", newName, opts...) or `ipfs key rename self <newname>`.
Common situations: Scripts iterating over all keys (including 'self' from `key list`) and renaming them; users trying to move their identity key to a new name.
Related errors
- cannot create key with name 'self'
- unrecognized key type: %s
- cannot overwrite key with name 'self'
- refusing to export key to %s: not a regular file, character
- cannot import key with name 'self'
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/e9a988d447cfaa82.
Report an issue: GitHub.