WEBVTT

00:08.670 --> 00:13.250
Who here is familiar with access control within web applications in some way or form?

00:13.390 --> 00:14.050
About half of you.

00:14.050 --> 00:14.450
That's cool.

00:14.450 --> 00:15.950
Who knows what RBAC is?

00:16.430 --> 00:17.150
ABAC?

00:17.790 --> 00:18.510
ReBAC?

00:19.070 --> 00:19.590
Cool.

00:20.530 --> 00:21.910
Increasingly dropping numbers of hands.

00:21.910 --> 00:22.950
That's kind of what I expected.

00:22.950 --> 00:25.570
I think we've got about 10% people here who know ReBAC.

00:25.570 --> 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.

00:29.370 --> 00:32.250
Now normally, this is a 45 minute to one hour conversation.

00:32.530 --> 00:37.030
So, excuse me if I skip over some bits, but please come and ask me questions afterwards.

00:37.030 --> 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.

00:47.790 --> 00:49.110
It's not always the right solution.

00:49.530 --> 00:50.410
But who am I?

00:50.550 --> 00:54.670
I'm a guy who develops slides that have really bad contrast on LED screens.

00:54.830 --> 00:58.070
Also, I've been a software engineer for too many years.

00:58.110 --> 00:59.630
I used to put the number up there.

00:59.650 --> 01:01.750
It made me feel old, so now I just do a sentence.

01:01.750 --> 01:03.050
You can do the maths in your head.

01:03.050 --> 01:06.130
I love working with developer and open source communities.

01:06.130 --> 01:07.950
I've been doing that for about 20 years.

01:08.030 --> 01:10.730
I'm really passionate about security and privacy.

01:10.810 --> 01:13.150
If you want to talk to me about any of those things, those are my jam.

01:13.150 --> 01:14.350
Come talk to me afterwards.

01:14.790 --> 01:21.130
I'm currently working as a developer advocate for a company called ArcJet, hence the branding across my chest here.

01:21.130 --> 01:24.790
We're a middleware security solution for your web applications.

01:24.810 --> 01:29.070
If you are writing any kind of web application at all, check out arcjet.com and just plug it in.

01:29.070 --> 01:29.710
It's free.

01:29.710 --> 01:30.250
Give it a try.

01:30.250 --> 01:31.750
We'd love to hear what you think about it.

01:31.750 --> 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.

01:37.070 --> 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.

01:48.190 --> 01:50.570
My Twitter handle is at BenDekarai.

01:50.570 --> 01:51.810
My DMs are open.

01:51.810 --> 01:54.150
Contact me, if you like.

01:54.150 --> 01:55.470
It's not an instruction.

01:55.670 --> 01:56.950
It's an offer.

01:57.290 --> 01:58.130
Let's get into it.

01:58.130 --> 01:59.330
Access Control 101.

01:59.330 --> 02:00.790
Basics and understandings thereof.

02:00.790 --> 02:05.470
First thing we're going to have a look at is the caricatures we're going to be looking at.

02:05.510 --> 02:07.910
Whenever it comes to access control, the dog wants the bone.

02:08.270 --> 02:11.890
We're going to look at ways that we can stop or allow the dog from accessing the bone.

02:11.890 --> 02:14.690
First one is going to be using RBAC, role-based access control.

02:14.810 --> 02:19.010
It's probably one of the simplest access control mechanisms, so we'll skip through this very quickly.

02:19.010 --> 02:20.670
Basically, we have a number of roles.

02:20.690 --> 02:23.270
You've got an admin, you've got a manager, employee, and a guest.

02:23.350 --> 02:25.410
In our case, our dog, this is Shadow.

02:25.750 --> 02:27.330
Shadow has a blue hat on.

02:27.330 --> 02:28.770
Blue hats are employees.

02:28.770 --> 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.

02:34.750 --> 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.

02:41.970 --> 02:45.010
So because Shadow has access, the door opens.

02:45.150 --> 02:46.130
Role-based access control.

02:46.130 --> 02:47.010
Nice and simple.

02:47.790 --> 02:48.510
Next one.

