Skip to content

CLOUDP-314916: OIDC e2e test single cluster #55

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

Merged
merged 97 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
f0b6a96
CRD changes
MaciejKaras Apr 25, 2025
d344589
Authorization package refactor - part 1
MaciejKaras Apr 24, 2025
99479f1
Authorization package refactor - part 2
MaciejKaras Apr 24, 2025
7c23143
Added validation logic + tests
MaciejKaras Apr 25, 2025
8cba1c1
Add URL test validation
MaciejKaras Apr 27, 2025
2528892
Fixed MDB Multi code
MaciejKaras Apr 27, 2025
1eaf9ab
Merge branch 'feature/mk-authorization-refactor' into feature/mk-oidc…
MaciejKaras Apr 27, 2025
6d27458
Propagating CRD values
MaciejKaras Apr 17, 2025
81e6107
Moved OIDCProviderConfigs to Deployment.Auth where it belongs
MaciejKaras Apr 25, 2025
024fa63
Fixed migrating to mongodb-kubernetes repository
MaciejKaras Apr 27, 2025
7a53fd7
Fixed unit tests + CRD generation
MaciejKaras Apr 27, 2025
97a5c99
Add unit tests
MaciejKaras Apr 27, 2025
6dd4976
Temporal fix for AC
MaciejKaras Apr 27, 2025
8b34222
Fix kubebuilder validation rules
MaciejKaras Apr 29, 2025
1cbe97a
Fixes for util.ParseURL
MaciejKaras Apr 30, 2025
0ce0874
Proper OIDC AC merging
MaciejKaras Apr 29, 2025
e4cfb11
Unit test fixes
MaciejKaras Apr 30, 2025
1667045
Fixed issue with disabling OIDC
MaciejKaras Apr 30, 2025
e882a8c
Resolve review comments
MaciejKaras Apr 30, 2025
8f5ff0a
Added getMechanismByName() func and removed global variables
MaciejKaras Apr 30, 2025
e533976
Review fixes
MaciejKaras May 5, 2025
279886f
Merge branch 'master' into feature/mk-oidc-crd-validations
MaciejKaras May 5, 2025
a8306a7
Add one more validation test
MaciejKaras May 5, 2025
866d6ae
Merge branch 'master' into feature/mk-authorization-refactor
MaciejKaras May 5, 2025
09e4628
Merge branch 'feature/mk-oidc-crd-validations' into feature/mk-oidc-c…
MaciejKaras May 5, 2025
23de25e
Merge branch 'feature/mk-authorization-refactor' into feature/mk-oidc…
MaciejKaras May 5, 2025
bcc1136
Fix bug
lucian-tosa May 9, 2025
2c08662
Merge remote-tracking branch 'origin/master' into feature/mk-oidc-crd…
lucian-tosa May 9, 2025
68750a4
Fix linter
lucian-tosa May 9, 2025
e7d3d06
Merge branch 'master' into feature/mk-oidc-crd-propagation
lucian-tosa May 9, 2025
2b306f5
remove refs
anandsyncs May 9, 2025
e4743bf
add more validations
anandsyncs May 18, 2025
d6e6ce7
lint fix
anandsyncs May 18, 2025
fe5cdef
Merge branch 'master' into anandsingh/oidc-e2e-tests
anandsyncs May 18, 2025
db52705
lint fix
anandsyncs May 18, 2025
2fb5a96
Merge remote-tracking branch 'origin/anandsingh/oidc-e2e-tests' into …
anandsyncs May 18, 2025
efacc00
make sure env vars are included
anandsyncs May 19, 2025
715c627
Merge branch 'master' into anandsingh/oidc-e2e-tests
anandsyncs May 19, 2025
764d3d5
Merge branch 'master' into feature/mk-oidc-crd-propagation
anandsyncs May 19, 2025
21647a0
Merge branch 'feature/mk-oidc-crd-propagation' into anandsingh/oidc-e…
anandsyncs May 19, 2025
63927a0
upgrade pymongo
anandsyncs May 19, 2025
bec3f6b
Merge remote-tracking branch 'origin/anandsingh/oidc-e2e-tests' into …
anandsyncs May 19, 2025
1b82b29
env vars tracer
anandsyncs May 20, 2025
ce6eb85
Merge branch 'master' into anandsingh/oidc-e2e-tests
anandsyncs May 20, 2025
9d2a304
env vars tracer
anandsyncs May 20, 2025
0b86f84
Merge remote-tracking branch 'origin/anandsingh/oidc-e2e-tests' into …
anandsyncs May 20, 2025
cb7cd70
fix lint
anandsyncs May 20, 2025
8da5102
env vars tracer
anandsyncs May 20, 2025
890fb13
env vars tracer
anandsyncs May 20, 2025
8b396d6
change version in the config
anandsyncs May 20, 2025
a5e357b
run separate e2e tests for different oidc flavors
anandsyncs May 20, 2025
b4db2e6
lint-fix
anandsyncs May 20, 2025
db45441
add sharded cluster tests to evergreen run
anandsyncs May 21, 2025
1bce820
Merge branch 'master' into feature/mk-oidc-crd-propagation
anandsyncs May 22, 2025
f7ec0f1
implement the authentication_mechanism interface correctly for oidc
anandsyncs May 22, 2025
c1f54a5
lint-fix
anandsyncs May 22, 2025
f271051
Merge branch 'master' into feature/mk-oidc-crd-propagation
anandsyncs May 22, 2025
390998c
Merge branch 'feature/mk-oidc-crd-propagation' into anandsingh/oidc-e…
anandsyncs May 22, 2025
3eed7fa
Merge branch 'master' into anandsingh/oidc-e2e-tests
anandsyncs May 22, 2025
bca4aa2
fix duplicate issuer uri problem
anandsyncs May 22, 2025
8dc9bd5
Merge remote-tracking branch 'origin/anandsingh/oidc-e2e-tests' into …
anandsyncs May 22, 2025
d5f406a
cleanup
anandsyncs May 22, 2025
4593b6f
Merge branch 'feature/mk-oidc-crd-propagation' into anandsingh/oidc-e…
anandsyncs May 22, 2025
e6ed367
update external auth validation
anandsyncs May 22, 2025
8d8bcdc
Merge branch 'feature/mk-oidc-crd-propagation' into anandsingh/oidc-e…
anandsyncs May 22, 2025
6ffe3f4
fix clean up error
anandsyncs May 23, 2025
1190494
Merge branch 'anandsingh/oidc-e2e-tests' of github.com:mongodb/mongod…
anandsyncs May 23, 2025
727979c
remove sharded cluster workforce test
anandsyncs May 23, 2025
0d8fd6e
Webhook validation tests
lucian-tosa May 23, 2025
0f1b385
assert cluster running state before asserting automation config
anandsyncs May 23, 2025
2d621b3
Merge branch 'feature/mk-oidc-crd-propagation' into anandsingh/oidc-e…
anandsyncs May 26, 2025
39c6702
Merge branch 'master' into anandsingh/oidc-e2e-tests
anandsyncs May 26, 2025
86f0be0
lint fix
anandsyncs May 26, 2025
19f161b
Merge branch 'master' into feature/mk-oidc-crd-propagation
anandsyncs May 26, 2025
26e24a0
remove default value for GroupsClaim
anandsyncs May 26, 2025
7257b4e
remove default value for GroupsClaim
anandsyncs May 26, 2025
ed2748d
Merge branch 'feature/mk-oidc-crd-propagation' into anandsingh/oidc-e…
anandsyncs May 26, 2025
1be8af8
Merge branch 'master' into anandsingh/oidc-e2e-tests
anandsyncs May 26, 2025
30bb749
remove default value for GroupsClaim from tests
anandsyncs May 26, 2025
5df3e5c
Merge branch 'master' into feature/mk-oidc-crd-propagation
anandsyncs May 26, 2025
9d56078
fix test
anandsyncs May 26, 2025
0b03de4
Merge branch 'feature/mk-oidc-crd-propagation' into anandsingh/oidc-e…
anandsyncs May 26, 2025
00adfc7
remove incorrect field
anandsyncs May 27, 2025
95c58de
Merge remote-tracking branch 'origin/anandsingh/oidc-e2e-tests' into …
anandsyncs May 27, 2025
a29f737
add explanation for manual aws setup
anandsyncs May 27, 2025
09409f1
lint fix
anandsyncs May 27, 2025
aad26e6
Update controllers/operator/authentication/oidc.go
anandsyncs May 28, 2025
49cb8ce
Merge branch 'master' into anandsingh/oidc-e2e-tests
anandsyncs May 28, 2025
05903d5
fix typo
anandsyncs May 28, 2025
13e76a3
Moved `mongoDBOIDCMechanism` to oidc_test.go as local variable
MaciejKaras May 29, 2025
646bec6
Removed `util.MergoDelete` from oidc implementation
MaciejKaras May 29, 2025
3e2839e
unit test fixes
MaciejKaras May 29, 2025
d0c2844
Merge branch 'master' into feature/mk-oidc-crd-propagation
anandsyncs May 30, 2025
8362cfb
Merge branch 'feature/mk-oidc-crd-propagation' into anandsingh/oidc-e…
anandsyncs May 30, 2025
1e91d2f
review fixes
MaciejKaras Jun 2, 2025
b9b58e8
Merge branch 'master' into anandsingh/oidc-e2e-tests
MaciejKaras Jun 2, 2025
0035c47
Fix e2e tests after master merge
MaciejKaras Jun 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .evergreen-functions.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
variables:
- &e2e_include_expansions_in_env
include_expansions_in_env:
- cognito_user_pool_id
- cognito_workload_federation_client_id
- cognito_user_name
- cognito_workload_federation_client_secret
- cognito_user_password
- cognito_workload_url
- cognito_workload_user_id
- ARTIFACTORY_PASSWORD
- ARTIFACTORY_USERNAME
- GRS_PASSWORD
Expand Down
26 changes: 26 additions & 0 deletions .evergreen-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,32 @@ tasks:
commands:
- func: e2e_test

