127
Containerizing your SOC

Containerizing your Security Operations Center

Embed Size (px)

Citation preview

Page 1: Containerizing your Security Operations Center

Containerizing your SOC

Page 2: Containerizing your Security Operations Center

@jimmesta

OWASP Santa Barbara Founder

AppSec California Organizer

Works at Invoca

Was consulting, now “defensing”

I really like containers

Page 3: Containerizing your Security Operations Center

Greetings from Sunny AppSec California!

Location: Santa Monica, Ca.

Date: January 23-25, 2017

Why: Because Winter

2017.appseccalifornia.org

Page 4: Containerizing your Security Operations Center
Page 5: Containerizing your Security Operations Center

Security Confessions:

A Time for Healing

Page 6: Containerizing your Security Operations Center

What are employees saying about your security program?

Page 7: Containerizing your Security Operations Center

Security as a [ ]

Page 8: Containerizing your Security Operations Center

Security as a Service?

Page 9: Containerizing your Security Operations Center

Security as a Magic Unicorn?

Page 10: Containerizing your Security Operations Center

Security as a Bottleneck

Page 11: Containerizing your Security Operations Center

Security as a Black Hole

Page 12: Containerizing your Security Operations Center

Security as a “No” Machine

Page 13: Containerizing your Security Operations Center

Security as a Hot Potato

Page 14: Containerizing your Security Operations Center

Security as a PDF Generator

Page 15: Containerizing your Security Operations Center

We are all under-staffed

Page 16: Containerizing your Security Operations Center

We are all over budget

Page 17: Containerizing your Security Operations Center

We are all too busy

Page 18: Containerizing your Security Operations Center

Can we DevSecOps our way out of this?

Page 19: Containerizing your Security Operations Center
Page 20: Containerizing your Security Operations Center
Page 21: Containerizing your Security Operations Center

Step 1: Install XCode Command Line Tools

xcode-select --install

Nice! It looks like I get to compile some stuff.

Page 22: Containerizing your Security Operations Center

Step 2: Make sure Java is updated

Dang. My Java is out of whack. What did I do? I’ll just update…

java --version

Page 23: Containerizing your Security Operations Center

20 minutes later...

Page 24: Containerizing your Security Operations Center

Step 3: Install Homebrew

But I use Macports and ZSH.. where’s my .bash_profile?

source ~/.bash_profile

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/.../)"

brew tap homebrew/versions

Page 25: Containerizing your Security Operations Center

Step 4: Update $PATH and Install Dependencies

Wait a minute. I need a local Postgres DB to run this thing?

echo PATH=/usr/local/bin:/usr/local/sbin:$PATH >> ~/.bash_profile

brew install nmap && brew install postgresql

Page 26: Containerizing your Security Operations Center

Step 5: Initialize the DB

What?! Postgres didn’t initialize? Forget this. Hacking is hard.

cp /user/local/Cellar/postgresql/9.4.0/.../...

initdb /usr/local/var/postgres

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Page 27: Containerizing your Security Operations Center

You just lost a golden opportunity to foster a co-worker's interest in security.

Page 28: Containerizing your Security Operations Center

How can we make our security tooling more about using the tool and less about maintenance?

Page 29: Containerizing your Security Operations Center

whitesourcesoftware.com

Page 30: Containerizing your Security Operations Center
Page 31: Containerizing your Security Operations Center

Docker is an Open Source engine to pack, ship, and run any application as a lightweight container.

Page 32: Containerizing your Security Operations Center

Why U No Just Virtualbox!?

Page 33: Containerizing your Security Operations Center

Traditional Virtual Machines

Source: https://www.docker.com/what-docker

Page 34: Containerizing your Security Operations Center

Docker Infrastructure

Source: https://www.docker.com/what-docker

Page 35: Containerizing your Security Operations Center
Page 36: Containerizing your Security Operations Center

Docker provides a user friendly API to create containers.

Page 37: Containerizing your Security Operations Center

Images use layers for efficiency and speed.

Page 38: Containerizing your Security Operations Center

Build the Docker image once and use it all over the place.

Page 39: Containerizing your Security Operations Center

