Skip to content
This repository was archived by the owner on Sep 17, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bd17829
Updated env-config/config-deploy.py to override
Oct 26, 2016
b5ee83e
Adding the original Dockerfile from
Oct 26, 2016
52c66a3
Adding original entrypoint scripts from
Oct 26, 2016
e7b3f63
Disable export of the SECURITY_MONKEY_SETTINGS
Oct 26, 2016
6680712
Remove unnecessary commented out lines
Oct 26, 2016
bc2fb00
Organize order of operations in api-init
Oct 27, 2016
59518f7
1 - Add SECURITY_MONKEY_API_PORT environment
Oct 27, 2016
415d587
Add original Dockerfile for nginx from
Oct 27, 2016
d0d5b5c
Add original securitymonkey.conf for nginx from
Oct 27, 2016
0d291fd
Add original insecure certs for tls provided
Oct 27, 2016
ee4e4e2
Move nginx resources to docker-nginx for simpler
Oct 27, 2016
2af97ae
Add items to .gitignore and
Oct 27, 2016
79a6ecd
Update Dockerfiles to build and run
Oct 27, 2016
cc0766b
Update FQDN settings to use environment
Oct 28, 2016
06e96c2
Update email settings to use environment
Oct 28, 2016
8b63c87
Add documentation for SecurityMonkey Docker
Oct 28, 2016
3d6c0a0
Add a forgotten comma
Oct 28, 2016
01bd572
Update entrypoints to work without chmod +x
Oct 28, 2016
9e6635a
Add a missing equals sign '='
Oct 28, 2016
c88d57e
Remove baked-in insecure certificates
Nov 1, 2016
819f72f
Add new entrypoint for nginx, disables ssl if cert:key pair are not f…
Nov 1, 2016
629cbd0
Add original nginx.conf for reference
Nov 1, 2016
10baf33
Turn daemon off in nginx.conf
Nov 1, 2016
633337d
Update nginx docker build and entrypoint
Nov 1, 2016
479ae6a
Move NGINX Dockerfile to docker-nginx/
Nov 1, 2016
4d3c309
Refactor for local docker development
Nov 4, 2016
560665f
More log changes for Docker
Nov 7, 2016
d84c348
Improvement for local docker-compose development
Nov 7, 2016
7b1a1db
Update securitymonkey.conf to latest from
Nov 7, 2016
ca0d003
Edit ssl crt/key location in securitymonkey.conf
Nov 7, 2016
452690d
Make NGINX output logs to stdout/err for SecurityMonkey Docker
Nov 7, 2016
8fba6d1
Hardcode smapi NGINX endpoint instead of 127.0.0.1 for Docker
Nov 7, 2016
485a920
Updated docker documentation
Nov 7, 2016
a198de6
Simplify config-docker.py in the use of
Nov 8, 2016
4cb743d
Add support for local insecure development
Nov 9, 2016
00021e4
Restore config-deploy.py from upstream
Nov 9, 2016
0ecc6be
Set API_PORT back to a String
Nov 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
secmonkey.env
boto.cfg
.travis.yml
#docs
supervisor
config-default.py
generate-docs.py
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ devlog/
venv/
.idea/

boto.cfg
secmonkey.env
*.crt
*.key

44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# Copyright 2014 Netflix, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ubuntu:14.04
MAINTAINER Netflix Open Source Development <talent@netflix.com>

ENV SECURITY_MONKEY_VERSION=v0.7.0 \
SECURITY_MONKEY_SETTINGS=/usr/local/src/security_monkey/env-config/config-docker.py

