Meteor.js + external Mongo. Meteor cannot login into Mongo - javascript

I have a meteor.js app + mongo db (2.6).
I've created a user in mongo like this:
use meteor
db.createUser(
{
user: "meteor",
pwd: "password",
roles:
[
{
role: "userAdmin",
db: "meteor"
}
]
}
)
here is my mongodb.conf:
dbpath=/data/db
logpath=/var/log/mongodb/mongodb.log
logappend=true
port = 27017
when i set auth = true then my meteor app cannot connect to mongo anymore. It says
Exception in callback of async function: MongoError: auth failed
Same error when i try to connect with RoboMongo when auth is true. When auth is false i can connect with RoboMongo. So it's not about Firewall or something.
I don't understand, what I can do to switch on authorization in Mongo, so that it would let me login. Please help.

It depends on how you start Meteor. You need to tell it which Mongo instance to use and also provide proper credentials like this:
export MONGO_URL=mongodb://<username>:<password>#<host>:<port>/<db>
That's the way I've been doing it with my Meteor apps and a dedicated MongoDB and it works nicely. But if RoboMongo is not able to connect, there may be something wrong with the Mongo configuration. You can use this command to enable authentication in your config:
mongod --auth --config /path/to/mongodb.conf
I assume you have an admin user already which was used to create the meteor user, you will run into issues if you start Mongo without authentication, then add a meteor user anonymously and restart with auth=true.

Related

Cannot connect to Cloud SQL SQL Server from Cloud Functions using private IP

I have a Cloud Function that I want to connect to a SQL Server Instance.
By documentation, you can only connect using a private IP.
Everytime I try to connect I get the error:
ERROR: (gcloud.functions.call) ResponseError: status=[400], code=[Bad Request], message=
[Function failed on loading user code. Error message: {"code":"ELOGIN","originalError":
{"message":"Logon failed for login 'sqlserver' due to trigger execution.","code":"ELOGIN"},"name":"ConnectionError"}]
My Cloud Function code:
const sql = require('mssql');
exports.test = (req, res) => {
const config = {
user: 'sqlserver',
password: 'test',
server: '10.60.80.3',
port:1433,
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000
}
};
const pool = new sql.ConnectionPool(config);
pool.connect()
.then(() => {
res.status(200).send({message: "Connection ready."});
})
.catch(err => {
res.status(500).send(err);
pool.close();
});
};
I have done the following configurations:
VPC Connector on default network
The default network was applied to Private IP configuration of SQL Server instance.
SQL Server Instance configuration
When creating the Cloud Function, you are required to select a service account and a VPC connector. I chose the connect-ip-sql connector. For service account, I tried with App Engine Default Service Account and Compute Engine Service Account ( both given the role of Cloud SQL client). Same error.
It seems to be a problem with SQL Server login and not about finding the network since I tried changing the network (setting the SQL Server in another VPC) and it returned CONNECTION TIMEOUT.
I can login using public ip in my SSMS using the default username-password. When I run the query:
select * from sys.server_triggers
There are three server triggers but there is no information what they do.
gcloudsql_RoleManagement
TRG_ProtectDropCustRootLogin
TRG_DisableRemoteConnectionForDbRoot
You cannot drop or change them, because Cloud SQL is a managed service and you have no access on the 'sa' superuser.
It would be best to request Google Cloud Support assistance (public tracker is mostly for bugs) since it could be a lot of things that could go wrong here.
But with that said, I assume you have the following in place:
GCP firewall rules that allows traffic from/to your Cloud Funtion and Cloud SQL MSSQL
Cloud SQL uses VPC peering for RFC-1918 connections, so I assume that your VPC connector route is there as exported and your MSSQL route is there as well as imported
Your Cloud Funtion VPC connector is in the same region as your Cloud MSSQL
I would recommend for you to enable flow logs and GCP firewall logs, also running connectivity test can also give you a hint on what might be blocking you

How can I set database authentication in Mongodb - Is SSH Pipes better for MongoDB?

I have installed MongoDB in my computer. I did't define any password and username for the installation. I can see everything with Robo 3T.
Now I want to protect my database.
I have tried to set authentication for the database. I followed https://docs.mongodb.com/manual/tutorial/enable-authentication/ . It did not work.
I still can reach mongodb with robo 3t and see all information.
I have also tried to start mongodb with --auth parameter. I have define a configuration file looks like
And for starting mongodb
mongod -f C:\mongodb\conf\mongodb.conf
Mongodb has been started but, it did not ask any pass. And I can save simple data with Postman without authentication.
What I want to do:
Protect my database against Robo 3t. :))
I dont want to save any data without auth.
Building Nodejs connection string that include pass like
mysql://root:password#localhost:port/dbName
Here is my Nodejs index.js code
this is my model.
PS: I am very new in Nodejs and Mongodb.
EDIT: inside conf file

Setup Auth0 with local database ran in a docker container

I've got a web-page at localhost:8080 with a login button that triggers a call to the auth0 handler. It works fine as long as it interacts with their database. Now i'm trying to set-up my own database, but can't seem to fill correctly the login script.
My database runs through a docker container via the command-line:
docker run —ip="172.0.0.3" —net="unihub-network" -p 13306:3306 -e MYSQL_ROOT_PASSWORD=mypasswd -d unihub-mysql
Using their template, I wrote:
function login(email, password, callback) {
var connection = mysql({
host: 'my-ip-address',
user: 'my-user',
password: 'my-psw',
database: 'UNIHUB_DB' //supposed to be the name of my db
});
Which obviously doesn't work. I can access my DB through software like SQuirreL at jdbc:mysql://localhost:13306/UNIHUB_DB, but it looks like i would need to access it through a URL to put in the login script for auth0.
Any thought on this ?

adonisjs migration issue with mysql

I'm trying to get the hang of adonisjs through this tutorial
I set up everything properly as instructed in there but I run into a problem when I type adonis migration:run.
The error I get on Terminal is Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'#'localhost' (using password: NO)
I have 0 experience with mysql and this confuses me. I'd appreciate some guidance/help here.
Cheers!
#katotopark, this means your MySQL server is rejecting the connection from the Adonisjs application. check for a file called (.env) in the root folder of your project and inside you will need to add the credentials for the connection the MySQL server. (probably user: root, password: the password you use when you installed MySQL)
your .env should look similar to this.
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root/or-another-mysql-user
DB_PASSWORD=your-database-user-password***
DB_DATABASE=the_name_of_your_database
Regards.

Finding MongoDB details after hosting on Ubuntu

I'm completely new to setting up servers, MongoDB, and still a little new to Javascript.
I'm trying to upload a Deployd server onto an online server. There is limited information on this, so at the moment, I set up a simple AWS Ubuntu server by doing the following tutorials:
http://zenborgium.blogspot.com/2012/12/how-to-setup-deployd-on-ubuntu-server.html
http://terraltech.com/how-to-setup-deployd-on-ubuntu-server/
However, I'm stuck at creating the production.js. There's a guide on it here. I'm specifically stuck at this line of code:
var server = deployd({
port: process.env.PORT || 5000,
env: 'production',
db: {
host: 'my.production.mongo.host',
port: 27105,
name: 'my-db',
credentials: {
username: 'username',
password: 'password'
}
}
});
server.listen();
Where do I find the host, port, name, and credentials that I should use from MongoDB? The tutorials say I need to use my own data, but I don't know where or how to find them.
First of all, you have to have MongoDB installed. I haven't used Deployd myself, but I will give you some information regarding the config file.
If you are running Mongo on the same ubuntu server as your application, you can use localhost to connect.
Default Mongo install runs on port 27017, in other words localhost:27017.
The 'name' parameter is just a name you give your database. So here you can put whatever you want, ex my-db.
With a clean Mongo install, you don't need any credentials. You have to set that up yourself if you want. I suppose leaving them out of the config file is ok, if not needed.
Your config file should therefor look something like this:
var server = deployd({
port: process.env.PORT || 5000,
env: 'production',
db: {
host: 'localhost',
port: 27017,
name: 'my-db'
}
});
update
I had a quick look at the tutorial you linked to. In one of the tutorials they created a user for mongodb. If you followed this step, you need to put that login information into you connect-object under credentials.
update 2
To get information about your mongodb install, check this SO post

Categories

Resources