Minimize concerns around compatibility and dependencies.

Page 40: Containerizing your Security Operations Center

So what about our “Securious” Dev who just wanted to run Metasploit?

Page 41: Containerizing your Security Operations Center

Step 1: Install Docker

Nice! That was super easy to point and click.

Page 42: Containerizing your Security Operations Center

Step 2: Run Command

That just..worked?

docker run -t -i linuxkonsult/kali-metasploit

Page 43: Containerizing your Security Operations Center

Step 3: Profit

Page 44: Containerizing your Security Operations Center

FROM linuxkonsult/kali

MAINTAINER Tom Eklöf "[email protected]"

ENV DEBIAN_FRONTEND noninteractive

ADD ./init.sh /init.sh

RUN apt-get -y update ; apt-get -y --force-yes install ruby metasploit-framework

CMD /init.sh

Dockerfile

Page 45: Containerizing your Security Operations Center

#!/bin/bash

/usr/share/metasploit-framework/msfupdate

/usr/share/metasploit-framework/msfconsole

init.sh

Page 46: Containerizing your Security Operations Center

What could go wrong with blindly pulling Docker images?

Page 47: Containerizing your Security Operations Center
Page 48: Containerizing your Security Operations Center

Always inspect and vet the Dockerfile before blindly using it.

Page 49: Containerizing your Security Operations Center

Tools like Clair, Quay, and Anchore can help identify vulnerabilities in images.

Page 50: Containerizing your Security Operations Center
Page 52: Containerizing your Security Operations Center

docker run is useful and all but how do we get these containers out to the world for others to use?

Page 53: Containerizing your Security Operations Center
Page 54: Containerizing your Security Operations Center

K8S - A Gentle Introduction

Page 55: Containerizing your Security Operations Center

Kubernetes is an open-source platform built to automate deployment, scaling and orchestration of containers.

Page 56: Containerizing your Security Operations Center

K8S is portable. Clusters can be deployed on a public/private cloud, on prem, and even on your laptop.

Page 57: Containerizing your Security Operations Center

K8S is customizable. It is modular and extensible to fit nearly any use-case.

Page 58: Containerizing your Security Operations Center

K8S is scalable. It provides self-healing, auto scaling, and replication.

Page 59: Containerizing your Security Operations Center

There are others!

Page 60: Containerizing your Security Operations Center

- Don’t orchestrate for the sake of orchestration (or because the cool kids are doing it)

- Containers first, then orchestration

- docker-compose does a fine job for many things

Page 61: Containerizing your Security Operations Center

Core Concepts

Page 62: Containerizing your Security Operations Center

https://flic.kr/p/bNpyRp

Page 63: Containerizing your Security Operations Center

clustervirtual machines that Kubernetes

manages

Page 64: Containerizing your Security Operations Center

clusternodemaster node node

Page 65: Containerizing your Security Operations Center

clusternodemaster node node

node node node

node node node

node node node

node node

node node node

node node nodemaster

master

node

Page 66: Containerizing your Security Operations Center

podgroup of

containers sharing storage

and network

Page 67: Containerizing your Security Operations Center

podcontainer container container

volume A volume B

network interface

Page 68: Containerizing your Security Operations Center

pod.yaml

apiVersion: v1kind: Podmetadata: name: owasp-appspec: containers: - name: owasp-app image: owasp-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 69: Containerizing your Security Operations Center

pod.yamlnodemaster node node

Page 70: Containerizing your Security Operations Center

pod.yamlnodemaster node node

Page 71: Containerizing your Security Operations Center

pod.yamlnodemaster node node

Page 72: Containerizing your Security Operations Center

deploymentensure N pods

are up and running

Page 73: Containerizing your Security Operations Center

deploy.yaml

kind: DeploymentapiVersion: extensions/v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: owasp-app image: owasp-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 74: Containerizing your Security Operations Center

deploy.yaml

kind: DeploymentapiVersion: extensions/v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: owasp-app image: owasp-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 75: Containerizing your Security Operations Center

deploy.yaml

kind: DeploymentapiVersion: extensions/v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: owasp-app image: owasp-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 76: Containerizing your Security Operations Center

