Skip to content

Commit b11f997

Browse files
committed
fix: TLS skip validation
1 parent da2ce46 commit b11f997

3 files changed

Lines changed: 57 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,26 @@ All notable changes to TelemetryFlow Agent will be documented in this file.
2424
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.1/),
2525
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
2626

27-
## [1.1.9] - 2026-03-12
27+
## [1.1.9] - 2026-03-15
2828

2929
### Added
3030

31+
- **Extended K8s Metrics Config Fields** (`collectors.kubernetes`): Five new config fields enabling TFO Agent to replace Prometheus, kube-state-metrics, and cAdvisor as external dependencies
32+
- `apiserver_metrics: true` — Scrape kube-apiserver `/metrics` endpoint for request rates, latency, error rates, work queue depth, CPU/memory usage
33+
- `coredns_metrics: true` — Scrape CoreDNS `/metrics` endpoint for DNS request rates, cache hit rates, duration p99, upstream requests, error rates
34+
- `coredns_service` — CoreDNS service address (default: `kube-dns.kube-system.svc.cluster.local:9153`)
35+
- `container_extended_metrics: true` — Collect per-container CPU throttling, memory working set, and OOM kill detection via Kubelet `/stats/summary` and cAdvisor
36+
- `pv_io_stats: true` — Collect PersistentVolume usage, IOPS, and throughput from Kubelet volume stats API
37+
- **cAdvisor TLS & Auth Support** (`internal/collector/cadvisor/cadvisor.go`): cAdvisor collector now supports HTTPS kubelet endpoints
38+
- `InsecureSkipVerify` config field to skip TLS certificate verification for self-signed kubelet certs
39+
- `BearerTokenPath` config field for custom ServiceAccount token path (auto-detected from standard K8s mount if empty)
40+
- Auto-reads bearer token from `/var/run/secrets/kubernetes.io/serviceaccount/token` for kubelet authentication
41+
- **RBAC Updates** (`deploy/helm/`, `deploy/kubernetes/`): Added missing permissions for new collectors
42+
- `pods/log` — required for pod log collection
43+
- `poddisruptionbudgets` (policy API group) — required for PDB collector
44+
- `endpointslices` (discovery.k8s.io) — replaces deprecated v1 Endpoints
45+
- `/metrics/cadvisor` non-resource URL — required for cAdvisor scraping
46+
3147
- **Prometheus Remote Write Receiver (`internal/receiver/remotewrite/`)**: New push-based ingestion path accepting Prometheus `remote_write` traffic directly
3248
- `receiver.go`: HTTP server lifecycle with graceful start/stop and configurable port
3349
- `handler.go`: HTTP request handler — snappy decompression + protobuf decode, content-type validation
@@ -47,6 +63,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4763

4864
### Fixed
4965

66+
- **Config env var expansion** (`internal/config/loader.go`): Viper-based config loader now calls `os.ExpandEnv()` on YAML content before parsing, resolving `${VAR}` placeholders in config values (e.g., `${NODE_IP}` in cAdvisor endpoint). Previously, env var references in config values were passed as literal strings, causing URL parse failures
67+
- **cAdvisor kubelet HTTPS** (`internal/collector/cadvisor/cadvisor.go`): HTTP client now respects `insecure_skip_verify` config and includes ServiceAccount bearer token in requests. Previously, HTTPS kubelet endpoints failed with `x509: certificate signed by unknown authority` and `403 Forbidden`
5068
- **eBPF build constraints**: Restored `//go:build linux` and `//go:build !linux` constraints to all 9 eBPF package files after bulk header replacement had stripped them
5169
- `types.go`, `gen.go`, `loader.go`, `helpers.go`, `config_linux.go`, `linux.go`, `hubble_linux.go``//go:build linux`
5270
- `linux_other.go`, `hubble_other.go``//go:build !linux`
@@ -55,6 +73,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5573

