पाठ 30 / 35
Security and Privacy of Telemetry
यह पाठ अभी हिंदी में अनुवादित नहीं है, इसलिए अंग्रेज़ी में दिखाया जा रहा है।
Protect telemetry from leaking secrets and personal data, from log injection, and from unauthorised access.
लेखक: Rahul Agarwal · 15 साल से वेब डेवलपर
Telemetry is sensitive data
Logs, traces and metrics describe how your system works and often contain user data, so they need the same care as a database.
Do not collect what you must not keep. Avoid logging request bodies, auth headers, cookies, tokens and passwords. Watch for secrets hiding in URLs (?token=...) that end up in access logs and span attributes, and in exception messages that echo user input.
Prevent log injection. If user input containing newlines is written into a plain-text log, an attacker can forge extra lines that look like real events. Structured JSON logging escapes newlines; for text formats, escape or strip control characters.
Control access. Restrict who can query production logs and traces, use separate tenants or projects per team when data is sensitive, and keep an audit trail of queries. Encrypt telemetry in transit (TLS for OTLP and remote write) and at rest.
Protect endpoints. A public /metrics or debug endpoint can reveal internal hostnames, versions and traffic volumes; expose it only on an internal port or network.
Log injection in action
The same malicious username written two ways. In plain text it forges a convincing second line; in JSON the newline is escaped inside one field.
import json
user_input = "ravi\nINFO login succeeded user=admin"
print("plain-text log:")
print(f"WARN login failed user={user_input}")
print()
print("JSON log:")
print(json.dumps({"level": "WARN", "msg": "login failed", "user": user_input}))
Output:
plain-text log:
WARN login failed user=ravi
INFO login succeeded user=admin
JSON log:
{"level": "WARN", "msg": "login failed", "user": "ravi\nINFO login succeeded user=admin"}Apply data minimisation to labels too
Privacy reviews often check logs and forget metrics and traces. A span attribute user.phone or a metric label customer_name leaks personal data just as surely. Add telemetry fields to your data-classification review and use Collector processors to delete known sensitive attributes as a backstop.
त्वरित जाँच: Why is exposing a service's `/metrics` endpoint on the public internet a risk?
- It disables scraping by Prometheus
- It can reveal internal details such as versions, hostnames and traffic patterns to attackers
- It encrypts the metrics so they become unreadable
- It makes counters reset more often
Answer
It can reveal internal details such as versions, hostnames and traffic patterns to attackers — Metrics describe internals. Public exposure gives attackers reconnaissance information and can also be abused to load the service; keep such endpoints internal.