Skip to content

Commit d5d8360

Browse files
committed
Add TLS support to auto-instrumentation
Signed-off-by: Pavol Loffay <[email protected]>
1 parent 65b40cb commit d5d8360

27 files changed

+1056
-19
lines changed

.chloggen/inst-tls.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: auto-instrumentation
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Add support for specifying exporter TLS certificates in auto-instrumentation.
9+
10+
# One or more tracking issues related to the change
11+
issues: [3338]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
Now Instrumentation CR supports specifying TLS certificates for exporter:
18+
```yaml
19+
spec:
20+
exporter:
21+
endpoint: https://otel-collector:4317
22+
tls:
23+
secretName: otel-tls-certs
24+
configMapName: otel-ca-bundle
25+
# otel-ca-bundle
26+
ca: ca.crt
27+
# present in otel-tls-certs
28+
cert: tls.crt
29+
# present in otel-tls-certs
30+
key: tls.key
31+
```
32+
33+
* Propagating secrets across namespaces can be done with https://github.com/EmberStack/kubernetes-reflector or https://github.com/zakkg3/ClusterSecret
34+
* Restarting workloads on certificate renewal can be done with https://github.com/stakater/Reloader or https://github.com/wave-k8s/wave

apis/v1alpha1/instrumentation_types.go

+29
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,37 @@ type Resource struct {
9797
// Exporter defines OTLP exporter configuration.
9898
type Exporter struct {
9999
// Endpoint is address of the collector with OTLP endpoint.
100+
// If the endpoint defines https:// scheme TLS has to be specified.
100101
// +optional
101102
Endpoint string `json:"endpoint,omitempty"`
103+
104+
// TLS defines certificates for TLS.
105+
// TLS needs to be enabled by specifying https:// scheme in the Endpoint.
106+
TLS *TLS `json:"tls,omitempty"`
107+
}
108+
109+
// TLS defines TLS configuration for exporter.
110+
type TLS struct {
111+
// SecretName defines secret name that will be used to configure TLS on the exporter.
112+
// It is user responsibility to create the secret in the namespace of the workload.
113+
// The secret must contain client certificate (Cert) and private key (Key).
114+
// The CA certificate might be defined in the secret or in the config map.
115+
SecretName string `json:"secretName,omitempty"`
116+
117+
// ConfigMapName defines configmap name with CA certificate. If it is not defined CA certificate will be
118+
// used from the secret defined in SecretName.
119+
ConfigMapName string `json:"configMapName,omitempty"`
120+
121+
// CA defines the key of certificate (e.g. ca.crt) in the configmap map, secret or absolute path to a certificate.
122+
// The absolute path can be used when certificate is already present on the workload filesystem e.g.
123+
// /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
124+
CA string `json:"ca,omitempty"`
125+
// Cert defines the key (e.g. tls.crt) of the client certificate in the secret or absolute path to a certificate.
126+
// The absolute path can be used when certificate is already present on the workload filesystem.
127+
Cert string `json:"cert,omitempty"`
128+
// Key defines a key (e.g. tls.key) of the private key in the secret or absolute path to a certificate.
129+
// The absolute path can be used when certificate is already present on the workload filesystem.
130+
Key string `json:"key,omitempty"`
102131
}
103132

104133
// Sampler defines sampling configuration.

apis/v1alpha1/instrumentation_webhook.go

+8
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ func (w InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings
236236
default:
237237
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.Sampler.Type)
238238
}
239+
240+
if r.Spec.Exporter.TLS != nil {
241+
tls := r.Spec.Exporter.TLS
242+
if tls.Key != "" && tls.Cert == "" || tls.Cert != "" && tls.Key == "" {
243+
warnings = append(warnings, "both exporter.tls.key and exporter.tls.cert mut be set")
244+
}
245+
}
246+
239247
return warnings, nil
240248
}
241249

