Skip to content

Commit 1de1ed2

Browse files
mx-psimashhurs
authored andcommitted
[exporter/datadog] Stop doing character validation for API keys (open-telemetry#42783)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> Stops doing validation of characters in API key. Validation of secrets is challenging. Furthermore, any possible changes on the API key format would mean users would have to upgrade their clients; being more flexible and leaving validation for runtime helps avoid unnecessary upgrades. #### Link to tracking issue Fixes open-telemetry#42677
1 parent 4692c8f commit 1de1ed2

File tree

5 files changed

+33
-38
lines changed

5 files changed

+33
-38
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/datadog, exporter/datadog, extension/datadog
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecates StaticAPIKeyCheck, stops doing validation for API key characters in Datadog exporter and extension.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [42677]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
This was causing issues to users since validation of secrets is challenging
20+
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [api,user]

extension/datadogextension/config.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ package datadogextension // import "github.com/open-telemetry/opentelemetry-coll
55

66
import (
77
"errors"
8-
"fmt"
9-
"strings"
108

119
"go.opentelemetry.io/collector/component"
1210
"go.opentelemetry.io/collector/config/confighttp"
@@ -36,10 +34,6 @@ func (c *Config) Validate() error {
3634
if c.API.Key == "" {
3735
return datadogconfig.ErrUnsetAPIKey
3836
}
39-
invalidAPIKeyChars := datadogconfig.NonHexRegex.FindAllString(string(c.API.Key), -1)
40-
if len(invalidAPIKeyChars) > 0 {
41-
return fmt.Errorf("%w: invalid characters: %s", datadogconfig.ErrAPIKeyFormat, strings.Join(invalidAPIKeyChars, ", "))
42-
}
4337
if c.HTTPConfig == nil {
4438
return errors.New("http config is required")
4539
}

extension/datadogextension/config_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package datadogextension // import "github.com/open-telemetry/opentelemetry-coll
55

66
import (
77
"errors"
8-
"fmt"
98
"testing"
109
"time"
1110

@@ -76,22 +75,6 @@ func TestConfig_Validate(t *testing.T) {
7675
},
7776
wantErr: datadogconfig.ErrUnsetAPIKey,
7877
},
79-
{
80-
name: "Invalid API key characters",
81-
config: Config{
82-
API: datadogconfig.APIConfig{
83-
Site: datadogconfig.DefaultSite,
84-
Key: "1234567890abcdef1234567890abcdeg",
85-
},
86-
HTTPConfig: &httpserver.Config{
87-
ServerConfig: confighttp.ServerConfig{
88-
Endpoint: "http://localhost:8080",
89-
},
90-
Path: "/metadata",
91-
},
92-
},
93-
wantErr: fmt.Errorf("%w: invalid characters: %s", datadogconfig.ErrAPIKeyFormat, "g"),
94-
},
9578
{
9679
name: "Missing HTTP config",
9780
config: Config{

pkg/datadog/config/config.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ var (
2828
ErrNoMetadata = errors.New("only_metadata can't be enabled when host_metadata::enabled = false or host_metadata::hostname_source != first_resource")
2929
// ErrInvalidHostname is returned when the hostname is invalid.
3030
ErrEmptyEndpoint = errors.New("endpoint cannot be empty")
31-
// ErrAPIKeyFormat is returned if API key contains invalid characters
32-
ErrAPIKeyFormat = errors.New("api::key contains invalid characters")
3331
// NonHexRegex is a regex of characters that are always invalid in a Datadog API key
3432
NonHexRegex = regexp.MustCompile(NonHexChars)
3533
)
@@ -139,8 +137,8 @@ func (c *Config) Validate() error {
139137
return fmt.Errorf("hostname field is invalid: %w", err)
140138
}
141139

142-
if err := StaticAPIKeyCheck(string(c.API.Key)); err != nil {
143-
return err
140+
if c.API.Key == "" {
141+
return ErrUnsetAPIKey
144142
}
145143

146144
if err := c.Traces.Validate(); err != nil {
@@ -161,14 +159,12 @@ func (c *Config) Validate() error {
161159

162160
// StaticAPIKey Check checks if api::key is either empty or contains invalid (non-hex) characters
163161
// It does not validate online; this is handled on startup.
162+
// Deprecated: [v0.136.0] Do not use, will be removed on the next minor version
164163
func StaticAPIKeyCheck(key string) error {
165164
if key == "" {
166165
return ErrUnsetAPIKey
167166
}
168-
invalidAPIKeyChars := NonHexRegex.FindAllString(key, -1)
169-
if len(invalidAPIKeyChars) > 0 {
170-
return fmt.Errorf("%w: invalid characters: %s", ErrAPIKeyFormat, strings.Join(invalidAPIKeyChars, ", "))
171-
}
167+
172168
return nil
173169
}
174170

pkg/datadog/config/config_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ func TestValidate(t *testing.T) {
4646
},
4747
err: ErrUnsetAPIKey.Error(),
4848
},
49-
{
50-
name: "invalid format api::key",
51-
cfg: &Config{
52-
API: APIConfig{Key: "'aaaaaaa"},
53-
},
54-
err: ErrAPIKeyFormat.Error(),
55-
},
5649
{
5750
name: "invalid hostname",
5851
cfg: &Config{

0 commit comments

Comments
 (0)