1"use strict";(globalThis.webpackChunkopenfga_dev=globalThis.webpackChunkopenfga_dev||[]).push([[754],{84094(e,i,d){d.r(i),d.d(i,{assets:()=>l,contentTitle:()=>o,default:()=>j,frontMatter:()=>c,metadata:()=>r,toc:()=>a});const r=JSON.parse('{"id":"content/modeling/advanced/iot","title":"IoT","description":"Modeling fine-grained authorization for an IoT security camera system","source":"@site/docs/content/modeling/advanced/iot.mdx","sourceDirName":"content/modeling/advanced","slug":"/modeling/advanced/iot","permalink":"/docs/modeling/advanced/iot","draft":false,"unlisted":false,"editUrl":"https://github.com/openfga/openfga.dev/edit/main/docs/content/modeling/advanced/iot.mdx","tags":[],"version":"current","lastUpdatedAt":1789987177000,"sidebarPosition":3,"frontMatter":{"title":"IoT","description":"Modeling fine-grained authorization for an IoT security camera system","sidebar_position":3,"slug":"/modeling/advanced/iot"},"sidebar":"docs","previous":{"title":"Slack","permalink":"/docs/modeling/advanced/slack"},"next":{"title":"Entitlements","permalink":"/docs/modeling/advanced/entitlements"}}');var s=d(74848),n=d(28453),t=d(20822);const c={title:"IoT",description:"Modeling fine-grained authorization for an IoT security camera system",sidebar_position:3,slug:"/modeling/advanced/iot"},o="Modeling Authorization for an IoT Security System with ",l={},a=[{value:"Before you start",id:"before-you-start",level:2},{value:"<ProductName></ProductName> concepts",id:"-concepts",level:3},{value:"Direct access",id:"direct-access",level:4},{value:"Modeling concentric relationships",id:"modeling-concentric-relationships",level:4},{value:"Direct relationships",id:"direct-relationships",level:4},{value:"User groups",id:"user-groups",level:4},{value:"Concepts & configuration language",id:"concepts--configuration-language",level:4},{value:"What You Will be modeling",id:"what-you-will-be-modeling",level:2},{value:"Requirements",id:"requirements",level:3},{value:"Defined Scenarios",id:"defined-scenarios",level:3},{value:"Modeling device authorization",id:"modeling-device-authorization",level:2},{value:"01. Writing the initial model for a device",id:"01-writing-the-initial-model-for-a-device",level:3},{value:"02. Inserting some relationship tuples",id:"02-inserting-some-relationship-tuples",level:3},{value:"Verification",id:"verification",level:4},{value:"03. Updating our authorization model to facilitate future changes",id:"03-updating-our-authorization-model-to-facilitate-future-changes",level:3},{value:"Verification",id:"verification-1",level:4},{value:"04. Modeling device groups",id:"04-modeling-device-groups",level:3},{value:"Updating relationship tuples on roles",id:"updating-relationship-tuples-on-roles",level:4},{value:"Verification",id:"verification-2",level:4},{value:"05. Disallow direct relationships To users",id:"05-disallow-direct-relationships-to-users",level:3},{value:"Updating the authorization model",id:"updating-the-authorization-model",level:4},{value:"Verification",id:"verification-3",level:4},{value:"Summary",id:"summary",level:2},{value:"Exercises for you",id:"exercises-for-you",level:3}];function h(e){const i={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",img:"img",li:"li",p:"p",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,n.R)(),...e.components},{Details:r}=i;return r||function(e,i){throw new Error("Expected "+(i?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Details",!0),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.header,{children:(0,s.jsxs)(i.h1,{id:"modeling-authorization-for-an-iot-security-system-with-",children:["Modeling Authorization for an IoT Security System with ",(0,s.jsx)(t.bU,{format:t.Ed.ShortForm})]})}),"\n",(0,s.jsx)(t.ZE,{}),"\n",(0,s.jsxs)(i.p,{children:["This tutorial explains how to model permissions for an IoT system using ",(0,s.jsx)(t.bU,{format:t.Ed.ShortForm}),"."]}),"\n",(0,s.jsx)(t.u6,{title:"What you will learn",children:(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsxs)(i.li,{children:["How to model a permission system using ",(0,s.jsx)(t.bU,{format:t.Ed.ProductLink})]}),"\n",(0,s.jsxs)(i.li,{children:["How to see ",(0,s.jsx)(t.bU,{format:t.Ed.ShortForm})," Authorization in action by modeling an IoT Security Camera System"]}),"\n"]})}),"\n",(0,s.jsx)(t.QF,{title:"IoT",preset:"iot",example:"IoT",store:"iot"}),"\n",(0,s.jsx)(i.h2,{id:"before-you-start",children:"Before you start"}),"\n",(0,s.jsxs)(i.p,{children:["In order to understand this guide correctly you must be familiar with some ",(0,s.jsx)(t.bU,{format:t.Ed.LongForm})," concepts and know how to develop the things that we will list below."]}),"\n",(0,s.jsxs)(r,{children:[(0,s.jsxs)("summary",{children:[(0,s.jsxs)(i.h3,{id:"-concepts",children:[(0,s.jsx)(t.bU,{format:t.Ed.ShortForm})," concepts"]}),(0,s.jsxs)(i.p,{children:["It would be helpful to have an understanding of some concepts of ",(0,s.jsx)(t.bU,{format:t.Ed.ShortForm})," before you start."]})]}),(0,s.jsx)(i.h4,{id:"direct-access",children:"Direct access"}),(0,s.jsxs)(i.p,{children:["You need to know how to create an authorization model and create a relationship tuple to grant a user access to an object. ",(0,s.jsx)(i.a,{href:"/docs/modeling/direct-access",children:"Learn more \u2192"})]}),(0,s.jsx)(i.h4,{id:"modeling-concentric-relationships",children:"Modeling concentric relationships"}),(0,s.jsxs)(i.p,{children:["You need to know how to update the authorization model to allow having nested relations such as all writers are readers. ",(0,s.jsx)(i.a,{href:"/docs/modeling/building-blocks/concentric-relationships",children:"Learn more \u2192"}
1),"\nUsed here to indicate that both IT Admins and Security Guards can view live video."]}),(0,s.jsx)(i.h4,{id:"direct-relationships",children:"Direct relationships"}),(0,s.jsxs)(i.p,{children:["You need to know how to disallow granting direct relation to an object and requiring the user to have a relation with another object that would imply a relation with the first one. ",(0,s.jsx)(i.a,{href:"/docs/modeling/building-blocks/direct-relationships",children:"Learn more \u2192"}),'\nUsed here to indicate that "Rename Device" is a permission that cannot be assigned directly, but can only be granted through the "IT Admin" role.']}),(0,s.jsx)(i.h4,{id:"user-groups",children:"User groups"}),(0,s.jsxs)(i.p,{children:["You need to know how to add users to groups and create relationships between groups of users and an object. ",(0,s.jsx)(i.a,{href:"/docs/modeling/building-blocks/direct-relationships",children:"Learn more \u2192"})]}),(0,s.jsx)(i.p,{children:"Used here to indicate that security guards on a certain group are security guards on a device in that group."}),(0,s.jsx)(i.h4,{id:"concepts--configuration-language",children:"Concepts & configuration language"}),(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsxs)(i.li,{children:["Some ",(0,s.jsx)(t.OK,{})]}),"\n",(0,s.jsx)(i.li,{children:(0,s.jsx)(i.a,{href:"/docs/configuration-language",children:"Configuration Language"})}),"\n"]})]}),"\n",(0,s.jsx)(i.h2,{id:"what-you-will-be-modeling",children:"What You Will be modeling"}),"\n",(0,s.jsxs)(i.p,{children:["In this tutorial, you will build an authorization model for a sample IoT Security Camera System (detailed below) using ",(0,s.jsx)(t.bU,{format:t.Ed.LongForm}),". You will use some scenarios to validate the model."]}),"\n",(0,s.jsxs)(i.p,{children:["The goal by the end of this post is to ask ",(0,s.jsx)(t.bU,{format:t.Ed.ShortForm}),": Does person X have permission to perform action Y on device Z? In response, you want to either get a confirmation that person X can indeed do that, or a rejection that they cannot."]}),"\n",(0,s.jsx)(i.h3,{id:"requirements",children:"Requirements"}),"\n",(0,s.jsx)(i.p,{children:"These are the requirements:"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Security guards"})," have access to ",(0,s.jsx)(i.strong,{children:"view live and recorded video"})," from ",(0,s.jsx)(i.strong,{children:"Devices"}),"."]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"IT Admins"})," can ",(0,s.jsx)(i.strong,{children:"view live and recorded videos"}),", as well as ",(0,s.jsx)(i.strong,{children:"rename"})," ",(0,s.jsx)(i.strong,{children:"Devices"}),"."]}),"\n",(0,s.jsxs)(i.li,{children:["To make access management easier, ",(0,s.jsx)(i.strong,{children:"Devices"})," can be grouped into ",(0,s.jsx)(i.strong,{children:"Device Groups"}),". ",(0,s.jsx)(i.strong,{children:"Security guards"})," with access to the ",(0,s.jsx)(i.strong,{children:"Device Group"})," are ",(0,s.jsx)(i.strong,{children:"Security Guards"})," with access to each ",(0,s.jsx)(i.strong,{children:"Device"})," in the group. Similarly for ",(0,s.jsx)(i.strong,{children:"IT Admins"}),"."]}),"\n"]}),"\n",(0,s.jsx)(i.h3,{id:"defined-scenarios",children:"Defined Scenarios"}),"\n",(0,s.jsx)(i.p,{children:"Use the following scenarios to be able to validate whether the model of the requirements is correct."}),"\n",(0,s.jsx)(i.p,{children:"There will be the following users:"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsx)(i.li,{children:"Anne"}),"\n",(0,s.jsx)(i.li,{children:"Beth"}),"\n",(0,s.jsx)(i.li,{children:"Charles"}),"\n",(0,s.jsx)(i.li,{children:"Dianne"}),"\n"]}),"\n",(0,s.jsx)(i.p,{children:"These users have the following roles and permissions:"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsx)(i.li,{children:"Anne is a Security Guard with access to only Device 1"}),"\n",(0,s.jsx)(i.li,{children:"Beth is an IT Admin with access to only Device 1"}),"\n",(0,s.jsx)(i.li,{children:"Charles is a Security Guard with access to Device 1 and everything in Device Group 1 (which is Device 2 and Device 3)"}),"\n",(0,s.jsx)(i.li,{children:"Dianne is an IT Admin with access to Device 1 and everything in Device Group 1"}),"\n"]}),"\n",(0,s.jsx)(i.p,{children:(0,s.jsx)(i.img,{alt:"Image showing requirements",src:d(16206).A+"",width:"1205",height:"461"})}),"\n",(0,s.jsx)(i.admonition,{type:"caution",children:(0,s.jsx)(i.p,{children:"In production, it is highly recommended to use unique, immutable identifiers. Names are used in this article to make it easier to read and follow."})}),"\n",(0,s.jsx)(i.h2,{id:"modeling-device-authorization",children:"Modeling device authorization"}),"\n",(0,s.jsxs)(i.p,{children:["The ",(0,s.jsx)(t.bU,{format:t.Ed.LongForm})," service is based on ",(0,s.jsx)(i.a,{href:"https://zanzibar.academy",children:"Zanzibar"}),", a Relationship Based Access Control system. This means it relies on ",(0,s.jsx)(t.OK,{section:"what-is-an-object",linkName:"object"})," and ",(0,s.jsx)(t.OK,{section:"what-is-a-user",linkName:"user"})," ",(0,s.jsx)(t.OK,{section:"what-is-a-relation",linkName:"relations"})," to perform authorization ",(0,s.jsx)(t.OK,{section:"what-is-a-check-request",linkName:"
1checks"}),"."]}),"\n",(0,s.jsxs)(i.p,{children:["Starting with devices, you will learn how to express the requirements in terms of relations you can feed into ",(0,s.jsx)(t.bU,{format:t.Ed.LongForm}),"."]}),"\n",(0,s.jsx)(i.h3,{id:"01-writing-the-initial-model-for-a-device",children:"01. Writing the initial model for a device"}),"\n",(0,s.jsx)(i.p,{children:"The requirements stated:"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Security guards"})," have access to ",(0,s.jsx)(i.strong,{children:"view live and recorded video"})," from ",(0,s.jsx)(i.strong,{children:"Devices"}),"."]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"IT Admins"})," can ",(0,s.jsx)(i.strong,{children:"view live and recorded videos"}),", as well as ",(0,s.jsx)(i.strong,{children:"rename"})," ",(0,s.jsx)(i.strong,{children:"Devices"}),"."]}),"\n"]}),"\n",(0,s.jsxs)(i.p,{children:["The goal is to ask ",(0,s.jsx)(t.bU,{format:t.Ed.ShortForm})," whether person X has permission to perform action Y on device Z. To start, you will set aside the Security Guard and IT Admin designations and focus on the actions a user can take."]}),"\n",(0,s.jsxs)(i.p,{children:["The actions users can take on a device are: ",(0,s.jsx)(i.em,{children:"view live videos"}),", ",(0,s.jsx)(i.em,{children:"view recorded videos"}),", and ",(0,s.jsx)(i.em,{children:"rename devices"}),". Mapping them to relations, they become: ",(0,s.jsx)(i.em,{children:"live_video_viewer"}),", ",(0,s.jsx)(i.em,{children:"recorded_video_viewer"}),", ",(0,s.jsx)(i.em,{children:"device_renamer"}),"."]}),"\n",(0,s.jsxs)(i.p,{children:["In ",(0,s.jsx)(t.bU,{format:t.Ed.ShortForm}),", the ",(0,s.jsx)(t.OK,{section:"what-is-an-authorization-model",linkName:"authorization model"})," for the device would be:"]}),"\n",(0,s.jsx)(t.pB,{configuration:{schema_version:"1.1",type_definitions:[{type:"user"},{type:"device",relations:{live_video_viewer:{this:{}},recorded_video_viewer:{this:{}},device_renamer:{this:{}}},metadata:{relations:{live_video_viewer:{directly_related_user_types:[{type:"user"}]},recorded_video_viewer:{directly_related_user_types:[{type:"user"}]},device_renamer:{directly_related_user_types:[{type:"user"}]}}}}]}}),"\n",(0,s.jsx)(i.h3,{id:"02-inserting-some-relationship-tuples",children:"02. Inserting some relationship tuples"}),"\n",(0,s.jsx)(i.p,{children:"The requirements are:"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Anne"})," is a ",(0,s.jsx)(i.strong,{children:"Security Guard"})," with access to only ",(0,s.jsx)(i.strong,{children:"Device 1"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Beth"})," is an ",(0,s.jsx)(i.strong,{children:"IT Admin"})," with access to only ",(0,s.jsx)(i.strong,{children:"Device 1"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Security Guards"})," can ",(0,s.jsx)(i.strong,{children:"view live and recorded video"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"IT Admins"})," can ",(0,s.jsx)(i.strong,{children:"view live and recorded video"})," and ",(0,s.jsx)(i.strong,{children:"rename"})," devices"]}),"\n"]}),"\n",(0,s.jsx)(i.p,{children:"Before we tackle the problem of users access to device based on their role, we will try to grant user access based on their view relationship directly."}),"\n",(0,s.jsx)(i.p,{children:"We will first focus on Anne and Beth's relationship with Device 1."}),"\n",(0,s.jsx)(i.p,{children:"To add Anne as live_video_viewer of device:1:"}),"\n",(0,s.jsx)(t.dp,{relationshipTuples:[{user:"user:anne",relation:"live_video_viewer",object:"device:1"}]}),"\n",(0,s.jsx)(i.p,{children:"To add Anne as recorded_video_viewer of device:1"}),"\n",(0,s.jsx)(t.dp,{relationshipTuples:[{user:"user:anne",relation:"recorded_video_viewer",object:"device:1"}]}),"\n",(0,s.jsx)(i.p,{children:"Likewise, we will add Beth's relationship with device:1."}),"\n",(0,s.jsx)(t.dp,{relationshipTuples:[{user:"user:beth",relation:"live_video_viewer",object:"device:1"},{user:"user:beth",relation:"recorded_video_viewer",object:"device:1"},{user:"user:beth",relation:"device_renamer",object:"device:1"}]}),"\n",(0,s.jsx)(i.h4,{id:"verification",children:"Verification"}),"\n",(0,s.jsxs)(i.p,{children:["Now that you have some relationship tuples added, you can start using it to ",(0,s.jsx)(t.OK,{section:"what-is-a-check-request",linkName:"ask"})," some questions, e.g., whether a person has access to rename a device."]}),"\n",(0,s.jsxs)(i.p,{children:["First, you will find out if ",(0,s.jsx)(i.co
1de,{children:"anne"})," has permission to ",(0,s.jsx)(i.code,{children:"view the live video"})," on ",(0,s.jsx)(i.code,{children:"device:1"}),", then you will see if ",(0,s.jsx)(i.code,{children:"anne"})," can ",(0,s.jsx)(i.code,{children:"rename"})," ",(0,s.jsx)(i.code,{children:"device:1"}),"."]}),"\n",(0,s.jsxs)(i.p,{children:["Anne has ",(0,s.jsx)(i.code,{children:"live_video_viewer"})," relationship with device:1."]}),"\n",(0,s.jsx)(t.ou,{user:"user:anne",relation:"live_video_viewer",object:"device:1",allowed:!0}),"\n",(0,s.jsxs)(i.p,{children:["On the other hand, Anne does not have ",(0,s.jsx)(i.code,{children:"device_renamer"})," relationship with device:1."]}),"\n",(0,s.jsx)(t.ou,{user:"user:anne",relation:"device_renamer",object:"device:1",allowed:!1}),"\n",(0,s.jsx)(i.p,{children:"Now, check the other relationships fore Anne and Beth."}),"\n",(0,s.jsxs)(i.table,{children:[(0,s.jsx)(i.thead,{children:(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.th,{children:"User"}),(0,s.jsx)(i.th,{children:"Object"}),(0,s.jsx)(i.th,{children:"Relation"}),(0,s.jsx)(i.th,{children:"Query"}),(0,s.jsx)(i.th,{children:"Relation?"})]})}),(0,s.jsxs)(i.tbody,{children:[(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:1 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:1 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:1 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:1 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:1 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:1 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]})]})]}),"\n",(0,s.jsx)(i.h3,{id:"03-updating-our-authorization-model-to-facilitate-future-changes",children:"03. Updating our authorization model to facilitate future changes"}),"\n",(0,s.jsxs)(i.p,{children:["Notice how you had to add the Anne and Beth as ",(0,s.jsx)(t.OK,{section:"what-are-direct-and-implied-relationships",linkName:"direct relations"})," to all the actions they can take on Device 1 instead of just stating that they are related as Security Guard or IT Admin, and having the other permissions implied? In practice this might have some disadvantages: if your authorization model changes, (e.g so that Security Guards can no longer view previously recorded videos), you would need to change relationship tuples in the system instead of just changing the configuration."]}),"\n",(0,s.jsxs)(i.p,{children:["We can address this by using ",(0,s.jsx)(i.a,{href:"/docs/modeling/building-blocks/concentric-relationships",children:(0,s.jsx)(i.strong,{children:"concentric relation models"})}),". It allows you to express that sets of users who have a relation X to the object also have relation Y. For example, anyone that is related to the device as a ",(0,s.jsx)(i.co
1de,{children:"security_guard"})," is also related as a ",(0,s.jsx)(i.code,{children:"live_video_viewer"})," and ",(0,s.jsx)(i.code,{children:"recorded_video_viewer"}),", and anyone who is related to the device as an ",(0,s.jsx)(i.code,{children:"it_admin"})," is also related as a ",(0,s.jsx)(i.code,{children:"live_video_viewer"}),", a ",(0,s.jsx)(i.code,{children:"recorded_video_viewer"}),", and a ",(0,s.jsx)(i.code,{children:"device_renamer"}),"."]}),"\n",(0,s.jsxs)(i.p,{children:["At the end you want to make sure that ",(0,s.jsx)(t.OK,{section:"what-is-a-check-request",linkName:"checking"})," if Anne, Beth, Charles, or Dianne have permission to view the live video or rename the device, will get you the correct answers back."]}),"\n",(0,s.jsx)(i.p,{children:"The resulting authorization model is:"}),"\n",(0,s.jsx)(t.pB,{configuration:{schema_version:"1.1",type_definitions:[{type:"device",relations:{it_admin:{this:{}},security_guard:{this:{}},live_video_viewer:{union:{child:[{this:{}},{computedUserset:{relation:"it_admin"}},{computedUserset:{relation:"security_guard"}}]}},recorded_video_viewer:{union:{child:[{this:{}},{computedUserset:{relation:"it_admin"}},{computedUserset:{relation:"security_guard"}}]}},device_renamer:{union:{child:[{this:{}},{computedUserset:{relation:"it_admin"}}]}}},metadata:{relations:{it_admin:{directly_related_user_types:[{type:"user"}]},security_guard:{directly_related_user_types:[{type:"user"}]},live_video_viewer:{directly_related_user_types:[{type:"user"}]},recorded_video_viewer:{directly_related_user_types:[{type:"user"}]},device_renamer:{directly_related_user_types:[{type:"user"}]}}}}]}}),"\n",(0,s.jsx)(i.p,{children:"The requirements are:"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Anne"})," and ",(0,s.jsx)(i.strong,{children:"Charles"})," are ",(0,s.jsx)(i.strong,{children:"Security Guards"})," with access ",(0,s.jsx)(i.strong,{children:"Device 1"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Beth"})," and ",(0,s.jsx)(i.strong,{children:"Dianne"})," are ",(0,s.jsx)(i.strong,{children:"IT Admins"})," with access ",(0,s.jsx)(i.strong,{children:"Device 1"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Security Guards"})," can ",(0,s.jsx)(i.strong,{children:"view live and recorded video"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"IT Admins"})," can ",(0,s.jsx)(i.strong,{children:"view live and recorded video"})," and ",(0,s.jsx)(i.strong,{children:"rename"})," devices"]}),"\n"]}),"\n",(0,s.jsxs)(i.p,{children:["Instead of adding different relationship tuples with direct relations to the actions they can take, as you did in the previous section, you will only add the relation to their role: ",(0,s.jsx)(i.code,{children:"it_admin"})," or ",(0,s.jsx)(i.code,{children:"security_guard"}),"."]}),"\n",(0,s.jsx)(t.dp,{relationshipTuples:[{user:"user:anne",relation:"security_guard",object:"device:1"},{user:"user:beth",relation:"it_admin",object:"device:1"},{user:"user:charles",relation:"security_guard",object:"device:1"},{user:"user:dianne",relation:"it_admin",object:"device:1"}]}),"\n",(0,s.jsx)(i.h4,{id:"verification-1",children:"Verification"}),"\n",(0,s.jsx)(i.p,{children:"We can now verify whether charles is related to device:1 as live_video_viewer."}),"\n",(0,s.jsx)(t.ou,{user:"user:charles",relation:"live_video_viewer",object:"device:1",allowed:!0}),"\n",(0,s.jsx)(i.p,{children:"Check the other relationships for anne, beth, charles and dianne."}),"\n",(0,s.jsxs)(i.table,{children:[(0,s.jsx)(i.thead,{children:(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.th,{children:"User"}),(0,s.jsx)(i.th,{children:"Object"}),(0,s.jsx)(i.th,{children:"Relation"}),(0,s.jsx)(i.th,{children:"Query"}),(0,s.jsx)(i.th,{children:"Relation?"})]})}),(0,s.jsxs)(i.tbody,{children:[(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}
1),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:1 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:1 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:1 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:1 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:1 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:1 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"charles"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is charles related to device:1 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"dianne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is dianne related to device:1 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"charles"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is charles related to device:1 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"dianne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is dianne related to device:1 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"charles"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is charles related to device:1 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"dianne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}
1),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is dianne related to device:1 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]})]})]}),"\n",(0,s.jsx)(i.h3,{id:"04-modeling-device-groups",children:"04. Modeling device groups"}),"\n",(0,s.jsx)(i.p,{children:"Now that you are done with devices. Let us tackle device groups."}),"\n",(0,s.jsx)(i.p,{children:"The requirements regarding device groups were:"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Devices"})," can be grouped into ",(0,s.jsx)(i.strong,{children:"Device Groups"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.strong,{children:"Security guards"})," with access to the ",(0,s.jsx)(i.strong,{children:"Device Group"})," are ",(0,s.jsx)(i.strong,{children:"Security Guards"})," with access to the ",(0,s.jsx)(i.strong,{children:"Devices"})," within the ",(0,s.jsx)(i.strong,{children:"Device Group"}),". Similarly for ",(0,s.jsx)(i.strong,{children:"IT Admins"})]}),"\n"]}),"\n",(0,s.jsxs)(i.p,{children:["The ",(0,s.jsx)(t.OK,{section:"what-is-a-type-definition",linkName:"type definition"})," for the device group:"]}),"\n",(0,s.jsx)(t.pB,{configuration:{schema_version:"1.1",type:"device_group",relations:{it_admin:{this:{}},security_guard:{this:{}}},metadata:{relations:{it_admin:{directly_related_user_types:[{type:"user"}]},security_guard:{directly_related_user_types:[{type:"user"}]}}}},skipVersion:!0}),"\n",(0,s.jsxs)(i.p,{children:["With this change, the full ",(0,s.jsx)(t.OK,{section:"what-is-an-authorization-model",linkName:"authorization model"})," becomes:"]}),"\n",(0,s.jsx)(t.pB,{configuration:{schema_version:"1.1",type_definitions:[{type:"user"},{type:"device",relations:{it_admin:{this:{}},security_guard:{this:{}},live_video_viewer:{union:{child:[{this:{}},{computedUserset:{relation:"it_admin"}},{computedUserset:{relation:"security_guard"}}]}},recorded_video_viewer:{union:{child:[{this:{}},{computedUserset:{relation:"it_admin"}},{computedUserset:{relation:"security_guard"}}]}},device_renamer:{union:{child:[{this:{}},{computedUserset:{relation:"it_admin"}}]}}},metadata:{relations:{it_admin:{directly_related_user_types:[{type:"user"},{type:"device_group",relation:"it_admin"}]},security_guard:{directly_related_user_types:[{type:"user"},{type:"device_group",relation:"security_guard"}]},live_video_viewer:{directly_related_user_types:[{type:"user"}]},recorded_video_viewer:{directly_related_user_types:[{type:"user"}]},device_renamer:{directly_related_user_types:[{type:"user"}]}}}},{type:"device_group",relations:{it_admin:{this:{}},security_guard:{this:{}}},metadata:{relations:{it_admin:{directly_related_user_types:[{type:"user"}]},security_guard:{directly_related_user_types:[{type:"user"}]}}}}]}}),"\n",(0,s.jsx)(i.h4,{id:"updating-relationship-tuples-on-roles",children:"Updating relationship tuples on roles"}),"\n",(0,s.jsxs)(i.p,{children:["Remember that ",(0,s.jsx)(i.strong,{children:"Charles"})," is a ",(0,s.jsx)(i.strong,{children:"Security Guard"}),", and ",(0,s.jsx)(i.strong,{children:"Dianne"})," an ",(0,s.jsx)(i.strong,{children:"IT Admin"})," on ",(0,s.jsx)(i.strong,{children:"Group 1"}),", enter the ",(0,s.jsx)(t.OK,{section:"what-is-a-relationship-tuple",linkName:"relationship tuples"})," below to reflect that."]}),"\n",(0,s.jsx)(t.dp,{relationshipTuples:[{user:"user:charles",relation:"security_guard",object:"device_group:group1"},{user:"user:dianne",relation:"it_admin",object:"device_group:group1"}]}),"\n",(0,s.jsxs)(i.p,{children:["You still need to give all the security guards of group1 a ",(0,s.jsx)(i.code,{children:"security_guard"})," relation to devices 2 and 3, and similarly for IT Admins. Add the following relationship tuples to do that."]}),"\n",(0,s.jsx)(t.dp,{relationshipTuples:[{user:"device_group:group1#security_guard",relation:"security_guard",object:"device:2"},{user:"device_group:group1#security_guard",relation:"security_guard",object:"device:3"},{user:"device_group:group1#it_admin",relation:"it_admin",object:"device:2"},{user:"device_group:group1#it_admin",relation:"it_admin",object:"device:3"}]}),"\n",(0,s.jsx)(i.h4,{id:"verification-2",children:"Verification"}),"\n",(0,s.jsx)(i.p,{children:"Now that you have finalized the model and added the relationship tuples, you can start asking some queries. Try asking the same queries you did earlier but on device 2 instead of device 1."}
1),"\n",(0,s.jsxs)(i.p,{children:["We can ask ",(0,s.jsx)(i.code,{children:"is dianne related to device:2 as live_video_viewer?"})]}),"\n",(0,s.jsx)(t.ou,{user:"dianne",relation:"live_video_viewer",object:"device:2",allowed:!0}),"\n",(0,s.jsxs)(i.p,{children:["Type any of the following queries in the ",(0,s.jsx)(i.strong,{children:"TUPLE QUERIES"})," section and press ",(0,s.jsx)(i.strong,{children:"ENTER"})," on your keyboard to see the results."]}),"\n",(0,s.jsxs)(i.table,{children:[(0,s.jsx)(i.thead,{children:(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.th,{children:"User"}),(0,s.jsx)(i.th,{children:"Object"}),(0,s.jsx)(i.th,{children:"Relation"}),(0,s.jsx)(i.th,{children:"Query"}),(0,s.jsx)(i.th,{children:"Relation?"})]})}),(0,s.jsxs)(i.tbody,{children:[(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:2 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:2 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:2 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:2 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"anne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is anne related to device:2 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"beth"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is beth related to device:2 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"charles"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is charles related to device:2 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"dianne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"live_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is dianne related to device:2 as live_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"charles"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is charles related to device:2 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.co
1de,{children:"dianne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is dianne related to device:2 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"charles"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is charles related to device:2 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"dianne"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:2"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is dianne related to device:2 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"Yes"})]})]})]}),"\n",(0,s.jsx)(i.h3,{id:"05-disallow-direct-relationships-to-users",children:"05. Disallow direct relationships To users"}),"\n",(0,s.jsxs)(i.p,{children:["Notice that despite following ",(0,s.jsx)(i.strong,{children:(0,s.jsx)(i.a,{href:"/docs/modeling/advanced/iot#03-updating-our-authorization-model-to-facilitate-future-changes",children:"Step 03"})}),", anne and beth still have direct relations to all the actions they can take on device:1."]}),"\n",(0,s.jsx)(i.h4,{id:"updating-the-authorization-model",children:"Updating the authorization model"}),"\n",(0,s.jsxs)(i.p,{children:[(0,s.jsx)(i.code,{children:"anne"})," is a ",(0,s.jsx)(i.code,{children:"live_video_viewer"})," by both her position as ",(0,s.jsx)(i.code,{children:"security_guard"})," as well as her ",(0,s.jsx)(i.em,{children:(0,s.jsx)(t.OK,{section:"what-are-direct-and-implied-relationships",linkName:"direct relationship"})})," assignment. This is undesirable. Imagine ",(0,s.jsx)(i.code,{children:"anne"})," left her position of ",(0,s.jsx)(i.code,{children:"security_guard"})," and she will still have ",(0,s.jsx)(i.code,{children:"live_video_viewer"})," access to ",(0,s.jsx)(i.code,{children:"device:1"}),"."]}),"\n",(0,s.jsxs)(i.p,{children:["To remedy this, remove ",(0,s.jsx)(i.code,{children:"[user]"})," from ",(0,s.jsx)(i.code,{children:"live_video_viewer"}),", ",(0,s.jsx)(i.code,{children:"recorded_video_viewer"})," and ",(0,s.jsx)(i.code,{children:"device_renamer"}),". This denies direct relations to ",(0,s.jsx)(i.code,{children:"live_video_viewer"}),", ",(0,s.jsx)(i.code,{children:"recorded_video_viewer"})," and ",(0,s.jsx)(i.code,{children:"device_renamer"})," from having an effect. To do this:"]}),"\n",(0,s.jsx)(t.pB,{configuration:{schema_version:"1.1",type_definitions:[{type:"user"},{type:"device",relations:{it_admin:{this:{}},security_guard:{this:{}},live_video_viewer:{union:{child:[{computedUserset:{relation:"it_admin"}},{computedUserset:{relation:"security_guard"}}]}},recorded_video_viewer:{union:{child:[{computedUserset:{relation:"it_admin"}},{computedUserset:{relation:"security_guard"}}]}},device_renamer:{union:{child:[{computedUserset:{relation:"it_admin"}}]}}},metadata:{relations:{it_admin:{directly_related_user_types:[{type:"user"},{type:"device_group",relation:"it_admin"}]},security_guard:{directly_related_user_types:[{type:"user"},{type:"device_group",relation:"security_guard"}]}}}},{type:"device_group",relations:{it_admin:{this:{}},security_guard:{this:{}}},metadata:{relations:{it_admin:{directly_related_user_types:[{type:"user"}]},security_guard:{directly_related_user_types:[{type:"user"}]}}}}]}}),"\n",(0,s.jsxs)(i.admonition,{type:"info",children:[(0,s.jsxs)(i.p,{children:["Notice that any reference to the ",(0,s.jsx)(i.a,{href:"/docs/configuration-language#direct-relationship-type-restrictions",children:(0,s.jsx)(i.strong,{children:"direct relationship type restrictions"})})," has been removed. That indicates that a user cannot have a ",(0,s.jsx)(t.OK,{section:"what-are-direct-and-implied-relationships",linkName:"direct relationship"})," with an object in this type."]}
1),(0,s.jsxs)(i.p,{children:["With this change, ",(0,s.jsx)(i.code,{children:"anne"})," can no longer have a ",(0,s.jsx)(i.code,{children:"live_video_viewer"})," permission for ",(0,s.jsx)(i.code,{children:"device:1"})," except through having a ",(0,s.jsx)(i.code,{children:"security_guard"})," or ",(0,s.jsx)(i.code,{children:"it_admin"})," role first, and when she loses access to that role, she will automatically lose access to the ",(0,s.jsx)(i.code,{children:"live_video_viewer"})," permission."]})]}),"\n",(0,s.jsx)(i.h4,{id:"verification-3",children:"Verification"}),"\n",(0,s.jsxs)(i.p,{children:["Now that direct relationship is denied, we should see that ",(0,s.jsx)(i.code,{children:"anne"})," has ",(0,s.jsx)(i.code,{children:"live_video_viewer"})," relation to ",(0,s.jsx)(i.code,{children:"device:1"})," solely based on her position as ",(0,s.jsx)(i.code,{children:"security_guard"})," to ",(0,s.jsx)(i.code,{children:"device:1"}),". Let's find out."]}),"\n",(0,s.jsxs)(i.p,{children:["To test this, we can add a new user ",(0,s.jsx)(i.code,{children:"emily"}),". Emily is ",(0,s.jsx)(i.strong,{children:"not"})," a ",(0,s.jsx)(i.code,{children:"security_guard"})," nor an ",(0,s.jsx)(i.code,{children:"it_admin"}),". However, we attempt to access via direct relations by adding the following ",(0,s.jsx)(t.OK,{section:"what-is-a-relationship-tuple",linkName:"relationship tuples"}),":"]}),"\n",(0,s.jsx)(t.dp,{relationshipTuples:[{user:"user:emily",relation:"live_video_viewer",object:"device:1"},{user:"user:emily",relation:"recorded_video_viewer",object:"device:1"},{user:"user:emily",relation:"device_renamer",object:"device:1"}]}),"\n",(0,s.jsxs)(i.p,{children:["Now try to query ",(0,s.jsx)(i.code,{children:"is emily related to device:1 as live_video_viewer?"}),". The returned result should be ",(0,s.jsx)(i.code,{children:"emily is not related to device:1 as live_video_viewer"}),". This confirms that direct relations have no effect on the ",(0,s.jsx)(i.code,{children:"live_video_viewer"})," relations, and that is because the ",(0,s.jsx)(i.a,{href:"/docs/configuration-language#direct-relationship-type-restrictions",children:(0,s.jsx)(i.strong,{children:"direct relationship type restriction"})})," was removed from the relation configuration."]}),"\n",(0,s.jsx)(t.ou,{user:"user:emily",relation:"live_video_viewer",object:"device:1",allowed:!1}),"\n",(0,s.jsx)(i.p,{children:"Query on the other relationships and you will see:"}),"\n",(0,s.jsxs)(i.table,{children:[(0,s.jsx)(i.thead,{children:(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.th,{children:"User"}),(0,s.jsx)(i.th,{children:"Object"}),(0,s.jsx)(i.th,{children:"Relation"}),(0,s.jsx)(i.th,{children:"Query"}),(0,s.jsx)(i.th,{children:"Relation?"})]})}),(0,s.jsxs)(i.tbody,{children:[(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"emily"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"recorded_video_viewer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is emily related to device:1 as recorded_video_viewer?"})}),(0,s.jsx)(i.td,{children:"No"})]}),(0,s.jsxs)(i.tr,{children:[(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"emily"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device:1"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"device_renamer"})}),(0,s.jsx)(i.td,{children:(0,s.jsx)(i.code,{children:"is emily related to device:1 as device_renamer?"})}),(0,s.jsx)(i.td,{children:"No"})]})]})]}),"\n",(0,s.jsx)(i.h2,{id:"summary",children:"Summary"}),"\n",(0,s.jsxs)(i.p,{children:["In this post, you were introduced to ",(0,s.jsx)(t.i4,{linkName:"fine grain authentication",section:"what-is-fine-grained-authorization"})," and ",(0,s.jsx)(t.bU,{format:t.Ed.LongForm}),"."]}),"\n",(0,s.jsxs)(i.p,{children:["Upcoming posts will dive deeper into ",(0,s.jsx)(t.bU,{format:t.Ed.LongForm}),", introducing concepts that will improve on the model you built today, and tackling more complex permission systems, with more relations and requirements that need to be met."]}),"\n",(0,s.jsx)(t.QF,{title:"IoT",preset:"iot",example:"IoT",store:"iot"}),"\n",(0,s.jsx)(i.h3,{id:"exercises-for-you",children:"Exercises for you"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsx)(i.li,{children:"Try adding a second group tied to devices 4 and 5. Add only Charles and Dianne to this group, then try to run queries that would validate your model."}),"\n",(0,s.jsx)(i.li,{children:"Management has decided that Security Guards can only access live videos, and instituted a new position called Security Officer who can view both live and recorded videos.
1Can you update the authorization model to reflect that?"}),"\n"]})]})}function j(e={}){const{wrapper:i}={...(0,n.R)(),...e.components};return i?(0,s.jsx)(i,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},16206(e,i,d){d.d(i,{A:()=>r});const r=d.p+"assets/images/iot-01-01e62d5f3e91ef20a4f763fb2079c1fa.svg"}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.