1 00:00:08,670 --> 00:00:13,250 Who here is familiar with access control within web applications in some way or form? 2 00:00:13,390 --> 00:00:14,050 About half of you. 3 00:00:14,050 --> 00:00:14,450 That's cool. 4 00:00:14,450 --> 00:00:15,950 Who knows what RBAC is? 5 00:00:16,430 --> 00:00:17,150 ABAC? 6 00:00:17,790 --> 00:00:18,510 ReBAC? 7 00:00:19,070 --> 00:00:19,590 Cool. 8 00:00:20,530 --> 00:00:21,910 Increasingly dropping numbers of hands. 9 00:00:21,910 --> 00:00:22,950 That's kind of what I expected. 10 00:00:22,950 --> 00:00:25,570 I think we've got about 10% people here who know ReBAC. 11 00:00:25,570 --> 00:00:29,370 So we're going to dive in, and we're going to go a little bit deep dive into how ReBAC works. 12 00:00:29,370 --> 00:00:32,250 Now normally, this is a 45 minute to one hour conversation. 13 00:00:32,530 --> 00:00:37,030 So, excuse me if I skip over some bits, but please come and ask me questions afterwards. 14 00:00:37,030 --> 00:00:47,790 But we're going to go a little bit deep on how the data actually gets stored, so that we as developers understand how ReBAC was going to help us, and how the relationship-based access control actually works, or may not work for you. 15 00:00:47,790 --> 00:00:49,110 It's not always the right solution. 16 00:00:49,530 --> 00:00:50,410 But who am I? 17 00:00:50,550 --> 00:00:54,670 I'm a guy who develops slides that have really bad contrast on LED screens. 18 00:00:54,830 --> 00:00:58,070 Also, I've been a software engineer for too many years. 19 00:00:58,110 --> 00:00:59,630 I used to put the number up there. 20 00:00:59,650 --> 00:01:01,750 It made me feel old, so now I just do a sentence. 21 00:01:01,750 --> 00:01:03,050 You can do the maths in your head. 22 00:01:03,050 --> 00:01:06,130 I love working with developer and open source communities. 23 00:01:06,130 --> 00:01:07,950 I've been doing that for about 20 years. 24 00:01:08,030 --> 00:01:10,730 I'm really passionate about security and privacy. 25 00:01:10,810 --> 00:01:13,150 If you want to talk to me about any of those things, those are my jam. 26 00:01:13,150 --> 00:01:14,350 Come talk to me afterwards. 27 00:01:14,790 --> 00:01:21,130 I'm currently working as a developer advocate for a company called ArcJet, hence the branding across my chest here. 28 00:01:21,130 --> 00:01:24,790 We're a middleware security solution for your web applications. 29 00:01:24,810 --> 00:01:29,070 If you are writing any kind of web application at all, check out arcjet.com and just plug it in. 30 00:01:29,070 --> 00:01:29,710 It's free. 31 00:01:29,710 --> 00:01:30,250 Give it a try. 32 00:01:30,250 --> 00:01:31,750 We'd love to hear what you think about it. 33 00:01:31,750 --> 00:01:37,030 If you want to contact me, I've got the X logo on there, although I still like to call them Twitter. 34 00:01:37,070 --> 00:01:48,190 I feel some ways about an organization whose community does not accept certain people's desire to change their identity, so I will not allow Twitter to change their identity either. 35 00:01:48,190 --> 00:01:50,570 My Twitter handle is at BenDekarai. 36 00:01:50,570 --> 00:01:51,810 My DMs are open. 37 00:01:51,810 --> 00:01:54,150 Contact me, if you like. 38 00:01:54,150 --> 00:01:55,470 It's not an instruction. 39 00:01:55,670 --> 00:01:56,950 It's an offer. 40 00:01:57,290 --> 00:01:58,130 Let's get into it. 41 00:01:58,130 --> 00:01:59,330 Access Control 101. 42 00:01:59,330 --> 00:02:00,790 Basics and understandings thereof. 43 00:02:00,790 --> 00:02:05,470 First thing we're going to have a look at is the caricatures we're going to be looking at. 44 00:02:05,510 --> 00:02:07,910 Whenever it comes to access control, the dog wants the bone. 45 00:02:08,270 --> 00:02:11,890 We're going to look at ways that we can stop or allow the dog from accessing the bone. 46 00:02:11,890 --> 00:02:14,690 First one is going to be using RBAC, role-based access control. 47 00:02:14,810 --> 00:02:19,010 It's probably one of the simplest access control mechanisms, so we'll skip through this very quickly. 48 00:02:19,010 --> 00:02:20,670 Basically, we have a number of roles. 49 00:02:20,690 --> 00:02:23,270 You've got an admin, you've got a manager, employee, and a guest. 50 00:02:23,350 --> 00:02:25,410 In our case, our dog, this is Shadow. 51 00:02:25,750 --> 00:02:27,330 Shadow has a blue hat on. 52 00:02:27,330 --> 00:02:28,770 Blue hats are employees. 53 00:02:28,770 --> 00:02:34,750 And the door is locked to all, but the admins, managers, and employees, we don't want guest dogs getting to the bones. 54 00:02:34,750 --> 00:02:41,970 Only employee, manager, and admin dogs, my analogies fall apart a little bit sometimes, are going to get access to the bones. 55 00:02:41,970 --> 00:02:45,010 So because Shadow has access, the door opens. 56 00:02:45,150 --> 00:02:46,130 Role-based access control. 57 00:02:46,130 --> 00:02:47,010 Nice and simple. 58 00:02:47,790 --> 00:02:48,510 Next one. 59 00:02:48,830 --> 00:02:50,590 Attribute-based access control. 60 00:02:50,590 --> 00:02:56,950 This is kind of like role-based, because you could say, well, a role is an attribute of a person, but attribute puts so many more layers on top of this. 61 00:02:56,950 --> 00:02:59,310 So we've got four attributes here of the dog. 62 00:02:59,310 --> 00:03:00,190 This is Min. 63 00:03:00,190 --> 00:03:02,790 This is a white Siberian husky. 64 00:03:02,790 --> 00:03:04,470 These are actual real dogs in my life. 65 00:03:04,470 --> 00:03:06,390 I like to relay them into my talks. 66 00:03:06,590 --> 00:03:07,850 There are four characteristics. 67 00:03:07,850 --> 00:03:09,870 Service dog, good boy, loyal, and fierce. 68 00:03:09,870 --> 00:03:14,370 I can tell you, while Shadow is a service dog, Min will never be a service dog. 69 00:03:14,370 --> 00:03:18,810 If you've ever seen one of those dogs that just cannot control itself because it's always so bloody happy, that's Min. 70 00:03:18,810 --> 00:03:20,830 So she will never ever be a service dog. 71 00:03:20,830 --> 00:03:24,210 But she is usually a good boy or loyal. 72 00:03:24,210 --> 00:03:25,390 She is not fierce. 73 00:03:25,390 --> 00:03:31,410 We've decided in this case that we're going to make her a loyal dog, and the door will open if you are a good boy or a loyal dog. 74 00:03:31,550 --> 00:03:34,590 Now, as an aside, I go on tangents occasionally. 75 00:03:34,710 --> 00:03:38,430 You might be asking yourself, but why doesn't the service dog get a bone? 76 00:03:38,430 --> 00:03:39,770 Because a service dog is good, right? 77 00:03:39,770 --> 00:03:41,890 Service dogs deserve bones. 78 00:03:41,990 --> 00:03:43,270 Does anybody agree with that? 79 00:03:43,750 --> 00:03:44,590 Nobody agrees with that? 80 00:03:44,590 --> 00:03:45,630 You all hate service dogs. 81 00:03:45,630 --> 00:03:46,830 That's what I'm learning about you lot. 82 00:03:46,830 --> 00:03:47,410 Jesus. 83 00:03:47,670 --> 00:03:48,690 Rough crowd. 84 00:03:49,270 --> 00:03:50,530 No, service dogs are working. 85 00:03:50,530 --> 00:03:51,510 They don't get to eat. 86 00:03:51,850 --> 00:03:56,370 But we're going to layer an attribute on top of this, because you could say, well, that's just a role, right? 87 00:03:56,370 --> 00:03:58,790 The attribute here we're going to put in is time. 88 00:03:58,790 --> 00:04:00,090 Who does have a dog? 89 00:04:01,410 --> 00:04:02,190 Wrong audience. 90 00:04:02,190 --> 00:04:03,290 Who has cats? 91 00:04:04,070 --> 00:04:06,490 Okay, let's pretend your cat likes eating bones. 92 00:04:07,390 --> 00:04:09,130 Or for those of you who have dogs. 93 00:04:09,430 --> 00:04:13,650 Who lets their dog sleep in their bedroom with them at night? 94 00:04:13,650 --> 00:04:17,810 Who would like the sound of a crunching bone at 3 a.m.? 95 00:04:17,810 --> 00:04:22,890 No, I certainly don't like the sound of a crunching bone at 3 a.m., so if it's outside of 9 p.m. 96 00:04:22,890 --> 00:04:24,610 to 9 a.m., no bone for you. 97 00:04:24,670 --> 00:04:26,990 So, sadly, men get no bone. 98 00:04:28,150 --> 00:04:30,470 But there are plenty of other things we can do attributes on. 99 00:04:30,470 --> 00:04:36,630 We've got actual identity, physical location, network location, the time, the weather, whether or not you're authenticated to a system. 100 00:04:36,630 --> 00:04:41,750 There are lots of things you can layer on top of this as an attribute of whether or not somebody should get access to a resource. 101 00:04:42,810 --> 00:04:49,430 So, a bit more complexity, a bit more flexibility about how we can control our resources, which brings us on to relationship-based access control. 102 00:04:49,430 --> 00:04:53,330 This changes the paradigm quite significantly as I lose my balance. 103 00:04:53,790 --> 00:04:57,810 So, this dog doesn't actually have a name. 104 00:04:57,810 --> 00:04:59,210 Who here had a dog? 105 00:04:59,550 --> 00:05:00,610 What was your dog's name? 106 00:05:00,610 --> 00:05:00,990 Liam. 107 00:05:01,010 --> 00:05:02,130 This is Liam. 108 00:05:02,130 --> 00:05:02,870 Thank you. 109 00:05:02,870 --> 00:05:04,550 Liam is actually a dog. 110 00:05:04,550 --> 00:05:06,190 Dali designed Liam. 111 00:05:06,230 --> 00:05:09,830 I thought it came out a little bit like a cat, but that's what we're going with. 112 00:05:09,830 --> 00:05:12,330 So, Liam has an owner. 113 00:05:12,530 --> 00:05:13,810 You are the mad scientist. 114 00:05:13,810 --> 00:05:14,570 Congratulations. 115 00:05:14,970 --> 00:05:16,650 So, Liam's owner is a mad scientist. 116 00:05:16,650 --> 00:05:19,230 The mad scientist is friends with a farmer. 117 00:05:19,230 --> 00:05:23,710 The farmer has a whole lot of sheep, and for the vegetarians in the audience, I apologize, but sheep have bones. 118 00:05:26,130 --> 00:05:27,070 Ten minutes? 119 00:05:28,110 --> 00:05:29,250 Oh, I need to stay back. 120 00:05:29,250 --> 00:05:32,370 This is not good for me because, A, I'm going to fall off the back of the stage. 121 00:05:32,450 --> 00:05:33,230 Not too far. 122 00:05:33,230 --> 00:05:33,590 Okay. 123 00:05:33,590 --> 00:05:34,510 Just right here. 124 00:05:34,510 --> 00:05:35,010 Okay. 125 00:05:35,330 --> 00:05:38,070 The guy who likes to roam may no longer roam. 126 00:05:38,150 --> 00:05:38,910 That's okay. 127 00:05:39,530 --> 00:05:43,350 So, we have this chain of relationships, as you can see. 128 00:05:43,350 --> 00:05:50,350 So, we can see here that Liam may or may not have access to the bone based on the rules that you can see. 129 00:05:50,650 --> 00:05:51,850 Now I'm getting feedback. 130 00:05:51,950 --> 00:05:53,930 Based on the rules you can see on the door there. 131 00:05:54,910 --> 00:05:56,870 Sorry, let's just zoom in a little bit. 132 00:05:56,870 --> 00:05:58,670 The rules you can see on the door there. 133 00:05:59,130 --> 00:06:03,890 So, with relationship-based access control, we don't actually have a concept of users anymore. 134 00:06:03,890 --> 00:06:10,770 We just have a concept of entities and relationships. 135 00:06:15,470 --> 00:06:16,370 Entities and relationships. 136 00:06:16,370 --> 00:06:17,910 I'll keep going unless they actually stop me. 137 00:06:17,910 --> 00:06:19,890 Or unless too many people in the audience cringe. 138 00:06:20,050 --> 00:06:21,050 It appears to be good again. 139 00:06:21,050 --> 00:06:22,230 So, here we've got an action. 140 00:06:22,230 --> 00:06:24,490 Can the action eat be completed on the bone? 141 00:06:25,590 --> 00:06:27,930 Note that we're looking here at what can be done to the bone. 142 00:06:27,930 --> 00:06:31,070 We're not looking at what Shadow or Liam can do. 143 00:06:31,450 --> 00:06:33,010 We're looking at what can be done to the bone. 144 00:06:33,010 --> 00:06:34,570 What actions can be taking place. 145 00:06:34,850 --> 00:06:41,730 If it's the animal owner or the friend of the owner of an animal, or the pet of a friend of the owner of the animal, they can eat the bone. 146 00:06:42,410 --> 00:06:48,330 Technically, I suppose you could argue, no, I probably wouldn't want the owner of the bone, the sheep, to be eating the bone. 147 00:06:48,330 --> 00:06:49,650 That would be a little bit weird. 148 00:06:49,970 --> 00:06:55,790 But you can see we just find here a set of relationships that allow us to decide whether or not the bone can be accessed by the dog. 149 00:06:56,090 --> 00:07:03,050 And because through those green lines there, which are really terrible in this background, you can see that the flow does actually go all the way through. 150 00:07:03,410 --> 00:07:04,370 Liam gets a bone. 151 00:07:04,470 --> 00:07:05,550 Good for Liam. 152 00:07:05,550 --> 00:07:06,770 So, the door opens. 153 00:07:07,310 --> 00:07:12,990 Now, say one day the farmer and the mad scientist break friends. 154 00:07:13,030 --> 00:07:14,490 They're no longer friends with each other. 155 00:07:14,490 --> 00:07:15,830 Suddenly, that relationship is broken. 156 00:07:15,830 --> 00:07:17,370 Now, nothing has changed about the bone. 157 00:07:17,370 --> 00:07:18,970 And nothing has changed about Liam. 158 00:07:18,970 --> 00:07:20,630 But the relationship is broken. 159 00:07:20,630 --> 00:07:23,390 Therefore, the friend component of that rule there breaks. 160 00:07:23,390 --> 00:07:27,530 So, the only rule that allowed Liam to get access to that bone is now broken. 161 00:07:27,530 --> 00:07:28,550 And the door shuts. 162 00:07:29,110 --> 00:07:31,630 So, that's what a relationship-based access control is about. 163 00:07:31,630 --> 00:07:35,830 It's not so much about defining what somebody or some user can do. 164 00:07:35,830 --> 00:07:42,930 It's about what actions can be performed on a resource based on a set of rules that relates lots of resources together. 165 00:07:43,070 --> 00:07:44,090 Does that make sense? 166 00:07:44,510 --> 00:07:45,230 Cool. 167 00:07:45,970 --> 00:07:51,590 So, under the hood, who here is familiar with the Entity Attribute Value model of designing? 168 00:07:51,610 --> 00:08:04,810 So, if you've ever done any kind of content management systems or anything like that where you've got an undefined, at the beginning of your project, you have an undefined number of entities, you want a way to be able to create new entities in your system without having to do a database deployment because they are nasty. 169 00:08:04,830 --> 00:08:06,470 Especially when you have a lot of data. 170 00:08:06,650 --> 00:08:16,550 So, the Entity Attribute Value model of data storage basically says you have a table that defines entities and you have another table that defines the attributes and values for that entity. 171 00:08:16,590 --> 00:08:19,810 So, if you want to add another entity, it's just another row in a table. 172 00:08:19,870 --> 00:08:20,710 Nice and simple. 173 00:08:21,030 --> 00:08:23,050 Let's have a quick look at how that works. 174 00:08:23,050 --> 00:08:24,690 So, we've got a user and an article. 175 00:08:24,690 --> 00:08:28,190 So, we're going to be looking at a blog post system, for example. 176 00:08:28,270 --> 00:08:32,290 So, we've got a user and an article, and on this right-hand side here, we've got a whole jumbled load of mess. 177 00:08:32,290 --> 00:08:34,910 But you can see that we've got the Entity ID, the second column. 178 00:08:34,910 --> 00:08:40,610 So, the first, second, and the last two rows in the attribute table belong to a user. 179 00:08:41,210 --> 00:08:48,490 And because the second column has number twos in it, the third and fourth rows belong to an article. 180 00:08:48,530 --> 00:08:52,630 So, you can see the user's username is Robin, and the user's password is Password. 181 00:08:52,750 --> 00:08:55,150 Down there, we have username Morgan and password. 182 00:08:55,990 --> 00:08:59,110 For some reason, they like using JSON Web Tokens for their passwords. 183 00:08:59,110 --> 00:09:00,670 But that's their password. 184 00:09:01,350 --> 00:09:04,910 And then, the middle two there, you can see that we've got an article, one article. 185 00:09:04,910 --> 00:09:06,450 Instance ID of the article is one. 186 00:09:06,450 --> 00:09:10,150 We've got a title of Rebec for the win, and content is CanHasFGA. 187 00:09:10,610 --> 00:09:12,030 Fine grained access control. 188 00:09:12,630 --> 00:09:27,670 So now, if we want to pull stuff out, we can use a fairly simple-ish join within an SQL table to say, well, pull all these things out, and I can pull out, for example, get me all of the articles that you have. 189 00:09:27,690 --> 00:09:29,770 Give me the title and the content. 190 00:09:29,770 --> 00:09:35,590 Or maybe, rather than getting information about one entity, you could say, give me a list of all the users, and just give me their usernames. 191 00:09:35,670 --> 00:09:46,570 So this table setup basically allows you to get really varied views across the data you have without having to change your database schema, without having to know what that schema looks like to start with. 192 00:09:46,650 --> 00:09:50,570 And you can store arbitrary data in there and pull it out in whichever way you want. 193 00:09:50,770 --> 00:09:53,670 It's complicated and expensive to pull out. 194 00:09:53,790 --> 00:09:57,770 And it's somewhat complicated to set up and use within... 195 00:09:57,770 --> 00:10:01,750 more so than if you had, like, an article table and a user table and a comment table. 196 00:10:01,970 --> 00:10:15,510 So if we wanted to add a comment, for example, we just add an extra row over there, and then we can add some extra columns here saying, okay, so we've now got this entity ID3, instance ID1, so this is comment number 1, the article ID is number 1, author is Sam, 197 00:10:15,510 --> 00:10:17,590 comment was first, and here's the date, Sam. 198 00:10:17,990 --> 00:10:22,990 So without making any database schema change, I've added a whole new entity to the system. 199 00:10:23,870 --> 00:10:30,270 The only reason I tell you about EAV is because this is very similar to the way that Reback is managed under the hood. 200 00:10:30,330 --> 00:10:32,130 So let's have a look at how that works. 201 00:10:32,270 --> 00:10:38,250 We've got entities on the left-hand side, Robin is a user, Acme Co is an organization, and Reback for the win is an article. 202 00:10:39,730 --> 00:10:41,550 And down here we have some relationships. 203 00:10:41,750 --> 00:10:51,410 So we're now looking at just subject ID, and I apologize for the color scheme, we've got a relationship ID, which is just arbitrary for this table, we've got a subject entity ID and an object entity ID. 204 00:10:51,410 --> 00:10:53,750 So how does a subject relate to an entity? 205 00:10:53,750 --> 00:10:58,230 A subject is an entity, it's just the primary entity within a relationship. 206 00:10:58,270 --> 00:11:05,170 So we're saying subject 1, the user, entity ID 3, the article, relationship type is owner. 207 00:11:05,510 --> 00:11:09,150 Therefore we know that Robin is the owner of the Reback for the win article. 208 00:11:10,550 --> 00:11:16,550 We can then add in that Robin, user 1, is a member of organization Acme Co. 209 00:11:17,450 --> 00:11:23,510 And we can add in that Morgan, user 4, is a member of the organization Acme Co. 210 00:11:23,510 --> 00:11:24,070 as well. 211 00:11:24,270 --> 00:11:28,150 So we now know that both Robin and Morgan are members of Acme Co. 212 00:11:28,150 --> 00:11:33,570 Now we have another one here where we say the organization is a viewer of the Reback article. 213 00:11:33,610 --> 00:11:35,850 But organizations can't view things. 214 00:11:36,430 --> 00:11:40,130 So we're able to extend that slightly and put an extra entity relation on there. 215 00:11:40,130 --> 00:11:42,230 How do the entities relate to each other? 216 00:11:42,310 --> 00:11:44,570 Through this member relation. 217 00:11:44,910 --> 00:11:52,350 So if we dial that back, if we see here we've got member in the middle two rows here, we've got a relationship of members. 218 00:11:52,350 --> 00:12:01,710 So what we now know is that members of organization 2 can view the Reback for the win article. 219 00:12:02,150 --> 00:12:09,010 So now if I add another member into that organization, they automatically inherit that because the relationship exists already. 220 00:12:09,570 --> 00:12:10,390 Does that make sense? 221 00:12:11,070 --> 00:12:12,870 This is where it gets a little bit murky. 222 00:12:13,170 --> 00:12:14,230 You don't need to know all of this. 223 00:12:14,230 --> 00:12:19,210 I just want you to understand how the data sits in there so that when we start pulling it out, you can see what's going on. 224 00:12:20,230 --> 00:12:24,470 So, the other thing we can do is define permissions on all of these. 225 00:12:24,470 --> 00:12:27,250 So we've got the relationships, but what does that actually mean they can do? 226 00:12:27,410 --> 00:12:33,230 So permission ID 1, again arbitrarily for the permissions table, relates to relationship ID 1. 227 00:12:33,230 --> 00:12:37,410 So relationship ID 1 was Robin is the owner of the Reback article. 228 00:12:37,850 --> 00:12:41,030 So we're saying here, well, one of the permissions is read. 229 00:12:42,750 --> 00:12:48,130 Relationship ID 1 is also that Robin is the owner of the article. 230 00:12:48,670 --> 00:12:50,090 Robin also has write access. 231 00:12:51,010 --> 00:12:58,430 And then we have relationship ID 4, which is this inferred down here, members of organization 2. 232 00:12:58,870 --> 00:13:01,970 Members of organization 2 have read permissions. 233 00:13:02,990 --> 00:13:07,570 So even over here, we've got relationship types and entities like viewer is just a label. 234 00:13:07,630 --> 00:13:09,390 It doesn't mean anything to the system. 235 00:13:09,410 --> 00:13:19,410 But when you look at that, you see what that means is the permission for viewer for any member of organization 2 has read access on article 1. 236 00:13:20,790 --> 00:13:23,490 So there's one extra table here compared to EAV. 237 00:13:23,490 --> 00:13:31,650 But this allows us to define a multitude of relationships and permissions and how they relate to each other and to other entities. 238 00:13:32,150 --> 00:13:34,590 And more importantly, they allow you to chain those entities. 239 00:13:34,590 --> 00:13:39,290 Remember how we went from Liam to the mad scientist to the farmer to the sheep to the bone? 240 00:13:39,430 --> 00:13:40,870 It's not just one-to-one. 241 00:13:40,870 --> 00:13:45,690 You can define these huge big chains, and if any part of that chain gets broken, then the relationship breaks. 242 00:13:46,870 --> 00:13:49,030 So querying the Reback model. 243 00:13:49,030 --> 00:13:50,110 How does this work? 244 00:13:50,330 --> 00:13:53,970 Let's say we come in here and we want to find out who can read. 245 00:13:54,370 --> 00:13:57,190 We can see here that the read... 246 00:13:57,190 --> 00:13:58,410 Sorry, who can write. 247 00:13:58,410 --> 00:14:00,110 The permission ID there is 2. 248 00:14:01,210 --> 00:14:03,150 So if we... 249 00:14:09,080 --> 00:14:11,420 I think I've got the wrong one highlighted there. 250 00:14:11,420 --> 00:14:14,400 I want to find out who can write to Reback article 2. 251 00:14:14,840 --> 00:14:17,640 So first thing we do is we look at the... 252 00:14:17,640 --> 00:14:19,500 and the highlighting isn't working so great here. 253 00:14:19,500 --> 00:14:22,520 The object entity ID 3 there is the Reback article. 254 00:14:22,520 --> 00:14:26,280 So we say, okay, within the relationships, let's find out everything we know about the article. 255 00:14:26,460 --> 00:14:34,760 And we can see here that the fourth one there can be excluded straight away because the relationship ID number 4 is not in the permissions table. 256 00:14:35,200 --> 00:14:38,880 However, relationship ID 1 is in that table. 257 00:14:38,880 --> 00:14:47,700 That is related to the object identity 2, so we can pull out that the user Robin has write access to the article. 258 00:14:47,880 --> 00:14:50,460 So you can look at things in other directions as well. 259 00:14:51,080 --> 00:14:55,940 And then further to that, you could even say, okay, well, tell me everything about the article, rather than starting from permissions. 260 00:14:55,940 --> 00:14:57,360 We look at article number 3. 261 00:14:57,620 --> 00:15:01,800 We know that Robin is the owner of that article already. 262 00:15:02,700 --> 00:15:05,660 And if we look at the viewer here, we can then... 263 00:15:05,660 --> 00:15:11,840 and this is what I was talking about before, how member gets extrapolated to infer relationship status. 264 00:15:11,840 --> 00:15:18,600 So we can see that the member here of organization 2 has access to the article. 265 00:15:18,780 --> 00:15:25,160 And if we then fold those in, you see how before this one here was highlighted, what we're now doing is saying the subject is now the object. 266 00:15:25,160 --> 00:15:33,080 So where the object is now entity ID 2, where also the relationship type is member, that's where this one basically gets folded out. 267 00:15:33,140 --> 00:15:35,780 So that's probably one of the most complicated lookups. 268 00:15:35,780 --> 00:15:41,520 It's really deep, diving straight into the depths of the Reback schema. 269 00:15:41,560 --> 00:15:52,060 But essentially what we're doing there at that point is we're saying this permission or this relationship here doesn't make sense from a permission sense, because you don't give permissions to inanimate objects like organizations necessarily. 270 00:15:52,060 --> 00:15:53,100 I mean, you do. 271 00:15:53,100 --> 00:15:55,340 But that doesn't really help an end user. 272 00:15:55,340 --> 00:16:01,520 How do we then unfold that and then extrapolate that to refer to the actual user entities? 273 00:16:02,040 --> 00:16:06,380 And this is where it gets complicated, because Reback, as I said, doesn't have a concept of a user necessarily. 274 00:16:06,420 --> 00:16:12,200 You could actually ask Reback what is the relationship between this organization and that network. 275 00:16:12,500 --> 00:16:13,840 Neither of them really do anything. 276 00:16:13,840 --> 00:16:14,780 They're system entities. 277 00:16:14,780 --> 00:16:15,940 They're not user entities. 278 00:16:15,940 --> 00:16:17,400 But they still have relationships. 279 00:16:17,400 --> 00:16:19,740 So it's powerful but also complex. 280 00:16:22,880 --> 00:16:24,200 Implementation details. 281 00:16:26,180 --> 00:16:32,600 Let's have a think about how we might do something in code, which is probably the way most of us do for more complicated business logic like this. 282 00:16:32,600 --> 00:16:48,380 So if we want to allow editing an article, if a user is an admin or an editor, if an editor is allowed to edit this particular article, if the article is sensitive, then we also want to make sure that the person is on site, and we want to make sure that they're doing it during office hours. 283 00:16:49,340 --> 00:16:54,140 Seems like a fairly robust kind of setup that you might have in a large organization. 284 00:16:54,620 --> 00:16:55,540 So, if. 285 00:16:55,980 --> 00:16:58,400 If the user is admin or if the user is editor. 286 00:16:58,700 --> 00:16:59,280 Cool. 287 00:16:59,420 --> 00:17:03,040 So we know what role the user has. 288 00:17:03,620 --> 00:17:08,360 Also, if the user is an editor and the list of document editors contains the current user. 289 00:17:08,500 --> 00:17:10,820 So we don't want any editor to be able to edit this. 290 00:17:11,180 --> 00:17:15,260 Only if the list of editors for this particular article includes the current user. 291 00:17:15,560 --> 00:17:17,240 So we can compound those two together. 292 00:17:17,920 --> 00:17:21,740 Then also we want to say, well, if the document isn't sensitive, then we can carry on. 293 00:17:21,740 --> 00:17:26,140 Otherwise, we're going to check to see if the user's location is on premises. 294 00:17:26,560 --> 00:17:30,220 Or if the user's location is currently in office hours. 295 00:17:30,220 --> 00:17:35,380 And I say the user's location because in a world like today, who knows when it's 9 to 5 for somebody. 296 00:17:35,460 --> 00:17:45,720 So as long as it's within the location they're in, it's working hours, and they're on premises, or the document is not sensitive, and they meet the user requirements, they're going to get access to this document. 297 00:17:46,840 --> 00:17:49,660 Imagine if you had to come back and change those rules three months later. 298 00:17:51,800 --> 00:17:58,860 So, instead what we're going to do is we're going to define entities within our relationship-based access management tool of choice. 299 00:17:59,020 --> 00:18:00,580 We're going to define a document. 300 00:18:00,760 --> 00:18:02,500 The document has an owner and an editor. 301 00:18:02,500 --> 00:18:09,040 The owner is a user, and the editor is a member of an organization with the member type editor. 302 00:18:09,240 --> 00:18:12,180 So you can have different types of people within groups. 303 00:18:12,820 --> 00:18:16,360 And then we're going to have a sensitive document, so that's the definition of a normal document. 304 00:18:16,420 --> 00:18:19,080 The sensitive document is going to extend document. 305 00:18:19,720 --> 00:18:28,340 It's also going to have an edit action on it that says, if it's within working hours, and it's a sensitive document, it's the document owner who's trying to do this action. 306 00:18:28,340 --> 00:18:32,040 Because remember, we're defining actions on an entity and who's allowed to perform it. 307 00:18:32,240 --> 00:18:35,180 So, can edit be done on a sensitive document? 308 00:18:35,180 --> 00:18:40,120 Yes, you can, if you are the document owner, and you are the document owner and you're on-premises. 309 00:18:41,100 --> 00:18:43,320 Or if you're an editor and you're on-premises. 310 00:18:44,020 --> 00:18:49,500 So this gets tied into your relationship-based access model, schema, and permission systems. 311 00:18:49,640 --> 00:18:52,980 So now your code can change from this to that. 312 00:18:54,480 --> 00:19:03,220 And now your business logic isn't restricted or it doesn't include the permissions check, because there's no real reason for that to be there. 313 00:19:03,220 --> 00:19:09,160 The permission for who should access an entity within your system should not be dependent on what's in the business logic. 314 00:19:09,160 --> 00:19:11,360 There's a fast and firm rule for that. 315 00:19:11,380 --> 00:19:13,080 This gives you two benefits. 316 00:19:13,080 --> 00:19:17,520 One from a clean code, easy-to-read perspective, that is much easier to read. 317 00:19:17,520 --> 00:19:18,880 You know exactly what's going to happen. 318 00:19:18,880 --> 00:19:20,400 You don't have to think about it. 319 00:19:20,400 --> 00:19:32,780 Also, from a permissions and access control management perspective, your security team can manage the rules and the schema separately from your development team and it puts the responsibility in the right place. 320 00:19:34,740 --> 00:19:36,560 So, demo time. 321 00:19:36,800 --> 00:19:37,620 This is the fun part. 322 00:19:37,900 --> 00:19:40,400 The first part was all about DOGS. 323 00:19:40,400 --> 00:19:44,960 Then we went to document access management, which is important, but boring. 324 00:19:44,960 --> 00:19:46,360 So we're going to go back to DOGS. 325 00:19:46,800 --> 00:19:49,540 I have tried a number of products. 326 00:19:49,540 --> 00:19:51,660 There are all these products up on the screen here. 327 00:19:51,660 --> 00:19:52,520 There are many more. 328 00:19:52,520 --> 00:19:55,800 These are relationship-based access management tools. 329 00:19:55,840 --> 00:19:57,300 Some of them are open source and free to use. 330 00:19:57,300 --> 00:19:58,380 Some of them are paid for. 331 00:19:58,380 --> 00:20:00,760 I'm going to be using Permify in this demo. 332 00:20:02,580 --> 00:20:06,040 Am I going to annoy anybody by switching over to this on the AV team? 333 00:20:06,040 --> 00:20:08,840 They didn't mic check me on this one, so I apologise in advance. 334 00:20:08,840 --> 00:20:10,420 But I'm going to need both hands to type. 335 00:20:11,280 --> 00:20:13,240 I'm just going to stop screen sharing. 336 00:20:15,220 --> 00:20:19,700 Let's jump over here and we're going to have a first look at Postman. 337 00:20:20,440 --> 00:20:22,200 Let's make this a bit bigger. 338 00:20:23,040 --> 00:20:24,740 Can you all read that okay? 339 00:20:24,940 --> 00:20:25,740 Excellent. 340 00:20:26,400 --> 00:20:28,860 Let's have a look from the beginning. 341 00:20:28,860 --> 00:20:30,600 We're going to create a tenant. 342 00:20:30,600 --> 00:20:42,700 In fact, the first thing I'm going to do, because like all developers, I decided to test this before I started the talk, so I'm just going to restart Permify in the background, so we're starting from a bank slate. 343 00:20:43,160 --> 00:20:46,940 Now over here, what we're going to do is we're going to create a new tenant. 344 00:20:46,940 --> 00:20:57,300 So Permify allows you to have multiple tenants in your system, so you can sandbox or isolate certain areas of your organisation or even certain organisations within a larger system. 345 00:20:58,040 --> 00:21:03,680 We're going to create a tenant over here called Dog & Bone. 346 00:21:04,240 --> 00:21:11,300 If I hit send on that, we'll see down here that we get a positive response back, a 200, and we've got our tenant. 347 00:21:11,300 --> 00:21:13,340 The next thing I'm going to do is create the schema. 348 00:21:13,440 --> 00:21:18,400 Now this schema for some reason, Permify wants it in a single string. 349 00:21:18,820 --> 00:21:22,380 So to make it easier, I have it over here. 350 00:21:24,540 --> 00:21:26,500 This is very similar to what we saw in the slides. 351 00:21:26,500 --> 00:21:28,360 Basically we've got a definition of a dog. 352 00:21:28,560 --> 00:21:30,480 A dog has an owner, which is a person. 353 00:21:30,680 --> 00:21:31,540 We've got a sheep. 354 00:21:31,540 --> 00:21:33,640 A sheep has an owner that is also a person. 355 00:21:33,780 --> 00:21:36,480 A sheep also has a bone, which is an entity type bone. 356 00:21:36,800 --> 00:21:37,880 We've got a person. 357 00:21:37,960 --> 00:21:40,280 A person can have a friend, would be another person. 358 00:21:40,280 --> 00:21:45,940 A person can also have sheep and a person can have dogs, so we've got bi-directional rules here. 359 00:21:45,940 --> 00:21:48,740 And then we've got a relationship between the bone. 360 00:21:48,740 --> 00:21:50,640 The bone has an owner, and that's a sheep. 361 00:21:50,640 --> 00:21:51,560 And then we've got a permission. 362 00:21:51,560 --> 00:21:54,360 Can the owner's friend's dog eat? 363 00:21:55,180 --> 00:22:00,120 And eat is true if that comes out as a relationship that exists. 364 00:22:01,900 --> 00:22:07,520 So let's submit that through, and we should find that that has now worked. 365 00:22:07,520 --> 00:22:09,820 If I now create some relationships... 366 00:22:12,180 --> 00:22:13,600 Come on, get bigger. 367 00:22:16,100 --> 00:22:16,980 Where's the handle? 368 00:22:17,560 --> 00:22:18,480 It's always hiding. 369 00:22:21,880 --> 00:22:23,940 I'll just scroll through this little by little. 370 00:22:24,200 --> 00:22:28,140 So, actually, if I make this slightly smaller, is that still readable at the back? 371 00:22:28,860 --> 00:22:29,740 Yep, okay. 372 00:22:29,840 --> 00:22:31,260 So at least we can see a bit more at a time. 373 00:22:31,260 --> 00:22:34,160 So we can see here we've got a relationship between a subject and an entity. 374 00:22:34,340 --> 00:22:38,540 Remember I said a subject is also an entity, but it's just the primary entity in a relationship. 375 00:22:38,540 --> 00:22:39,960 Is the microphone cutting out? 376 00:22:39,960 --> 00:22:40,920 A little? 377 00:22:41,240 --> 00:22:44,560 I'll go back to this one, because I don't need to type as much now. 378 00:22:44,560 --> 00:22:48,700 So we can see that the subject, mad scientist, is the owner of Shadow the dog. 379 00:22:48,940 --> 00:22:53,020 We can see here that Shadow the dog is also a dog belonging to the scientist. 380 00:22:53,400 --> 00:22:55,980 And then we've got the farmer has Dolly the sheep. 381 00:22:56,220 --> 00:22:58,040 The sheep belongs to the farmer. 382 00:22:58,220 --> 00:23:06,020 We've got Dolly is a sheep to the femur, and the femur is a bone to the sheep. 383 00:23:06,020 --> 00:23:08,500 So we've got these relationships built up now. 384 00:23:08,860 --> 00:23:21,220 So if I come through and I ask what friends does the scientist have, because we haven't defined those relationships yet, if I execute that, we'll see down here that the result is nothing. 385 00:23:21,220 --> 00:23:23,180 He has no friends. 386 00:23:23,180 --> 00:23:24,680 He's a sad scientist. 387 00:23:25,100 --> 00:23:28,140 As it happens, the farmer is also a sad farmer. 388 00:23:28,260 --> 00:23:31,640 Although the farmer has sheep, so a little bit happier, probably. 389 00:23:32,160 --> 00:23:33,680 I know, sheep are better than dogs? 390 00:23:33,680 --> 00:23:35,180 I digress yet again. 391 00:23:35,260 --> 00:23:36,840 So can shadow eat the bone? 392 00:23:37,000 --> 00:23:37,800 What do we reckon? 393 00:23:39,460 --> 00:23:41,720 No, so if I hit that, it comes through. 394 00:23:41,900 --> 00:23:42,840 Result denied. 395 00:23:43,240 --> 00:23:51,260 So it's a very low energy kind of reaction that I'm getting. 396 00:23:51,260 --> 00:23:53,380 But it's also a very low energy kind of output. 397 00:23:53,400 --> 00:23:57,020 So I thought, I've got these two requests here that I can make. 398 00:23:57,020 --> 00:24:00,260 The first one calls data right. 399 00:24:00,700 --> 00:24:04,460 What I'm going to do is I'm going to say, okay, the mad scientist is now friends with the farmer. 400 00:24:04,640 --> 00:24:06,780 And then I've got another one here, break friends. 401 00:24:06,960 --> 00:24:08,180 It's data delete. 402 00:24:08,180 --> 00:24:11,600 And in here I'm defining the mad scientist is no longer a friend with the farmer. 403 00:24:11,640 --> 00:24:15,040 So to make this a little more exciting, I decided to 404 00:24:19,530 --> 00:24:21,870 show you all my sister's Facebook page. 405 00:24:22,790 --> 00:24:25,210 And also, let's bring this back in over here. 406 00:24:25,830 --> 00:24:27,410 I have a dog and a bone. 407 00:24:27,410 --> 00:24:31,230 Let's just refresh this because it doesn't like having the lid shut on it. 408 00:24:31,870 --> 00:24:34,670 And for some reason, I'm getting an image rendering error. 409 00:24:34,670 --> 00:24:35,550 There we go. 410 00:24:35,710 --> 00:24:37,070 What demos go perfectly. 411 00:24:37,070 --> 00:24:38,670 So, doors closed. 412 00:24:38,670 --> 00:24:39,830 Dog can't get a bone. 413 00:24:39,830 --> 00:24:47,010 So what happens if the farmer makes friends with the scientist? 414 00:24:47,010 --> 00:24:47,870 What do you think? 415 00:24:52,460 --> 00:24:53,940 No, it didn't work. 416 00:24:55,400 --> 00:24:57,060 Did I call the right one there? 417 00:24:57,380 --> 00:24:58,780 Looks like you're offline. 418 00:24:58,800 --> 00:25:00,560 Yeah, but I'm doing everything locally. 419 00:25:00,560 --> 00:25:00,880 So, 420 00:25:06,900 --> 00:25:08,480 did I call the wrong one? 421 00:25:08,680 --> 00:25:10,100 Did I call break friends? 422 00:25:10,360 --> 00:25:12,040 Let's double click on that one. 423 00:25:15,330 --> 00:25:16,470 Darn it. 424 00:25:16,910 --> 00:25:28,550 Well, I will show you that if we come over here and look at friends of mad scientist, we should now have, there we go, the friendship is now in here. 425 00:25:28,550 --> 00:25:33,850 So now if our call can shadow eat the bone, it comes back as still denied. 426 00:25:34,030 --> 00:25:34,590 Okay. 427 00:25:34,590 --> 00:25:36,150 So, this is where the demo fails. 428 00:25:36,150 --> 00:25:38,610 I'm more than happy to work out why the demo failed. 429 00:25:38,610 --> 00:25:44,250 It was probably something to do with keeping my Wi-Fi off at Defcon and closing my laptop lid between testing demos. 430 00:25:44,450 --> 00:25:45,930 But the theory is there. 431 00:25:45,930 --> 00:25:47,950 The results should have come back immediately. 432 00:25:47,950 --> 00:25:50,090 I had a little bit of a cheat in my app. 433 00:25:50,090 --> 00:25:51,710 It was basically polling every second. 434 00:25:51,970 --> 00:25:57,170 But there are plenty of ways of connecting to databases and getting a full-time stream of data back. 435 00:25:57,170 --> 00:26:05,070 So you can get almost like a push notification or an immediate notification of permission changes if that's something you need in your environment. 436 00:26:05,070 --> 00:26:10,610 Most of the time it's probably something you only need every time you make a request to make sure that requests should be honored. 437 00:26:11,770 --> 00:26:25,970 But one of the things that I want to caution is that while this is complicated and exciting and perhaps when it comes to permission systems, dare I say a little bit sexy, I'm not sure, it's not always the right solution. 438 00:26:25,970 --> 00:26:31,730 As I said, there's a lot more computation power required for doing things like checking whether or not a permission should be granted. 439 00:26:31,910 --> 00:26:34,830 Role-based access control is always going to be your easiest. 440 00:26:34,930 --> 00:26:38,270 That's always simply like, is this person an admin, yes or no? 441 00:26:38,610 --> 00:26:44,910 In fact, in some situations, if you think of your home internet router, you don't even have permission systems like, are they logged in, yes or no? 442 00:26:45,030 --> 00:26:46,550 That's technically the simplest. 443 00:26:47,030 --> 00:26:57,810 So work out which level of permissions complexity or the way that your data is modeled and how you want to define whether or not access should be allowed. 444 00:26:57,950 --> 00:27:02,690 Work out what level of complexity you can get to at a minimum while still meeting your requirements. 445 00:27:02,690 --> 00:27:07,590 Because if you go for the full thing straight out, re-back all the way, baby, absolutely it's fun. 446 00:27:07,810 --> 00:27:12,030 You will probably create a situation where your job is now indispensable. 447 00:27:12,050 --> 00:27:15,230 You will not be fired because nobody knows what the hell you did. 448 00:27:15,310 --> 00:27:17,190 But it's not always the right solution. 449 00:27:17,290 --> 00:27:18,650 Pick the right one for you. 450 00:27:18,650 --> 00:27:27,930 If you're currently going through a situation where you want to implement some kind of permission control, more than welcome to come up and talk to me afterwards and tell me a story. 451 00:27:27,930 --> 00:27:32,110 I'll let you know if I've got any clue at all as to what you may or may not consider. 452 00:27:32,470 --> 00:27:39,930 I'm certainly not going to tell you I know your system inside out and can tell you what the answer is, but I'm happy to have a chat and go through that with you. 453 00:27:40,150 --> 00:27:44,610 But I would like to finish by just saying thank you. 454 00:27:44,870 --> 00:27:46,550 If I can even fire my slides. 455 00:27:50,260 --> 00:27:52,040 Let's just get that back up there. 456 00:27:52,140 --> 00:27:55,040 So again, that's my contact details at the top there. 457 00:27:55,540 --> 00:27:59,240 ArcJet are currently running a contest if you want to try our product out. 458 00:27:59,600 --> 00:28:01,380 There's some prizes we're giving away as well. 459 00:28:01,380 --> 00:28:02,580 Challenge.arcjet.com. 460 00:28:02,580 --> 00:28:03,140 Give it a try. 461 00:28:03,140 --> 00:28:03,800 Let us know. 462 00:28:03,800 --> 00:28:12,260 We would really love to know from you how you find the product, how easy it is to use and what we can do to make it easier for you to make your website sit better. 463 00:28:12,700 --> 00:28:14,460 But this talk was about permission systems. 464 00:28:14,460 --> 00:28:15,380 Come talk to me. 465 00:28:15,420 --> 00:28:16,120 Thank you for your time. 466 00:28:16,120 --> 00:28:17,780 Have a great rest of your DEF CON. 467 00:28:23,820 --> 00:28:24,860 DEF CON.