AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless...

103
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Jim Tran and Justin Pirtle November 30, 2016 MBL306 Serverless Authentication and Authorization Identity Management for Serverless Architectures

Transcript of AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless...

Page 1: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Jim Tran and Justin Pirtle

November 30, 2016

MBL306

Serverless Authentication

and Authorization

Identity Management for Serverless Architectures

Page 2: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

What to expect from the session

• Assumes high-level familiarity with serverless API

architectures (API Gateway, Lambda)

• Learn how to implement identity management for your

serverless apps, using• Amazon Cognito User Pools

• Amazon Cognito Federated Identities

• Amazon API Gateway

• AWS Lambda

• AWS Identity and Access Management (IAM)

Page 3: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Hybrid mobile app• Runs in web browser, Android, Apple iOS devices

• Built using Ionic 2 Framework

• Angular 2 / TypeScript

• AWS SDKs for JavaScript

Do try this at home• Mobile app + API are open-sourced

(Apache 2.0 license)

• https://github.com/awslabs/

aws-serverless-auth-reference-app

SpaceFinderHelps you book conference rooms and desks

Page 4: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)
Page 5: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

ManagingIdentities

Page 6: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Page 7: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

1. Sign-up

Sign-up and sign-in

2. Sign-in

Page 8: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Username Email Password

beverly123 [email protected] Password$123

pilotjane [email protected] a##eroplan3

sudhir1977 [email protected] mmd414997a

2. Sign-in

1. Sign-up

Page 9: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

• Never store passwords in plaintext!

• Vulnerable to rogue employees

• A hacked DB results in

all passwords being compromised

Username Email Password

beverly123 [email protected] Password$123

pilotjane [email protected] a##eroplan3

sudhir1977 [email protected] mmd414997a

Sign-up and sign-in

2. Sign-in

1. Sign-up

Page 10: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Username Email Hashed Password

beverly123 [email protected] 21a730e7d6cc9d715efcc0514ed69a1f

pilotjane [email protected] fea74fde863cd38f88b3393f590ae883

sudhir1977 [email protected] 6ce6be14f0c775cc9b3dbe4e18d9fc7d

2. Sign in

1. Sign up

Page 11: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

• MD5/SHA1 collisions

• Rainbow Tables

• Dictionary attacks, brute-force (GPUs can compute

billions of hashes/sec)

Username Email Hashed Password

beverly123 [email protected] 21a730e7d6cc9d715efcc0514ed69a1f

pilotjane [email protected] fea74fde863cd38f88b3393f590ae883

sudhir1977 [email protected] 6ce6be14f0c775cc9b3dbe4e18d9fc7d

Sign-up and sign-in

2. Sign in

1. Sign up

Page 12: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Username Email Salted Hash

beverly123 [email protected] 1e66f9358530620b2bcae79dada717c…

pilotjane [email protected] 88fccd9cf82377d11d2fede177457d47…

sudhir1977 [email protected] 08a5981de4fecf04b1359a179962a48...

2. Sign in

1. Sign up

• Incorporate app-specific salt +

random user-specific salt

• Use algorithm with configurable # of iterations (e.g.

bcrypt, PBKDF2), to slow down brute force attacks

Page 13: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

2. Sign in

1. Sign up

Username Email

beverly123 [email protected]

pilotjane [email protected]

sudhir1977 [email protected]

Page 14: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Username Email SRP Verifier function

beverly123 [email protected] <password-specific verifier>

pilotjane [email protected] <password-specific verifier>

sudhir1977 [email protected] <password-specific verifier>

2. Sign in

1. Sign up

Page 15: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Username Email SRP Verifier function

beverly123 [email protected] <password-specific verifier>

pilotjane [email protected] <password-specific verifier>

sudhir1977 [email protected] <password-specific verifier>

2. Sign in

1. Sign up

• Secure Remote Password (SRP) Protocol

• Verifier-based protocol

• Passwords never travel over the wire

• Resistant to several attack vectors

• Perfect Forward Secrecy

Page 16: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Username Email SRP Verifier function

beverly123 [email protected] <password-specific verifier>

pilotjane [email protected] <password-specific verifier>

sudhir1977 [email protected] <password-specific verifier>

2. Sign in

1. Sign up

Best practices

☐ Secure password handling