5674
- **Helm chart path**: Renamed `deploy/helm/tfo-agent/``deploy/helm/telemetryflow-agent/` for naming consistency with other TelemetryFlow Helm charts
5775
- **Platform monolith configs** (`config/tfo-agent/`): All three deployment configs (`tfo-agent.yaml`, `tfo-agent.k8s.yaml`, `tfo-agent.container.yaml`) updated with KSM gap fields and `remote_write_receiver` section
76+
- **All config files updated** (`configs/`, `deploy/`): Added extended K8s metrics fields (`apiserver_metrics`, `coredns_metrics`, `container_extended_metrics`, `pv_io_stats`) to all config variants — `configs/tfo-agent.yaml`, `configs/tfo-agent.default.yaml`, `configs/tfo-agent-one-for-all.yaml`, `deploy/helm/values.yaml`, `deploy/helm/values-one-for-all.yaml`, `deploy/kubernetes/configmap.yaml`
5877

5978
## [1.1.8] - 2026-03-09
6079

internal/collector/cadvisor/cadvisor.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ package cadvisor
2020

2121
import (
2222
"context"
23+
"crypto/tls"
2324
"fmt"
2425
"io"
2526
"net/http"
27+
"os"
2628
"strings"
2729
"sync"
2830
"time"
@@ -40,9 +42,10 @@ const collectorName = "cadvisor"
4042
// CAdvisorCollector scrapes container metrics from a cAdvisor Prometheus endpoint.
4143
// It implements the collector.Collector interface.
4244
type CAdvisorCollector struct {
43-
cfg config.CAdvisorCollectorConfig
44-
logger *zap.Logger
45-
client *http.Client
45+
cfg config.CAdvisorCollectorConfig
46+
logger *zap.Logger
47+
client *http.Client
48+
bearerToken string
4649

4750
mu sync.RWMutex
4851
running bool
@@ -64,13 +67,29 @@ func NewCAdvisorCollector(cfg config.CAdvisorCollectorConfig, logger *zap.Logger
6467
cfg.Timeout = 10 * time.Second
6568
}
6669

70+
// Build HTTP transport with optional TLS skip for kubelet HTTPS endpoints
71+
transport := http.DefaultTransport.(*http.Transport).Clone()
72+
if cfg.InsecureSkipVerify {
73+
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} //nolint:gosec // user-configured for kubelet self-signed certs
74+
}
75+
76+
// Auto-detect ServiceAccount bearer token for kubelet auth
77+
bearerToken := ""
78+
tokenPath := cfg.BearerTokenPath
79+
if tokenPath == "" {
80+
tokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token"
81+
}
82+
if tokenBytes, err := os.ReadFile(tokenPath); err == nil {
83+
bearerToken = strings.TrimSpace(string(tokenBytes))
84+
logger.Named(collectorName).Info("Using ServiceAccount bearer token for kubelet auth")
85+
}
86+
6787
return &CAdvisorCollector{
68-
cfg: cfg,
69-
logger: logger.Named(collectorName),
70-
client: &http.Client{
71-
Timeout: cfg.Timeout,
72-
},
73-
stopChan: make(chan struct{}),
88+
cfg: cfg,
89+
logger: logger.Named(collectorName),
90+
client: &http.Client{Timeout: cfg.Timeout, Transport: transport},
91+
bearerToken: bearerToken,
92+
stopChan: make(chan struct{}),
7493
}
7594
}
7695

@@ -155,6 +174,9 @@ func (c *CAdvisorCollector) Collect(ctx context.Context) ([]collector.Metric, er
155174
return nil, fmt.Errorf("cadvisor: create request: %w", err)
156175
}
157176
req.Header.Set("Accept", string(expfmt.NewFormat(expfmt.TypeTextPlain)))
177+
if c.bearerToken != "" {
178+
req.Header.Set("Authorization", "Bearer "+c.bearerToken)
179+
}
158180

159181
resp, err := c.client.Do(req)
160182
if err != nil {

internal/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ type CAdvisorCollectorConfig struct {
259259
// MetricNames is an optional allowlist of metric names to collect (empty = all container_*/machine_*)
260260
MetricNames []string `mapstructure:"metric_names"`
261261

262+
// InsecureSkipVerify disables TLS certificate verification for kubelet HTTPS endpoints
263+
InsecureSkipVerify bool `mapstructure:"insecure_skip_verify"`
264+
265+
// BearerTokenPath is the path to the ServiceAccount token for kubelet auth (auto-detected if empty)
266+
BearerTokenPath string `mapstructure:"bearer_token_path"`
267+
262268
// Labels are additional labels applied to all cAdvisor metrics
263269
Labels map[string]string `mapstructure:"labels"`
264270
}

0 commit comments

Comments
 (0)