mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 21:35:52 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
93 lines
2.5 KiB
Go
93 lines
2.5 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package troubleshoot
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
envoy_admin_v3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
|
|
"github.com/hashicorp/consul/troubleshoot/validate"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
)
|
|
|
|
func (t *Troubleshoot) validateCerts(certs *envoy_admin_v3.Certificates) validate.Messages {
|
|
|
|
var certMessages validate.Messages
|
|
// TODO: we can probably warn if the expiration date is close
|
|
now := time.Now()
|
|
|
|
if certs == nil {
|
|
msg := validate.Message{
|
|
Success: false,
|
|
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",
|
|
},
|
|
}
|
|
return []validate.Message{msg}
|
|
}
|
|
|
|
if len(certs.GetCertificates()) == 0 {
|
|
msg := validate.Message{
|
|
Success: false,
|
|
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",
|
|
},
|
|
}
|
|
return []validate.Message{msg}
|
|
}
|
|
|
|
for _, cert := range certs.GetCertificates() {
|
|
for _, cacert := range cert.GetCaCert() {
|
|
if now.After(cacert.GetExpirationTime().AsTime()) {
|
|
msg := validate.Message{
|
|
Success: false,
|
|
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",
|
|
},
|
|
}
|
|
certMessages = append(certMessages, msg)
|
|
}
|
|
|
|
}
|
|
for _, cc := range cert.GetCertChain() {
|
|
if now.After(cc.GetExpirationTime().AsTime()) {
|
|
msg := validate.Message{
|
|
Success: false,
|
|
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",
|
|
},
|
|
}
|
|
certMessages = append(certMessages, msg)
|
|
}
|
|
}
|
|
}
|
|
return certMessages
|
|
}
|
|
|
|
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
|
|
}
|