Page 17: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Username Email SRP Verifier function

beverly123 [email protected] <password-specific verifier>

pilotjane [email protected] <password-specific verifier>

sudhir1977 [email protected] <password-specific verifier>

2. Sign in

1. Sign up

Best practices

☐ Secure password handling

☐ Encrypt all data server-side

☐ Enforce password policies (min length, valid characters)

☐ Token-based Authentication

☐ MFA - via SMS for sign-in and forgot password flows

☐ Support CAPTCHAs and other custom authentication flows

☐ Scalable to 100s of millions of users

Page 18: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

Username Email SRP Verifier function

beverly123 [email protected] <password-specific verifier>

pilotjane [email protected] <password-specific verifier>

sudhir1977 [email protected] <password-specific verifier>

2. Sign in

1. Sign up

User flows

☐ Registration

☐ Verify email/phone

☐ Secure sign-in

☐ Forgot password

☐ Change password

☐ Sign-out

Best practices

☐ Secure password handling

☐ Encrypt all data server-side

☐ Enforce password policies (min length, valid characters)

☐ Token-based Authentication

☐ MFA - via SMS for sign-in and forgot password flows

☐ Support CAPTCHAs and other custom authentication flows

☐ Scalable to 100s of millions of users

Page 19: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and sign-in

2. Sign in

1. Sign up

User flows

☐ Registration

☐ Verify email/phone

☐ Secure sign-in

☐ Forgot password

☐ Change password

☐ Sign-out

Best practices

☐ Secure password handling

☐ Encrypt all data server-side

☐ Enforce password policies (min length, valid characters)

☐ Token-based Authentication

☐ MFA - via SMS for sign-in and forgot password flows

☐ Support CAPTCHAs and other custom authentication flows

☐ Scalable to 100s of millions of users

Amazon Cognito

User Pools

Page 20: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign-up and Sign-inAmazon Cognito

User Pools

Page 21: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Page 22: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS / Email

Page 23: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS / Email

Confirm registration

Page 24: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Page 25: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Authenticate (via SRP)

Page 26: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Authenticate (via SRP)

JWT Tokens

Page 27: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Page 28: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Authenticate (via SRP)

Page 29: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Authenticate (via SRP)

Define Authentication

Challenge

Page 30: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Define Authentication

Challenge

Custom challenge (CAPTCHA, custom 2FA)

Authenticate (via SRP)

Page 31: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Define Authentication

Challenge

Verify Authentication

Challenge Response

Custom challenge (CAPTCHA, custom 2FA)

Authenticate (via SRP)

Challenge response

Page 32: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Register

Verification SMS or email

Confirm registration

Successful registration

Define Authentication

Challenge

Verify Authentication

Challenge Response

Custom challenge (CAPTCHA, custom 2FA)

Authenticate (via SRP)

Challenge response

JWT Tokens

Page 33: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Pre Sign-Up

Validation

Post Confirmation

Custom logic

Define Authentication

Challenge

Verify Authentication

Challenge Response

Pre Authentication

Validation

Post Authentication

custom logic

Register

Verification SMS or email

Confirm registration

Successful registration

Authenticate (via SRP)

Custom challenge (CAPTCHA, custom 2FA)

Challenge response

JWT Tokens

Page 34: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Authenticate (via SRP)

JWT Tokens

Page 35: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Sign up and sign inAmazon Cognito

User Pools

Authenticate (via SRP)

JWT Tokens

Page 36: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

JWT token

eyJraWQiOiI5ZXJydERLbHRxOFl3YUp5MkdadE9ieWtSREVB

OVNCNGlEVDZ2V21UZVFFPSIsImFsZyI6IlJTMjU2In0.eyJz

dWIiOiI2ZjU1NzM2OC1hODg0LTQ4NGUtYjY2Mi05ZmM2OWYz

YzM4MDIiLCJhdWQiOiI2bGtmczcwcm92a3ViaXJoMXF0bnR2

ajAxMiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91

c2UiOiJpZCIsImF1dGhfdGltZSI6MTQ3ODQ0OTA2MCwiaXNz

IjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5h

bWF6b25hd3MuY29tXC91cy1lYXN0LTFfWE1sVVc5c1V5Iiwi

Y29nbml0bzp1c2VybmFtZSI6InRlc3QxMjMiLCJleHAiOjE0

