1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import random
pdp_name = "pdp1"
policy_name = "Session policy example"
model_name = "Session"
policy_genre = "session"
SUBJECT_NUMBER = 200
OBJECT_NUMBER = 200
ROLE_NUMBER = 100
subjects = {}
for _id in range(SUBJECT_NUMBER):
subjects["user{}".format(_id)] = ""
objects = {"admin": "", }
for _id in range(ROLE_NUMBER):
objects["role{}".format(_id)] = ""
actions = {"activate": "", "deactivate": ""}
subject_categories = {"subjectid": "", }
object_categories = {"role": "", }
action_categories = {"session-action": "", }
subject_data = {"subjectid": {}}
for _id in range(SUBJECT_NUMBER):
subject_data["subjectid"]["user{}".format(_id)] = ""
object_data = {"role": {
"admin": "",
"*": ""
}}
for _id in range(ROLE_NUMBER):
object_data["role"]["role{}".format(_id)] = ""
action_data = {"session-action": {"activate": "", "deactivate": "", "*": ""}}
subject_assignments = {}
for _id in range(SUBJECT_NUMBER):
subject_assignments["user{}".format(_id)] = ({"subjectid": "user{}".format(_id)}, )
object_assignments = {"admin": ({"role": "admin"}, {"role": "*"})}
for _id in range(ROLE_NUMBER):
_role = "role{}".format(_id)
object_assignments[_role] = ({"role": _role}, {"role": "*"})
action_assignments = {"activate": ({"session-action": "activate"}, {"session-action": "*"}, ),
"deactivate": ({"session-action": "deactivate"}, {"session-action": "*"}, )
}
meta_rule = {
"session": {"id": "", "value": ("subjectid", "role", "session-action")},
}
rules = {
"session": []
}
for _id in range(SUBJECT_NUMBER):
_subject = "user{}".format(_id)
_object = "role{}".format(random.choice(range(ROLE_NUMBER)))
rules["session"].append({
"rule": (_subject, _object, "*"),
"instructions": (
{
"update": {
"operation": "add",
"target": "rbac:role:admin" # add the role admin to the current user
}
},
{"chain": {"name": "rbac"}} # chain with the meta_rule named rbac
)
})
|