Securing Clojure web services & applications with Friend Chas Emerick @cemerick http://cemerick.com

What are we not talking about? • SQL injection • Cross Site Request Forgeries • Replay attacks • Untrusted code evaluation/jailing

Clojure web security with Friend (March 19, 2013)

What are we talking about? •

Authentication (a.k.a. A1, authN) •



“Who are you?”

Authorization (a.k.a. A2, authZ) •

“What are you allowed to do?”

Clojure web security with Friend (March 19, 2013)

Auth options in Clojure-world • spring-security • brentonashworth/sandbar • remvee/ring-basic-authentication • DerGuteMoritz/clj-oauth2 • Roll-your-own None were completely fulfilling… Clojure web security with Friend (March 19, 2013)

http://www.flickr.com/photos/nayvera/2888789282/

Seriously, why? • Implementing auth (properly) is: • High risk • Minimal reward • Absolutely necessary • Should be a solved problem

Clojure web security with Friend (March 19, 2013)

Envy https://github.com/bnoguchi/everyauth

Clojure web security with Friend (March 19, 2013)

Wishlist • Assume Ring • Use any authentication authority I want • Easy: username/password, HTTP Basic • PITA: OpenID, OAuth(2) • Custom: multi-factor auth, phishing prevention • Flexible authorization options • role-based • room for ACLs, capability systems, & more Clojure web security with Friend (March 19, 2013)

Friend

http://github.com/cemerick/friend • Ring middleware • Authentication workflows are Ring handlers++ • Credential sources are functions • Hashing functions are...functions

Clojure web security with Friend (March 19, 2013)

Batteries included • Authentication workflows • form-based “interactive” login • HTTP Basic (Digest, soon) • OpenId (Google Yahoo Wordpress &c) • “Channel enforcement” (e.g. require HTTPS) Clojure web security with Friend (March 19, 2013)

Batteries included (2/2) • Authorization options • Roles based on Clojure’s ad-hoc hierarchies • Functions, macros, and Ring middleware for easily enforcing rolebased authorization policy • Arbitrary imperative control Clojure web security with Friend (March 19, 2013)

Architecture & Examples

Clojure web security with Friend (March 19, 2013)

Clojure web security with Friend (March 19, 2013)

(ns  your.ring.app    (:require  [cemerick.friend  :as  friend]                        (cemerick.friend  [workflows  :as  workflows]                                                          [credentials  :as  creds])))

