-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Docker as non root user. docker-compose build now succeeds. #78
Docker as non root user. docker-compose build now succeeds. #78
Conversation
I'm going to be working through docker security soon, so I may be adding changing some defaults. I'm starting to realise how much additional attack surface docker brings to the table. Check this doc (https://benchmarks.cisecurity.org/downloads/show-single/?file=docker12.100) by CIS. The added speed docker gives devops doesn't come for free. Everything has a cost, we either pay now or later, the earlier we pay, the less exploited we (our dev teams and customers) will be. |
@@ -10,5 +10,6 @@ services: | |||
- mongo | |||
mongo: | |||
image: mongo:latest | |||
user: mongodb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mongo now also runs as non-root user. I've tested that mongodb doesn't need to be a host user.
docker ps --quiet | xargs docker inspect --format '{{ .Id }}: User={{.Config.User}}'
yields:
<web container hash>: User=nodegoat_docker
<mongo container hash>: User=mongodb
I tested with a couple of tests:
binarymist@2c596c1
binarymist@37b8a3a
Without user: mongodb
configured, the results of the above command look like:
<web container hash>: User=nodegoat_docker
<mongo container hash>: User=
Notice the absence of mongodb
? That means root
is the user running the container.
RUN npm install | ||
COPY . $workdir | ||
|
||
# Permissions need to be reaplied, due to how docker applies root to new files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before reapplying non-root user ownership and removal of other permissions (that's this change), the directory listings looked like this:
Step 12 : RUN ls -liah
---> Running in f8692fc32cc7
total 116K
13 drwxr-xr-x 9 nodegoat_docker nodegoat_docker 4.0K Sep 13 09:00 .
12 drwxr-xr-x 7 root root 4.0K Sep 13 09:00 ..
65 drwxr-xr-x 8 root root 4.0K Sep 13 08:59 .git
53 -rw-r--r-- 1 root root 178 Sep 12 04:22 .gitignore
69 -rw-r--r-- 1 root root 1.9K Nov 21 2015 .jshintrc
61 -rw-r--r-- 1 root root 55 Nov 21 2015 .nodemonignore
58 -rw-r--r-- 1 root root 715 Sep 13 08:59 Dockerfile
55 -rw-r--r-- 1 root root 6.6K Sep 12 04:16 Gruntfile.js
60 -rw-r--r-- 1 root root 11K Nov 21 2015 LICENSE
68 -rw-r--r-- 1 root root 48 Nov 21 2015 Procfile
64 -rw-r--r-- 1 root root 5.6K Sep 12 04:22 README.md
56 drwxr-xr-x 6 root root 4.0K Nov 21 2015 app
66 -rw-r--r-- 1 root root 527 Nov 15 2015 app.json
54 drwxr-xr-x 3 root root 4.0K May 16 11:41 artifacts
62 drwxr-xr-x 3 root root 4.0K Nov 21 2015 config
57 -rw-r--r-- 1 root root 244 Sep 13 04:51 docker-compose.yml
67 drwxr-xr-x 498 root root 20K Sep 12 03:50 node_modules
63 -rw-r--r-- 1 root root 1.4K Sep 12 04:22 package.json
52 -rw-r--r-- 1 root root 4.6K Sep 12 04:01 server.js
59 drwxr-xr-x 4 root root 4.0K Nov 21 2015 test
---> ad42366b24d7
Removing intermediate container f8692fc32cc7
Step 13 : RUN ls ../ -liah
---> Running in 4074cc02dd1d
total 12K
12 drwxr-xr-x 7 root root 4.0K Sep 13 09:00 .
11 drwxr-xr-x 32 root root 4.0K Sep 13 09:00 ..
13 drwxr-xr-x 9 nodegoat_docker nodegoat_docker 4.0K Sep 13 09:00 app
---> 6e0f3ba5f890
Removing intermediate container 4074cc02dd1d
After reapplying non-root user ownership and removal of other permissions (that's this change), the directory listings look like this:
Step 15 : RUN ls -liah
---> Running in 8662e1657d0f
total 116K
13 drwxr-x--- 21 nodegoat_docker nodegoat_docker 4.0K Sep 13 08:51 .
12 drwxr-xr-x 9 root root 4.0K Sep 13 08:51 ..
65 drwxr-x--- 20 nodegoat_docker nodegoat_docker 4.0K Sep 13 08:51 .git
53 -rw-r----- 1 nodegoat_docker nodegoat_docker 178 Sep 12 04:22 .gitignore
69 -rw-r----- 1 nodegoat_docker nodegoat_docker 1.9K Nov 21 2015 .jshintrc
61 -rw-r----- 1 nodegoat_docker nodegoat_docker 55 Nov 21 2015 .nodemonignore
58 -rw-r----- 1 nodegoat_docker nodegoat_docker 884 Sep 13 08:46 Dockerfile
55 -rw-r----- 1 nodegoat_docker nodegoat_docker 6.6K Sep 12 04:16 Gruntfile.js
60 -rw-r----- 1 nodegoat_docker nodegoat_docker 11K Nov 21 2015 LICENSE
68 -rw-r----- 1 nodegoat_docker nodegoat_docker 48 Nov 21 2015 Procfile
64 -rw-r----- 1 nodegoat_docker nodegoat_docker 5.6K Sep 12 04:22 README.md
56 drwxr-x--- 14 nodegoat_docker nodegoat_docker 4.0K Sep 13 08:51 app
66 -rw-r----- 1 nodegoat_docker nodegoat_docker 527 Nov 15 2015 app.json
54 drwxr-x--- 5 nodegoat_docker nodegoat_docker 4.0K Sep 13 08:51 artifacts
62 drwxr-x--- 5 nodegoat_docker nodegoat_docker 4.0K Sep 13 08:51 config
57 -rw-r----- 1 nodegoat_docker nodegoat_docker 244 Sep 13 04:51 docker-compose.yml
67 drwxr-x--- 1428 nodegoat_docker nodegoat_docker 20K Sep 13 08:51 node_modules
63 -rw-r----- 1 nodegoat_docker nodegoat_docker 1.4K Sep 12 04:22 package.json
52 -rw-r----- 1 nodegoat_docker nodegoat_docker 4.6K Sep 12 04:01 server.js
59 drwxr-x--- 8 nodegoat_docker nodegoat_docker 4.0K Sep 13 08:51 test
---> b88d816315b1
Removing intermediate container 8662e1657d0f
Step 16 : RUN ls ../ -liah
---> Running in 0ee2dcc889a6
total 12K
12 drwxr-xr-x 9 root root 4.0K Sep 13 08:51 .
11 drwxr-xr-x 34 root root 4.0K Sep 13 08:51 ..
13 drwxr-x--- 21 nodegoat_docker nodegoat_docker 4.0K Sep 13 08:51 app
---> 1f9f9ad49e73
Removing intermediate container 0ee2dcc889a6
This is a fix so that Docker doesn't run all commands and the container as root. @Pamplemousse : your feedback on this would be good also.
This also includes the temporary downgrade fix for #77