Skip to content

config: reject TLS cert/key/CA file paths that don't exist during validation - #23828

Open
mittalpk wants to merge 2 commits into
hashicorp:mainfrom
mittalpk:fix/validate-tls-cert-file-existence
Open

config: reject TLS cert/key/CA file paths that don't exist during validation#23828
mittalpk wants to merge 2 commits into
hashicorp:mainfrom
mittalpk:fix/validate-tls-cert-file-existence

Conversation

@mittalpk

Copy link
Copy Markdown

Description

`consul validate` builds and checks the runtime config but never touches the TLS cert/key/CA file paths on disk. A typo'd path in `tls.internal_rpc.cert_file` (or `https`/`grpc`, or `ca_file`/`ca_path`) passes validation cleanly and only surfaces once the agent actually tries to start and load TLS, with no useful error at that point.

This adds a check to `validate()` that stats each configured cert/key/ca file (and confirms `ca_path` is a directory) for the internal RPC, HTTPS, and gRPC protocols, failing validation early with a clear `tls.. "" does not exist` error instead.

Fixes #23820

Testing & Reproduction steps

Confirmed live: built both an unpatched `main` binary and this branch's binary, ran `consul validate` against a config with a typo'd `tls.internal_rpc.cert_file`. Unpatched: "Configuration is valid!". Fixed: "Config validation failed: tls.internal_rpc.cert_file ... does not exist".

Added `TestBuilder_validateTLSFiles` (direct unit coverage of missing/wrong-type cert, key, ca_file, ca_path across all three protocols) and `TestLoad_TLSCertFileMustExist` (end-to-end `Load()` reproduction of the reported issue, both the failing and passing case).

Several existing tests used placeholder paths that never pointed at real files on disk, since nothing previously checked them. Updated those to use real temp files/dirs so they still test what they originally tested: `TestBuilder_WarnGRPCTLS`, `TestLoad_DeprecatedConfig`, the "TLS defaults and overrides" and "auto config authorizer ok" cases in `TestLoad_IntegrationWithFlags`, and the `TestLoad_FullConfig` golden fixture.

Full `agent/config` package test suite passes.

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

…idation

consul validate builds and checks the runtime config but never touches
the TLS cert/key/CA file paths on disk. A typo'd path in
tls.internal_rpc.cert_file (or https/grpc, or ca_file/ca_path) passes
validation cleanly and only surfaces once the agent tries to start and
load TLS, with no useful error at that point.

Adds a check to validate() that stats each configured cert/key/ca file
(and confirms ca_path is a directory) for the internal RPC, HTTPS, and
gRPC protocols, failing validation early with a clear
tls.<protocol>.<field> "<path>" does not exist error instead.

Fixes hashicorp#23820
@mittalpk
mittalpk requested review from a team as code owners August 17, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consul validate misses typo in path to TLS certificates in configuration file that prevents start

1 participant