< Return to Video

RailsConf 2014 - Authorization in a Service-Oriented Environment by Alan Cohen

  • 0:17 - 0:21
    ALAN COHEN: OK. Can everyone hear me? Raise
    your hand if,
  • 0:21 - 0:25
    yeah? Cool. This is my first talk, so I'm
    a little bit
  • 0:25 - 0:31
    nervous. I'm gonna, actually, take a picture
    for my mom.
  • 0:31 - 0:38
    So, if everyone can, like, wave. Awesome.
    Yes. All right.
  • 0:42 - 0:49
    All right. Cool. So, my talk is about authorization.
  • 0:49 - 0:55
    Service-oriented authorization. My name is
    Alan, by the way.
  • 0:55 - 0:59
    You can find me on Twitter and GitHub.
  • 0:59 - 1:04
    I work at a company called The Climate Corporation.
  • 1:04 - 1:07
    I'm a Ruby developer there. I've been there
    for
  • 1:07 - 1:10
    about a year and a half working on, we
  • 1:10 - 1:12
    have an insurance product, I work on the backend
  • 1:12 - 1:17
    as well as other parts of our web infrastructure.
  • 1:17 - 1:23
    We have products that help protect farmers
    from weather
  • 1:23 - 1:28
    disasters and improve their farming operations
    during the planting
  • 1:28 - 1:32
    and, before and after the planting season.
    It's sort
  • 1:32 - 1:34
    of like, if I'm gonna make it, like, buzz-word
  • 1:34 - 1:38
    compliant, it's big data farming.
  • 1:38 - 1:41
    So, a little bit of background before I get
  • 1:41 - 1:47
    into my talk. What is authorization? So, if
    you
  • 1:47 - 1:51
    were in this room before, you probably learned
    about
  • 1:51 - 1:56
    authentication in a service, service-oriented
    environment. Today I'm talking
  • 1:56 - 2:02
    authorization. So, authentication is concerned
    with identity. Authorization is
  • 2:04 - 2:08
    concerned with access.
  • 2:08 - 2:10
    There are different types of authorization.
    If you've ever
  • 2:10 - 2:15
    implemented it. You can think about role-based
    access control,
  • 2:15 - 2:20
    attribute-based access control, access control
    lists, rule-based access control.
  • 2:20 - 2:23
    It can go on and on. I'm not talking
  • 2:23 - 2:28
    about a specific implementation of authorization,
    but just, in
  • 2:28 - 2:30
    general, right.
  • 2:30 - 2:34
    What is service oriented architecture? Right.
    There's been many,
  • 2:34 - 2:36
    many talks. I think this entire track is on
  • 2:36 - 2:40
    service oriented architecture. And, you know,
    there's been talks
  • 2:40 - 2:43
    yesterday. I've gone to a few of these talks.
  • 2:43 - 2:49
    I, they, service oriented architecture is
    many different solutions
  • 2:49 - 2:51
    to different problems. But, you know, it's
    around the
  • 2:51 - 2:53
    same theme, I guess.
  • 2:53 - 2:56
    This, where I'm not talking about a specific
    implementation
  • 2:56 - 3:00
    of SOA, so I want to find a really
  • 3:00 - 3:03
    basic definition of it, and I found this.
    A
  • 3:03 - 3:07
    loosely-coupled architecture designed to meet
    the business needs of
  • 3:07 - 3:11
    an organization. I found this on the Microsoft
    Developer
  • 3:11 - 3:13
    Network site. And it also had this, like,
    really
  • 3:13 - 3:17
    interesting quote. And it started with, SOAs
    are like
  • 3:17 - 3:22
    snowflakes. No two are alike.
  • 3:22 - 3:24
    But I wanted to find like a, a better
  • 3:24 - 3:27
    definition. And actually, when I was watching
    Brian Morton's
  • 3:27 - 3:33
    talk from Big Rails, Big Ruby last year, Rails,
  • 3:33 - 3:35
    Services and Rails, The Shit They Don't Tell
    You.
  • 3:35 - 3:38
    He says, Components that scale individually.
    That's sort of
  • 3:38 - 3:42
    how he defines service oriented architecture.
  • 3:42 - 3:44
    And I, I recommend that talk, if you want
  • 3:44 - 3:48
    to learn about implementing service oriented
    architecture. Some services
  • 3:48 - 3:51
    oriented architecture, from someone who has
    the battle scars
  • 3:51 - 3:55
    moving over to something like that. But today,
    I'm
  • 3:55 - 4:01
    not, I'm not, like, focusing on what it is.
  • 4:01 - 4:08
    So, why talk about it? Right. Why, why services
  • 4:09 - 4:12
    oriented architecture? We have to und- you
    know, before
  • 4:12 - 4:14
    we get into authorization, I want to talk
    a
  • 4:14 - 4:18
    little bit about why we would use SOA. SOA
  • 4:18 - 4:22
    gives us a lot of things, right. Reusability,
    we
  • 4:22 - 4:25
    can allocate resources as we need them, loose
    coupling,
  • 4:25 - 4:28
    we can change out libraries, a codebase that
    scales
  • 4:28 - 4:31
    across teams and so, we get, we get things
  • 4:31 - 4:33
    that are good for both our software and for
  • 4:33 - 4:36
    our software development process.
  • 4:36 - 4:37
    There are a lot of problems, also, right,
    that
  • 4:37 - 4:39
    you have to solve when you have a service
  • 4:39 - 4:42
    oriented architecture. Right, services speaking
    to one another. Like,
  • 4:42 - 4:46
    a lot of things become difficult. But hopefully
    you're
  • 4:46 - 4:51
    here because the, the benefits of SOA outweigh
    the
  • 4:51 - 4:54
    problems that you might have. And you've already
    sort
  • 4:54 - 4:56
    of made that decision. I'm not gonna try to
  • 4:56 - 4:58
    sell you on it.
  • 4:58 - 5:02
    So, what is service oriented authorization?
    Well, if we
  • 5:02 - 5:06
    think about the benefits of services oriented
    architecture, it
  • 5:06 - 5:11
    should be sort of parallel to that. Reusability,
    I
  • 5:11 - 5:14
    want to be able to use the, the same
  • 5:14 - 5:21
    authorization tools, libraries, code, across
    multiple services. Loose coupling.
  • 5:21 - 5:25
    My application code is not coupled to my authorization
  • 5:25 - 5:32
    implementation. And then, lastly, scalability.
    So, this is like
  • 5:32 - 5:36
    a requirement when you have multiple services.
    And this
  • 5:36 - 5:38
    is just gonna be like a general requirement
    when
  • 5:38 - 5:40
    we talk about, like, the framework that I
    want
  • 5:40 - 5:42
    to use.
  • 5:42 - 5:46
    So, let's imagine a typical Rails application,
    ignoring things
  • 5:46 - 5:51
    like the database and other third-party services.
    You have
  • 5:51 - 5:53
    your, you have Rails, you have your business
    logic,
  • 5:53 - 5:56
    and then you have some third-party gems that
    you
  • 5:56 - 5:59
    might use.
  • 5:59 - 6:02
    The important part is your business logic,
    right. That's,
  • 6:02 - 6:05
    like, if you have an online product, like
    BaseCamp,
  • 6:05 - 6:08
    right, that's the interesting stuff. That's
    the part that's
  • 6:08 - 6:10
    gonna make you money. It's what, why your
    cosumer's
  • 6:10 - 6:13
    pay you money. Everything else is just there
    to
  • 6:13 - 6:17
    help you deliver that product.
  • 6:17 - 6:19
    I think authorization can be thought of as
    part
  • 6:19 - 6:22
    of your business. Whether it's part of the
    security
  • 6:22 - 6:25
    of your application, for example, like, you
    have employees
  • 6:25 - 6:28
    that, only your employees are allowed to administer
    customer
  • 6:28 - 6:31
    data, like, for customer support. Or, whether
    it's part
  • 6:31 - 6:34
    of the feature of your application. Like,
    in BaseCamp,
  • 6:34 - 6:39
    you have, like admin users in different groups.
  • 6:39 - 6:43
    So, what does authorization look like today?
    I think,
  • 6:43 - 6:47
    you know, the most popular authorization library
    is -
  • 6:47 - 6:50
    I don't know if you can see this -
  • 6:50 - 6:52
    but, this is like a snapshot of CanCan's GitHub's
  • 6:52 - 6:58
    page. I think it's probably the most popular
    authorization
  • 6:58 - 7:01
    gem. We use it in production. It works. It's
  • 7:01 - 7:04
    historically been well-supported. I think
    it's still pretty good.
  • 7:04 - 7:08
    But, you know, it gives you, like, a really
  • 7:08 - 7:13
    nice declarative DSL for specifying rules,
    like, so then,
  • 7:13 - 7:16
    you specify your rules, like, within your
    application, and
  • 7:16 - 7:19
    it's, like, nice Ruby DSL. And then you can
  • 7:19 - 7:22
    ask questions like, can a user manage this
    other
  • 7:22 - 7:25
    user's data. Can a user purchase a policy,
    if
  • 7:25 - 7:27
    you're selling insurance.
  • 7:27 - 7:31
    But the question is, does this approach align
    with
  • 7:31 - 7:37
    what we've defined as service oriented authorization?
    Right. CanCan
  • 7:37 - 7:40
    is reusable, right, because it's a library.
    So, you
  • 7:40 - 7:43
    know, the authorization implementation is
    decoupled from our app.
  • 7:43 - 7:47
    We don't, like, bake authorization into our
    app.
  • 7:47 - 7:51
    But it's, it's not really loosely coupled,
    right. If
  • 7:51 - 7:54
    you think about it, your authorization rules
    are, are
  • 7:54 - 7:58
    embedded in your application code, right.
    So like, the,
  • 7:58 - 8:04
    the. What is it? Yeah. The, your rules are
  • 8:04 - 8:07
    in your application. And there's some limitations
    to this
  • 8:07 - 8:11
    approach, which aren't apparent at first,
    right.
  • 8:11 - 8:14
    And, so what? Like, what are those limitations?
    Or,
  • 8:14 - 8:18
    why does that matter? Well, I think that if
  • 8:18 - 8:20
    we want to keep the core of our application
  • 8:20 - 8:23
    small and understandable as possible, we want
    to, we
  • 8:23 - 8:24
    want to do that because that's the part that
  • 8:24 - 8:27
    makes us money. The business logic is what's
    important.
  • 8:27 - 8:28
    And it's the part we want to keep free
  • 8:28 - 8:31
    of bugs. If we, if we do that, we
  • 8:31 - 8:35
    can develop with confidence, like we know
    we won't
  • 8:35 - 8:40
    develop and create bugs. Our business logic
    is concerned
  • 8:40 - 8:43
    with authorization only as far as we need
    to
  • 8:43 - 8:46
    make sure to enforce it. But we shouldn't
    care
  • 8:46 - 8:49
    about how it's implemented, but just that
    it works.
  • 8:49 - 8:52
    So, this is your business logic. This is you
  • 8:52 - 8:58
    enforcing authorization in your code. But
    the rest is,
  • 8:58 - 9:01
    I think, can, should be thought of as implementation
  • 9:01 - 9:04
    details, right. Where you define those rules.
    It doesn't
  • 9:04 - 9:07
    necessarily need to be part of your system.
    It
  • 9:07 - 9:08
    needs to exist somewhere.
  • 9:08 - 9:14
    And I'll explain why, why that matters, right.
    So,
  • 9:14 - 9:16
    in a services oriented architecture, right,
    you usually start
  • 9:16 - 9:22
    with a monolithic application. And if we've
    coupled our
  • 9:22 - 9:24
    rules to our application, then it's gonna
    be very
  • 9:24 - 9:29
    difficult to split things into services, right.
    Especially if
  • 9:29 - 9:34
    there, all these services are concerned with
    a user.
  • 9:34 - 9:37
    You have all these user rules in your, in
  • 9:37 - 9:40
    your monoRails app, but now they sort of have
  • 9:40 - 9:42
    to be broken out. And that's fine if you're
  • 9:42 - 9:46
    gonna use, right, CanCan across these different
    Ruby or
  • 9:46 - 9:52
    Rails applications. But a services oriented
    architecture usually, by
  • 9:52 - 9:57
    default, means you're gonna have, like, a
    heterogenous environment.
  • 9:57 - 9:59
    And this is actually very similar to what
    we
  • 9:59 - 10:01
    have in production today, where we don't just
    have
  • 10:01 - 10:04
    the Rails stack. We have other, other things,
    either
  • 10:04 - 10:06
    in Java or Clojure or whatever it might be
  • 10:06 - 10:10
    in the future. And, there really isn't an
    easy
  • 10:10 - 10:14
    way to go from CanCan to Clojure, right.
  • 10:14 - 10:20
    So, we want to, we want to think about
  • 10:20 - 10:23
    a different framework to, to basically do
    this. So,
  • 10:23 - 10:26
    what are the goals of whatever approach we
    take?
  • 10:26 - 10:30
    Well, the goal, goals, you know, restating
    them. Reusability,
  • 10:30 - 10:32
    scalability, and loose coupling.
  • 10:32 - 10:36
    So, let's go back to our app, right. We
  • 10:36 - 10:40
    have the same Rails app, but it's, it's very
  • 10:40 - 10:44
    simplified. Your app, when you move it onto
    different
  • 10:44 - 10:48
    services, might look like this, where you
    have different
  • 10:48 - 10:51
    JavaScript frontends that are, you know, we
    deploy them
  • 10:51 - 10:53
    as different modules. Our users like see a
    single
  • 10:53 - 10:58
    interface, but really it's several different,
    several different applications
  • 10:58 - 11:02
    that are speaking to several different backends.
  • 11:02 - 11:06
    And the business logic that used to reside
    in
  • 11:06 - 11:11
    a single application now is residing across
    multiple applications,
  • 11:11 - 11:18
    and those, yeah. So, the, the key take away
  • 11:18 - 11:22
    is that this is a heterogenous environment,
    and so
  • 11:22 - 11:26
    we shouldn't constrain ourselves, right, by
    language or run
  • 11:26 - 11:28
    time. We want to use the best possible tools
  • 11:28 - 11:32
    to, to grow our services, to build them.
  • 11:32 - 11:35
    So, reusability means we want code that doesn't
    require
  • 11:35 - 11:40
    us to predict the future. And, if I'm gonna
  • 11:40 - 11:45
    extract my authorization into another service
    or, part of
  • 11:45 - 11:48
    my authorization into a separate service,
    like, I need,
  • 11:48 - 11:50
    I need to be able to do that without,
  • 11:50 - 11:52
    without having to rewrite it. I don't want
    to
  • 11:52 - 11:57
    have to rewrite everything.
  • 11:57 - 12:01
    And that's, loose coupling means, like, that,
    we, we're
  • 12:01 - 12:05
    gonna decouple the access decision from the
    access policy.
  • 12:05 - 12:12
    So, just, restating, restating that, we can't
    use this,
  • 12:12 - 12:16
    right, outside of a, outside of our Rails
    application.
  • 12:16 - 12:21
    We also need whatever framework to be scalable.
    So,
  • 12:21 - 12:23
    there's, you know, when I was researching
    this and
  • 12:23 - 12:26
    I was like, what are, what are the available
  • 12:26 - 12:29
    tools to be able to do something like this?
  • 12:29 - 12:33
    And I didn't really find anything. I did find,
  • 12:33 - 12:37
    of this, of this thing called XACML. I mean,
  • 12:37 - 12:38
    raise your hand if you've heard of XACML.
  • 12:38 - 12:42
    Yeah. So I see, like, maybe ten people have
  • 12:42 - 12:46
    raised your hand. So XACML is, it's XML, and
  • 12:46 - 12:50
    it stands for extensible access control markup
    language. And
  • 12:50 - 12:54
    it's a declarative policy language implemented
    in XML. And
  • 12:54 - 12:58
    it defines a processing model that describes
    how to
  • 12:58 - 13:02
    evaluate access requests according to rules
    defined and policies.
  • 13:02 - 13:04
    So it actually, if you read the spec it's,
  • 13:04 - 13:06
    I think like hundreds of pages long, and it
  • 13:06 - 13:10
    actually defines an entire architecture using
    XML to define
  • 13:10 - 13:13
    authorization rules and sort of like, all
    these different
  • 13:13 - 13:16
    services to implement authorization. And that,
    in fact, it
  • 13:16 - 13:20
    uses a centralized authorization service,
    and it's pretty, it's
  • 13:20 - 13:22
    pretty complex, I think.
  • 13:22 - 13:24
    But, I found this from a spec, and I
  • 13:24 - 13:29
    thought this was actually really poignant.
    The XACML model
  • 13:29 - 13:32
    supports and encourages the separation of
    the access decision
  • 13:32 - 13:35
    from the point of use.
  • 13:35 - 13:38
    When access decisions are baked into client
    applications, it
  • 13:38 - 13:41
    is very difficult to update the decision criteria
    when
  • 13:41 - 13:45
    the governing policy changes. When the client
    is decoupled
  • 13:45 - 13:50
    from the access decision, authorization policies
    can be updated
  • 13:50 - 13:53
    on the fly and affect all clients immediately.
  • 13:53 - 13:59
    So, this is what an XACML policy would look
  • 13:59 - 14:03
    like. I got the indenting wrong, but, I mean,
  • 14:03 - 14:06
    you get the idea. It's, it's pretty complex,
    but
  • 14:06 - 14:08
    it gives us this advantage of being able to
  • 14:08 - 14:11
    update and modify the rules without touching
    our application
  • 14:11 - 14:15
    code, and so it should, we should be able
  • 14:15 - 14:18
    to use this in sort of a hit, in
  • 14:18 - 14:21
    a heterogenous environment. As long as we
    have some
  • 14:21 - 14:24
    authorization library that we can use within
    our application.
  • 14:24 - 14:29
    But, I thought that this is, this is, like,
  • 14:29 - 14:31
    way too much for, for what we needed, right.
  • 14:31 - 14:34
    Like, we, like, we don't have thousands and
    thousands
  • 14:34 - 14:37
    of rules. Our application is actually fairly
    simple compared
  • 14:37 - 14:41
    to the implementations I've seen for this.
    So, I
  • 14:41 - 14:44
    wanted to, to, you know, try something a little
  • 14:44 - 14:48
    bit simpler, right.
  • 14:48 - 14:55
    Thing is, I didn't, I didn't really find anything
  • 14:55 - 15:00
    simpler. So, when, when we were discussing
    this authorization
  • 15:00 - 15:04
    framework that I'm gonna go over, we, we thought,
  • 15:04 - 15:05
    like, all right, let's, let's come up with
    a
  • 15:05 - 15:08
    very simple language that we can use and,
    you
  • 15:08 - 15:09
    know, as we, as we build this out, as
  • 15:09 - 15:11
    we test it, we can, we can experiment with
  • 15:11 - 15:14
    it, and if we need to bake more features
  • 15:14 - 15:18
    into it, let's do that. But let's, let's,
    let's
  • 15:18 - 15:20
    implement as few features as we need as possible.
  • 15:20 - 15:23
    And, so that's where we started.
  • 15:23 - 15:26
    So, just a recap: we talked a little bit
  • 15:26 - 15:31
    about why would we choose SOA architecture.
    What SOA
  • 15:31 - 15:34
    might be. And we set our goals to be
  • 15:34 - 15:37
    scalability, flexibility, and loose coupling.
    And we talked about
  • 15:37 - 15:39
    why we chose these three goals. Like, what
    are
  • 15:39 - 15:41
    their benefits.
  • 15:41 - 15:45
    So, what, like, what did we come up with?
  • 15:45 - 15:48
    And, I guess, I didn't, I didn't really talk
  • 15:48 - 15:51
    about, like, what this is. What this framework
    is.
  • 15:51 - 15:53
    But, you know, I worked, I worked with a
  • 15:53 - 15:54
    few guys in my company. We said all right.
  • 15:54 - 15:58
    Let's, let's build this, it's, it's not really
    a
  • 15:58 - 16:00
    framework. It's more like let's, let's define
    a language
  • 16:00 - 16:04
    where we can, we can define authorization
    policies, and
  • 16:04 - 16:08
    it's really, it's agnostic to, to Rails, whatever
    it
  • 16:08 - 16:12
    is, and let's, let's try to create, like,
    a
  • 16:12 - 16:15
    reference implementation and experiment with
    it. And then see
  • 16:15 - 16:17
    if it's, if this is a rich enough language
  • 16:17 - 16:20
    to be able to use and replace whatever we
  • 16:20 - 16:21
    have today.
  • 16:21 - 16:25
    So, this is, this is sort of, like, this
  • 16:25 - 16:28
    is the like, the v zero dot one alpha
  • 16:28 - 16:30
    of the language, right. We don't, there's
    not like
  • 16:30 - 16:32
    an official spec that we, you know, we have
  • 16:32 - 16:35
    a very, like, early spec for this, and this
  • 16:35 - 16:40
    is sort of like what we came up with.
  • 16:40 - 16:43
    And I'll go through, like, each, each object
    in
  • 16:43 - 16:47
    this, in this, in this JSON. So, we have
  • 16:47 - 16:52
    a resource. A resource could be defined within
    a
  • 16:52 - 16:54
    namespace, and so it could also be like, just
  • 16:54 - 16:56
    the name of a class. So like, if it's
  • 16:56 - 16:58
    a Rails application, it could be like an ActiveRecord
  • 16:58 - 17:04
    model. An action, or a set of actions. So,
  • 17:04 - 17:06
    a rule will apply to a set of actions,
  • 17:06 - 17:08
    just like in CanCan, you sort of do the
  • 17:08 - 17:12
    same thing.
  • 17:12 - 17:15
    You have a set of conditions that define the
  • 17:15 - 17:19
    evaluation context of a rule. So, whether
    a rule
  • 17:19 - 17:24
    applies or not. So, in this case, this is
  • 17:24 - 17:27
    like, how we would say, like, the, the role
  • 17:27 - 17:34
    of a user must equal admin. So, if we're,
  • 17:34 - 17:35
    right.
  • 17:35 - 17:38
    And then every rule will have an effect. So
  • 17:38 - 17:41
    it'll be either allow or deny. So we have
  • 17:41 - 17:47
    this language. But, something is missing.
    And that's, what's
  • 17:47 - 17:50
    sort of bridging that gap, right. We have
    an
  • 17:50 - 17:52
    application. Now we have a set of rules. Like,
  • 17:52 - 17:54
    what's, what's connecting the two?
  • 17:54 - 17:57
    And so, right, I wrote this really small gem,
  • 17:57 - 18:02
    and it's called IronHide. And, we just have
    this
  • 18:02 - 18:05
    practice of naming all of our gems at work
  • 18:05 - 18:11
    after Transformer characters. So, IronHide
    is this, is sort
  • 18:11 - 18:14
    of this bridge. We define a set of rules,
  • 18:14 - 18:16
    and we have our application, and then we include
  • 18:16 - 18:20
    IronHide into our application, and IronHide
    exposes the same
  • 18:20 - 18:23
    API that CanCan would, and so it's sort of
  • 18:23 - 18:24
    like a drop-in.
  • 18:24 - 18:29
    And, so like, what is it? It's not a
  • 18:29 - 18:33
    service. It doesn't provide an authorization
    service for us.
  • 18:33 - 18:35
    It's actually just a library. So, that, that's
    an
  • 18:35 - 18:42
    important distinction, because we're, you
    know, where are the
  • 18:42 - 18:44
    rules, right? If it's not a service, then
    it's
  • 18:44 - 18:46
    gonna have to call out and get the rules
  • 18:46 - 18:47
    from somewhere.
  • 18:47 - 18:49
    And that's, that's actually pretty cool, because
    we can
  • 18:49 - 18:51
    store the rules anywhere we want, right. They're
    just,
  • 18:51 - 18:55
    it's just JSON. So, JSON can really be stored
  • 18:55 - 18:56
    anywhere. It can be stored, like, on, on disc.
  • 18:56 - 19:00
    It can be stored in the document store. And
  • 19:00 - 19:06
    having this, like, plugability to different
    backend stores gives
  • 19:06 - 19:07
    us scalability.
  • 19:07 - 19:14
    So, does it meet our goals? Right. Reusability,
    scalability,
  • 19:14 - 19:20
    loose coupling. The authorization rules are
    not part of
  • 19:20 - 19:26
    the application code. The, the language in
    which we
  • 19:26 - 19:29
    define the rules is language agnostic. So
    it should
  • 19:29 - 19:36
    be reusable across, across environments. And,
    if we've decoupled
  • 19:36 - 19:39
    the backing store from the authorization implementation,
    then it
  • 19:39 - 19:40
    should be as scalable as we want it to
  • 19:40 - 19:42
    be.
  • 19:42 - 19:46
    So, today, it's still a work in progress.
    It's
  • 19:46 - 19:50
    still something that we're experimenting with,
    right. You know.
  • 19:50 - 19:53
    XACML is like, it's a very well-defined spec.
    I
  • 19:53 - 19:55
    think it's like version three point 0 of the
  • 19:55 - 20:00
    spec. It's, it's sort of like an enterprise-level
    design.
  • 20:00 - 20:04
    This is like, you know, we're experimenting
    with it.
  • 20:04 - 20:06
    You know. Could it scale to thousands and
    thousands
  • 20:06 - 20:08
    of rules and to like, many, many services?
    I
  • 20:08 - 20:10
    don't know yet. Right.
  • 20:10 - 20:14
    It's not yet in production. But, and it's
    also
  • 20:14 - 20:17
    something that, you know, we need to standardize
    and
  • 20:17 - 20:19
    name the policy language. Right. There's no
    name for
  • 20:19 - 20:26
    it. Like, so. I'd like to actually do a
  • 20:27 - 20:34
    demo. So. Let's see if this works.
  • 20:39 - 20:46
    Where is this? Can everyone see that? No.
    If
  • 20:55 - 20:57
    I make the. Too small?
  • 20:57 - 20:59
    AUDIENCE: We can't see the font.
  • 20:59 - 21:06
    A.C.: Can't see-? Oh, yeah. Would it, would
    it
  • 21:10 - 21:12
    be better if I made the background light and
  • 21:12 - 21:13
    the foreground dark?
  • 21:13 - 21:13
    AUDIENCE: No.
  • 21:13 - 21:17
    A.C.: No. OK. Right. So, so this is, like,
  • 21:17 - 21:19
    this is a rule, right. It's, and it's, and
  • 21:19 - 21:23
    this is, and I've written this just directly
    into
  • 21:23 - 21:26
    a flat file on my disc. So there's some
  • 21:26 - 21:31
    resource under this app namespace, a set of
    actions.
  • 21:31 - 21:37
    An effect and a set of conditions.
  • 21:37 - 21:43
    And then, I actually made, like, a really
    simple
  • 21:43 - 21:45
    -it's not an app. It's just. I created a
  • 21:45 - 21:51
    user class. It has a manager id and an
  • 21:51 - 21:56
    id. And if you look at the, right, if
  • 21:56 - 21:59
    you look at the rule, I'm saying that a
  • 21:59 - 22:04
    user, it's allowed to read or manage another
    user.
  • 22:04 - 22:07
    In this case, the resource is also a user.
  • 22:07 - 22:10
    So, we're always authorizing against the
    user. So, the
  • 22:10 - 22:13
    user is allowed to do something to another
    thing.
  • 22:13 - 22:15
    And in this case it's another user.
  • 22:15 - 22:17
    As long as the user's id is equal to
  • 22:17 - 22:24
    the other thing's manager id. So, here, we
    have
  • 22:24 - 22:28
    a user with a manager. I'm gonna run this
  • 22:28 - 22:31
    and then jump directly into the console, so
    I
  • 22:31 - 22:35
    can, like, start writing code.
  • 22:35 - 22:42
    Oh. OK. So, right. I can, I can. Let's
  • 22:57 - 23:04
    see. User. Right. So, this. This user has
    a
  • 23:11 - 23:18
    manager id now that's equal to the manager's
    id.
  • 23:19 - 23:23
    And then. I didn't, I didn't really go into
  • 23:23 - 23:26
    depth, into the IronHide, like, library, but
    I'm gonna
  • 23:26 - 23:29
    post a link to the source. I've tried to
  • 23:29 - 23:32
    write a pretty well-documented README.
  • 23:32 - 23:38
    So, it should be fairly self-explanatory.
    Basically, there's a,
  • 23:38 - 23:45
    a configuration. Oh. Crap.
  • 23:58 - 24:05
    OK. And then. So. It's like. It works.
  • 24:20 - 24:27
    AUDIENCE: [laughter - applause]
  • 24:27 - 24:33
    A.C.: Yeah. It's actually kind of funny, cause
    I
  • 24:33 - 24:36
    tried recording this, and it was probably
    easier doing
  • 24:36 - 24:43
    it live. I'm gonna try to jump back.
  • 24:43 - 24:50
    So. So yeah. These, these are links to the
  • 24:50 - 24:52
    source, so that's like. I tried getting a
    short
  • 24:52 - 24:56
    link for the GitHub page. And there's actually
    a
  • 24:56 - 24:59
    sample app with, sort of like, what, it was
  • 24:59 - 25:01
    sort of like that, maybe with a few, a
  • 25:01 - 25:05
    few additional things. And I also wrote, like,
    an
  • 25:05 - 25:09
    adapter that would let you use, like, CouchDB
    as
  • 25:09 - 25:11
    the backing store for the rules.
  • 25:11 - 25:13
    CouchDB's pretty cool. So. It was the first
    time
  • 25:13 - 25:14
    I used it.
  • 25:17 - 25:18
    OK.
  • 25:19 - 25:20
    AUDIENCE: [applause]
Title:
RailsConf 2014 - Authorization in a Service-Oriented Environment by Alan Cohen
Description:

more » « less
Duration:
25:45

English subtitles

Revisions