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 all 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
17 changes: 14 additions & 3 deletions controllers/om/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,22 @@ func (d Deployment) SetRoles(roles []mdbv1.MongoDbRole) {
}

func (d Deployment) GetRoles() []mdbv1.MongoDbRole {
val, ok := d["roles"].([]mdbv1.MongoDbRole)
if !ok {
roles, ok := d["roles"]
if !ok || roles == nil {
return []mdbv1.MongoDbRole{}
}
return val

rolesBytes, err := json.Marshal(roles)
if err != nil {
return []mdbv1.MongoDbRole{}
}

var result []mdbv1.MongoDbRole
if err := json.Unmarshal(rolesBytes, &result); err != nil {
return []mdbv1.MongoDbRole{}
}

return result
}

// GetAgentVersion returns the current version of all Agents in the deployment. It's empty until the
Expand Down
1 change: 1 addition & 0 deletions controllers/operator/authentication/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func enableAgentAuthentication(conn om.Connection, opts Options, log *zap.Sugare

// we then configure the agent authentication for that type
mechanism := convertToMechanismOrPanic(opts.AgentMechanism, ac)

if err := ensureAgentAuthenticationIsConfigured(conn, opts, ac, mechanism, log); err != nil {
return xerrors.Errorf("error ensuring agent authentication is configured: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ def assert_processes_size(self, expected_size: int):
def assert_sharding_size(self, expected_size: int):
assert len(self.automation_config["sharding"]) == expected_size

def assert_oidc_providers_size(self, expected_size: int):
assert len(self.automation_config["oidcProviderConfigs"]) == expected_size

def assert_oidc_configuration(self, oidc_config: Optional[Dict] = None):
actual_configs = self.automation_config["oidcProviderConfigs"]
assert len(actual_configs) == len(
oidc_config
), f"Expected {len(oidc_config)} OIDC configs, but got {len(actual_configs)}"

for expected, actual in zip(oidc_config, actual_configs):
assert expected == actual, f"Expected OIDC config: {expected}, but got: {actual}"

def assert_empty(self):
self.assert_processes_size(0)
self.assert_replica_sets_size(0)
Expand Down
35 changes: 35 additions & 0 deletions docker/mongodb-kubernetes-tests/kubetester/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,41 @@ def get_authentication(self) -> Optional[Dict]:
except KeyError:
return {}

def get_oidc_provider_configs(self) -> Optional[Dict]:
try:
return self["spec"]["security"]["authentication"]["oidcProviderConfigs"]
except KeyError:
return {}

def set_oidc_provider_configs(self, oidc_provider_configs: Dict):
self["spec"]["security"]["authentication"]["oidcProviderConfigs"] = oidc_provider_configs
return self

def append_oidc_provider_config(self, new_config: Dict):
if "oidcProviderConfigs" not in self["spec"]["security"]["authentication"]:
self["spec"]["security"]["authentication"]["oidcProviderConfigs"] = []

oidc_configs = self["spec"]["security"]["authentication"]["oidcProviderConfigs"]

oidc_configs.append(new_config)

self["spec"]["security"]["authentication"]["oidcProviderConfigs"] = oidc_configs

return self

def get_roles(self) -> Optional[Dict]:
try:
return self["spec"]["security"]["roles"]
except KeyError:
return {}

def append_role(self, new_role: Dict):
if "roles" not in self["spec"]["security"]:
self["spec"]["security"]["roles"] = []
self["spec"]["security"]["roles"].append(new_role)

return self

def get_authentication_modes(self) -> Optional[Dict]:
try:
return self.get_authentication()["modes"]
Expand Down
56 changes: 56 additions & 0 deletions docker/mongodb-kubernetes-tests/kubetester/mongotester.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import inspect
import logging
import os
import random
import string
import threading
Expand All @@ -11,6 +12,8 @@
from kubetester import kubetester
from kubetester.kubetester import KubernetesTester
from opentelemetry import trace
from pycognito import Cognito
from pymongo.auth_oidc import OIDCCallback, OIDCCallbackContext, OIDCCallbackResult
from pymongo.errors import OperationFailure, PyMongoError, ServerSelectionTimeoutError
from pytest import fail

Expand Down Expand Up @@ -61,6 +64,18 @@ def with_ldap(ssl_certfile: Optional[str] = None, tls_ca_file: Optional[str] = N
return options


class MyOIDCCallback(OIDCCallback):
def fetch(self, context: OIDCCallbackContext) -> OIDCCallbackResult:
u = Cognito(
user_pool_id=os.getenv("cognito_user_pool_id"),
client_id=os.getenv("cognito_workload_federation_client_id"),
username=os.getenv("cognito_user_name"),
client_secret=os.getenv("cognito_workload_federation_client_secret"),
)
u.authenticate(password=os.getenv("cognito_user_password"))
return OIDCCallbackResult(access_token=u.id_token)


class MongoTester:
"""MongoTester is a general abstraction to work with mongo database. It encapsulates the client created in
the constructor. All general methods non-specific to types of mongodb topologies should reside here."""
Expand Down Expand Up @@ -277,6 +292,47 @@ def assert_ldap_authentication(
fail(msg=f"unable to authenticate after {total_attempts} attempts")
time.sleep(5)

def assert_oidc_authentication(
self,
db: str = "admin",
collection: str = "myCol",
attempts: int = 10,
):
assert attempts > 0

props = {"OIDC_CALLBACK": MyOIDCCallback()}

total_attempts = attempts
while True:
attempts -= 1
try:
# Initialize the MongoDB client with OIDC authentication
self.client = self._init_client(
authMechanism="MONGODB-OIDC",
authMechanismProperties=props,
)
# Perform a write operation to test authentication
self.client[db][collection].insert_one({"test": "oidc_auth_test"})
return
except OperationFailure as e:
if attempts == 0:
raise RuntimeError(f"Unable to authenticate after {total_attempts} attempts: {e}")
time.sleep(5)

def assert_oidc_authentication_fails(self, db: str = "admin", collection: str = "myCol", attempts: int = 10):
assert attempts > 0
total_attempts = attempts
while True:
attempts -= 1
try:
if attempts <= 0:
fail(msg=f"was able to authenticate with OIDC after {total_attempts} attempts")

self.assert_oidc_authentication(db, collection, 1)
time.sleep(5)
except RuntimeError:
return

def upload_random_data(
self,
count: int,
Expand Down
26 changes: 26 additions & 0 deletions docker/mongodb-kubernetes-tests/kubetester/oidc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

# Note: The project uses AWS Cognito in the mongodb-mms-testing AWS account to facilitate OIDC authentication testing.
# This setup includes:

# User Pool: A user pool in Cognito manages the identities.
# Users: We use the user credentials to do authentication.
# App Client: An app client is configured for machine-to-machine (M2M) authentication.
# Groups: Cognito groups are used to manage users from the user pool for GroupMembership access.

# Environment variables and secrets required for these tests (like client IDs, URLs, and user IDs, as seen in the Python code)
# are stored in Evergreen and fetched from there during test execution.

# A session explaining the setup can be found here: http://go/k8s-oidc-session


def get_cognito_workload_client_id() -> str:
return os.getenv("cognito_workload_federation_client_id", "")


def get_cognito_workload_url() -> str:
return os.getenv("cognito_workload_url", "")


def get_cognito_workload_user_id() -> str:
return os.getenv("cognito_workload_user_id", "")
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: mongodb.com/v1
kind: MongoDBUser
metadata:
name: oidc-user-0
spec:
username: "<filled-in-test>"
db: "$external"
mongodbResourceRef:
name: oidc-replica-set
roles:
- db: "admin"
name: "readWriteAnyDatabase"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
name: oidc-replica-set
spec:
type: ReplicaSet
members: 3
version: 7.0.5-ent

opsManager:
configMapRef:
name: my-project
credentials: my-credentials

security:
authentication:
agents:
mode: SCRAM
enabled: true
modes:
- SCRAM
- OIDC
oidcProviderConfigs:
- audience: "<filled-in-test>"
clientId: "<filled-in-test>"
issuerURI: "<filled-in-test>"
requestedScopes: [ ]
userClaim: "sub"
authorizationMethod: "WorkloadIdentityFederation"
authorizationType: "UserID"
configurationName: "OIDC-test-user"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
name: oidc-replica-set
spec:
type: ReplicaSet
members: 3
version: 7.0.5-ent

opsManager:
configMapRef:
name: my-project
credentials: my-credentials

security:
authentication:
agents:
mode: SCRAM
enabled: true
modes:
- SCRAM
- OIDC
oidcProviderConfigs:
- audience: "<filled-in-test>"
clientId: "<filled-in-test>"
issuerURI: "<filled-in-test>"
requestedScopes: [ ]
userClaim: "sub"
groupsClaim: "cognito:groups"
authorizationMethod: "WorkforceIdentityFederation"
authorizationType: "GroupMembership"
configurationName: "OIDC-test-group"
- audience: "dummy-audience"
clientId: "dummy-client-id"
issuerURI: "https://valid-issuer.example.com"
requestedScopes: [ ]
userClaim: "sub"
authorizationMethod: "WorkloadIdentityFederation"
authorizationType: "UserID"
configurationName: "OIDC-test-user"
roles:
- role: "OIDC-test-group/test"
db: "admin"
roles:
- role: "readWriteAnyDatabase"
db: "admin"
Loading