Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPORTER] Add OTLP HTTP SSL support #1793

Merged
merged 90 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
e3f1b17
[WIP] Implement OTLP HTTP SSL
marcalff Nov 23, 2022
236832d
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Nov 23, 2022
9f5c8aa
Format cleanup
marcalff Nov 23, 2022
82341ef
Cleanup
marcalff Nov 23, 2022
000e36d
Fixed windows build
marcalff Nov 24, 2022
29f2851
PROTOTYPE, investigating CURLOPT for SSL.
marcalff Nov 24, 2022
98cf4bb
Build cleanup
marcalff Nov 25, 2022
0a7d8a6
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Nov 25, 2022
8362479
Build cleanup
marcalff Nov 25, 2022
20d0e16
Implement CURLOPT for SSL.
marcalff Nov 25, 2022
e4afdb6
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Nov 28, 2022
41dfeb9
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Dec 1, 2022
461eec5
Work in progress
marcalff Dec 1, 2022
8c7e68e
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Dec 2, 2022
d25fae8
Work in progress
marcalff Dec 6, 2022
d5164e3
Work in progress, continued.
marcalff Dec 6, 2022
d686852
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Dec 7, 2022
cf6cb43
Used CAINFO
marcalff Dec 7, 2022
51eaad7
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Dec 7, 2022
eba3156
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Dec 11, 2022
21acc47
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Dec 13, 2022
956774a
Added doc, testing with SSL/TLS.
marcalff Dec 13, 2022
299d774
Implemented flag ssl_insecure_skip_verify.
marcalff Dec 13, 2022
d5a54fd
Format cleanup
marcalff Dec 13, 2022
e17c891
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Dec 13, 2022
1e96070
Code cleanup.
marcalff Dec 14, 2022
512e793
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Jan 2, 2023
becf5df
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Jan 4, 2023
9fc560d
Add TLS support - work in progress
marcalff Jan 4, 2023
09204ba
WIP
marcalff Jan 10, 2023
dfcd670
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Jan 16, 2023
e49eef5
SSL TLS
marcalff Jan 16, 2023
4c78897
TLS SSL, continued.
marcalff Jan 17, 2023
46c0662
WIP
marcalff Jan 17, 2023
7294163
Revert TLS 1.2 and 1.3 mix, fixed build breaks.
marcalff Jan 17, 2023
88e88e1
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Jan 17, 2023
7c3f50c
Format
marcalff Jan 17, 2023
4f301cb
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Jan 17, 2023
cb9e025
Resolved TLS 1.2 vs TLS 1.3 CIPHER.
marcalff Jan 18, 2023
cd8a172
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Jan 24, 2023
71e83c1
Implemented code review comments.
marcalff Jan 24, 2023
e0f91a0
Fixed GCC 12 warnings
marcalff Jan 24, 2023
e0bc8bb
Code cleanup for TLS version.
marcalff Jan 24, 2023
3b0663f
Code cleanup
marcalff Jan 25, 2023
3b31f96
Implemented test client (draft)
marcalff Jan 29, 2023
ab3bba8
format cleanup, maintainer build
marcalff Jan 29, 2023
1e2a610
add grpc in maintainer ci
marcalff Jan 29, 2023
2266202
CI
marcalff Jan 29, 2023
ea15e31
PROTOBUF_VERSION: 3.21.12
marcalff Jan 29, 2023
835fab4
Back to probuf 3.20.3,
marcalff Jan 29, 2023
72edc68
Do not check in cert, generate them (todo)
marcalff Jan 29, 2023
7b7009c
CI protobuf
marcalff Jan 29, 2023
05e4419
Merge branch 'open-telemetry:main' into fix_otlp_http_ssl_1402
marcalff Jan 29, 2023
beb6aa8
Protobuf tar name
marcalff Jan 29, 2023
9cc76a9
Run func test
marcalff Jan 29, 2023
f6fff95
Func test, continued.
marcalff Jan 29, 2023
65b72e3
Fix cfssl
marcalff Jan 29, 2023
25bc4f7
functional test client, continued.
marcalff Jan 30, 2023
e493ed1
Fixed build warnings.
marcalff Feb 1, 2023
8ed1403
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Feb 1, 2023
1a26090
Integration of functional tests to CI
marcalff Feb 2, 2023
e228383
Run both sync and async functional tests, added report in CI.
marcalff Feb 2, 2023
4458dac
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Feb 3, 2023
4074614
ASYNC tests failed,
marcalff Feb 4, 2023
62ce2e8
Implemented warnings on duration env var, when parsing failed.
marcalff Feb 8, 2023
750155e
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Feb 8, 2023
73eca29
Fixed copyright.
marcalff Feb 8, 2023
4074120
Fixed code review comments.
marcalff Feb 9, 2023
3bc586b
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Feb 13, 2023
34eff9e
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Feb 13, 2023
0f17600
Code cleanup
marcalff Feb 14, 2023
4437433
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Feb 17, 2023
cb9b6eb
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Mar 3, 2023
af04e5d
WIP
marcalff Mar 3, 2023
2613c7d
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Mar 11, 2023
eb9bc19
Cleanup env var names.
marcalff Mar 11, 2023
f6d6c04
Resolved duplication of SSL options.
marcalff Mar 11, 2023
f088bbc
Code cleanup
marcalff Mar 12, 2023
dce246e
CHANGELOG
marcalff Mar 12, 2023
ba6d403
Removed notes.txt, duplicated with ssl doc.
marcalff Mar 12, 2023
659ff69
Build cleanup
marcalff Mar 12, 2023
a5e6cdf
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Mar 23, 2023
df6335e
Fixed code review comments, added _PREVIEW to feature flags.
marcalff Mar 24, 2023
663f009
Fixed warnings in maintainer mode.
marcalff Mar 24, 2023
5b529bd
Merge branch 'main' into fix_otlp_http_ssl_1402
marcalff Mar 29, 2023
eb6c362
Implemented code review comments.
marcalff Mar 30, 2023
0593b4c
Fixed http examples
marcalff Mar 30, 2023
340ac8d
Build cleanup for windows / gmock
marcalff Mar 30, 2023
c247437
Build cleanup, windows + gmock macros
marcalff Mar 30, 2023
8a47cf8
Merge branch 'main' into fix_otlp_http_ssl_1402
esigo Apr 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ option(
option(WITH_EXAMPLES "Whether to build examples" ON)

option(WITH_LOGS_PREVIEW "Whether to build logs preview" OFF)
option(WITH_ASYNC_EXPORT_PREVIEW "Whether enable async export" OFF)
option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF)
option(WITH_OTLP_HTTP_SSL_PREVIEW "Whether to enable otlp http ssl export" OFF)
# Exemplar specs status is experimental, so behind feature flag by default
option(WITH_METRICS_EXEMPLAR_PREVIEW
"Whethere to enable exemplar within metrics" OFF)
Expand Down
5 changes: 5 additions & 0 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ if(WITH_ASYNC_EXPORT_PREVIEW)
target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT)
endif()