Nzg0NTI2NjAsImdpdmVuX25hbWUiOiJUZXN0IiwiaWF0Ijox

NDc4NDQ5MDYwLCJmYW1pbHlfbmFtZSI6IlRlc3QiLCJlbWFp

bCI6InRyYW5qaW1AYW1hem9uLmNvbSJ9.atQO0SJg9V97d6t

YonHNx0q7Zuof8-d-q0u69zNnuSJtmzGvOAW97tP2e3GydY9

K8q_2kG2IzkpEMUEdaeWjz2qG5dS328Scm6pRDPpC5pOkU8y

mjH7DBPfVXhtgS3iOhyleFhtmaTaYb_lYLpaaV10m8sVFOMH

tjdfrAm26Fq7zyjWYTSfzhqud29Ti4zn9PhcE7aL3s7BB8CJ

18_yFXSoG5CYCpLszvHazx1cbmPoXFrlFlPvZ07Oy8EbOaGs

4CukmoYiV-5RnZsA9JXj405Kp50k-v8HCL6ZACDw3OYMV87P

e6PuEqbzQLlc8BufKThm0xBiO6NJtvI7iC2sEIQ

Page 37: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

JWT token

eyJraWQiOiI5ZXJydERLbHRxOFl3YUp5MkdadE9ieWtSREVB

OVNCNGlEVDZ2V21UZVFFPSIsImFsZyI6IlJTMjU2In0.eyJz

dWIiOiI2ZjU1NzM2OC1hODg0LTQ4NGUtYjY2Mi05ZmM2OWYz

YzM4MDIiLCJhdWQiOiI2bGtmczcwcm92a3ViaXJoMXF0bnR2

ajAxMiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91

c2UiOiJpZCIsImF1dGhfdGltZSI6MTQ3ODQ0OTA2MCwiaXNz

IjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5h

bWF6b25hd3MuY29tXC91cy1lYXN0LTFfWE1sVVc5c1V5Iiwi

Y29nbml0bzp1c2VybmFtZSI6InRlc3QxMjMiLCJleHAiOjE0

Nzg0NTI2NjAsImdpdmVuX25hbWUiOiJUZXN0IiwiaWF0Ijox

NDc4NDQ5MDYwLCJmYW1pbHlfbmFtZSI6IlRlc3QiLCJlbWFp

bCI6InRyYW5qaW1AYW1hem9uLmNvbSJ9.atQO0SJg9V97d6t

YonHNx0q7Zuof8-d-q0u69zNnuSJtmzGvOAW97tP2e3GydY9

K8q_2kG2IzkpEMUEdaeWjz2qG5dS328Scm6pRDPpC5pOkU8y

mjH7DBPfVXhtgS3iOhyleFhtmaTaYb_lYLpaaV10m8sVFOMH

tjdfrAm26Fq7zyjWYTSfzhqud29Ti4zn9PhcE7aL3s7BB8CJ

18_yFXSoG5CYCpLszvHazx1cbmPoXFrlFlPvZ07Oy8EbOaGs

4CukmoYiV-5RnZsA9JXj405Kp50k-v8HCL6ZACDw3OYMV87P

e6PuEqbzQLlc8BufKThm0xBiO6NJtvI7iC2sEIQ

{

"kid":"9errtDKltq8YwaJy2GZtObykRDEA9SB4iDT6vWmTeQE=",

"alg":"RS256”

}

Header

Page 38: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

JWT token

eyJraWQiOiI5ZXJydERLbHRxOFl3YUp5MkdadE9ieWtSREVB

OVNCNGlEVDZ2V21UZVFFPSIsImFsZyI6IlJTMjU2In0.eyJz

dWIiOiI2ZjU1NzM2OC1hODg0LTQ4NGUtYjY2Mi05ZmM2OWYz

YzM4MDIiLCJhdWQiOiI2bGtmczcwcm92a3ViaXJoMXF0bnR2

ajAxMiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91

c2UiOiJpZCIsImF1dGhfdGltZSI6MTQ3ODQ0OTA2MCwiaXNz

IjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5h

bWF6b25hd3MuY29tXC91cy1lYXN0LTFfWE1sVVc5c1V5Iiwi

Y29nbml0bzp1c2VybmFtZSI6InRlc3QxMjMiLCJleHAiOjE0

