Plugins: Prevent passing host environment variables to plugin processes by default (#113412)

* remove pluginsSkipHostEnvVars toggle

* fix tests
This commit is contained in:
Will Browne
2025-11-13 15:31:57 +00:00
committed by GitHub
parent ae8a8cf16e
commit f041563df3
11 changed files with 188 additions and 212 deletions
@@ -144,65 +144,39 @@ func Test_configureAppChildPlugin(t *testing.T) {
func TestSkipEnvVarsDecorateFunc(t *testing.T) {
const pluginID = "plugin-id"
t.Run("config field is false", func(t *testing.T) {
f := SkipHostEnvVarsDecorateFunc(&config.PluginManagementCfg{
Features: config.Features{SkipHostEnvVarsEnabled: false},
})
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
require.NoError(t, err)
require.False(t, p.SkipHostEnvVars)
})
t.Run("config field is true", func(t *testing.T) {
t.Run("no plugin settings should set SkipHostEnvVars to true", func(t *testing.T) {
for _, tc := range []struct {
name string
forwardHostEnvVars []string
expSkipHostEnvVars bool
}{
{
name: "plugin id not present in forwardHostEnvVars should set SkipHostEnvVars to true (empty)",
forwardHostEnvVars: []string{},
expSkipHostEnvVars: true,
},
{
name: "plugin id not present in forwardHostEnvVars should set SkipHostEnvVars to true (other id)",
forwardHostEnvVars: []string{"other-id", "yet-another-id"},
expSkipHostEnvVars: true,
},
{
name: "plugin id in forwardHostEnvVars should set SkipHostEnvVars to false (only)",
forwardHostEnvVars: []string{pluginID},
expSkipHostEnvVars: false,
},
{
name: "plugin id in forwardHostEnvVars should set SkipHostEnvVars to false (with other)",
forwardHostEnvVars: []string{"a-plugin", pluginID, "other-id"},
expSkipHostEnvVars: false,
},
} {
t.Run(tc.name, func(t *testing.T) {
f := SkipHostEnvVarsDecorateFunc(&config.PluginManagementCfg{
Features: config.Features{SkipHostEnvVarsEnabled: true},
ForwardHostEnvVars: tc.forwardHostEnvVars,
})
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
require.NoError(t, err)
require.True(t, p.SkipHostEnvVars)
require.Equal(t, tc.expSkipHostEnvVars, p.SkipHostEnvVars)
})
t.Run("plugin setting", func(t *testing.T) {
for _, tc := range []struct {
name string
forwardHostEnvVars []string
expSkipHostEnvVars bool
}{
{
name: "plugin id not present in forwardHostEnvVars should set SkipHostEnvVars to true (empty)",
forwardHostEnvVars: []string{},
expSkipHostEnvVars: true,
},
{
name: "plugin id not present in forwardHostEnvVars should set SkipHostEnvVars to true (other id)",
forwardHostEnvVars: []string{"other-id", "yet-another-id"},
expSkipHostEnvVars: true,
},
{
name: "plugin id in forwardHostEnvVars should set SkipHostEnvVars to false (only)",
forwardHostEnvVars: []string{pluginID},
expSkipHostEnvVars: false,
},
{
name: "plugin id in forwardHostEnvVars should set SkipHostEnvVars to false (with other)",
forwardHostEnvVars: []string{"a-plugin", pluginID, "other-id"},
expSkipHostEnvVars: false,
},
} {
t.Run(tc.name, func(t *testing.T) {
f := SkipHostEnvVarsDecorateFunc(&config.PluginManagementCfg{
Features: config.Features{
SkipHostEnvVarsEnabled: true,
},
ForwardHostEnvVars: tc.forwardHostEnvVars,
})
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
require.NoError(t, err)
require.Equal(t, tc.expSkipHostEnvVars, p.SkipHostEnvVars)
})
}
})
})
}
}