Building Effective, Secure Container Delivery Pipelines With Docker
How to apply lessons from shipping code using many different formats in order to build effective, secure container delivery pipelines.
Join the DZone community and get the full member experience.Join For Free
opinions on how best to package and deliver applications are legion and, like many other aspects of the software world, are subject to recurring trend cycles. on the server-side, the current favorite is container delivery : a “full stack” approach in which your application and everything it needs to run are specified in a container definition . that definition is then “compiled” down to a container image and deployed by retrieving the image and passing it to a container runtime to create a running instance.
here, i’d like to talk about how we can apply lessons from experience of shipping code using many different formats in order to build effective, secure container delivery pipelines.
the way it’s described above, container delivery does not sound much different from most other packaging and deployment models: replace container image with war file , ami or ova and the process looks pretty much the same. a trivial point, perhaps, but one worth making: the fact that containers aren’t that different from other full stack formats means that there are quite a few lessons that we’ve already learned which we can apply to the process of building and delivering containers.
one thing certainly does stand out in the general discussion around container delivery, however: the strong emphasis on how containers apparently will “empower the developer” and “free them from the shackles of ops.” unlike delivering, say, a war file, .net application or rails app, however, a container is not just a bundle of traditional “application code”. it includes all the other levels of the software stack, right down to the operating system.
most container technologies provide nice mechanisms that mean that developers generally don’t have to bother with the actual details of configuring all the lower levels, but can inherit these from a base image instead. in most cases, though, the developer – as the “deliverer” of the final artifact – is still ultimately responsible for the entire container.
the point being: application developers often aren’t expert at, or even particularly interested in, the levels of the system below the application tier. the tendency more frequently – and i’ve fallen victim to this temptation myself – is to “just quickly change this setting because i read in that stack overflow post that it might fix the problem we’re having.”
this is especially tempting with containers as a distribution format because the “system levels” are encapsulated in the base image and so are practically invisible – a generally very desirable characteristic. with other full stack packaging formats – ovas, virtual boxes, amis and the like – the system levels are not abstracted away as much, so it feels more logical that ops should play a role in the production process of such packages.
not that the “in your face” presence of the system levels is something we want to repeat: arguably, one of the reasons the other formats haven’t caught on in the way many hope containers will is precisely because they have such a comparatively heavyweight feel. still, as the recent discussions about the number of insecure images in the docker registry shows, we need to find a way to add more ops-side input into the container delivery process than is common today.
the points below assume that the development team is indeed ultimately responsible for the definition of the entire system. different models are possible with containers, too. for example, you could have a paas-like model in which the developers provide app components that are automatically combined with an ops-owned container definition. however, i would not call this a container delivery model because here the container definition is not the deliverable, but a runtime implementation detail.
here, then, are my “food for thought” discussion points for building effective, secure container delivery pipelines.
1. developers provide container definitions in scm
the container definition – dockerfile or other, higher-level definition that “compiles down” to a container descriptor – is the source deliverable, and so should be stored as a versioned artifact in a source control repository.
2. container definitions and dependencies are compiled to container images in an ops-controlled environment
concretely: the build or ci system that generates the container images from the container definitions should not be owned or administered by the development team. this helps ensure that all ops-related checks that need to be executed against the container definitions and associated dependencies are carried out correctly.
implementing this recommendation does not require the entire ci setup to be controlled by ops. for example, you could limit direct publish access to your image registry to an ops-managed “image build service”, which could be called from a developer-run ci server.
3. minimal base image catalog is enforced
just as many build environments for application code enforce a whitelist of libraries and other allowed dependencies, your container pipeline should only process container definitions that inherit from a whitelisted set of supported base images. from a maintenance perspective, this whitelist should be as small as possible.
if exceptions need to be made – a particular project requires a component that can only run on a specific os, for example – these should be limited to container definitions for that specific project.
4. developer-provided container definitions can be pre-processed to choose a different base image
requiring development teams to manually update their container definitions in source control whenever the base image whitelist is updated, e.g. after a security patch, is tedious and creates unnecessary delay. instead, the image build system should be able to automatically choose a different base image, if necessary, with suitable notification back to the development team.
container definition formats that allow symlink-style image references, such as docker via the latest tag, can support this out-of-the-box. however, you may want to exert more fine-grained control over base image choice, such as automatically replacing a reference to an explicitly-specified version such as v10.4.8 by v10.4.9 if 10.4.9 contains an important security patch.
5a. developer-provided container definitions can be scanned to enforce particular policies
in general, even though image inheritance means that developers generally don’t need to mess with lower-level system settings in their container definitions, nothing prevents them from doing so. for example, the container definition could change the security configuration of the os, install insecure versions of libraries, create open mail relays etc. etc.
ideally, code review that includes ops will prevent such changes from ever making it into the container definition. you will most likely also be running security scans against your running container instances to try to catch such problems after the fact. the ability to automatically check for “problematic” parts of a container definition at image build time – having a linter for container definitions, if you will – is an additional tool that should be in your toolbox, however.
5b. developer-provided containers can be “ black box ” tested to enforce particular policies
if the previous point can be described as “white box” testing of container definitions, then this point is about black box testing of the resulting image: ensure that your image build system is able to create instances of new container definitions in a safe/sandbox environment and run assertions (using a tool such as cucumber or similar) against them.
6. images in your registry that were created from a particular base image can be invalidated
the ability to enforce a base image whitelist at build time should prevent any new container images from referencing insecure or otherwise unsupported base images. but what about all those images already in your registry that inherited from such a base image? how do you prevent new container instances being created from those?
consider implementing a system that allows you to check, just before spinning up a container instance from an image, whether that image is still “safe”. this can be as simple as creating a wrapper for your ‘instantiate container’ command that checks for the absence of an ‘unsupported’ tag or other piece of metadata on the image, or as advanced as a plugin or extension that hooks directly into your container runtime.
7. images derived from a “banned” base image can be rebuilt using an updated base image automatically
when a base image is banned, you want to be able to immediately trigger new container image builds, using an updated base, for each container definition inheriting from the now banned base image. otherwise, you won’t have any runnable container images for that application until the next code change, or until someone manually triggers the delivery pipeline for that app, since the latest version is now “unsafe”.
note that i’m not trying to recommend this as a “standard” part of the image build process – the correct way to create new container definitions once a base image is invalidated is definitely to update the container definition in source control and allow the pipeline to build a new image version based on that. rather, this capability is a stop-gap solution to help bridge the gap until the new image is available.
8. post-deployment commands can be automatically run against running containers
while all the new image versions are building, you’ll still have plenty of running container instances that use the now banned base image. in that case, it’s very useful to be able to specify commands to be run automatically against all container instances that meet a certain condition (such as inheriting from a particular base image).
modifying containers at runtime in this way is generally frowned upon, and this capability should again only be considered a temporary fix until new image versions based on updated container definitions in source control have been built, and all running instances have been updated.
but if you have large numbers of running container instances and many images that need rebuilding (which might take quite some time – think build storm), the ability to quickly apply an “emergency band-aid” can be essential. even if it only takes a few minutes until all the new images have been built and all running container instances have been updated, that can still be a big problem in the face of a critical security vulnerability.
for inspiration: how shipping containers are made
with thanks to boyd hemphill for his thoughtful review comments.
Published at DZone with permission of Andrew Phillips, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.