Updates Dockerfile to include security

Mongo users are also now being set up correctly.
This commit is contained in:
Patrick McDonagh
2017-05-03 10:46:22 -05:00
parent 51c20d2e46
commit bdae9f2f12
4 changed files with 31 additions and 23 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
poc_variables.js

View File

@@ -7,9 +7,9 @@ RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep D
RUN apt-get update && apt-get install -y mongodb-org RUN apt-get update && apt-get install -y mongodb-org
RUN mkdir -p /data/db RUN mkdir -p /data/db
COPY setup_mongo_admin.js /tmp/setup_mongo_admin.js COPY setup_mongo_users.js /tmp/setup_mongo_users.js
RUN mongod --fork --logpath=/var/log/mongodb.log && sleep 5 && mongo < /tmp/setup_mongo_admin.js RUN mongod --fork --logpath=/var/log/mongodb.log && sleep 5 && mongo < /tmp/setup_mongo_users.js
# COPY mongod.conf /etc/mongod.conf COPY mongod.conf /etc/mongod.conf
EXPOSE 27107 EXPOSE 27107
CMD ["/usr/bin/mongod"] CMD ["/usr/bin/mongod"]

View File

@@ -1,20 +0,0 @@
admin = db.getSiblingDB('admin');
admin.createUser(
{
user: "admin",
pwd: "HenryPump@1903",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
);
poc = db.getSiblingDB('poc');
poc.createUser({
user: "poc_www",
pwd: "HenryPump1903",
roles: [ { role: "readWrite", db: "poc" } ]
});
poc.createUser({
user: "poc_java",
pwd: "HenryPump@1903",
roles: [ { role: "readWrite", db: "poc" } ]
});

26
setup_mongo_users.js Normal file
View File

@@ -0,0 +1,26 @@
var ADMIN_USER = {username: "", password: ""};
var USERLIST = [
{username: "", password: "", db: ""},
{username: "", password: "", db: ""},
];
var admin_db = db.getSiblingDB('admin');
admin_db.createUser(
{
user: ADMIN_USER.username,
pwd: ADMIN_USER.password,
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
);
for (var i = 0; i < USERLIST.length; i++){
var user = USERLIST[i];
var user_db = db.getSiblingDB(user.db);
user_db.users.insert({username: user.username});
user_db.createUser({
user: user.username,
pwd: user.password,
roles: [ { role: "readWrite", db: user.db } ]
});
}