You are on page 1of 30

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SVS309-R2

Architecting secure serverless


applications
Josh Kahn (he/him)
Principal Solutions Architect
Tech Leader – Serverless
AWS

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Security is everyone’s
responsibility

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Four principles to securing serverless
applications
1. Understand shared responsibility model

2. Grant least privilege

3. Implement defense in depth

4. Secure your software supply chain

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Let’s apply these principles to a sample architecture
Order service Payment service

Loyalty service

AWS Step
Functions
fulfillment
workflow

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Let’s apply these principles to a sample architecture
3 Order service Payment service

Loyalty service

4 2
Software supply chain 1

AWS Step
Functions
fulfillment
workflow

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SECURITY PRINCIPLE #1

Understand shared
responsibility with AWS

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Shared responsibility with AWS
Customer data
Customers are
responsible for
Customer

Platform, applications, IAM their security and


compliance
Operating system, network, and firewall configuration IN
the cloud
Client-side data encryption and Server-side encryption Network traffic protection
data integrity authentication (file system and/or data) (encryption/integrity/identity)

Foundation services
AWS is
Compute Storage Database Networking responsible for
AWS

the security
OF
AWS infrastructure Regions, AZs, and data centers the cloud

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
With serverless, AWS takes a greater share of
responsibility
Customer Customer data, applications, IAM

Data encryption and Application Internet access


integrity authentication management Monitoring and logging
(tools provided by platform)

Network traffic protection


Code encryption
AWS IAM

Platform management Firewall configuration


(data at rest)
(data in transit)
AWS

Operating system and network configuration

Compute Storage Database Networking

AWS Infrastructure Regions, AZs, and data centers

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda service composed of control and data planes
Control plane
• Management APIs, such as
o CreateFunction
o UpdateFunctionCode Controller

• Requires IAM permission to access

Data plane
• Invoke Lambda function via Invoke Requests

• IAM permission or resource policy Data plane


Responses
• When invoked, executes code on Client

o Existing execution environment, if exists


o New environment, after allocation

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Secure Lambda functions with AWS IAM
Function policy Execution role
• Defines how function can be invoked • Defines which AWS resources can access via IAM
• Supports cross-account access • Used for poll-based invocations (Lambda polling)
• Used for synchronous and asynchronous invocations

“Actions on API Gateway A can invoke Lambda “Lambda function A can write data to
function B” DynamoDB Table B”

Function policy Execution role

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Secure other resources with AWS IAM
Resource policy Execution role
• Defines access to event bus, for example PutEvent • Assumed by event bus to determine access to AWS
resources
• Use conditions to scope permissions
• Allows cross-account access
• Allows cross-account access
“Principals in Account A can publish new order
events to the event bus in Account B” “Event Bus A can publish events to Event Bus B”

Account A – Web store Account B – Central event bus Account C – Invoice


processing
New order New order
created created
publishes

eCommerce Rules
Event Bus

Resource policy Execution role


© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SECURITY PRINCIPLE #2

Grant least privilege

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What does it mean to grant least privilege?
• Grant only the essential
privileges needed to perform
intended work
• Attach to function via AWS IAM
execution role
o Prefer unique role per function
o Assign fine-grained permissions
o Enforce permission boundaries

• Be specific: Identify limited set of


resources and actions allowed
o Scrutinize use of “*”

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS SAM accelerates policy, role development

Amazon API AWS Lambda Amazon DynamoDB


Gateway

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SECURITY PRINCIPLE #3

Practice defense in depth

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Common vectors of attack

App vulnerabilities Dependencies Host/network

SQL injection Libraries Patching


Cross-site scripting (XSS) Distributions Network segmentation
OWASP Top 10 Base images
Common vulnerabilities
and exposures (CVE)

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How to practice defense in depth?
• Implement multiple,
redundant measures across
system to address common AWS Fargate
task
Amazon DynamoDB
table

attack vectors Amazon


API Gateway

• Leverage AWS managed AWS Lambda Amazon S3

services and integrations function bucket

• Consider service features,


e.g., backup and encryption
AWS KMS key
AWS WAF AWS IAM

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Brief aside on Firecracker

Firecracker is built on KVM, the same


hypervisor that EC2 Nitro instances are
built on.

Hardware virtualization ensures that


tasks from different customers can run
safely on the same physical machine.

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda function isolation Lambda function
boundary

• Each function runs in a dedicated Function,


layer code
Function,
layer code
Function,
layer code
Function,
layer code
execution environment
o Each execution environment handles Lambda Lambda Lambda Lambda
one concurrent invocation runtime runtime runtime runtime

Execution Execution Execution Execution


environment environment environment environment
• Execution environment may be
reused between invocations MicroVM MicroVM MicroVM MicroVM
o Use caution when storing sensitive
data in memory or /tmp
Hypervisor

• AWS maintains runtime and Host OS


execution environment
o Patching, etc. Lambda worker (EC2 instance, bare metal)

o Does not apply to container


packaging or customer runtimes
AWS account boundary
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Securing a serverless web service

Amazon AWS Amazon


API Gateway Lambda DynamoDB
Request validation Sanitize input
Authorization Execution role
mTLS Minimize dependencies
Rate limiting Vulnerability scanning
Throttling

AWS WAF
XSS rules
SQLi rules
OWASP Top 10

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SECURITY PRINCIPLE #4

Secure your software


supply chain

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Secure your software supply chain
• Keep it simple
o Prefer single responsibility
do “x”
o Easier to debug; cleaner IAM privileges

• Again, never hardcode secrets do “y”


in code
do “z”
• Leverage code and vulnerability
scanning
o Don’t forget dependencies

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Managing dependencies is key

• Understand you dependencies: • Leverage dependency check


https://deps.dev/ tools, such as
o OWASP

• Minimize dependencies o Protego


o Snyk
o Twistlock
• Keep dependencies up-to-date
to reduce risk and effort o Puresec

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Common security topics

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How do I secure access to my API? Are API
keys good enough?
• Options for authorization:
o IAM
o Cognito user pool/JWT AWS Fargate Amazon DynamoDB
task table
o Lambda authorizer

• Can be used with: Amazon


API Gateway

o AWS WAF AWS Lambda Amazon S3


function bucket
o Resource policies
o Mutual TLS (mTLS)

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Should my Lambda function be VPC-enabled?
• Lambda functions always run in
VPCs owned by the Lambda
service team Customer VPC AWS Lambda Service VPC

o When VPC is enabled, configured with


access to your VPC via an ENI
• Lambda functions are always Elastic network
interface(s)
VPC to VPC
NAT
invoked via Invoke action
o Access controlled by AWS IAM

• Answer: Only if your function


needs access to resources in
the VPC
© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How should I handle secrets?
• Function requires static, sensitive data
o For example, API key or password

• While convenient, do not use Lambda


environment variables
o Accessible to anyone with access to the function
AWS Secrets
• Answer: Use purpose-built services, Manager
such as AWS Secrets Manager secured
with IAM permissions

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How do I know my code has not been
changed?
• Use IAM permissions to limit
create/update actions
• Monitor with AWS Config,
AWS CloudTrail
• Leverage code signing to
cryptographically sign code
o Allow deployment of functions only
from trusted publishers

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you!
Josh Kahn
@joshuaakahn

© 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.

You might also like