Nzg0NTI2NjAsImdpdmVuX25hbWUiOiJUZXN0IiwiaWF0Ijox

NDc4NDQ5MDYwLCJmYW1pbHlfbmFtZSI6IlRlc3QiLCJlbWFp

bCI6InRyYW5qaW1AYW1hem9uLmNvbSJ9.atQO0SJg9V97d6t

YonHNx0q7Zuof8-d-q0u69zNnuSJtmzGvOAW97tP2e3GydY9

K8q_2kG2IzkpEMUEdaeWjz2qG5dS328Scm6pRDPpC5pOkU8y

mjH7DBPfVXhtgS3iOhyleFhtmaTaYb_lYLpaaV10m8sVFOMH

tjdfrAm26Fq7zyjWYTSfzhqud29Ti4zn9PhcE7aL3s7BB8CJ

18_yFXSoG5CYCpLszvHazx1cbmPoXFrlFlPvZ07Oy8EbOaGs

4CukmoYiV-5RnZsA9JXj405Kp50k-v8HCL6ZACDw3OYMV87P

e6PuEqbzQLlc8BufKThm0xBiO6NJtvI7iC2sEIQ

{

"sub":"6f557368-a884-484e-b662-9fc69f3c3802",

"aud":"6lkfs70rovkubirh1qtntvj012",

"email_verified":true,

"token_use":"id",

"auth_time":1478449060,

"iss":"https:\/\/cognito-idp.us-east-1.amazonaws.com

\/us-east-1_XMlUW9sUy",

"cognito:username":"test123",

"exp":1478452660,

"given_name”:"Test",

"iat":1478449060,

"family_name":"Test",

"email":”[email protected]"

}

Payload

Page 39: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

JWT token

eyJraWQiOiI5ZXJydERLbHRxOFl3YUp5MkdadE9ieWtSREVB

OVNCNGlEVDZ2V21UZVFFPSIsImFsZyI6IlJTMjU2In0.eyJz

dWIiOiI2ZjU1NzM2OC1hODg0LTQ4NGUtYjY2Mi05ZmM2OWYz

YzM4MDIiLCJhdWQiOiI2bGtmczcwcm92a3ViaXJoMXF0bnR2

ajAxMiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91

c2UiOiJpZCIsImF1dGhfdGltZSI6MTQ3ODQ0OTA2MCwiaXNz

IjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5h

bWF6b25hd3MuY29tXC91cy1lYXN0LTFfWE1sVVc5c1V5Iiwi

Y29nbml0bzp1c2VybmFtZSI6InRlc3QxMjMiLCJleHAiOjE0

Nzg0NTI2NjAsImdpdmVuX25hbWUiOiJUZXN0IiwiaWF0Ijox

NDc4NDQ5MDYwLCJmYW1pbHlfbmFtZSI6IlRlc3QiLCJlbWFp

bCI6InRyYW5qaW1AYW1hem9uLmNvbSJ9.atQO0SJg9V97d6t

YonHNx0q7Zuof8-d-q0u69zNnuSJtmzGvOAW97tP2e3GydY9

K8q_2kG2IzkpEMUEdaeWjz2qG5dS328Scm6pRDPpC5pOkU8y

mjH7DBPfVXhtgS3iOhyleFhtmaTaYb_lYLpaaV10m8sVFOMH

tjdfrAm26Fq7zyjWYTSfzhqud29Ti4zn9PhcE7aL3s7BB8CJ

18_yFXSoG5CYCpLszvHazx1cbmPoXFrlFlPvZ07Oy8EbOaGs

4CukmoYiV-5RnZsA9JXj405Kp50k-v8HCL6ZACDw3OYMV87P

e6PuEqbzQLlc8BufKThm0xBiO6NJtvI7iC2sEIQSignature

HMACSHA256(base64UrlEncode(header) + "." +

base64UrlEncode(payload), {secret});

Page 40: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

JWT token

eyJraWQiOiI5ZXJydERLbHRxOFl3YUp5MkdadE9ieWtSREVB

OVNCNGlEVDZ2V21UZVFFPSIsImFsZyI6IlJTMjU2In0.eyJz

dWIiOiI2ZjU1NzM2OC1hODg0LTQ4NGUtYjY2Mi05ZmM2OWYz

