{"record":{"id":"1bbf1f3e2cc068ab","repo":"grafana/k6","slug":"failed-to-append-ca-certificate-d-from-pem","errorCode":null,"errorMessage":"failed to append ca certificate [%d] from PEM","messagePattern":"failed to append ca certificate \\[(.+?)\\] from PEM","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/grpc/client.go","lineNumber":163,"sourceCode":"\t\treturn nil, err\n\t}\n\tkey = pem.EncodeToMemory(&pem.Block{\n\t\tType:  blockType,\n\t\tBytes: decryptedKey,\n\t})\n\treturn key, nil\n}\n\nfunc buildTLSConfig(\n\tparentConfig *tls.Config, certificate, key []byte, caCertificates [][]byte,\n\taiaFetcher *netext.AIAFetcher, insecureSkipVerify bool, logger logrus.FieldLogger,\n) (*tls.Config, error) {\n\tvar cp *x509.CertPool\n\tif len(caCertificates) > 0 {\n\t\tcp, _ = x509.SystemCertPool()\n\t\tfor i, caCert := range caCertificates {\n\t\t\tif ok := cp.AppendCertsFromPEM(caCert); !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to append ca certificate [%d] from PEM\", i)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Ignoring 'TLS MinVersion is too low' because this tls.Config will inherit MinValue and MaxValue\n\t// from the vu state tls.Config\n\n\t// Take insecureSkipVerify from the user's option, not parentConfig — the AIA wrapper\n\t// forces parentConfig.InsecureSkipVerify to true internally, so inheriting silently\n\t// disables verification.\n\ttlsCfg := &tls.Config{\n\t\tCipherSuites:       parentConfig.CipherSuites,\n\t\tInsecureSkipVerify: insecureSkipVerify, //nolint:gosec\n\t\tMinVersion:         parentConfig.MinVersion,\n\t\tMaxVersion:         parentConfig.MaxVersion,\n\t\tRenegotiation:      parentConfig.Renegotiation,\n\t\tRootCAs:            cp,\n\t}","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/grpc/client.go#L145-L181","documentation":"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).","triggerScenarios":"Thrown at internal/js/modules/k6/grpc/client.go:157 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide a valid PEM-encoded CA certificate (BEGIN CERTIFICATE block)","Check for truncated or concatenated-with-garbage PEM content","Verify the index reported in the message against your ca array to find the bad entry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}