Skip to content

Conversation

kakkoyun
Copy link
Member

@kakkoyun kakkoyun commented Sep 5, 2025

Eliminate PII leakage in telemetry data sent to external services by enforcing
strict security controls on telemetry logging with comprehensive static analysis.

Redesigned telemetry Error API to require constant messages only, implemented
SafeError with automatic stack trace redaction, and created mission-critical
static checker rules with bulletproof scoping.

  • Messages: Constant templates only (no dynamic strings/format verbs)
  • Stack traces: Customer code frames replaced with "REDACTED" placeholder
  • Error details: Only error type exposed, never error messages
  • Collections: SafeSlice with explicit type conversions (no %v formatting)
  • Static enforcement: Comprehensive ruleguard rules prevent all violations

SafeError extracts error types and redacts customer stack frames using contrib/
directory for frame classification. API breaking change from telemetrylog.Error(err)

to Error("message", SafeError(err)) ensures constant messages with secure error
details.

Signed-off-by: Kemal Akkoyun [email protected]

What does this PR do?

Motivation

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running ./scripts/lint.sh locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@kakkoyun kakkoyun marked this pull request as ready for review September 5, 2025 19:56
@kakkoyun kakkoyun requested review from a team as code owners September 5, 2025 19:56
  Eliminate PII leakage in telemetry data sent to external services by enforcing
  strict security controls on telemetry logging with comprehensive static analysis.

  Redesigned telemetry Error API to require constant messages only, implemented
  SafeError with automatic stack trace redaction, and created mission-critical
  static checker rules with bulletproof scoping.

  - Messages: Constant templates only (no dynamic strings/format verbs)
  - Stack traces: Customer code frames replaced with "REDACTED" placeholder
  - Error details: Only error type exposed, never error messages
  - Collections: SafeSlice with explicit type conversions (no %v formatting)
  - Static enforcement: Comprehensive ruleguard rules prevent all violations

  SafeError extracts error types and redacts customer stack frames using contrib/
  directory for frame classification. API breaking change from telemetrylog.Error(err)

  to Error("message", SafeError(err)) ensures constant messages with secure error
  details.

Signed-off-by: Kemal Akkoyun <[email protected]>
@kakkoyun kakkoyun force-pushed the kakkoyun/LANGPLAT-767/improve_telemtery_error_logs branch from b572220 to 38893c1 Compare September 5, 2025 20:20
Copy link
Contributor

@bouwkast bouwkast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this looks great thanks a bunch @kakkoyun
I think this will do it, I don't see anything that stands out.

I wasn't actually aware of WithTags being a thing, but they appear fine to me, I would like to follow up on that outside of this PR with the ASM team (I think they implemented it) to just figure out what the expectations are for that.

(don't take this as a go review 😛)

@@ -175,14 +177,16 @@ func (m *WAFManager) RestoreDefaultConfig() error {
}

func logLocalDiagnosticMessages(name string, feature *libddwaf.Feature) {
logger := telemetryLog.With(telemetry.WithTags([]string{"appsec_config_key:" + name, "log_type:local::diagnostic"}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my understanding is that the WithTags is something that ASM designed / built into the telemetry logs.

I am actually not very familiar with them, but so far I think they are okay, they fall out of the message (I think) so hopefully they don't impact our deduplication logic.

I'll plan on following up on these though to find out more about how they work - it seems that ASM pushed for this and relies on it entirely as some of their logs don't get sent anywhere else.

Comment on lines +10 to +11
// This package implements strict security controls for telemetry logging to prevent
// PII and sensitive information from being sent to external telemetry services.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks 👍

One additional element is that constant messages also allows us to better deduplicate log messages to reduce how many of the same log we actually send

redactedPlaceholder = "REDACTED"
)

// TODO: Dynamically generate knownThirdPartyLibraries from contrib/ directory structure at build time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@quinna-h wondering if we maybe already have this or something like this? 😄

Just wondering, we don't need to act on this here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this is a great addition!


//go:build ruleguard

// Package gorules contains security-focused telemetry logging rules for dd-trace-go.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and an analyzer very nice 🚀 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants