Skip to content
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

Input x509_cert throws exception on file with private key in it #6871

Closed
robinsmidsrod opened this issue Jan 7, 2020 · 0 comments · Fixed by #6893
Closed

Input x509_cert throws exception on file with private key in it #6871

robinsmidsrod opened this issue Jan 7, 2020 · 0 comments · Fixed by #6893
Labels
bug unexpected problem or unintended behavior
Milestone

Comments

@robinsmidsrod
Copy link

If a file with both certificates and private keys is monitored by x509_cert input, no metrics are emitted for that file.

Relevant telegraf.conf:

[[inputs.x509_cert]]
  sources = [
    "/etc/pki/public.crt",
    "/etc/pki/public.pem",
  ]

System info:

Telegraf 1.13.0 (git: HEAD 773e4ca)
Ubuntu 18.04 64-bit (Azure VM)

Steps to reproduce:

  1. Create a file with a normal certificate, a CA certificate and a private key concatenated in that order.
  2. Set it up as a monitored file as mentioned above.

Expected behavior:

Expect to get metrics for both the primary certificate and the CA certificate, and the private key should be ignored.

Actual behavior:

No metrics are emitted, and this error is shown in the log:

2020-01-07T13:02:40Z E! [inputs.x509_cert] Error in plugin: cannot get SSL cert '/etc/pki/public.pem': asn1: structure error: tags don't match (16 vs {class:0 tag:2 length:1 isCompound:false}) {optional:false explicit:false application:false private:false defaultValue: tag: stringType:0 timeType:0 set:false omitEmpty:false} tbsCertificate @2

Additional info:

My guess is that the x509.ParseCertificate() function is triggering an error when the private key is encountered and all the certificates found in the file so far are discarded.

Metrics for the public.crt file are emitted, as that file contains no private key (but has multiple certificates).

In earlier versions of telegraf (tested 1.12.x) the metrics for the first certificate of the file was emitted, even if the file contained a private key. This commit seems to be involved: c53d538

@danielnelson danielnelson added bug unexpected problem or unintended behavior ready labels Jan 8, 2020
@danielnelson danielnelson added this to the 1.13.2 milestone Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants