continuous security and devops - sans information … · continuous security and devops: ... single...

36
Continuous Security and DevOps: Three Keys for Modern Security Success © 2017 Frank Kim | All Rights Reserved

Upload: hoanglien

Post on 28-Apr-2018

232 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Continuous Security and DevOps:Three Keys for Modern Security Success

© 2017 Frank Kim | All Rights Reserved

Page 2: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

• ThinkSec

• Founder

• SANS Institute

• Former CISO

• Curriculum Lead

• Management and Application Security

• Author & Instructor

• MGT514, DEV540, DEV541

Frank Kim

2

Introduction

• Shout out to Eric Johnson

• Summit Co-Chair

• Author of many of these slides

Page 3: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

3

Security Perceptions

“DevOps is just another excuse

for developers to have

root access in production.”

- Traditional security expert

Page 4: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

4

Walls of Confusion

Image concept: http://dev2ops.org/2010/02/what-is-devops

Development Operations

I want stability!I want change!

Wal

l of C

onfu

sion

Page 5: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

#1 Champion Change

Page 6: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

6

Embracing Change

“It’s not the strongest that survive or

the most intelligent that survive.

It’s the ones that are most adaptable to change.”

- Charles Darwin

Page 7: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Monolith Architecture Security Controls

• Common security controls are applied to each trust boundary in the monolith architecture:

Client Browser MySQL DatabaseServerWeb Server

Spring Boot / Tomcat

Public Subnet Private Subnet

ELB

2 3

1. Security Controls

Web Application Firewall

HTTPS, Rate Limiting

1

2. Security Controls

Authentication, Authorization

Access control, Validation

3. Security Controls

System Authentication, TLS

Encryption at rest

Page 8: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Microservice Architecture

• How does this change in a microservice architecture?

Account Management

Human Resources

DiscountCoupons

Employee

Customer Service

Private Subnet

MySQL DatabaseServer

Coupon Bucket

Public Subnet

Single Page App

EBSVolume

Mobile App

IoT Factory Device

Page 9: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Microservice Architecture Attack Surface

• Consider the attack surface in a modern microservice architecture:

Account Management

DiscountCoupons

Customer Service

Private Subnet

MySQL DatabaseServer

Public Subnet

Single Page App

Mobile App

IoT Factory Device

Employee

Human Resources

Coupon Bucket

EBSVolume

Page 10: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

• Adding an API Gateway to provide perimeter security controls:

Microservice API Gateway Architecture

Account Management

DiscountCoupons

Customer Service

Private Subnet

MySQL DatabaseServer

Public Subnet

Single Page App

Mobile App

IoT Factory Device

Employee

Human Resources

Coupon Bucket

EBSVolume

API Gateway

AuthorizationAccess

Control

Page 11: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Serverless Computing

• Serverless refers to new, non-traditional architecture

• Does not use dedicated containers

• Event-triggered computing requests

• Ephemeral environment

• Servers fully managed by 3rd party (e.g. AWS)

• Referred to as Functions as a service (FaaS)

• Example Technologies

• AWS Lambda, MS Azure Functions, Google Cloud Functions

• Amazon API Gateway

Page 12: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Serverless Security Benefits

• How does serverless improve security?

• Attack surface is smaller

• No servers to patch

• No long running servers

That can be scanned or attacked

That can have malware installed on them

• Fewer compromised servers

If malware is installed the next request brings up new, clean “server”

Page 13: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Serverless Security Concerns

• How does serverless make security harder?

• Attack surface is bigger (but different)

Anyone can deploy a function

Cost to deploy a function is effectively zero (not charged for idle time)

Difficult to track and delete functions

• Authentication and access control

Who has permission to deploy functions?

How do you lock down what each function can do?

• Compliance

Which functions will handle sensitive data and where is it stored?

Are there multitenancy risks?

Is your implementation itself compliance?

Page 14: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Serverless and Application Security

• Application security is even more important with serverless

• If attackers have less infrastructure to attack

• The focus naturally shifts to the application

• Every function crosses a trust boundary

• Functions are designed to independent

• Therefore each function must be secured independently

• Apply application security best practices

• Input validation / sanitization must be performed in each function

• Perform code review and automated scans

• Review dependencies and libraries used by functions

Page 15: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

AWS WAF Security Automations Architecture

• 15

CloudWatch

Event

AWS Lambda

Access Handler

S3 Log

Bucket

Amazon API

Gateway

AWS WAF

SQL Injection & XSS protection

Bad bot & scraper protection

Scanner & HTTP flood protection

Known attacker / bad IP protection

IP whitelist / blacklist

AWS Lambda

Log Parser

AWS Lambda

IP Lists Parser

Amazon

CloudFront

Application

Load Balancer

hourly

Third-party IP

reputation lists

access logs

requests to honeypot endpoint

Image credit: http://docs.aws.amazon.com/solutions/latest/aws-waf-security-automations/architecture.html

Page 16: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

#2 Seize the Simple

Page 17: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

17

Keep it Simple

“Simplicity is the ultimate form of sophistication.”

– Leonardo Da Vinci

Page 18: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

1818

Hunt the Bug

Can you identify the bug in this code snippet?

1

2

3

4

5

6

7

8

9

10

11

12

<%

String theme = request.getParameter("look");

if (theme == null && session != null) {

theme = (String)session.getAttribute("look");

}

if (session !=null) session.setAttribute("look", theme);

%>

<link rel="stylesheet" type="text/css" media="all"

href="<%= request.getContextPath() %>

/ui/theme/<%= theme %>/colors.css" />

Page 19: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

1919

Hunt the Bug

Can you identify the bug in this code snippet?

1

2

3

4

5

6

7

8

9

10

11

12

<%

String theme = request.getParameter("look");

if (theme == null && session != null) {

theme = (String)session.getAttribute("look");

}

if (session !=null) session.setAttribute("look", theme);

%>

<link rel="stylesheet" type="text/css" media="all"

href="<%= request.getContextPath() %>

/ui/theme/<%= theme %>/colors.css" />

Page 20: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

20

• Output encoding automatically applied for:

HTML tags using ngBind directive (e.g. ng-bind)

Output from Angular expressions (e.g. {{var}} )

• When certain HTML tags should be allowed, use the ngBindHtml directive (e.g. ng-bind-html)

Output is tokenized

Tokens are passed through a whitelist

Non-whitelist tokens are encoded

AngularJS ngSanitize

Page 21: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

21

• ngBind

ngSanitize Examples

<div ng-controller="ExampleController">

<label>Enter name: <input type="text" ng-model="name"></label><br>

Hello <span ng-bind="name"></span>!

</div>

<div ng-controller="ExampleController" class="expressions">

Expression:<input type='text' ng-model="expr" size="80"/>

<button ng-click="addExp(expr)">Evaluate</button>

<ul>

<li ng-repeat="expr in exprs track by $index">

[ <a href="" ng-click="removeExp($index)">X</a> ]

<code>{{expr}}</code> => <span ng-bind="$parent.$eval(expr)"></span>

</li>

</ul>

</div>

• Angular expression

Page 22: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

22

• AngularJS uses features that violate standard CSP rules

• eval() and Function(string) generated functions are used to improve performance when evaluating expressions

• Inline styles are used to inject custom styling (e.g. ngCloak and ngHide)

Linking to angular-csp.css will allow the directives to work when CSP is blocking inline styles

Content Security Policy (CSP)

Page 23: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

23

• The ngCsp (e.g. ng-csp) directive will instruct AngularJS to not use CSP-breaking features

ngCsp

<!doctype html>

<html ng-app ng-csp>

...

</html>

Page 24: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

24

Security tools for static analysis:

• Free / open source:

