@@ -164,7 +164,7 @@ class PAMCreateRecordRotationCommand(Command):
164
164
parser = argparse .ArgumentParser (prog = 'pam rotation new' )
165
165
parser .add_argument ('--record' , '-r' , required = True , dest = 'record_uid' , action = 'store' , help = 'Record UID that will be rotated manually or via schedule' )
166
166
parser .add_argument ('--config' , '-c' , dest = 'config_uid' , action = 'store' , help = 'UID of the PAM Configuration.' )
167
- parser .add_argument ('--resource' , '-rs' , required = False , dest = 'resource_uid' , action = 'store' , help = 'UID of the resource recourd .' )
167
+ parser .add_argument ('--resource' , '-rs' , required = False , dest = 'resource_uid' , action = 'store' , help = 'UID of the resource record .' )
168
168
schedule_group = parser .add_mutually_exclusive_group ()
169
169
schedule_group .add_argument ('--schedulejson' , '-sj' , required = False , dest = 'schedule_json_data' , action = 'append' , help = 'Json of the scheduler. Example: -sj \' {"type": "WEEKLY", "utcTime": "15:44", "weekday": "SUNDAY", "intervalCount": 1}\' ' )
170
170
schedule_group .add_argument ('--schedulecron' , '-sc' , required = False , dest = 'schedule_cron_data' , action = 'append' , help = 'Cron tab string of the scheduler. Example: to run job daily at 5:56PM UTC enter following cron -sc "0 56 17 * * ?"' )
@@ -228,28 +228,29 @@ def execute(self, params, **kwargs):
228
228
pass
229
229
230
230
# 2. Load password complexity rules
231
- if not pwd_complexity :
231
+ if pwd_complexity is None :
232
232
if current_record_rotation :
233
233
pwd_complexity_rule_list_encrypted = utils .base64_url_decode (current_record_rotation ['pwd_complexity' ])
234
234
else :
235
235
pwd_complexity_rule_list_encrypted = b''
236
236
else :
237
- pwd_complexity_list = [s .strip () for s in pwd_complexity .split (',' )]
238
- if len (pwd_complexity_list ) != 5 or not all (n .isnumeric () for n in pwd_complexity_list ):
239
- logging .warning (
240
- 'Invalid rules to generate password. Format is "length, upper, lower, digits, symbols". Ex: 32,5,5,5,5'
241
- )
242
- return
243
-
244
- rule_list_dict = {
245
- 'length' : int (pwd_complexity_list [0 ]),
246
- 'caps' : int (pwd_complexity_list [1 ]),
247
- 'lowercase' : int (pwd_complexity_list [2 ]),
248
- 'digits' : int (pwd_complexity_list [3 ]),
249
- 'special' : int (pwd_complexity_list [4 ])
250
- }
251
-
252
- pwd_complexity_rule_list_encrypted = router_helper .encrypt_pwd_complexity (rule_list_dict , record .record_key )
237
+ if pwd_complexity :
238
+ pwd_complexity_list = [s .strip () for s in pwd_complexity .split (',' )]
239
+ if len (pwd_complexity_list ) != 5 or not all (n .isnumeric () for n in pwd_complexity_list ):
240
+ logging .warning (
241
+ 'Invalid rules to generate password. Format is "length, upper, lower, digits, symbols". Ex: 32,5,5,5,5'
242
+ )
243
+ return
244
+ rule_list_dict = {
245
+ 'length' : int (pwd_complexity_list [0 ]),
246
+ 'caps' : int (pwd_complexity_list [1 ]),
247
+ 'lowercase' : int (pwd_complexity_list [2 ]),
248
+ 'digits' : int (pwd_complexity_list [3 ]),
249
+ 'special' : int (pwd_complexity_list [4 ])
250
+ }
251
+ pwd_complexity_rule_list_encrypted = router_helper .encrypt_pwd_complexity (rule_list_dict , record .record_key )
252
+ else :
253
+ pwd_complexity_rule_list_encrypted = b''
253
254
254
255
255
256
# 3. Resource record check
@@ -1061,14 +1062,42 @@ def execute(self, params, **kwargs):
1061
1062
if rri_status_name == 'RRS_ONLINE' :
1062
1063
1063
1064
print (f'Rotation Status: { bcolors .OKBLUE } Ready to rotate ({ rri_status_name } ){ bcolors .ENDC } ' )
1064
- print (f'PAM Config UID: { bcolors .OKBLUE } { utils .base64_url_encode (rri .configurationUid )} { bcolors .ENDC } ' )
1065
+ configuration_uid = utils .base64_url_encode (rri .configurationUid )
1066
+ print (f'PAM Config UID: { bcolors .OKBLUE } { configuration_uid } { bcolors .ENDC } ' )
1065
1067
print (f'Node ID: { bcolors .OKBLUE } { rri .nodeId } { bcolors .ENDC } ' )
1066
1068
1067
1069
print (f"Gateway Name where the rotation will be performed: { bcolors .OKBLUE } { (rri .controllerName if rri .controllerName else '-' )} { bcolors .ENDC } " )
1068
1070
print (f"Gateway Uid: { bcolors .OKBLUE } { (utils .base64_url_encode (rri .controllerUid ) if rri .controllerUid else '-' ) } { bcolors .ENDC } " )
1071
+ if rri .resourceUid :
1072
+ resource_id = utils .base64_url_encode (rri .resourceUid )
1073
+ resource_ok = False
1074
+ if resource_id in params .record_cache :
1075
+ configuration = vault .KeeperRecord .load (params , configuration_uid )
1076
+ if isinstance (configuration , vault .TypedRecord ):
1077
+ field = configuration .get_typed_field ('pamResources' )
1078
+ if field and isinstance (field .value , list ) and len (field .value ) == 1 :
1079
+ rv = field .value [0 ]
1080
+ if isinstance (rv , dict ):
1081
+ resources = rv .get ('resourceRef' )
1082
+ if isinstance (resources , list ):
1083
+ resource_ok = resource_id in resources
1084
+ print (f"Admin Resource Uid: { bcolors .OKBLUE if resource_ok else bcolors .FAIL } { resource_id } { bcolors .ENDC } " )
1085
+
1069
1086
# print(f"Router Cookie: {bcolors.OKBLUE}{(rri.cookie if rri.cookie else '-')}{bcolors.ENDC}")
1070
1087
# print(f"scriptName: {bcolors.OKGREEN}{rri.scriptName}{bcolors.ENDC}")
1071
- print (f"Password Complexity: { bcolors .OKGREEN } { rri .pwdComplexity if rri .pwdComplexity else '[not set]' } { bcolors .ENDC } " )
1088
+ if rri .pwdComplexity :
1089
+ print (f"Password Complexity: { bcolors .OKGREEN } { rri .pwdComplexity } { bcolors .ENDC } " )
1090
+ try :
1091
+ record = params .record_cache .get (record_uid )
1092
+ if record :
1093
+ complexity = crypto .decrypt_aes_v2 (utils .base64_url_decode (rri .pwdComplexity ), record ['record_key_unencrypted' ])
1094
+ c = json .loads (complexity .decode ())
1095
+ print (f"Password Complexity Data: { bcolors .OKBLUE } Length: { c .get ('length' )} ; Lowercase: { c .get ('lowercase' )} ; Uppercase: { c .get ('caps' )} ; Digits: { c .get ('digits' )} ; Symbols: { c .get ('special' )} { bcolors .ENDC } " )
1096
+ except :
1097
+ pass
1098
+ else :
1099
+ print (f"Password Complexity: { bcolors .OKGREEN } [not set]{ bcolors .ENDC } " )
1100
+
1072
1101
print (f"Is Rotation Disabled: { bcolors .OKGREEN } { rri .disabled } { bcolors .ENDC } " )
1073
1102
print (f"\n Command to manually rotate: { bcolors .OKGREEN } pam action rotate -r { record_uid } { bcolors .ENDC } " )
1074
1103
else :
@@ -1402,6 +1431,18 @@ def execute(self, params, **kwargs):
1402
1431
# Find record by record uid
1403
1432
ri = record_rotation_get (params , utils .base64_url_decode (record .record_uid ))
1404
1433
ri_pwd_complexity_encrypted = ri .pwdComplexity
1434
+ if not ri_pwd_complexity_encrypted :
1435
+ rule_list_dict = {
1436
+ 'length' : 20 ,
1437
+ 'caps' : 1 ,
1438
+ 'lowercase' : 1 ,
1439
+ 'digits' : 1 ,
1440
+ 'special' : 1 ,
1441
+ }
1442
+ ri_pwd_complexity_encrypted = utils .base64_url_encode (router_helper .encrypt_pwd_complexity (rule_list_dict , record .record_key ))
1443
+ # else:
1444
+ # rule_list_json = crypto.decrypt_aes_v2(utils.base64_url_decode(ri_pwd_complexity_encrypted), record.record_key)
1445
+ # complexity = json.loads(rule_list_json.decode())
1405
1446
1406
1447
ri_rotation_setting_uid = utils .base64_url_encode (ri .configurationUid ) # Configuration on the UI is "Rotation Setting"
1407
1448
resource_uid = utils .base64_url_encode (ri .resourceUid )
0 commit comments