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

Emit "days remaining" and count of certificates type performance data metrics #445

Closed
atc0005 opened this issue Dec 16, 2022 · 5 comments · Fixed by #465
Closed

Emit "days remaining" and count of certificates type performance data metrics #445

atc0005 opened this issue Dec 16, 2022 · 5 comments · Fixed by #465
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request output/perfdata Service Perf Data (aka, "performance data") plugin/check_cert
Milestone

Comments

@atc0005
Copy link
Owner

atc0005 commented Dec 16, 2022

The question will be whether this applies to any monitored certificate or only the leaf certificate.

Emitting metrics for the specific chain position likely won't be useful, so I'm leaning towards making the assumption that days_remaining (or whatever name is settled on) will be for the certificate in chain position 0.

We could also apply a restriction that the certificate in chain position 0 be a leaf certificate, but that seems fragile.

@atc0005 atc0005 added enhancement New feature or request plugin/check_cert tests output/perfdata Service Perf Data (aka, "performance data") labels Dec 16, 2022
@atc0005 atc0005 added this to the Future milestone Dec 16, 2022
@atc0005 atc0005 self-assigned this Dec 16, 2022
@atc0005 atc0005 modified the milestones: Future, Next Feature Release Jan 24, 2023
@atc0005
Copy link
Owner Author

atc0005 commented Jan 24, 2023

Some potential *_days_remaining metrics:

  • leaf_cert_days_remaining
  • intermediate_certs_days_remaining
  • root_cert_days_remaining

Arguments against:

  • root_cert_days_remaining
    • including a root certificate in a certificate chain does not appear to be best practice, so emitting a metric for it is questionable
    • emitting the metric conditionally would likely cause issues for tools that always expect a metric to be present
  • leaf_cert_days_remaining
    • won't have any use if there are no leaf certs in the chain
      • e.g., if the plugin is used to monitor an intermediates bundle separately
      • not sure if this a real concern?
  • intermediate_certs_days_remaining
    • if the certificate is already flagged as problematic, is there value in noting this separately?
      • if a flag is added to ignore expired intermediates, emitting a metric to track the value could be valuable?
    • emitting the metric conditionally would likely cause issues for tools that always expect a metric to be present
      • e.g., if the cert for 20xx contains intermediates, but the replacement cert chain for 20xy contains just a leaf cert

All of this said, I'm thinking the best approach is one of:

  • name the metric leaf_cert_days_remaining and conditionally emit whenever a leaf certificate is detected
    • this would prevent emitting a metric that communicates "zero days remaining, your cert is about to expire" for (rare?) cases where a cert bundle (e.g., via file flag) is monitored separately
  • name the metric days_remaining and document that it is specifically for the certificate in chain position 0
    • this would be regardless of whether the certificate in chain position 0 is a leaf certificate or the outermost intermediate certificate

@atc0005
Copy link
Owner Author

atc0005 commented Jan 24, 2023

Another option is to list metrics for each certificate in the chain based on position.

If we go that route, we still have two options:

  • starting at position 0
    • matches openssl output
  • starting at position 1
    • matches lscert output
    • matches check_cert plugin output
    • matches ssllabs.com output

Output below for reference.

If we go this route, for consistency we should probably start at position 1 so that there is a strong correlation between the output from the check_cert plugin and lscert CLI tool and the performance data metrics.


openssl lists certificates in a chain starting with position 0:

openssl s_client output
$ echo "" | openssl s_client -showcerts -connect www.google.com:443
CONNECTED(0000019C)
---
Certificate chain
 0 s:CN = www.google.com
   i:C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