02:48.830 --> 02:50.590
Attribute-based access control.

02:50.590 --> 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.

02:56.950 --> 02:59.310
So we've got four attributes here of the dog.

02:59.310 --> 03:00.190
This is Min.

03:00.190 --> 03:02.790
This is a white Siberian husky.

03:02.790 --> 03:04.470
These are actual real dogs in my life.

03:04.470 --> 03:06.390
I like to relay them into my talks.

03:06.590 --> 03:07.850
There are four characteristics.

03:07.850 --> 03:09.870
Service dog, good boy, loyal, and fierce.

03:09.870 --> 03:14.370
I can tell you, while Shadow is a service dog, Min will never be a service dog.

03:14.370 --> 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.

03:18.810 --> 03:20.830
So she will never ever be a service dog.

03:20.830 --> 03:24.210
But she is usually a good boy or loyal.

03:24.210 --> 03:25.390
She is not fierce.

03:25.390 --> 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.

03:31.550 --> 03:34.590
Now, as an aside, I go on tangents occasionally.

03:34.710 --> 03:38.430
You might be asking yourself, but why doesn't the service dog get a bone?

03:38.430 --> 03:39.770
Because a service dog is good, right?

03:39.770 --> 03:41.890
Service dogs deserve bones.

03:41.990 --> 03:43.270
Does anybody agree with that?

03:43.750 --> 03:44.590
Nobody agrees with that?

03:44.590 --> 03:45.630
You all hate service dogs.

03:45.630 --> 03:46.830
That's what I'm learning about you lot.

03:46.830 --> 03:47.410
Jesus.

03:47.670 --> 03:48.690
Rough crowd.

03:49.270 --> 03:50.530
No, service dogs are working.

03:50.530 --> 03:51.510
They don't get to eat.

03:51.850 --> 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?

03:56.370 --> 03:58.790
The attribute here we're going to put in is time.

03:58.790 --> 04:00.090
Who does have a dog?

04:01.410 --> 04:02.190
Wrong audience.

04:02.190 --> 04:03.290
Who has cats?

04:04.070 --> 04:06.490
Okay, let's pretend your cat likes eating bones.

04:07.390 --> 04:09.130
Or for those of you who have dogs.

04:09.430 --> 04:13.650
Who lets their dog sleep in their bedroom with them at night?

04:13.650 --> 04:17.810
Who would like the sound of a crunching bone at 3 a.m.?

04:17.810 --> 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.

04:22.890 --> 04:24.610
to 9 a.m., no bone for you.

04:24.670 --> 04:26.990
So, sadly, men get no bone.

04:28.150 --> 04:30.470
But there are plenty of other things we can do attributes on.

04:30.470 --> 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.

04:36.630 --> 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.

04:42.810 --> 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.

04:49.430 --> 04:53.330
This changes the paradigm quite significantly as I lose my balance.

04:53.790 --> 04:57.810
So, this dog doesn't actually have a name.

04:57.810 --> 04:59.210
Who here had a dog?

04:59.550 --> 05:00.610
What was your dog's name?

05:00.610 --> 05:00.990
Liam.

05:01.010 --> 05:02.130
This is Liam.

05:02.130 --> 05:02.870
Thank you.

05:02.870 --> 05:04.550
Liam is actually a dog.

05:04.550 --> 05:06.190
Dali designed Liam.

05:06.230 --> 05:09.830
I thought it came out a little bit like a cat, but that's what we're going with.

05:09.830 --> 05:12.330
So, Liam has an owner.

05:12.530 --> 05:13.810
You are the mad scientist.

05:13.810 --> 05:14.570
Congratulations.

05:14.970 --> 05:16.650
So, Liam's owner is a mad scientist.

05:16.650 --> 05:19.230
The mad scientist is friends with a farmer.

05:19.230 --> 05:23.710
The farmer has a whole lot of sheep, and for the vegetarians in the audience, I apologize, but sheep have bones.

05:26.130 --> 05:27.070
Ten minutes?

05:28.110 --> 05:29.250
Oh, I need to stay back.

