Creating database dynamically using nodejs in an authenticated environment of mongodb - node.js

Started mongod shared instance without keyfile option
Created a user in admin database with all roles and then started the instances with the keyfile option
Using that user we saved a serverside scripting to create a database dynamically.
Then from nodejs we connected admin db and tried executing the serverside script using db.eval
getting the below mentioened error
/home/administrator/Node# node t1.js
open!
Error :null
Error :Error: eval failed: unauthorized

Related

Can't connect to ClearDB database after resetting password

I am trying to deploy a very simple nodejs api through Heroku and utilizing the clearDB add on so I can connect to the MySQL db the api utilizes. I had everything connected and working then realized I had hard coded and exposed the database user and password information. I reset the password on clearDB to reset the exposed information. So far I have created environment variables locally and the config variable for the new password on Heroku but now the app crashes anytime I try to connect to the db, is there somewhere else that the new password will be needed?
ClearDB stores the username and password information inside the URL to the db so if you only updated it in the config variable for the password you will also need to update it in the variable containing the URL string as well.

MongoAtlas AWS IAM Role Authentication

I am setting up a deployment for my company's API Server and it fails to connect to MongoAtlas via IAM role
What I've done:
Set up a IAM Role on AWS (APIServer)
Set up a Database User on Atlas with the role (arn:aws:iam::< my aws acc id >:role/APIServer)
Configure a launch template and an auto scaling group, launching Amazon Linux EC2 instances with the role
Have my NodeJS application connect to my Atlas with the following setting:
key
value
URL
mongodb+srv://dev.< cluster >.mongodb.net/< DB >
authSource
'$external'
authMechanism
'MONGODB-AWS'
I ended up receiving the following error message
MongoServerError: bad auth : user arn:aws:sts::<my aws acc id>:assumed-role/APIServer/* is not found
Note: the info enclosed in <> are intentionally replaced, since I have already found several solutions pointing out having <> as part of the password, which is not my case here
I have the same problem, the only solution I found until now is to create a aws iam user (not a role, so you can generate security credentials), set up that user on atlas and put the security credentials of the user in a .env file in your node application. In this way mongodb will retrieve automatically that user and it works because you are not assuming a role, so the arn is correct.
This is still not a good solution to me, because I do not want to manage those keys. Best thing you can do probably is storing those credentials in aws secrets manager, give the ec2 role the permission to retrieve that secret, and when you start the instance with a script you can automatically retrieve the secrete and create the .env file.
(Still a disappointing solution to me)
Edit:
As I self answered in this post: AWS EC2 connection to MongoDB Atlas failing, could not find user
The solution for me was to change the scope of the Atlas user.
You need AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN to connect. You can get/create them from AWS IAM > Users dashboard. I recommend for mongo create a new secret key.
After creation you can get your connection string from mongodb website if you have already a cluster.
Example URL:
mongodb+srv://<AWS access key>:<AWS secret key>#cluster0.zphy22p.mongodb.net/?authSource=%24external&authMechanism=MONGODB-AWS&retryWrites=true&w=majority&authMechanismProperties=AWS_SESSION_TOKEN:<session token (for AWS IAM Roles)>

createConnection MongoError: Authentication failed

I have a node.js app that uses MongoDB as a database.
I have also the management of MongoDB.
When the app starts, it connects to MongoDB without any problem.
I am trying to let the user defines which database he/she will connect to. To do that I create mongo.conf like that:
And in the app, I defined the connection uri like that:
MONGODB_URL="mongodb://< username>:< password>#34.72.5.46:27017/"
The database user has the root role. As I mentioned, in first opening the app connects to the database. In the first opening, I am using mongoose.connect
But when the user inserts a database name that doesn't exist, via the app, I am using mongoose.createConnection. And then I get this error:
MongoNetworkError: failed to connect to server [34.72.5.46:27017] on first connect [MongoError: Authentication failed.
What should I do?
I solved my issue. It has been needed to add "?authSource=admin" at the end of the mongo URI

How to create a node js application with vue js as frontend and postgres as backend

I would like to know the folder structure of NodeJs as server side VueJs and postgres as back end
As my requirement is we will register user (not from external site ) we will create the user
After authentication authorized user can use web service or content
most important user authentication. which authentication method should use
I have read about passport it is using for authentication between various external site
I have read number of topics i could not found suitable, please guide me
summaries the requirement
folder structure of node
user authentication
NodeJs and VueJs connection
open source

How Openam works with ADLDS datastore

I am trying to connect openam ,with ADLDS as data store using Active Director Application mode,
I had ADLDS server, running on my windows machine
what would be the LDAP bind DN: by default its shows:
CN=Administrator,CN=Users,dc=xyz,dc=zyz.
I had go through the hints given in OpenAM document. but didn't work for me
http://docs.forgerock.org/en/openam/12.0.0/admin-guide/index.html#sec-data-stores-adam
while on check of Load Schema it gives error ” Error
Unable to load schema for plug-in ADLDS for realm /. error result”
what will be the steps to connect Openam with ADLDS data store.
Thanks,

Resources