# OIDC tests
- name: e2e_replica_set_oidc_m2m_group
tags: [ "patch-run" ]
commands:
- func: e2e_test

- name: e2e_replica_set_oidc_m2m_user
tags: [ "patch-run" ]
commands:
- func: e2e_test

- name: e2e_replica_set_oidc_workforce
tags: [ "patch-run" ]
commands:
- func: e2e_test

- name: e2e_sharded_cluster_oidc_m2m_group
tags: [ "patch-run" ]
commands:
- func: e2e_test

- name: e2e_sharded_cluster_oidc_m2m_user
tags: [ "patch-run" ]
commands:
- func: e2e_test

- name: e2e_search_community_basic
tags: ["patch-run"]
commands:
Expand Down
6 changes: 6 additions & 0 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,12 @@ task_groups:
- e2e_replica_set_pv_resize
- e2e_sharded_cluster_pv_resize
- e2e_community_and_meko_replicaset_scale
# OIDC test group
- e2e_replica_set_oidc_m2m_group
- e2e_replica_set_oidc_m2m_user
- e2e_replica_set_oidc_workforce
- e2e_sharded_cluster_oidc_m2m_group
- e2e_sharded_cluster_oidc_m2m_user
<<: *teardown_group

# this task group contains just a one task, which is smoke testing whether the operator
Expand Down
6 changes: 3 additions & 3 deletions api/v1/mdb/mongodb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ func (s *Security) IsOIDCEnabled() bool {
if s == nil || s.Authentication == nil || !s.Authentication.Enabled {
return false
}

return s.Authentication.IsOIDCEnabled()
}