05:29.250 --> 05:32.370
This is not good for me because, A, I'm going to fall off the back of the stage.

05:32.450 --> 05:33.230
Not too far.

05:33.230 --> 05:33.590
Okay.

05:33.590 --> 05:34.510
Just right here.

05:34.510 --> 05:35.010
Okay.

05:35.330 --> 05:38.070
The guy who likes to roam may no longer roam.

05:38.150 --> 05:38.910
That's okay.

05:39.530 --> 05:43.350
So, we have this chain of relationships, as you can see.

05:43.350 --> 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.

05:50.650 --> 05:51.850
Now I'm getting feedback.

05:51.950 --> 05:53.930
Based on the rules you can see on the door there.

05:54.910 --> 05:56.870
Sorry, let's just zoom in a little bit.

05:56.870 --> 05:58.670
The rules you can see on the door there.

05:59.130 --> 06:03.890
So, with relationship-based access control, we don't actually have a concept of users anymore.

06:03.890 --> 06:10.770
We just have a concept of entities and relationships.

06:15.470 --> 06:16.370
Entities and relationships.

06:16.370 --> 06:17.910
I'll keep going unless they actually stop me.

06:17.910 --> 06:19.890
Or unless too many people in the audience cringe.

06:20.050 --> 06:21.050
It appears to be good again.

06:21.050 --> 06:22.230
So, here we've got an action.

06:22.230 --> 06:24.490
Can the action eat be completed on the bone?

06:25.590 --> 06:27.930
Note that we're looking here at what can be done to the bone.

06:27.930 --> 06:31.070
We're not looking at what Shadow or Liam can do.

06:31.450 --> 06:33.010
We're looking at what can be done to the bone.

06:33.010 --> 06:34.570
What actions can be taking place.

06:34.850 --> 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.

06:42.410 --> 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.

06:48.330 --> 06:49.650
That would be a little bit weird.

06:49.970 --> 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.

06:56.090 --> 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.

07:03.410 --> 07:04.370
Liam gets a bone.

07:04.470 --> 07:05.550
Good for Liam.

07:05.550 --> 07:06.770
So, the door opens.

07:07.310 --> 07:12.990
Now, say one day the farmer and the mad scientist break friends.

07:13.030 --> 07:14.490
They're no longer friends with each other.

07:14.490 --> 07:15.830
Suddenly, that relationship is broken.

07:15.830 --> 07:17.370
Now, nothing has changed about the bone.

07:17.370 --> 07:18.970
And nothing has changed about Liam.

07:18.970 --> 07:20.630
But the relationship is broken.

07:20.630 --> 07:23.390
Therefore, the friend component of that rule there breaks.

07:23.390 --> 07:27.530
So, the only rule that allowed Liam to get access to that bone is now broken.

07:27.530 --> 07:28.550
And the door shuts.

07:29.110 --> 07:31.630
So, that's what a relationship-based access control is about.

07:31.630 --> 07:35.830
It's not so much about defining what somebody or some user can do.

07:35.830 --> 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.

07:43.070 --> 07:44.090
Does that make sense?

07:44.510 --> 07:45.230
Cool.

07:45.970 --> 07:51.590
So, under the hood, who here is familiar with the Entity Attribute Value model of designing?

07:51.610 --> 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.

08:04.830 --> 08:06.470
Especially when you have a lot of data.

08:06.650 --> 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.

08:16.590 --> 08:19.810
So, if you want to add another entity, it's just another row in a table.

08:19.870 --> 08:20.710
Nice and simple.

08:21.030 --> 08:23.050
Let's have a quick look at how that works.

08:23.050 --> 08:24.690
So, we've got a user and an article.

08:24.690 --> 08:28.190
So, we're going to be looking at a blog post system, for example.

08:28.270 --> 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.

08:32.290 --> 08:34.910
But you can see that we've got the Entity ID, the second column.

08:34.910 --> 08:40.610
So, the first, second, and the last two rows in the attribute table belong to a user.

08:41.210 --> 08:48.490
And because the second column has number twos in it, the third and fourth rows belong to an article.

