-
Notifications
You must be signed in to change notification settings - Fork 339
Redact OTLP header and Datadog key configs in telemetry #11583
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
Open
bm1549
wants to merge
6
commits into
master
Choose a base branch
from
brian.marks/omit-sensitive-config-telemetry
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2c36e1a
Redact OTLP header and Datadog key configurations from configuration …
bm1549 ede87b9
test(telemetry): guard that sensitive-marked configs are actually red…
bm1549 bae31f8
Address review: alphabetize filter list, migrate ConfigCollectorTest …
bm1549 ae0d111
Simplify config redaction and extend it to all collected credential c…
bm1549 31f95fc
Drop deprecated profiling api-key fallbacks; keep ConfigCollectorTest…
bm1549 4cbc945
Apply suggestion from @bm1549
bm1549 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
utils/config-utils/src/test/java/datadog/trace/api/SensitiveConfigRedactionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package datadog.trace.api; | ||
|
|
||
| import static datadog.trace.util.ConfigStrings.toEnvVar; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.lang.reflect.Field; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
| import java.util.stream.Collectors; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.snakeyaml.engine.v2.api.Load; | ||
| import org.snakeyaml.engine.v2.api.LoadSettings; | ||
|
|
||
| /** | ||
| * Drift-guard test keeping the {@code "sensitive": true} entries in {@code | ||
| * metadata/supported-configurations.json} in sync with {@code ConfigSetting.CONFIG_FILTER_LIST}. | ||
| * The registry attribute is not read at runtime, so this test is what keeps the two from drifting. | ||
| */ | ||
| public class SensitiveConfigRedactionTest { | ||
|
|
||
| private static final String REGISTRY_RELATIVE_PATH = "metadata/supported-configurations.json"; | ||
|
|
||
| // Normalizes a config name to the canonical token under which its value is COLLECTED, so the | ||
| // registry's public names line up with the property-name forms in CONFIG_FILTER_LIST. toEnvVar | ||
| // upper-cases and replaces "." / "-" with "_"; we strip a leading "DD_" so the dotted property | ||
| // name and the DD_ env-var form of the same config collapse together. OTLP exporter headers set | ||
| // via the OpenTelemetry env vars are collected under the Datadog otlp.<signal>.headers keys, so | ||
| // the OTEL_ names map onto that collected form. | ||
| private static String canonical(String name) { | ||
| String env = toEnvVar(name); | ||
| if (env.startsWith("DD_")) { | ||
| env = env.substring("DD_".length()); | ||
| } | ||
| if (env.equals("OTEL_EXPORTER_OTLP_HEADERS")) { | ||
| // The generic OTEL header env var funnels into every otlp.<signal>.headers; traces stands in. | ||
| return "OTLP_TRACES_HEADERS"; | ||
| } | ||
| if (env.startsWith("OTEL_EXPORTER_OTLP_") && env.endsWith("_HEADERS")) { | ||
| return "OTLP_" + env.substring("OTEL_EXPORTER_OTLP_".length()); | ||
| } | ||
| return env; | ||
| } | ||
|
|
||
| @Test | ||
| void sensitiveRegistryEntriesAndFilterListStayInSync() { | ||
| Set<String> registryCanonical = | ||
| sensitiveRegistryKeys().stream() | ||
| .map(SensitiveConfigRedactionTest::canonical) | ||
| .collect(toTreeSet()); | ||
| Set<String> filterCanonical = | ||
| configFilterList().stream() | ||
| .map(SensitiveConfigRedactionTest::canonical) | ||
| .collect(toTreeSet()); | ||
|
|
||
| assertFalse(registryCanonical.isEmpty(), "expected at least one \"sensitive\": true config"); | ||
| assertEquals( | ||
| registryCanonical, | ||
| filterCanonical, | ||
| "Registry \"sensitive\": true entries and ConfigSetting.CONFIG_FILTER_LIST must match after " | ||
| + "canonicalization. Reconcile metadata/supported-configurations.json and " | ||
| + "CONFIG_FILTER_LIST in ConfigSetting.java."); | ||
| } | ||
|
|
||
| // Registry keys for every entry marked "sensitive": true. Aliases are not collected separately -- | ||
| // a value is always collected under its primary key's property name -- so they are not needed | ||
| // here. | ||
| @SuppressWarnings("unchecked") | ||
| private static Set<String> sensitiveRegistryKeys() { | ||
| Path registry = locateRegistry(); | ||
| String content; | ||
| try { | ||
| content = new String(Files.readAllBytes(registry), StandardCharsets.UTF_8); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("Failed to read " + registry, e); | ||
| } | ||
|
|
||
| Object parsed = new Load(LoadSettings.builder().build()).loadFromString(content); | ||
| Map<String, Object> root = (Map<String, Object>) parsed; | ||
| Map<String, Object> supported = (Map<String, Object>) root.get("supportedConfigurations"); | ||
|
|
||
| Set<String> sensitive = new TreeSet<>(); | ||
| for (Map.Entry<String, Object> entry : supported.entrySet()) { | ||
| for (Object def : (List<Object>) entry.getValue()) { | ||
| Map<String, Object> definition = (Map<String, Object>) def; | ||
| if (Boolean.TRUE.equals(definition.get("sensitive"))) { | ||
| sensitive.add(entry.getKey()); | ||
| } | ||
| } | ||
| } | ||
| return sensitive; | ||
| } | ||
|
|
||
| // Reads CONFIG_FILTER_LIST from ConfigSetting via reflection. | ||
| @SuppressWarnings("unchecked") | ||
| private static Set<String> configFilterList() { | ||
| try { | ||
| Field field = ConfigSetting.class.getDeclaredField("CONFIG_FILTER_LIST"); | ||
| field.setAccessible(true); | ||
| return (Set<String>) field.get(null); | ||
| } catch (NoSuchFieldException | IllegalAccessException e) { | ||
| throw new IllegalStateException("Could not read ConfigSetting.CONFIG_FILTER_LIST", e); | ||
| } | ||
| } | ||
|
|
||
| // Walks up from the working directory until metadata/supported-configurations.json is found. | ||
| private static Path locateRegistry() { | ||
| Path dir = Paths.get(System.getProperty("user.dir")).toAbsolutePath(); | ||
| for (Path current = dir; current != null; current = current.getParent()) { | ||
| Path candidate = current.resolve(REGISTRY_RELATIVE_PATH); | ||
| if (Files.isRegularFile(candidate)) { | ||
| return candidate; | ||
| } | ||
| } | ||
| throw new IllegalStateException("Could not locate " + REGISTRY_RELATIVE_PATH + " from " + dir); | ||
| } | ||
|
|
||
| private static java.util.stream.Collector<String, ?, TreeSet<String>> toTreeSet() { | ||
| return Collectors.toCollection(TreeSet::new); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to prove that the only format that occurs here is
dd.api-keyand notDD_API_KEY. Cleaning this up