dgraph-io/dgraph · error

Key size value is too large (x > 4096)

Error message

Key size value is too large (x > 4096)

What it means

dgraph cert create validates the RSA key size requested via --keysize before generating certificates. createCerts rejects any value above keySizeTooLarge (4096 bits) because such keys are slow to generate and exceed the tool's supported range. The error is returned from createCerts and aborts certificate creation before any files are written.

Source

Thrown at dgraph/cmd/cert/create.go:260

func createCerts(opt *options) error {
	if opt == nil {
		return errors.New("nil options")
	}

	if opt.dir == "" {
		return errors.New("Invalid TLS directory")
	}

	err := os.Mkdir(opt.dir, 0700)
	if err != nil && !os.IsExist(err) {
		return err
	}

	switch {
	case opt.keySize < keySizeTooSmall:
		return errors.New("Key size value is too small (x < 512)")
	case opt.keySize > keySizeTooLarge:
		return errors.New("Key size value is too large (x > 4096)")
	case opt.keySize%2 != 0:
		return errors.New("Key size value must be a factor of 2")
	}

	switch opt.curve {
	case "":
	case "P224", "P256", "P384", "P521":
	default:
		return errors.New(`Elliptic curve value must be one of: P224, P256, P384 or P521`)
	}

	// no path then save it in certsDir.
	if filepath.Base(opt.caKey) == opt.caKey {
		opt.caKey = filepath.Join(opt.dir, opt.caKey)
	}
	opt.caCert = filepath.Join(opt.dir, defaultCACert)

	if err := createCAPair(opt); err != nil {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Use a key size between 512 and 4096 bits; 2048 is the common secure choice
  2. Run `dgraph cert create --help` to confirm the supported range (keySizeTooSmall=512, keySizeTooLarge=4096)
  3. If higher strength is needed, switch to an ECDSA curve (P256/P384/P521) instead of a huge RSA key

Example fix

// before
dgraph cert create --keysize 8192
// after
dgraph cert create --keysize 2048
Defensive patterns

Strategy: validation

Validate before calling

const minKeySize, maxKeySize = 512, 4096
func validateKeySize(n int) error {
    if n < minKeySize { return fmt.Errorf("key size %d too small (< %d)", n, minKeySize) }
    if n > maxKeySize { return fmt.Errorf("key size %d too large (> %d)", n, maxKeySize) }
    if n%2 != 0 { return fmt.Errorf("key size %d must be a factor of 2", n) }
    return nil
}
// call before: if err := validateKeySize(*keySizeFlag); err != nil { return err }

Prevention

When it happens

Trigger: Running `dgraph cert create --keysize N` where N > 4096 (e.g. --keysize 8192). The opt.keySize value is parsed from flags and checked in the first switch of createCerts.

Common situations: Operators trying to 'harden' TLS by requesting 8192-bit RSA keys, or passing a keysize in a nonstandard unit (e.g. bits vs bytes confusion) or copying examples that use larger sizes than dgraph supports.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/01cb79e39ae2dd26. Report an issue: GitHub.