Answers: <p>A tool that I think is rather under recognised is <a href="https://github.com/openshift/source-to-image" rel="nofollow noreferrer">s2i</a>. The basic idea is that you don’t put a Dockerfile into your source repo specifying the runtime to use you keep your app code bare (just code). The decision as to which security patched s2i image to compile and run the code with is a separate matter that is independent and can be centrally managed.</p>
  
  <p>The way this is used in the OKD world is that a “BuildConfig” pulls your code from git to make an application image and is trigger by either a git webook or a docker registry push that updated the s2i image with a security patch. </p>
  
  <p>In our case we have many node and php apps. To security patch either runtime we push the latest s2i image into our OKD docker registry and that causes all our application images to be recreated and redeployed. </p>
  
  <p>Why I think that is of interest is that it basically says that what the code is, and how the code is run from a container security perspective, should not be conflated. They are two concerns that are not on the same cadence. A high impact vulnerability should be patched in the main test environment immediately and not be dependent on talking to several scrum teams about pushing a change to the Dockerfile in each team’s git repo. </p>
  
  <p>When you have many apps or many small dev teams that separation to do “policy based security patching” of containers can be very useful. You can run s2i on your desktop or with container based SaaS ci tool such as <a href="https://gist.github.com/simbo1905/056d193328c81250a54b7c68f8a9e77b" rel="nofollow noreferrer">circleci</a>. It would be straightforward to run it in, say, Jenkins. That means you can have, say, dozens of micro service Jenkins deploy jobs triggered by git webook that run s2i and push the final image. You can then control the version of the s2i image you use in all the Jenkins jobs in one place. You can then script a security update that updates the s2i docker url to the latest security fix and triggers all Jenkins release jobs to run to apply the patched s2i to all microservices. No code or config needs to change in any git repo.</p>
  
  <p>While I mention OKD by default it doesn’t let you run a container image as uid 0 (root). It uses a random uid and gid 0. This is for security in case the process gets out of its jail and tries to modify the host. Most public docker images just expect you run as root and file permission don’t let you run the app in the image as an arbitrary uid as <code>docker —user ${rand_uid}:0</code>. You have to bake an image that gives gid 0 the file permissions to run the app. The s2i images all work under these circumstances. </p>
  
  <p>If you need apps in docker to lookup the use details in <code>/etc/passwd</code> when running as a random uid the you can fake that. <a href="https://github.com/ocd-scm/ocd-environment-webhook/blob/039162d357c3d01c09ff03177352b889ce7605f0/bin/ocd-checkout-env.sh#L10" rel="nofollow noreferrer">Here</a> is a script that runs git in docker as random uid where git wants to lookup the current in <code>/etc/passwd</code> so the script fakes it. </p>
  
  <p>The lesson here IMHO is that while in theory docker gives perfect isolation in practice all code is subject to security flaws. In theory many small dev teams will update all Dockerfiles immediately or very frequently but in practice dev teams are focused on features not long term security patching. (I work with one microservies platform that currently has >200 git repos and dev teams on three continents so coordinating anything is a challenge.) So security should be “defence in depth” and take concrete steps to do centralised patching of container images, not run containers as root, and use a random uid that isn’t in the host <code>/etc/passwd</code> so cannot read or write outside of its jail. </p>
  
Answers: CC BY-SA 4.0
Answers: 2019-02-04T22:45:42.210Z
Answers: 2019-02-09T07:08:24.163Z
Answers: 2019-02-09T07:08:24.163Z
Answers: simbo1905
Answers: <p>You might also want to run a scan for security vulnerabilities of some sample base images so your students get an idea of how changing the base can affect how secure your image is. For example comparing an alpine image versus a full blown Ubuntu image (especially some of the older Ubuntu images).</p>
  
  <p>Clair is a decent scanner that can be <a href="https://github.com/arminc/clair-scanner" rel="nofollow noreferrer">set up fairly easily</a> in docker containers. It is also the scanner that <a href="https://docs.gitlab.com/ee/ci/examples/container_scanning.html" rel="nofollow noreferrer">GitLab use for container scanner</a> if you use their CI / CD platform.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-02-08T17:48:03.280Z
