Skip to content

Commit f0545dd

Browse files
committed
[confmap] Restrict implicit type conversion
1 parent fc28929 commit f0545dd

File tree

58 files changed

+198
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+198
-53
lines changed

cmd/mdatagen/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/gogo/protobuf v1.3.2 // indirect
3131
github.com/golang/protobuf v1.5.3 // indirect
3232
github.com/google/uuid v1.6.0 // indirect
33+
github.com/hashicorp/go-version v1.6.0 // indirect
3334
github.com/json-iterator/go v1.1.12 // indirect
3435
github.com/knadh/koanf/maps v0.1.1 // indirect
3536
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
@@ -44,6 +45,7 @@ require (
4445
github.com/prometheus/common v0.48.0 // indirect
4546
github.com/prometheus/procfs v0.12.0 // indirect
4647
go.opentelemetry.io/collector/config/configtelemetry v0.97.0 // indirect
48+
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
4749
go.opentelemetry.io/otel v1.24.0 // indirect
4850
go.opentelemetry.io/otel/exporters/prometheus v0.46.0 // indirect
4951
go.opentelemetry.io/otel/sdk v1.24.0 // indirect

cmd/mdatagen/go.sum

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

component/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ require (
3030
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
3131
github.com/gogo/protobuf v1.3.2 // indirect
3232
github.com/golang/protobuf v1.5.3 // indirect
33+
github.com/hashicorp/go-version v1.6.0 // indirect
3334
github.com/knadh/koanf/maps v0.1.1 // indirect
3435
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
3536
github.com/knadh/koanf/v2 v2.1.0 // indirect
3637
github.com/mitchellh/copystructure v1.2.0 // indirect
3738
github.com/mitchellh/reflectwalk v1.0.2 // indirect
3839
github.com/pmezard/go-difflib v1.0.0 // indirect
3940
github.com/prometheus/procfs v0.12.0 // indirect
41+
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
4042
golang.org/x/net v0.23.0 // indirect
4143
golang.org/x/sys v0.18.0 // indirect
4244
golang.org/x/text v0.14.0 // indirect

component/go.sum

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

config/configauth/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
1616
github.com/gogo/protobuf v1.3.2 // indirect
1717
github.com/golang/protobuf v1.5.3 // indirect
18+
github.com/hashicorp/go-version v1.6.0 // indirect
1819
github.com/knadh/koanf/maps v0.1.1 // indirect
1920
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
2021
github.com/knadh/koanf/v2 v2.1.0 // indirect
@@ -23,6 +24,7 @@ require (
2324
github.com/pmezard/go-difflib v1.0.0 // indirect
2425
go.opentelemetry.io/collector/config/configtelemetry v0.97.0 // indirect
2526
go.opentelemetry.io/collector/confmap v0.97.0 // indirect
27+
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
2628
go.opentelemetry.io/collector/pdata v1.4.0 // indirect
2729
go.opentelemetry.io/otel v1.24.0 // indirect
2830
go.opentelemetry.io/otel/metric v1.24.0 // indirect

config/configauth/go.sum

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

config/configopaque/go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ require (
1212
require (
1313
github.com/davecgh/go-spew v1.1.1 // indirect
1414
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
15+
github.com/hashicorp/go-version v1.6.0 // indirect
1516
github.com/knadh/koanf/maps v0.1.1 // indirect
1617
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
1718
github.com/knadh/koanf/v2 v2.1.0 // indirect
18-
github.com/kr/pretty v0.3.1 // indirect
1919
github.com/mitchellh/copystructure v1.2.0 // indirect
2020
github.com/mitchellh/reflectwalk v1.0.2 // indirect
2121
github.com/pmezard/go-difflib v1.0.0 // indirect
22-
github.com/rogpeppe/go-internal v1.10.0 // indirect
22+
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
2323
go.uber.org/multierr v1.11.0 // indirect
2424
go.uber.org/zap v1.27.0 // indirect
25-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
2625
)
2726

2827
replace go.opentelemetry.io/collector/confmap => ../../confmap

config/configopaque/go.sum

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

config/configtls/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010

1111
require (
1212
github.com/davecgh/go-spew v1.1.1 // indirect
13-
github.com/kr/text v0.2.0 // indirect
1413
github.com/pmezard/go-difflib v1.0.0 // indirect
1514
golang.org/x/sys v0.14.0 // indirect
1615
gopkg.in/yaml.v3 v3.0.1 // indirect

config/configtls/go.sum

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

confmap/confmap.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,22 @@ import (
1717
"github.com/knadh/koanf/v2"
1818

1919
encoder "go.opentelemetry.io/collector/confmap/internal/mapstructure"
20+
"go.opentelemetry.io/collector/featuregate"
2021
)
2122

2223
const (
2324
// KeyDelimiter is used as the default key delimiter in the default koanf instance.
2425
KeyDelimiter = "::"
26+
// DisableWeaklyTyped is the feature gate name that that disables implicit type conversions in confmap.
27+
DisableWeaklyTyped = "confmap.DisableWeaklyTypedInput"
28+
)
29+
30+
// DisableWeaklyTypedfeatureGate is the feature gate that disables implicit type conversions in confmap.
31+
var DisableWeaklyTypedfeatureGate = featuregate.GlobalRegistry().MustRegister(
32+
DisableWeaklyTyped,
33+
featuregate.StageBeta,
34+
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector/issues/9532"),
35+
featuregate.WithRegisterDescription("disables weakly typed input option in confmap"),
2536
)
2637

2738
// New creates a new empty confmap.Conf instance.
@@ -148,11 +159,10 @@ func (l *Conf) ToStringMap() map[string]any {
148159
// encoding.TextUnmarshaler. Allows custom unmarshaling for structs implementing confmap.Unmarshaler.
149160
func decodeConfig(m *Conf, result any, errorUnused bool) error {
150161
dc := &mapstructure.DecoderConfig{
151-
ErrorUnused: errorUnused,
152-
Result: result,
153-
TagName: "mapstructure",
154-
WeaklyTypedInput: true,
155-
MatchName: caseSensitiveMatchName,
162+
ErrorUnused: errorUnused,
163+
Result: result,
164+
TagName: "mapstructure",
165+
MatchName: caseSensitiveMatchName,
156166
DecodeHook: mapstructure.ComposeDecodeHookFunc(
157167
expandNilStructPointersHookFunc(),
158168
mapstructure.StringToSliceHookFunc(","),
@@ -166,6 +176,9 @@ func decodeConfig(m *Conf, result any, errorUnused bool) error {
166176
zeroSliceHookFunc(),
167177
),
168178
}
179+
if !DisableWeaklyTypedfeatureGate.IsEnabled() {
180+
dc.WeaklyTypedInput = true
181+
}
169182
decoder, err := mapstructure.NewDecoder(dc)
170183
if err != nil {
171184
return err

confmap/converter/expandconverter/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ require (
1212
require (
1313
github.com/davecgh/go-spew v1.1.1 // indirect
1414
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
15+
github.com/hashicorp/go-version v1.6.0 // indirect
1516
github.com/knadh/koanf/maps v0.1.1 // indirect
1617
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
1718
github.com/knadh/koanf/v2 v2.1.0 // indirect
1819
github.com/mitchellh/copystructure v1.2.0 // indirect
1920
github.com/mitchellh/reflectwalk v1.0.2 // indirect
2021
github.com/pmezard/go-difflib v1.0.0 // indirect
22+
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
2123
go.uber.org/multierr v1.11.0 // indirect
2224
gopkg.in/yaml.v3 v3.0.1 // indirect
2325
)

0 commit comments

Comments
 (0)