Skip to content

Commit 6dd4976

Browse files
committed
Temporal fix for AC
1 parent 97a5c99 commit 6dd4976

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

controllers/om/automation_config.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121
// configuration which are merged into the `Deployment` object before sending it back to Ops Manager.
2222
// As of right now only support configuring LogRotate for monitoring and backup via dedicated endpoints.
2323
type AutomationConfig struct {
24-
Auth *Auth
25-
AgentSSL *AgentSSL
26-
Deployment Deployment
27-
Ldap *ldap.Ldap
24+
Auth *Auth
25+
AgentSSL *AgentSSL
26+
Deployment Deployment
27+
Ldap *ldap.Ldap
28+
OIDCProviderConfigs []oidc.ProviderConfig
2829
}
2930

3031
// Apply merges the state of all concrete structs into the Deployment (map[string]interface{})
@@ -60,6 +61,21 @@ func applyInto(a AutomationConfig, into *Deployment) error {
6061
(*into)["ldap"] = mergedLdap
6162
}
6263

64+
if _, ok := a.Deployment["oidcProviderConfigs"]; ok || len(a.OIDCProviderConfigs) > 0 {
65+
// TODO: this is not merged yet, but only overridden
66+
bytes, err := json.Marshal(a.OIDCProviderConfigs)
67+
if err != nil {
68+
return err
69+
}
70+
71+
dst := make([]map[string]interface{}, 0)
72+
err = json.Unmarshal(bytes, &dst)
73+
if err != nil {
74+
return err
75+
}
76+
(*into)["oidcProviderConfigs"] = dst
77+
}
78+
6379
return nil
6480
}
6581

@@ -228,8 +244,6 @@ type Auth struct {
228244
NewAutoPwd string `json:"newAutoPwd,omitempty"`
229245
// LdapGroupDN is required when enabling LDAP authz and agents authentication on $external
230246
LdapGroupDN string `json:"autoLdapGroupDN,omitempty"`
231-
// OIDCProviderConfigs is a list of OIDC provider configurations
232-
OIDCProviderConfigs []oidc.ProviderConfig `json:"oidcProviderConfigs,omitempty"`
233247
}
234248

235249
// IsEnabled is a convenience function to aid readability
@@ -436,6 +450,19 @@ func BuildAutomationConfigFromDeployment(deployment Deployment) (*AutomationConf
436450
finalAutomationConfig.Ldap = acLdap
437451
}
438452

453+
oidcSlice, ok := deployment["oidcProviderConfigs"]
454+
if ok {
455+
oidcMarshalled, err := json.Marshal(oidcSlice)
456+
if err != nil {
457+
return nil, err
458+
}
459+
providerConfigs := make([]oidc.ProviderConfig, 0)
460+
if err := json.Unmarshal(oidcMarshalled, &providerConfigs); err != nil {
461+
return nil, err
462+
}
463+
finalAutomationConfig.OIDCProviderConfigs = providerConfigs
464+
}
465+
439466
return finalAutomationConfig, nil
440467
}
441468

controllers/operator/authentication/oidc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (o *oidcAuthMechanism) EnableDeploymentAuthentication(conn om.Connection, o
3636
ac.Auth.DeploymentAuthMechanisms = append(ac.Auth.DeploymentAuthMechanisms, string(MongoDBOIDC))
3737
}
3838
// TODO merge configs with existing ones, and don't overwrite read only values
39-
ac.Auth.OIDCProviderConfigs = opts.OIDCProviderConfigs
39+
ac.OIDCProviderConfigs = opts.OIDCProviderConfigs
4040

4141
return nil
4242
}, log)
@@ -45,7 +45,7 @@ func (o *oidcAuthMechanism) EnableDeploymentAuthentication(conn om.Connection, o
4545
func (o *oidcAuthMechanism) DisableDeploymentAuthentication(conn om.Connection, log *zap.SugaredLogger) error {
4646
return conn.ReadUpdateAutomationConfig(func(ac *om.AutomationConfig) error {
4747
ac.Auth.DeploymentAuthMechanisms = stringutil.Remove(ac.Auth.DeploymentAuthMechanisms, string(MongoDBOIDC))
48-
ac.Auth.OIDCProviderConfigs = nil
48+
ac.OIDCProviderConfigs = nil
4949

5050
return nil
5151
}, log)
@@ -56,7 +56,7 @@ func (o *oidcAuthMechanism) IsAgentAuthenticationConfigured(*om.AutomationConfig
5656
}
5757

5858
func (o *oidcAuthMechanism) IsDeploymentAuthenticationConfigured(ac *om.AutomationConfig, opts Options) bool {
59-
return stringutil.Contains(ac.Auth.DeploymentAuthMechanisms, string(MongoDBOIDC)) && oidcProviderConfigsEqual(ac.Auth.OIDCProviderConfigs, opts.OIDCProviderConfigs)
59+
return stringutil.Contains(ac.Auth.DeploymentAuthMechanisms, string(MongoDBOIDC)) && oidcProviderConfigsEqual(ac.OIDCProviderConfigs, opts.OIDCProviderConfigs)
6060
}
6161

6262
func oidcProviderConfigsEqual(lhs []oidc.ProviderConfig, rhs []oidc.ProviderConfig) bool {

controllers/operator/authentication/oidc_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestOIDC_EnableDeploymentAuthentication(t *testing.T) {
1515
conn := om.NewMockedOmConnection(om.NewDeployment())
1616
ac, err := conn.ReadAutomationConfig()
1717
require.NoError(t, err)
18-
assert.Empty(t, ac.Auth.OIDCProviderConfigs)
18+
assert.Empty(t, ac.OIDCProviderConfigs)
1919
assert.Empty(t, ac.Auth.DeploymentAuthMechanisms)
2020

2121
providerConfigs := []oidc.ProviderConfig{
@@ -55,7 +55,7 @@ func TestOIDC_EnableDeploymentAuthentication(t *testing.T) {
5555
ac, err = conn.ReadAutomationConfig()
5656
require.NoError(t, err)
5757
assert.Contains(t, ac.Auth.DeploymentAuthMechanisms, string(MongoDBOIDC))
58-
assert.Equal(t, providerConfigs, ac.Auth.OIDCProviderConfigs)
58+
assert.Equal(t, providerConfigs, ac.OIDCProviderConfigs)
5959

6060
configured = MongoDBOIDCMechanism.IsDeploymentAuthenticationConfigured(ac, opts)
6161
assert.True(t, configured)
@@ -70,7 +70,7 @@ func TestOIDC_EnableDeploymentAuthentication(t *testing.T) {
7070
assert.False(t, configured)
7171

7272
assert.NotContains(t, ac.Auth.DeploymentAuthMechanisms, string(MongoDBOIDC))
73-
assert.Empty(t, ac.Auth.OIDCProviderConfigs)
73+
assert.Empty(t, ac.OIDCProviderConfigs)
7474
}
7575

7676
func TestOIDC_EnableAgentAuthentication(t *testing.T) {

0 commit comments

Comments
 (0)