kubernetes/kops · error

error encoding public key: %w

Error message

error encoding public key: %w

What it means

PEM-encoding the marshaled public key into an in-memory buffer failed while computing the signer's key ID. Encoding to a bytes.Buffer cannot realistically fail, so this is a defensive wrap; if observed it points to memory exhaustion or a non-standard key type.

Source

Thrown at pkg/bootstrap/pkibootstrap/pkisigner.go:81

func NewAuthenticator(hostname string, signer crypto.Signer) (bootstrap.Authenticator, error) {
	keyID, err := computeKeyID(signer)
	if err != nil {
		return nil, err
	}

	return &pkiAuthenticator{hostname: hostname, signer: signer, keyID: keyID}, nil
}

func computeKeyID(signer crypto.Signer) (string, error) {
	publicKey := signer.Public()
	pkData, err := x509.MarshalPKIXPublicKey(publicKey)
	if err != nil {
		return "", fmt.Errorf("error converting public key to x509: %w", err)
	}

	var b bytes.Buffer
	if err := pem.Encode(&b, &pem.Block{Type: "PUBLIC KEY", Bytes: pkData}); err != nil {
		return "", fmt.Errorf("error encoding public key: %w", err)
	}
	return b.String(), nil
}

func NewAuthenticatorFromFile(p string) (bootstrap.Authenticator, error) {
	hostname, err := os.Hostname()
	if err != nil {
		return nil, fmt.Errorf("couldn't determine hostname: %w", err)
	}

	keyBytes, err := os.ReadFile(p)
	if err != nil {
		return nil, fmt.Errorf("error reading %q: %w", p, err)
	}
	key, err := pki.ParsePEMPrivateKey(keyBytes)
	if err != nil {
		return nil, fmt.Errorf("error parsing key from %q: %w", p, err)
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the wrapped error — an EOF from a bytes.Buffer is effectively impossible and indicates a bug
  2. Verify the crypto.Signer was constructed with a standard key type (RSA, ECDSA, Ed25519)
  3. Report as a bug if reproducible
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at pkg/bootstrap/pkibootstrap/pkisigner.go:81 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/3861fb8a82e5f800. Report an issue: GitHub.