Skip to content

Commit a0a983a

Browse files
authored
Use json-iterator for secrets marshalling (#44309)
### What does this PR do? Use json-iterator for secrets marshalling in the file `comp/core/secrets/impl/fetch_secret.go` ### Motivation If my `datadog.yaml config` contains this: ``` secret_backend_command: /opt/datadog-agent/scripts/script.py secret_backend_type: aws.secrets secret_backend_config: a: b: c api_key: ENC[my_api_key] ``` Then running this code with `DD_CONF_NODETREEMODEL=enable` leads to `b: c` having type `map[interface{}]interface{}` which `encoding/json` fails to marshal. The third-party package `"github.com/json-iterator/go"` will correctly marshal this. ### Describe how you validated your changes ### Additional Notes It's unclear why enabling NTM causes this different runtime type. It could be a good idea to make sure the yaml reader never returns objects of type `map[interface{}]interface{}`. Co-authored-by: dustin.long <dustin.long@datadoghq.com>
1 parent 19a6b24 commit a0a983a

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

comp/core/secrets/fx/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ require (
4343
github.com/gofrs/flock v0.13.0 // indirect
4444
github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb // indirect
4545
github.com/inconshreveable/mousetrap v1.1.0 // indirect
46+
github.com/json-iterator/go v1.1.12 // indirect
4647
github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35 // indirect
4748
github.com/mattn/go-colorable v0.1.14 // indirect
4849
github.com/mattn/go-isatty v0.0.20 // indirect
4950
github.com/mdlayher/socket v0.5.1 // indirect
5051
github.com/mdlayher/vsock v1.2.1 // indirect
52+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
53+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
5154
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5255
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
5356
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect

comp/core/secrets/fx/go.sum

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

comp/core/secrets/impl/fetch_secret.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ package secretsimpl
88
import (
99
"bytes"
1010
"context"
11-
"encoding/json"
1211
"errors"
1312
"fmt"
1413
"os/exec"
1514
"strconv"
1615
"strings"
1716
"time"
1817

18+
json "github.com/json-iterator/go"
19+
1920
secrets "github.com/DataDog/datadog-agent/comp/core/secrets/def"
2021
"github.com/DataDog/datadog-agent/pkg/util/log"
2122
)

comp/core/secrets/impl/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/DataDog/datadog-agent/pkg/util/testutil v0.59.0
1818
github.com/DataDog/datadog-agent/pkg/util/winutil v0.68.3
1919
github.com/benbjohnson/clock v1.3.5
20+
github.com/json-iterator/go v1.1.12
2021
github.com/stretchr/testify v1.11.1
2122
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9
2223
golang.org/x/sys v0.39.0
@@ -52,6 +53,8 @@ require (
5253
github.com/mattn/go-isatty v0.0.20 // indirect
5354
github.com/mdlayher/socket v0.5.1 // indirect
5455
github.com/mdlayher/vsock v1.2.1 // indirect
56+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
57+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
5558
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5659
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
5760
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect

comp/core/secrets/impl/go.sum

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)