diff --git a/.chloggen/confmap-expandconverter-featuregate.yaml b/.chloggen/confmap-expandconverter-featuregate.yaml new file mode 100644 index 00000000000..19aac1af43e --- /dev/null +++ b/.chloggen/confmap-expandconverter-featuregate.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: expandconverter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Adds `confmap.allowEnvVarExpansion` feature gate to control use of $ENV syntax. + +# One or more tracking issues or pull requests related to the change +issues: [10144] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: Deprecates expandconverter + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/cmd/builder/internal/builder/templates/main.go.tmpl b/cmd/builder/internal/builder/templates/main.go.tmpl index f9964c5d5ec..e93843aa77b 100644 --- a/cmd/builder/internal/builder/templates/main.go.tmpl +++ b/cmd/builder/internal/builder/templates/main.go.tmpl @@ -24,6 +24,13 @@ func main() { Version: "{{ .Distribution.Version }}", } + var converterFactories []confmap.ConverterFactory + if otelcol.PreventEnvVarExpansionFeatureGate.IsEnabled() { + converterFactories = []confmap.ConverterFactory{ + expandconverter.NewFactory(), + } + } + set := otelcol.CollectorSettings{ BuildInfo: info, Factories: components, @@ -35,9 +42,7 @@ func main() { {{.Name}}.NewFactory(), {{- end}} }, - ConverterFactories: []confmap.ConverterFactory{ - expandconverter.NewFactory(), - }, + ConverterFactories: converterFactories, }, }, {{- end}} diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index beaeb912ee4..f95d460336a 100644 --- a/cmd/otelcorecol/main.go +++ b/cmd/otelcorecol/main.go @@ -24,6 +24,13 @@ func main() { Version: "0.100.0-dev", } + var converterFactories []confmap.ConverterFactory + if otelcol.PreventEnvVarExpansionFeatureGate.IsEnabled() { + converterFactories = []confmap.ConverterFactory{ + expandconverter.NewFactory(), + } + } + set := otelcol.CollectorSettings{ BuildInfo: info, Factories: components, @@ -36,9 +43,7 @@ func main() { httpsprovider.NewFactory(), yamlprovider.NewFactory(), }, - ConverterFactories: []confmap.ConverterFactory{ - expandconverter.NewFactory(), - }, + ConverterFactories: converterFactories, }, }, } diff --git a/confmap/converter/expandconverter/expand.go b/confmap/converter/expandconverter/expand.go index 98bc455d907..3a22743ed05 100644 --- a/confmap/converter/expandconverter/expand.go +++ b/confmap/converter/expandconverter/expand.go @@ -23,6 +23,10 @@ type converter struct { // NewFactory returns a factory for a confmap.Converter, // which expands all environment variables for a given confmap.Conf. +// +// Deprecated: [v0.101.0] The expand converter is deprecated, the collector will no longer support this style environment +// variable substitution by default. Use ${...} or ${env:...} instead. +// See https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/env-vars.md for more details. func NewFactory() confmap.ConverterFactory { return confmap.NewConverterFactory(newConverter) } diff --git a/otelcol/command_test.go b/otelcol/command_test.go index 69e1a943d2b..c2429d3fae1 100644 --- a/otelcol/command_test.go +++ b/otelcol/command_test.go @@ -73,7 +73,7 @@ func TestAddDefaultConfmapModules(t *testing.T) { ResolverSettings: confmap.ResolverSettings{}, }, } - flgs := flags(featuregate.NewRegistry()) + flgs := flags(featuregate.GlobalRegistry()) err := flgs.Parse([]string{"--config=otelcol-nop.yaml"}) require.NoError(t, err) diff --git a/otelcol/configprovider.go b/otelcol/configprovider.go index 477541fd4bd..d1943647d9f 100644 --- a/otelcol/configprovider.go +++ b/otelcol/configprovider.go @@ -14,6 +14,16 @@ import ( "go.opentelemetry.io/collector/confmap/provider/httpprovider" "go.opentelemetry.io/collector/confmap/provider/httpsprovider" "go.opentelemetry.io/collector/confmap/provider/yamlprovider" + "go.opentelemetry.io/collector/featuregate" +) + +// PreventEnvVarExpansionFeatureGate is the feature gate that controls whether the collector +// supports configuring the OpenTelemetry SDK via configuration +var PreventEnvVarExpansionFeatureGate = featuregate.GlobalRegistry().MustRegister( + "confmap.preventEnvVarExpansion", + featuregate.StageAlpha, + featuregate.WithRegisterDescription("controls whether the collector supports expanding $ENV in configuration"), + featuregate.WithRegisterFromVersion("v0.101.0"), ) // ConfigProvider provides the service configuration. @@ -132,6 +142,12 @@ func (cm *configProvider) GetConfmap(ctx context.Context) (*confmap.Conf, error) } func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings { + var converterFactories []confmap.ConverterFactory + if !PreventEnvVarExpansionFeatureGate.IsEnabled() { + converterFactories = []confmap.ConverterFactory{ + expandconverter.NewFactory(), + } + } return ConfigProviderSettings{ ResolverSettings: confmap.ResolverSettings{ URIs: uris, @@ -142,7 +158,7 @@ func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings { httpprovider.NewFactory(), httpsprovider.NewFactory(), }, - ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()}, + ConverterFactories: converterFactories, }, } }