Find Security Bugs, Phan, Puma Scan, Brakeman, Bandit, Flawfinder, QARK

• Commercial:

HP Fortify, Checkmarx, Coverity, IBM AppScan Source, Klocwork, Veracode, Brakeman Pro

Static Analysis Tools

Page 25: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

25

Secure Code Spell Checker

Page 26: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

#3 Automate Everything

Page 27: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

27

Critical Security Controls (CSC)

Page 28: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Infrastructure as Code

• Different approaches to set up and manage systems

1) Traditional: manual checklists and scripts, ad hoc changes/fixes made by system administrators at runtime

2) Modern: treating Infrastructure as Code and configuration management as system engineering

• Configuration management with scripts is not scalable or traceable and is error prone

• Leads to configuration drift over time

• Configuration management tools

• Chef, Puppet, Ansible, Salt/Saltstack, CFEngine

Page 29: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

AWS CloudFormation Example

29

Creating an EC2 instanceInstancePublic:

Type: AWS::EC2::Instance

Properties:

IamInstanceProfile: !Ref InstanceProfilePhotoReadOnly

ImageId: !FindInMap [Images, !Ref "AWS::Region", ecs]

InstanceType: "t2.micro"

KeyName: "secretKey"

SecurityGroupIds:

- !Ref SecurityGroupPublic

SubnetId: !Ref SubnetPublic

UserData:

Fn::Base64:

!Sub |

#!/bin/bash -xe

yum update -y

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Page 30: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

3030

Retrieving All EC2 Instances

Command line call to retrieve all AWS EC2 instances:

Output:

1

2

3

aws ec2 describe-instances --output json | jq '.Reservations[].Instances[] |

[.LaunchTime, .InstanceType, .InstanceId, .SecurityGroups[].GroupId,

.Tags[].Value]'

1

2

3

4

5

6

7

8

9

[ "2017-01-08T18:51:46.000Z", "t2.micro", "i-0500510e3f808d2ee", "sg-7caf4600"

, "prod-springline-aws-web", "Springboot MVC target application“

, "SANS\\app.user"

]

[

"2017-01-08T18:55:02.000Z", "t2.micro", "i-0e74e490c2ebc5d37", "sg-79af4605"

,"qa-springline-aws-web", "QA Springboot MVC target application“

, "SANS\\app.user"

]

Page 31: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Blue/Green Deployment

• Divert traffic from one environment to another

Each running a different version of the application

• Benefits of blue/green deployments

Reduced downtime

Improved ability to rollback

Faster deployment of features and bug fixes

• Use blue/green deploys when you have:

Immutable infrastructure

Well defined environment boundary

Ability to automate changes

Page 32: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

AWS EC2 Container Service (ECS) – Example

Blue Green Blue Green

ECS Container Instance ECS Container Instance

Service Description

Task Definition

Blue ECS Service

Service Description

Task Definition

Green ECS Service

• Deployment process

Use original blue service and task def

Create new green service and task def

Map new green service to ELB

Scale up green service by increasing number of tasks

Remove blue service, setting tasks to 0

Page 33: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Swapping the AWS ECS Service

• Create a new “green” ECS Service

• Increase the desired count for the “green” service

• Turn off the “blue” service when ready

aws ecs update-service --cluster DM-ecs --service $GreenService --desired-count 1

aws ecs update-service --cluster DM-ecs --service $BlueService --desired-count 0

aws cloudformation deploy --template-file green-web-ecs-service.yaml --stack-name green-web-ecs-service

Page 34: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

34

Getting to Yes

Page 35: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

35

Three Keys for Security Success

Champion Change

Seize the

Simple

Automate Everything

Page 36: Continuous Security and DevOps - SANS Information … · Continuous Security and DevOps: ... Single Page App Mobile App IoT Factory Device Employee ... aws ec2 describe-instances--output

Questions?

Frank [email protected]

@fykim

© 2017 Frank Kim | All Rights Reserved