You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CLOUDP-350197: allow to create a custom role with cluster: true (#553)
# Summary
This PR fixes a problem which was preventing creating cluster-wide
mongodb custom roles.
**Context**
As described in [MongoDB
docs](https://www.mongodb.com/docs/manual/reference/system-roles-collection/#mongodb-data-admin.system.roles.privileges-n-.resource)
the resource object is either:
```
{ db: <database>, collection: <collection> }
```
or
```
{ cluster : true }
```
So that means we cannot provide empty strings for `db` and `collection`
fields as empty string means "any db/collection".
At the same time our previous serialization rules were always sending
empty strings even if not set. This was the source of the problem - it
wasn't possible to specify `cluster: true` because the operator was also
sending empty db and collections.
**Backwards compatibility**
Making `db` and `collection` fields just as omitempty `*string` is not
sufficient, because that would change the semantics of the resource and
would be potentially a breaking change. In order to preserve backwards
compatibility we need additional logic (see
[normalizePrivilegeResource](https://github.com/mongodb/mongodb-kubernetes/pull/553/files#diff-457d90107d5cbfbfb07a276cc6d58bd1f53c710f58ce19d6ec54daa7ab8e08aaR174)
that will maintain the same behavior for non-cluster-wide resources
(sending empty strings even if the field is not set in yaml).
## Proof of Work
Tests passing.
<!-- start git-machete generated -->
# Based on PR #551
## Chain of upstream PRs as of 2025-10-25
* PR #551:
`master` ← `lsierant/custom-roles-regression-tests`
* **PR #553 (THIS ONE)**:
`lsierant/custom-roles-regression-tests` ← `lsierant/custom-roles`
<!-- end git-machete generated -->
Copy file name to clipboardExpand all lines: docker/mongodb-kubernetes-tests/tests/authentication/fixtures/cluster-mongodb-role-with-empty-strings.yaml
Copy file name to clipboardExpand all lines: docker/mongodb-kubernetes-tests/tests/authentication/fixtures/cluster-mongodb-role-without-empty-strings.yaml
0 commit comments