YzM4MDIiLCJhdWQiOiI2bGtmczcwcm92a3ViaXJoMXF0bnR2

ajAxMiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91

c2UiOiJpZCIsImF1dGhfdGltZSI6MTQ3ODQ0OTA2MCwiaXNz

IjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5h

bWF6b25hd3MuY29tXC91cy1lYXN0LTFfWE1sVVc5c1V5Iiwi

Y29nbml0bzp1c2VybmFtZSI6InRlc3QxMjMiLCJleHAiOjE0

Nzg0NTI2NjAsImdpdmVuX25hbWUiOiJUZXN0IiwiaWF0Ijox

NDc4NDQ5MDYwLCJmYW1pbHlfbmFtZSI6IlRlc3QiLCJlbWFp

bCI6InRyYW5qaW1AYW1hem9uLmNvbSJ9.atQO0SJg9V97d6t

YonHNx0q7Zuof8-d-q0u69zNnuSJtmzGvOAW97tP2e3GydY9

K8q_2kG2IzkpEMUEdaeWjz2qG5dS328Scm6pRDPpC5pOkU8y

mjH7DBPfVXhtgS3iOhyleFhtmaTaYb_lYLpaaV10m8sVFOMH

tjdfrAm26Fq7zyjWYTSfzhqud29Ti4zn9PhcE7aL3s7BB8CJ

18_yFXSoG5CYCpLszvHazx1cbmPoXFrlFlPvZ07Oy8EbOaGs

4CukmoYiV-5RnZsA9JXj405Kp50k-v8HCL6ZACDw3OYMV87P

e6PuEqbzQLlc8BufKThm0xBiO6NJtvI7iC2sEIQ

{

"kid":"9errtDKltq8YwaJy2GZtObykRDEA9SB4iDT6vWmTeQE=",

"alg":"RS256”

}

Header

{

"sub":"6f557368-a884-484e-b662-9fc69f3c3802",

"aud":"6lkfs70rovkubirh1qtntvj012",

"email_verified":true,

"token_use":"id",

"auth_time":1478449060,

"iss":"https:\/\/cognito-idp.us-east-1.amazonaws.com

\/us-east-1_XMlUW9sUy",

"cognito:username":"test123",

"exp":1478452660,

"given_name”:"Test",

"iat":1478449060,

"family_name":"Test",

"email":”[email protected]"

}

Payload

Signature

HMACSHA256(base64UrlEncode(header) + "." +

base64UrlEncode(payload), {secret});

Page 41: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Application so far…

Amazon Cognito

User Pools

AWS resources

(e.g. Amazon S3)

Amazon Cognito

Federated Identities

Page 42: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access toAWS resources

Page 43: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

Page 44: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

Page 45: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

Page 46: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

3. Get Identity ID

Page 47: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

4. Identity ID

Page 48: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

5. GetCredentials (ID JWT Token)

Page 49: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

Page 50: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

Page 51: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

8. Temporary

AWS credentials

Page 52: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Federating access to AWS resources

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon S3

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Security Token

Service (STS)

Page 53: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

DEMO

Page 54: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

AuthorizingServerless APIs

Page 55: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SpaceFinder API

(Microservice)

Application so far…

Amazon Cognito

User Pools

AWS resources

(e.g. Amazon S3)

Amazon Cognito

Federated Identities

Page 56: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SpaceFinder API

POST /locations

GET /locations

GET /locations/{locationId}

DELETE /locations/{locationId}

GET /locations/{locationId}/resources

POST /locations/{locationId}/resources

DELETE /locations/{locationId}/resources/{resourceId}

GET /locations/{locationId}/resources/{resourceId}/bookings

GET /users/{userId}/bookings

POST /users/{userId}/bookings

DELETE /users/{userId}/bookings/{bookingId}

Page 57: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SpaceFinder API

Admin only

Admin only

Admin only

Admin only

POST /locations

GET /locations

GET /locations/{locationId}

DELETE /locations/{locationId}

GET /locations/{locationId}/resources

POST /locations/{locationId}/resources

DELETE /locations/{locationId}/resources/{resourceId}

GET /locations/{locationId}/resources/{resourceId}/bookings

GET /users/{userId}/bookings

POST /users/{userId}/bookings

DELETE /users/{userId}/bookings/{bookingId}

