Who here is familiar with access control within web applications in some way or form? About half of you. That's cool. Who knows what RBAC is? ABAC? ReBAC? Cool. Increasingly dropping numbers of hands. That's kind of what I expected. I think we've got about 10% people here who know ReBAC. So we're going to dive in, and we're going to go a little bit deep dive into how ReBAC works. Now normally, this is a 45 minute to one hour conversation. So, excuse me if I skip over some bits, but please come and ask me questions afterwards. 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. It's not always the right solution. But who am I? I'm a guy who develops slides that have really bad contrast on LED screens. Also, I've been a software engineer for too many years. I used to put the number up there. It made me feel old, so now I just do a sentence. You can do the maths in your head. I love working with developer and open source communities. I've been doing that for about 20 years. I'm really passionate about security and privacy. If you want to talk to me about any of those things, those are my jam. Come talk to me afterwards. I'm currently working as a developer advocate for a company called ArcJet, hence the branding across my chest here. We're a middleware security solution for your web applications. If you are writing any kind of web application at all, check out arcjet.com and just plug it in. It's free. Give it a try. We'd love to hear what you think about it. If you want to contact me, I've got the X logo on there, although I still like to call them Twitter. 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. My Twitter handle is at BenDekarai. My DMs are open. Contact me, if you like. It's not an instruction. It's an offer. Let's get into it. Access Control 101. Basics and understandings thereof. First thing we're going to have a look at is the caricatures we're going to be looking at. Whenever it comes to access control, the dog wants the bone. We're going to look at ways that we can stop or allow the dog from accessing the bone. First one is going to be using RBAC, role-based access control. It's probably one of the simplest access control mechanisms, so we'll skip through this very quickly. Basically, we have a number of roles. You've got an admin, you've got a manager, employee, and a guest. In our case, our dog, this is Shadow. Shadow has a blue hat on. Blue hats are employees. And the door is locked to all, but the admins, managers, and employees, we don't want guest dogs getting to the bones. Only employee, manager, and admin dogs, my analogies fall apart a little bit sometimes, are going to get access to the bones. So because Shadow has access, the door opens. Role-based access control. Nice and simple. Next one. Attribute-based access control. 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. So we've got four attributes here of the dog. This is Min. This is a white Siberian husky. These are actual real dogs in my life. I like to relay them into my talks. There are four characteristics. Service dog, good boy, loyal, and fierce. I can tell you, while Shadow is a service dog, Min will never be a service dog. If you've ever seen one of those dogs that just cannot control itself because it's always so bloody happy, that's Min. So she will never ever be a service dog. But she is usually a good boy or loyal. She is not fierce. 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. Now, as an aside, I go on tangents occasionally. You might be asking yourself, but why doesn't the service dog get a bone? Because a service dog is good, right? Service dogs deserve bones. Does anybody agree with that? Nobody agrees with that? You all hate service dogs. That's what I'm learning about you lot. Jesus. Rough crowd. No, service dogs are working. They don't get to eat. But we're going to layer an attribute on top of this, because you could say, well, that's just a role, right? The attribute here we're going to put in is time. Who does have a dog? Wrong audience. Who has cats? Okay, let's pretend your cat likes eating bones. Or for those of you who have dogs. Who lets their dog sleep in their bedroom with them at night? Who would like the sound of a crunching bone at 3 a.m.? 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. to 9 a.m., no bone for you. So, sadly, men get no bone. But there are plenty of other things we can do attributes on. We've got actual identity, physical location, network location, the time, the weather, whether or not you're authenticated to a system. 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. 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. This changes the paradigm quite significantly as I lose my balance. So, this dog doesn't actually have a name. Who here had a dog? What was your dog's name? Liam. This is Liam. Thank you. Liam is actually a dog. Dali designed Liam. I thought it came out a little bit like a cat, but that's what we're going with. So, Liam has an owner. You are the mad scientist. Congratulations. So, Liam's owner is a mad scientist. The mad scientist is friends with a farmer. The farmer has a whole lot of sheep, and for the vegetarians in the audience, I apologize, but sheep have bones. Ten minutes? Oh, I need to stay back. This is not good for me because, A, I'm going to fall off the back of the stage. Not too far. Okay. Just right here. Okay. The guy who likes to roam may no longer roam. That's okay. So, we have this chain of relationships, as you can see. So, we can see here that Liam may or may not have access to the bone based on the rules that you can see. Now I'm getting feedback. Based on the rules you can see on the door there. Sorry, let's just zoom in a little bit. The rules you can see on the door there. So, with relationship-based access control, we don't actually have a concept of users anymore. We just have a concept of entities and relationships. Entities and relationships. I'll keep going unless they actually stop me. Or unless too many people in the audience cringe. It appears to be good again. So, here we've got an action. Can the action eat be completed on the bone? Note that we're looking here at what can be done to the bone. We're not looking at what Shadow or Liam can do. We're looking at what can be done to the bone. What actions can be taking place. 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. Technically, I suppose you could argue, no, I probably wouldn't want the owner of the bone, the sheep, to be eating the bone. That would be a little bit weird. 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. 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. Liam gets a bone. Good for Liam. So, the door opens. Now, say one day the farmer and the mad scientist break friends. They're no longer friends with each other. Suddenly, that relationship is broken. Now, nothing has changed about the bone. And nothing has changed about Liam. But the relationship is broken. Therefore, the friend component of that rule there breaks. So, the only rule that allowed Liam to get access to that bone is now broken. And the door shuts. So, that's what a relationship-based access control is about. It's not so much about defining what somebody or some user can do. It's about what actions can be performed on a resource based on a set of rules that relates lots of resources together. Does that make sense? Cool. So, under the hood, who here is familiar with the Entity Attribute Value model of designing? 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. Especially when you have a lot of data. 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. So, if you want to add another entity, it's just another row in a table. Nice and simple. Let's have a quick look at how that works. So, we've got a user and an article. So, we're going to be looking at a blog post system, for example. 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. But you can see that we've got the Entity ID, the second column. So, the first, second, and the last two rows in the attribute table belong to a user. And because the second column has number twos in it, the third and fourth rows belong to an article. So, you can see the user's username is Robin, and the user's password is Password. Down there, we have username Morgan and password. For some reason, they like using JSON Web Tokens for their passwords. But that's their password. And then, the middle two there, you can see that we've got an article, one article. Instance ID of the article is one. We've got a title of Rebec for the win, and content is CanHasFGA. Fine grained access control. 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. Give me the title and the content. 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. 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. And you can store arbitrary data in there and pull it out in whichever way you want. It's complicated and expensive to pull out. And it's somewhat complicated to set up and use within... more so than if you had, like, an article table and a user table and a comment table. 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, comment was first, and here's the date, Sam. So without making any database schema change, I've added a whole new entity to the system. The only reason I tell you about EAV is because this is very similar to the way that Reback is managed under the hood. So let's have a look at how that works. 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. And down here we have some relationships. 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. So how does a subject relate to an entity? A subject is an entity, it's just the primary entity within a relationship. So we're saying subject 1, the user, entity ID 3, the article, relationship type is owner. Therefore we know that Robin is the owner of the Reback for the win article. We can then add in that Robin, user 1, is a member of organization Acme Co. And we can add in that Morgan, user 4, is a member of the organization Acme Co. as well. So we now know that both Robin and Morgan are members of Acme Co. Now we have another one here where we say the organization is a viewer of the Reback article. But organizations can't view things. So we're able to extend that slightly and put an extra entity relation on there. How do the entities relate to each other? Through this member relation. 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. So what we now know is that members of organization 2 can view the Reback for the win article. So now if I add another member into that organization, they automatically inherit that because the relationship exists already. Does that make sense? This is where it gets a little bit murky. You don't need to know all of this. 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. So, the other thing we can do is define permissions on all of these. So we've got the relationships, but what does that actually mean they can do? So permission ID 1, again arbitrarily for the permissions table, relates to relationship ID 1. So relationship ID 1 was Robin is the owner of the Reback article. So we're saying here, well, one of the permissions is read. Relationship ID 1 is also that Robin is the owner of the article. Robin also has write access. And then we have relationship ID 4, which is this inferred down here, members of organization 2. Members of organization 2 have read permissions. So even over here, we've got relationship types and entities like viewer is just a label. It doesn't mean anything to the system. 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. So there's one extra table here compared to EAV. But this allows us to define a multitude of relationships and permissions and how they relate to each other and to other entities. And more importantly, they allow you to chain those entities. Remember how we went from Liam to the mad scientist to the farmer to the sheep to the bone? It's not just one-to-one. You can define these huge big chains, and if any part of that chain gets broken, then the relationship breaks. So querying the Reback model. How does this work? Let's say we come in here and we want to find out who can read. We can see here that the read... Sorry, who can write. The permission ID there is 2. So if we... I think I've got the wrong one highlighted there. I want to find out who can write to Reback article 2. So first thing we do is we look at the... and the highlighting isn't working so great here. The object entity ID 3 there is the Reback article. So we say, okay, within the relationships, let's find out everything we know about the article. 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. However, relationship ID 1 is in that table. That is related to the object identity 2, so we can pull out that the user Robin has write access to the article. So you can look at things in other directions as well. And then further to that, you could even say, okay, well, tell me everything about the article, rather than starting from permissions. We look at article number 3. We know that Robin is the owner of that article already. And if we look at the viewer here, we can then... and this is what I was talking about before, how member gets extrapolated to infer relationship status. So we can see that the member here of organization 2 has access to the article. 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. 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. So that's probably one of the most complicated lookups. It's really deep, diving straight into the depths of the Reback schema. 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. I mean, you do. But that doesn't really help an end user. How do we then unfold that and then extrapolate that to refer to the actual user entities? And this is where it gets complicated, because Reback, as I said, doesn't have a concept of a user necessarily. You could actually ask Reback what is the relationship between this organization and that network. Neither of them really do anything. They're system entities. They're not user entities. But they still have relationships. So it's powerful but also complex. Implementation details. 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. 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. Seems like a fairly robust kind of setup that you might have in a large organization. So, if. If the user is admin or if the user is editor. Cool. So we know what role the user has. Also, if the user is an editor and the list of document editors contains the current user. So we don't want any editor to be able to edit this. Only if the list of editors for this particular article includes the current user. So we can compound those two together. Then also we want to say, well, if the document isn't sensitive, then we can carry on. Otherwise, we're going to check to see if the user's location is on premises. Or if the user's location is currently in office hours. And I say the user's location because in a world like today, who knows when it's 9 to 5 for somebody. 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. Imagine if you had to come back and change those rules three months later. So, instead what we're going to do is we're going to define entities within our relationship-based access management tool of choice. We're going to define a document. The document has an owner and an editor. The owner is a user, and the editor is a member of an organization with the member type editor. So you can have different types of people within groups. And then we're going to have a sensitive document, so that's the definition of a normal document. The sensitive document is going to extend document. 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. Because remember, we're defining actions on an entity and who's allowed to perform it. So, can edit be done on a sensitive document? Yes, you can, if you are the document owner, and you are the document owner and you're on-premises. Or if you're an editor and you're on-premises. So this gets tied into your relationship-based access model, schema, and permission systems. So now your code can change from this to that. 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. The permission for who should access an entity within your system should not be dependent on what's in the business logic. There's a fast and firm rule for that. This gives you two benefits. One from a clean code, easy-to-read perspective, that is much easier to read. You know exactly what's going to happen. You don't have to think about it. 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. So, demo time. This is the fun part. The first part was all about DOGS. Then we went to document access management, which is important, but boring. So we're going to go back to DOGS. I have tried a number of products. There are all these products up on the screen here. There are many more. These are relationship-based access management tools. Some of them are open source and free to use. Some of them are paid for. I'm going to be using Permify in this demo. Am I going to annoy anybody by switching over to this on the AV team? They didn't mic check me on this one, so I apologise in advance. But I'm going to need both hands to type. I'm just going to stop screen sharing. Let's jump over here and we're going to have a first look at Postman. Let's make this a bit bigger. Can you all read that okay? Excellent. Let's have a look from the beginning. We're going to create a tenant. 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. Now over here, what we're going to do is we're going to create a new tenant. 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. We're going to create a tenant over here called Dog & Bone. 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. The next thing I'm going to do is create the schema. Now this schema for some reason, Permify wants it in a single string. So to make it easier, I have it over here. This is very similar to what we saw in the slides. Basically we've got a definition of a dog. A dog has an owner, which is a person. We've got a sheep. A sheep has an owner that is also a person. A sheep also has a bone, which is an entity type bone. We've got a person. A person can have a friend, would be another person. A person can also have sheep and a person can have dogs, so we've got bi-directional rules here. And then we've got a relationship between the bone. The bone has an owner, and that's a sheep. And then we've got a permission. Can the owner's friend's dog eat? And eat is true if that comes out as a relationship that exists. So let's submit that through, and we should find that that has now worked. If I now create some relationships... Come on, get bigger. Where's the handle? It's always hiding. I'll just scroll through this little by little. So, actually, if I make this slightly smaller, is that still readable at the back? Yep, okay. So at least we can see a bit more at a time. So we can see here we've got a relationship between a subject and an entity. Remember I said a subject is also an entity, but it's just the primary entity in a relationship. Is the microphone cutting out? A little? I'll go back to this one, because I don't need to type as much now. So we can see that the subject, mad scientist, is the owner of Shadow the dog. We can see here that Shadow the dog is also a dog belonging to the scientist. And then we've got the farmer has Dolly the sheep. The sheep belongs to the farmer. We've got Dolly is a sheep to the femur, and the femur is a bone to the sheep. So we've got these relationships built up now. 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. He has no friends. He's a sad scientist. As it happens, the farmer is also a sad farmer. Although the farmer has sheep, so a little bit happier, probably. I know, sheep are better than dogs? I digress yet again. So can shadow eat the bone? What do we reckon? No, so if I hit that, it comes through. Result denied. So it's a very low energy kind of reaction that I'm getting. But it's also a very low energy kind of output. So I thought, I've got these two requests here that I can make. The first one calls data right. What I'm going to do is I'm going to say, okay, the mad scientist is now friends with the farmer. And then I've got another one here, break friends. It's data delete. And in here I'm defining the mad scientist is no longer a friend with the farmer. So to make this a little more exciting, I decided to show you all my sister's Facebook page. And also, let's bring this back in over here. I have a dog and a bone. Let's just refresh this because it doesn't like having the lid shut on it. And for some reason, I'm getting an image rendering error. There we go. What demos go perfectly. So, doors closed. Dog can't get a bone. So what happens if the farmer makes friends with the scientist? What do you think? No, it didn't work. Did I call the right one there? Looks like you're offline. Yeah, but I'm doing everything locally. So, did I call the wrong one? Did I call break friends? Let's double click on that one. Darn it. 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. So now if our call can shadow eat the bone, it comes back as still denied. Okay. So, this is where the demo fails. I'm more than happy to work out why the demo failed. It was probably something to do with keeping my Wi-Fi off at Defcon and closing my laptop lid between testing demos. But the theory is there. The results should have come back immediately. I had a little bit of a cheat in my app. It was basically polling every second. But there are plenty of ways of connecting to databases and getting a full-time stream of data back. 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. 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. 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. As I said, there's a lot more computation power required for doing things like checking whether or not a permission should be granted. Role-based access control is always going to be your easiest. That's always simply like, is this person an admin, yes or no? 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? That's technically the simplest. 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. Work out what level of complexity you can get to at a minimum while still meeting your requirements. Because if you go for the full thing straight out, re-back all the way, baby, absolutely it's fun. You will probably create a situation where your job is now indispensable. You will not be fired because nobody knows what the hell you did. But it's not always the right solution. Pick the right one for you. 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. I'll let you know if I've got any clue at all as to what you may or may not consider. 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. But I would like to finish by just saying thank you. If I can even fire my slides. Let's just get that back up there. So again, that's my contact details at the top there. ArcJet are currently running a contest if you want to try our product out. There's some prizes we're giving away as well. Challenge.arcjet.com. Give it a try. Let us know. 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. But this talk was about permission systems. Come talk to me. Thank you for your time. Have a great rest of your DEF CON. DEF CON.