Skip to content

Leak of private key inline_string when specifying multiple tls certificates #4757

Closed

Description

@cetanu

Issue summary

Specifying more than one auth.TlsCertificate causes Envoy to dump the proto of the affected listener to the logs; if there is an inline private key, it is not redacted prior to logging.

Api Config Source for LDS = REST, not gRPC/file

Error produced by Envoy

newline separated to enhance readability

[9][warning][config] bazel-out/k8-opt/bin/source/common/config/_virtual_includes/http_subscription_lib/common/config/http_subscription_impl.h:87] 

REST config update rejected: Proto constraint validation failed 
(ListenerValidationError.FilterChains[i]: ["embedded message failed validation"] | 
caused by FilterChainValidationError.TlsContext: ["embedded message failed validation"] | 
caused by DownstreamTlsContextValidationError.CommonTlsContext: ["embedded message failed validation"] | 
caused by CommonTlsContextValidationError.TlsCertificates: ["value must contain no more than " '\x01' " item(s)"]): name: "TestListener"
<insert proto dump here>

Example configuration

{
  "@type": "type.googleapis.com/envoy.api.v2.Listener",
  "name": "TestListener",
  "address": {
    "socket_address": {
      "address": "0.0.0.0",
      "port_value": 443,
      "protocol": "TCP"
    }
  },
  "filter_chains": [
    {
      "filters": [
        {
          "config": {
            "access_log": [
              {
                "config": {
                  "path": "/var/log/envoy/access.log"
                },
                "name": "envoy.file_access_log"
              }
            ],
            "codec_type": "AUTO",
            "http_filters": [
              {
                "name": "envoy.gzip"
              },
              {
                "name": "envoy.router"
              }
            ],
            "rds": {
              "config_source": {
                "api_config_source": {
                  "api_type": "REST",
                  "cluster_names": [
                    "controlplane"
                  ],
                  "refresh_delay": "5s"
                }
              },
              "route_config_name": "service_instances_rds"
            },
            "stat_prefix": "backends"
          },
          "name": "envoy.http_connection_manager"
        }
      ],
      "tls_context": {
        "common_tls_context": {
          "tls_certificates": [
            {
              "certificate_chain": {
                "inline_string": "-----BEGIN CERTIFICATE-----"
              },
              "private_key": {
                "inline_string": "-----BEGIN PRIVATE KEY-----"
              }
            },
            {
              "certificate_chain": {
                "inline_string": "-----BEGIN CERTIFICATE-----"
              }
            },
            {
              "certificate_chain": {
                "inline_string": "-----BEGIN CERTIFICATE-----"
              }
            }
          ]
        }
      }
    }
  ]
}