apis/v1alpha1/instrumentation_webhook_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,40 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
113113
},
114114
},
115115
},
116+
{
117+
name: "tls cert set but missing key",
118+
inst: Instrumentation{
119+
Spec: InstrumentationSpec{
120+
Sampler: Sampler{
121+
Type: ParentBasedTraceIDRatio,
122+
Argument: "0.99",
123+
},
124+
Exporter: Exporter{
125+
TLS: &TLS{
126+
Cert: "cert",
127+
},
128+
},
129+
},
130+
},
131+
warnings: []string{"both exporter.tls.key and exporter.tls.cert mut be set"},
132+
},
133+
{
134+
name: "tls key set but missing cert",
135+
inst: Instrumentation{
136+
Spec: InstrumentationSpec{
137+
Sampler: Sampler{
138+
Type: ParentBasedTraceIDRatio,
139+
Argument: "0.99",
140+
},
141+
Exporter: Exporter{
142+
TLS: &TLS{
143+
Key: "key",
144+
},
145+
},
146+
},
147+
},
148+
warnings: []string{"both exporter.tls.key and exporter.tls.cert mut be set"},
149+
},
116150
}
117151

118152
for _, test := range tests {

apis/v1alpha1/zz_generated.deepcopy.go

+21-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ metadata:
9999
categories: Logging & Tracing,Monitoring
100100
certified: "false"
101101
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
102-
createdAt: "2024-10-08T09:52:53Z"
102+
createdAt: "2024-10-09T17:08:59Z"
103103
description: Provides the OpenTelemetry components, including the Collector
104104
operators.operatorframework.io/builder: operator-sdk-v1.29.0
105105
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3

bundle/community/manifests/opentelemetry.io_instrumentations.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,19 @@ spec:
409409
properties:
410410
endpoint:
411411
type: string
412+
tls:
413+
properties:
414+
ca:
415+
type: string
416+
cert:
417+
type: string
418+
configMapName:
419+
type: string
420+
key:
421+
type: string
422+
secretName:
423+
type: string
424+
type: object
412425
type: object
413426
go:
414427
properties:

bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ metadata:
9999
categories: Logging & Tracing,Monitoring
100100
certified: "false"
101101
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
102-
createdAt: "2024-10-08T09:52:57Z"
102+
createdAt: "2024-10-09T17:08:59Z"
103103
description: Provides the OpenTelemetry components, including the Collector
104104
operators.operatorframework.io/builder: operator-sdk-v1.29.0
105105
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3

bundle/openshift/manifests/opentelemetry.io_instrumentations.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,19 @@ spec:
409409
properties:
410410
endpoint:
411411
type: string
412+
tls:
413+
properties:
414+
ca:
415+
type: string
416+
cert:
417+
type: string
418+
configMapName:
419+
type: string
420+
key:
421+
type: string
422+
secretName:
423+
type: string
424+
type: object
412425
type: object
413426
go:
414427
properties:

config/crd/bases/opentelemetry.io_instrumentations.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,19 @@ spec:
407407
properties:
408408
endpoint:
409409
type: string
410+
tls:
411+
properties:
412+
ca:
413+
type: string
414+
cert:
415+
type: string
416+
configMapName:
417+
type: string
418+
key:
419+
type: string
420+
secretName:
421+
type: string
422+
type: object
410423
type: object
411424
go:
412425
properties:

docs/api.md

+74-1
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,80 @@ Exporter defines exporter configuration.
16251625
<td><b>endpoint</b></td>
16261626
<td>string</td>
16271627
<td>
1628-
Endpoint is address of the collector with OTLP endpoint.<br/>
1628+
Endpoint is address of the collector with OTLP endpoint.
1629+
If the endpoint defines https:// scheme TLS has to be specified.<br/>
1630+
</td>
1631+
<td>false</td>
1632+
</tr><tr>
1633+
<td><b><a href="#instrumentationspecexportertls">tls</a></b></td>
1634+
<td>object</td>
1635+
<td>
1636+
TLS defines certificates for TLS.
1637+
TLS needs to be enabled by specifying https:// scheme in the Endpoint.<br/>
1638+
</td>
1639+
<td>false</td>
1640+
</tr></tbody>
1641+
</table>
1642+
1643+
1644+
### Instrumentation.spec.exporter.tls
1645+
<sup><sup>[↩ Parent](#instrumentationspecexporter)</sup></sup>
1646+
1647+
1648+
1649+
TLS defines certificates for TLS.
1650+
TLS needs to be enabled by specifying https:// scheme in the Endpoint.
1651+
1652+
<table>
1653+
<thead>
1654+
<tr>
1655+
<th>Name</th>
1656+
<th>Type</th>
1657+
<th>Description</th>
1658+
<th>Required</th>
1659+
</tr>
1660+
</thead>
1661+
<tbody><tr>
1662+
<td><b>ca</b></td>
1663+
<td>string</td>
1664+
<td>
1665+
CA defines the key of certificate (e.g. ca.crt) in the configmap map, secret or absolute path to a certificate.
1666+
The absolute path can be used when certificate is already present on the workload filesystem e.g.
1667+
/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt<br/>
1668+
</td>
1669+
<td>false</td>
1670+
</tr><tr>
1671+
<td><b>cert</b></td>
1672+
<td>string</td>
1673+
<td>
1674+
Cert defines the key (e.g. tls.crt) of the client certificate in the secret or absolute path to a certificate.
1675+
The absolute path can be used when certificate is already present on the workload filesystem.<br/>
1676+
</td>
1677+
<td>false</td>
1678+
</tr><tr>
1679+
<td><b>configMapName</b></td>
1680+
<td>string</td>
1681+
<td>
1682+
ConfigMapName defines configmap name with CA certificate. If it is not defined CA certificate will be
1683+
used from the secret defined in SecretName.<br/>
1684+
</td>
1685+
<td>false</td>
1686+
</tr><tr>
1687+
<td><b>key</b></td>
1688+
<td>string</td>
1689+
<td>
1690+
Key defines a key (e.g. tls.key) of the private key in the secret or absolute path to a certificate.
1691+
The absolute path can be used when certificate is already present on the workload filesystem.<br/>
1692+
</td>
1693+
<td>false</td>
1694+
</tr><tr>
1695+
<td><b>secretName</b></td>
1696+
<td>string</td>
1697+
<td>
1698+
SecretName defines secret name that will be used to configure TLS on the exporter.
1699+
It is user responsibility to create the secret in the namespace of the workload.
1700+
The secret must contain client certificate (Cert) and private key (Key).
1701+
The CA certificate might be defined in the secret or in the config map.<br/>
16291702
</td>
16301703
<td>false</td>
16311704
</tr></tbody>

pkg/constants/env.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
package constants
1616

1717
const (
18-
EnvOTELServiceName = "OTEL_SERVICE_NAME"
19-
EnvOTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
20-
EnvOTELResourceAttrs = "OTEL_RESOURCE_ATTRIBUTES"
21-
EnvOTELPropagators = "OTEL_PROPAGATORS"
22-
EnvOTELTracesSampler = "OTEL_TRACES_SAMPLER"
23-
EnvOTELTracesSamplerArg = "OTEL_TRACES_SAMPLER_ARG"
18+
EnvOTELServiceName = "OTEL_SERVICE_NAME"
19+
EnvOTELResourceAttrs = "OTEL_RESOURCE_ATTRIBUTES"
20+
EnvOTELPropagators = "OTEL_PROPAGATORS"
21+
EnvOTELTracesSampler = "OTEL_TRACES_SAMPLER"
22+
EnvOTELTracesSamplerArg = "OTEL_TRACES_SAMPLER_ARG"
23+
24+
EnvOTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
25+
EnvOTELExporterCertificate = "OTEL_EXPORTER_OTLP_CERTIFICATE"
26+
EnvOTELExporterClientCertificate = "OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE"
27+
EnvOTELExporterClientKey = "OTEL_EXPORTER_OTLP_CLIENT_KEY"
2428

2529
InstrumentationPrefix = "instrumentation.opentelemetry.io/"
2630
AnnotationDefaultAutoInstrumentationJava = InstrumentationPrefix + "default-auto-instrumentation-java-image"

0 commit comments

Comments
 (0)