Answers: 2019-02-08T17:48:03.280Z
Answers: Andrew Monkhouse
Answers: <p>In my experience with "raising awareness about security" (for technical-minded people) is simply to show them the problem in action.</p>
  
  <p>Find out what concrete, practical problems actually exist, and just show them (by actually showing, or by having them find out for themselves).</p>
  
  <p>All docker security problems I've come upon have been quite self-evident and kind of obvious in hindsight. Except for one issue way back (pre-1.0) where they originally had blacklist for kernel calls instead of whitelists, most other issues can readily be shown by configuration, or hello-world style images, or by sharp thinking ("do we really want to use the IAmNotEvil/SpecialUbuntuDistribution image from dockerhub instead of an official, and how do we know the official one is good?").</p>
  
  <p>Oh, and for a complete discussion, don't forget to show them in which aspects Docker is <em>more</em> secure (or more easily secured) than a plain server...</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-02-09T19:36:00.877Z
Answers: 2019-02-09T19:36:00.877Z
Answers: AnoE
Body: <p>I'm in the process of preparing a Docker course for students with little to no familiarities with containers, the underlying OS mechanisms involved, and their implied limitations.</p>
  
  <p>In many Docker tutorials, security concerns often go unmentioned. And it is easy to assume there are not much security issues involved by running containerized application on a general purpose system.</p>
  
  <p>On my side, I would raise students awareness about these issues early as part of my course. It is not necessarily about teaching them how to mitigate these issues. But really about dismantle that misconception Docker is secure by default. Unfortunately, I could not afford spending to much curriculum time on these aspects.</p>
  
  <p><strong>So, I'm looking for tools and/or examples that could be easily run and understood by my students so they get an idea of the possible security implications of using Docker. What would you suggest?</strong></p>
  
  <p><hr>
  For what it worth, I initially thought about:</p>
  
  <ul>
  <li><a href="https://www.electricmonk.nl/log/2017/09/30/root-your-docker-host-in-10-seconds-for-fun-and-profit/" rel="nofollow noreferrer">rooting a Docker host</a> -- which seems a good example</li>
  <li>and running <a href="https://github.com/docker/docker-bench-security" rel="nofollow noreferrer">Docker Bench</a>. But from <a href="https://devops.stackexchange.com/a/6221/11179">that answer</a>, Docker Bench is probably not the best tool for my particular needs.</li>
  </ul>
  
