Skip to content

Commit

Permalink
Add TLS support to auto-instrumentation
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay committed Oct 9, 2024
1 parent 65b40cb commit c414808
Show file tree
Hide file tree
Showing 15 changed files with 752 additions and 10 deletions.
30 changes: 30 additions & 0 deletions .chloggen/inst-tls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: auto-instrumentation

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for specifying exporter TLS certificates in auto-instrumentation.

# One or more tracking issues related to the change
issues: [3338]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Now Instrumentation CR supports specifying TLS certificates for exporter:
```yaml
spec:
exporter:
endpoint: https://otel-collector:4317
tls:
secretName: otel-tls-certs
ca: ca.crt
cert: tls.crt
key: tls.key
```
* Propagating secrets across namespaces can be done with https://github.com/EmberStack/kubernetes-reflector or https://github.com/zakkg3/ClusterSecret
* Restarting workloads on certificate renewal can be done with https://github.com/stakater/Reloader or https://github.com/wave-k8s/wave
28 changes: 28 additions & 0 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,36 @@ type Resource struct {
// Exporter defines OTLP exporter configuration.
type Exporter struct {
// Endpoint is address of the collector with OTLP endpoint.
// The TLS is enabled
// +optional
Endpoint string `json:"endpoint,omitempty"`

// TLS defines certificates for TLS.
// TLS needs to be enabled by specifying https:// scheme in the Endpoint.
TLS *TLS `json:"tls,omitempty"`
}

// TLS defines TLS configuration for exporter.
type TLS struct {
// SecretName defines secret name that will be used to configure TLS on the exporter.
// It is user responsibility to create the secret in the namespace of the workload.
// The secret should contain keys ca.crt, tls.key, tls.crt
SecretName string `json:"secretName,omitempty"`

// ConfigMapName defines configmap name with CA certificate. If it is not defined CA certificate will be
// used from the secret defined in SecretName.
ConfigMapName string `json:"configMapName,omitempty"`

// CA defines the key of certificate in the configmap map, secret or absolute path to a certificate.
// The absolute path can be used when certificate is already present on the workload filesystem e.g.
// /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
CA string `json:"ca,omitempty"`
// Cert defines the key of the client certificate in the secret or absolute path to a certificate.
// The absolute path can be used when certificate is already present on the workload filesystem.
Cert string `json:"cert,omitempty"`
// Key defines a key of the private key in the secret or absolute path to a certificate.
// The absolute path can be used when certificate is already present on the workload filesystem.
Key string `json:"key,omitempty"`
}

// Sampler defines sampling configuration.
Expand Down
22 changes: 21 additions & 1 deletion apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-10-08T09:52:53Z"
createdAt: "2024-10-09T17:08:59Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
13 changes: 13 additions & 0 deletions bundle/community/manifests/opentelemetry.io_instrumentations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,19 @@ spec:
properties:
endpoint:
type: string
tls:
properties:
ca:
type: string
cert:
type: string
configMapName:
type: string
key:
type: string
secretName:
type: string
type: object
type: object
go:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-10-08T09:52:57Z"
createdAt: "2024-10-09T17:08:59Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
13 changes: 13 additions & 0 deletions bundle/openshift/manifests/opentelemetry.io_instrumentations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,19 @@ spec:
properties:
endpoint:
type: string
tls:
properties:
ca:
type: string
cert:
type: string
configMapName:
type: string
key:
type: string
secretName:
type: string
type: object
type: object
go:
properties:
Expand Down
13 changes: 13 additions & 0 deletions config/crd/bases/opentelemetry.io_instrumentations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ spec:
properties:
endpoint:
type: string
tls:
properties:
ca:
type: string
cert:
type: string
configMapName:
type: string
key:
type: string
secretName:
type: string
type: object
type: object
go:
properties:
Expand Down
66 changes: 65 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,71 @@ Exporter defines exporter configuration.
<td><b>endpoint</b></td>
<td>string</td>
<td>
Endpoint is address of the collector with OTLP endpoint.<br/>
Endpoint is address of the collector with OTLP endpoint.
The TLS is enabled<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#instrumentationspecexportertls">tls</a></b></td>
<td>object</td>
<td>
TLS defines certificates for TLS.
TLS needs to be enabled by specifying https:// scheme in the Endpoint.<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### Instrumentation.spec.exporter.tls
<sup><sup>[↩ Parent](#instrumentationspecexporter)</sup></sup>



TLS defines certificates for TLS.
TLS needs to be enabled by specifying https:// scheme in the Endpoint.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>ca</b></td>
<td>string</td>
<td>
CA defines the key of certificate in the secret or absolute path to a certificate.
The absolute path can be used when certificate is already present on the workload filesystem e.g.
/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>cert</b></td>
<td>string</td>
<td>
Cert defines the key of the client certificate in the secret or absolute path to a certificate.
The absolute path can be used when certificate is already present on the workload filesystem.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>key</b></td>
<td>string</td>
<td>
Key defines a key of the private key in the secret or absolute path to a certificate.
The absolute path can be used when certificate is already present on the workload filesystem.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>secretName</b></td>
<td>string</td>
<td>
SecretName defines a secret name that will be used to configure TLS on the exporter.
It is user responsibility to create the secret in the namespace of the workload.
The secret should contain keys ca.crt, tls.key, tls.crt<br/>
</td>
<td>false</td>
</tr></tbody>
Expand Down
16 changes: 10 additions & 6 deletions pkg/constants/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
package constants

const (
EnvOTELServiceName = "OTEL_SERVICE_NAME"
EnvOTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
EnvOTELResourceAttrs = "OTEL_RESOURCE_ATTRIBUTES"
EnvOTELPropagators = "OTEL_PROPAGATORS"
EnvOTELTracesSampler = "OTEL_TRACES_SAMPLER"
EnvOTELTracesSamplerArg = "OTEL_TRACES_SAMPLER_ARG"
EnvOTELServiceName = "OTEL_SERVICE_NAME"
EnvOTELResourceAttrs = "OTEL_RESOURCE_ATTRIBUTES"
EnvOTELPropagators = "OTEL_PROPAGATORS"
EnvOTELTracesSampler = "OTEL_TRACES_SAMPLER"
EnvOTELTracesSamplerArg = "OTEL_TRACES_SAMPLER_ARG"

EnvOTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
EnvOTELExporterCertificate = "OTEL_EXPORTER_OTLP_CERTIFICATE"
EnvOTELExporterClientCertificate = "OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE"
EnvOTELExporterClientKey = "OTEL_EXPORTER_OTLP_CLIENT_KEY"

InstrumentationPrefix = "instrumentation.opentelemetry.io/"
AnnotationDefaultAutoInstrumentationJava = InstrumentationPrefix + "default-auto-instrumentation-java-image"
Expand Down
Loading

0 comments on commit c414808

Please sign in to comment.