Skip to content

Commit 12014f0

Browse files
committed
[OTLP] add mTLS receiver for otel collector for integration test
1 parent 1183adb commit 12014f0

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# Self-signed cert generated by integration test
22
otel-collector.crt
33
otel-collector.key
4+
otel-client-cert.pem
5+
otel-client-key.pem
6+
otel-ca-cert.pem

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/create-cert.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,38 @@ cp /otel-collector.crt /otel-collector.key /cfg
1111

1212
chmod 644 /cfg/otel-collector.key
1313

14+
# Generate CA and client cert for mTLS
15+
echo "\
16+
basicConstraints = CA:FALSE
17+
nsCertType = server
18+
nsComment = "OpenSSL Generated CA Certificate"
19+
subjectKeyIdentifier = hash
20+
authorityKeyIdentifier = keyid,issuer:always
21+
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
22+
extendedKeyUsage = serverAuth
23+
" > /ca_cert_ext.cnf
24+
25+
openssl ecparam -genkey -name prime256v1 -out /otel-ca-key.pem
26+
openssl req -new -sha256 -key /otel-ca-key.pem -out /otel-ca-csr.pem -subj "/CN=otel-test-ca"
27+
openssl x509 -req -in /otel-ca-csr.pem -sha256 -days 365 -signkey /otel-ca-key.pem -out /otel-ca-cert.pem -extfile /ca_cert_ext.cnf
28+
29+
echo "\
30+
basicConstraints = CA:FALSE
31+
nsCertType = client, email
32+
nsComment = "OpenSSL Generated Client Certificate"
33+
subjectKeyIdentifier = hash
34+
authorityKeyIdentifier = keyid,issuer
35+
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
36+
extendedKeyUsage = clientAuth, emailProtection
37+
" > client_cert_ext.cnf
38+
39+
openssl ecparam -genkey -name prime256v1 -out /otel-client-key.pem
40+
openssl req -new -key /otel-client-key.pem -out /otel-client-csr.pem -subj "/CN=otel-test-client"
41+
openssl x509 -req -in /otel-client-csr.pem -CA /otel-ca-cert.pem -CAkey /otel-ca-key.pem -out /otel-client-cert.pem -CAcreateserial -days 365 -sha256 -extfile /client_cert_ext.cnf
42+
43+
cp /otel-ca-cert.pem /otel-client-cert.pem /otel-client-key.pem /cfg
44+
cp /otel-ca-cert.pem /usr/local/share/ca-certificates/otel-ca-cert.pem
45+
1446
# The integration test is run via docker-compose with the --exit-code-from
1547
# option. The --exit-code-from option implies --abort-on-container-exit
1648
# which means when any container exits then all containers are stopped.

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/otel-collector-config.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ receivers:
2323
tls:
2424
cert_file: /cfg/otel-collector.crt
2525
key_file: /cfg/otel-collector.key
26+
otlp/mtls:
27+
protocols:
28+
grpc:
29+
endpoint: 0.0.0.0:6317
30+
tls:
31+
cert_file: /cfg/otel-collector.crt
32+
key_file: /cfg/otel-collector.key
33+
client_ca_file: /cfg/otel-ca-cert.pem
34+
http:
35+
endpoint: 0.0.0.0:6318
36+
tls:
37+
cert_file: /cfg/otel-collector.crt
38+
key_file: /cfg/otel-collector.key
39+
client_ca_file: /cfg/otel-ca-cert.pem
2640

2741
exporters:
2842
logging:
@@ -31,8 +45,8 @@ exporters:
3145
service:
3246
pipelines:
3347
traces:
34-
receivers: [otlp, otlp/tls]
48+
receivers: [otlp, otlp/tls, otlp/mtls]
3549
exporters: [logging]
3650
metrics:
37-
receivers: [otlp, otlp/tls]
51+
receivers: [otlp, otlp/tls, otlp/mtls]
3852
exporters: [logging]

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void CreateGrpcChannel_WithCertificates_ReturnsChannelWithoutException()
181181
{
182182
CertificateFile = trustedCACertPath,
183183
ClientCertificateFile = certPath,
184-
ClientKeyFile = pKeyPath
184+
ClientKeyFile = pKeyPath,
185185
};
186186

187187
using var channel = OtlpExporterOptionsExtensions.CreateChannel(otlpOptions);

0 commit comments

Comments
 (0)