Activity

  1. zuercher commented on Oct 17, 2018

    @zuercher
    Member

    Seems like this would happen with gRPC or file as the LDS source as well. And also in CDS for tls_context data in Cluster.

  2. PiotrSikora commented on Jan 7, 2019

    @PiotrSikora
    Contributor

    Private keys (and possibly other sensitive information) can be also leaked via /config_dump (I could swear there was a bug for it, but I cannot find it now).

    I imagine there should be a way to sanitize sensitive data at the protobuf level. @htuch any ideas?

  3. cetanu commented on Jan 7, 2019

    @cetanu
    Author

    @PiotrSikora , I found this acceptable only because I thought it's the intention to only expose this interface to administrators, since it also has the /quitquitquit endpoint that literally kills the process... Although it would be nice to hide these things. I haven't kept up to date with SDS (Secret Discovery Service) how is it handled with that? Still exposed?

  4. htuch commented on Jan 7, 2019

    @htuch
    Member

    @PiotrSikora I don't know if there is a standard way to do this in OSS protobuf today. It could be done as an annotation though, where we store encrypted data in-memory (and for the standard DebugString()), only making it available to C++ via additional accessor methods that a protoc plugin generates.

  5. terinjokes commented on Feb 14, 2019

    @terinjokes

    I just got bitten by this.

    I don't have the expectation that increasing the log level up one from the default would start exposing private key material. I don't see a reference to this behavior in the docs nor in the help text.

       -l <string>,  --log-level <string>
         Log levels:
         [trace][debug][info][warning][error][critical][off]
    
         Default is [info]
  6. htuch commented on Feb 14, 2019

    @htuch
    Member

    I agree that we should scrub private keys from the config dump and log messages. Turning up logging though is still going to be a minefield for PII and other data leakage, this should be expected; if you switch to trace level, you will start seeing data plane traffic unencrypted. This is WAI, we want to be able to debug at trace level, trace level shouldn't be used in production outside of very controlled debug scenarios.

  7. terinjokes commented on Feb 14, 2019

    @terinjokes

    @htuch I understand. I definitely expect things like this from trace. At debug we expected more logging around timings, memory pressures, and the like.

  8. htuch commented on Feb 14, 2019

    @htuch
    Member

    @terinjokes PRs welcome. My comment in #4757 (comment) is aspirational, I think we can just do some manual redaction of protos in config dump and debug log statements for now.

  9. stevesloka commented on May 6, 2019

    @stevesloka
    Member

    I'd like to help out here and see if I can send up a PR. Any notes or pointers to help get started? Should I start with just the config dump, then move from there with separate PR's?

  10. htuch commented on May 6, 2019

    @htuch
    Member

    @stevesloka I would advocate for having a sanitizeProto method that takes something like a Listener config that we're about to dump and redacts the keys. So, most call sites should have a single line change to wrap the dumped proto with this.

  11. stevesloka commented on May 8, 2019

    @stevesloka
    Member

    Do you have any other tips of where to integrate @htuch? I'm new to the code base and still digging through.

  12. htuch commented on May 9, 2019

    @htuch
    Member

    @stevesloka a good start would be to look at the uses of DebugString() for proto in grpc_mux_impl.cc. The main challenge there is it's dealing with generic protobuf Message; you'll need to downcast to the relevant protos to do scrubbing.

  13. stevesloka commented on May 22, 2019

    @stevesloka
    Member

    Hey @htuch, I'm not following where DebugString is used for the specific use case that this issue is trying to solve. I can see usages of this coming from util.cc, but I'm just not clear on the higher level approach to how we might fix this.

  14. 6 remaining items

  15. mattklein123 commented on Aug 26, 2019

    @mattklein123
    Member

    FWIW I think this is better suited to an annotation that we can then process and utilize in different ways including logging, tap, etc.

  16. incfly commented on Dec 11, 2019

    @incfly
    Contributor

    Hi folks, we're considering to contribute a workaround fix by hardcode traversal the listener/cluster/secrets, before the desired approach (proto annotation && reflection) landed. Thus the admin config dump interface won't be subjected to leak private key.

    Something like an utility function as void RedactSecurityData(protobuf::Message& message).

    WDTY? @htuch @mergeconflict

  17. mergeconflict commented on Dec 11, 2019

    @mergeconflict

    @incfly Funny timing... I actually just picked this back up. I have an implementation that's probably about halfway done. Let's chat tomorrow?

  18. incfly commented on Dec 11, 2019

    @incfly
    Contributor
  19. terinjokes commented on Dec 11, 2019

    @terinjokes

    @incfly @mergeconflict Awesome. We were just talking about this bug today, since it effects are ability to debug some issues.

  20. mattklein123 commented on Dec 11, 2019

    @mattklein123
    Member

    FWIW I feel like we have enough code in the codebase now dealing with annotations, parsing, etc. that it shouldn't be that hard to do this "the right way."

  21. mergeconflict commented on Dec 11, 2019

    @mergeconflict

    I have a PR up: #9315. It still needs some work, and doesn't fix this issue yet (currently it only redacts SSL certs in the admin config_dump) but I intend to apply it to this as well.

  22. incfly commented on Dec 11, 2019

    @incfly
    Contributor

    Thanks @mergeconflict ! Yeah, #9315 will satisfy our needs. I'll follow up on that PR.

  23. mergeconflict commented on Jan 15, 2020

    @mergeconflict

    I just took another look at this... I think this might be trickier than just inserting a call to MessageUtil::redact() before logging, because the error message is actually coming from protoc-gen-validate. That looks like:

    bool Validate(const ::envoy::WhateverMessage& m, pgv::ValidationMsg* err);

    I can't think of an obvious way to have pgv redact messages before serializing and populating the error... Any suggestions @mattklein123 @htuch?

  24. mattklein123 commented on Jan 15, 2020

    @mattklein123
    Member

    I can't think of an obvious way to have pgv redact messages before serializing and populating the error... Any suggestions @mattklein123 @htuch?

    The only way that I can think of is to have PGV become aware of the redaction annotation, which seems like a reasonable thing to work towards?

  25. htuch commented on Jan 16, 2020

    @htuch
    Member

    It could be fixed in PGV. In the interim, we could redact before passing to PGV. Then we continue to use the original message. The main downside there is you then skip PGV of redacted fields.

  26. mergeconflict commented on Jan 17, 2020

    @mergeconflict

    It could be fixed in PGV. In the interim, we could redact before passing to PGV. Then we continue to use the original message. The main downside there is you then skip PGV of redacted fields.

    @htuch I would guess the main downside to that approach is the runtime cost of preemptively redacting everything (making a copy and iterating over it). There could also be cases where a PGV annotation expresses some constraint that is violated by redaction.

  27. htuch commented on Jan 17, 2020

    @htuch
    Member

    @mergeconflict yep, I think the long term solution is fixing in PGV.

  28. cetanu commented on Oct 15, 2023

    @cetanu
    Author

    I think this has been fixed??? I'm going to close this and if needed we can reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions