wide-machine-60917
04/27/2023, 8:56 AMchilly-king-10285
04/27/2023, 8:56 AMwide-machine-60917
04/27/2023, 8:56 AMchilly-king-10285
04/27/2023, 8:56 AMchilly-king-10285
04/27/2023, 8:56 AMchilly-king-10285
04/27/2023, 8:56 AMwide-machine-60917
04/27/2023, 8:57 AMchilly-king-10285
04/27/2023, 8:57 AMchilly-king-10285
04/27/2023, 8:58 AMOwner
, LegalEntity
, and Employee
. The objects could be the resources you want to manage access for, such as AttributeGroup
and any other relevant objects. 2. Define the relationships between the objects and subjects. Here's an example of how you can define the namespaces and relationships using OPL: typescript import { Namespace, Context } from "@ory/keto-namespace-types" class Owner implements Namespace {} class LegalEntity implements Namespace {} class Employee implements Namespace {} class AttributeGroup implements Namespace { related: { owners: Owner[] legalEntities: LegalEntity[] employees: Employee[] } } // Add other relevant objects and their relationships here
3. Define the permissions for each object in the OPL. For example, you can define the create
, view
, and assign
permissions for the AttributeGroup
object. 4. Test your permission model to ensure it works as expected. For more information on creating a permission model and defining namespaces, refer to the following Ory documentation: - [Namespaces](https://www.ory.sh/docs/keto/concepts/namespaces) - [Create a permission model](https://www.ory.sh/docs/keto/modeling/create-permission-model) Remember that this is just a starting point, and you may need to adjust the model based on your specific requirements and use case.wide-machine-60917
04/27/2023, 10:20 AMchilly-king-10285
04/27/2023, 10:20 AMchilly-king-10285
04/27/2023, 10:21 AMtypescript class User implements Namespace { related: { manager: User[] } }
manager
is a relationship defined within the User
namespace. It represents a many-to-many relationship between users, where one user can be a manager of other users. The manager
relationship is an array of User
objects, indicating that a user can have multiple managers. This relationship can be used to model scenarios where users have managers, and you want to control access to resources based on the manager-user relationship.wide-machine-60917
04/27/2023, 10:23 AMchilly-king-10285
04/27/2023, 10:23 AMchilly-king-10285
04/27/2023, 10:23 AMUser
as the subject and LegalEntity
as the object, and define the read
and write
access relationships using the Ory Permission Language (OPL). Here's an example: typescript import { Namespace, Context } from "@ory/keto-namespace-types" class User implements Namespace {} class LegalEntity implements Namespace { related: { readers: User[] writers: User[] } permits = { read: (ctx: Context): boolean => this.related.readers.includes(ctx.subject), write: (ctx: Context): boolean => this.related.writers.includes(ctx.subject), } }
In this example, the LegalEntity
namespace has two relationships: readers
and writers
. These relationships represent users who have read and write access to the legal entity, respectively. The permits
object defines the read
and write
permissions based on the relationships. A user has read access if they are in the readers
relationship, and write access if they are in the writers
relationship. Some users can have both read and write access if they are included in both relationships.wide-machine-60917
04/27/2023, 10:59 AMchilly-king-10285
04/27/2023, 10:59 AMchilly-king-10285
04/27/2023, 10:59 AMSubjectSet
is a concept in Ory Keto that refers to all subjects who have the same relation
on an object
. It allows Ory Permissions to be flexible by defining indirections, which can be used to realize models like RBAC (Role-Based Access Control) or inheritance of relations. Subject sets can also indirect to other subject sets. In the context of a graph of relations, subject sets represent all intermediary nodes. Here's a brief overview of the SubjectSet
fields: - `namespace`: The namespace of the object and relation referenced in this subject set. - `object`: The object related by this subject set. - `relation`: The relation between the object and the subjects. For more information, refer to the following extracts: - [Subject sets in Ory Keto concepts](https://www.ory.sh/docs/keto/concepts/subjects#subject-sets) - [SubjectSet in Ory Keto Protocol Documentation](https://www.ory.sh/docs/keto/reference/proto-api#subjectset)wide-machine-60917
04/27/2023, 12:45 PMchilly-king-10285
04/27/2023, 12:45 PMchilly-king-10285
04/27/2023, 12:45 PMwide-machine-60917
04/27/2023, 2:12 PMclass User implements Namespace {}
class LegalEntity implements Namespace {
related: {
readers: User[]
writers: User[]
}
permits = {
read: (ctx: Context): boolean =>
this.related.readers.includes(ctx.subject) ||
this.related.writers.includes(ctx.subject),
write: (ctx: Context): boolean => this.related.writers.includes(ctx.subject),
}
}
chilly-king-10285
04/27/2023, 2:12 PMchilly-king-10285
04/27/2023, 2:12 PM