plan b: service to service authentication with oauth

42
Service to Service Authentication with OAuth Zalando Tech Meetup Dortmund, 2016-05-12 Background: Mike Mozart / CC BY 2.0

Upload: henning-jacobs

Post on 18-Jan-2017

1.134 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Plan B: Service to Service Authentication with OAuth

Service to Service Authentication with OAuthZalando Tech Meetup Dortmund, 2016-05-12

Background: Mike Mozart / CC BY 2.0

Page 2: Plan B: Service to Service Authentication with OAuth

15 countries

3 fulfillment centers

18 million active customers

3 billion € revenue 2015

135+ million visits per month

10.000+ employees in Europe

ZALANDO

Page 3: Plan B: Service to Service Authentication with OAuth

RADICAL AGILITY

Page 4: Plan B: Service to Service Authentication with OAuth

AUTONOMY

Page 5: Plan B: Service to Service Authentication with OAuth

ONE DATA CENTER PER TEAM

Page 6: Plan B: Service to Service Authentication with OAuth

Internet

*.abc.example.org *.xyz.example.org

Team ABC Team XYZ

ISOLATED AWS ACCOUNTS

EC2EC2

ELBELB

EC2

Page 7: Plan B: Service to Service Authentication with OAuth

● 1000+ in Zalando Tech

● 100+ AWS Accounts

● 300+ Applications

SOME NUMBERS..

Page 8: Plan B: Service to Service Authentication with OAuth

Internetbob.xyz.example.org

Team ABC Team XYZ

SERVICE TO SERVICE

bobEC2

ELB

alice

Page 9: Plan B: Service to Service Authentication with OAuth

● HTTP Basic Auth● SAML● Kerberos● OAuth 2.0● “Notariat”

AUTHENTICATION CANDIDATES

Page 10: Plan B: Service to Service Authentication with OAuth

● HTTP Basic Auth● SAML● Kerberos● OAuth 2.0● “Notariat”

AUTHENTICATION CANDIDATES

Page 11: Plan B: Service to Service Authentication with OAuth

TheOAuth 2.0 authorization framework enables a third-party applicationto obtain limited access toan HTTP service.

- oauth.net

OAUTH?

Page 12: Plan B: Service to Service Authentication with OAuth

● Resource Owner

● Client

● Resource Server

● Authorization Server

OAUTH ROLES

Page 13: Plan B: Service to Service Authentication with OAuth

● Resource Owner ⟺ User

● Client ⟺ Application

● Resource Server ⟺ REST API

● Authorization Server ⟺ OAuth Provider

OAUTH ROLES

Page 14: Plan B: Service to Service Authentication with OAuth

OAUTH REDIRECT FLOW

Authz Server /OAuth Provider

access protected resource

Resource Owner / User

Resource Server /REST API

Client / Application

validatetoken

Page 15: Plan B: Service to Service Authentication with OAuth

https://demo.zmon.io/

EXAMPLE OAUTH REDIRECT FLOW

Page 16: Plan B: Service to Service Authentication with OAuth

● One Service User per Application

● Resource Owner Password Credentials

Grant Type

● Automatic credential distribution

and rotation

OAUTH FOR SERVICE TO SERVICE

Page 17: Plan B: Service to Service Authentication with OAuth

Authorization: Bearer 123f

Team ABC Team XYZ

SERVICE TO SERVICE

bobEC2

ELB

alice

S3Authz Server /

OAuth Provider validate token

Page 18: Plan B: Service to Service Authentication with OAuth

OAUTH CREDENTIAL DISTRIBUTION VIA S3 BUCKETS

AWS

WEB UI

get access token

store passwords

get passwordS3

rotate passwords Authz Server /

OAuth Provider

alice

create app

Page 19: Plan B: Service to Service Authentication with OAuth

● Alice reads OAuth credentials from S3

● Alice gets access token from Auth. Server

● Alice calls Bob with Bearer token

● Bob validates token against Auth. Server

OAUTH SERVICE TO SERVICE FLOW

Page 20: Plan B: Service to Service Authentication with OAuth

● Install some OAuth Provider

● Set up credential distribution

● PROFIT!!!

EASY ENOUGH

Page 21: Plan B: Service to Service Authentication with OAuth
Page 22: Plan B: Service to Service Authentication with OAuth

● Network Latency?

● Token Storage?

● Availability?

WHAT ABOUT

bobalice

Authz Server /OAuth Provider

TokenStorage

createtoken validate

Page 23: Plan B: Service to Service Authentication with OAuth

● Robustness & resilience

● Low latency for token validation

● Horizontal scalability

PLAN B: GOALS

Page 24: Plan B: Service to Service Authentication with OAuth

● JWT access token

● No write operation

● Cassandra

PLAN B: APPROACH

bobalice

createtoken Token

