OpenTelemetry Collector Security
MetricsHub Enterprise includes an embedded OpenTelemetry Collector. This page describes how communications between the MetricsHub Agent and the Collector are secured, and how to customize these security settings.
Receiver Security
To prevent unauthorized access, the gRPC listener is by default only opened on localhost:
otlp:
protocols:
grpc:
endpoint: localhost:4317
This means only processes running on the same machine can send data to the Collector.
Transport Security
MetricsHub secures the communications between the MetricsHub Agent's internal OTLP Exporter and the OpenTelemetry Collector's internal OTLP gRPC Receiver using TLS encryption.
The OTLP gRPC Receiver is configured as follows in the otel/otel-config.yaml file:
otlp:
protocols:
grpc:
endpoint: localhost:4317
tls:
cert_file: ../security/otel.crt
key_file: ../security/otel.key
Request Authentication
Once TLS is established, the OTLP gRPC Receiver uses the basicauth authenticator to verify any incoming request:
otlp:
protocols:
grpc:
endpoint: localhost:4317
tls:
cert_file: ../security/otel.crt
key_file: ../security/otel.key
auth:
authenticator: basicauth
Customizing TLS Certificates
You can use your own certificate to secure the communications between the MetricsHub Agent and the OpenTelemetry Collector by replacing the default TLS certificate of the OTLP gRPC Receiver.
Prerequisites
- The certificate file must be in PEM format and can contain one or more certificate chains. The first certificate compatible with the client's requirements will be automatically selected.
- The private key must be non-encrypted and in PEM format.
- The certificate must include the
subjectAltNameextension indicatingDNS:localhost,IP:127.0.0.1because internal communications are onlocalhostonly and the MetricsHub Agent'sOTLP Exporterperforms hostname verification.
Procedure
-
Generate your new private key and certificate files (for example:
my-otel.keyandmy-otel.crt). -
Copy the generated certificate and private key files into the
securitydirectory. -
In the
otel/otel-config.yamlfile, update thetls:cert_fileandtls:key_fileattributes of theOTLP gRPC Receiver:receivers:
otlp:
protocols:
grpc:
endpoint: localhost:4317
tls:
cert_file: ../security/my-otel.crt # Your new certificate file
key_file: ../security/my-otel.key # Your new private key file
auth:
authenticator: basicauth -
In the
config/metricshub.yamlfile, set your new certificate ascertificatein theOTLP Exporterconfiguration section:On Linux:
otel:
otel.exporter.otlp.metrics.certificate: /opt/metricshub/lib/security/my-otel.crtOn Windows:
otel:
otel.exporter.otlp.metrics.certificate: C:/ProgramData/MetricsHub/security/my-otel.crt -
Restart MetricsHub.
Generating a Self-Signed Certificate with OpenSSL
OpenSSL is a command-line tool to generate X.509 certificates. You can use it to generate self-signed certificates.
Note: The example below explains how to generate a server certificate using the OpenSSL utility on a Linux machine. Your organization may define its own security policy to handle certificates and private keys. Before proceeding, make sure this procedure aligns with your organization's requirements.
-
Create a private key for the Certificate Authority (CA):
openssl genrsa 2048 > ca.key -
Generate the X.509 certificate for the CA:
openssl req -new -x509 -nodes -days 365000 \
-key ca.key \
-out ca.crt -
Generate the private key and certificate request:
openssl req -newkey rsa:2048 -nodes -days 365000 \
-keyout my-otel.key \
-out my-otel.req -
Create a
cert.conffile that defines the required extension:[ req ]
req_extensions = req_ext
[ req_ext ]
subjectAltName = DNS:localhost,IP:127.0.0.1 -
Generate the X.509 certificate for the
OTLP gRPC Receiver:openssl x509 -req -days 365000 -set_serial 01 \
-in my-otel.req \
-out my-otel.crt \
-CA ca.crt \
-CAkey ca.key \
-extfile cert.conf -extensions req_ext -
Your certificate (
my-otel.crt) and private key (my-otel.key) are now generated in PEM format. Verify your certificate:openssl verify -CAfile ca.crt ca.crt my-otel.crt
Customizing OTLP Authentication Password
You can use your own password to have the OTLP gRPC Receiver authenticate incoming requests.
Prerequisites
Access to the htpasswd tool:
- On Linux: Install the
httpd-toolspackage (orapache2-utilson Debian/Ubuntu) - On Windows: The
htpasswdutility is available in Apache for Windows packages
Procedure
-
Create a new
.htpasswd-otelfile using your username and password:htpasswd -cbB .htpasswd-otel myUsername myPassword -
Copy the
.htpasswd-otelfile into thesecuritydirectory. -
In the
otel/otel-config.yamlfile, update thefileattribute of thebasicauthextension:extensions:
# ...
basicauth:
htpasswd:
file: ../security/.htpasswd-otel # Your new htpasswd file -
In the
otel/otel-config.yamlfile, make surebasicauthis declared as a service extension and as theOTLP gRPC Receiverauthenticator:service:
# ...
extensions: [health_check, basicauth]
pipelines:
# ...
receivers:
otlp:
protocols:
grpc:
# ...
auth:
authenticator: basicauth -
Generate a
base64string using the same credentials. Join your username and password with a colon and encode the result:echo -n 'myUsername:myPassword' | base64Output:
bXlVc2VybmFtZTpteVBhc3N3b3Jk -
In the
config/metricshub.yamlfile, add theAuthorizationheader to the OTLP exporter configuration:otel:
otel.exporter.otlp.metrics.headers: Authorization=Basic bXlVc2VybmFtZTpteVBhc3N3b3JkThe header value must be
Basic BASE64_CREDENTIALS, whereBASE64_CREDENTIALSis the value you generated in the previous step. -
Restart MetricsHub.
Disabling TLS (Not Recommended)
Warning: Disabling TLS means communications between the MetricsHub Agent and the OpenTelemetry Collector are no longer encrypted. Only do this in isolated test environments.
-
In the
otel/otel-config.yamlfile, remove or comment out thetlssection:receivers:
otlp:
protocols:
grpc:
endpoint: localhost:4317
# tls:
# cert_file: ../security/otel.crt
# key_file: ../security/otel.key
auth:
authenticator: basicauth -
In the
config/metricshub.yamlfile, update the OTLP exporter endpoint to use HTTP:otel:
otel.exporter.otlp.metrics.endpoint: http://localhost:4317 -
Remove or comment out the
certificateattribute inconfig/metricshub.yaml:otel:
otel.exporter.otlp.metrics.endpoint: http://localhost:4317
# otel.exporter.otlp.metrics.certificate: security/otel.crt -
Restart MetricsHub.
Disabling Authentication (Not Recommended)
Warning: Disabling authentication means incoming requests will no longer be verified by the OpenTelemetry Collector, which may expose you to unauthorized access.
-
In the
otel/otel-config.yamlfile, remove or comment out theauthsection:receivers:
otlp:
protocols:
grpc:
endpoint: localhost:4317
tls:
cert_file: ../security/otel.crt
key_file: ../security/otel.key
# auth:
# authenticator: basicauth -
In the
otel/otel-config.yamlfile, removebasicauthfrom the service extensions list:service:
# ...
extensions: [health_check] # basicauth removed
pipelines:
# ... -
In the
config/metricshub.yamlfile, remove theAuthorizationheader:otel:
# otel.exporter.otlp.metrics.headers: Authorization=Basic ... -
Restart MetricsHub.