{"record":{"id":"1485f8aab379af5a","repo":"ory/hydra","slug":"jwks-unable-to-generate-key","errorCode":null,"errorMessage":"jwks: unable to generate key","messagePattern":"jwks: unable to generate key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"oryx/jwksx/generator.go","lineNumber":101,"sourceCode":"\t\t\tbits = 384\n\t\t}\n\t\tif bits < 384 {\n\t\t\treturn nil, errors.Errorf(`jwksx: key size must be at least 2038448 bit for algorithm \"%s\"`, alg)\n\t\t}\n\tcase jose.HS512:\n\t\tif bits == 0 {\n\t\t\tbits = 1024\n\t\t}\n\t\tif bits < 512 {\n\t\t\treturn nil, errors.Errorf(`jwksx: key size must be at least 512 bit for algorithm \"%s\"`, alg)\n\t\t}\n\t}\n\n\tswitch alg {\n\tcase jose.ES256:\n\t\t// The cryptographic operations are implemented using constant-time algorithms.\n\t\tkey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)\n\t\treturn key, errors.Wrapf(err, \"jwks: unable to generate key\")\n\tcase jose.ES384:\n\t\t// NB: The cryptographic operations do not use constant-time algorithms.\n\t\tkey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)\n\t\treturn key, errors.Wrapf(err, \"jwks: unable to generate key\")\n\tcase jose.ES512:\n\t\t// NB: The cryptographic operations do not use constant-time algorithms.\n\t\tkey, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)\n\t\treturn key, errors.Wrapf(err, \"jwks: unable to generate key\")\n\tcase jose.EdDSA:\n\t\t_, key, err := ed25519.GenerateKey(rand.Reader)\n\t\treturn key, errors.Wrapf(err, \"jwks: unable to generate key\")\n\tcase jose.RS256, jose.RS384, jose.RS512, jose.PS256, jose.PS384, jose.PS512:\n\t\tkey, err := rsa.GenerateKey(rand.Reader, bits)\n\t\treturn key, errors.Wrapf(err, \"jwks: unable to generate key\")\n\tcase jose.HS256, jose.HS384, jose.HS512:\n\t\tif bits%8 != 0 {\n\t\t\treturn nil, errors.Errorf(`jwksx: key size must be a multiple of 8 for algorithm \"%s\" but got: %d`, alg, bits)\n\t\t}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/jwksx/generator.go#L83-L119","documentation":"This is the wrap message around a failure from crypto/ecdsa's ecdsa.GenerateKey when generating the ES256 (P-256) key. The only realistic cause is the crypto/rand entropy source failing (rand.Reader read error), which is extremely rare and usually indicates a broken system entropy pool. It can also fire even when err is nil because errors.Wrapf is called unconditionally, though wrapping a nil error returns nil in the pkg/errors used here only if it handles nil — with github.com/pkg/errors, Wrapf(nil, ...) returns nil, so this message always implies a real GenerateKey failure.","triggerScenarios":"GenerateSigningKeys(id, \"ES256\", bits) passing size validation, then ecdsa.GenerateKey(elliptic.P256(), rand.Reader) returning an error — i.e. the OS entropy source (/dev/urandom, getrandom) failed.","commonSituations":"Running in restricted containers/VMs with a broken or exhausted entropy pool; sandboxed CI environments lacking /dev/urandom access; unusual kernels or embedded environments.","solutions":["Verify the host's entropy source is functional (check /dev/urandom is readable, kernel getrandom works)","Restart or fix the container/VM if its random device is broken","Retry generation — entropy read failures are often transient","Upgrade the Go runtime/OS if getrandom is misbehaving"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check the entropy source before generation:\nif f, err := os.Open(\"/dev/urandom\"); err != nil {\n\treturn fmt.Errorf(\"entropy source unavailable: %w\", err)\n} else {\n\tf.Close()\n}","typeGuard":null,"tryCatchPattern":"jwks, err := jwksx.GenerateSigningKeys(id, \"ES256\", 0)\nif err != nil && strings.Contains(err.Error(), \"unable to generate key\") {\n\t// transient entropy failure: back off and retry\n\ttime.Sleep(100 * time.Millisecond)\n\tjwks, err = jwksx.GenerateSigningKeys(id, \"ES256\", 0)\n}","preventionTips":["Ensure containers/VMs expose a working /dev/urandom and getrandom","Avoid running key generation in heavily restricted sandboxes","Retry generation once or twice on failure — entropy errors are usually transient","Monitor host entropy health if generating keys at scale"],"tags":["jwks","go","crypto","entropy","ecdsa"],"backgroundTag":"entropy-source-failure","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}