Tags: <docker><devsecops>
Title: How to raise awareness about the security risk involved with running Docker?
UserDisplayName: Sylvain Leroux
ThreadText: # How to raise awareness about the security risk involved with running Docker?
  
  (Asked by: username_0 on 2019-02-04)
  
  I'm in the process of preparing a Docker course for students with little to no familiarities with containers, the underlying OS mechanisms involved, and their implied limitations.
  
  In many Docker tutorials, security concerns often go unmentioned. And it is easy to assume there are not much security issues involved by running containerized application on a general purpose system.
  
  On my side, I would raise students awareness about these issues early as part of my course. It is not necessarily about teaching them how to mitigate these issues. But really about dismantle that misconception Docker is secure by default. Unfortunately, I could not afford spending to much curriculum time on these aspects.
  
  **So, I'm looking for tools and/or examples that could be easily run and understood by my students so they get an idea of the possible security implications of using Docker. What would you suggest?**
  
  ---
  
  For what it worth, I initially thought about:
  
  * [rooting a Docker host](https://www.electricmonk.nl/log/2017/09/30/root-your-docker-host-in-10-seconds-for-fun-and-profit/) -- which seems a good example
  * and running [Docker Bench](https://github.com/docker/docker-bench-security). But from [that answer](https://devops.stackexchange.com/a/6221/11179), Docker Bench is probably not the best tool for my particular needs.
  
  **Tags:** docker, devsecops
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2019-02-04. Score: 3
  
  A tool that I think is rather under recognised is [s2i](https://github.com/openshift/source-to-image). The basic idea is that you don’t put a Dockerfile into your source repo specifying the runtime to use you keep your app code bare (just code). The decision as to which security patched s2i image to compile and run the code with is a separate matter that is independent and can be centrally managed.
  
  The way this is used in the OKD world is that a “BuildConfig” pulls your code from git to make an application image and is trigger by either a git webook or a docker registry push that updated the s2i image with a security patch.
  
  In our case we have many node and php apps. To security patch either runtime we push the latest s2i image into our OKD docker registry and that causes all our application images to be recreated and redeployed.
  
  Why I think that is of interest is that it basically says that what the code is, and how the code is run from a container security perspective, should not be conflated. They are two concerns that are not on the same cadence. A high impact vulnerability should be patched in the main test environment immediately and not be dependent on talking to several scrum teams about pushing a change to the Dockerfile in each team’s git repo.
  
  When you have many apps or many small dev teams that separation to do “policy based security patching” of containers can be very useful. You can run s2i on your desktop or with container based SaaS ci tool such as [circleci](https://gist.github.com/username_1/056d193328c81250a54b7c68f8a9e77b). It would be straightforward to run it in, say, Jenkins. That means you can have, say, dozens of micro service Jenkins deploy jobs triggered by git webook that run s2i and push the final image. You can then control the version of the s2i image you use in all the Jenkins jobs in one place. You can then script a security update that updates the s2i docker url to the latest security fix and triggers all Jenkins release jobs to run to apply the patched s2i to all microservices. No code or config needs to change in any git repo.
  
  While I mention OKD by default it doesn’t let you run a container image as uid 0 (root). It uses a random uid and gid 0. This is for security in case the process gets out of its jail and tries to modify the host. Most public docker images just expect you run as root and file permission don’t let you run the app in the image as an arbitrary uid as `docker —user ${rand_uid}:0`. You have to bake an image that gives gid 0 the file permissions to run the app. The s2i images all work under these circumstances.
  
  If you need apps in docker to lookup the use details in `/etc/passwd` when running as a random uid the you can fake that. [Here](https://github.com/ocd-scm/ocd-environment-webhook/blob/039162d357c3d01c09ff03177352b889ce7605f0/bin/ocd-checkout-env.sh#L10) is a script that runs git in docker as random uid where git wants to lookup the current in `/etc/passwd` so the script fakes it.
  
  The lesson here IMHO is that while in theory docker gives perfect isolation in practice all code is subject to security flaws. In theory many small dev teams will update all Dockerfiles immediately or very frequently but in practice dev teams are focused on features not long term security patching. (I work with one microservies platform that currently has >200 git repos and dev teams on three continents so coordinating anything is a challenge.) So security should be “defence in depth” and take concrete steps to do centralised patching of container images, not run containers as root, and use a random uid that isn’t in the host `/etc/passwd` so cannot read or write outside of its jail.
  
  
  ---
  
  ### Answer by username_2 on 2019-02-08. Score: 3
  
  You might also want to run a scan for security vulnerabilities of some sample base images so your students get an idea of how changing the base can affect how secure your image is. For example comparing an alpine image versus a full blown Ubuntu image (especially some of the older Ubuntu images).
  
  Clair is a decent scanner that can be [set up fairly easily](https://github.com/arminc/clair-scanner) in docker containers. It is also the scanner that [GitLab use for container scanner](https://docs.gitlab.com/ee/ci/examples/container_scanning.html) if you use their CI / CD platform.
  
  
  ---
  
  ### Answer by username_3 on 2019-02-09. Score: 1
  
  In my experience with "raising awareness about security" (for technical-minded people) is simply to show them the problem in action.
  
  Find out what concrete, practical problems actually exist, and just show them (by actually showing, or by having them find out for themselves).
  
  All docker security problems I've come upon have been quite self-evident and kind of obvious in hindsight. Except for one issue way back (pre-1.0) where they originally had blacklist for kernel calls instead of whitelists, most other issues can readily be shown by configuration, or hello-world style images, or by sharp thinking ("do we really want to use the IAmNotEvil/SpecialUbuntuDistribution image from dockerhub instead of an official, and how do we know the official one is good?").
  
  Oh, and for a complete discussion, don't forget to show them in which aspects Docker is *more* secure (or more easily secured) than a plain server...
  
  
  ---
  
  