{"record":{"id":"39e0e157fdebf1be","repo":"kubernetes/kops","slug":"error-parsing-kops-rsa-private-key-size-s-as-inte","errorCode":null,"errorMessage":"error parsing KOPS_RSA_PRIVATE_KEY_SIZE=%s as integer","messagePattern":"error parsing KOPS_RSA_PRIVATE_KEY_SIZE=(.+?) as integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/pki/privatekey.go","lineNumber":59,"sourceCode":"\nfunc ParsePEMPrivateKey(data []byte) (*PrivateKey, error) {\n\tk, err := parsePEMPrivateKey(data)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif k == nil {\n\t\treturn nil, nil\n\t}\n\treturn &PrivateKey{Key: k}, nil\n}\n\nfunc GeneratePrivateKey() (*PrivateKey, error) {\n\trsaKeySize := DefaultPrivateKeySize\n\n\tif os.Getenv(\"KOPS_RSA_PRIVATE_KEY_SIZE\") != \"\" {\n\t\ts := os.Getenv(\"KOPS_RSA_PRIVATE_KEY_SIZE\")\n\t\tif v, err := strconv.Atoi(s); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error parsing KOPS_RSA_PRIVATE_KEY_SIZE=%s as integer\", s)\n\t\t} else {\n\t\t\trsaKeySize = int(v)\n\t\t\tklog.V(4).Infof(\"Generating key of size %d, set by KOPS_RSA_PRIVATE_KEY_SIZE env var\", rsaKeySize)\n\t\t}\n\t}\n\n\trsaKey, err := rsa.GenerateKey(crypto_rand.Reader, rsaKeySize)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error generating RSA private key: %v\", err)\n\t}\n\n\tprivateKey := &PrivateKey{Key: rsaKey}\n\treturn privateKey, nil\n}\n\ntype PrivateKey struct {\n\tKey crypto.Signer\n}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/pki/privatekey.go#L41-L77","documentation":"GeneratePrivateKey reads the KOPS_RSA_PRIVATE_KEY_SIZE environment variable to override the default RSA key size (2048). If the value cannot be parsed as an integer by strconv.Atoi, generation aborts with this error instead of silently falling back.","triggerScenarios":"Setting KOPS_RSA_PRIVATE_KEY_SIZE to a non-integer (e.g. \"2048bit\", \"2k\", \"\" handled earlier, so anything non-numeric like \"abc\" or \"4096 \") before any call path that generates a key: createKeypair, IssueCert, BuildChallengeServerCertificate, or a Run entry point.","commonSituations":"CI scripts exporting KOPS_RSA_PRIVATE_KEY_SIZE with units or trailing characters; shell quoting issues injecting whitespace/extra chars; typo in the numeric value.","solutions":["Set KOPS_RSA_PRIVATE_KEY_SIZE to a plain integer, e.g. export KOPS_RSA_PRIVATE_KEY_SIZE=4096.","Unset the variable to fall back to the default key size.","Check the exporting script for stray units, spaces, or CR characters."],"exampleFix":"// before\nexport KOPS_RSA_PRIVATE_KEY_SIZE=4096bit\n// after\nexport KOPS_RSA_PRIVATE_KEY_SIZE=4096","handlingStrategy":"validation","validationCode":"if s := os.Getenv(\"KOPS_RSA_PRIVATE_KEY_SIZE\"); s != \"\" {\n    if _, err := strconv.Atoi(s); err != nil {\n        return fmt.Errorf(\"KOPS_RSA_PRIVATE_KEY_SIZE=%q is not an integer\", s)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export the variable as a bare integer with no units or whitespace","Unset it if you want the 2048 default","Validate env in CI scripts before invoking kops"],"tags":["pki","rsa","environment-variable","configuration"],"backgroundTag":"invalid-env-var-value","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"}