joe-elliott / cert-exporter

A Prometheus exporter that publishes cert expirations on disk and in Kubernetes secrets
Apache License 2.0
313 stars 88 forks source link

Can't process certificates that ends with new line #155

Open jiri-lazensky opened 7 months ago

jiri-lazensky commented 7 months ago

Cert-exporter can't process certificates that ends with new line.

Error example:

I0103 13:48:29.196561       1 periodicSecretChecker.go:164] Publishing <cert> tls.crt
E0103 13:48:29.196578       1 periodicSecretChecker.go:167] Error exporting secret Failed to parse intermediate as a per

I believe that this line is the "cause".

https://github.com/joe-elliott/cert-exporter/blob/28bb9e554f835f8940f89e2390b9bc205c76f100/src/exporters/certHelpers.go#L101

In my fork I have solved it by adding function that will remove all new lines from the end of file - https://github.com/joe-elliott/cert-exporter/compare/master...jiri-lazensky:cert-exporter:feat-remove-newline-from-end-of-the-cert.

Please let me know if you consider this as an issue, or if you expect that certificates will end without new line char, thanks!

joe-elliott commented 7 months ago

Yeah, that's probably the issue. Basically if there's an extra character after the last parsed PEM it attempts to parse again.

if rest is composed of whitespace only should we just ignore it?

jiri-lazensky commented 7 months ago

@joe-elliott I guess that would work also 👍. I went with simplest sanitation I could think of without touching the cert parsing itself.

joe-elliott commented 7 months ago

yeah, if you're up for a PR i think just ignoring whitespace would be better that way we'd catch similar future issues

jiri-lazensky commented 7 months ago

156

EconomicTouristsArmLate commented 1 month ago

Is there something blocking a patch release to roll this out?

joe-elliott commented 1 month ago

Nope. I actually thought this was in a release. I will get one cut soon to catch the fixes and improvements that have been added since

https://github.com/joe-elliott/cert-exporter/releases/tag/v2.12.0