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

Conversation

inelpandzic
Copy link
Contributor

@inelpandzic inelpandzic commented Oct 30, 2024

K8SPSMDB-1164 Powered by Pull Request Badge

CHANGE DESCRIPTION

Problem:
There was no ability to add a user to $external database because setting user.PasswordSecretRef was mandatory and for a user with $external database we don't provide user credentials, since they are handled by the external provider.

Solution:
Add a support to create user with $external database.

Note:
This PR also adds support for generating user pass/secret if it is not set. Task https://perconadev.atlassian.net/browse/K8SPSMDB-1171
Also covers task: https://perconadev.atlassian.net/browse/K8SPSMDB-1162

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?
  • Are OpenShift compare files changed for E2E tests (compare/*-oc.yml)?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported MongoDB version?
  • Does the change support oldest and newest supported Kubernetes version?

@pull-request-size pull-request-size bot added the size/L 100-499 lines label Oct 30, 2024
@inelpandzic inelpandzic changed the title K8SPSMDB-1164: -external-user-db K8SPSMDB-1164: Allow creating user with $external database Oct 30, 2024
Copy link
Collaborator

@hors hors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inelpandzic please add test case for https://github.com/percona/percona-server-mongodb-operator/blob/main/e2e-tests/ldap-tls/run test as well. We need to be sure that it works

@inelpandzic
Copy link
Contributor Author

@inelpandzic please add test case for https://github.com/percona/percona-server-mongodb-operator/blob/main/e2e-tests/ldap-tls/run test as well. We need to be sure that it works

@hors I was thinking about this but now I'm positive we don't need to do it since it will not provide any value. The way that you enable external authentication ability is simply by creating a user with $external database that will set user authentication method to external. We are testing this in custom-users-roles/custom-users-roles-sharded tests and with that we are 100% sure that this works.

If we need to add this test as well to make sure it works, then we would need to cover Kerberos and other external auth providers.

@hors hors self-requested a review November 14, 2024 10:19
Comment on lines +426 to +428
if err != nil && name != defaultName {
return nil, errors.Wrap(err, "failed to get user secret")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we don't create the secret object if user just wants to customize its name. Was it like this in the spec? @spron-in @eleo007

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what do you mean by "user just wants to customize its name", but how this behaves is like this:

  • If in the spec the user sets passwordSecretRef.name we will look for that secret. If we don't find it we will fail creating that user.
  • If the user does not set passwordSecretRef.name, we will create secret {cluster-name}-custom-user-secret, generate a password for the user and set it by the key named after user name.

And yes, I'll add this to the spec as well.

pooknull
pooknull previously approved these changes Nov 18, 2024
egegunes
egegunes previously approved these changes Nov 18, 2024
@egegunes
Copy link
Contributor

@inelpandzic looks like now you need to fix role order in e2e test 😄

nmarukovich
nmarukovich previously approved these changes Nov 18, 2024
@inelpandzic
Copy link
Contributor Author

@inelpandzic looks like now you need to fix role order in e2e test 😄

Yeah, I know... :)

@pull-request-size pull-request-size bot added size/XL 500-999 lines and removed size/L 100-499 lines labels Nov 21, 2024
@egegunes egegunes added this to the v1.19.0 milestone Nov 25, 2024
echo "$cmd"
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change


desc 'check role recreated after deleted from DB'
run_mongos \
'use admin\n db.dropRole("role-one")' \
"$mongosUri"
sleep 15
compare 'admin' 'db.getRole("role-one", {showPrivileges: true, showAuthenticationRestrictions: true})' \
"$mongosUri" "role-one"
compare 'admin' "$(get_role_cmd \"role-one\" )" "$mongosUri" "role-one"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
compare 'admin' "$(get_role_cmd \"role-one\" )" "$mongosUri" "role-one"
compare 'admin' "$(get_role_cmd \"role-one\")" "$mongosUri" "role-one"

Comment on lines +302 to +303
compare 'admin' "$(get_role_cmd \"role-one\" )" "$mongosUri" "role-one"
compare 'admin' "$(get_role_cmd \"role-two\" )" "$mongosUri" "role-two"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
compare 'admin' "$(get_role_cmd \"role-one\" )" "$mongosUri" "role-one"
compare 'admin' "$(get_role_cmd \"role-two\" )" "$mongosUri" "role-two"
compare 'admin' "$(get_role_cmd \"role-one\")" "$mongosUri" "role-one"
compare 'admin' "$(get_role_cmd \"role-two\")" "$mongosUri" "role-two"

@@ -282,16 +324,14 @@ kubectl_bin patch psmdb ${cluster} --type=merge --patch '{
}}'
wait_for_running $cluster-rs0 3

compare 'admin' 'db.getRole("role-two", {showPrivileges: true, showAuthenticationRestrictions: true})' \
"$mongosUri" "role-two-updated"
compare 'admin' "$(get_role_cmd \"role-two\" )" "$mongosUri" "role-two-updated"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
compare 'admin' "$(get_role_cmd \"role-two\" )" "$mongosUri" "role-two-updated"
compare 'admin' "$(get_role_cmd \"role-two\")" "$mongosUri" "role-two-updated"


desc 'check role update from DB'
run_mongos \
'use admin\n db.updateRole( "role-two",{privileges:[{resource: {db:"config", collection:"" }, actions: ["find", "update"]}]})' \
"$mongosUri"
sleep 15
compare 'admin' 'db.getRole("role-two", {showPrivileges: true, showAuthenticationRestrictions: true})' \
"$mongosUri" "role-two-updated"
compare 'admin' "$(get_role_cmd \"role-two\" )" "$mongosUri" "role-two-updated"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
compare 'admin' "$(get_role_cmd \"role-two\" )" "$mongosUri" "role-two-updated"
compare 'admin' "$(get_role_cmd \"role-two\")" "$mongosUri" "role-two-updated"

@@ -315,8 +355,7 @@ kubectl_bin patch psmdb ${cluster} --type=merge --patch '{
}}'
wait_for_running $cluster-rs0 3

compare 'admin' 'db.getRole("role-three", {showPrivileges: true, showAuthenticationRestrictions: true})' \
"$mongosUri" "role-three"
compare 'admin' "$(get_role_cmd \"role-three\" )" "$mongosUri" "role-three"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
compare 'admin' "$(get_role_cmd \"role-three\" )" "$mongosUri" "role-three"
compare 'admin' "$(get_role_cmd \"role-three\")" "$mongosUri" "role-three"

Comment on lines +475 to +476
compare 'testAdmin1' "$(get_role_cmd \"role-four\" )" "$mongosUri" "role-four"
compare 'testAdmin2' "$(get_role_cmd \"role-five\" )" "$mongosUri" "role-five"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
compare 'testAdmin1' "$(get_role_cmd \"role-four\" )" "$mongosUri" "role-four"
compare 'testAdmin2' "$(get_role_cmd \"role-five\" )" "$mongosUri" "role-five"
compare 'testAdmin1' "$(get_role_cmd \"role-four\")" "$mongosUri" "role-four"
compare 'testAdmin2' "$(get_role_cmd \"role-five\")" "$mongosUri" "role-five"

@@ -18,7 +18,44 @@ compare() {
| sed '/"userId"/d' \
>$tmp_dir/${target}

diff ${test_dir}/compare/${target}.json $tmp_dir/${target}
diff ${test_dir}/compare/${target}.json $tmp_dir/${target}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
diff ${test_dir}/compare/${target}.json $tmp_dir/${target}
diff ${test_dir}/compare/${target}.json $tmp_dir/${target}

echo "$cmd"
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change

@JNKPercona
Copy link
Collaborator

Test name Status
arbiter passed
balancer passed
custom-replset-name passed
custom-tls passed
custom-users-roles passed
custom-users-roles-sharded passed
cross-site-sharded passed
data-at-rest-encryption passed
data-sharded passed
demand-backup passed
demand-backup-fs passed
demand-backup-eks-credentials-irsa passed
demand-backup-physical passed
demand-backup-physical-sharded passed
demand-backup-sharded passed
expose-sharded passed
ignore-labels-annotations passed
init-deploy passed
finalizer passed
ldap passed
ldap-tls passed
limits passed
liveness passed
mongod-major-upgrade passed
mongod-major-upgrade-sharded passed
monitoring-2-0 passed
multi-cluster-service passed
non-voting passed
one-pod passed
operator-self-healing-chaos passed
pitr passed
pitr-sharded passed
pitr-physical passed
pvc-resize passed
recover-no-primary passed
replset-overrides passed
rs-shard-migration passed
scaling passed
scheduled-backup passed
security-context passed
self-healing-chaos passed
service-per-pod passed
serviceless-external-nodes passed
smart-update passed
split-horizon passed
storage passed
tls-issue-cert-manager passed
upgrade passed
upgrade-consistency passed
upgrade-consistency-sharded-tls passed
upgrade-sharded passed
users passed
version-service passed
We run 53 out of 53

commit: 6394cce
image: perconalab/percona-server-mongodb-operator:PR-1690-6394ccee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XL 500-999 lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants