Share
Embed
Autheo
A stateless, token based authentication and authorization system.
Julian Espinel
August 30, 2014
Transcript
51 slides
-
Agenda 1. Contexto del problema. 2. ¿Qué es REST? 3.
¿Cómo asegurar servicios HTTP? 4. Principios básicos de autenticación y autorización. 5. Autenticación y autorización a través de tokens. 6. ¿Por qué es importante no mantener sesión? 7. ¿Cómo almacenar contraseñas en una base de datos de forma segura? 8. Q&A 9. Referencias -
2. ¿Qué es REST? REST or RESTful API? REST: Architectural
Style. RESTful: Web services in a REST architecture. HTTP Services -
2. ¿Qué es REST? Características de servicios HTTP 1. Resources
2. URLs 3. HTTP methods 4. Media Type 5. Hypermedia controls -
2. ¿Qué es REST? 3. HTTP methods PUT /oms/api/orders GET
/inventory/api/warehouses POST /inventory/api/products POST /cargo/api/trackings GET /cargo/api/airway-bills -
2. ¿Qué es REST? 4. Media types Ordenes (JSON) Bodegas
(XML) Productos (ATOM) Trackings (JSON) Guias de envio (MessagePack) -
2. ¿Qué es REST? 5. Hypermedia controls Ordenes { "orderId":
123, ... ... "links": [ { "rel": ["self"], "href": "http://oms/api/orders/123" }, { "rel": ["previous"], "href": "http://oms/api/orders/122" }, { "rel": ["next"], "href": "http://oms/api/orders/124" }, { "rel": ["collection"], "href": "http://oms/api/orders" } ] } -
2. ¿Qué es REST? 5. Hypermedia controls Ordenes Formats to
help: 1. HAL: http://stateless.co/hal_specification.html 2. Collection+JSON: http://amundsen.com/media-types/collection/ 3. Siren: https://github.com/kevinswiber/siren -
4. Principios básicos de autenticación y autorización. Autenticación: “Es el
acto de establecimiento o confirmación de algo (o alguien) como auténtico”. -
4. Principios básicos de autenticación y autorización. Autenticación: • Username,
password. • Biometrics (huella dactilar, iris). • Two factor authentication. -
4. Principios básicos de autenticación y autorización. Autorización: “Es la
función de especificar derechos de acceso a diferentes recursos”. -
4. Principios básicos de autenticación y autorización. Autorización: • Role
based access control • Token based access control • Rule based access control -
5. Autenticación y autorización a través de tokens Token based
authentication Username:Password Token: dcf24b68d2782f0ca7ea -
5. Autenticación y autorización a través de tokens Token based
authentication Internals Username:Password Token: dcf24b68d2782f0ca7ea Error: credentials are not valid Verify credentials OK: token NOK: error Cache token OK: token 1 7 2 3 5 6 4 4: Generate token -
Authorization: dcf24b68d2782f0ca7ea GET /sellers/samsung/orders/123 5. Autenticación y autorización a través
de tokens Token based authorization 200, 401, 403 ... 200: OK 400: Bad request 401: Unauthorized 403: Forbidden -
5. Autenticación y autorización a través de tokens Token based
authorization Internals (1) Authorization: dcf24b68d2782f0ca7ea GET /sellers/samsung/orders/123 200: order 123 Error: 400, 401, 403 .... 1 4 Verify token and permissions NOK OK 2 3 ¿Cómo verificar la identidad de un usuario y los permisos de este a través de un token? -
5. Autenticación y autorización a través de tokens Token based
authorization Internals (2) Organization Role User Autheo Permission 1 1 1 0..* 0..* 0..* 0..* 0..* 1 -
5. Autenticación y autorización a través de tokens Token based
authorization Internals (3) ¿Qué guardarmos en Redis? Open Source NoSQL DB Key -> Value -
5. Autenticación y autorización a través de tokens Token based
authorization Internals (4) ¿Qué guardarmos en Redis? { "tokenValue": "e1815e2afaba1a7a3d63", "username": "dianasierrra", "userOrganization": "samsung", "userRole": "marketing" } e1815e2afaba1a7a3d63 -
5. Autenticación y autorización a través de tokens Token based
authorization Internals (5) ¿Qué guardarmos en Redis? [ { "id": 1, "name": "ver ordenes", "httpVerb": "GET", "url": "sellers/*/orders" }, { "id": 2, "name": "ver clientes", "httpVerb": "GET", "url": "sellers/*/customers" }, { "id": 3, "name": "ver reportes", "httpVerb": "GET", "url": "sellers/*/reports" } ] Maketing -
5. Autenticación y autorización a través de tokens Token based
authorization Internals (6) ¿Qué guardarmos en Redis? Tokens & Roles -
6. ¿Por qué es importante no mantener sesión? Saltar en
paracaídas Ver el problema desde diferentes alturas -
6. ¿Por qué es importante no mantener sesión? Altura 1
km: autenticación y autorización Username:Password Token: dcf24b68d2782f0ca7ea 200, 401, 403 ... Authorization: dcf24b68d2782f0ca7ea GET /sellers/samsung/orders/123 -
6. ¿Por qué es importante no mantener sesión? Altura 500
m (1): autenticación Username:Password Token: dcf24b68d2782f0ca7ea Username:Password Token: dcf24b68d2782f0ca7ea -
6. ¿Por qué es importante no mantener sesión? Altura 500
m (2): autorización Authorization: dcf24b68d2782f0ca7ea GET /sellers/samsung/orders/123 200, 401, 403 ... 200 Authorization: dcf24b68d2782f0ca7ea GET /sellers/samsung/orders/123 -
6. ¿Por qué es importante no mantener sesión? Altura 500
m (3): autorización Authorization: dcf24b68d2782f0ca7ea GET /sellers/samsung/orders/123 200, 401, 403 ... Authorization: dcf24b68d2782f0ca7ea GET /sellers/samsung/orders/123 200 ? ¿Cómo escalo horizontalmente? -
6.1. ¿Cómo hacerlo? Altura 100 m (1): autenticación SET dcf24b68d2782f0ca7ea
OK Username:Password Token: dcf24b68d2782f0ca7ea Replicate Replicate -
6.1. ¿Cómo hacerlo? Altura 100 m (2): autorización GET dcf24b68d2782f0ca7ea
Token 200 Authorization: dcf24b68d2782f0ca7ea GET /sellers/samsung/orders/123 -
6.1. ¿Cómo hacerlo? Altura 100 m (3): autorización Authorization: dcf24b68d2782f0ca7ea
GET /sellers/samsung/orders/123 200 GET dcf24b68d2782f0ca7ea Token -
7. ¿Cómo almacenar contraseñas de forma segura? Plain Password: BogotaJVM123
Saved Password: 1000*c34397efbac000c6c59b6d6dc75160e45a ef4e3597261e91*1140b45c23fe1f78fe456bf5 bf19543505e396ed7dc813c9 -
7. ¿Cómo almacenar contraseñas de forma segura? BogotaJVM123 1000*c34397efbac000c6c59b6d6 dc75160e45aef4e3597261e91*11
40b45c23fe1f78fe456bf5bf1954 3505e396ed7dc813c9 -
7. ¿Cómo almacenar contraseñas de forma segura? BogotaJVM123 1000*c34397efbac000c6c59b6d6 dc75160e45aef4e3597261e91*11
40b45c23fe1f78fe456bf5bf1954 3505e396ed7dc813c9 BogotaJVM123 1000*c34397efbac000c6c59b6d6 dc75160e45aef4e3597261e91*11 40b45c23fe1f78fe456bf5bf1954 3505e396ed7dc813c9 X X F(X) F(X) -
7. ¿Cómo almacenar contraseñas de forma segura? ¿Cómo ir de
X -> F(X)? 1. Salt 2. Hash 3. Save -
7. ¿Cómo almacenar contraseñas de forma segura? ¿Cómo ir de
X -> F(X)? 1. Salt BogotaJVM123 + Meetup3 = BogotaJVM123Meetup3 Plain password Salt Password + salt -
7. ¿Cómo almacenar contraseñas de forma segura? ¿Cómo ir de
X -> F(X)? 2. Hash hash(BogotaJVM123Meetup3) = Cryptographic hash function Salted and hashed password Password + salt 1140b45c23fe1f78fe456bf5 bf19543505e396ed7dc813c9 -
7. ¿Cómo almacenar contraseñas de forma segura? ¿Cómo ir de
X -> F(X)? 3. Save Password to save = Cryptographic hash function Iterations:Salt:Hash Password + salt 1000*c34397efbac000c6c59b6d6dc75160e45aef4e 3597261e91*1140b45c23fe1f78fe456bf5bf195435 05e396ed7dc813c9 -
Referencias 1. http://martinfowler.com/articles/richardsonMaturityModel.html 2. http://stackoverflow.com/questions/1568834/whats-the-difference-between-rest-restful 3. https://www.ics.uci.edu/~fielding/pubs/dissertation/fielding_dissertation.pdf 4. http://msgpack.org/ 5.
https://coderwall.com/p/xvzu-g 6. http://stateless.co/hal_specification.html 7. http://amundsen.com/media-types/collection/ 8. https://github.com/kevinswiber/siren 9. http://en.wikipedia.org/wiki/Authentication 10. http://en.wikipedia.org/wiki/Authorization 11. http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 12. http://redis.io 13. http://stackoverflow.com/questions/20588467/how-to-do-stateless-session-less-cookie-less- authentication 14. http://blog.moertel.com/posts/2006-12-15-never-store-passwords-in-a-database.html 15. https://crackstation.net/hashing-security.htm