Page 58: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

API Gateway: three types of authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

Custom Identity Providers

AWS IAM authorization

Custom Authorizers

User Pools Authorizers

Page 59: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

API Gateway: three types of authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

Custom Identity Providers

AWS IAM authorization

Custom Authorizers

User Pools Authorizers

Page 60: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

AmazonAPIGateway

User Pools authorizers

Amazon Cognito

User Pools

Amazon

DynamoDB

Lambdafunction

Page 61: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

User Pools authorizers

AmazonAPIGateway

Amazon Cognito

User Pools

Amazon

DynamoDB

Lambdafunction

Page 62: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

User Pools authorizers

AmazonAPIGateway

Amazon Cognito

User Pools

Amazon

DynamoDB

Lambdafunction

Page 63: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

User Pools authorizers

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

Amazon Cognito

User Pools

Page 64: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

User Pools authorizers

4. Validate

Identity token

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

Amazon Cognito

User Pools

Page 65: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

User Pools authorizers

5. Invoke API Call

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

Amazon Cognito

User Pools

Page 66: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

User Pools authorizers

6. Access

AWS ResourcesAmazon

DynamoDB

Lambdafunction

AmazonAPIGateway

Amazon Cognito

User Pools

Page 67: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

API Gateway: three types of authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

Custom Identity Providers

AWS IAM authorization

Custom Authorizers

User Pools Authorizers

Page 68: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

IAM-based authorization

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

Amazon Cognito

Federated Identities

Amazon Cognito

User Pools

AWS Identity &

Access Management

Page 69: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon Cognito

User Pools

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

IAM-based authorization

Amazon Cognito

Federated Identities

AWS Identity &

Access Management

Page 70: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

IAM-based authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

AWS Identity &

Access Management

Page 71: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

3. Request AWS credentials

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

IAM-based authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

AWS Identity &

Access Management

Page 72: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Mo

nit

ori

ng

Auth

Mobile app

4. Validate Id token

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

IAM-based authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

AWS Identity &

Access Management

Page 73: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Auth

Mobile app

5. Temp AWS credentials

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

IAM-based authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

AWS Identity &

Access Management

Page 74: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Mobile app

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

IAM-based authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

AWS Identity &

Access Management

Page 75: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Mobile app

Amazon

DynamoDB

Lambdafunction

AmazonAPIGateway

IAM-based authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

AWS Identity &

Access Management

Page 76: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Tro

ttlin

g

Ca

ch

e

Lo

gg

ing

Mo

nit

ori

ng

Mobile app

8. Invoke Lambda

Lambdafunction

AmazonAPIGateway

IAM-based authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

AWS Identity &

Access Management

Amazon

DynamoDB

Page 77: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

IAM policy detail

{

"Version": "2012-10-17",

"Statement": [

{

"Action": "execute-api:Invoke",

"Effect": ”Allow",

"Resource": "arn:aws:execute-api:*:*:ff5h9tpwfh/*"

},

{

"Action": "execute-api:Invoke",

"Effect": "Deny",

"Resource": "arn:aws:execute-api:*:*:ff5h9tpwfh/*/POST/locations/*"

}

]

}

Page 78: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

API Gateway: three types of authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

Custom Identity Providers

AWS IAM authorization

Custom Authorizers

User Pools Authorizers

Page 79: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Custom Authorizer

Lambda function

Auth

Mobile app

Lambdafunction

AmazonAPIGateway

Amazon

DynamoDB

AWS Identity &

Access Management

Custom authorizers

Page 80: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Custom Authorizer

Lambda function

Mobile app

Lambdafunction

AmazonAPIGateway

Amazon

DynamoDB

AWS Identity &

Access Management

Custom authorizers

Page 81: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Custom Authorizer

Lambda function

Auth

Mobile app

Lambdafunction

AmazonAPIGateway

Amazon

DynamoDB

AWS Identity &

Access Management

Custom authorizers

Page 82: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Custom Authorizer

Lambda function

Auth

Mobile app

Lambdafunction

AmazonAPIGateway

Amazon

DynamoDB

AWS Identity &

Access Management

Custom authorizers

Page 83: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Auth

Mobile app

Lambdafunction

AmazonAPIGateway

Custom authorizers

Amazon