Expand Down Expand Up @@ -1092,9 +1093,8 @@ type OIDCProviderConfig struct {
// The identifier of the claim that includes the principal's IdP user group membership information.
// Accept the default value unless your IdP uses a different claim, or you need a custom claim.
// Required when selected GroupMembership as the authorization type, ignored otherwise
// +kubebuilder:default=groups
// +kubebuilder:validation:Optional
GroupsClaim string `json:"groupsClaim,omitempty"`
GroupsClaim *string `json:"groupsClaim"`

// Configure single-sign-on for human user access to Ops Manager deployments with Workforce Identity Federation.
// For programmatic, application access to Ops Manager deployments use Workload Identity Federation.
Expand All @@ -1106,7 +1106,7 @@ type OIDCProviderConfig struct {
// registered with an external Identity Provider.
// Required when selected Workforce Identity Federation authorization method
// +kubebuilder:validation:Optional
ClientId string `json:"clientId,omitempty"`
ClientId *string `json:"clientId"`

// Tokens that give users permission to request data from the authorization endpoint.
// Only used for Workforce Identity Federation authorization method
Expand Down
8 changes: 4 additions & 4 deletions api/v1/mdb/mongodb_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ func oidcProviderConfigIssuerURIValidator(config OIDCProviderConfig) func(DbComm
func oidcProviderConfigClientIdValidator(config OIDCProviderConfig) func(DbCommonSpec) v1.ValidationResult {
return func(_ DbCommonSpec) v1.ValidationResult {
if config.AuthorizationMethod == OIDCAuthorizationMethodWorkforceIdentityFederation {
if config.ClientId == "" {
if config.ClientId == nil || *config.ClientId == "" {
return v1.ValidationError("ClientId has to be specified in OIDC provider config %q with Workforce Identity Federation", config.ConfigurationName)
}
} else if config.AuthorizationMethod == OIDCAuthorizationMethodWorkloadIdentityFederation {
if config.ClientId != "" {
if config.ClientId != nil {
return v1.ValidationWarning("ClientId will be ignored in OIDC provider config %q with Workload Identity Federation", config.ConfigurationName)
}
}
Expand All @@ -280,11 +280,11 @@ func oidcProviderConfigRequestedScopesValidator(config OIDCProviderConfig) func(
func oidcProviderConfigAuthorizationTypeValidator(config OIDCProviderConfig) func(DbCommonSpec) v1.ValidationResult {
return func(_ DbCommonSpec) v1.ValidationResult {
if config.AuthorizationType == OIDCAuthorizationTypeGroupMembership {
if config.GroupsClaim == "" {
if config.GroupsClaim == nil || *config.GroupsClaim == "" {
return v1.ValidationError("GroupsClaim has to be specified in OIDC provider config %q when using Group Membership authorization", config.ConfigurationName)
}
} else if config.AuthorizationType == OIDCAuthorizationTypeUserID {
if config.GroupsClaim != "" {
if config.GroupsClaim != nil {
return v1.ValidationWarning("GroupsClaim will be ignored in OIDC provider config %q when using User ID authorization", config.ConfigurationName)
}
}
Expand Down
20 changes: 10 additions & 10 deletions api/v1/mdb/mongodb_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ func TestOIDCAuthValidation(t *testing.T) {
ConfigurationName: "provider",
IssuerURI: "https://example1.com",
AuthorizationMethod: OIDCAuthorizationMethodWorkforceIdentityFederation,
ClientId: "clientId1",
ClientId: ptr.To("clientId1"),
},
{
ConfigurationName: "provider",
IssuerURI: "https://example2.com",
AuthorizationMethod: OIDCAuthorizationMethodWorkforceIdentityFederation,
ClientId: "clientId2",
ClientId: ptr.To("clientId2"),
},
},
},
Expand All @@ -281,13 +281,13 @@ func TestOIDCAuthValidation(t *testing.T) {
ConfigurationName: "test-provider1",
IssuerURI: "https://example1.com",
AuthorizationMethod: OIDCAuthorizationMethodWorkforceIdentityFederation,
ClientId: "clientId1",
ClientId: ptr.To("clientId1"),
},
{
ConfigurationName: "test-provider2",
IssuerURI: "https://example2.com",
AuthorizationMethod: OIDCAuthorizationMethodWorkforceIdentityFederation,
ClientId: "clientId2",
ClientId: ptr.To("clientId2"),
},
},
},
Expand All @@ -304,7 +304,7 @@ func TestOIDCAuthValidation(t *testing.T) {
ConfigurationName: "test-provider-workforce1",
IssuerURI: "https://example1.com",
AuthorizationMethod: OIDCAuthorizationMethodWorkforceIdentityFederation,
ClientId: "clientId1",
ClientId: ptr.To("clientId1"),
},
{
ConfigurationName: "test-provider-workload2",
Expand Down Expand Up @@ -376,7 +376,7 @@ func TestOIDCAuthValidation(t *testing.T) {
ConfigurationName: "test-provider",
IssuerURI: "https://example.com",
AuthorizationMethod: OIDCAuthorizationMethodWorkloadIdentityFederation,
ClientId: "clientId",
ClientId: ptr.To("clientId"),
},
},
},
Expand Down Expand Up @@ -410,7 +410,7 @@ func TestOIDCAuthValidation(t *testing.T) {
ConfigurationName: "test-provider1",
IssuerURI: "https://example.com",
AuthorizationType: OIDCAuthorizationTypeGroupMembership,
GroupsClaim: "groups",
GroupsClaim: ptr.To("groups"),
},
{
ConfigurationName: "test-provider2",
Expand All @@ -432,7 +432,7 @@ func TestOIDCAuthValidation(t *testing.T) {
ConfigurationName: "test-provider1",
IssuerURI: "https://example.com",
AuthorizationType: OIDCAuthorizationTypeUserID,
GroupsClaim: "groups",
GroupsClaim: ptr.To("groups"),
UserClaim: "sub",
},
{
Expand All @@ -456,13 +456,13 @@ func TestOIDCAuthValidation(t *testing.T) {
ConfigurationName: "test-provider1",
IssuerURI: "https://example.com",
AuthorizationType: OIDCAuthorizationTypeGroupMembership,
GroupsClaim: "groups",
GroupsClaim: ptr.To("groups"),
},
{
ConfigurationName: "test-provider2",
IssuerURI: "https://example.com",
AuthorizationType: OIDCAuthorizationTypeGroupMembership,
GroupsClaim: "groups",
GroupsClaim: ptr.To("groups"),
},
},
},
Expand Down
37 changes: 37 additions & 0 deletions api/v1/mdb/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/crd/bases/mongodb.com_mongodb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,6 @@ spec:
pattern: ^[a-zA-Z0-9-_]+$
type: string
groupsClaim:
default: groups
description: |-
The identifier of the claim that includes the principal's IdP user group membership information.
Accept the default value unless your IdP uses a different claim, or you need a custom claim.
Expand Down
1 change: 0 additions & 1 deletion config/crd/bases/mongodb.com_mongodbmulticluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ spec:
pattern: ^[a-zA-Z0-9-_]+$
type: string
groupsClaim:
default: groups
description: |-
The identifier of the claim that includes the principal's IdP user group membership information.
Accept the default value unless your IdP uses a different claim, or you need a custom claim.
Expand Down
1 change: 0 additions & 1 deletion config/crd/bases/mongodb.com_opsmanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,6 @@ spec:
pattern: ^[a-zA-Z0-9-_]+$
type: string
groupsClaim:
default: groups
description: |-
The identifier of the claim that includes the principal's IdP user group membership information.
Accept the default value unless your IdP uses a different claim, or you need a custom claim.
Expand Down
80 changes: 76 additions & 4 deletions controllers/om/automation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"k8s.io/apimachinery/pkg/api/equality"

"github.com/mongodb/mongodb-kubernetes/controllers/operator/ldap"
"github.com/mongodb/mongodb-kubernetes/controllers/operator/oidc"
"github.com/mongodb/mongodb-kubernetes/pkg/util"
"github.com/mongodb/mongodb-kubernetes/pkg/util/generate"
"github.com/mongodb/mongodb-kubernetes/pkg/util/maputil"
Expand All @@ -20,10 +21,11 @@ import (
// configuration which are merged into the `Deployment` object before sending it back to Ops Manager.
// As of right now only support configuring LogRotate for monitoring and backup via dedicated endpoints.
type AutomationConfig struct {
Auth *Auth
AgentSSL *AgentSSL
Deployment Deployment
Ldap *ldap.Ldap
Auth *Auth
AgentSSL *AgentSSL
Deployment Deployment
Ldap *ldap.Ldap
OIDCProviderConfigs []oidc.ProviderConfig
}

// Apply merges the state of all concrete structs into the Deployment (map[string]interface{})
Expand Down Expand Up @@ -58,9 +60,66 @@ func applyInto(a AutomationConfig, into *Deployment) error {
}
(*into)["ldap"] = mergedLdap
}

if len(a.OIDCProviderConfigs) > 0 {
updateOIDCProviderConfigs(a, into)
} else {
// Clear oidcProviderConfigs if no configs are provided
delete(*into, "oidcProviderConfigs")
}

return nil
}

func updateOIDCProviderConfigs(a AutomationConfig, into *Deployment) {
deploymentConfigs := make(map[string]map[string]any)
if configs, ok := a.Deployment["oidcProviderConfigs"]; ok {
configsSliceAny := cast.ToSlice(configs)
for _, configAny := range configsSliceAny {
config := configAny.(map[string]any)
configName := config["authNamePrefix"].(string)
deploymentConfigs[configName] = config
}
}

result := make([]map[string]any, 0)
for _, config := range a.OIDCProviderConfigs {
deploymentConfig, ok := deploymentConfigs[config.AuthNamePrefix]
if !ok {
deploymentConfig = make(map[string]any)
}

deploymentConfig["authNamePrefix"] = config.AuthNamePrefix
deploymentConfig["audience"] = config.Audience
deploymentConfig["issuerUri"] = config.IssuerUri
deploymentConfig["userClaim"] = config.UserClaim
deploymentConfig["supportsHumanFlows"] = config.SupportsHumanFlows
deploymentConfig["useAuthorizationClaim"] = config.UseAuthorizationClaim

if config.ClientId == nil {
delete(deploymentConfig, "clientId")
} else {
deploymentConfig["clientId"] = config.ClientId
}

if len(config.RequestedScopes) == 0 {
delete(deploymentConfig, "requestedScopes")
} else {
deploymentConfig["requestedScopes"] = config.RequestedScopes
}

if config.GroupsClaim == nil {
delete(deploymentConfig, "groupsClaim")
} else {
deploymentConfig["groupsClaim"] = config.GroupsClaim
}

result = append(result, deploymentConfig)
}

(*into)["oidcProviderConfigs"] = result
}

// EqualsWithoutDeployment returns true if two AutomationConfig objects are meaningful equal by following the following conditions:
// - Not taking AutomationConfig.Deployment into consideration.
// - Serializing ac A and ac B to ensure that we remove util.MergoDelete before comparing those two.
Expand Down Expand Up @@ -432,6 +491,19 @@ func BuildAutomationConfigFromDeployment(deployment Deployment) (*AutomationConf
finalAutomationConfig.Ldap = acLdap
}

oidcConfigsArray, ok := deployment["oidcProviderConfigs"]
if ok {
oidcMarshalled, err := json.Marshal(oidcConfigsArray)
if err != nil {
return nil, err
}
providerConfigs := make([]oidc.ProviderConfig, 0)
if err := json.Unmarshal(oidcMarshalled, &providerConfigs); err != nil {
return nil, err
}
finalAutomationConfig.OIDCProviderConfigs = providerConfigs
}

return finalAutomationConfig, nil
}

Expand Down
Loading