Giter Club home page Giter Club logo

secdocker's Introduction

godoc reference Go Report Card codecov License: MIT

SecDocker Logo

SecDocker

An application firewall for Docker

Description

SecDocker is a Go application that acts as a firewall for Docker. It's designed to receive all the traffic that goes to the Docker API / socket and drop the requests that contain unauthorized parameters. You can provide rules and specifications as well as general restrictions to be applied to every request, modifying the traffic as it goes to the Docker daemon.

This application is meant to run transparently. In order to work, you must redirect the traffic to this tool without modifiying it. The easiest way to do this (specially in a test environment) is by using iptables.

For example:

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 2376 -j REDIRECT --to-port 8999

to redirect external traffic to SecDocker

Config file

An example config file is provided in the repo as config.yml

The config file has the following fields:

  • plugins

    The list of plugins to be loaded

  • restrictions

    Here are the rules that SecDocker checks. If a run command contains any of the rules, the action is blocked.

    Available restrictions:

    • ports
    • users
    • mounts
    • environment
    • securitypolicies
    • images
    • privileged
  • general

    This are the restrictions that are applied to each run instruction after it is checked.

    Available restrictions:

    • memory
    • cpu
    • user
    • environment

Log file

A log file based on Logrus is written to secdocker.log containing information about every event that happens. This includes:

  • Requests received
  • Allowed requests
  • Forbidden options requested

Compile and run

  • To compile:

    go build

  • To run:

    ./secdocker

Testing

To test the code run:

go test `go list ./... | grep -v plugins` -v -cover -coverprofile=coverage.out

To obtain the coverage:

go tool cover -func=coverage.out

Plugins

Plugins are components that are independent from the original program. In our case, the only requirement is that the the plugins must be compiled with the current version of SecDocker in order to work.

To compile them:

go build -buildmode=plugin -o plugin_name.so plugin_name.go

Plugins are called by using Process(image string) bool at the moment. In order to create your own plugin, you must implement this method inside the plugin. The bool response says if the plugin output states that the image is safe.

At the moment, we have 2 plugins:

  • Anchore

    This plugin depends on a working anchore engine (https://hub.docker.com/r/anchore/anchore-engine). It will ask for an analysis of the image. All can be customized inside the config.yml file inside the anchore folder.

  • Notary

    This plugin checks if the local image that is being run has the same digest as the remote image.

CI

The application is designed to be used in DevOps environments to provide a secure use of containers. An example diagram with Jenkins and Github / Gitlab is provided:

Flow diagrams

Blocked create container

Credits

It was built at: https://seguridad.unileon.es/index.php/SecDocker

Notes

The TCP proxy code (tcpintercept package) is a modified version of the one from the project Trudy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.