Skip to content

Commit a16040e

Browse files
committed
Fix apiserver scraper TLS config
1 parent e490516 commit a16040e

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

charts/amazon-cloudwatch-observability/templates/linux/_otel-container-insights-cluster-scraper-config.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ receivers:
1717
tls_config:
1818
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
1919
insecure_skip_verify: false
20+
{{- if eq .Values.k8sMode "AKS" }}
21+
# Endpoints SD dials the apiserver by IP. On AKS the managed control-plane endpoint IP is
22+
# not in the serving cert's SANs (only DNS names + the ClusterIP are), so verify against a
23+
# DNS SAN instead. On EKS the endpoint IPs are in the SANs, so this is not needed there.
24+
server_name: kubernetes.default.svc
25+
{{- end }}
2026
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
2127
kubernetes_sd_configs:
2228
- role: endpoints

integration-tests/amazon-cloudwatch-observability/terraform/minikube/scenarios/default/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ resource "null_resource" "validator" {
1111
depends_on = [module.base.helm_release]
1212

1313
provisioner "local-exec" {
14-
command = "go test ${var.test_dir} -v -run=TestDefault"
14+
# Anchored so it does not also match TestDefault*.
15+
command = "go test ${var.test_dir} -v -run='TestDefault$'"
1516
}
1617
}
1718

integration-tests/amazon-cloudwatch-observability/validations/minikube/scenarios/aks_otel_container_insights_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func TestAKSOtelContainerInsights(t *testing.T) {
7676
t.Run("WebhookEnforcerDisabled", func(t *testing.T) {
7777
validateAKSWebhookEnforcerDisabled(t, k8sClient)
7878
})
79+
t.Run("ApiserverTLSServerName", func(t *testing.T) {
80+
validateAKSApiserverTLSServerName(t, agentMap)
81+
})
7982

8083
t.Log("AKS OTEL Container Insights scenario validation passed")
8184
}
@@ -155,6 +158,18 @@ func validateOTELConfigRoutingAKS(t *testing.T, agentMap map[string]unstructured
155158
}
156159
}
157160

161+
// validateAKSApiserverTLSServerName checks the apiserver scrape verifies TLS against a DNS SAN. On
162+
// AKS, endpoints SD dials the managed control-plane IP, which is absent from the serving cert's SANs,
163+
// so without server_name every scrape fails TLS and no apiserver metrics reach CloudWatch.
164+
func validateAKSApiserverTLSServerName(t *testing.T, agentMap map[string]unstructured.Unstructured) {
165+
scraper := otelConfigOf(t, agentMap, "cloudwatch-agent-cluster-scraper")
166+
if scraper == "" {
167+
return
168+
}
169+
assert.True(t, strings.Contains(scraper, "server_name: kubernetes.default.svc"),
170+
"cluster-scraper otelConfig should set server_name for the apiserver TLS scrape on AKS")
171+
}
172+
158173
// validateAKSServiceAttributes checks the AKS-gated service.*/deployment.environment.name are on the
159174
// node agent but NOT the cluster-scraper (scraper metrics describe other workloads, not its own).
160175
func validateAKSServiceAttributes(t *testing.T, agentMap map[string]unstructured.Unstructured) {

0 commit comments

Comments
 (0)