-----BEGIN CERTIFICATE-----
MIIEhzCCA2+gAwIBAgIQVramuodXnA0KZSP2PDqq9TANBgkqhkiG9w0BAQsFADBG
MQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExM
QzETMBEGA1UEAxMKR1RTIENBIDFDMzAeFw0yMzAxMDIwODE5MTlaFw0yMzAzMjcw
ODE5MThaMBkxFzAVBgNVBAMTDnd3dy5nb29nbGUuY29tMFkwEwYHKoZIzj0CAQYI
KoZIzj0DAQcDQgAEZ6s7EvAOtBEY/mA7QXOM8eh3zB3CKtQOAPjAgCslU7sXrHM0
fD5nyzdFozwUhSe9t/3FGYvE8NvMHX9dfYBnMKOCAmcwggJjMA4GA1UdDwEB/wQE
AwIHgDATBgNVHSUEDDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQW
BBTv9gk5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8RpCw2BfWP7c44XBBLHqHiWHD11
AJMyCkuK4vNGWlU=
-----END CERTIFICATE-----
 1 s:C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
   i:C = US, O = Google Trust Services LLC, CN = GTS Root R1
-----BEGIN CERTIFICATE-----
MIIFljCCA36gAwIBAgINAgO8U1lrNMcY9QFQZjANBgkqhkiG9w0BAQsFADBHMQsw
CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU
MBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMjAwODEzMDAwMDQyWhcNMjcwOTMwMDAw
MDQyWjBGMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp
Y2VzIExMQzETMBEGA1UEAxMKR1RTIENBIDFDMzCCASIwDQYJKoZIhvcNAQEBBQAD
ggEPADCCAQoCggEBAPWI3+dijB43+DdCkH9sh9D7ZYIl/ejLa6T/belaI+KZ9hzp
kgOZE3wJCor6QtZeViSqejOEH9Hpabu5dOxXTGZok3c3VVP+ORBNtzS7XyV3NzsX
lOo85Z3VvMO0Q+sup0fvsEQRY9i0QYXdQTBIkxu/t/bgRQIh4JZCF8/ZK2VWNAcm
BA2o/X3KLu/qSHw3TT8An4Pf73WELnlXXPxXbhqW//yMmqaZviXZf5YsBvcRKgKA
gOtjGDxQSYflispfGStZloEAoPtR28p3CwvJlk/vcEnHXG0g/Zm0tOLKLnf9LdwL
tmsTDIwZKxeWmLnwi/agJ7u2441Rj72ux5uxiZ0CAwEAAaOCAYAwggF8MA4GA1Ud
DwEB/wQEAwIBhjAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwEgYDVR0T
AQH/BAgwBgEB/wIBADAdBgNVHQ4EFgQUinR/r4XN7pXNPZzQ4kYU83E1HScwHwYD
VR0jBBgwFoAU5K8rJnEaK0gnhS9SZizv8IkTcT4waAYIKwYBBQUHAQEEXDBaMCYG
CCsGAQUFBz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N = GTS Root R1
   i:C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CA
