28
Close Encounters of Modern Architecture #1 - CDN and JWT - 2016-10-07 eurie Inc. Takahiro Ikeuchi © 2016 eurie Inc.

Close Encounters of Modern Architecture 1 - CDN and JWT

  • Upload
    -

  • View
    302

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Close Encounters of Modern Architecture 1 - CDN and JWT

Close Encounters of

Modern Architecture #1

- CDN and JWT -

2016-10-07

eurie Inc. Takahiro Ikeuchi

© 2016 eurie Inc.

Page 2: Close Encounters of Modern Architecture 1 - CDN and JWT

AgendaSPA with Amazon CloudFront

REST API with Amazon CloudFront

JWT, Try for more state less

© 2016 eurie Inc. 2

Page 3: Close Encounters of Modern Architecture 1 - CDN and JWT

AuthorTakahiro Ikeuchi @iktakahiro

Company / Community

eurie Inc. Founder & CEO

SQUEEZE Inc. Tech Adviser

PyData.Tokyo Organizer

Specialties (or just a dabbler :-D

Go lang, Python, React.js, TypeScript

Cloud Infrastructure, UI Design etc...

© 2016 eurie Inc. 3

Page 4: Close Encounters of Modern Architecture 1 - CDN and JWT

ConclusionI recommend that you adopt CDN to deliveryour Single Page Application.

Amazon CloudFront + S3 is a good solution.

You may deploy CDN in front of your ServerSide Application to improve the performance.

JWT is handiness and secure. You have to useJWT and Local storage instead of Cookie.

© 2016 eurie Inc. 4

Page 5: Close Encounters of Modern Architecture 1 - CDN and JWT

We Love:RESTful API

Go lang (framework: echo)

Single Page Application

React.js + Typescript

Elasticsearch

AWS Aurora, Lambda, CloudFront, WAF...

Codeship.com

© 2016 eurie Inc. 5

Page 6: Close Encounters of Modern Architecture 1 - CDN and JWT

SPA with Amazon CloudFront

© 2016 eurie Inc. 6

Page 7: Close Encounters of Modern Architecture 1 - CDN and JWT

© 2016 eurie Inc. 7

Page 8: Close Encounters of Modern Architecture 1 - CDN and JWT

Focus: Applications

© 2016 eurie Inc. 8

Page 9: Close Encounters of Modern Architecture 1 - CDN and JWT

What is Amazon CloudFront

CDN = Contents Delivery Network

Competitors: Akamai, Fastly,Google Cloud CDN

Edge locations around the world

Integration with Amazon S3

https://aws.amazon.com/cloudfront/

© 2016 eurie Inc. 9

Page 10: Close Encounters of Modern Architecture 1 - CDN and JWT

Why Amazon CloudFront ?

High Availability

Fast Network

HTTP/2.0

Free SSL Certi�cation (only SNI)

Cache Control System

© 2016 eurie Inc. 10

Page 11: Close Encounters of Modern Architecture 1 - CDN and JWT

Fast NetworkAmazon CloudFront edge locations are locatedin around the world.(US, Europe, Asia, South Amerca)

https://aws.amazon.com/cloudfront/details/

© 2016 eurie Inc. 11

Page 12: Close Encounters of Modern Architecture 1 - CDN and JWT

HTTP/2.0Amazon CloudFront supports HTTP/2.0

© 2016 eurie Inc. 12

Page 13: Close Encounters of Modern Architecture 1 - CDN and JWT

REST API with Amazon CloudFront

© 2016 eurie Inc. 13

Page 14: Close Encounters of Modern Architecture 1 - CDN and JWT

© 2016 eurie Inc. 14

Page 15: Close Encounters of Modern Architecture 1 - CDN and JWT

Why to deploy CDN in front of ourREST API?

Fast Network

Free SSL Certi�cation (only SNI)

WAF = Web Application Firewall

A REST API also bene�ts from technorogies ofAmazon CloudFront.

© 2016 eurie Inc. 15

Page 16: Close Encounters of Modern Architecture 1 - CDN and JWT

Really Fast?See below:

Secured API Acceleration with Engineers fromAmazon CloudFront and Slack

CloudFrontをかますとキャッシュなしのAPIコールでも速くなるようだ - sonots:blog (Japanese)

© 2016 eurie Inc. 16

Page 17: Close Encounters of Modern Architecture 1 - CDN and JWT

http://www.slideshare.net/AmazonWebServices/secured-api-acceleration-with-engineers-from-amazon-cloudfront-and-slack 17

Page 18: Close Encounters of Modern Architecture 1 - CDN and JWT

JWT, Try for more state less

© 2016 eurie Inc. 18

Page 19: Close Encounters of Modern Architecture 1 - CDN and JWT

What is JWT

JSON Web Token

The pronunciation of JWT is the same as"jot". In japanese, "じょっと".

RFC 7519 - JSON Web Token (JWT)

https://jwt.io/

JWT is a token based authentication scheme.

Probably, better approach than Cookie.

© 2016 eurie Inc. 19

Page 20: Close Encounters of Modern Architecture 1 - CDN and JWT

JWT Structure

Structure

HEADER.CLAIMS.SIGNATURE

e.g.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ

© 2016 eurie Inc. 20

Page 21: Close Encounters of Modern Architecture 1 - CDN and JWT

JWT Header

Encoded Token

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

Decoded Token

{ "alg": "HS256", "typ": "JWT"}

JSON -> Base64 URL Encoding -> Token

© 2016 eurie Inc. 21

Page 22: Close Encounters of Modern Architecture 1 - CDN and JWT

JWT Claims (Payload)

Encoded Token

eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9

Decoded Token

{ "sub": "1234567890", "name": "John Doe", "admin": true}

© 2016 eurie Inc. 22

Page 23: Close Encounters of Modern Architecture 1 - CDN and JWT

Signature

JWT Header and payload are just a JSON. That isto say, it can be built easily by someone.

Solution: JWT contains a signature (JWS)

RFC 7515 - JSON Web Signature (JWS)

(Most) JWT libraries can detect tokenmanipulations.

© 2016 eurie Inc. 23

Page 24: Close Encounters of Modern Architecture 1 - CDN and JWT

How to use

Set JWT in HTTP Authorization Header.

Authorization: Bearer {{ JWT }}

RFC 6750 - The OAuth 2.0 AuthorizationFramework: Bearer Token Usage

© 2016 eurie Inc. 24

Page 25: Close Encounters of Modern Architecture 1 - CDN and JWT

JWT Libraries

Python: jpadilla/pyjwt

Node.js: auth0/node-jsonwebtoken

Go lang: dgrijalva/jwt-go

© 2016 eurie Inc. 25

Page 26: Close Encounters of Modern Architecture 1 - CDN and JWT

Bene�ts of JWT and Bearer

Cookie-less

A HTTP Request does not force push data ina Local (Session) Storage.

State-less

JWT contains all the required informationabout a user.

A Server-Side Application does not have tomanage a session. (But if you need a high-security requirement, consider it.)

© 2016 eurie Inc. 26

Page 27: Close Encounters of Modern Architecture 1 - CDN and JWT

Secure

A Protection from token manipulations.

Signing Algorithms: RSA, ECDSA

Many libraries supports JWT.

© 2016 eurie Inc. 27

Page 28: Close Encounters of Modern Architecture 1 - CDN and JWT

ConclusionI recommend that you adopt CDN to deliveryour Single Page Application.

Amazon CloudFront + S3 is a good solution.

You may deploy CDN in front of your ServerSide Application to improve the performance.

JWT is handiness and secure. You have to useJWT and Local storage instead of Cookie.

© 2016 eurie Inc. 28