08:48.530 --> 08:52.630
So, you can see the user's username is Robin, and the user's password is Password.

08:52.750 --> 08:55.150
Down there, we have username Morgan and password.

08:55.990 --> 08:59.110
For some reason, they like using JSON Web Tokens for their passwords.

08:59.110 --> 09:00.670
But that's their password.

09:01.350 --> 09:04.910
And then, the middle two there, you can see that we've got an article, one article.

09:04.910 --> 09:06.450
Instance ID of the article is one.

09:06.450 --> 09:10.150
We've got a title of Rebec for the win, and content is CanHasFGA.

09:10.610 --> 09:12.030
Fine grained access control.

09:12.630 --> 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.

09:27.690 --> 09:29.770
Give me the title and the content.

09:29.770 --> 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.

09:35.670 --> 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.

09:46.650 --> 09:50.570
And you can store arbitrary data in there and pull it out in whichever way you want.

09:50.770 --> 09:53.670
It's complicated and expensive to pull out.

09:53.790 --> 09:57.770
And it's somewhat complicated to set up and use within...

09:57.770 --> 10:01.750
more so than if you had, like, an article table and a user table and a comment table.

10:01.970 --> 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,

10:15.510 --> 10:17.590
comment was first, and here's the date, Sam.

10:17.990 --> 10:22.990
So without making any database schema change, I've added a whole new entity to the system.

10:23.870 --> 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.

10:30.330 --> 10:32.130
So let's have a look at how that works.

10:32.270 --> 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.

10:39.730 --> 10:41.550
And down here we have some relationships.

10:41.750 --> 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.

10:51.410 --> 10:53.750
So how does a subject relate to an entity?

10:53.750 --> 10:58.230
A subject is an entity, it's just the primary entity within a relationship.

10:58.270 --> 11:05.170
So we're saying subject 1, the user, entity ID 3, the article, relationship type is owner.

11:05.510 --> 11:09.150
Therefore we know that Robin is the owner of the Reback for the win article.

11:10.550 --> 11:16.550
We can then add in that Robin, user 1, is a member of organization Acme Co.

11:17.450 --> 11:23.510
And we can add in that Morgan, user 4, is a member of the organization Acme Co.

11:23.510 --> 11:24.070
as well.

11:24.270 --> 11:28.150
So we now know that both Robin and Morgan are members of Acme Co.

11:28.150 --> 11:33.570
Now we have another one here where we say the organization is a viewer of the Reback article.

11:33.610 --> 11:35.850
But organizations can't view things.

11:36.430 --> 11:40.130
So we're able to extend that slightly and put an extra entity relation on there.

11:40.130 --> 11:42.230
How do the entities relate to each other?

11:42.310 --> 11:44.570
Through this member relation.

11:44.910 --> 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.

11:52.350 --> 12:01.710
So what we now know is that members of organization 2 can view the Reback for the win article.

12:02.150 --> 12:09.010
So now if I add another member into that organization, they automatically inherit that because the relationship exists already.

12:09.570 --> 12:10.390
Does that make sense?

12:11.070 --> 12:12.870
This is where it gets a little bit murky.

12:13.170 --> 12:14.230
You don't need to know all of this.

12:14.230 --> 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.

12:20.230 --> 12:24.470
So, the other thing we can do is define permissions on all of these.

12:24.470 --> 12:27.250
So we've got the relationships, but what does that actually mean they can do?

12:27.410 --> 12:33.230
So permission ID 1, again arbitrarily for the permissions table, relates to relationship ID 1.

12:33.230 --> 12:37.410
So relationship ID 1 was Robin is the owner of the Reback article.

12:37.850 --> 12:41.030
So we're saying here, well, one of the permissions is read.

12:42.750 --> 12:48.130
Relationship ID 1 is also that Robin is the owner of the article.

12:48.670 --> 12:50.090
Robin also has write access.

12:51.010 --> 12:58.430
And then we have relationship ID 4, which is this inferred down here, members of organization 2.

12:58.870 --> 13:01.970
Members of organization 2 have read permissions.

13:02.990 --> 13:07.570
So even over here, we've got relationship types and entities like viewer is just a label.