-----BEGIN CERTIFICATE-----
MIIFYjCCBEqgAwIBAgIQd70NbNs2+RrqIQ/E8FjTDTANBgkqhkiG9w0BAQsFADBX
MQswCQYDVQQGEwJCRTEZMBcGA1UEChMQR2xvYmFsU2lnbiBudi1zYTEQMA4GA1UE
CxMHUm9vdCBDQTEbMBkGA1UEAxMSR2xvYmFsU2lnbiBSb290IENBMB4XDTIwMDYx
OTAwMDA0MloXDTI4MDEyODAwMDA0MlowRzELMAkGA1UEBhMCVVMxIjAgBgNVBAoT
GUdvb2dsZSBUcnVzdCBTZXJ2aWNlcyBMTEMxFDASBgNVBAMTC0dUUyBSb290IFIx
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAthECix7joXebO9y/lD63
ladAPKH9gvl9MgaCcfb2jH/76Nu8ai6Xl6OMS/kr9rH5zoQdsfnFl97vufKj6bwS
iV6nqlKr+CMny6SxnGPb15l+8Ape62im9MZaRw1NEDPjTrETo8gYbEvs/AmQ351k
KSUjB6G00j0uYODP0gmHu81I8E3CwnqIiru6z1kZ1q+PsAewnjHxgsHA3y6mbWwZ
DrXYfiYaRQM9sHmklCitD38m5agI/pboPGiUU+6DOogrFZYJsuB6jC511pzrp1Zk
j5ZPaK49l8KEj8C8QMALXL32h7M1bKwYUH+E4EzNktMg6TO8UpmvMrUpsyUqtEj5
cuHKZPfmghCN6J3Cioj6OGaK/GP5Afl4/Xtcd/p2h/rs37EOeZVXtL0m79YB0esW
CruOC7XFxYpVq9Os6pFLKcwZpDIlTirxZUTQAs6qzkm06p98g7BAe+dDq6dso499
iYH6TKX/1Y7DzkvgtdizjkXPdsDtQCv9Uw+wp9U7DbGKogPeMa3Md+pvez7W35Ei
Eua++tgy/BBjFFFy3l3WFpO9KWgz7zpm7AeKJt8T11dleCfeXkkUAKIAf5qoIbap
sZWwpbkNFhHax2xIPEDgfg1azVY80ZcFuctL7TlLnMQ/0lUTbiSw1nH69MG6zO0b
9f6BQdgAmD06yK56mDcYBZUCAwEAAaOCATgwggE0MA4GA1UdDwEB/wQEAwIBhjAP
BgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTkrysmcRorSCeFL1JmLO/wiRNxPjAf
BgNVHSMEGDAWgBRge2YaRQ2XyolQL30EzTSo//z9SzBgBggrBgEFBQcBAQRUMFIw
JQYIKwYBBQUHMAGGGWh0dHA6Ly9vY3NwLnBraS5nb29nL2dzcjEwKQYIKwYBBQUH
MAKGHWh0dHA6Ly9wa2kuZ29vZy9nc3IxL2dzcjEuY3J0MDIGA1UdHwQrMCkwJ6Al
oCOGIWh0dHA6Ly9jcmwucGtpLmdvb2cvZ3NyMS9nc3IxLmNybDA7BgNVHSAENDAy
MAgGBmeBDAECATAIBgZngQwBAgIwDQYLKwYBBAHWeQIFAwIwDQYLKwYBBAHWeQIF
AwMwDQYJKoZIhvcNAQELBQADggEBADSkHrEoo9C0dhemMXoh6dFSPsjbdBZBiLg9
NR3t5P+T4Vxfq7vqfM/b5A3Ri1fyJm9bvhdGaJQ3b2t6yMAYN/olUazsaL+yyEn9
WprKASOshIArAoyZl+tJaox118fessmXn1hIVw41oeQa1v1vg4Fv74zPl6/AhSrw
9U5pCZEt4Wi4wStz6dTZ/CLANx8LZh1J7QJVj2fhMtfTJr9w4z30Z209fOU0iOMy
+qduBmpvvYuR7hZL6Dupszfnw0Skfths18dG9ZKb59UhvmaSGZRVbNQpsg3BZlvi
d0lIKO2d1xozclOzgjXPYovJJIultzkMu34qQb9Sz/yilrbCgj8=
-----END CERTIFICATE-----
---
Server certificate
subject=CN = www.google.com

issuer=C = US, O = Google Trust Services LLC, CN = GTS CA 1C3

---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: ECDSA
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 4295 bytes and written 396 bytes
Verification: OK
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 256 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
depth=2 C = US, O = Google Trust Services LLC, CN = GTS Root R1
verify return:1
depth=1 C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
verify return:1
depth=0 CN = www.google.com
verify return:1
DONE

while tooling from this projects lists certificates starting at 1:

lscert output
$ lscert www.google.com


======================
CERTIFICATES | SUMMARY
======================

- OK: 3 certs retrieved for service running on www.google.com (142.251.15.104) at port 443 using host value "www.google.com"
- OK: Hostname validation using value "www.google.com" successful for leaf certificate
- OK: SANs List validation ignored: 0 SANs entries specified, 1 SANs entries on leaf cert [0 EXPECTED, 0 MISSING, 0 UNEXPECTED]
- OK: Expiration validation successful: leaf cert "www.google.com" expires next with 61d 19h remaining (until 2023-03-27 08:19:18 +0000 UTC) [EXPIRED: 0, EXPIRING: 0, OK: 3]


============================
CERTIFICATES | CHAIN DETAILS
============================

