Skip to content

Commit 2d7edd0

Browse files
committed
Enable TLS for /metrics endpoint and add tests
Signed-off-by: peppi-lotta <[email protected]>
1 parent 7daab3e commit 2d7edd0

21 files changed

+1148
-10
lines changed

api/pkg/apis/projectcalico/v3/felixconfig.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,30 @@ type FelixConfigurationSpec struct {
442442
// set to false. This reduces the number of metrics reported, reducing Prometheus load. [Default: true]
443443
PrometheusWireGuardMetricsEnabled *bool `json:"prometheusWireGuardMetricsEnabled,omitempty"`
444444

445+
// MetricsTLSEnabled specifies whether TLS encryption is enabled for the /metrics endpoint.
446+
// If set to true, the metrics server will only be accessible over HTTPS. Default is false.
447+
MetricsTLSEnabled *bool `json:"metricsTLSEnabled,omitempty"`
448+
449+
// MetricsTLSCACertFile defines the absolute path to the TLS CA certificate file used for securing the /metrics endpoint.
450+
// This certificate must be valid and accessible by the calico-node process.
451+
MetricsTLSCACertFile *string `json:"metricsTLSCACertFile,omitempty"`
452+
453+
// MetricsTLSCertFile defines the absolute path to the TLS certificate file used for securing the /metrics endpoint.
454+
// This certificate must be valid and accessible by the calico-node process.
455+
MetricsTLSCertFile *string `json:"metricsTLSCertFile,omitempty"`
456+
457+
// MetricsTLSPrivateKeyFile defines the absolute path to the private key file corresponding to the TLS certificate
458+
// used for securing the /metrics endpoint. The private key must be valid and accessible by the calico-node process.
459+
MetricsTLSPrivateKeyFile *string `json:"metricsTLSPrivateKeyFile,omitempty"`
460+
461+
// MetricsClientAuthType specifies the client authentication type for the /metrics endpoint.
462+
// This determines how the server validates client certificates. Default is "NoClientCert".
463+
MetricsClientAuthType *string `json:"metricsClientAuthType,omitempty"`
464+
465+
// MetricsTLSMinVersion specifies the minimum TLS version allowed for the /metrics endpoint.
466+
// This ensures that only secure versions of TLS are used. Default is "1.3".
467+
MetricsTLSMinVersion *string `json:"metricsTLSMinVersion,omitempty"`
468+
445469
// FailsafeInboundHostPorts is a list of ProtoPort struct objects including UDP/TCP/SCTP ports and CIDRs that Felix will
446470
// allow incoming traffic to host endpoints on irrespective of the security policy. This is useful to avoid accidentally
447471
// cutting off a host with incorrect configuration. For backwards compatibility, if the protocol is not specified,

api/pkg/apis/projectcalico/v3/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pkg/openapi/generated.openapi.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

felix/config/config_params.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,13 @@ type Config struct {
404404
PrometheusProcessMetricsEnabled bool `config:"bool;true"`
405405
PrometheusWireGuardMetricsEnabled bool `config:"bool;true"`
406406

407+
MetricsTLSEnabled bool `config:"bool;false"`
408+
MetricsTLSCACertFile string `config:"string;"`
409+
MetricsTLSCertFile string `config:"string;"`
410+
MetricsTLSPrivateKeyFile string `config:"string;"`
411+
MetricsTLSMinVersion string `config:"oneof(TLS12,TLS13);TLS13"`
412+
MetricsClientAuthType string `config:"oneof(RequireAndVerifyClientCert,VerifyClientCertIfGiven,NoClientCert);NoClientCert"`
413+
407414
FailsafeInboundHostPorts []ProtoPort `config:"port-list;tcp:22,udp:68,tcp:179,tcp:2379,tcp:2380,tcp:5473,tcp:6443,tcp:6666,tcp:6667;die-on-fail"`
408415
FailsafeOutboundHostPorts []ProtoPort `config:"port-list;udp:53,udp:67,tcp:179,tcp:2379,tcp:2380,tcp:5473,tcp:6443,tcp:6666,tcp:6667;die-on-fail"`
409416

felix/daemon/daemon.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,22 @@ configRetry:
733733
gaugeHost.Set(1)
734734
prometheus.MustRegister(gaugeHost)
735735
dp.ConfigurePrometheusMetrics(configParams)
736-
go metricsserver.ServePrometheusMetricsForever(
737-
configParams.PrometheusMetricsHost,
738-
configParams.PrometheusMetricsPort,
739-
)
736+
if configParams.MetricsTLSEnabled == true {
737+
go metricsserver.ServePrometheusMetricsHTTPS(
738+
configParams.PrometheusMetricsHost,
739+
configParams.PrometheusMetricsPort,
740+
configParams.MetricsTLSCertFile,
741+
configParams.MetricsTLSPrivateKeyFile,
742+
configParams.MetricsTLSMinVersion,
743+
configParams.MetricsClientAuthType,
744+
configParams.MetricsTLSCACertFile,
745+
)
746+
} else {
747+
go metricsserver.ServePrometheusMetricsHTTP(
748+
configParams.PrometheusMetricsHost,
749+
configParams.PrometheusMetricsPort,
750+
)
751+
}
740752
}
741753

742754
// Register signal handlers to dump memory/CPU profiles.

felix/docs/config-params.json

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)