2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-02-02 22:24:18 +00:00
|
|
|
package troubleshoot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
envoy_admin_v3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
|
2023-02-08 21:03:15 +00:00
|
|
|
"github.com/hashicorp/consul/troubleshoot/validate"
|
2023-02-02 22:24:18 +00:00
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
|
|
)
|
|
|
|
|
2023-02-08 21:03:15 +00:00
|
|
|
func (t *Troubleshoot) validateCerts(certs *envoy_admin_v3.Certificates) validate.Messages {
|
2023-02-02 22:24:18 +00:00
|
|
|
|
2023-02-08 21:03:15 +00:00
|
|
|
var certMessages validate.Messages
|
2023-02-02 22:24:18 +00:00
|
|
|
// TODO: we can probably warn if the expiration date is close
|
|
|
|
now := time.Now()
|
|
|
|
|
2023-02-07 17:58:00 +00:00
|
|
|
if certs == nil {
|
2023-02-08 21:03:15 +00:00
|
|
|
msg := validate.Message{
|
|
|
|
Success: false,
|
2023-02-17 15:43:05 +00:00
|
|
|
Message: "Certificate object is nil in the proxy configuration",
|
|
|
|
PossibleActions: []string{
|
|
|
|
"Check the logs of the Consul agent configuring the local proxy and ensure XDS updates are being sent to the proxy",
|
|
|
|
},
|
2023-02-08 21:03:15 +00:00
|
|
|
}
|
|
|
|
return []validate.Message{msg}
|
2023-02-07 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(certs.GetCertificates()) == 0 {
|
2023-02-08 21:03:15 +00:00
|
|
|
msg := validate.Message{
|
|
|
|
Success: false,
|
2023-02-17 15:43:05 +00:00
|
|
|
Message: "No certificates found",
|
|
|
|
PossibleActions: []string{
|
|
|
|
"Check the logs of the Consul agent configuring the local proxy and ensure XDS updates are being sent to the proxy",
|
|
|
|
},
|
2023-02-08 21:03:15 +00:00
|
|
|
}
|
|
|
|
return []validate.Message{msg}
|
2023-02-07 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-02 22:24:18 +00:00
|
|
|
for _, cert := range certs.GetCertificates() {
|
|
|
|
for _, cacert := range cert.GetCaCert() {
|
|
|
|
if now.After(cacert.GetExpirationTime().AsTime()) {
|
2023-02-08 21:03:15 +00:00
|
|
|
msg := validate.Message{
|
|
|
|
Success: false,
|
2023-02-17 15:43:05 +00:00
|
|
|
Message: "CA certificate is expired",
|
|
|
|
PossibleActions: []string{
|
|
|
|
"Check the logs of the Consul agent configuring the local proxy and ensure XDS updates are being sent to the proxy",
|
|
|
|
},
|
2023-02-08 21:03:15 +00:00
|
|
|
}
|
|
|
|
certMessages = append(certMessages, msg)
|
2023-02-02 22:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, cc := range cert.GetCertChain() {
|
|
|
|
if now.After(cc.GetExpirationTime().AsTime()) {
|
2023-02-08 21:03:15 +00:00
|
|
|
msg := validate.Message{
|
|
|
|
Success: false,
|
2023-02-17 15:43:05 +00:00
|
|
|
Message: "Certificate chain is expired",
|
|
|
|
PossibleActions: []string{
|
|
|
|
"Check the logs of the Consul agent configuring the local proxy and ensure XDS updates are being sent to the proxy",
|
|
|
|
},
|
2023-02-08 21:03:15 +00:00
|
|
|
}
|
|
|
|
certMessages = append(certMessages, msg)
|
2023-02-02 22:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-08 21:03:15 +00:00
|
|
|
return certMessages
|
2023-02-02 22:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Troubleshoot) getEnvoyCerts() (*envoy_admin_v3.Certificates, error) {
|
|
|
|
|
|
|
|
certsRaw, err := t.request("certs?format=json")
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error in requesting Envoy Admin API /certs endpoint: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
certs := &envoy_admin_v3.Certificates{}
|
|
|
|
|
|
|
|
unmarshal := &protojson.UnmarshalOptions{
|
|
|
|
DiscardUnknown: true,
|
|
|
|
}
|
|
|
|
err = unmarshal.Unmarshal(certsRaw, certs)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error in unmarshalling /certs response: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.envoyCerts = certs
|
|
|
|
return certs, nil
|
|
|
|
}
|