13:07.630 --> 13:09.390
It doesn't mean anything to the system.

13:09.410 --> 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.

13:20.790 --> 13:23.490
So there's one extra table here compared to EAV.

13:23.490 --> 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.

13:32.150 --> 13:34.590
And more importantly, they allow you to chain those entities.

13:34.590 --> 13:39.290
Remember how we went from Liam to the mad scientist to the farmer to the sheep to the bone?

13:39.430 --> 13:40.870
It's not just one-to-one.

13:40.870 --> 13:45.690
You can define these huge big chains, and if any part of that chain gets broken, then the relationship breaks.

13:46.870 --> 13:49.030
So querying the Reback model.

13:49.030 --> 13:50.110
How does this work?

13:50.330 --> 13:53.970
Let's say we come in here and we want to find out who can read.

13:54.370 --> 13:57.190
We can see here that the read...

13:57.190 --> 13:58.410
Sorry, who can write.

13:58.410 --> 14:00.110
The permission ID there is 2.

14:01.210 --> 14:03.150
So if we...

14:09.080 --> 14:11.420
I think I've got the wrong one highlighted there.

14:11.420 --> 14:14.400
I want to find out who can write to Reback article 2.

14:14.840 --> 14:17.640
So first thing we do is we look at the...

14:17.640 --> 14:19.500
and the highlighting isn't working so great here.

14:19.500 --> 14:22.520
The object entity ID 3 there is the Reback article.

14:22.520 --> 14:26.280
So we say, okay, within the relationships, let's find out everything we know about the article.

14:26.460 --> 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.

14:35.200 --> 14:38.880
However, relationship ID 1 is in that table.

14:38.880 --> 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.

14:47.880 --> 14:50.460
So you can look at things in other directions as well.

14:51.080 --> 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.

14:55.940 --> 14:57.360
We look at article number 3.

14:57.620 --> 15:01.800
We know that Robin is the owner of that article already.

15:02.700 --> 15:05.660
And if we look at the viewer here, we can then...

15:05.660 --> 15:11.840
and this is what I was talking about before, how member gets extrapolated to infer relationship status.

15:11.840 --> 15:18.600
So we can see that the member here of organization 2 has access to the article.

15:18.780 --> 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.

15:25.160 --> 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.

15:33.140 --> 15:35.780
So that's probably one of the most complicated lookups.

15:35.780 --> 15:41.520
It's really deep, diving straight into the depths of the Reback schema.

15:41.560 --> 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.

15:52.060 --> 15:53.100
I mean, you do.

15:53.100 --> 15:55.340
But that doesn't really help an end user.

15:55.340 --> 16:01.520
How do we then unfold that and then extrapolate that to refer to the actual user entities?

16:02.040 --> 16:06.380
And this is where it gets complicated, because Reback, as I said, doesn't have a concept of a user necessarily.

16:06.420 --> 16:12.200
You could actually ask Reback what is the relationship between this organization and that network.

16:12.500 --> 16:13.840
Neither of them really do anything.

16:13.840 --> 16:14.780
They're system entities.

16:14.780 --> 16:15.940
They're not user entities.

16:15.940 --> 16:17.400
But they still have relationships.

16:17.400 --> 16:19.740
So it's powerful but also complex.

16:22.880 --> 16:24.200
Implementation details.

16:26.180 --> 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.

16:32.600 --> 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.

16:49.340 --> 16:54.140
Seems like a fairly robust kind of setup that you might have in a large organization.

16:54.620 --> 16:55.540
So, if.

16:55.980 --> 16:58.400
If the user is admin or if the user is editor.

16:58.700 --> 16:59.280
Cool.

16:59.420 --> 17:03.040
So we know what role the user has.

17:03.620 --> 17:08.360
Also, if the user is an editor and the list of document editors contains the current user.

17:08.500 --> 17:10.820
So we don't want any editor to be able to edit this.

17:11.180 --> 17:15.260
Only if the list of editors for this particular article includes the current user.

17:15.560 --> 17:17.240
So we can compound those two together.

