Skip to content

Add trace events to scenarios where a certificate is loaded and used by an application to monitor for expiration #86814

Open

Description

@joperezr

It is unfortunately not uncommon for applications (particularly web applications) to fail whenever relying on certificates that expire. This can happen both for certificates that are specific to the application itself, or certificates of other services that our application is trying to call into. If the .NET platform started emitting some sort of telemetry each time a certificate is used, and amongst other things, included the expiration date of that certificate, then components can be built on top of that telemetry which will be able to configure filters and then set up monitoring alerts so the application developers can get notified ahead of time and prevent an issue that might take the application down.

It is important to try to define what "using" a certificate means and which scenarios are the ones that developers would care about, since certificates get used a lot by applications these days on scenarios that some might not care about, for instance, certificates will get loaded each time the application makes an https request. This means that defining the scenarios that a developer might care about could help reducing potential "noise".

Here are some initial goals that we would like to enable for application developers with this:

  • Provide the ability to observe certificates used by dotnet runtime in the context of an application, including usage metadata. Cert use-case examples include service/app identity authentication (i.e. TLS, mTLS), data encryption/decryption, and signing. Including certificates where the app only has the public key.
  • The observation hook/event stream must allow listeners to obtain certificate metadata to filter certificates it does not care about. e.g. customer data certificates.
  • Ability to infer usage from metadata.

cc: @InterpolationStation @GrabYourPitchforks @ericstj @geeknoid @tarekgh

Activity

  1. ghost added
    untriaged
    on May 26, 2023
  2. ghost added
    needs-area-label
    on May 26, 2023
  3. removed
    needs-area-label
    on May 26, 2023
  4. tarekgh commented on May 26, 2023

    @tarekgh
    Member

    @joperezr I think we decided to use EventSource there as the code in the corelib. It is worth calling that out.

  5. added this to the 8.0.0 milestone on May 26, 2023
  6. ghost removed
    untriaged
    on May 26, 2023
  7. bartonjs commented on May 26, 2023

    @bartonjs
    Member

    I don't think any of this telemetry belongs with certificates; it's all going to be particular use cases.

    It probably makes sense for SslStream to log what certificate is being used to start a server authentication context, and perhaps the expiration thereof, and similarly when using a certificate for client authentication. But that would be very different than loading a certificate out of the AuthentiCode signature of an executable, or any other situation.

    Since it's all context-specific, I think this issue should be closed, and anywhere that it seems relevant to have such logging (e.g. SslStream) should have individual focused items.

  8. ericstj commented on May 30, 2023

    @ericstj
    Member

    Let's keep this issue open to track the cross-cutting ask and discussion. I believe that @geeknoid and @InterpolationStation also had scenarios where the application loads certificates and uses them itself. They would like some telemetry about those as well. I'm not sure if all those would be covered by passing to framework API or not.

  9. geeknoid commented on May 30, 2023

    @geeknoid
    Member

    We need a single chokepoint to unilaterally capture all cert accesses going on in the system such that we can report robust telemetry with no gaps. The idea is that we would have filters so that only telemetry relevant for a specific scenario gets emitted.

  10. vcsjones commented on May 30, 2023

    @vcsjones
    Member

    We need a single chokepoint to unilaterally capture all cert accesses going on in the system

    Some random thoughts.

    First, I don't think there is a "single" chokepoint in .NET because the OS may access certificates on behalf of .NET. Say for example, OCSP responses. .NET doesn't ever actually see the OCSP responder's certificate on Windows, to my knowledge. Expired OCSP responders happen, and has caused at least one outage for a Microsoft operated site, as far as I am aware.

    Now, I might be playing "gotcha" here, but I want to make sure it is understood that no amount of telemetry in .NET can capture literally every single certificate access. The OS is doing some lifting in some places.

    Maybe you're not interested in expired OCSP responders (or other things the OS does on .NETs behalf). I would say that is reasonable, but if you aren't interested in that scenario, what scenarios are you interested in? And that is where the telemetry should go - not in S.S.C.X509Certificates.

    The idea is that we would have filters so that only telemetry relevant for a specific scenario gets emitted.

    What do you need in the trace event to understand if it is relevant or not? Let's say telemetry is added to X509Certificate2 and friends - where does the data that you are filtering on come from? From a certificate's perspective, it has no idea why it is being used - it's just a public key with extra stuff. Maybe that stuff is part of what you want to filter on. Or maybe it isn't. For example, server certificates and client certificates can be indistinguishable from each other because most CAs issue certificates with both EKUs. So the certificate has no idea if it is being used in a client scenario or a server scenario.

  11. geeknoid commented on May 31, 2023

    @geeknoid
    Member

    The reality of the situation is that services are constantly experiencing outages due to cert expiration. Do you have any recommendations on how the libraries can provide support to avoid this problem from occurring? We found that producing telemetry is a relatively simple and effective way to enable systematic detection of potentially outdated secrets. The problem with our current solution is that it requires a dedicated API call that customers must call explicitly, which is easy to forget to do.

    I'm open to other ideas.

  12. ericstj commented on Jun 28, 2023

    @ericstj
    Member

    Perhaps it would be helpful to enumerate all the certificate use cases and see if a .Net solution covers the majority on all platforms? What do you think @InterpolationStation @geeknoid?

  13. blowdart commented on Jun 28, 2023

    @blowdart
    Contributor

    Honestly if services are failing due to cert expiration that indicates, at least to me, an auto renewal process is the right way to go rather than relying on .net to perhaps catch something, depending on code paths. And that is a solved problem, windows had CEL/CES long before acme came along.

    And if your cert issuance process doesn't have automatic renewal frankly it should.

  14. InterpolationStation commented on Jun 28, 2023

    @InterpolationStation

    Hi @blowdart, configuring auto-renewal is part of the solution, but rotation does not ensure new versions have been deployed/consumed by services. The only way to know if an expiring certificate is no longer used is to monitor applications cert usage telemetry. Many outages have occurred when service owners did not know when an expiring cert was in-use by their service, or a failed/partial deployment did not update all nodes with the new cert, or a deployment rollback to LKG used an expired certificate. Observing all certs used by the application is the only way to detect and prevent these outages.

  15. modified the milestones: 8.0.0, 9.0.0 on Jul 28, 2023
  16. modified the milestones: 9.0.0, Future on Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions