-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_misc.py
More file actions
842 lines (782 loc) · 38 KB
/
test_misc.py
File metadata and controls
842 lines (782 loc) · 38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
""" Miscellaneous IPA Bug Automations
:requirement: IDM-SSSD-REQ: Testing SSSD in IPA Provider
:casecomponent: sssd
:subsystemteam: sst_idm_sssd
:upstream: yes
:status: approved
"""
import datetime
import re
import time
import subprocess
import pexpect
import pexpect.pxssh
import pytest
from sssd.testlib.common.utils import sssdTools
from sssd.testlib.common.exceptions import SSSDException
@pytest.mark.usefixtures('default_ipa_users', 'reset_password')
@pytest.mark.tier1
class Testipabz(object):
""" IPA BZ Automations """
@staticmethod
def test_blank_kinit(multihost):
"""
:title: verify sssd fails to start with
invalid default keytab file
:id: 525cbe28-f835-4d2e-9583-d3f614b8486e
:requirement: IDM-SSSD-REQ : KRB5 Provider
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1748292
:description: systemctl status sssd says No such file or
directory about "default" when keytab exists but is empty file
"""
# stop sssd
multihost.client[0].service_sssd('stop')
# backup /etc/krb5.keytab
backup = 'mv /etc/krb5.keytab /etc/krb5.keytab.orig'
multihost.client[0].run_command(backup)
# create an empty keytab
empty_keytab = 'echo -n > /etc/krb5.keytab'
multihost.client[0].run_command(empty_keytab)
# start sssd
try:
multihost.client[0].service_sssd('start')
except SSSDException:
status = 'PASS'
logs = 'journalctl -x -n 50 --no-pager'
cmd = multihost.client[0].run_command(logs, raiseonerr=False)
search_txt = 'krb5_kt_start_seq_get failed: '\
'Unsupported key table format version number'
check = re.compile(r'%s' % search_txt)
if not check.search(cmd.stdout_text):
status = 'FAIL'
else:
status = 'FAIL'
pytest.fail("sssd should fail to restart")
# restore /etc/krb5.keytab
restore = 'mv /etc/krb5.keytab.orig /etc/krb5.keytab'
multihost.client[0].run_command(restore)
assert status == 'PASS'
@staticmethod
def test_2f_auth_prompt(multihost, backupsssdconf):
"""
:title: 2f authentication prompt
:id: cc596a8a-27d6-48f2-8d6c-c821ebfffd63
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1749279
:steps:
1. Set authentication of a ipa-user to the OTP
2. Add otptoken for that user
3. Add a section 'prompting/2fa' in sssd.conf and
add prompt related options
4. Confirm that when intended user tries to log in via ssh, the end
part of login prompt is as per option set in step3.
:expectedresults:
1. Should succeed
2. Should succeed
3. Should succeed
4. Should succeed
:customerscenario: True
:description: 2F auth prompt should be as per the
option set in 'prompting/2fa' section of sssd.conf
"""
client = sssdTools(multihost.client[0])
domain_name = client.get_domain_section_name()
client_ip = multihost.client[0].ip
k_admin = 'kinit admin'
multihost.client[0].run_command(k_admin,
stdin_text='Secret123',
raiseonerr=False)
usr = 'fubar'
cmd = f"echo 'Secret123' | ipa user-add --first fu --last" \
f" bar --password {usr}"
multihost.client[0].run_command(cmd, raiseonerr=False)
try:
multihost.client[0].run_command(
f'ipa user-mod --user-auth-type=otp {usr}')
except subprocess.CalledProcessError:
pytest.fail(f"Failed to modify user-auth-type of {usr}")
try:
multihost.client[0].run_command(f'ipa otptoken-add --owner={usr}')
except subprocess.CalledProcessError:
pytest.fail(f"Failed to add otptoken of user {usr}")
try:
client.sssd_conf('prompting/password', None, 'delete')
except SSSDException as err:
if 'section do not exist' in str(err):
print(f'{err}. nothing to delete')
else:
print(f'unexpected exception: {err}')
raise SSSDException(str(err))
sec = 'prompting/2fa'
params = {'single_prompt': 'True',
'first_prompt': 'Password + OTP:'}
client.sssd_conf(sec, params)
client.clear_sssd_cache()
ssh_cmd = f'ssh -o StrictHostKeyChecking=no -l {usr}@{domain_name}' \
f' {client_ip}'
child = pexpect.spawn(ssh_cmd)
index = child.expect(['.*assword:', '.*Password.*OTP:',
'.*First.*Factor:'])
child.sendcontrol('c')
multihost.client[0].run_command(f'ipa user-del {usr}', raiseonerr=False)
assert index == 1, \
"Authentication prompt does contain Password + OTP combination"
@staticmethod
def test_sssdconfig_remove_domains(multihost):
"""
:title: Verify SSSDConfig.save_domain API removes
all autofs entries from sssd.conf
:id: 3efaf0af-58a7-4631-8555-da8a7bbcf351
:description:
SSSDConfig.save_domain(domain) does not always
remove all entries removed from domain
:bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=1796989
"""
setup_automount = "ipa-client-automount --location default -U " \
"--server %s" % multihost.master[0].sys_hostname
uninstall_automount = "ipa-client-automount --uninstall -U " \
"--server %s" % multihost.master[0].sys_hostname
for _ in range(5):
cmd1 = multihost.client[0].run_command(setup_automount,
raiseonerr=False)
time.sleep(5)
cmd2 = multihost.client[0].run_command(uninstall_automount,
raiseonerr=False)
assert cmd1.returncode == 0
assert cmd2.returncode == 0
@staticmethod
def test_filter_groups(multihost, default_ipa_groups,
add_group_member, backupsssdconf):
"""
:title: filter_groups option partially filters the group from id
output of the user because gidNumber still appears in id output
:id: 8babb6ee-7141-4723-a79d-c5cf7879a9b4
:customerscenario: True
:description:
filter_groups option partially filters the group from 'id' output
of the user because gidNumber still appears in 'id' output
:steps:
1. Create IPA users, groups and add users in groups.
2. Add filter_groups in sssd.conf.
3. Check filter_groups option filters the group from 'id' output.
:expectedresults:
1. Successfully add users, groups and users added in groups.
2. Successfully added filter_groups in sssd.conf.
3. Successfully filter out the groups.
:bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=1876658
"""
gid_start = default_ipa_groups
sssd_client = sssdTools(multihost.client[0])
domain_name = '%s/%s' % ('domain',
sssd_client.get_domain_section_name())
enable_filtergroups1 = {'filter_groups': 'ipa-group1, ipa-group2'}
sssd_client.sssd_conf(domain_name, enable_filtergroups1)
sssd_client.clear_sssd_cache()
lk_cmd1 = 'id foobar1'
cmd1 = multihost.client[0].run_command(lk_cmd1, raiseonerr=False)
assert cmd1.returncode == 0
assert all(x not in cmd1.stdout_text for x in ["ipa-group1",
"ipa-group2"]), \
"The unexpected group name found in the id output!"
assert all(x not in cmd1.stdout_text for x in [str(gid_start + 1),
str(gid_start + 2)]), \
"The unexpected gid found in the id output!"
enable_filtergroups2 = {'filter_groups': 'ipa-group3, ipa-group4, '
'ipa-group5'}
sssd_client.sssd_conf(domain_name, enable_filtergroups2)
sssd_client.clear_sssd_cache()
lk_cmd2 = 'id foobar2'
cmd2 = multihost.client[0].run_command(lk_cmd2, raiseonerr=False)
assert cmd2.returncode == 0
assert all(x not in cmd2.stdout_text for x in ["ipa-group3",
"ipa-group4",
"ipa-group5"]), \
"The unexpected group name found in the id output!"
assert all(x not in cmd2.stdout_text for x in [str(gid_start + 3),
str(gid_start + 4),
str(gid_start + 5)]), \
"The unexpected gid found in the id output!"
@staticmethod
def test_asymmetric_auth_for_nsupdate(multihost, create_reverse_zone):
"""
:title: Support asymmetric auth for nsupdate
:id: 2bc5c4c7-7296-434b-8f38-2b7297b32b9b
:requirement: dyndns
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1884301
"""
arch = multihost.client[0].run_command(
'uname -m', raiseonerr=False).stdout_text
if 'x86_64' not in arch:
pytest.skip("Test is not stable on other architectures.")
client = sssdTools(multihost.client[0])
client_hostname = multihost.client[0].sys_hostname
server_hostname = multihost.master[0].sys_hostname
client_l = client_hostname.split('.', 1)
client_hostname_short = client_l[0]
client_ip = multihost.client[0].ip
subnet = client_ip.split('.', 3)
del subnet[-1]
subnet.reverse()
domain_name = client.get_domain_section_name()
client.sssd_conf(
'domain/%s' % domain_name,
{'dyndns_force_tcp': 'true',
'dyndns_update': 'true',
'dyndns_update_ptr': 'true',
'dyndns_refresh_interval': '5',
'dyndns_auth_ptr': 'None',
'dyndns_server': '%s' % server_hostname})
cmd_del_record = 'ipa dnsrecord-del %s %s --del-all' % \
(domain_name, client_hostname_short)
multihost.master[0].run_command(cmd_del_record, raiseonerr=False)
client.remove_sss_cache('/var/lib/sss/db')
multihost.client[0].service_sssd('restart')
time.sleep(10)
cmd_check_arecord = 'nslookup %s' % client_hostname
cmd_check_ptrrecord = 'nslookup %s' % client_ip
rc_arecord = multihost.client[0].run_command(cmd_check_arecord,
raiseonerr=False)
rc_ptrrecord = multihost.client[0].run_command(cmd_check_ptrrecord,
raiseonerr=False)
assert rc_arecord.returncode == 0
assert client_ip in rc_arecord.stdout_text
assert rc_ptrrecord.returncode == 0
assert client_hostname in rc_ptrrecord.stdout_text
@staticmethod
def test_authentication_indicators(multihost, backupsssdconf):
"""
:title: Add support to verify authentication
indicators in pam_sss_gss
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1926622
:id: 4891ed62-7fc8-11eb-98be-002b677efe14
:steps:
1. Add pam_sss_gss configuration to /etc/sssd/sssd.conf
2. Add pam_sss_gss.so to /etc/pam.d/sudo
3. Restart SSSD
4. Enable SSSD debug logs
5. Switch to 'admin' user
6. obtain Kerberos ticket and check that it
was obtained using SPAKE pre-authentication.
7. Create sudo configuration that allows an admin to
run SUDO rules
8. Try 'sudo -l' as admin
9. As root, check content of sssd_pam.log
10. Check if acquired service ticket has req. indicators: 0
11. Add pam_sss_gss configuration to /etc/sssd/sssd.conf
12. Check if acquired service ticket has req.
indicators: 2
:expectedresults:
1. Should succeed
2. Should succeed
3. Should succeed
4. Should succeed
5. Should succeed
6. Should succeed
7. Should succeed
8. Should succeed
9. Should succeed
10. Should succeed
11. Should succeed
12. Should succeed
"""
client = sssdTools(multihost.client[0])
domain_params = {'pam_gssapi_services': 'sudo, sudo-i',
'pam_gssapi_indicators_map': 'hardened, '
'sudo:pkinit, '
'sudo-i:otp'}
client.sssd_conf('pam', domain_params)
multihost.client[0].run_command(
'cp -vf /etc/pam.d/sudo /etc/pam.d/sudo_indicators')
multihost.client[0].run_command("sed -i "
"'2s/^/auth sufficient "
"pam_sss_gss.so debug\\n/' "
"/etc/pam.d/sudo")
multihost.client[0].run_command(
'cp -vf /etc/pam.d/sudo-i /etc/pam.d/sudo-i_indicators')
multihost.client[0].run_command("sed -i "
"'2s/^/auth sufficient "
"pam_sss_gss.so debug\\n/' "
"/etc/pam.d/sudo-i")
client.clear_sssd_cache()
multihost.client[0].run_command("sssctl debug-level 9")
user = 'admin'
test_password = "Secret123"
multihost.client[0].run_command(
f'su -l {user} -c "kinit"', stdin_text=test_password,
raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "klist"', raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudocmd-add ALL2"', raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-add testrule2"', raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-add-allow-command testrule2 '
f'--sudocmds \'ALL2\'"', raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-mod testrule2 --hostcat=all"',
raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-add-user testrule2 --users admin"',
raiseonerr=False)
time.sleep(5)
multihost.client[0].run_command(f'su -l {user} -c "sudo -l"')
time.sleep(3)
search = multihost.client[0].run_command(
'fgrep gssapi_ /var/log/sssd/sssd_pam.log | tail -10')
domain_params = {'pam_gssapi_services': 'sudo, sudo-i',
'pam_gssapi_indicators_map': 'sudo-i:hardened'}
client.sssd_conf('pam', domain_params)
client.clear_sssd_cache()
multihost.client[0].run_command("sssctl debug-level 9")
multihost.client[0].run_command(
f'su -l {user} -c "kinit admin"', stdin_text=test_password,
raiseonerr=False)
multihost.client[0].run_command(f'su -l {user} -c "sudo -l"')
multihost.client[0].run_command(
f'su -l {user} -c "klist"', raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-del testrule2"', raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudocmd-del ALL2"', raiseonerr=False)
multihost.client[0].run_command(
'cp -vf /etc/pam.d/sudo_indicators /etc/pam.d/sudo')
multihost.client[0].run_command(
'cp -vf /etc/pam.d/sudo-i_indicators /etc/pam.d/sudo-i')
search2 = multihost.client[0].run_command(
'fgrep gssapi_ /var/log/sssd/sssd_pam.log | tail -10')
assert 'indicators: 0' in search.stdout_text
assert 'indicators: 2' in search2.stdout_text
@staticmethod
def test_pass_krb5cname_to_pam(multihost,
backupsssdconf,
backup_config_pam_gssapi_services):
"""
:title: pass KRB5CCNAME to pam_authenticate environment
if available
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1917379
:id: e3a6accc-781d-11ec-a83c-845cf3eff344
:steps:
1. Take backup of files
2. Configure domain_params
3. Configure /etc/pam.d/sudo
4. Configur /etc/pam.d/sudo-i
5. Create IPA sudo rule of /usr/sbin/sssctl
for user admin
6. Check user admin can use sudo command
7. Restore of files
:expectedresults:
1. Should succeed
2. Should succeed
3. Should succeed
4. Should succeed
5. Should succeed
6. Should succeed
7. Should succeed
"""
tools = sssdTools(multihost.client[0])
tools.clear_sssd_cache()
domain_name = tools.get_domain_section_name()
user = "admin"
test_password = "Secret123"
sys_hostname = multihost.client[0].sys_hostname
multihost.client[0].run_command(
f'su -l {user} -c "kinit"', stdin_text=test_password,
raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudocmd-add /usr/sbin/sssctl"',
raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-add idm_user_sssctl"',
raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-add-allow-command idm_user_sssctl'
f' --sudocmds \'/usr/sbin/sssctl\'"', raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-add-host idm_user_sssctl --hosts'
f' {sys_hostname}"', raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "ipa sudorule-add-user idm_user_sssctl --users'
f' admin"', raiseonerr=False)
tools.clear_sssd_cache()
multihost.client[0].run_command(
f'su -l {user} -c "kinit"', stdin_text=test_password,
raiseonerr=False)
multihost.client[0].run_command(
f'su -l {user} -c "sudo -S -l"', stdin_text=test_password,
raiseonerr=False)
result = multihost.client[0].run_command(
f'su -l {user} -c "echo -e \"Secret123\" | sudo -S /usr/sbin/sssctl domain-list"'
)
assert domain_name in result.stdout_text
@staticmethod
def test_ssh_hash_knownhosts(multihost, reset_password, backupsssdconf):
"""
:title: Current value of ssh_hash_known_hosts causes error in
the default configuration in FIPS mode.
:description: In SSSD the default value for ssh_hash_known_hosts
is set to true, It should be changed to false for consistency with
the OpenSSH setting that does not hashes host names by default
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2014249
:id: 1cee74c8-a0ad-44d4-8287-a32e3266de22
:customerscenario: false
:steps:
1. Stop SSSD
2. Configure SSSD with ssh having default value of
ssh_hash_known_hosts / ssh_hash_known_hosts = True /
ssh_hash_known_hosts = False
3. Remove /var/lib/sss/pubconf/known_hosts file
4. Start SSSD
5. Perform SSH using IPA user
6. Check if hostnames are hashed/unhashed in
/var/lib/sss/pubconf/known_hosts
:expectedresults:
1. Should succeed
2. Should succeed
3. Should succeed
4. Should succeed
5. Should succeed
6. Hostnames should be hashed/unhashed as per the value of
ssh_hash_known_hosts
"""
file_status = multihost.client[0].run_command(
"test -f /var/lib/sss/pubconf/known_hosts", raiseonerr=False
)
if file_status.returncode != 0:
pytest.skip("Sssd switched from sss_ssh_knownhostsproxy to sss_ssh_knownhosts")
tools = sssdTools(multihost.client[0])
server_host = multihost.master[0].sys_hostname
def check_hostname_hash(hash_value=None):
"""no hash_value or hash_value = True or hash_value = False"""
multihost.client[0].service_sssd("stop")
if hash_value is None:
tools.sssd_conf(
"ssh", {"ssh_hash_known_hosts": ""}, action="delete")
else:
tools.sssd_conf(
"ssh", {"ssh_hash_known_hosts": hash_value},
action="update")
multihost.client[0].run_command(r"rm -rf /var/lib/sss/pubconf"
r"/known_hosts")
multihost.client[0].service_sssd("start")
cmd = f"ssh foobar0@{server_host} echo 'login successful'"
multihost.client[0].run_command(cmd, stdin_text="Secret123",
raiseonerr=False)
known_hosts = multihost.client[0].run_command(r"cat /var/lib/sss"
r"/pubconf"
r"/known_hosts")
print(f'cat /var/lib/sss/pubconf/known_hosts\n'
f'{known_hosts.stdout_text}')
if re.search(fr'^{server_host}', known_hosts.stdout_text):
return 0 # hostname not hashed
return 1 # hostname hashed
# ssh_hash_known_hosts is not used, default value is False
hashing_not_defined = check_hostname_hash() == 0
# ssh_hash_known_hosts = True
hashing_true = check_hostname_hash("True") == 1
# ssh_hash_known_hosts = False
hashing_false = check_hostname_hash("False") == 0
# Cleanup
multihost.client[0].run_command(r"rm -rf /var/lib/sss/pubconf"
r"/known_hosts")
# Test result evaluation
assert hashing_not_defined, "Hostnames hashed - Bugzilla " \
"2014249/2015070"
assert hashing_true, "Hostnames not hashed"
assert hashing_false, "Hostnames hashed"
@staticmethod
def test_ssh_expiration_warning(multihost, reset_password, hbac_sshd_rule,
setup_ipa_client, backupsssdconf):
"""test_ssh_expiration_warning
:title: IDM-SSSD-TC: ipa_provider: Show password expiration warning
when IdM users login with SSH keys
:description: When an IdM user logs in with SSH key based
authentication, they should see password expiration warnings.
Customer would like to see password expiration warnings even when
logging in with SSH keys so users can proactively change their
passwords before they expire.
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1765354
:id: c1c20cff-edb4-41cd-a879-0eeb98a9c53a
:customerscenario: true
:setup:
1. Generate ssh keys for an user.
2. Upload public key to ipa for the user.
3. Change the password expiration to tomorrow for the user.
4. Configure hbac rule for the user enabling sshd service.
5. Configure ipa_access_order and pwd_expiration_warning
6. Set user password to expire in one day.
:steps:
1. Login using ssh key as the user to the client machine.
2. Check the output of the ssh.
:expectedresults:
1. User is logged in.
2. Password expiration message is shown.
"""
# pylint: disable=W0613
client = sssdTools(multihost.client[0])
domain_name = client.get_domain_section_name()
client.sssd_conf(
'domain/%s' % domain_name,
{'ipa_access_order': 'pwd_expire_policy_warn',
'pwd_expiration_warning': '3'}
)
client.clear_sssd_cache()
# Make sure that user home is not present with unwanted files and
# possibly wrong ownership
multihost.client[0].run_command(
'rm -rf /home/foobar1', raiseonerr=False)
multihost.client[0].run_command(
'getent passwd foobar1@testrealm.test', raiseonerr=False)
# Generate keypair
multihost.client[0].run_command(
r"""su -l foobar1@testrealm.test -c 'ssh-keygen -b 2048 -t rsa"""
r""" -q -f /home/foobar1/.ssh/id_rsa -N ""' """, raiseonerr=False)
# Get the pubkey
pubkey = multihost.client[0].get_file_contents(
"/home/foobar1/.ssh/id_rsa.pub").decode('utf-8').strip()
multihost.master[0].run_command('kinit admin', stdin_text='Secret123',
raiseonerr=False)
# Upload the pubkey to IPA
multihost.master[0].run_command(
f'ipa user-mod foobar1 --sshpubkey="{pubkey}"', raiseonerr=False)
# Make password expiring tomorrow
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
date_for_ipa = tomorrow.strftime("%Y%m%d%H%M%SZ")
multihost.master[0].run_command(
f'ipa user-mod foobar1 --setattr=krbPasswordExpiration='
f'"{date_for_ipa}"', raiseonerr=False)
client.clear_sssd_cache()
# Run ssh
# This one does not work RHEL 8
# cmd = 'su - foobar1@testrealm.test -c " ssh -v ' \
# '-o StrictHostKeychecking=no -o UserKnownHostsFile=/dev/null ' \
# '-o GSSAPIAuthentication=no -o PasswordAuthentication=no ' \
# '-l foobar1@testrealm.test localhost \'whoami\' " 2>&1'
cmd = 'sudo -u foobar1@testrealm.test ssh -v ' \
'-o StrictHostKeychecking=no -o UserKnownHostsFile=/dev/null ' \
'-o GSSAPIAuthentication=no -o PasswordAuthentication=no ' \
'-l foobar1@testrealm.test localhost <<< whoami 2>&1'
ssh_cmd = multihost.client[0].run_command(cmd, raiseonerr=False)
# Teardown
multihost.master[0].run_command(
'ipa user-mod foobar1 --setattr=krbPasswordExpiration='
'"20370101000000Z"', raiseonerr=False)
multihost.master[0].run_command(
'ipa user-mod foobar1 --sshpubkey=""', raiseonerr=False)
multihost.client[0].run_command(
'rm -rf /home/foobar1', raiseonerr=False)
# Test result evaluation
assert ssh_cmd.returncode == 0, "Ssh login failed."
assert "Your password will expire in " in ssh_cmd.stdout_text, \
"The password expiration notice was not shown."
@staticmethod
def test_ssh_expired_warning(multihost, reset_password, hbac_sshd_rule,
setup_ipa_client, backupsssdconf):
"""test_ssh_expired_warning
:title: IDM-SSSD-TC: ipa_provider: Show password expired warning
when IdM users login with SSH keys
:description: When an IdM user logs in with SSH key based
authentication, they should see password warning if
their psssword is expired.
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1765354
:id: 2fe08fa9-6491-46df-81a6-4c5e80d8e671
:customerscenario: true
:setup:
1. Generate ssh keys for an user.
2. Upload public key to ipa for the user.
3. Change the password expiration to tomorrow for the user.
4. Configure hbac rule for the user enabling sshd service.
5. Configure ipa_access_order and pwd_expiration_warning
6. Expire user password
:steps:
1. Login using ssh key as the user to the client machine.
2. Check the output of the ssh.
:expectedresults:
1. User is logged in.
2. Password expiration message is shown.
"""
# pylint: disable=W0613
client = sssdTools(multihost.client[0])
domain_name = client.get_domain_section_name()
client.sssd_conf(
'domain/%s' % domain_name,
{'ipa_access_order': 'pwd_expire_policy_warn',
'pwd_expiration_warning': '3'}
)
client.clear_sssd_cache()
# Make sure that user home is not present with unwanted files and
# possibly wrong ownership
multihost.client[0].run_command(
'rm -rf /home/foobar1', raiseonerr=False)
multihost.client[0].run_command(
'getent passwd foobar1@testrealm.test', raiseonerr=False)
# Generate keypair
multihost.client[0].run_command(
r"""su -l foobar1@testrealm.test -c 'ssh-keygen -b 2048 -t rsa"""
r""" -q -f /home/foobar1/.ssh/id_rsa -N ""' """, raiseonerr=False)
# Get the pubkey
pubkey = multihost.client[0].get_file_contents(
"/home/foobar1/.ssh/id_rsa.pub").decode('utf-8').strip()
multihost.master[0].run_command('kinit admin', stdin_text='Secret123',
raiseonerr=False)
# Upload the pubkey to IPA
multihost.master[0].run_command(
f'ipa user-mod foobar1 --sshpubkey="{pubkey}"', raiseonerr=False)
# Make password expired yesterday
yesterday = datetime.date.today() - datetime.timedelta(days=1)
date_for_ipa = yesterday.strftime("%Y%m%d%H%M%SZ")
multihost.master[0].run_command(
f'ipa user-mod foobar1 --setattr=krbPasswordExpiration='
f'"{date_for_ipa}"', raiseonerr=False)
client.clear_sssd_cache()
# Run ssh
# This one does not work RHEL 8
# cmd = 'su - foobar1@testrealm.test -c " ssh -v ' \
# '-o StrictHostKeychecking=no -o UserKnownHostsFile=/dev/null ' \
# '-o GSSAPIAuthentication=no -o PasswordAuthentication=no ' \
# '-l foobar1@testrealm.test localhost \'whoami\' " 2>&1'
cmd = 'sudo -u foobar1@testrealm.test ssh -v ' \
'-o StrictHostKeychecking=no -o UserKnownHostsFile=/dev/null ' \
'-o GSSAPIAuthentication=no -o PasswordAuthentication=no ' \
'-l foobar1@testrealm.test localhost <<< whoami 2>&1'
ssh_cmd = multihost.client[0].run_command(cmd, raiseonerr=False)
# Teardown
multihost.master[0].run_command(
'ipa user-mod foobar1 --setattr=krbPasswordExpiration='
'"20370101000000Z"', raiseonerr=False)
multihost.master[0].run_command(
'ipa user-mod foobar1 --sshpubkey=""', raiseonerr=False)
multihost.client[0].run_command(
'rm -rf /home/foobar1', raiseonerr=False)
# Test result evaluation
assert ssh_cmd.returncode == 0, "Ssh login failed."
assert "Your password has expired" in ssh_cmd.stdout_text, \
"The password expiration notice was not shown."
def test_anonymous_pkinit_for_fast(self, multihost, backupsssdconf):
"""
:title: Allow SSSD to use anonymous pkinit for FAST
:id: 4a3ecc11-0d5b-4dce-bd08-5b1f47164b44
:customerscenario: True
:description:
For SSSD to use FAST a Kerberos keytab and service principal must
exist. SSSD to be enhanced to allow for the use of anonymous pkinit
to create the FAST session.
:steps:
1. Setup a IPA server/client with default setting.
2. Call anonymous processing using #kinit -n.
3. Set 'krb5_fast_use_anonymous_pkinit = True' in sssd.conf.
4. Login to the IPA user.
5. Check a ccache file with the FAST armor ticket.
:expectedresults:
1. Successfully setup the IPA server/client.
2. Successfully called anonymous processing.
3. Successfully set the option in sssd.conf.
4. Successfully logged in to IPA user.
5. Successfully get a ccache file with the FAST armor ticket
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1859751
"""
multihost.client[0].run_command('yum install krb5-pkinit -y')
sssd_client = sssdTools(multihost.client[0])
domain_name = f'domain/{sssd_client.get_domain_section_name()}'
add_anony_pkinit = {'krb5_fast_use_anonymous_pkinit': 'True'}
sssd_client.sssd_conf(domain_name, add_anony_pkinit)
sssd_client.clear_sssd_cache()
cmd_kinit = multihost.client[0].run_command('kinit -n')
assert cmd_kinit.returncode == 0
sssd_client.auth_from_client('foobar0', "Secret123")
cmd_klist = f'klist /var/lib/sss/db/fast_ccache_' \
f'{sssd_client.get_domain_section_name().upper()}'
output = multihost.client[0].run_command(cmd_klist).stdout_text
principal = 'WELLKNOWN/ANONYMOUS@WELLKNOWN:ANONYMOUS'
assert principal in output
def test_anonymous_pkinit_for_fast_false(self, multihost, backupsssdconf):
"""
:title: Negative test for allow SSSD to use anonymous pkinit for FAST
:id: de823122-af88-41f6-b762-63083fccaa87
:customerscenario: True
:description:
For SSSD to use FAST a Kerberos keytab and service principal must
exist. SSSD to be enhanced to allow for the use of anonymous pkinit
to create the FAST session. With
'krb5_fast_use_anonymous_pkinit = False' the ccache will have a
ticket for the host principal.
:steps:
1. Setup a IPA server/client with default setting.
2. Call anonymous processing using #kinit -n.
3. Set 'krb5_fast_use_anonymous_pkinit = False' in sssd.conf.
4. Login to the IPA user.
5. Check a ccache file for the host principal.
:expectedresults:
1. Successfully setup the IPA server/client.
2. Successfully called anonymous processing.
3. Successfully set the option in sssd.conf.
4. Successfully logged in to IPA user.
5. Successfully get a ccache file with the host principal.
:bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=1859751
"""
sssd_client = sssdTools(multihost.client[0])
domain_section = sssd_client.get_domain_section_name()
domain_name = f'domain/{domain_section}'
add_anony_pkinit = {'krb5_fast_use_anonymous_pkinit': 'False'}
sssd_client.sssd_conf(domain_name, add_anony_pkinit)
sssd_client.clear_sssd_cache()
cmd_kinit = multihost.client[0].run_command('kinit -n')
assert cmd_kinit.returncode == 0
sssd_client.auth_from_client('foobar1', "Secret123")
cmd_klist = f'klist /var/lib/sss/db/' \
f'fast_ccache_{domain_section.upper()}'
output = multihost.client[0].run_command(cmd_klist).stdout_text
principal = re.compile(rf'principal:.host.'
rf'{multihost.client[0].sys_hostname}@'
rf'{domain_section.upper()}')
assert principal.search(output)
@staticmethod
def test_pam_misc_conv_bufsize(multihost, backupsssdconf):
"""
:title: Increase PAM_MISC_CONV_BUFSIZE to max at 4096 instead of 512 bytes
:bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2209785
https://bugzilla.redhat.com/show_bug.cgi?id=2215007
:id: d97365bc-0b4a-11ee-84be-845cf3eff344
:steps:
1. Create an IPA user with a password longer than 512 characters.
2. Use sssctl to check the user authentication (sssctl user-checks USER -a auth)
and when requested input the password.
:expectedresults:
1. User should be created
2. User should be able to login
"""
client = sssdTools(multihost.client[0])
password = "Inthedepthsofthecosmoswherestarsignitethetapestryoftheuniverseaneth" \
"erealdanceofcelestialbodiesunfoldsweavingtalesoftimeandspaceinasymphonyof" \
"cosmicproportionsPlanetswhirlontheireternalpathsgalaxiescollideina" \
"celestialballetandblackholesdevourwithvoracioushungerWithinthiscos" \
"mictheatemysteriesaboundawaitingthecuriousgazeofexplorerswhodaretou" \
"nveilthesecretsthatliewithinthevastexpanseofthecosmosFromthebirthof" \
"starstotheenigmaofdarkmattereverydiscoverysparksnewquestionspropell" \
"inghumanitysquestforknowledgebeyondtheconfinesofEar" \
"thWitheachpassingmomentastronomersandscie"
kinit_admin = 'kinit admin'
multihost.master[0].run_command(kinit_admin,
stdin_text='Secret123',
raiseonerr=False)
user_info = {'firstname': 'Aoo',
'lastname': 'Boo', 'loginname': 'aooboo',
'default_password': 'RedHat@123',
'reset_password': password}
useradd = f"echo {user_info['default_password']} | ipa user-add --first " \
f"{user_info['firstname']} --last {user_info['lastname']} --password {user_info['loginname']}"
cmd_useradd = multihost.master[0].run_command(useradd)
cmd = f"echo -e 'RedHat@123\n{password}\n{password}' | kinit aooboo"
multihost.client[0].run_command(cmd, raiseonerr=False)
multihost.client[0].run_command('kdestroy')
client.clear_sssd_cache()
multihost.client[0].run_command("> /var/log/secure")
multihost.client[0].run_command(f"echo -e {password} | sssctl user-checks aooboo -a auth")
multihost.master[0].run_command('ipa user-del aooboo', raiseonerr=False)
time.sleep(2)
logfile = multihost.client[0].get_file_contents("/var/log/secure").decode('utf-8')
assert cmd_useradd.returncode == 0
assert "Authentication failure" not in logfile
assert "pam_sss(system-auth:auth): authentication success" in logfile