perun.proxy.utils 2.5.2__tar.gz → 2.5.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/PKG-INFO +9 -2
  2. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/README.md +8 -1
  3. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/sync_usable_token_types.py +32 -25
  4. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun.proxy.utils.egg-info/PKG-INFO +9 -2
  5. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/setup.cfg +1 -1
  6. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/LICENSE +0 -0
  7. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/__init__.py +0 -0
  8. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/metadata_expiration.py +0 -0
  9. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/__init__.py +0 -0
  10. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_custom_command.py +0 -0
  11. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_dockers.py +0 -0
  12. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_exabgp_propagation.py +0 -0
  13. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_ldap.py +0 -0
  14. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_ldap_syncrepl.py +0 -0
  15. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_mongodb.py +0 -0
  16. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_nginx.py +0 -0
  17. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_pgsql.py +0 -0
  18. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_php_syntax.py +0 -0
  19. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_privacyidea.py +0 -0
  20. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_rpc_status.py +0 -0
  21. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_saml.py +0 -0
  22. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/check_user_logins.py +0 -0
  23. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/nagios/webserver_availability.py +0 -0
  24. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/print_docker_versions.py +0 -0
  25. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/run_probes.py +0 -0
  26. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/run_version_script.py +0 -0
  27. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/separate_oidc_logs.py +0 -0
  28. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun/proxy/utils/separate_ssp_logs.py +0 -0
  29. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun.proxy.utils.egg-info/SOURCES.txt +0 -0
  30. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun.proxy.utils.egg-info/dependency_links.txt +0 -0
  31. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun.proxy.utils.egg-info/entry_points.txt +0 -0
  32. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun.proxy.utils.egg-info/requires.txt +0 -0
  33. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/perun.proxy.utils.egg-info/top_level.txt +0 -0
  34. {perun.proxy.utils-2.5.2 → perun.proxy.utils-2.5.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: perun.proxy.utils
3
- Version: 2.5.2
3
+ Version: 2.5.4
4
4
  Summary: Utilities and monitoring probes for Perun ProxyIdP
5
5
  Home-page: https://gitlab.ics.muni.cz/perun/perun-proxyidp/perun-proxy-utils.git
6
6
  Requires-Python: >=3.9
@@ -111,9 +111,16 @@ run_version_script --help
111
111
  ### sync_usable_token_types.py
112
112
 
113
113
  Collects information about the usable token types of each privacyIDEA user and sends it
114
- to Perun. Each user with usable tokens in privacyIDEA is assigned a list of their types, for example: `['backupcode', 'totp']`. A token is considered usable when it is **active** and it is not **locked** or
114
+ to Perun. Each user with usable tokens in privacyIDEA is assigned a list of their types,
115
+ for example: `['backupcode', 'totp']`. A token is considered usable when it is **active
116
+ ** and it is not **locked** or
115
117
  **revoked** and its rollout state allows logging in.
116
118
 
119
+ Requires configuration
120
+ of [perun connector](https://gitlab.ics.muni.cz/perun/perun-proxyidp/perun-connector)
121
+ module to work properly. It also needs to be executed in the same environment as
122
+ privacyIDEA to acquire its Flask context (e.g. inside privacyIDEA docker container).
123
+
117
124
  For more usage instructions, run:
118
125
 
119
126
  ```sh
@@ -86,9 +86,16 @@ run_version_script --help
86
86
  ### sync_usable_token_types.py
87
87
 
88
88
  Collects information about the usable token types of each privacyIDEA user and sends it
89
- to Perun. Each user with usable tokens in privacyIDEA is assigned a list of their types, for example: `['backupcode', 'totp']`. A token is considered usable when it is **active** and it is not **locked** or
89
+ to Perun. Each user with usable tokens in privacyIDEA is assigned a list of their types,
90
+ for example: `['backupcode', 'totp']`. A token is considered usable when it is **active
91
+ ** and it is not **locked** or
90
92
  **revoked** and its rollout state allows logging in.
91
93
 
94
+ Requires configuration
95
+ of [perun connector](https://gitlab.ics.muni.cz/perun/perun-proxyidp/perun-connector)
96
+ module to work properly. It also needs to be executed in the same environment as
97
+ privacyIDEA to acquire its Flask context (e.g. inside privacyIDEA docker container).
98
+
92
99
  For more usage instructions, run:
93
100
 
94
101
  ```sh
@@ -1,10 +1,12 @@
1
1
  import argparse
2
2
  import os
3
3
  import re
4
+ from collections import defaultdict
4
5
  from typing import List, Tuple, Optional, Pattern
5
6
 
6
7
  import yaml
7
8
  from perun.connector import AdaptersManager
9
+ from privacyidea.app import create_app
8
10
  from privacyidea.models import db, TokenOwner, Token
9
11
  from sqlalchemy import tuple_
10
12
 
@@ -13,6 +15,9 @@ PERUN_USER_ID_REGEX = r"perunUserId=(?P<perun_user_id>\d+),"
13
15
  MFA_ACTIVE_TOKENS_ATTR_NAME = "urn:perun:user:attribute-def:def:mfaTokenTypes:mu"
14
16
  PERUN_CONNECTOR_CONFIG_PATH = "/etc/perun-connector.yaml"
15
17
 
18
+ # create app to have access to Flask application context
19
+ app = create_app(config_name="development")
20
+
16
21
 
17
22
  class ROLLOUTSTATE(object):
18
23
  CLIENTWAIT = "clientwait"
@@ -57,7 +62,9 @@ def get_args():
57
62
  """
58
63
  Supports the command-line arguments listed below.
59
64
  """
60
- parser = argparse.ArgumentParser(description="SAML authentication check")
65
+ parser = argparse.ArgumentParser(
66
+ description="Collects information about the usable token types of each privacyIDEA user and sends it to Perun."
67
+ )
61
68
  parser._optionals.title = "Options"
62
69
  parser.add_argument(
63
70
  "--mfa-active-tokens-attr-name",
@@ -87,22 +94,24 @@ def get_user_token_types() -> List[Tuple[str, str]]:
87
94
  for token_type, usable_states_lst in USABLE_ROLLOUT_STATES.items()
88
95
  for usable_state in usable_states_lst
89
96
  ]
90
- user_token_types = (
91
- db.session.query(TokenOwner.user_id, Token.tokentype)
92
- .join(Token, Token.id == TokenOwner.token_id)
93
- .filter(Token.active.is_(True))
94
- .filter(Token.locked.is_(False))
95
- .filter(Token.revoked.is_(False))
96
- .filter(
97
- tuple_(Token.tokentype, Token.rollout_state).in_(
98
- usable_rollout_states_tuples
97
+
98
+ with app.app_context():
99
+ user_token_types = (
100
+ db.session.query(TokenOwner.user_id, Token.tokentype)
101
+ .join(Token, Token.id == TokenOwner.token_id)
102
+ .filter(Token.active.is_(True))
103
+ .filter(Token.locked.is_(False))
104
+ .filter(Token.revoked.is_(False))
105
+ .filter(
106
+ tuple_(Token.tokentype, Token.rollout_state).in_(
107
+ usable_rollout_states_tuples
108
+ )
99
109
  )
110
+ .distinct(TokenOwner.user_id, Token.tokentype)
111
+ .order_by(TokenOwner.user_id)
112
+ .all()
100
113
  )
101
- .distinct(TokenOwner.user_id, Token.tokentype)
102
- .order_by(TokenOwner.user_id)
103
- .all()
104
- )
105
- return user_token_types
114
+ return user_token_types
106
115
 
107
116
 
108
117
  def parse_perun_user_id(
@@ -120,18 +129,16 @@ def main():
120
129
  mfa_active_tokens_attr_name = args.mfa_active_tokens_attr_name
121
130
  adapters_manager = get_adapters_manager(args.perun_connector_config_path)
122
131
  user_token_types = get_user_token_types()
123
- current_user_id = ""
124
- current_user_token_types = []
132
+ user_all_usable_tokens = defaultdict(list)
133
+
125
134
  for privacyidea_user_id, token_type in user_token_types:
126
135
  perun_user_id = parse_perun_user_id(perun_user_id_regex, privacyidea_user_id)
127
- if perun_user_id and perun_user_id != current_user_id:
128
- if current_user_id:
129
- current_user_token_types.sort()
130
- attr_to_set = {mfa_active_tokens_attr_name: current_user_token_types}
131
- adapters_manager.set_user_attributes(int(perun_user_id), attr_to_set)
132
- current_user_id = perun_user_id
133
- current_user_token_types = []
134
- current_user_token_types.append(token_type)
136
+ user_all_usable_tokens[perun_user_id].append(token_type)
137
+
138
+ for perun_user_id, token_types in user_all_usable_tokens.items():
139
+ token_types.sort()
140
+ attr_to_set = {mfa_active_tokens_attr_name: token_types}
141
+ adapters_manager.set_user_attributes(int(perun_user_id), attr_to_set)
135
142
 
136
143
 
137
144
  if __name__ == "__main__":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: perun.proxy.utils
3
- Version: 2.5.2
3
+ Version: 2.5.4
4
4
  Summary: Utilities and monitoring probes for Perun ProxyIdP
5
5
  Home-page: https://gitlab.ics.muni.cz/perun/perun-proxyidp/perun-proxy-utils.git
6
6
  Requires-Python: >=3.9
@@ -111,9 +111,16 @@ run_version_script --help
111
111
  ### sync_usable_token_types.py
112
112
 
113
113
  Collects information about the usable token types of each privacyIDEA user and sends it
114
- to Perun. Each user with usable tokens in privacyIDEA is assigned a list of their types, for example: `['backupcode', 'totp']`. A token is considered usable when it is **active** and it is not **locked** or
114
+ to Perun. Each user with usable tokens in privacyIDEA is assigned a list of their types,
115
+ for example: `['backupcode', 'totp']`. A token is considered usable when it is **active
116
+ ** and it is not **locked** or
115
117
  **revoked** and its rollout state allows logging in.
116
118
 
119
+ Requires configuration
120
+ of [perun connector](https://gitlab.ics.muni.cz/perun/perun-proxyidp/perun-connector)
121
+ module to work properly. It also needs to be executed in the same environment as
122
+ privacyIDEA to acquire its Flask context (e.g. inside privacyIDEA docker container).
123
+
117
124
  For more usage instructions, run:
118
125
 
119
126
  ```sh
@@ -1,5 +1,5 @@
1
1
  [metadata]
2
- version = 2.5.2
2
+ version = 2.5.4
3
3
  license_files = LICENSE
4
4
  long_description = file: README.md
5
5
  long_description_content_type = text/markdown