DynamoDB

4. Check

policy

cache

AWS Identity &

Access Management

Custom Authorizer

Lambda function

Page 84: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Auth

Mobile app

Lambdafunction

AmazonAPIGateway

Custom authorizers

Amazon

DynamoDB

5. V

alid

ate

to

ken

AWS Identity &

Access Management

Custom Authorizer

Lambda function

Page 85: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Custom Authorizer

Lambda function

Auth

Mobile app

Lambdafunction

AmazonAPIGateway

Custom authorizers

Amazon

DynamoDB

6. G

en

era

te a

nd

retu

rn

use

r IA

M p

olic

y

AWS Identity &

Access Management

Page 86: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Custom Authorizer

Lambda function

Auth

Mobile app

Lambdafunction

AmazonAPIGateway

Custom authorizers

Amazon

DynamoDB

AWS Identity &

Access Management

Page 87: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Custom Authorizer

Lambda function

Auth

Mobile app

Lambdafunction

AmazonAPIGateway

Custom authorizers

Amazon

DynamoDB

8. Invoke Lambda

AWS Identity &

Access Management

Page 88: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Custom authorizer Lambda

var testPolicy = new AuthPolicy(”userIdentifier", "XXXXXXXXXXXX", apiOptions);

testPolicy.allowMethod(AuthPolicy.HttpVerb.POST, "/locations/*");

testPolicy.allowMethod(AuthPolicy.HttpVerb.DELETE, "/locations/*");

callback(null, testPolicy.getPolicy());

Sample Code

Page 89: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

API Gateway: three types of authorization

Amazon Cognito

User Pools

Amazon Cognito

Federated Identities

Custom Identity Providers

AWS IAM authorization

Custom Authorizers

User Pools Authorizers

Page 90: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

DEMO

Page 91: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Integratingwith SAML

Page 92: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SpaceFinder API

(Microservice)

Architecture so far…

Amazon Cognito

User Pools

Enterprise

Identity

Provider

AWS resources

(e.g. Amazon S3)

Amazon Cognito

Federated Identities

Page 93: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Integrating with SAML

• Microsoft Active Directory Federation Services (ADFS)

and Shibboleth are popular SAML providers.

• SAML 2.0 supports two bindings:

• POST

• Re-direct

• Capturing the SAML response in a mobile app is non-

trivial.

Page 94: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SAML

Endpoint

e.g. ADFS

or Shibboleth

Integrating with SAML

Corporate Directory

e.g. Active Directory

or OpenLDAP

Page 95: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SAML

Endpoint

e.g. ADFS

or Shibboleth

Amazon Cognito

Federated Identities

2. Get AWS credentials

Integrating with SAML

Corporate Directory

e.g. Active Directory

or OpenLDAP

?

Page 96: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SAML

Endpoint

e.g. ADFS

or Shibboleth

Amazon Cognito

Federated Identities

2. Get AWS credentials

Integrating with SAML

Corporate Directory

e.g. Active Directory

or OpenLDAP

Serverless APIs or AWS resources

Page 97: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Wrap up

Page 98: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SpaceFinder API

(Microservice)

SpaceFinder mobile app

Amazon Cognito

User Pools

Enterprise

Identity

Provider

AWS resources

(e.g. Amazon S3)

Amazon Cognito

Federated Identities

Page 99: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

SpaceFinder API

(Microservice)

SpaceFinder web app

Amazon Cognito

User Pools

Enterprise

Identity

Provider

AWS resources

(e.g. Amazon S3)

Amazon Cognito

Federated Identities

Page 100: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Do try this at home• Mobile app + API are open-sourced (Apache 2.0 license)

https://github.com/awslabs/

aws-serverless-auth-reference-app

SpaceFinder

Page 101: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Thank you!

Page 102: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Remember to complete

your evaluations!

Page 103: AWS re:Invent 2016: Serverless Authentication and Authorization: Identity Management for Serverless Architectures (MBL306)

Related Sessions

• MLB404 – Real-World Deep Dive: Native, Hybrid, and

Web with Serverless and AWS Mobile

Services

• MLB310 – Add User Sign-In, User Management, and

Security to your Mobile and Web Applications

with Amazon Cognito

• MLB305 – Developing Mobile Apps and Serverless

Microservices for Enterprises using AWS