-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
auth=true creates users but does not limit other logins in recent mongo versions #192
Comments
Oh, the default properties for my environment don't contain the properties added later, in case that was unclear. |
roles and database being required should be updated in the documentation too, it is very unclear |
This still doesn't work exactly how I would expect, you can still open mongo client without specifying a user, but at least you can't really do anything. So other options might be needed in addition... [vagrant@bluesky-db-prod ~]$ mongo fish
|
My mongo-fu is kinda weak, but doesn't the localhost exception allow a way out of that catch-22? |
Using localhost exception would be fine to create initial admin user (or all of them I guess), but for defense in depth it should be disabled after that I would think. In any event I am currently having to not include user_management after first run because it throws a bunch of warnings and occasionally caused the run to fail. iCanLogIntoMongo = system('mongo --quiet -u adminuser -p adminpass --eval "db.system.users.find({user:'someuser'}).count()" admin') |
The local host exemption seems to be automatically disabled once you've used it by the server. Basically, "if authentication is enabled and there are no users in the admin db, allow someone to create that user". So once that user is made, the conditions of the exemption stop applying. I've been playing a bit with this recipe trying to get an understanding of both the code and mongo authentication. So bear with me, part of this is rubber duck debugging. Are you using v1 or v2 of the mongodb gem? There seem to be different code paths based on which version is installed. Part of the problem seems to be that the act of creating the admin user calls some functionality that requires admin privileges, such as listing users and databases. Part of this is because, as you've noted, the cookbook doesn't actually enable authentication, so it's gone unnoticed. The good news is I'm able to replicate the problem and also have an inspec test to ensure that authentication is turned on (basically looking through startup logs to make sure that "authentication is disabled you fool!" message doesn't appear) I think the code solution here is to build a separate mechanism for creating that admin user rather than the current method of prepending it to the list of users and treating it the same. But would love to hear from people more learned than myself. |
Did you ever find out if you were using v1 or v2 of the mongo gem?
For test-kitchen, I'm able to create users and enable auth with the following attributes when using the default v1 of the gem, but it gets the same problems as you for v2. mongodb:
config:
auth: true
mongod:
security:
authorization: enabled |
[root@bluesky-db-uat dbsave]# /opt/chef/embedded/bin/gem list --local *** LOCAL GEMS *** addressable (2.5.2, 2.4.0) |
Still hitting this with v1 so bump. *** LOCAL GEMS *** mongo (1.12.5) |
[root@docker-db-dev ~]# mongo -version |
There are multiple reasons why this is failing on MongoDB > 3.0. First and foremost, as already indicated, authentication is not even enabled by the cookbook if Second it seems that the localhost exception no longer allows more than just the initial admin user to be added And third, when using mongo gem ~> 2.0, the method
And fourth, it seems that
So it looks like for adding the initial admin user, the current library functions will not work. I'm currently trying to fix this issue (and address several others, like converting the definition into a custom resource, and systemd unit files) in a fork and will file PR's when done. |
Marking stale due to inactivity. Remove stale label or comment or this will be closed in 7 days. Alternatively drop by the #sous-chefs channel on the Chef Community Slack and we'll be happy to help! Thanks, Sous-Chefs. |
As discussed in the documentation for the latest release (https://docs.mongodb.com/manual/tutorial/enable-authentication/) if a configuration file is in use then --auth doesn't have any effect but the security.authorization setting is required in the configuration file. There is a catch22 implied by that tutorial also. If we simply add the security.authorization setting (default['mongodb']['config']['mongod']['security']['authorization'] = 'enabled') this blows up with huge errors because the users cannot be created (since there is no admin login by default)
My workaround, which seems okay but ugly is something like this:
#Set passwords from databag for admin user
node.default['mongodb']['admin']['username'] = 'myadminuser'
node.default['mongodb']['admin']['password'] = db_passwords["mongodb_password"]
node.default['mongodb']['admin']["roles"] = [ "userAdminAnyDatabase" ]
node.default['mongodb']['admin']["database"] = 'admin'
myuser = {
"username" => "rouser",
"password" => db_passwords["mongodb_ro_password"],
"roles" => [ "read" ],
"database" => "#{node.chef_environment}"
}
node.default['mongodb']['users'] << myuser
include_recipe "sc-mongodb::default"
#There is a restart here
include_recipe "sc-mongodb::user_management"
#There is a restart here
bash 'add in user level security after mongo users are created' do
code <<-EOH
echo "security:\n authorization: enabled\nsetParameter:\n enableLocalhostAuthBypass: false" >> /etc/mongod.conf
EOH
not_if 'grep -c "enableLocalhostAuthBypass" /etc/mongod.conf'
end
#There is a restart after everything finishes
The text was updated successfully, but these errors were encountered: