Whamcloud - gitweb
LU-17173 gss: user keys go to user keyring
[fs/lustre-release.git] / lustre / tests / sanity-krb5.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
13 init_test_env $@
14 init_logging
15
16 ALWAYS_EXCEPT="$SANITY_GSS_EXCEPT"
17
18 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
19
20 build_test_filter
21
22 require_dsh_mds || exit 0
23
24 # $RUNAS_ID may get set incorrectly somewhere else
25 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
26     error "RUNAS_ID set to 0, but UID is also 0!"
27
28 # remove $SEC, we'd like to control everything by ourselves
29 unset SEC
30
31 #
32 # global variables of this sanity
33 #
34 DBENCH_PID=0
35
36 # set manually
37 GSS=true
38 GSS_KRB5=true
39
40 check_krb_env() {
41         which klist || skip "Kerberos env not setup"
42         which kinit || skip "Kerberos env not setup"
43 }
44
45 prepare_krb5_creds() {
46         echo prepare krb5 cred
47         echo RUNAS=$RUNAS
48         $RUNAS krb5_login.sh || exit 1
49 }
50
51 check_krb_env
52 prepare_krb5_creds
53
54 # we want double mount
55 MOUNT_2=${MOUNT_2:-"yes"}
56 check_and_setup_lustre
57
58 rm -rf $DIR/[df][0-9]*
59
60 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
61
62 start_dbench()
63 {
64         local NPROC=$(grep -c ^processor /proc/cpuinfo)
65         [ $NPROC -gt 2 ] && NPROC=2
66         bash rundbench -D $DIR/$tdir $NPROC 1>/dev/null &
67         DBENCH_PID=$!
68         sleep 2
69
70         num=$(ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l)
71         if [ $num -ne 1 ]; then
72                 error "failed to start dbench $NPROC"
73         else
74                 echo "started dbench with $NPROC processes at background"
75         fi
76
77         return 0
78 }
79
80 check_dbench()
81 {
82         num=$(ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l)
83         if [ $num -eq 0 ]; then
84                 echo "dbench $DBENCH_PID already finished"
85                 wait $DBENCH_PID || error "dbench $PID exit with error"
86                 start_dbench
87         elif [ $num -ne 1 ]; then
88                 killall -9 dbench
89                 error "found $num instance of pid $DBENCH_PID ???"
90         fi
91
92         return 0
93 }
94
95 stop_dbench()
96 {
97         for ((;;)); do
98                 killall dbench 2>/dev/null
99                 local num=$(ps --no-headers -p $DBENCH_PID | wc -l)
100                 if [ $num -eq 0 ]; then
101                         echo "dbench finished"
102                         break
103                 fi
104                 echo "dbench $DBENCH_PID is still running, waiting 2s..."
105                 sleep 2
106         done
107
108         wait $DBENCH_PID || true
109         sync || true
110 }
111
112 error_dbench()
113 {
114         local err_str=$1
115
116         killall -9 dbench
117         sleep 1
118
119         error $err_str
120 }
121
122 # obtain and cache Kerberos ticket-granting ticket
123 refresh_krb5_tgt() {
124         local myRUNAS_UID=$1
125         local myRUNAS_GID=$2
126         shift 2
127         local myRUNAS=$@
128         if [ -z "$myRUNAS" ]; then
129                 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
130         fi
131
132         CLIENTS=${CLIENTS:-$HOSTNAME}
133         do_nodes $CLIENTS "set -x
134 if ! $myRUNAS krb5_login.sh; then
135     echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
136     exit 1
137 fi"
138 }
139
140 restore_krb5_cred() {
141         local keys=$(keyctl show | awk '$6 ~ "^lgssc:" {print $1}')
142
143         for key in $keys; do
144                 keyctl unlink $key
145         done
146         echo RUNAS=$RUNAS
147         $RUNAS krb5_login.sh || exit 1
148 }
149
150 check_multiple_gss_daemons() {
151         local facet=$1
152         local gssd=$2
153         local gssd_name=$(basename $gssd)
154
155         for ((i = 0; i < 10; i++)); do
156                 do_facet $facet "$gssd -vvv"
157         done
158
159         # wait daemons entering "stable" status
160         sleep 5
161
162         local num=$(do_facet $facet ps -o cmd -C $gssd_name |
163                 grep -c $gssd_name)
164         echo "$num instance(s) of $gssd_name are running"
165
166         if [ $num -ne 1 ]; then
167                 error "$gssd_name not unique"
168         fi
169 }
170
171 calc_connection_cnt
172 umask 077
173
174 test_0() {
175         local my_facet=mds
176
177         echo "bring up gss daemons..."
178         start_gss_daemons
179
180         echo "check with someone already running..."
181         check_multiple_gss_daemons $my_facet $LSVCGSSD
182
183         echo "check with someone run & finished..."
184         do_facet $my_facet killall -q -2 lgssd $LSVCGSSD || true
185         sleep 5 # wait fully exit
186         check_multiple_gss_daemons $my_facet $LSVCGSSD
187
188         echo "check refresh..."
189         do_facet $my_facet killall -q -2 lgssd $LSVCGSSD || true
190         sleep 5 # wait fully exit
191         do_facet $my_facet ipcrm -S 0x3b92d473
192         check_multiple_gss_daemons $my_facet $LSVCGSSD
193 }
194 run_test 0 "start multiple gss daemons"
195
196 set_flavor_all krb5p
197
198 test_1a() {
199         local file=$DIR/$tdir/$tfile
200
201         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
202         chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
203         $RUNAS ls -ld $DIR/$tdir
204
205         # access w/o cred
206         $RUNAS $LFS flushctx -k -r $MOUNT || error "can't flush context"
207         $RUNAS touch $file && error "unexpected success"
208
209         # access w/ cred
210         restore_krb5_cred
211         $RUNAS touch $file || error "should not fail"
212         [ -f $file ] || error "$file not found"
213 }
214 run_test 1a "access with or without krb5 credential"
215
216 test_1b() {
217         local file=$DIR/$tdir/$tfile
218         local lgssconf=/etc/request-key.d/lgssc.conf
219         local clients=$CLIENTS
220         local realm
221
222         [ -z $clients ] && clients=$HOSTNAME
223         zconf_umount_clients $clients $MOUNT || error "umount clients failed"
224
225         echo "stop gss daemons..."
226         stop_gss_daemons
227
228         # get local realm from krb5.conf, assume the same for all nodes
229         realm=$(grep default_realm /etc/krb5.conf | awk '{print $3}')
230
231         # add -R option to lgss_keyring on local client
232         cp $lgssconf $TMP/lgssc.conf
233         stack_trap "yes | cp $TMP/lgssc.conf $lgssconf" EXIT
234         sed -i s+lgss_keyring+\&\ \-R\ $realm+ $lgssconf
235
236         # add -R option to lsvcgssd
237         echo "bring up gss daemons..."
238         start_gss_daemons '' '' "-R $realm"
239         stack_trap "stop_gss_daemons ; start_gss_daemons" EXIT
240
241         zconf_mount_clients $clients $MOUNT || error "mount clients failed"
242
243         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
244         chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
245         $RUNAS touch $file || error "touch $file failed"
246         [ -f $file ] || error "$file not found"
247 }
248 run_test 1b "Use specified realm"
249
250 test_2() {
251         local file1=$DIR/$tdir/$tfile-1
252         local file2=$DIR/$tdir/$tfile-2
253
254         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
255         chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
256
257         # current access should be ok
258         $RUNAS touch $file1 || error "can't touch $file1"
259         [ -f $file1 ] || error "$file1 not found"
260
261         # cleanup all cred/ctx and touch
262         $RUNAS $LFS flushctx -k -r $MOUNT || error "can't flush context"
263         $RUNAS touch $file2 && error "unexpected success"
264
265         # restore and touch
266         restore_krb5_cred
267         $RUNAS touch $file2 || error "should not fail"
268         [ -f $file2 ] || error "$file2 not found"
269 }
270 run_test 2 "lfs flushctx"
271
272 test_3() {
273         local file=$DIR/$tdir/$tfile
274
275         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
276         chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
277
278         # create file
279         echo "aaaaaaaaaaaaaaaaa" > $file
280         chmod 0666 $file
281         $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
282         $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
283         $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
284
285         # start multiop
286         $RUNAS $MULTIOP $file o_r &
287         OPPID=$!
288         # wait multiop finish its open()
289         sleep 1
290
291         # cleanup all cred/ctx and check
292         # metadata check should fail, but file data check should succeed
293         # because we always use root credential to OSTs
294         $RUNAS $LFS flushctx -k -r $MOUNT || error "can't flush context"
295         echo "destroyed credentials/contexs for $RUNAS_ID"
296         $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
297         kill -s 10 $OPPID
298         wait $OPPID || error "read file data failed"
299         echo "read file data OK"
300
301         # restore and check again
302         restore_krb5_cred
303         echo "restored credentials for $RUNAS_ID"
304         $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
305         echo "$RUNAS_ID checkstat OK"
306         $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
307         echo "$UID checkstat OK"
308         $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
309         echo "$RUNAS_ID read file data OK"
310 }
311 run_test 3 "local cache under DLM lock"
312
313 test_5() {
314         local file1=$DIR/$tdir/$tfile-1
315         local file2=$DIR/$tdir/$tfile-2
316         local wait_time=$((TIMEOUT + TIMEOUT / 2))
317
318         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
319         chmod 0777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
320
321         # current access should be ok
322         $RUNAS touch $file1 || error "can't touch $file1"
323         [ -f $file1 ] || error "$file1 not found"
324
325         # flush context
326         $RUNAS $LFS flushctx $MOUNT || error "can't flush context"
327
328         # stop lsvcgssd
329         send_sigint $(comma_list $(mdts_nodes)) $LSVCGSSD
330         sleep 5
331         check_gss_daemon_nodes $(comma_list $(mdts_nodes)) $LSVCGSSD &&
332                 error "$LSVCGSSD still running"
333
334         $RUNAS touch $file2 && error "should fail without $LSVCGSSD"
335
336         # restart lsvcgssd, expect touch succeed
337         echo "restart $LSVCGSSD and recovering"
338         start_gss_daemons $(comma_list $(mdts_nodes)) "$LSVCGSSD -vvv"
339         sleep 5
340         check_gss_daemon_nodes $(comma_list $(mdts_nodes)) $LSVCGSSD
341         $RUNAS touch $file2 || error "should not fail now"
342         [ -f $file2 ] || error "$file2 not found"
343 }
344 run_test 5 "lsvcgssd dead, operations fail"
345
346 test_6() {
347         local nfile=10
348
349         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
350         for ((i=0; i<$nfile; i++)); do
351                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=8k count=1 ||
352                     error "dd $tfile-$i failed"
353         done
354         ls -l $DIR/$tdir/* > /dev/null || error "ls failed"
355         rm -rf $DIR2/$tdir/* || error "rm failed"
356         rmdir $DIR2/$tdir || error "rmdir failed"
357 }
358 run_test 6 "test basic DLM callback works"
359
360 test_7() {
361         local num_osts
362
363         # for open(), client only reserve space for default stripe count lovea,
364         # and server may return larger lovea in reply (because of larger stripe
365         # count), client need call enlarge_reqbuf() and save the replied lovea
366         # in request for future possible replay.
367         #
368         # Note: current script does NOT guarantee enlarge_reqbuf() will be in
369         # the path, however it does work in local test which has 2 OSTs and
370         # default stripe count is 1.
371         [[ $OSTCOUNT -ge 2 ]] || skip_env "needs >= 2 OSTs"
372
373         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
374         $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe -c $OSTCOUNT"
375
376         echo "creating..."
377         for ((i = 0; i < 20; i++)); do
378                 dd if=/dev/zero of=$DIR/$tdir/f$i bs=4k count=16 2>/dev/null
379         done
380         echo "reading..."
381         for ((i = 0; i < 20; i++)); do
382                 dd if=$DIR/$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
383         done
384 }
385 run_test 7 "exercise enlarge_reqbuf()"
386
387 test_8()
388 {
389         local atoldbase=$(do_facet $SINGLEMDS "$LCTL get_param -n at_history")
390         local req_delay
391
392         do_facet $SINGLEMDS "$LCTL set_param at_history=8" || true
393         stack_trap \
394                 "do_facet $SINGLEMDS $LCTL set_param at_history=$atoldbase" EXIT
395
396         mkdir -p $DIR/$tdir
397         chmod a+w $DIR/$tdir
398
399         $LCTL dk > /dev/null
400         debugsave
401         stack_trap debugrestore EXIT
402         $LCTL set_param debug=+other
403
404         # wait for the at estimation come down, this is faster
405         while [ true ]; do
406                 req_delay=$($LCTL get_param -n \
407                         mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
408                         awk '/portal 12/ {print $5}' | tail -1)
409                 [ $req_delay -le 5 ] && break
410                 echo "current AT estimation is $req_delay, wait a little bit"
411                 sleep 8
412         done
413         req_delay=$((${req_delay} + ${req_delay} / 4 + 5))
414
415         # sleep sometime in ctx handle
416         do_facet $SINGLEMDS $LCTL set_param fail_val=$req_delay
417         #define OBD_FAIL_SEC_CTX_HDL_PAUSE       0x1204
418         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1204
419
420         $RUNAS $LFS flushctx -k -r $MOUNT ||
421                 error "can't flush context on $MOUNT"
422         restore_krb5_cred
423
424         $RUNAS touch $DIR/$tdir/$tfile &
425         TOUCHPID=$!
426         echo "waiting for touch (pid $TOUCHPID) to finish..."
427         sleep 30 # give it a chance to really trigger context init rpc
428         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
429         wait $TOUCHPID || error "touch should have succeeded"
430
431         $LCTL dk | grep -i "Early reply #" || error "No early reply"
432 }
433 run_test 8 "Early reply sent for slow gss context negotiation"
434
435 #
436 # following tests will manipulate flavors and may end with any flavor set,
437 # so each test should not assume any start flavor.
438 #
439
440 test_90() {
441         if [ "$SLOW" = "no" ]; then
442                 total=10
443         else
444                 total=60
445         fi
446
447         mkdir $DIR/$tdir
448
449         restore_to_default_flavor
450         set_flavor_all krb5p
451
452         start_dbench
453
454         for ((n = 1; n <= $total; n++)); do
455                 sleep 2
456                 check_dbench
457                 echo "flush ctx ($n/$total) ..."
458                 $LFS flushctx -k -r $MOUNT ||
459                         error "can't flush context on $MOUNT"
460         done
461         check_dbench
462         #sleep to let ctxs be re-established
463         sleep 10
464         stop_dbench
465 }
466 run_test 90 "recoverable from losing contexts under load"
467
468 test_99() {
469         local nrule_old
470         local nrule_new=0
471         local max=32
472
473         #
474         # general rules
475         #
476         nrule_old=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
477             2>/dev/null | grep -c "$FSNAME.srpc.flavor.")
478         echo "original general rules: $nrule_old"
479
480         for ((i = $nrule_old; i < $max; i++)); do
481                 set_rule $FSNAME ${NETTYPE}$i cli2mdt krb5n ||
482                         error "set rule $i (1)"
483                 set_rule $FSNAME ${NETTYPE}$i cli2ost krb5n ||
484                         error "set rule $i (2)"
485                 set_rule $FSNAME ${NETTYPE}$i mdt2ost null ||
486                         error "set rule $i (3)"
487                 set_rule $FSNAME ${NETTYPE}$i mdt2mdt null ||
488                         error "set rule $i (4)"
489         done
490         for ((i = $nrule_old; i < $max; i++)); do
491                 set_rule $FSNAME ${NETTYPE}$i cli2mdt ||
492                         error "remove rule $i (1)"
493                 set_rule $FSNAME ${NETTYPE}$i cli2ost ||
494                         error "remove rule $i (2)"
495                 set_rule $FSNAME ${NETTYPE}$i mdt2ost ||
496                         error "remove rule $i (3)"
497                 set_rule $FSNAME ${NETTYPE}$i mdt2mdt ||
498                         error "remove rule $i (4)"
499
500         done
501
502         nrule_new=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
503             2>/dev/null | grep -c "$FSNAME.srpc.flavor.")
504         if [ $nrule_new != $nrule_old ]; then
505                 error "general rule: $nrule_new != $nrule_old"
506         fi
507
508         #
509         # target-specific rules
510         #
511         nrule_old=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
512             2>/dev/null | grep -c "$FSNAME-MDT0000.srpc.flavor.")
513         echo "original target rules: $nrule_old"
514
515         for ((i = $nrule_old; i < $max; i++)); do
516                 set_rule $FSNAME-MDT0000 ${NETTYPE}$i cli2mdt krb5i ||
517                         error "set new rule $i (1)"
518                 set_rule $FSNAME-MDT0000 ${NETTYPE}$i mdt2ost null ||
519                         error "set new rule $i (2)"
520                 set_rule $FSNAME-MDT0000 ${NETTYPE}$i mdt2mdt null ||
521                         error "set new rule $i (3)"
522         done
523         for ((i = $nrule_old; i < $max; i++)); do
524                 set_rule $FSNAME-MDT0000 ${NETTYPE}$i cli2mdt ||
525                         error "remove new rule $i (1)"
526                 set_rule $FSNAME-MDT0000 ${NETTYPE}$i mdt2ost ||
527                         error "remove new rule $i (2)"
528                 set_rule $FSNAME-MDT0000 ${NETTYPE}$i mdt2mdt ||
529                         error "remove new rule $i (3)"
530         done
531
532         nrule_new=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
533             2>/dev/null \ | grep -c "$FSNAME-MDT0000.srpc.flavor.")
534         if [ $nrule_new != $nrule_old ]; then
535                 error "general rule: $nrule_new != $nrule_old"
536         fi
537 }
538 run_test 99 "set large number of sptlrpc rules"
539
540 test_100() {
541         # started from default flavors
542         restore_to_default_flavor
543
544         mkdir $DIR/$tdir
545
546         # running dbench in background
547         start_dbench
548
549         #
550         # all: null -> krb5n -> krb5a -> krb5i -> krb5p
551         #
552         set_flavor_all krb5n
553         check_dbench
554
555         set_flavor_all krb5a
556         check_dbench
557
558         set_flavor_all krb5i
559         check_dbench
560
561         set_flavor_all krb5p
562         check_dbench
563
564         #
565         # * - MDT0: krb5a
566         # * - OST0: krb5i
567         #
568         # nothing should be changed because they are overridden by above rules
569         #
570         set_rule $FSNAME-MDT0000 any cli2mdt krb5a
571         set_rule $FSNAME-OST0000 any cli2ost krb5i
572         wait_flavor cli2mdt krb5p || error_dbench "1"
573         check_dbench
574         wait_flavor cli2ost krb5p || error_dbench "2"
575
576         #
577         # remove:
578         #  * - MDT0: krb5a
579         #  * - OST0: krb5i
580         #
581         set_rule $FSNAME-MDT0000 any cli2mdt
582         set_rule $FSNAME-OST0000 any cli2ost
583         check_dbench
584
585         #
586         # delete all rules
587         #
588         set_rule $FSNAME any mdt2mdt
589         set_rule $FSNAME any cli2mdt
590         set_rule $FSNAME any mdt2ost
591         set_rule $FSNAME any cli2ost
592         restore_to_default_flavor
593         check_dbench
594
595         stop_dbench
596 }
597 run_test 100 "change security flavor on the fly under load"
598
599 switch_sec_test()
600 {
601         local flavor0=$1
602         local flavor1=$2
603         local filename=$DIR/$tfile
604         local multiop_pid
605         local num
606
607         #
608         # after setting flavor0, start multiop which uses flavor0 rpc, and let
609         # server drop the reply; then switch to flavor1, the resend should be
610         # completed using flavor1. To exercise the code of switching ctx/sec
611         # for a resend request.
612         #
613         log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
614
615         set_rule $FSNAME any cli2mdt $flavor0
616         wait_flavor cli2mdt $flavor0
617         rm -f $filename || error "remove old $filename failed"
618
619         #MDS_REINT = 36
620         #define OBD_FAIL_PTLRPC_DROP_REQ_OPC     0x513
621         do_facet $SINGLEMDS lctl set_param fail_val=36
622         do_facet $SINGLEMDS lctl set_param fail_loc=0x513
623         log "starting multiop"
624         $MULTIOP $filename m &
625         multiop_pid=$!
626         echo "multiop pid=$multiop_pid"
627         sleep 1
628
629         set_rule $FSNAME any cli2mdt $flavor1
630         wait_flavor cli2mdt $flavor1
631
632         num=$(ps --no-headers -p $multiop_pid 2>/dev/null | wc -l)
633         [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
634         echo "process $multiop_pid is still hanging there... OK"
635
636         do_facet $SINGLEMDS lctl set_param fail_loc=0
637         log "waiting for multiop ($multiop_pid) to finish"
638         wait $multiop_pid || error "multiop returned error"
639 }
640
641 test_101()
642 {
643         # started from default flavors
644         restore_to_default_flavor
645
646         switch_sec_test null  krb5n
647         switch_sec_test krb5n krb5a
648         switch_sec_test krb5a krb5i
649         switch_sec_test krb5i krb5p
650         switch_sec_test krb5p null
651 }
652 run_test 101 "switch ctx/sec for resending request"
653
654 error_102()
655 {
656         local err_str=$1
657
658         killall -9 dbench
659         sleep 1
660
661         error $err_str
662 }
663
664 test_102() {
665         # started from default flavors
666         restore_to_default_flavor
667
668         mkdir $DIR/$tdir
669
670         # run dbench background
671         start_dbench
672
673         echo "Testing null->krb5n->krb5a->krb5i->krb5p->null"
674         set_flavor_all krb5n
675         set_flavor_all krb5a
676         set_flavor_all krb5i
677         set_flavor_all krb5p
678         set_flavor_all null
679
680         check_dbench
681
682         echo "waiting for 15s and check again"
683         sleep 15
684         check_dbench
685
686         echo "Testing null->krb5i->null->krb5i->null..."
687         for ((idx = 0; idx < 5; idx++)); do
688                 set_flavor_all krb5i
689                 set_flavor_all null
690         done
691         set_flavor_all krb5i
692
693         check_dbench
694
695         echo "waiting for 15s and check again"
696         sleep 15
697         check_dbench
698
699         stop_dbench
700 }
701 run_test 102 "survive from fast flavor switch"
702
703 test_150() {
704         local mount_opts
705         local count
706         local clients=$CLIENTS
707
708         [ -z $clients ] && clients=$HOSTNAME
709
710         # started from default flavors
711         restore_to_default_flavor
712
713         # at this time no rules has been set on mgs; mgc use null
714         # flavor to connect to mgs
715         count=$(flvr_cnt_mgc2mgs null)
716         [ $count -eq 1 ] || error "$count mgc connections use null flavor"
717
718         zconf_umount_clients $clients $MOUNT || error "umount failed (1)"
719
720         # mount client with conflict flavor - should fail
721         mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=krb5p"
722         zconf_mount_clients $clients $MOUNT $mount_opts &&
723                 error "mount with conflict flavor should have failed"
724
725         # mount client with same flavor - should succeed
726         mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=null"
727         zconf_mount_clients $clients $MOUNT $mount_opts ||
728                 error "mount with same flavor should have succeeded"
729         zconf_umount_clients $clients $MOUNT || error "umount failed (2)"
730
731         # mount client with default flavor - should succeed
732         zconf_mount_clients $clients $MOUNT ||
733                 error "mount with default flavor should have succeeded"
734 }
735 run_test 150 "secure mgs connection: client flavor setting"
736
737 exit_151() {
738         # remove mgs rule
739         set_rule _mgs any any
740
741         # umount everything, then remount
742         stopall
743         setupall
744 }
745
746 test_151() {
747         local new_opts
748
749         stack_trap exit_151 EXIT
750
751         # set mgs rule to only accept krb5p
752         set_rule _mgs any any krb5p
753
754         # umount everything, modules still loaded
755         stopall
756
757         # start gss daemon on mgs node
758         combined_mgs_mds || start_gss_daemons $mgs_HOST "$LSVCGSSD -vvv"
759
760         # start mgs
761         start mgs $(mgsdevname 1) $MDS_MOUNT_OPTS
762
763         # mount with default flavor, expected to fail
764         start ost1 "$(ostdevname 1)" $OST_MOUNT_OPTS
765         wait_mgc_import_state ost1 FULL 0 &&
766                 error "mount with default flavor should have failed"
767         stop ost1
768
769         # mount with unauthorized flavor should fail
770         if [ -z "$OST_MOUNT_OPTS" ]; then
771                 new_opts="-o mgssec=null"
772         else
773                 new_opts="$OST_MOUNT_OPTS,mgssec=null"
774         fi
775         start ost1 "$(ostdevname 1)" $new_opts
776         wait_mgc_import_state ost1 FULL 0 &&
777                 error "mount with unauthorized flavor should have failed"
778         stop ost1
779
780         # mount with designated flavor should succeed
781         if [ -z "$OST_MOUNT_OPTS" ]; then
782                 new_opts="-o mgssec=krb5p"
783         else
784                 new_opts="$OST_MOUNT_OPTS,mgssec=krb5p"
785         fi
786         start ost1 "$(ostdevname 1)" $new_opts
787         wait_mgc_import_state ost1 FULL 0 ||
788                 error "mount with designated flavor should have succeeded"
789
790         stop ost1 -f
791 }
792 run_test 151 "secure mgs connection: server flavor control"
793
794 complete_test $SECONDS
795 set_flavor_all null
796 cleanup_gss
797 check_and_cleanup_lustre
798 exit_status