Skip to content

Commit 7bf0197

Browse files
committed
Manually merge PR166 to add auto sign up for externally authenticated users with active peer acceptance even if they don't fit the direct auto sign up filters.
git-svn-id: svn+ssh://svn.code.sf.net/p/migrid/code/trunk@6180 b75ad72c-e7d7-11dd-a971-7dbc132099af
1 parent 1003ad3 commit 7bf0197

File tree

6 files changed

+60
-7
lines changed

6 files changed

+60
-7
lines changed

mig/install/MiGserver-template.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ auto_add_filter_method = __AUTO_ADD_FILTER_METHOD__
3030
# auth methods explicitly enabled with auto_add_X_user. Space separated list of
3131
# user field and regexp-filter pattern pairs separated by colons.
3232
auto_add_user_permit = __AUTO_ADD_USER_PERMIT__
33+
# Optional limit on users who may sign up through autocreate without operator
34+
# interaction if a valid peer exists. Defaults to allow ANY distinguished name
35+
# if unset but only for auth methods explicitly enabled with auto_add_X_user.
36+
# Space separated list of user field and regexp-filter pattern pairs separated
37+
# by colons.
38+
auto_add_user_with_peer = __AUTO_ADD_USER_WITH_PEER__
3339
# Default account expiry unless set. Renew and web login extends by default.
3440
cert_valid_days = __CERT_VALID_DAYS__
3541
oid_valid_days = __OID_VALID_DAYS__

mig/install/generateconfs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def main(argv, _generate_confs=generate_confs, _print=print):
7272
'auto_add_filter_fields',
7373
'auto_add_filter_method',
7474
'auto_add_user_permit',
75+
'auto_add_user_with_peer',
7576
'base_fqdn',
7677
'public_fqdn',
7778
'public_alias_fqdn',

