File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ import fnmatch
2
+
3
+ from mlflow_oidc_auth .config import config
4
+
5
+
6
+ def token_get_user_groups (token : dict ) -> list [str ]:
7
+ """Retrieve the list of groups this user (based on the provided token) is a member of
8
+
9
+ Args:
10
+ token: dictionary holding the oidc token information
11
+
12
+ Returns:
13
+ list of all the groups this user is a member of
14
+ """
15
+ user_groups = []
16
+
17
+ if config .OIDC_GROUP_DETECTION_PLUGIN :
18
+ import importlib
19
+
20
+ user_groups = importlib .import_module (config .OIDC_GROUP_DETECTION_PLUGIN ).get_user_groups (token ["access_token" ])
21
+ else :
22
+ user_groups = token ["userinfo" ][config .OIDC_GROUPS_ATTRIBUTE ]
23
+
24
+ # Now filter the user groups to keep only those matching the pattern or the ADMIN group
25
+ user_groups = sorted (
26
+ set (
27
+ [
28
+ g
29
+ for g in user_groups
30
+ if (g == config .OIDC_ADMIN_GROUP_NAME ) or any (fnmatch .fnmatch (g , p ) for p in config .OIDC_GROUP_FILTER_PATTERNS )
31
+ ]
32
+ )
33
+ )
34
+
35
+ return user_groups
36
+
37
+
38
+ def token_get_user_is_admin (user_groups : list [str ]):
39
+ """Check if the admin group is included in the user_groups. In that case
40
+ it means that the user is an admin user
41
+
42
+ Args:
43
+ user_groups (list[str]): list of the groups the current user belongs to
44
+
45
+ Returns:
46
+ True if the admin group is in the list of the groups of the current user, False otherwise
47
+
48
+ """
49
+ is_admin = False
50
+
51
+ if config .OIDC_ADMIN_GROUP_NAME in user_groups :
52
+ is_admin = True
53
+
54
+ return is_admin
You can’t perform that action at this time.
0 commit comments