17:17.920 --> 17:21.740
Then also we want to say, well, if the document isn't sensitive, then we can carry on.

17:21.740 --> 17:26.140
Otherwise, we're going to check to see if the user's location is on premises.

17:26.560 --> 17:30.220
Or if the user's location is currently in office hours.

17:30.220 --> 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.

17:35.460 --> 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.

17:46.840 --> 17:49.660
Imagine if you had to come back and change those rules three months later.

17:51.800 --> 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.

17:59.020 --> 18:00.580
We're going to define a document.

18:00.760 --> 18:02.500
The document has an owner and an editor.

18:02.500 --> 18:09.040
The owner is a user, and the editor is a member of an organization with the member type editor.

18:09.240 --> 18:12.180
So you can have different types of people within groups.

18:12.820 --> 18:16.360
And then we're going to have a sensitive document, so that's the definition of a normal document.

18:16.420 --> 18:19.080
The sensitive document is going to extend document.

18:19.720 --> 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.

18:28.340 --> 18:32.040
Because remember, we're defining actions on an entity and who's allowed to perform it.

18:32.240 --> 18:35.180
So, can edit be done on a sensitive document?

18:35.180 --> 18:40.120
Yes, you can, if you are the document owner, and you are the document owner and you're on-premises.

18:41.100 --> 18:43.320
Or if you're an editor and you're on-premises.

18:44.020 --> 18:49.500
So this gets tied into your relationship-based access model, schema, and permission systems.

18:49.640 --> 18:52.980
So now your code can change from this to that.

18:54.480 --> 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.

19:03.220 --> 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.

19:09.160 --> 19:11.360
There's a fast and firm rule for that.

19:11.380 --> 19:13.080
This gives you two benefits.

19:13.080 --> 19:17.520
One from a clean code, easy-to-read perspective, that is much easier to read.

19:17.520 --> 19:18.880
You know exactly what's going to happen.

19:18.880 --> 19:20.400
You don't have to think about it.

19:20.400 --> 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.

19:34.740 --> 19:36.560
So, demo time.

19:36.800 --> 19:37.620
This is the fun part.

19:37.900 --> 19:40.400
The first part was all about DOGS.

19:40.400 --> 19:44.960
Then we went to document access management, which is important, but boring.

19:44.960 --> 19:46.360
So we're going to go back to DOGS.

19:46.800 --> 19:49.540
I have tried a number of products.

19:49.540 --> 19:51.660
There are all these products up on the screen here.

19:51.660 --> 19:52.520
There are many more.

19:52.520 --> 19:55.800
These are relationship-based access management tools.

19:55.840 --> 19:57.300
Some of them are open source and free to use.

19:57.300 --> 19:58.380
Some of them are paid for.

19:58.380 --> 20:00.760
I'm going to be using Permify in this demo.

20:02.580 --> 20:06.040
Am I going to annoy anybody by switching over to this on the AV team?

20:06.040 --> 20:08.840
They didn't mic check me on this one, so I apologise in advance.

20:08.840 --> 20:10.420
But I'm going to need both hands to type.

20:11.280 --> 20:13.240
I'm just going to stop screen sharing.

20:15.220 --> 20:19.700
Let's jump over here and we're going to have a first look at Postman.

20:20.440 --> 20:22.200
Let's make this a bit bigger.

20:23.040 --> 20:24.740
Can you all read that okay?

20:24.940 --> 20:25.740
Excellent.

20:26.400 --> 20:28.860
Let's have a look from the beginning.

20:28.860 --> 20:30.600
We're going to create a tenant.

20:30.600 --> 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.

20:43.160 --> 20:46.940
Now over here, what we're going to do is we're going to create a new tenant.

20:46.940 --> 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.

20:58.040 --> 21:03.680
We're going to create a tenant over here called Dog & Bone.

21:04.240 --> 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.

21:11.300 --> 21:13.340
The next thing I'm going to do is create the schema.

21:13.440 --> 21:18.400
Now this schema for some reason, Permify wants it in a single string.

21:18.820 --> 21:22.380
So to make it easier, I have it over here.

