-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/v1/agent/connect/ca/leaf/web endpoint returns CertPEM without a trailing newline when using vault ca provider #8178
Comments
Went digging to see if trailing newline was defined in the spec for how keys should be formatted, found
And also the note that "most extant parsers ignore blanks at the ends of lines". I think the proper implementation would be to always trim trailing whitespace at the point of generation (would that be in Vault itself or is Consul inserting additional whitespace here?) and the consumer should trim any whitespace from keys received (Consul could do this, but downstream consumers of Consul's API should too) and always insert newlines between keys when concatenating together, similar to the implementation in nginx/kubernetes-ingress#3 Keys without trailing whitespace should be expected, but trimming unexpected whitespace when present should be acceptable. |
The trailing newline comes from the go stdlib The Vault CA provider does not add a trailing newline to the data it gets from vault: https://github.com/hashicorp/consul/blob/v1.8.0/agent/connect/ca/provider_vault.go#L358 Another difference between these 2 cases is that the built-in CA example has only a single cert. The vault example has 3 certificates. If some of those are intermediate certs, it could be this code: https://github.com/hashicorp/consul/blob/v1.8.0/agent/consul/connect_ca_endpoint.go#L544-L559, which correctly trims to only a single newline between certs, but does not add a trailing newline. |
Sooo, this appears to become more of a problem when we're the consumer and concatenating these certs together at https://github.com/hashicorp/consul/blob/master/agent/connect_ca_endpoint.go#L41, such as when migrating from the built-in Consul CA to a Vault CA, resulting in a line Refs #8774 |
Not to crash the conversation, but I brought this up with a few Hashicorp folks recently, and figured I would throw in my $.02. I think Mike has the right idea here. My reading of the relevant RFCs surrounding the PEM format (8555#9.1 and 7468#3 for ABNF spec) implies that there exists at least one newline between each root's body. When provided a cross-signed certificate, I expect it to conform to the following standard (lifted from the RFCs):
This would imply, to me, that there must exist a terminal newline (CRLF/CR/LF) at the end of each certificate, and another when concatenating. Mike linked to the line that I found (and blamed) during my debugging; but, at the time I could not tell if that was indeed the place from whence Envoy was getting its problematic configuration. It would seem that around https://github.com/hashicorp/consul/blob/master/agent/connect_ca_endpoint.go#L41, ensuring that there is a terminal newline with a concatenating newline would be to spec. Ensuring that there's exactly one newline will probably work for most parsers, but wouldn't exactly be to spec, if I were to hazard a guess. |
Overview of the Issue
When the Vault CA provider is used, the response from the leaf endpoint, e.g.
/v1/agent/connect/ca/leaf/web
has a keyCertPEM
. This key does not have a trailing newline.When the built in Consul CA provider is used, this key does have a trailing newline.
The responses should be consistent (either no trailing newline or trailing newline).
Built-in CA Response:
Vault CA Response:
Reproduction Steps
curl http://127.0.0.1:8500/v1/agent/connect/ca/leaf/web
The text was updated successfully, but these errors were encountered: