Why mongo login without auth data? - mongodb

I create admin-user for some db. Look dump:
>db.system.users.find().pretty()
{
"_id" : ObjectId("533aa7175572233602378633"),
"user" : "root",
"pwd" : "06dbc97127a71ab5b359a6a6e9ff5f53",
"roles" : [
"readWrite",
"userAdmin",
"dbAdmin",
"readWriteAnyDatabase",
"userAdminAnyDatabase",
"dbAdminAnyDatabase"
]
}
Check login:
mongo some_db -u root -p 5415 - ok!
mongo some_db -u root -p 54153 - error!
mongo some_db - ok! Why this method allows you to enter into the database?

You have to set the auth configuration to true to require authentication.
Important tip: If you set the option to true but you don't have any users you can still connect using "localhost" from inside the server
Source here

You won't be able to access anything because you are not authenticated.

Related

Mongodb Compass: Connection timed out

I installed Mongodb on my remote server using this documentation. I have Ubuntu 16.04 on my remote server. Mongodb got installed successfully. I added the user like this:
use admin
db.createUser(
{
user: 'myuser',
pwd: 'password',
roles: [ { role: 'readWrite', db: 'mydb' } ]
}
);
I also made changes in the mongod.conf like this:
net:
port: 27017
bindIp: 127.0.0.1,<server_ip>
security:
authorization: 'enabled'
Now when I try to connect to mongodb using conneciton string like this:
mongodb://myuser:password#server_ip:27017/mydb
It gives me the following error:
connection timed out
What am I doing wrong here? I am using Laravel Forge to manage sever.
As it turned out the port was not open and that was the only issue. Opened the port and now its working fine.

user authentication not working on mongodb 3.6.5