21:24.540 --> 21:26.500
This is very similar to what we saw in the slides.

21:26.500 --> 21:28.360
Basically we've got a definition of a dog.

21:28.560 --> 21:30.480
A dog has an owner, which is a person.

21:30.680 --> 21:31.540
We've got a sheep.

21:31.540 --> 21:33.640
A sheep has an owner that is also a person.

21:33.780 --> 21:36.480
A sheep also has a bone, which is an entity type bone.

21:36.800 --> 21:37.880
We've got a person.

21:37.960 --> 21:40.280
A person can have a friend, would be another person.

21:40.280 --> 21:45.940
A person can also have sheep and a person can have dogs, so we've got bi-directional rules here.

21:45.940 --> 21:48.740
And then we've got a relationship between the bone.

21:48.740 --> 21:50.640
The bone has an owner, and that's a sheep.

21:50.640 --> 21:51.560
And then we've got a permission.

21:51.560 --> 21:54.360
Can the owner's friend's dog eat?

21:55.180 --> 22:00.120
And eat is true if that comes out as a relationship that exists.

22:01.900 --> 22:07.520
So let's submit that through, and we should find that that has now worked.

22:07.520 --> 22:09.820
If I now create some relationships...

22:12.180 --> 22:13.600
Come on, get bigger.

22:16.100 --> 22:16.980
Where's the handle?

22:17.560 --> 22:18.480
It's always hiding.

22:21.880 --> 22:23.940
I'll just scroll through this little by little.

22:24.200 --> 22:28.140
So, actually, if I make this slightly smaller, is that still readable at the back?

22:28.860 --> 22:29.740
Yep, okay.

22:29.840 --> 22:31.260
So at least we can see a bit more at a time.

22:31.260 --> 22:34.160
So we can see here we've got a relationship between a subject and an entity.

22:34.340 --> 22:38.540
Remember I said a subject is also an entity, but it's just the primary entity in a relationship.

22:38.540 --> 22:39.960
Is the microphone cutting out?

22:39.960 --> 22:40.920
A little?

22:41.240 --> 22:44.560
I'll go back to this one, because I don't need to type as much now.

22:44.560 --> 22:48.700
So we can see that the subject, mad scientist, is the owner of Shadow the dog.

22:48.940 --> 22:53.020
We can see here that Shadow the dog is also a dog belonging to the scientist.

22:53.400 --> 22:55.980
And then we've got the farmer has Dolly the sheep.

22:56.220 --> 22:58.040
The sheep belongs to the farmer.

22:58.220 --> 23:06.020
We've got Dolly is a sheep to the femur, and the femur is a bone to the sheep.

23:06.020 --> 23:08.500
So we've got these relationships built up now.

23:08.860 --> 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.

23:21.220 --> 23:23.180
He has no friends.

23:23.180 --> 23:24.680
He's a sad scientist.

23:25.100 --> 23:28.140
As it happens, the farmer is also a sad farmer.

23:28.260 --> 23:31.640
Although the farmer has sheep, so a little bit happier, probably.

23:32.160 --> 23:33.680
I know, sheep are better than dogs?

23:33.680 --> 23:35.180
I digress yet again.

23:35.260 --> 23:36.840
So can shadow eat the bone?

23:37.000 --> 23:37.800
What do we reckon?

23:39.460 --> 23:41.720
No, so if I hit that, it comes through.

23:41.900 --> 23:42.840
Result denied.

23:43.240 --> 23:51.260
So it's a very low energy kind of reaction that I'm getting.

23:51.260 --> 23:53.380
But it's also a very low energy kind of output.

23:53.400 --> 23:57.020
So I thought, I've got these two requests here that I can make.

23:57.020 --> 24:00.260
The first one calls data right.

24:00.700 --> 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.

24:04.640 --> 24:06.780
And then I've got another one here, break friends.

24:06.960 --> 24:08.180
It's data delete.

24:08.180 --> 24:11.600
And in here I'm defining the mad scientist is no longer a friend with the farmer.

24:11.640 --> 24:15.040
So to make this a little more exciting, I decided to