RUN apt-get update &&\
apt-get -y -q install python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 curl &&\
apt-get install -y python-pip python-dev python-psycopg2 libffi-dev libpq-dev libyaml-dev libxml2-dev libxmlsec1-dev git sudo swig &&\
rm -rf /var/lib/apt/lists/*

RUN cd /usr/local/src &&\
# git clone --branch $SECURITY_MONKEY_VERSION https://github.com/Netflix/security_monkey.git
/bin/mkdir -p security_monkey
ADD . /usr/local/src/security_monkey

RUN cd /usr/local/src/security_monkey &&\
python setup.py install &&\
/bin/mkdir -p /var/log/security_monkey/

RUN chmod +x /usr/local/src/security_monkey/docker/*.sh &&\
mkdir -pv /var/log/security_monkey &&\
/usr/bin/touch /var/log/security_monkey/securitymonkey.log
# ln -s /dev/stdout /var/log/security_monkey/securitymonkey.log

WORKDIR /usr/local/src/security_monkey
EXPOSE 5000

ENTRYPOINT ["/usr/local/src/security_monkey/docker/api-start.sh"]
86 changes: 86 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---

###
#
# Documentation: http://securitymonkey.readthedocs.io/en/latest/index.html
# http://securitymonkey.readthedocs.io/en/latest/docker.html
#
# shortcuts
# open https://$(docker-machine active | xargs docker-machine ip)
#
###


version: '2'
services:
postgres:
container_name: secmonkey-db
image: postgres:9
# volumes:
# - ./postgres-data/:/var/lib/postgresql/data

api:
container_name: secmonkey-api
image: secmonkey:latest
volumes_from:
- init
depends_on:
- postgres
env_file: secmonkey.env
entrypoint: ["/usr/local/src/security_monkey/docker/api-start.sh"]

scheduler:
container_name: secmonkey-scheduler
image: secmonkey:latest
volumes_from:
- init
depends_on:
- api
env_file: secmonkey.env
entrypoint: ["/usr/local/src/security_monkey/docker/scheduler-start.sh"]

nginx:
container_name: secmonkey-nginx
build:
context: ./
dockerfile: ./docker/nginx/Dockerfile
image: secmonkey-nginx:latest
working_dir: /etc/nginx
volumes:
- ./docker/nginx/server.crt:/etc/nginx/ssl/server.crt
- ./docker/nginx/server.key:/etc/nginx/ssl/server.key
- ./docker/nginx/securitymonkey.conf:/etc/nginx/conf.d/securitymonkey.conf
- ./docker/nginx/start-nginx.sh:/usr/local/src/security_monkey/docker/nginx/start-nginx.sh
depends_on:
- api
ports:
- 80:80
- 443:443
links:
- api:smapi

# volumes:
# - postgres-data: {}

### ### ###
### ### ###

init:
container_name: init
build: .
image: secmonkey:latest
working_dir: /usr/local/src/security_monkey
volumes:
- ./data/aws_accounts.json:/usr/local/src/security_monkey/data/aws_accounts.json
- ./docker:/usr/local/src/security_monkey/docker/
- ./env-config/config-docker.py:/usr/local/src/security_monkey/env-config/config-docker.py
depends_on:
- postgres
env_file: secmonkey.env
# environment:
# - AWS_ACCESS_KEY_ID=
# - AWS_SECRET_ACCESS_KEY=
# - SECURITY_MONKEY_POSTGRES_HOST=
entrypoint: # /usr/local/src/security_monkey/docker/api-init.sh
- sleep
- 8h
9 changes: 9 additions & 0 deletions docker/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
************************
Docker local development
************************

Project resources
=================

- `Docker documentation <http://securitymonkey.readthedocs.org/docker.html>`_
- `Development documentation <http://securitymonkey.readthedocs.org/development.html>`_
15 changes: 15 additions & 0 deletions docker/api-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

sudo -u ${SECURITY_MONKEY_POSTGRES_USER:-postgres} psql\
-h ${SECURITY_MONKEY_POSTGRES_HOST:-postgres} -p ${SECURITY_MONKEY_POSTGRES_PORT:-5432}\
--command "ALTER USER ${SECURITY_MONKEY_POSTGRES_USER:-postgres} with PASSWORD '${SECURITY_MONKEY_POSTGRES_PASSWORD:-securitymonkeypassword}';"

sudo -u ${SECURITY_MONKEY_POSTGRES_USER:-postgres} createdb\
-h ${SECURITY_MONKEY_POSTGRES_HOST:-postgres} -p ${SECURITY_MONKEY_POSTGRES_PORT:-5432}\
-O ${SECURITY_MONKEY_POSTGRES_USER:-postgres} ${SECURITY_MONKEY_POSTGRES_DATABASE:-secmonkey}

mkdir -p /var/log/security_monkey/
touch "/var/log/security_monkey/security_monkey-deploy.log"

cd /usr/local/src/security_monkey
python manage.py db upgrade
4 changes: 4 additions & 0 deletions docker/api-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cd /usr/local/src/security_monkey
python manage.py run_api_server -b 0.0.0.0:${SECURITY_MONKEY_API_PORT:-5000}
50 changes: 50 additions & 0 deletions docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2014 Netflix, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM nginx:1.11.4
MAINTAINER Netflix Open Source Development <talent@netflix.com>

ENV SECURITY_MONKEY_VERSION=v0.7.0
RUN apt-get update &&\
apt-get install -y curl git sudo apt-transport-https &&\
curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - &&\
curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list && \
apt-get update &&\
apt-get install -y -q dart &&\
rm -rf /var/lib/apt/lists/*

RUN cd /usr/local/src &&\
# git clone -b $SECURITY_MONKEY_VERSION https://github.com/Netflix/security_monkey.git
mkdir -p security_monkey
ADD . /usr/local/src/security_monkey

RUN cd /usr/local/src/security_monkey/dart &&\
/usr/lib/dart/bin/pub get &&\
/usr/lib/dart/bin/pub build &&\
/bin/mkdir -p /usr/local/src/security_monkey/security_monkey/static/ &&\
/bin/cp -R /usr/local/src/security_monkey/dart/build/web/* /usr/local/src/security_monkey/security_monkey/static/

RUN /bin/rm /etc/nginx/conf.d/default.conf &&\
/bin/mkdir -p /var/log/security_monkey/ /etc/nginx/ssl/ &&\
ln -s /dev/stdout /var/log/security_monkey/security_monkey.access.log &&\
ln -s /dev/stderr /var/log/security_monkey/security_monkey.error.log

WORKDIR /etc/nginx
EXPOSE 443

ADD docker/nginx/securitymonkey.conf /etc/nginx/conf.d/securitymonkey.conf
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
# ADD docker/nginx/server.crt docker/nginx/server.key /etc/nginx/ssl/

ENTRYPOINT ["/usr/local/src/security_monkey/docker/nginx/start-nginx.sh"]
33 changes: 33 additions & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

user nginx;
worker_processes 1;
daemon off;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}
37 changes: 37 additions & 0 deletions docker/nginx/securitymonkey.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "SAMEORIGIN";
add_header Strict-Transport-Security "max-age=631138519";
add_header Content-Security-Policy "default-src 'self'; font-src 'self' https://fonts.gstatic.com; script-src 'self' https://ajax.googleapis.com; style-src 'self' https://fonts.googleapis.com;";

server {
listen 0.0.0.0:80;
listen 0.0.0.0:443 ssl;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
access_log /var/log/security_monkey/security_monkey.access.log;
error_log /var/log/security_monkey/security_monkey.error.log;

location ~* ^/(reset|confirm|healthcheck|register|login|logout|api) {
proxy_read_timeout 120;
proxy_pass http://smapi:5000;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /static {
rewrite ^/static/(.*)$ /$1 break;
root /usr/local/src/security_monkey/security_monkey/static;
index ui.html;
}

location / {
root /usr/local/src/security_monkey/security_monkey/static;
index ui.html;
}

}
14 changes: 14 additions & 0 deletions docker/nginx/start-nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

SECURITY_MONKEY_SSL_CERT=${SECURITY_MONKEY_SSL_CERT:-/etc/nginx/ssl/server.crt}
SECURITY_MONKEY_SSL_KEY=${SECURITY_MONKEY_SSL_KEY:-/etc/nginx/ssl/server.key}

if [ ! -f "$SECURITY_MONKEY_SSL_CERT" ] || [ ! -f "$SECURITY_MONKEY_SSL_KEY" ]; then
# Fail if SSL is unavailable
echo "$(date) Error: Missing files required for SSL"
# exit 1
sed -i.bak 's@.*ssl@# &@' /etc/nginx/conf.d/securitymonkey.conf &&\
echo "$(date) Warn: Disabled ssl in securitymonkey.conf"
fi

exec nginx
7 changes: 7 additions & 0 deletions docker/scheduler-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

mkdir -p /var/log/security_monkey
touch /var/log/security_monkey/security_monkey-deploy.log

cd /usr/local/src/security_monkey
python manage.py start_scheduler
51 changes: 51 additions & 0 deletions docs/docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Docker Instructions
===================

The docker-compose.yml file describes the SecurityMonkey environment. This is intended for local development with the intention of deploying SecurityMonkey containers with a Docker Orchestration tool like Kubernetes.

The Dockerfile builds SecurityMonkey into a container with several different entrypoints. These are for the different responsibilities SecurityMonkey has.
Also, the docker/nginx/Dockerfile file is used to build an NGINX container that will front the API, serve the static assets, and provide TLS.

Quick Start:
------------
Define your specific settings in **secmonkey.env** file. For example, this file will look like::

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
SECURITY_MONKEY_POSTGRES_HOST=postgres
SECURITY_MONKEY_FQDN=192.168.99.100

$ docker-compose build
``this will locally build all the containers necessary``

$ docker-compose up -d postgres
``this will start the database container``

$ docker-compose up -d init
``this will start a container in which you canuse to setup the database, create users, and other manual configurations, see the below section for more info``

$ docker-compose up
``this will bring up the remaining containers (scheduler and nginx)``

Commands:
---------

$ docker-compose build ``[api | scheduler | nginx | init]``

$ docker-compose up -d ``[postgres | api | scheduler | nginx | init]``

More Info:
----------
::

$ docker-compose up -d init

The init container is where the SecurityMonkey code is available for you to run manual configurations such as::

$ python manage.py create_user admin@example.com Admin

and/or::

$ python manage.py add_account --number $account --name $name -r SecurityMonkey

The init container provides a sandbox and is useful for local development. It is not required otherwise.
2 changes: 2 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Docker Images
Before we start, consider following the `docker instructions <https://github.com/Netflix-Skunkworks/zerotodocker/wiki/Security-Monkey>`_
. Docker helps simplify the process to get up and running. The docker images are not currently ready for production use, but are good enough to get up and running with an instance of security_monkey.

Local `docker instructions <./docker.html>`_

Not into the docker thing? Keep reading.

Setup IAM Roles
Expand Down
Loading