;  assemble  your  ring  app  however  you  like (def  ring-­‐app  #_...) ;  assert  relationships  between  roles  in  your  app  (optional) (derive  ::student  ::user) (derive  ::admin  ::student) ;  a  dummy  in-­‐memory  user  "database" (def  users  {"root"  {:username  "root"                                        :password  (creds/hash-­‐bcrypt  "admin_password")                                        :roles  #{::admin}}                        "jane"  {:username  "jane"                                        :password  (creds/hash-­‐bcrypt  "Jane’s  password")                                        :roles  #{::student}                                        :year  1}}) (def  secured-­‐app    (friend/authenticate  ring-­‐app        {:credential-­‐fn  (partial  creds/bcrypt-­‐credential-­‐fn  users)          :workflows  [(workflows/interactive-­‐form)                                  (workflows/http-­‐basic  :realm  "Friend  demo")  #_...]}))

Clojure web security with Friend (March 19, 2013)

;;  enforcing  arbitrary  &  role-­‐based  authorization  policies (compojure.core/defroutes  app    (GET  "/requires-­‐authentication"  req        ;  scope  within  which  a  user  must  be  authenticated  in  any  capacity        (friend/authenticated  #_...))    (GET  "/course-­‐schedules"  req        ;  scope  within  which  a  user  must  have  >=  ::student  role        (friend/authorize  #{::student}  #_...))    (GET  "/admissions"  req        ;  scope  within  which  a  user  must  have  >=  ::admin  role        (friend/authorize  #{::admin}  #_...))    (GET  "/freshman-­‐orientation"  req        ;  arbitrary  authorization  criteria        ;  e.g.  require  that  a  user  have  >=  ::admin  role,  OR  be  a  freshman        (let  [id  (friend/identity  req)]            (if  (or  (friend/authorized?  #{::admin}  id)                        (and  (friend/authorized?  #{::student}  id)                            (-­‐>  id  friend/current-­‐authorization  :year  (=  0))))                #_...                (friend/throw-­‐unauthorized  id                    {:reason  "Must  be  a  freshman  to  access  orientation  info"})))))

Clojure web security with Friend (March 19, 2013)

Demo

Clojure web security with Friend (March 19, 2013)

Coming soon • Factor out OpenID • Canned support for OAuth2 providers • Simplification of workflow contract • More eyes / audit?

Clojure web security with Friend (March 19, 2013)

Questions?

http://cemerick.com @cemerick http://clojurebook.com @ClojureBook Clojure web security with Friend (March 19, 2013)

GET - GitHub

OpenId (Google Yahoo Wordpress &c) ... (workflows/http-‐basic :realm "Friend demo") #_...]})) ... Clojure web security with Friend (March 19, 2013). Demo ...

828KB Sizes 4 Downloads 196 Views

Recommend Documents

SIP HTTP GET commands - GitHub
A network error will be raised if this is run in Auto mode. Parameters: ○ sid=x is .... the third program http://x.x.x.x/dp?pw=opendoor&pid=-1 delete all programs ...

GitHub
domain = meq.domain(10,20,0,10); cells = meq.cells(domain,num_freq=200, num_time=100); ...... This is now contaminator-free. – Observe the ghosts. Optional ...

GitHub
data can only be “corrected” for a single point on the sky. ... sufficient to predict it at the phase center (shifting ... errors (well this is actually good news, isn't it?)

Get In, Get Connected, Get Hired
Some students effectively leverage their education to transform ... An essential read for those seeking a degree or a career in business, Get In, Get Connected, ...

Get the Facts. Get the Facts.
and services to transform ... Provide your pastor, rabbi or imam with a list of the area. Twelve Step ... Post in a prominent place a list of the Twelve Step groups.

Get the Facts. Get the Facts.
alcohol to get “high.” Unifying ... and counseling if they have an alcohol/drug abuse or addiction ... If you are in recovery, read how some people are now sharing.

Get the Facts. Get the Facts.
science, education and services ... a person's lifetime; usually follows a predictable course; and has ... Post in a prominent place a list of the Twelve Step groups.

Torsten - GitHub
Metrum Research Group has developed a prototype Pharmacokinetic/Pharmacodynamic (PKPD) model library for use in Stan 2.12. ... Torsten uses a development version of Stan, that follows the 2.12 release, in order to implement the matrix exponential fun

Untitled - GitHub
The next section reviews some approaches adopted for this problem, in astronomy and in computer vision gener- ... cussed below), we would question the sensitivity of a. Delaunay triangulation alone for capturing the .... computation to be improved fr

ECf000172411 - GitHub
Robert. Spec Sr Trading Supt. ENA West Power Fundamental Analysis. Timothy A Heizenrader. 1400 Smith St, Houston, Tx. Yes. Yes. Arnold. John. VP Trading.

Untitled - GitHub
Iwip a man in the middle implementation. TOR. Andrea Marcelli prof. Fulvio Risso. 1859. Page 3. from packets. PEX. CethernetDipo topo data. Private. Execution. Environment to the awareness of a connection. FROG develpment. Cethernet DipD tcpD data. P

BOOM - GitHub
Dec 4, 2016 - 3.2.3 Managing the Global History Register . ..... Put another way, instructions don't need to spend N cycles moving their way through the fetch ...

Supervisor - GitHub
When given an integer, the supervisor terminates the child process using. Process.exit(child, :shutdown) and waits for an exist signal within the time.

robtarr - GitHub
http://globalmoxie.com/blog/making-of-people-mobile.shtml. Saturday, October ... http://24ways.org/2011/conditional-loading-for-responsive-designs. Saturday ...

MY9221 - GitHub
The MY9221, 12-channels (R/G/B x 4) c o n s t a n t current APDM (Adaptive Pulse Density. Modulation) LED driver, operates over a 3V ~ 5.5V input voltage ...

fpYlll - GitHub
Jul 6, 2017 - fpylll is a Python (2 and 3) library for performing lattice reduction on ... expressiveness and ease-of-use beat raw performance.1. 1Okay, to ... py.test for testing Python. .... GSO complete API for plain Gram-Schmidt objects, all.

article - GitHub
2 Universidad Nacional de Tres de Febrero, Caseros, Argentina. ..... www-nlpir.nist.gov/projects/duc/guidelines/2002.html. 6. .... http://singhal.info/ieee2001.pdf.