grafana/k6 · error

failed to append ca certificate

Error message

failed to append ca certificate [%d] from PEM

What it means

Raised in buildTLSConfig when x509.CertPool.AppendCertsFromPEM rejects the i-th CA certificate passed via grpc.connect tls options — the PEM block could not be parsed into a certificate (malformed or non-certificate PEM).

Solutions

  1. Provide a valid PEM-encoded CA certificate (BEGIN CERTIFICATE block)
  2. Check for truncated or concatenated-with-garbage PEM content
  3. Verify the index reported in the message against your ca array to find the bad entry
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/grpc/client.go:157 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/1bbf1f3e2cc068ab. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/grpc/client.go:163

		return nil, err
	}
	key = pem.EncodeToMemory(&pem.Block{
		Type:  blockType,
		Bytes: decryptedKey,
	})
	return key, nil
}

func buildTLSConfig(
	parentConfig *tls.Config, certificate, key []byte, caCertificates [][]byte,
	aiaFetcher *netext.AIAFetcher, insecureSkipVerify bool, logger logrus.FieldLogger,
) (*tls.Config, error) {
	var cp *x509.CertPool
	if len(caCertificates) > 0 {
		cp, _ = x509.SystemCertPool()
		for i, caCert := range caCertificates {
			if ok := cp.AppendCertsFromPEM(caCert); !ok {
				return nil, fmt.Errorf("failed to append ca certificate [%d] from PEM", i)
			}
		}
	}

	// Ignoring 'TLS MinVersion is too low' because this tls.Config will inherit MinValue and MaxValue
	// from the vu state tls.Config

	// Take insecureSkipVerify from the user's option, not parentConfig — the AIA wrapper
	// forces parentConfig.InsecureSkipVerify to true internally, so inheriting silently
	// disables verification.
	tlsCfg := &tls.Config{
		CipherSuites:       parentConfig.CipherSuites,
		InsecureSkipVerify: insecureSkipVerify, //nolint:gosec
		MinVersion:         parentConfig.MinVersion,
		MaxVersion:         parentConfig.MaxVersion,
		Renegotiation:      parentConfig.Renegotiation,
		RootCAs:            cp,
	}

View on GitHub (pinned to 8d06114777)