# A better place should be in exporter/otlp, not api
if(WITH_OTLP_HTTP_SSL_PREVIEW)
target_compile_definitions(opentelemetry_api INTERFACE ENABLE_OTLP_HTTP_SSL)
endif()

if(WITH_METRICS_EXEMPLAR_PREVIEW)
target_compile_definitions(opentelemetry_api
INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW)
Expand Down
351 changes: 351 additions & 0 deletions docs/testing-with-ssl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,351 @@
# Testing with SSL/TLS

## Required software

The opentelemetry-collector
[documentation](https://opentelemetry.io/docs/collector/configuration/#setting-up-certificates)
uses [cfssl](https://github.com/cloudflare/cfssl),
so we are using cfssl as well here.

In addition, install `openssl`, which provides tooling for testing.

## Generating CERT

### Generating CA CERT

First, write a CA request file in json, named `ca_csr.json`

It should contains the following data:

```console
shell> cat ca_csr.json
{
"hosts": ["localhost", "127.0.0.1"],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"O": "OpenTelemetry CA Example"
}
]
}
```

Then, generate a CA certificate:

```console
shell> cfssl genkey -initca ca_csr.json | cfssljson -bare ca
2022/12/13 16:42:57 [INFO] generate received request
2022/12/13 16:42:57 [INFO] received CSR
2022/12/13 16:42:57 [INFO] generating key: rsa-2048
2022/12/13 16:42:57 [INFO] encoded CSR
2022/12/13 16:42:57 [INFO] signed certificate with serial number 78705522450145914781445058194934247010984259280
```

This will create three files, `ca.csr`, `ca.pem` and `ca-key.pem`

Congratulation, "OpenTelemetry CA Example" is now a CA certification
authority, with signing keys.

### Generating Client CERT

Second, write a certificate request file in json, named `client_csr.json`,
for the opentelemetry-cpp client.

It should contains the following data:

```console
shell> cat client_csr.json
{
"hosts": ["localhost", "127.0.0.1"],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"O": "OpenTelemetry Client Example"
}
]
}
```

Note that the name ("OpenTelemetry Client Example") should be different
from the CA authority name ("OpenTelemetry CA Example"),
otherwise the client certificate will be self-signed, and rejected later in SSL/TLS.

Now, use the CA certificate generated in the previous step
to create and sign a new client certificate.

```console
shell> cfssl gencert -ca ca.pem -ca-key ca-key.pem client_csr.json | cfssljson -bare client_cert
2022/12/13 16:50:18 [INFO] generate received request
2022/12/13 16:50:18 [INFO] received CSR
2022/12/13 16:50:18 [INFO] generating key: rsa-2048
2022/12/13 16:50:18 [INFO] encoded CSR
2022/12/13 16:50:18 [INFO] signed certificate with serial number 579932794730090029542135367576037344135399122179
```

This will create three files, `client_cert.csr`, `client_cert.pem` and `client_cert-key.pem`

### Generating Server CERT

Third and likewise, write a certificate request file in json, named `server_csr.json`,
for the opentelemetry server (the opentelemetry-collector)

It should contains the following data:

```console
shell> cat server_csr.json
{
"hosts": ["localhost", "127.0.0.1"],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"O": "OpenTelemetry Server Example"
}
]
}
```

Likewise, use a different name from the CA authority name.

Use the CA certificate to create and sign a new server certificate.

```console
shell> cfssl gencert -ca ca.pem -ca-key ca-key.pem server_csr.json | cfssljson -bare server_cert
2022/12/13 17:04:40 [INFO] generate received request
2022/12/13 17:04:40 [INFO] received CSR
2022/12/13 17:04:40 [INFO] generating key: rsa-2048
2022/12/13 17:04:40 [INFO] encoded CSR
2022/12/13 17:04:40 [INFO] signed certificate with serial number 332420451189450993545238745169293824985460186638
```

This will create three files, `server_cert.csr`, `server_cert.pem` and `server_cert-key.pem`

### Verify certificates

Verify the certificates generated, using `openssl`:

```console
shell> openssl verify -CAfile ca.pem server_cert.pem client_cert.pem
server_cert.pem: OK
client_cert.pem: OK
```

Useful commands, to inspect certificates if needed (output not shown here)

```console
shell> openssl x509 -in ca.pem -text
```

```console
shell> openssl x509 -in client_cert.pem -text
```

```console
shell> openssl x509 -in server_cert.pem -text
```

## OpenTelemetry SSL clients

### Simulated client, for testing

Use `openssl` to simulate an opentelemetry-cpp client connecting to port 4318:

```console
shell> openssl s_client -connect localhost:4318 -CAfile ca.pem -cert client_cert.pem -key client_cert-key.pem
```

### OTLP HTTP Client

Use the example `example_otlp_http` client to connect to an OTLP HTTP server:

```console
shell> export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://localhost:4318/v1/traces
shell> export OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE=ca.pem
shell> export OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE=client_cert.pem
shell> export OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY=client_cert-key.pem
shell> example_otlp_http
```

## OpenTelemetry SSL servers

### Simulated server, for testing

Use `openssl` to simulate an opentelemetry-collector process serving port 4318:

```console
shell> openssl s_server -accept 4318 -CAfile ca.pem -cert server_cert.pem -key server_cert-key.pem
Using default temp DH parameters
ACCEPT
```

This command does not return,
the server waits for SSL connections (Use CTRL-C to quit).

### OTLP HTTP Server

To use a server that:

- implements OTLP HTTP
- supports SSL

use the opentelemetry-collector,
configured to use SSL/TLS for receivers:

```console
shell> cat otel-collector-config-ssl.yaml
receivers:
otlp:
protocols:
http:
tls:
ca_file: ca.pem
cert_file: server_cert.pem
key_file: server_cert-key.pem
...
```

For example:

```console
shell> /path/to/bin/otelcorecol_linux_amd64 --config /path/to/otel-config-ssl.yaml
```

Note, the `example/http/http_example` can not be used (it understands neither SSL
nor OTLP HTTP).

## Testing SSL on the wire

### Fake client with fake server

This configuration tests nothing in opentelemetry,
but is useful to understand what a nominal SSL communication between a
client and a server should look like.

### Real client with fake server

In this configuration, we can test that the opentelemetry-cpp
client actually sends SSL traffic on the wire.

### Fake client with real server

In this configuration, we can test that the opentelemetry-collector
server actually accepts SSL traffic on the wire.
This can be used to verify the client keys are working properly.

## Full integration test with SSL

Start an opentelemetry-collector, configured to use SSL/TLS.

```console
shell> /path/to/bin/otelcorecol_linux_amd64 --config /path/to/otel-config-ssl.yaml
...
2022-12-13T18:03:21.140+0100 info otlpreceiver@v0.66.0/otlp.go:89 Starting HTTP server {"kind": "receiver", "name": "otlp", "pipeline": "metrics", "endpoint": "0.0.0.0:4318"}
2022-12-13T18:03:21.141+0100 info service/pipelines.go:106 Receiver started. {"kind": "receiver", "name": "otlp", "pipeline": "metrics"}
2022-12-13T18:03:21.141+0100 info service/pipelines.go:102 Receiver is starting... {"kind": "receiver", "name": "otlp", "pipeline": "traces"}
2022-12-13T18:03:21.141+0100 info service/pipelines.go:106 Receiver started. {"kind": "receiver", "name": "otlp", "pipeline": "traces"}
2022-12-13T18:03:21.141+0100 info service/service.go:105 Everything is ready. Begin running and processing data.
```

Start the example_otlp_http client, configured to use SSL/TLS.

```console
shell> export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://localhost:4318/v1/traces
shell> export OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE=ca.pem
shell> export OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE=client_cert.pem
shell> export OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY=client_cert-key.pem
shell> example_otlp_http
```

The opentelemetry-collector process receives data, as seen in logs:

```console
2022-12-13T18:05:36.611+0100 info TracesExporter {"kind": "exporter", "data_type": "traces", "name": "logging", "#spans": 4}
2022-12-13T18:05:36.611+0100 info ResourceSpans #0
Resource SchemaURL:
Resource attributes:
-> service.name: Str(unknown_service)
-> telemetry.sdk.version: Str(1.8.1)
-> telemetry.sdk.name: Str(opentelemetry)
-> telemetry.sdk.language: Str(cpp)
ScopeSpans #0
ScopeSpans SchemaURL:
InstrumentationScope foo_library 1.8.1
Span #0
Trace ID : ebbd7e13e9cdfb05f0ca9ed4b0cdf6c0
Parent ID : 042ae76539c294c6
ID : c87b21d63c505bae
Name : f1
Kind : Internal
Start time : 2022-12-13 17:05:36.482165738 +0000 UTC
End time : 2022-12-13 17:05:36.482170938 +0000 UTC
Status code : Unset
Status message :
ResourceSpans #1
Resource SchemaURL:
Resource attributes:
-> service.name: Str(unknown_service)
-> telemetry.sdk.version: Str(1.8.1)
-> telemetry.sdk.name: Str(opentelemetry)
-> telemetry.sdk.language: Str(cpp)
ScopeSpans #0
ScopeSpans SchemaURL:
InstrumentationScope foo_library 1.8.1
Span #0
Trace ID : ebbd7e13e9cdfb05f0ca9ed4b0cdf6c0
Parent ID : 042ae76539c294c6
ID : 801227b9ee6d3b03
Name : f1
Kind : Internal
Start time : 2022-12-13 17:05:36.487636362 +0000 UTC
End time : 2022-12-13 17:05:36.487641983 +0000 UTC
Status code : Unset
Status message :
ResourceSpans #2
Resource SchemaURL:
Resource attributes:
-> service.name: Str(unknown_service)
-> telemetry.sdk.version: Str(1.8.1)
-> telemetry.sdk.name: Str(opentelemetry)
-> telemetry.sdk.language: Str(cpp)
ScopeSpans #0
ScopeSpans SchemaURL:
InstrumentationScope foo_library 1.8.1
Span #0
Trace ID : ebbd7e13e9cdfb05f0ca9ed4b0cdf6c0
Parent ID : 6489f2ada8d95da0
ID : 042ae76539c294c6
Name : f2
Kind : Internal
Start time : 2022-12-13 17:05:36.482154908 +0000 UTC
End time : 2022-12-13 17:05:36.488641122 +0000 UTC
Status code : Unset
Status message :
ResourceSpans #3
Resource SchemaURL:
Resource attributes:
-> service.name: Str(unknown_service)
-> telemetry.sdk.version: Str(1.8.1)
-> telemetry.sdk.name: Str(opentelemetry)
-> telemetry.sdk.language: Str(cpp)
ScopeSpans #0
ScopeSpans SchemaURL:
InstrumentationScope foo_library 1.8.1
Span #0
Trace ID : ebbd7e13e9cdfb05f0ca9ed4b0cdf6c0
Parent ID :
ID : 6489f2ada8d95da0
Name : library
Kind : Internal
Start time : 2022-12-13 17:05:36.482136052 +0000 UTC
End time : 2022-12-13 17:05:36.489263125 +0000 UTC
Status code : Unset
Status message :
```
2 changes: 2 additions & 0 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark")
cc_library(
name = "otlp_recordable",
srcs = [
"src/otlp_environment.cc",
"src/otlp_log_recordable.cc",
"src/otlp_metric_utils.cc",
"src/otlp_populate_attribute_utils.cc",
"src/otlp_recordable.cc",
"src/otlp_recordable_utils.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
"include/opentelemetry/exporters/otlp/otlp_log_recordable.h",
"include/opentelemetry/exporters/otlp/otlp_metric_utils.h",
"include/opentelemetry/exporters/otlp/otlp_populate_attribute_utils.h",
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_library(
opentelemetry_otlp_recordable
src/otlp_log_recordable.cc src/otlp_recordable.cc
src/otlp_environment.cc src/otlp_log_recordable.cc src/otlp_recordable.cc
src/otlp_populate_attribute_utils.cc src/otlp_recordable_utils.cc
src/otlp_metric_utils.cc)
set_target_properties(opentelemetry_otlp_recordable PROPERTIES EXPORT_NAME
Expand Down
Loading