24:19.530 --> 24:21.870
show you all my sister's Facebook page.

24:22.790 --> 24:25.210
And also, let's bring this back in over here.

24:25.830 --> 24:27.410
I have a dog and a bone.

24:27.410 --> 24:31.230
Let's just refresh this because it doesn't like having the lid shut on it.

24:31.870 --> 24:34.670
And for some reason, I'm getting an image rendering error.

24:34.670 --> 24:35.550
There we go.

24:35.710 --> 24:37.070
What demos go perfectly.

24:37.070 --> 24:38.670
So, doors closed.

24:38.670 --> 24:39.830
Dog can't get a bone.

24:39.830 --> 24:47.010
So what happens if the farmer makes friends with the scientist?

24:47.010 --> 24:47.870
What do you think?

24:52.460 --> 24:53.940
No, it didn't work.

24:55.400 --> 24:57.060
Did I call the right one there?

24:57.380 --> 24:58.780
Looks like you're offline.

24:58.800 --> 25:00.560
Yeah, but I'm doing everything locally.

25:00.560 --> 25:00.880
So,

25:06.900 --> 25:08.480
did I call the wrong one?

25:08.680 --> 25:10.100
Did I call break friends?

25:10.360 --> 25:12.040
Let's double click on that one.

25:15.330 --> 25:16.470
Darn it.

25:16.910 --> 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.

25:28.550 --> 25:33.850
So now if our call can shadow eat the bone, it comes back as still denied.

25:34.030 --> 25:34.590
Okay.

25:34.590 --> 25:36.150
So, this is where the demo fails.

25:36.150 --> 25:38.610
I'm more than happy to work out why the demo failed.

25:38.610 --> 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.

25:44.450 --> 25:45.930
But the theory is there.

25:45.930 --> 25:47.950
The results should have come back immediately.

25:47.950 --> 25:50.090
I had a little bit of a cheat in my app.

25:50.090 --> 25:51.710
It was basically polling every second.

25:51.970 --> 25:57.170
But there are plenty of ways of connecting to databases and getting a full-time stream of data back.

25:57.170 --> 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.

26:05.070 --> 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.

26:11.770 --> 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.

26:25.970 --> 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.

26:31.910 --> 26:34.830
Role-based access control is always going to be your easiest.

26:34.930 --> 26:38.270
That's always simply like, is this person an admin, yes or no?

26:38.610 --> 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?

26:45.030 --> 26:46.550
That's technically the simplest.

26:47.030 --> 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.

26:57.950 --> 27:02.690
Work out what level of complexity you can get to at a minimum while still meeting your requirements.

27:02.690 --> 27:07.590
Because if you go for the full thing straight out, re-back all the way, baby, absolutely it's fun.

27:07.810 --> 27:12.030
You will probably create a situation where your job is now indispensable.

27:12.050 --> 27:15.230
You will not be fired because nobody knows what the hell you did.

27:15.310 --> 27:17.190
But it's not always the right solution.

27:17.290 --> 27:18.650
Pick the right one for you.

27:18.650 --> 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.

27:27.930 --> 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.

27:32.470 --> 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.

27:40.150 --> 27:44.610
But I would like to finish by just saying thank you.

27:44.870 --> 27:46.550
If I can even fire my slides.

27:50.260 --> 27:52.040
Let's just get that back up there.

27:52.140 --> 27:55.040
So again, that's my contact details at the top there.

27:55.540 --> 27:59.240
ArcJet are currently running a contest if you want to try our product out.

27:59.600 --> 28:01.380
There's some prizes we're giving away as well.

28:01.380 --> 28:02.580
Challenge.arcjet.com.

28:02.580 --> 28:03.140
Give it a try.

28:03.140 --> 28:03.800
Let us know.

28:03.800 --> 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.

28:12.700 --> 28:14.460
But this talk was about permission systems.

28:14.460 --> 28:15.380
Come talk to me.

28:15.420 --> 28:16.120
Thank you for your time.

28:16.120 --> 28:17.780
Have a great rest of your DEF CON.

28:23.820 --> 28:24.860
DEF CON.