I have installed mongodb 3.6.5 on aws ec2 server and setup following in .conf file
net:
port: 27017
bindIp: serverIP
security:
authorization: 'enabled'
then created user with following command in admin db and restarted mongodb
db.createUser(
{
user: "mydbuser",
pwd: "mydbpass",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
now when I try to access db from console with following command if doesnt allow me and gives me error of authentication.
mongo serverIP --port 27017 -u "mydbuser" -p "mydbpass" --authenticationDatabase "admin"
Can someone help me what is wrong with it.
getting following error
MongoDB server version: 3.6.5
2019-01-11T08:46:50.245+0000 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1608:20
#(auth):6:1
#(auth):1:2
exception: login failed
The method you are following is correct but there is some variations in mongodb while accepting credentials as string. You might need to enclose your username and password within single quote instead of double quote as follows.
mongo serverIP --port 27017 -u 'mydbuser' -p 'mydbpass' --authenticationDatabase 'admin'
Double quotes will work if you dont have special characters in your username/password.
For more details on mongo Check here https://docs.mongodb.com/manual/reference/program/mongo/

Keycloak: Admin-cli Add SMTP server details?

In our keycloak we have written admin-cli command to make things smooth after keycloak bought up .We will create some basic Realm/user/group and other details from the help of admin-cli .
Now we want to add the SMTP server details through admin-cli . How can be achieve this ?
Ok at last too many hit and try i found the solution . Here is the details how to add the SMTP server details via admin-cli
First Step Enable HTTPS(As in our case keycloak running on HTTPS)
/opt/keycloak/bin/kcadm.sh config truststore --trustpass keycloak /opt/keycloak/security/ssl/keycloak.jks
Second Step Login with client admin-cli
/opt/keycloak/bin/kcadm.sh config credentials --server https://{{keycloak_server_IP}}:{{keycloak_port}}/auth --realm master --user admin --password admin --client admin-cli
If realm not created create it via this
/opt/keycloak/bin/kcadm.sh create realms -s realm=SURE -s enabled=true
and then run below command
/opt/keycloak/bin/kcadm.sh update realms/CRUE_Realm -x -s 'smtpServer.host=Your Host Name' -s 'smtpServer.from=email#somemail.com' -s 'smtpServer.fromDisplayName=Mail Support' -s 'smtpServer.auth=false' -s 'smtpServer.ssl=false'
You can also use this command
/opt/keycloak/bin/kcadm.sh update realms/CRUE_Realm -f - << EOF
{"smtpServer" : {
"replyToDisplayName" : "...",
"starttls" : "",
"auth" : "true",
"envelopeFrom" : "...",
"ssl" : "true",
"password" : "...",
"port" : "...",
"host" : "...",
"replyTo" : "...",
"from" : "...",
"fromDisplayName" : "...",
"user" : "..."
}
}
EOF

Connect session in PostgreSQL with SailsJS

I have a personal project in SailsJS, Passport-Local and PostgreSQL. I managed to get connection and save users in PostgreSQL DB. But I have big problem with session storing. From what I know SailsJS is using Connect to get it done.
Previous working code for MongoDB:
connections: {
prodMongodbServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
//user: '',
//password: '',
database: 'sails-auth'
}
},
session: {
adapter: 'mongo',
host: 'localhost',
port: 27017,
db: 'sails-auth',
collection: 'sessions'
}
My (working) connection to PostgreSQL:
connections: {
somePostgresqlServer: {
adapter: 'sails-postgresql',
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'Password1',
database: 'sails-auth'
}
},
And the code I have problem with:
session: {
adapter: 'connect-pg-simple',
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'Password1',
db: 'sails-auth'
}
I've installed connect-pg-simple, executed SQL code but when I am starting sails app I get an error:
$ sails lift
info: Starting app...
Init Express midleware
Failed to prune sessions: password authentication failed for user "myPcUser"
info:
info: .-..-.
info:
info: Sails <| .-..-.
info: v0.11.3 |\
info: /|.\
info: / || \
info: ,' |' \
info: .-'.-==|/_--'
info: `--'-------'
info: __---___--___---___--___---___--___
info: ____---___--___---___--___---___--___-__
info:
I thought that it may be beetter to use connect-pg, but it requires so many dependecy that I stayed with simple version. Anyone know what this problem is about? Im on windows so its weird that it have problem with my PC User...
Or maybe someone have some solution for using PostgreSQL for users, etc and Mongo for sessions. For what I've tested Passport doesnt allow to do that (user can sign up but can't sign in)
Perhaps you can fix this error open PostgreSQL client authentication configuration file:
/var/lib/pgsql/data/pg_hba.conf
and change:
local all all trust
host all 127.0.0.1/32 trust
Save and close the file. Restart Postgresql server:
service postgresql restart
To make it work
Install the connect-pg-simple node module: $ npm install connect-pg-simple
In session.js define the adapter and connection string:
adapter: 'connect-pg-simple',
conString: 'postgres://user:pass#host:5432/dbname',
3) run the SQL commands on file node_modules/connect-pg-simple/table.sql to create the table for sessions. :
CREATE TABLE "session" (
"sid" varchar NOT NULL COLLATE "default",
"sess" json NOT NULL,
"expire" timestamp(6) NOT NULL
)
WITH (OIDS=FALSE);
ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
CREATE INDEX "IDX_session_expire" ON "session" ("expire");
I used for that sails-pg-session.
The information about sessions must be stored in config/session.js:
adapter: 'sails-pg-session',
database: 'dbname',
host: 'localhost',
user: 'dbuser',
password: 'dbpasswd',
port: 5432
Hope it helps

How to use mongodb-express with MeteorJS' MongoDB?

I'm building an application in MeteorJS.
I want to have GUI access to built-in MongoDB database.
So I found: https://github.com/andzdroid/mongo-express
I installed it, configured it to connect to localhost:3001.
Since mongodb doesn't have a default admin password, I tried to create it by:
meteor mongo
use admin
db.addUser("admin","password")
then I set
adminUsername: 'admin',
adminPassword: 'password',
in mongo-express\config.js.
However when I open localhost:8081, it asks me login credentials again and even if I insert them manaully (admin, password) it doesn't work.
So I went back to meteor mongo, tried to create admin user again and go error
Error: couln't add user: User admin#admin" already exists
What am I doing wrong?
edit /usr/local/lib/node_modules/mongo-express/config.default.js
find and edit to:
} else {
mongo = {
db: 'meteor',
host: 'localhost',
password: '',
port: 3001,
ssl: false,
url: 'mongodb://localhost:3001/meteor',
username: '',
};
}