add authentication to any application
play

ADD AUTHENTICATION TO ANY APPLICATION Aaron Parecki @aaronpk - PowerPoint PPT Presentation

ADD AUTHENTICATION TO ANY APPLICATION Aaron Parecki @aaronpk aaronpk.com Developer Advocate at Okta @oktadev oauth.net @aaronpk oauth2simplified.com avocado.lol @aaronpk avocado.lol @aaronpk avocado.lol wiki.avocado.lol


  1. ADD AUTHENTICATION TO ANY APPLICATION Aaron Parecki • @aaronpk • aaronpk.com Developer Advocate at Okta • @oktadev

  2. oauth.net @aaronpk

  3. oauth2simplified.com

  4. avocado.lol @aaronpk

  5. avocado.lol @aaronpk

  6. avocado.lol wiki.avocado.lol @aaronpk

  7. avocado.lol Public Internet Private Network wiki.avocado.lol @aaronpk

  8. avocado.lol wiki.avocado.lol User Database Public Internet @aaronpk

  9. avocado.lol stats.avocado.lol wiki.avocado.lol User Database @aaronpk

  10. avocado.lol wiki.avocado.lol stats.avocado.lol User Database .htpasswd @aaronpk

  11. avocado.lol wiki.avocado.lol stats.avocado.lol ci.avocado.lol User Database .htpasswd GitHub Auth @aaronpk

  12. USER MANAGEMENT ▸ Add the user to wiki account database ▸ Add password to .htpasswd file ▸ Add the user to the GitHub organization @aaronpk

  13. avocado.lol wiki.avocado.lol stats.avocado.lol ci.avocado.lol SAML Plugin .htpasswd SAML Plugin ?? SAML LDAP Database @aaronpk

  14. There must be a better way! @aaronpk

  15. ngx_http_auth_request_module @aaronpk

  16. http://nginx.org/en/docs/http/ngx_http_auth_request_module.html @aaronpk

  17. 1 avocado.lol login.avocado.lol sub-request 2 3 wiki.avocado.lol stats.avocado.lol ci.avocado.lol @aaronpk

  18. Enable the auth subrequest Send the subrequest to here location / { auth_request /validate; ... } Pass the subrequest to this backend location = /validate { We don’t care about 
 proxy_pass ... the request body proxy_pass_request_body off; proxy_set_header Content-Length ""; proxy_set_header X-Original-URI $request_uri; } @aaronpk

  19. ? avocado.lol login.avocado.lol wiki.avocado.lol stats.avocado.lol ci.avocado.lol @aaronpk

  20. LASSO github.com/LassoProject @aaronpk

  21. LASSO ▸ A microservice written in Go ▸ Supports a variety of OAuth/OIDC 
 authentication mechanisms ▸ Configurable session cookie lifetime ▸ Handles the nginx auth_module subrequest, 
 returning HTTP 200 or 401 ▸ Uses a JWT cookie for fast and stateless verification @aaronpk

  22. NGINX CONFIG server { listen 443 ssl http2; Send the subrequest here server_name stats.avocado.lol; auth_request /lasso-validate; … } @aaronpk

  23. server { listen 443 ssl http2; server_name stats.avocado.lol; This is the address that 
 auth_request /lasso-validate; Lasso is listening on auth_request_set $auth_user $upstream_http_x_lasso_user; location = /lasso-validate { proxy_pass http://127.0.0.1:9090/validate; proxy_pass_request_body off; proxy_set_header Content-Length ""; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; # these return values are passed to the @error401 call auth_request_set $auth_resp_jwt $upstream_http_x_lasso_jwt; auth_request_set $auth_resp_err $upstream_http_x_lasso_err; auth_request_set $auth_resp_failcount $upstream_http_x_lasso_failcount; } When Lasso says they are not 
 error_page 401 = @error401; logged in, redirect to the login URL location @error401 { return 302 https://login.avocado.lol/login?url= https://$http_host$request_uri&lasso-failcount=$auth_resp_failcount &X-Lasso-Token=$auth_resp_jwt&error=$auth_resp_err; } } @aaronpk

  24. NGINX CONFIG The public hostname of the 
 Lasso server server { listen 443 ssl http2; server_name login.avocado.lol; ssl_certificate /etc/letsencrypt/live/login.avocado.lol/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/login.avocado.lol/privkey.pem; This is the address that 
 # Proxy to your Lasso instance location / { Lasso is listening on proxy_set_header Host login.avocado.lol; proxy_set_header X-Forwarded-Proto https; proxy_pass http://127.0.0.1:9090; } } @aaronpk

  25. avocado.lol login.avocado.lol wiki.avocado.lol stats.avocado.lol ci.avocado.lol @aaronpk

  26. avocado.lol login.avocado.lol wiki.avocado.lol stats.avocado.lol ci.avocado.lol @aaronpk

  27. avocado.lol login.avocado.lol wiki.avocado.lol stats.avocado.lol ci.avocado.lol @aaronpk

  28. avocado.lol login.avocado.lol wiki.avocado.lol stats.avocado.lol ci.avocado.lol @aaronpk

  29. https://stats.avocado.lol/ redirecting to… https://login.avocado.lol/login?url=https://stats.avocado.lol/… @aaronpk

  30. https://login.avocado.lol/login?url=https://stats.avocado.lol/ redirecting to… https://accounts.google.com/login… @aaronpk

  31. https://accounts.google.com/?…. to continue to login.avocado.lol Aaron Parecki aaronpk@avocado.lol @aaronpk

  32. https://login.avocado.lol/callback?code=azsyxuqmdkfhgpw redirecting to… https://stats.avocado.lol/ @aaronpk

  33. https://stats.avocado.lol/ 100 75 50 25 0 APRIL MAY JUNE JULY @aaronpk

  34. Nginx Lasso Google GET stats.avocado.lol GET login.avocado.lol/validate Not 401 Not Authorized Authorized 302 login.avocado.lol GET login.avocado.lol Lasso Login 302 accounts.google.com/oauth/authorize GET accounts.google.com/oauth/authorize Google 302 login.avocado.lol/callback?code=x OAuth GET login.avocado.lol/callback?code=x POST accounts.google.com/oauth/token Lasso Begins { "user": "username@avocado.lol" } Session 302 stats.avocado.lol Cookie: Lasso-Session: eyJ... GET stats.avocado.lol GET login.avocado.lol/validate Authorized! 200 OK 200 OK @aaronpk

  35. LASSO USE CASES Restrict to email address domain name 
 (e.g. Google Apps Accounts) Allow all users if they can authenticate 
 (e.g. your own OAuth/OpenID Connect server) Public access, authenticate for additional privileges 
 (e.g. read-only public wiki, log in to edit) @aaronpk

  36. CONFIGURING LASSO - GOOGLE APPS DOMAIN config.yml lasso: Require authentication 
 listen: 127.0.0.1 on every request port: 9090 publicAccess: false Allow only users at 
 allowAllUsers: false the domains below domains: 
 - avocado.lol 
 Allow users with email 
 addresses at this domain oauth: provider: google client_id: 144124... client_secret: u_eWvYCtD callback_urls: - https://login.avocado.lol/auth preferredDomain: avocado.lol @aaronpk

  37. CONFIGURING LASSO - CUSTOM OPENID SERVER config.yml Require authentication 
 lasso: on every request listen: 127.0.0.1 port: 9090 Allow any user at 
 publicAccess: false the OAuth server allowAllUsers: true oauth: provider: oidc client_id: 014223 client_secret: JKLOL auth_url: https://dev-442449.oktapreview.com/oauth2/default/v1/authorize token_url: https://dev-442449.oktapreview.com/oauth2/default/v1/token user_info_url: https://dev-442449.oktapreview.com/oauth2/default/v1/userinfo scopes: Custom OpenID Connect 
 - openid - email server configuration - profile callback_url: https://login.avocado.lol/auth @aaronpk

  38. CONFIGURING LASSO - WORDPRESS SERVER config.yml Require authentication 
 lasso: on every request listen: 127.0.0.1 port: 9090 Allow any user who 
 publicAccess: false can log in to this WordPress allowAllUsers: true oauth: provider: indieauth client_id: https://login.avocado.lol/ auth_url: https://wordpress.avocado.lol/wp-json/indieauth/1.0/auth callback_url: https://login.avocado.lol/auth WordPress OAuth 
 server configuration @aaronpk

  39. https://stats.avocado.lol/ redirecting to… https://login.avocado.lol/login?url=https://stats.avocado.lol/… @aaronpk

  40. https://login.avocado.lol/login?url=https://stats.avocado.lol/ redirecting to… https://wordpress.avocado.lol/wp-login.php?… @aaronpk

  41. https://wordpress.avocado.lol/wp-login.php?…. @aaronpk

  42. https://login.avocado.lol/callback?code=azsyxuqmdkfhgpw redirecting to… https://stats.avocado.lol/ @aaronpk

  43. https://stats.avocado.lol/ 100 75 50 25 0 APRIL MAY JUNE JULY @aaronpk

  44. CONFIGURING LASSO - PUBLIC ACCESS WITH GITHUB LOGIN config.yml lasso: Allow requests even 
 listen: 127.0.0.1 without authentication port: 9090 publicAccess: true Anyone with a GitHub 
 allowAllUsers: true account can log in oauth: provider: github Configure GitHub credentials client_id: client_secret: auth_url: https://github.com/login/oauth/authorize token_url: https://github.com/login/oauth/access_token scopes: - user user_info_url: https://api.github.com/user?access_token= @aaronpk

  45. https://stats.avocado.lol/ Log In 100 75 50 25 0 APRIL MAY JUNE JULY @aaronpk

  46. https://stats.avocado.lol/ redirecting to… https://login.avocado.lol/login?url=https://stats.avocado.lol/… @aaronpk

  47. https://login.avocado.lol/login?url=https://stats.avocado.lol/ redirecting to… https://wordpress.avocado.lol/wp-login.php?… @aaronpk

  48. https://github.com/login/oauth/authorize?…. @aaronpk

  49. https://login.avocado.lol/callback?code=azsyxuqmdkfhgpw redirecting to… https://stats.avocado.lol/ @aaronpk

  50. https://stats.avocado.lol/ Logged in as @aaronpk 100 75 50 25 0 APRIL MAY JUNE JULY @aaronpk

  51. WHO LOGGED IN? server { ... auth_request_set $auth_user $upstream_http_x_lasso_user; ... fastcgi_param REMOTE_USER $auth_user; 
 # or proxy_set_header Remote-User $auth_user; ... } <?php if($_SERVER['REMOTE_USER']) echo 'Hello, ' . $_SERVER['REMOTE_USER'] . '!'; else echo 'Not logged in'; @aaronpk

Recommend


More recommend