Skip to content

Commit 853d159

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 7d68a90 commit 853d159

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
@@ -73,6 +73,7 @@ def main(argv, _generate_confs=generate_confs, _print=print):
7373
'auto_add_filter_fields',
7474
'auto_add_filter_method',
7575
'auto_add_user_permit',
76+
'auto_add_user_with_peer',
7677
'base_fqdn',
7778
'public_fqdn',
7879
'public_alias_fqdn',

mig/shared/accountreq.py

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

12461246

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

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

12571261

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

mig/shared/configuration.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def fix_missing(config_file, verbose=True):
151151
'auto_add_oidc_user': False,
152152
'auto_add_resource': False,
153153
'auto_add_user_permit': 'distinguished_name:.*',
154+
'auto_add_user_with_peer': 'distinguished_name:.*',
154155
'auto_add_filter_method': '',
155156
'auto_add_filter_fields': '',
156157
'server_fqdn': fqdn,
@@ -693,6 +694,7 @@ def get(self, *args, **kwargs):
693694
'auto_add_oidc_user': False,
694695
'auto_add_resource': False,
695696
'auto_add_user_permit': [('distinguished_name', '.*')],
697+
'auto_add_user_with_peer': [('distinguished_name', '.*')],
696698
'auto_add_filter_method': '',
697699
'auto_add_filter_fields': [],
698700

@@ -2630,12 +2632,21 @@ def reload_config(self, verbose, skip_log=False, disable_auth_log=False,
26302632
if config.has_option('GLOBAL', 'auto_add_resource'):
26312633
self.auto_add_resource = config.getboolean('GLOBAL',
26322634
'auto_add_resource')
2633-
# Limit sign up without operator interaction using ID fields regex.
2635+
# Limit direct sign up without operator interaction using ID field and
2636+
# regex pairs.
26342637
# For autocreate auto_add_X_user must be True and auto_add_user_permit
26352638
# specification must match actual user on all given fields.
26362639
if config.has_option('GLOBAL', 'auto_add_user_permit'):
26372640
req = config.get('GLOBAL', 'auto_add_user_permit').split()
26382641
self.auto_add_user_permit = [i.split(':', 2) for i in req]
2642+
# Limit peer accepted sign up without operator interaction using ID
2643+
# field and regex pairs.
2644+
# For autocreate auto_add_X_user must be True and
2645+
# auto_add_user_with_peer specification must match actual user on all
2646+
# given fields. Plus an active peer acceptance to match must exist.
2647+
if config.has_option('GLOBAL', 'auto_add_user_with_peer'):
2648+
req = config.get('GLOBAL', 'auto_add_user_with_peer').split()
2649+
self.auto_add_user_with_peer = [i.split(':', 2) for i in req]
26392650

26402651
# Apply requested automatic filtering of selected auto add user fields
26412652
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

@@ -46,7 +46,8 @@
4646
import time
4747

4848
from mig.shared import returnvalues
49-
from mig.shared.accountreq import auto_add_user_allowed
49+
from mig.shared.accountreq import auto_add_user_allowed_direct, \
50+
auto_add_user_allowed_with_peer
5051
from mig.shared.accountstate import default_account_expire
5152
from mig.shared.bailout import filter_output_objects
5253
from mig.shared.base import client_id_dir, canonical_user, mask_creds, \
@@ -729,7 +730,13 @@ def main(client_id, user_arguments_dict, environ=None):
729730
configuration.auto_add_oidc_user:
730731
fill_user(user_dict)
731732

732-
if not auto_add_user_allowed(configuration, user_dict):
733+
if auto_add_user_allowed_direct(configuration, user_dict):
734+
logger.debug('autocreate directly permitted for %s' % client_id)
735+
elif auto_add_user_allowed_with_peer(configuration, user_dict):
736+
logger.debug('autocreate only permitted with peer for %s' %
737+
client_id)
738+
peer_pattern = keyword_auto
739+
else:
733740
logger.warning('autocreate not permitted for %s' % client_id)
734741
output_objects.append({
735742
'object_type': 'error_text', 'text':

mig/shared/install.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def generate_confs(
331331
auto_add_filter_fields='',
332332
auto_add_filter_method='skip',
333333
auto_add_user_permit='distinguished_name:.*',
334+
auto_add_user_with_peer='distinguished_name:.*',
334335
cert_valid_days=365,
335336
oid_valid_days=365,
336337
oidc_valid_days=365,
@@ -648,6 +649,7 @@ def _generate_confs_prepare(
648649
auto_add_filter_fields,
649650
auto_add_filter_method,
650651
auto_add_user_permit,
652+
auto_add_user_with_peer,
651653
cert_valid_days,
652654
oid_valid_days,
653655
oidc_valid_days,
@@ -895,6 +897,7 @@ def _generate_confs_prepare(
895897
user_dict['__AUTO_ADD_FILTER_FIELDS__'] = auto_add_filter_fields
896898
user_dict['__AUTO_ADD_FILTER_METHOD__'] = auto_add_filter_method
897899
user_dict['__AUTO_ADD_USER_PERMIT__'] = auto_add_user_permit
900+
user_dict['__AUTO_ADD_USER_WITH_PEER__'] = auto_add_user_with_peer
898901
user_dict['__CERT_VALID_DAYS__'] = "%s" % cert_valid_days
899902
user_dict['__OID_VALID_DAYS__'] = "%s" % oid_valid_days
900903
user_dict['__OIDC_VALID_DAYS__'] = "%s" % oidc_valid_days
@@ -2596,6 +2599,7 @@ def create_user(
25962599
auto_add_filter_fields = ''
25972600
auto_add_filter_method = 'skip'
25982601
auto_add_user_permit = 'distinguished_name:.*'
2602+
auto_add_user_with_peer = 'distinguished_name:.*'
25992603
cert_valid_days = 365
26002604
oid_valid_days = 365
26012605
oidc_valid_days = 365

0 commit comments

Comments
 (0)