{"record":{"id":"0b93e78ed75bdfe0","repo":"JuliusBrussee/caveman","slug":"production-requires-an-https-clickhouse-url-tl","errorCode":null,"errorMessage":"production requires an https:// CLICKHOUSE_URL (TLS only); ClickHouse credentials travel as HTTP Basic and a plaintext endpoint ships them in the clear","messagePattern":"production requires an https:// CLICKHOUSE_URL \\(TLS only\\); ClickHouse credentials travel as HTTP Basic and a plaintext endpoint ships them in the clear","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"shared/platform/chhttp/chhttp.go","lineNumber":277,"sourceCode":"// It refuses, in production, a non-HTTPS CLICKHOUSE_URL (the ClickHouse password\n// travels as HTTP Basic, so plaintext ships it in the clear) and any attempt to\n// disable certificate verification. It also resolves the TLS configuration\n// eagerly so an unreadable or unparseable CA bundle fails the process at boot\n// instead of at the first telemetry flush. Outside production it warns — loudly\n// and once — when verification has been switched off.\n//\n// It is NOT guaranteed to run before every client is constructed: control-api\n// builds a package-level query client at init (internal/httpapi/chclients.go), so\n// that one exists before main calls anything. That ordering is safe rather than\n// lucky — a client built from a rejected configuration carries errTransport and\n// refuses to send, so the failure is the refusal either way; ValidateProduction's\n// job is to turn it into a loud non-zero exit at boot instead of a runtime error.\nfunc ValidateProduction(logger *slog.Logger) error {\n\tif production() {\n\t\traw := strings.TrimSpace(env.String(\"CLICKHOUSE_URL\", \"\"))\n\t\tparsed, err := url.Parse(raw)\n\t\tif err != nil || !strings.EqualFold(parsed.Scheme, \"https\") || parsed.Hostname() == \"\" {\n\t\t\treturn fmt.Errorf(\"production requires an https:// CLICKHOUSE_URL (TLS only); ClickHouse credentials travel as HTTP Basic and a plaintext endpoint ships them in the clear\")\n\t\t}\n\t}\n\tcfg, err := tlsClientConfig()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif cfg != nil && cfg.InsecureSkipVerify && logger != nil {\n\t\tlogger.Warn(\"ClickHouse TLS certificate verification is DISABLED\",\n\t\t\t\"variable\", skipVerifyEnv,\n\t\t\t\"env\", env.String(\"CAVE_ENV\", \"local\"),\n\t\t\t\"impact\", \"telemetry and aggregate queries can be read or forged by any in-path party; never set this in production\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":259,"sourceCodeEnd":292,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/chhttp/chhttp.go#L259-L292","documentation":"ValidateProduction refuses non-https CLICKHOUSE_URL values when running in production. ClickHouse credentials travel as HTTP Basic auth, so a plaintext endpoint would ship them in the clear; the check enforces TLS-only endpoints at boot so misconfiguration becomes a loud non-zero exit rather than a runtime leak.","triggerScenarios":"Setting CLICKHOUSE_URL=http://clickhouse:8123 (or a schemeless/broken URL) while CAVE_ENV indicates production, then calling chhttp.ValidateProduction(logger).","commonSituations":"Reusing a local docker-compose http:// URL in a prod deploy; omitting the scheme entirely (CLICKHOUSE_URL=clickhouse:8123); an internal service behind a TLS-terminating proxy where the upstream URL was never switched to https.","solutions":["Set CLICKHOUSE_URL to an https:// endpoint with a hostname, e.g. https://clickhouse.internal.example.com:8443.","If TLS terminates at a sidecar/proxy, point CLICKHOUSE_URL at the TLS frontend rather than the plaintext upstream.","Verify the URL parses and includes scheme+host locally before deploying (url.Parse check or curl the https URL).","If this fires unexpectedly in what should be staging, fix CAVE_ENV so production gates aren't evaluated."],"exampleFix":"// before\nCLICKHOUSE_URL=http://clickhouse:8123\n// after\nCLICKHOUSE_URL=https://clickhouse.internal.example.com:8443","handlingStrategy":"validation","validationCode":"raw := strings.TrimSpace(os.Getenv(\"CLICKHOUSE_URL\"))\nu, err := url.Parse(raw)\nif err != nil || !strings.EqualFold(u.Scheme, \"https\") || u.Hostname() == \"\" {\n    return errors.New(\"CLICKHOUSE_URL must be an absolute https:// URL with a host\")\n}","typeGuard":null,"tryCatchPattern":"if err := chhttp.ValidateProduction(logger); err != nil {\n    if strings.Contains(err.Error(), \"https:// CLICKHOUSE_URL\") {\n        logger.Error(\"plaintext ClickHouse endpoint refused in production\", \"err\", err)\n        os.Exit(1)\n    }\n    return err\n}","preventionTips":["Always include the https:// scheme in CLICKHOUSE_URL across all environments.","Point prod at the TLS-terminating proxy, never the plaintext upstream port.","Call ValidateProduction as the first thing in main() so bad config exits before serving."],"tags":["production","tls","clickhouse","security","config"],"backgroundTag":"invalid-config-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}