Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure: Expose Azure settings to external plugins #34484

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/plugins/backendplugin/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func (m *manager) Register(pluginID string, factory backendplugin.PluginFactoryF
}

hostEnv = append(hostEnv, m.getAWSEnvironmentVariables()...)
hostEnv = append(hostEnv, m.getAzureEnvironmentVariables()...)

pluginSettings := getPluginSettings(pluginID, m.Cfg)
env := pluginSettings.ToEnv("GF_PLUGIN", hostEnv)

Expand Down Expand Up @@ -164,6 +166,21 @@ func (m *manager) getAWSEnvironmentVariables() []string {
return variables
}

func (m *manager) getAzureEnvironmentVariables() []string {
variables := []string{}
if m.Cfg.Azure.Cloud != "" {
variables = append(variables, "AZURE_CLOUD="+m.Cfg.Azure.Cloud)
}
if m.Cfg.Azure.ManagedIdentityClientId != "" {
variables = append(variables, "AZURE_MANAGED_IDENTITY_CLIENT_ID="+m.Cfg.Azure.ManagedIdentityClientId)
}
if m.Cfg.Azure.ManagedIdentityEnabled {
variables = append(variables, "AZURE_MANAGED_IDENTITY_ENABLED=true")
}

return variables
}

//nolint: staticcheck // plugins.DataPlugin deprecated
func (m *manager) GetDataPlugin(pluginID string) interface{} {
p, _ := m.Get(pluginID)
Expand Down
30 changes: 26 additions & 4 deletions pkg/plugins/backendplugin/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ func TestManager(t *testing.T) {
})

t.Run("Should provide expected host environment variables", func(t *testing.T) {
require.Len(t, ctx.env, 4)
require.EqualValues(t, []string{"GF_VERSION=7.0.0", "GF_EDITION=Open Source", fmt.Sprintf("%s=true", awsds.AssumeRoleEnabledEnvVarKeyName), fmt.Sprintf("%s=keys,credentials", awsds.AllowedAuthProvidersEnvVarKeyName)}, ctx.env)
require.Len(t, ctx.env, 7)
require.EqualValues(t, []string{
"GF_VERSION=7.0.0",
"GF_EDITION=Open Source",
fmt.Sprintf("%s=true", awsds.AssumeRoleEnabledEnvVarKeyName),
fmt.Sprintf("%s=keys,credentials", awsds.AllowedAuthProvidersEnvVarKeyName),
"AZURE_CLOUD=AzureCloud",
"AZURE_MANAGED_IDENTITY_CLIENT_ID=client-id",
"AZURE_MANAGED_IDENTITY_ENABLED=true"},
ctx.env)
})

t.Run("When manager runs should start and stop plugin", func(t *testing.T) {
Expand Down Expand Up @@ -282,8 +290,18 @@ func TestManager(t *testing.T) {
require.NoError(t, err)

t.Run("Should provide expected host environment variables", func(t *testing.T) {
require.Len(t, ctx.env, 6)
require.EqualValues(t, []string{"GF_VERSION=7.0.0", "GF_EDITION=Enterprise", "GF_ENTERPRISE_LICENSE_PATH=/license.txt", "GF_ENTERPRISE_LICENSE_TEXT=testtoken", fmt.Sprintf("%s=true", awsds.AssumeRoleEnabledEnvVarKeyName), fmt.Sprintf("%s=keys,credentials", awsds.AllowedAuthProvidersEnvVarKeyName)}, ctx.env)
require.Len(t, ctx.env, 9)
require.EqualValues(t, []string{
"GF_VERSION=7.0.0",
"GF_EDITION=Enterprise",
"GF_ENTERPRISE_LICENSE_PATH=/license.txt",
"GF_ENTERPRISE_LICENSE_TEXT=testtoken",
fmt.Sprintf("%s=true", awsds.AssumeRoleEnabledEnvVarKeyName),
fmt.Sprintf("%s=keys,credentials", awsds.AllowedAuthProvidersEnvVarKeyName),
"AZURE_CLOUD=AzureCloud",
"AZURE_MANAGED_IDENTITY_CLIENT_ID=client-id",
"AZURE_MANAGED_IDENTITY_ENABLED=true"},
ctx.env)
})
})
})
Expand All @@ -304,6 +322,10 @@ func newManagerScenario(t *testing.T, managed bool, fn func(t *testing.T, ctx *m
cfg.AWSAllowedAuthProviders = []string{"keys", "credentials"}
cfg.AWSAssumeRoleEnabled = true

cfg.Azure.ManagedIdentityEnabled = true
cfg.Azure.Cloud = "AzureCloud"
cfg.Azure.ManagedIdentityClientId = "client-id"

license := &testLicensingService{}
validator := &testPluginRequestValidator{}
ctx := &managerScenarioCtx{
Expand Down