Certificate 1 of 3 (leaf):
        Name: CN=www.google.com
        SANs entries: [www.google.com]
        Issuer: CN=GTS CA 1C3,O=Google Trust Services LLC,C=US
        Serial: 56:B6:A6:BA:87:57:9C:0D:0A:65:23:F6:3C:3A:AA:F5
        Issued On: 2023-01-02 08:19:19 +0000 UTC
        Expiration: 2023-03-27 08:19:18 +0000 UTC
        Status: [OK] 61d 19h remaining

Certificate 2 of 3 (intermediate):
        Name: CN=GTS CA 1C3,O=Google Trust Services LLC,C=US
        SANs entries: []
        Issuer: CN=GTS Root R1,O=Google Trust Services LLC,C=US
        Serial: 02:03:BC:53:59:6B:34:C7:18:F5:01:50:66
        Issued On: 2020-08-13 00:00:42 +0000 UTC
        Expiration: 2027-09-30 00:00:42 +0000 UTC
        Status: [OK] 1709d 11h remaining

Certificate 3 of 3 (intermediate):
        Name: CN=GTS Root R1,O=Google Trust Services LLC,C=US
        SANs entries: []
        Issuer: CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE
        Serial: 77:BD:0D:6C:DB:36:F9:1A:EA:21:0F:C4:F0:58:D3:0D
        Issued On: 2020-06-19 00:00:42 +0000 UTC
        Expiration: 2028-01-28 00:00:42 +0000 UTC
        Status: [OK] 1829d 11h remaining

@atc0005
Copy link
Owner Author

atc0005 commented Jan 24, 2023

Regardless of which option I go with:

  • dipping below 0 into negative days remaining (likely) isn't useful
  • perfdata metric(s) should include WARNING and CRITICAL thresholds

@atc0005
Copy link
Owner Author

atc0005 commented Jan 31, 2023

Decided to skip emitting expires_root metric for now. Since I'm using zero as the baseline, emitting 0 when no root certificates are found is likely to be confusing.

Also, as already noted, including the root certificate in the chain is no longer considered a good practice (though it seems it is still common for some CAs to include it in their intermediate bundles).

@atc0005
Copy link
Owner Author

atc0005 commented Jan 31, 2023

Decided to skip emitting expires_root metric for now.

I'll drop support for this from the incoming PR as part of cleaning up the associated branch (e.g., squashing commits). I should look at the ARCHIVE-i445-emit-days-remaining-perfdata branch if I decide to add the support in the future.

atc0005 added a commit that referenced this issue Jan 31, 2023
Add performance data metrics to track upcoming expirations
and total certificate types (scopes) in the chain:

- `expires_leaf`
- `expires_intermediate`
- `certs_present_leaf`
- `certs_present_intermediate`
- `certs_present_root`
- `certs_present_unknown`

As part of providing these performance data metrics various helper
functions were added:

- `certs.NumLeafCerts`
- `certs.NumIntermediateCerts`
- `certs.NumRootCerts`
- `certs.NumUnknownCerts`
- `certs.LeafCerts`
- `certs.IntermediateCerts`
- `certs.RootCerts`
- `certs.OldestLeafCert`
- `certs.OldestIntermediateCert`
- `certs.OldestRootCert`
- `certs.ExpiresInDays`

The README file has been updated to list the purpose of each
performance data metric.

As of this commit, failure to collect performance data is emitted as
an error message and recorded in the plugin's error collection (for
display in `LongServiceOutput`). Future work is scheduled to revisit
this choice and audit exit states as a whole to determine if more
appropriate exit states should be used.

refs GH-445
refs GH-464
@atc0005 atc0005 added documentation Improvements or additions to documentation and removed tests labels Jan 31, 2023
atc0005 added a commit that referenced this issue Jan 31, 2023
@atc0005 atc0005 changed the title Emit days_remaining performance data Emit "days_remaining" performance data metrics for certificates in cert chain Jan 31, 2023
@atc0005 atc0005 changed the title Emit "days_remaining" performance data metrics for certificates in cert chain Emit "days remaining" performance data metrics for certificates in cert chain Jan 31, 2023
@atc0005 atc0005 changed the title Emit "days remaining" performance data metrics for certificates in cert chain Emit "days remaining" and count of certificates type performance data metrics Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request output/perfdata Service Perf Data (aka, "performance data") plugin/check_cert
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant