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

K8SPSMDB-1164: Allow creating user with $external database #1690

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
281ea28
Update crds.
inelpandzic Oct 30, 2024
6e85b24
Generate custom user pass.
inelpandzic Oct 30, 2024
b91a8a1
Update e2e test.
inelpandzic Oct 30, 2024
2e90cb9
Fix check
inelpandzic Oct 30, 2024
f204fad
Remove check
inelpandzic Oct 30, 2024
1780fb8
Log
inelpandzic Oct 30, 2024
5dec493
Fix
inelpandzic Oct 30, 2024
b9c3932
Propper pass key.
inelpandzic Oct 30, 2024
579342f
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Oct 30, 2024
1de4b2c
Refactor and fix external db user creation.
inelpandzic Oct 30, 2024
7eeb1ba
Update e2e test.
inelpandzic Oct 30, 2024
75c1edc
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Nov 1, 2024
79d8181
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Nov 13, 2024
0c83355
Update e2e tests.
inelpandzic Nov 13, 2024
0bc1914
Make sure if external DB user is created that we don't handle user
inelpandzic Nov 13, 2024
42e16f1
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Nov 13, 2024
965cc40
Fix custom-users-roles-sharded test.
inelpandzic Nov 14, 2024
5e4d011
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Nov 14, 2024
1c33033
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Nov 17, 2024
5330f06
Order roles for getUser.
inelpandzic Nov 21, 2024
9be37ca
Fix getRole order.
inelpandzic Nov 21, 2024
9a99799
Fix getRole roles order.
inelpandzic Nov 21, 2024
a4fa535
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Nov 21, 2024
6ea2dda
Refactor
inelpandzic Nov 21, 2024
d05e2e1
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Nov 22, 2024
6394cce
Merge branch 'main' into K8SPSMDB-1164-external-user-db
inelpandzic Nov 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18764,7 +18764,6 @@ spec:
type: array
required:
- name
- passwordSecretRef
- roles
type: object
type: array
Expand Down
1 change: 0 additions & 1 deletion deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19460,7 +19460,6 @@ spec:
type: array
required:
- name
- passwordSecretRef
- roles
type: object
type: array
Expand Down
1 change: 0 additions & 1 deletion deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19460,7 +19460,6 @@ spec:
type: array
required:
- name
- passwordSecretRef
- roles
type: object
type: array
Expand Down
1 change: 0 additions & 1 deletion deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19460,7 +19460,6 @@ spec:
type: array
required:
- name
- passwordSecretRef
- roles
type: object
type: array
Expand Down
20 changes: 20 additions & 0 deletions e2e-tests/custom-users-roles-sharded/compare/user-external.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
switched to db $external
{
"_id" : "$external.user-external",
"user" : "user-external",
"db" : "$external",
"roles" : [
{
"role" : "clusterAdmin",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"external"
]
}
bye
21 changes: 21 additions & 0 deletions e2e-tests/custom-users-roles-sharded/compare/user-gen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
switched to db admin
{
"_id" : "admin.user-gen",
"user" : "user-gen",
"db" : "admin",
"roles" : [
{
"role" : "clusterAdmin",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
bye
14 changes: 14 additions & 0 deletions e2e-tests/custom-users-roles-sharded/conf/some-name-rs0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ spec:
db: admin
- name: userAdminAnyDatabase
db: admin
- name: user-gen
db: admin
roles:
- name: clusterAdmin
db: admin
- name: userAdminAnyDatabase
db: admin
- name: user-external
db: $external
roles:
- name: clusterAdmin
db: admin
- name: userAdminAnyDatabase
db: admin

backup:
enabled: false
Expand Down
9 changes: 9 additions & 0 deletions e2e-tests/custom-users-roles-sharded/run
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ userOnePass=$(getSecretData "user-one" "userOnePassKey")
compare 'admin' 'db.getUser("user-one")' "$mongosUri" "user-one"
check_auth "$userOne:$userOnePass@$cluster-mongos.$namespace"

generatedUserSecret="$cluster-custom-user-secret"
generatedPass=$(kubectl_bin get secret $generatedUserSecret -o jsonpath="{.data.user-gen}" | base64 -d)
compare 'admin' 'db.getUser("user-gen")' "$mongosUri" "user-gen"
check_auth "user-gen:$generatedPass@$cluster-mongos.$namespace"

# Only check if $external.user-external user exists, as the password is not known
# since we don't have a external provider set in this test
compare '$external' 'db.getUser("user-external")' "$mongosUri" "user-external"

desc 'delete initial user from CR and create a new one'
kubectl_bin patch psmdb ${cluster} --type=merge --patch '{
"spec": {"users":[
Expand Down
20 changes: 20 additions & 0 deletions e2e-tests/custom-users-roles/compare/user-external.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
switched to db $external
{
"_id" : "$external.user-external",
"user" : "user-external",
"db" : "$external",
"roles" : [
{
"role" : "clusterAdmin",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"external"
]
}
bye
21 changes: 21 additions & 0 deletions e2e-tests/custom-users-roles/compare/user-gen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
switched to db admin
{
"_id" : "admin.user-gen",
"user" : "user-gen",
"db" : "admin",
"roles" : [
{
"role" : "clusterAdmin",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
bye
15 changes: 15 additions & 0 deletions e2e-tests/custom-users-roles/conf/some-name-rs0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ spec:
db: admin
- name: userAdminAnyDatabase
db: admin
- name: user-gen
db: admin
roles:
- name: clusterAdmin
db: admin
- name: userAdminAnyDatabase
db: admin
- name: user-external
db: $external
roles:
- name: clusterAdmin
db: admin
- name: userAdminAnyDatabase
db: admin

backup:
enabled: true
image: perconalab/percona-server-mongodb-operator:1.1.0-backup
Expand Down
11 changes: 10 additions & 1 deletion e2e-tests/custom-users-roles/run
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ userOnePass=$(getSecretData "user-one" "userOnePassKey")
compare 'admin' 'db.getUser("user-one")' "$mongoUri" "user-one"
check_mongo_auth "$userOne:$userOnePass@$cluster-0.$cluster.$namespace"

desc 'delete initial user from CR and create a new one'
generatedUserSecret="$psmdb-custom-user-secret"
generatedPass=$(kubectl_bin get secret $generatedUserSecret -o jsonpath="{.data.user-gen}" | base64 -d)
compare 'admin' 'db.getUser("user-gen")' "$mongoUri" "user-gen"
check_mongo_auth "user-gen:$generatedPass@$cluster-0.$cluster.$namespace"

# Only check if $external.user-external user exists, as the password is not known
# since we don't have a external provider set in this test
compare '$external' 'db.getUser("user-external")' "$mongoUri" "user-external"

desc 'delete initial users from CR and create a new one'
kubectl_bin patch psmdb ${psmdb} --type=merge --patch '{
"spec": {"users":[
{
Expand Down
1 change: 0 additions & 1 deletion e2e-tests/version-service/conf/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19460,7 +19460,6 @@ spec:
type: array
required:
- name
- passwordSecretRef
- roles
type: object
type: array
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/psmdb/v1/psmdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ type SecretKeySelector struct {
}

type User struct {
Name string `json:"name"`
DB string `json:"db,omitempty"`
PasswordSecretRef SecretKeySelector `json:"passwordSecretRef"`
Roles []UserRole `json:"roles"`
Name string `json:"name"`
DB string `json:"db,omitempty"`
PasswordSecretRef *SecretKeySelector `json:"passwordSecretRef,omitempty"`
Roles []UserRole `json:"roles"`
}

func (u *User) UserID() string {
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/psmdb/v1/zz_generated.deepcopy.go

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

Loading
Loading