deploy.yaml

kind: DeploymentapiVersion: extensions/v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: owasp-app image: owasp-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 77: Containerizing your Security Operations Center

deploy.yamlnodemaster node node

Page 78: Containerizing your Security Operations Center

deploy.yamlnodemaster node node

Page 79: Containerizing your Security Operations Center

deploy.yamlnodemaster node node

10.0.0.1 10.0.0.210.0.0.3

10.0.0.4

Page 80: Containerizing your Security Operations Center

serviceabstraction layer that enables pod communication

Page 81: Containerizing your Security Operations Center

servicenodemaster node node

10.0.0.1 10.0.0.210.0.0.3

10.0.0.4

Page 82: Containerizing your Security Operations Center

servicemaster

service

Page 83: Containerizing your Security Operations Center

servicemaster

service

service

Page 84: Containerizing your Security Operations Center

servicemaster

service

service

public load balancer

tools.beardsec.com

Page 85: Containerizing your Security Operations Center

svc.yaml

kind: ServiceapiVersion: v1metadata: name: web-frontendspec: ports: - name: http port: 80 targetPort: 80 protocol: TCP selector: role: web type: LoadBalancer

Page 86: Containerizing your Security Operations Center

svc.yaml

kind: ServiceapiVersion: v1metadata: name: web-frontendspec: ports: - name: http port: 80 targetPort: 80 protocol: TCP selector: role: web type: LoadBalancer

Page 87: Containerizing your Security Operations Center

svc.yaml

kind: ServiceapiVersion: v1metadata: name: web-frontendspec: ports: - name: http port: 80 targetPort: 80 protocol: TCP selector: role: web type: LoadBalancer

Page 88: Containerizing your Security Operations Center

svc.yaml

kind: ServiceapiVersion: v1metadata: name: web-frontendspec: ports: - name: http port: 80 targetPort: 80 protocol: TCP selector: role: web type: LoadBalancer

Page 89: Containerizing your Security Operations Center

namespacemanage different environments in the same cluster

Page 90: Containerizing your Security Operations Center

ns.yamlkind: NamespaceapiVersion: v1metadata: name: sec-tools

Page 91: Containerizing your Security Operations Center

kubectl

master apiserver

HTTPS

schedulerReplication controller

node

node kubelet

pod pod pod

proxy External LB

Page 92: Containerizing your Security Operations Center

Sounds great! What about security?

Page 93: Containerizing your Security Operations Center

apiserver

