<@U04UQ68083H> Build be the request to configure t...
# ory-copilot
b
@chilly-king-10285 Build be the request to configure the next relation tuple. I have subject_id: superuser in Keto server that has relations to all my objects (read, write, delete). Now I want to create the relation so the user with email X will be "member" of superuser. So what superuser can do the user with email X also can. Here is the example of my requests: PATCH http://localhost:4467/admin/relation-tuples/ body: [ { "action": "insert", "relation_tuple": { "namespace": "data-reference-app", "object": "country", "relation": "read", "subject_id": "superuser" } } ] Now I want to connect user with Email X to the super user, so the user with email X can also read country. Is that clear?
c
A message from kapa.ai
Yes, your requirement is clear. You want to create a relationship where a user with email X has the same permissions as the 'superuser'. This can be achieved by creating a relationship where the 'superuser' is the 'subject_set' and the user with email X is the 'subject_id'. Here is an example of how you can structure your request:
Copy code
json PUT <http://localhost:4467/admin/relation-tuples/> {   "namespace": "data-reference-app",   "object": "country",   "relation": "read",   "subject_id": "user_with_email_X",   "subject_set": {     "namespace": "data-reference-app",     "object": "country",     "relation": "read"   } }
In this request, 'user_with_email_X' is the 'subject_id' and the 'superuser' is represented as the 'subject_set'. This means that 'user_with_email_X' will have the same permissions as the 'superuser'. Please replace 'user_with_email_X' with the actual email of the user. This is based on the information provided in the [Ory Keto API documentation](https://www.ory.sh/docs/keto/reference/rest-api) for creating a relationship.
b
@chilly-king-10285 I do not understand how adding this subject_set:
Copy code
"subject_set": {
    "namespace": "data-reference-app",
    "object": "country",
    "relation": "read"
  }
We are connecting user_with_email_X to superuser Explain it to me
c
A message from kapa.ai
In Ory Keto, a subject set is a set of all subjects that have a specific relation on an object. In your case, the 'superuser' has a 'read' relation on the 'country' object in the 'data-reference-app' namespace. This is represented as a subject set. When you add this subject set to the relation tuple for 'user_with_email_X', you are essentially saying that 'user_with_email_X' has the same permissions as all subjects in the subject set. Since the 'superuser' is the only subject in this set, 'user_with_email_X' will have the same permissions as the 'superuser'. However, I apologize for the confusion, but upon reviewing the knowledge sources, it seems there might be a misunderstanding. The 'subject_set' field in the relation tuple is not used to inherit permissions from another user. Instead, it is used to define a set of subjects that have a specific relation on an object. To achieve your requirement of having 'user_with_email_X' inherit permissions from 'superuser', you would need to implement this logic in your application. This could be done by checking if a user is a 'member' of 'superuser' and then granting them the same permissions. For more information on subjects and subject sets, you can refer to the [Ory Keto documentation on subjects](https://www.ory.sh/docs/keto/concepts/subjects).
b
@chilly-king-10285 how I can implement this logic? To achieve your requirement of having 'user_with_email_X' inherit permissions from 'superuser', you would need to implement this logic in your application. This could be done by checking if a user is a 'member' of 'superuser' and then granting them the same permissions.
c
A message from kapa.ai
To implement this logic, you would need to create a new relation that represents the 'member' relationship between 'user_with_email_X' and 'superuser'. Then, when checking permissions for 'user_with_email_X', you would also check if they are a 'member' of 'superuser' and if so, grant them the same permissions. Here's a high-level overview of how you could implement this: 1. Create a 'member' relation: You would need to create a new relation that represents the 'member' relationship. This could be done by creating a new relation tuple where 'user_with_email_X' is the 'subject_id' and 'superuser' is the 'object'. The 'relation' would be 'member'. Here's an example of how you could structure this request:
Copy code
json PUT <http://localhost:4467/admin/relation-tuples/> {{   "namespace": "data-reference-app",   "object": "superuser",   "relation": "member",   "subject_id": "user_with_email_X" }}
2. Check 'member' relation when checking permissions: When checking if 'user_with_email_X' has a certain permission, you would also need to check if they are a 'member' of 'superuser'. If they are, you would grant them the same permissions as 'superuser'. This would require modifying your permission checking logic in your application. Please note that this is a high-level overview and the exact implementation would depend on the specifics of your application and how you have set up your Ory Keto server. For more information on how to work with relation tuples in Ory Keto, you can refer to the [Ory Keto documentation](https://www.ory.sh/docs/keto/).
b
@chilly-king-10285 is there is a way to configure keto so it says me my role based on my email?
c
A message from kapa.ai
Yes, you can configure Ory Keto to determine a user's role based on their email. This involves creating relation tuples that associate a user (identified by their email) with a specific role. Here's an example of how you could structure a relation tuple to associate a user with a role:
Copy code
json PUT <http://localhost:4467/admin/relation-tuples/> {{   "namespace": "roles",   "object": "admin",   "relation": "member",   "subject_id": "user_with_email_X" }}
In this example, 'user_with_email_X' is the user's email and 'admin' is the role. The 'relation' is 'member', indicating that the user is a member of the 'admin' role. To check a user's role, you would use the
keto relation-tuple get
command with the user's email as the
--subject-id
parameter. Here's an example:
Copy code
bash keto relation-tuple get --subject-id=user_with_email_X --relation=member --format json --read-remote localhost:4466
This command would return a list of all relation tuples where the user is the subject, allowing you to determine their role. Please replace 'user_with_email_X' with the actual email of the user. For more information on how to work with relation tuples in Ory Keto, you can refer to the [Ory Keto documentation](https://www.ory.sh/docs/keto/guides/rbac#creating-relationships).