CodeWithDanDockerServices icon indicating copy to clipboard operation
CodeWithDanDockerServices copied to clipboard

Secrets mongo deployment does not create admin user

Open richard-autry opened this issue 4 years ago • 2 comments

In the course: "Kubernetes for Developers: Core Concepts, 7 Creating ConfigMaps and Secrets, Secrets in Action", the mongo.deployment.yml does not create an admin user or allow authentication at the shell level or otherwise.

I followed the steps create the secrets with kubectl and using the current version of mongo.deployment.yml: https://github.com/DanWahlin/DockerAndKubernetesCourseCode/blob/main/samples/secrets/mongo.deployment.yml

Output after pod creation:

➜  secrets k apply -f mongo.deployment.yml
configmap/mongo-secrets-env created
storageclass.storage.k8s.io/local-storage created
persistentvolume/mongo-pv created
persistentvolumeclaim/mongo-pvc created
statefulset.apps/mongo created
➜  secrets k get pods
NAME                              READY   STATUS    RESTARTS   AGE
mongo-0                           1/1     Running   0          3s
node-configmap-577f5d6b98-qlwwb   1/1     Running   0          140m

Output attempting to auth inside mongo shell in the pod:

➜  ckad_training k exec mongo-0 -it sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
# mongo 
MongoDB shell version v5.0.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a66eee69-b066-4639-b06f-422745204d16") }
MongoDB server version: 5.0.6
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
> db.auth("admin", "password")
Error: Authentication failed.
0
> use codeWithDan
switched to db codeWithDan
> db.auth("admin", "password")
Error: Authentication failed.
0

Output from Studio T3 (using legacy SHA-1, but basic SHA-256 has same result):

Screen Shot 2022-03-29 at 2 18 02 PM

Would love to know what the solution is here as I was not able to find anything. Thanks!

richard-autry avatar Mar 29 '22 18:03 richard-autry

Hi @richard-autry. I'm out of the office until the end of the week but will try to look at this when I'm caught up with work and get some free time. I wouldn't expect the 3T connection to work since the service is using a ClusterIP which isn't accessible outside the cluster (it'd need to be a NodePort or Loadbalancer service like with some of the others).

I would expect you'd be able to login by shelling into the container like you did - not sure on that part without getting some time to check it out. You might try using "webrole" instead of "admin" though since that's the account the web app uses to call in.

DanWahlin avatar Apr 04 '22 19:04 DanWahlin

Late to the party here, but I'm pretty sure this is because mongo eliminated the "mongo" shell script in recent versions, this needs to be "mongosh" now. https://github.com/docker-library/mongo/issues/558

I changed .docker/mongo_scripts/first_run.sh lines 29 and 36 to use mongosh and it seemed to fix the issue. You can see the failures in the mongo-0 pod logs before the change, after the change they go away.

I will open a PR with the fix

kalepeterson avatar Oct 06 '22 16:10 kalepeterson