{"record":{"id":"1d347c1071099a63","repo":"kubernetes/kops","slug":"unable-to-find-specified-ssh-key-q","errorCode":null,"errorMessage":"unable to find specified SSH key %q","messagePattern":"unable to find specified SSH key %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/sshkey.go","lineNumber":74,"sourceCode":"func (e *SSHKey) Find(c *fi.CloudupContext) (*SSHKey, error) {\n\tcloud := awsup.GetCloud(c)\n\n\treturn e.find(c.Context(), cloud)\n}\n\nfunc (e *SSHKey) find(ctx context.Context, cloud awsup.AWSCloud) (*SSHKey, error) {\n\trequest := &ec2.DescribeKeyPairsInput{\n\t\tKeyNames: []string{fi.ValueOf(e.Name)},\n\t}\n\n\tresponse, err := cloud.EC2().DescribeKeyPairs(ctx, request)\n\tif err != nil && awsup.AWSErrorCode(err) != \"InvalidKeyPair.NotFound\" {\n\t\treturn nil, fmt.Errorf(\"error listing SSHKeys: %v\", err)\n\t}\n\n\tif response == nil || len(response.KeyPairs) == 0 {\n\t\tif e.IsExistingKey() && *e.Name != \"\" {\n\t\t\treturn nil, fmt.Errorf(\"unable to find specified SSH key %q\", *e.Name)\n\t\t}\n\t\treturn nil, nil\n\t}\n\n\tif len(response.KeyPairs) != 1 {\n\t\treturn nil, fmt.Errorf(\"Found multiple SSHKeys with Name %q\", *e.Name)\n\t}\n\n\tk := response.KeyPairs[0]\n\tactual := &SSHKey{\n\t\tID:             k.KeyPairId,\n\t\tName:           k.KeyName,\n\t\tKeyFingerprint: k.KeyFingerprint,\n\t\tTags:           mapEC2TagsToMap(k.Tags),\n\t\tShared:         e.Shared,\n\t}\n\n\t// Avoid spurious changes","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/sshkey.go#L56-L92","documentation":"When DescribeKeyPairs returns no key pairs at all and the task is marked as referencing an existing key (IsExistingKey) with a non-empty name, kOps fails with \"unable to find specified SSH key\". This protects against silently creating a new key when the user explicitly said the key already exists.","triggerScenarios":"Spec sets an SSH key by name with existing semantics, but no EC2 key pair with that exact name exists in the target region/account.","commonSituations":"Typo in the SSH key name in the cluster spec; key exists in a different region; key was deleted out-of-band; running kOps against a different account than where the key was created.","solutions":["Correct the key name in the cluster spec (kops get instancegroups / cluster.yaml).","Verify the key exists: aws ec2 describe-key-pairs --key-names <name> in the target region.","Import the key if missing: aws ec2 import-key-pair --key-name <name> --public-key-material fileb://id_rsa.pub.","Switch the cluster to a different key or drop the existing-key flag so kOps creates one."],"exampleFix":"// before (cluster spec)\nsshKeyName: \"admin-prod-key\"\n// after\nsshKeyName: \"admin-staging-key\" // name that exists in the target region","handlingStrategy":"validation","validationCode":"keyName := spec.SSHKeyName\nout, err := exec.Command(\"aws\", \"ec2\", \"describe-key-pairs\",\n    \"--region\", region, \"--key-names\", keyName).Output()\nif err != nil {\n    return fmt.Errorf(\"SSH key %q does not exist in %s; import it or fix the spec\", keyName, region)\n}","typeGuard":"func keyExistsInRegion(keyName, region string) bool {\n    out, err := exec.Command(\"aws\", \"ec2\", \"describe-key-pairs\", \"--region\", region, \"--key-names\", keyName).Output()\n    return err == nil && len(out) > 0\n}","tryCatchPattern":null,"preventionTips":["Verify key names with aws ec2 describe-key-pairs in the target region before setting them in specs.","Remember keys are region-scoped; don't reuse names across regions assuming they exist.","Import keys with aws ec2 import-key-pair before referencing them.","Keep key names centralized in one config to avoid typos."],"tags":["aws","ec2","ssh-key","not-found"],"backgroundTag":"resource-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"}