Info validateProvider

credential storage

Page 25: Plan B: Service to Service Authentication with OAuth

JSON WEB TOKENS (JWT)

Page 26: Plan B: Service to Service Authentication with OAuth

$ curl -u alice-service:mypw \

-d 'grant_type=password&username=alice-service&password=123' \

https://planb-provider.example.org/oauth2/access_token?realm=/services

{

"access_token": "eyJraWQiOXN0a2V5LWVzMjU2..",

"token_type": "Bearer",

"expires_in": 28800,

"scope": "cn",

"realm": "/services"

}

PLAN B TOKEN ENDPOINT

Page 27: Plan B: Service to Service Authentication with OAuth

Authorization: Bearer ↲a8dfcf02-2d21-fe12-8791-822f48749018

Authorization: Bearer ↲eyJraWQiOiJ0ZXN0a2V5LWVzMjU2IiwiYWxnIjoiRVMyNTYifQ.eyJzdWIiOiJ0ZXN0MiIsInNjb3BlIjpbImNuIl0sImlzcyI6IkIiLCJyZWFsbSI6Ii9zZXJ2aWNlcyIsImV4cCI6MTQ1NzMxOTgxNCwiaWF0IjoxNDU3MjkxMDE0fQ.KmDsVB09RAOYwT0Y6E9tdQpg0rAPd8SExYhcZ9tXEO6y9AWX4wBylnmNHVoetWu7MwoexWkaKdpKk09IodMVug

36 chars vs ~300 chars

JWT AS OAUTH ACCESS TOKEN

Page 28: Plan B: Service to Service Authentication with OAuth

● JWT libs exist for every major language

● De-facto standard: HTTP call to Token Info

● New OAuth RFC defines

Token Introspection Endpoint

JWT: HOW TO VALIDATE?

Page 29: Plan B: Service to Service Authentication with OAuth

GET /oauth2/tokeninfo?access_token=eyJraWQiOiJ0ZXN0a2VLWVzMjU2..

{

"expires_in": 28292,

"grant_type": "password",

"realm": "/services",

"scope": ["cn", "pets.read"],

"token_type": "Bearer",

"uid": "alice-service"

}

PLAN B TOKEN INFO

Page 30: Plan B: Service to Service Authentication with OAuth

● Self-contained JWT tokens

● No revocation standard

REVOKING TOKENS

Page 31: Plan B: Service to Service Authentication with OAuth

● Revoke single tokens

● Revoke tokens by claims

“Revoke all tokens issued before 1st of May for user John Doe”

REVOCATION LISTS

Page 32: Plan B: Service to Service Authentication with OAuth

REVOCATION SERVICE

Token Info

Revocation ServicePOST /revocations

GET /revocations?from=...

Page 33: Plan B: Service to Service Authentication with OAuth

PLAN B: COMPLETE PICTURE

bobalice

createtoken

Token Infovalidate

Provider

credential storageRevocation

pollpublic keys

pollrevocation listsS3

call with Bearer token

Page 34: Plan B: Service to Service Authentication with OAuth

● OAuth credentials in CREDENTIALS_DIR

● Token endpoint available at

OAUTH2_ACCESS_TOKEN_URL

ALICE’ PERSPECTIVE

Page 35: Plan B: Service to Service Authentication with OAuth

● Validation endpoint (Token Info) available at

TOKENINFO_URL

BOB’S PERSPECTIVE

Page 36: Plan B: Service to Service Authentication with OAuth

● Robustness & resilience⇒ Cassandra, no SPOF

● Low latency for token validation⇒ Token Info next to application

● Horizontal scalability⇒ Cassandra, “stateless” Token Info

PLAN B: GOALS?

Page 37: Plan B: Service to Service Authentication with OAuth

● >1300 active service users (last 5 days)● 8 h JWT lifetime● 40 rps on Token Endpoint (Provider)● 1500 rps on Token Info (caching!)● 0.5 ms JWT validation (99%)● 11 ms Token Info latency (99%)

PLAN B IN PRODUCTION

Page 38: Plan B: Service to Service Authentication with OAuth
Page 39: Plan B: Service to Service Authentication with OAuth

Created for Service2Service, but also supports:

● Authorization Code Grant Type

● Implicit Grant Type

● User Consent

PLAN B PROVIDER

Page 40: Plan B: Service to Service Authentication with OAuth

● 3rd party Mobile App

● OAuth Implicit Flow

PLAN B FOR CUSTOMERS

Page 41: Plan B: Service to Service Authentication with OAuth

● Consent Screen

● Consent stored

in Cassandra

PLAN B FOR CUSTOMERS

Page 42: Plan B: Service to Service Authentication with OAuth

Questions?

Plan B Docsplanb.readthedocs.orgSTUPS Homepagestups.io

tech.zalando.com@try_except_