Authentication(Who can access the

cluster?kubectl

Authorization(What can

they access?)

Admission Control

(Which policies are applied for

this user?

Access Granted

https://

K8S Security Model

Page 94: Containerizing your Security Operations Center

- K8S API typically serves traffic over TLS- Self-Signed Cert provisioned on

operators laptop in $USER/.kube/config

Transport Security

apiserver

Authentication(Who can access the

cluster?kubectl

Authorization(What can

they access?)

Admission Control

(Which policies are applied for

this user?

Access Granted

https://

Page 95: Containerizing your Security Operations Center

- Supports many authentication modules:HTTP Basic, OpenID, Tokens, Client Cert, Keystone

- Multiple modules can be specified

Authentication

apiserver

Authentication(Who can access the

cluster?kubectl

Authorization(What can

they access?)

Admission Control

(Which policies are applied for

this user?

Access Granted

https://

Page 96: Containerizing your Security Operations Center

- Every HTTP request is authorized get, list, create, update, etc.

- Request attributes are checked against policy

Authorization

apiserver

Authentication(Who can access the

cluster?kubectl

Authorization(What can

they access?)

Admission Control

(Which policies are applied for

this user?

Access Granted

https://

Page 97: Containerizing your Security Operations Center

Authorization

--authorization-mode=AlwaysAllow allows all requests;

use if you don’t need authorization.

--authorization-mode=ABAC allows for a simple

local-file-based user-configured authorization policy.

--authorization-mode=RBAC is an experimental

implementation which allows for authorization to be driven by the

Kubernetes API.

Page 98: Containerizing your Security Operations Center

Role Resource TypesRole

ClusterRole

RoleBinding

ClusterRoleBinding

http://kubernetes.io/docs/admin/authorization/

Page 99: Containerizing your Security Operations Center

rb.yaml

kind: RoleBindingapiVersion: rbac.authorization.k8s.io/v1alpha1metadata: name: read-pods namespace: sec-toolssubjects: - kind: User name: jimmyroleRef: kind: Role namespace: sec-tools name: pod-reader apiVersion: rbac.authorization.k8s.io/v1alpha1

Page 100: Containerizing your Security Operations Center

- Intercept requests prior to object creation

- May mutate incoming request to apply system defaults

Admission Controllers

apiserver

Authentication(Who can access the

cluster?kubectl

Authorization(What can

they access?)

Admission Control

(Which policies are applied for

this user?

Access Granted

https://

Page 101: Containerizing your Security Operations Center

Admission Controllers

AlwaysPullImages

DenyEscalatingExec

ResourceQuota

http://kubernetes.io/docs/admin/admission-controllers/

Page 102: Containerizing your Security Operations Center

Secrets Everywhere!

Page 103: Containerizing your Security Operations Center

K8S Secret Object

- Secrets can only be accessed by pods in the same namespace

- Secrets are only sent to nodes with pods that require it

- Not written to disk - stored on tmpfs- Deleted once dependent pod is removed

Page 104: Containerizing your Security Operations Center

Buyer Beware

- Secrets are stored in plaintext on the apiserver (etcd)- Protect etcd with your life

- Don’t forget what OWASP taught you!- Secrets in logs, app security, etc.

- Anyone with root on any node can read secrets by impersonating kubelet

Page 105: Containerizing your Security Operations Center

Vault

- It works! But no official K8S support (yet)

- API driven, do what you will- Customize your deployment

Page 106: Containerizing your Security Operations Center

#!/bin/bash

PASSWORD="$(vault read -field=value secret/password | base64)"

# Create YAML object from stdin

cat <<EOF | kubectl create -f -

apiVersion: v1

kind: Secret

metadata:

name: mysecret

type: Opaque

data:

password: "${PASSWORD}"

EOF

```

Page 107: Containerizing your Security Operations Center

secret.yaml

apiVersion: v1kind: Secretmetadata: name: owasp-secretstype: Opaquedata: username:d293IHlvdSBkZWNvZGVkIGl0 password: Z29vZCBmb3IgeW91 host:bm90aGluZyBqdWljeSB0aG91Z2g=

Page 108: Containerizing your Security Operations Center

deploy.yaml

kind: DeploymentapiVersion: extensions/v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: owasp-app image: owasp-app

env: - name: OWASP_PASS valueFrom: secretKeyRef: name: owasp-secrets key: password

ports: - containerPort: 443

Page 109: Containerizing your Security Operations Center

Security Hygiene

- Restrict SSH access to nodes- Only use trusted images- Regularly apply updates to your K8S

environment (including kubectl)- Log all of the things- Apply SecurityContext to deploymentsrunAsNonRoot, readOnlyRootFilesystem

Page 110: Containerizing your Security Operations Center

Demo (sort of)

- 2 node cluster running on GCE- Kubernetes 1.4

Page 111: Containerizing your Security Operations Center
Page 112: Containerizing your Security Operations Center
Page 113: Containerizing your Security Operations Center
Page 114: Containerizing your Security Operations Center
Page 115: Containerizing your Security Operations Center
Page 116: Containerizing your Security Operations Center
Page 117: Containerizing your Security Operations Center
Page 118: Containerizing your Security Operations Center
Page 119: Containerizing your Security Operations Center
Page 120: Containerizing your Security Operations Center
Page 121: Containerizing your Security Operations Center
Page 122: Containerizing your Security Operations Center
Page 123: Containerizing your Security Operations Center
Page 124: Containerizing your Security Operations Center
Page 125: Containerizing your Security Operations Center

- Maintain one K8S cluster- Deploy and scale security tooling - DevSecOps all the things- We are part of this container journey

together

Security can be an enabler

Page 127: Containerizing your Security Operations Center

Questions?