mig/shared/accountreq.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,17 +1243,41 @@ def user_manage_commands(configuration, mig_user, req_path, user_id, user_dict,
12431243
return cmd_helpers
12441244

12451245

1246-
def auto_add_user_allowed(configuration, user_dict):
1246+
def __auto_add_user_allowed(configuration, user_dict, permit_list):
12471247
"""Check if user with user_dict is allowed to sign up without operator
1248-
approval e.g. using autocreate based on optional configuration limits.
1248+
approval e.g. using autocreate based on optional configuration limits in
1249+
given permit_list of fields and regex values. Always fail if permit_list
1250+
is empty.
12491251
"""
12501252

1251-
for (key, val) in configuration.auto_add_user_permit:
1253+
if not permit_list:
1254+
return False
1255+
for (key, val) in permit_list:
12521256
if not re.match(val, user_dict.get(key, 'NO SUCH FIELD')):
12531257
return False
12541258
return True
12551259

12561260

1261+
def auto_add_user_allowed_direct(configuration, user_dict):
1262+
"""Check if user with user_dict is allowed to sign up directly e.g. using
1263+
autocreate without operator or peer approval. The check is based on
1264+
optional configuration limits and must match all such permit expressions.
1265+
"""
1266+
return __auto_add_user_allowed(configuration, user_dict,
1267+
configuration.auto_add_user_permit)
1268+
1269+
1270+
def auto_add_user_allowed_with_peer(configuration, user_dict):
1271+
"""Check if user with user_dict is allowed to sign up with peer acceptance
1272+
e.g. using autocreate without explicit operator approval. The check is
1273+
based on optional configuration limits and must match all such permit
1274+
expressions.
1275+
"""
1276+
1277+
return __auto_add_user_allowed(configuration, user_dict,
1278+
configuration.auto_add_user_with_peer)
1279+
1280+
12571281
def peers_permit_allowed(configuration, user_dict):
12581282
"""Check if user with user_dict is allowed to manage peers based on
12591283
optional configuration limits.

mig/shared/configuration.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def fix_missing(config_file, verbose=True):
139139
'auto_add_oidc_user': False,
140140
'auto_add_resource': False,
141141
'auto_add_user_permit': 'distinguished_name:.*',
142+
'auto_add_user_with_peer': 'distinguished_name:.*',
142143
'auto_add_filter_method': '',
143144
'auto_add_filter_fields': '',
144145
'server_fqdn': fqdn,
@@ -671,6 +672,7 @@ def fix_missing(config_file, verbose=True):
671672
'auto_add_oidc_user': False,
672673
'auto_add_resource': False,
673674
'auto_add_user_permit': [('distinguished_name', '.*')],
675+
'auto_add_user_with_peer': [('distinguished_name', '.*')],
674676
'auto_add_filter_method': '',
675677
'auto_add_filter_fields': [],
676678

@@ -2605,12 +2607,21 @@ def reload_config(self, verbose, skip_log=False, disable_auth_log=False,
26052607
if config.has_option('GLOBAL', 'auto_add_resource'):
26062608
self.auto_add_resource = config.getboolean('GLOBAL',
26072609
'auto_add_resource')
2608-
# Limit sign up without operator interaction using ID fields regex.
2610+
# Limit direct sign up without operator interaction using ID field and
2611+
# regex pairs.
26092612
# For autocreate auto_add_X_user must be True and auto_add_user_permit
26102613
# specification must match actual user on all given fields.
26112614
if config.has_option('GLOBAL', 'auto_add_user_permit'):
26122615
req = config.get('GLOBAL', 'auto_add_user_permit').split()
26132616
self.auto_add_user_permit = [i.split(':', 2) for i in req]
2617+
# Limit peer accepted sign up without operator interaction using ID
2618+
# field and regex pairs.
2619+
# For autocreate auto_add_X_user must be True and
2620+
# auto_add_user_with_peer specification must match actual user on all
2621+
# given fields. Plus an active peer acceptance to match must exist.
2622+
if config.has_option('GLOBAL', 'auto_add_user_with_peer'):
2623+
req = config.get('GLOBAL', 'auto_add_user_with_peer').split()
2624+
self.auto_add_user_with_peer = [i.split(':', 2) for i in req]
26142625

26152626
# Apply requested automatic filtering of selected auto add user fields
26162627
if config.has_option('GLOBAL', 'auto_add_filter_method'):

mig/shared/functionality/autocreate.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
Also see req-/extcertaction.py
3434
Differences:
3535
- automatic upload of a proxy certificate when provided
36-
- no special check for KU organization
36+
- no special check for organization and email match
3737
- allows empty fields for things like country, email, and state
3838
"""
3939

@@ -44,7 +44,8 @@
4444
import time
4545

4646
from mig.shared import returnvalues
47-
from mig.shared.accountreq import auto_add_user_allowed
47+
from mig.shared.accountreq import auto_add_user_allowed_direct, \
48+
auto_add_user_allowed_with_peer
4849
from mig.shared.accountstate import default_account_expire
4950
from mig.shared.bailout import filter_output_objects
5051
from mig.shared.base import client_id_dir, canonical_user, mask_creds, \
@@ -726,7 +727,13 @@ def main(client_id, user_arguments_dict, environ=None):
726727
configuration.auto_add_oidc_user:
727728
fill_user(user_dict)
728729

729-
if not auto_add_user_allowed(configuration, user_dict):
730+
if auto_add_user_allowed_direct(configuration, user_dict):
731+
logger.debug('autocreate directly permitted for %s' % client_id)
732+
elif auto_add_user_allowed_with_peer(configuration, user_dict):
733+
logger.debug('autocreate only permitted with peer for %s' %
734+
client_id)
735+
peer_pattern = keyword_auto
736+
else:
730737
logger.warning('autocreate not permitted for %s' % client_id)
731738
output_objects.append({
732739
'object_type': 'error_text', 'text':

mig/shared/install.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def generate_confs(
327327
auto_add_filter_fields='',
328328
auto_add_filter_method='skip',
329329
auto_add_user_permit='distinguished_name:.*',
330+
auto_add_user_with_peer='distinguished_name:.*',
330331
cert_valid_days=365,
331332
oid_valid_days=365,
332333
oidc_valid_days=365,
@@ -644,6 +645,7 @@ def _generate_confs_prepare(
644645
auto_add_filter_fields,
645646
auto_add_filter_method,
646647
auto_add_user_permit,
648+
auto_add_user_with_peer,
647649
cert_valid_days,
648650
oid_valid_days,
649651
oidc_valid_days,
@@ -891,6 +893,7 @@ def _generate_confs_prepare(
891893
user_dict['__AUTO_ADD_FILTER_FIELDS__'] = auto_add_filter_fields
892894
user_dict['__AUTO_ADD_FILTER_METHOD__'] = auto_add_filter_method
893895
user_dict['__AUTO_ADD_USER_PERMIT__'] = auto_add_user_permit
896+
user_dict['__AUTO_ADD_USER_WITH_PEER__'] = auto_add_user_with_peer
894897
user_dict['__CERT_VALID_DAYS__'] = "%s" % cert_valid_days
895898
user_dict['__OID_VALID_DAYS__'] = "%s" % oid_valid_days
896899
user_dict['__OIDC_VALID_DAYS__'] = "%s" % oidc_valid_days
@@ -2583,6 +2586,7 @@ def create_user(
25832586
auto_add_filter_fields = ''
25842587
auto_add_filter_method = 'skip'
25852588
auto_add_user_permit = 'distinguished_name:.*'
2589+
auto_add_user_with_peer = 'distinguished_name:.*'
25862590
cert_valid_days = 365
25872591
oid_valid_days = 365
25882592
oidc_valid_days = 365

0 commit comments

Comments
 (0)