3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 [ "$EXCEPT" ] && echo "Skipping tests: `echo $EXCEPT`"
13 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
14 export NAME=${NAME:-local}
16 LUSTRE=${LUSTRE:-`dirname $0`/..}
17 . $LUSTRE/tests/test-framework.sh
19 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
21 RUNAS=${RUNAS:-"$LUSTRE/tests/runas"}
22 WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
25 PERM_CONF=$CONFDIR/perm.conf
26 SANITYSECLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
29 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
30 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
34 USER0=`cat /etc/passwd|grep :$ID0:$ID0:|cut -d: -f1`
35 USER1=`cat /etc/passwd|grep :$ID1:$ID1:|cut -d: -f1`
38 echo "Please add user0 (uid=$ID0 gid=$ID0)! Skip sanity-sec" && exit 0
41 echo "Please add user1 (uid=$ID1 gid=$ID1)! Skip sanity-sec" && exit 0
43 check_and_setup_lustre
46 if [ "$I_MOUNTED" = "yes" ]; then
47 cleanupall -f || error "sec_cleanup"
52 [ -z "`echo $DIR | grep $MOUNT`" ] && \
53 error "$DIR not in $MOUNT" && sec_cleanup && exit 1
55 [ `echo $MOUNT | wc -w` -gt 1 ] && \
56 echo "NAME=$MOUNT mounted more than once" && sec_cleanup && exit 0
58 [ $MDSCOUNT -gt 1 ] && \
59 echo "skip multi-MDS test" && sec_cleanup && exit 0
62 GSS_REF=$(lsmod | grep ^ptlrpc_gss | awk '{print $3}')
63 if [ ! -z "$GSS_REF" -a "$GSS_REF" != "0" ]; then
65 echo "with GSS support"
68 echo "without GSS support"
71 MDT="`do_facet $SINGLEMDS "lctl get_param -N mdt.\*MDT\*.stats 2>/dev/null | cut -d"." -f2" || true`"
72 [ -z "$MDT" ] && error "fail to get MDT device" && exit 1
73 do_facet $SINGLEMDS "mkdir -p $CONFDIR"
74 IDENTITY_FLUSH=mdt.$MDT.identity_flush
76 CAPA_TIMEOUT=mdt.$MDT.capa_timeout
77 MDSSECLEVEL=mdt.$MDT.sec_level
80 if [ -z "$(lctl get_param -n llite.*.client_type | grep remote 2>/dev/null)" ]; then
96 if ! $RUNAS -u $user krb5_login.sh; then
97 error "$user login kerberos failed."
101 if ! $RUNAS -u $user -g $group ls $DIR > /dev/null 2>&1; then
102 $RUNAS -u $user lfs flushctx -k
103 $RUNAS -u $user krb5_login.sh
104 if ! $RUNAS -u $user -g $group ls $DIR > /dev/null 2>&1; then
105 error "init $user $group failed."
111 declare -a identity_old
114 for num in `seq $MDSCOUNT`; do
115 switch_identity $num true || identity_old[$num]=$?
118 if ! $RUNAS -u $ID0 ls $DIR > /dev/null 2>&1; then
119 sec_login $USER0 $USER0
122 if ! $RUNAS -u $ID1 ls $DIR > /dev/null 2>&1; then
123 sec_login $USER1 $USER1
128 # run as different user
132 chmod 0755 $DIR || error "chmod (1)"
133 rm -rf $DIR/$tdir || error "rm (1)"
134 mkdir -p $DIR/$tdir || error "mkdir (1)"
136 if [ "$CLIENT_TYPE" = "remote" ]; then
137 do_facet $SINGLEMDS "echo '* 0 normtown' > $PERM_CONF"
138 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
139 chown $USER0 $DIR/$tdir && error "chown (1)"
140 do_facet $SINGLEMDS "echo '* 0 rmtown' > $PERM_CONF"
141 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
143 chown $USER0 $DIR/$tdir || error "chown (2)"
146 $RUNAS -u $ID0 ls $DIR || error "ls (1)"
147 rm -f $DIR/f0 || error "rm (2)"
148 $RUNAS -u $ID0 touch $DIR/f0 && error "touch (1)"
149 $RUNAS -u $ID0 touch $DIR/$tdir/f1 || error "touch (2)"
150 $RUNAS -u $ID1 touch $DIR/$tdir/f2 && error "touch (3)"
151 touch $DIR/$tdir/f3 || error "touch (4)"
152 chown root $DIR/$tdir || error "chown (3)"
153 chgrp $USER0 $DIR/$tdir || error "chgrp (1)"
154 chmod 0775 $DIR/$tdir || error "chmod (2)"
155 $RUNAS -u $ID0 touch $DIR/$tdir/f4 || error "touch (5)"
156 $RUNAS -u $ID1 touch $DIR/$tdir/f5 && error "touch (6)"
157 touch $DIR/$tdir/f6 || error "touch (7)"
158 rm -rf $DIR/$tdir || error "rm (3)"
160 if [ "$CLIENT_TYPE" = "remote" ]; then
161 do_facet $SINGLEMDS "rm -f $PERM_CONF"
162 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
165 run_test 0 "uid permission ============================="
169 [ $GSS_SUP = 0 ] && skip "without GSS support." && return
171 if [ "$CLIENT_TYPE" = "remote" ]; then
172 do_facet $SINGLEMDS "echo '* 0 rmtown' > $PERM_CONF"
173 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
179 chown $USER0 $DIR/$tdir || error "chown (1)"
180 $RUNAS -u $ID1 -v $ID0 touch $DIR/$tdir/f0 && error "touch (2)"
181 echo "enable uid $ID1 setuid"
182 do_facet $SINGLEMDS "echo '* $ID1 setuid' >> $PERM_CONF"
183 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
184 $RUNAS -u $ID1 -v $ID0 touch $DIR/$tdir/f1 || error "touch (3)"
186 chown root $DIR/$tdir || error "chown (4)"
187 chgrp $USER0 $DIR/$tdir || error "chgrp (5)"
188 chmod 0770 $DIR/$tdir || error "chmod (6)"
189 $RUNAS -u $ID1 -g $ID1 touch $DIR/$tdir/f2 && error "touch (7)"
190 $RUNAS -u $ID1 -g $ID1 -j $ID0 touch $DIR/$tdir/f3 && error "touch (8)"
191 echo "enable uid $ID1 setuid,setgid"
192 do_facet $SINGLEMDS "echo '* $ID1 setuid,setgid' > $PERM_CONF"
193 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
194 $RUNAS -u $ID1 -g $ID1 -j $ID0 touch $DIR/$tdir/f4 || error "touch (9)"
195 $RUNAS -u $ID1 -v $ID0 -g $ID1 -j $ID0 touch $DIR/$tdir/f5 || error "touch (10)"
199 do_facet $SINGLEMDS "rm -f $PERM_CONF"
200 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
202 run_test 1 "setuid/gid ============================="
204 run_rmtacl_subtest() {
205 $SAVE_PWD/rmtacl/run $SAVE_PWD/rmtacl/$1.test
210 # for remote client only
212 [ "$CLIENT_TYPE" = "local" ] && \
213 skip "remote_acl for remote client only" && return
214 [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep ^acl)" ] && \
215 skip "must have acl enabled" && return
216 [ -z "$(which setfacl 2>/dev/null)" ] && \
217 skip "could not find setfacl" && return
218 [ "$UID" != 0 ] && skip "must run as root" && return
220 do_facet $SINGLEMDS "echo '* 0 rmtacl,rmtown' > $PERM_CONF"
221 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
225 sec_login daemon daemon
226 sec_login games users
232 echo "performing cp ..."
233 run_rmtacl_subtest cp || error "cp"
234 echo "performing getfacl-noacl..."
235 run_rmtacl_subtest getfacl-noacl || error "getfacl-noacl"
236 echo "performing misc..."
237 run_rmtacl_subtest misc || error "misc"
238 echo "performing permissions..."
239 run_rmtacl_subtest permissions || error "permissions"
240 echo "performing setfacl..."
241 run_rmtacl_subtest setfacl || error "setfacl"
243 # inheritance test got from HP
244 echo "performing inheritance..."
245 cp $SAVE_PWD/rmtacl/make-tree .
247 run_rmtacl_subtest inheritance || error "inheritance"
253 do_facet $SINGLEMDS "rm -f $PERM_CONF"
254 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
256 run_test 2 "rmtacl ============================="
259 # root_squash will be redesigned in Lustre 1.7
261 skip "root_squash will be redesigned in Lustre 1.7" && return
263 run_test 3 "rootsquash ============================="
265 # bug 3285 - supplementary group should always succeed.
266 # NB: the supplementary groups are set for local client only,
267 # as for remote client, the groups of the specified uid on MDT
268 # will be obtained by upcall /sbin/l_getidentity and used.
270 if [ "$CLIENT_TYPE" = "remote" ]; then
271 do_facet $SINGLEMDS "echo '* 0 rmtown' > $PERM_CONF"
272 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
277 chmod 0771 $DIR/$tdir
278 chgrp $ID0 $DIR/$tdir
279 $RUNAS -u $ID0 ls $DIR/$tdir || error "setgroups (1)"
280 if [ "$CLIENT_TYPE" = "local" ]; then
281 do_facet $SINGLEMDS "echo '* $ID1 setgrp' > $PERM_CONF"
282 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
283 $RUNAS -u $ID1 -G1,2,$ID0 ls $DIR/$tdir || error "setgroups (2)"
285 $RUNAS -u $ID1 -G1,2 ls $DIR/$tdir && error "setgroups (3)"
288 do_facet $SINGLEMDS "rm -f $PERM_CONF"
289 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
291 run_test 4 "set supplementary group ==============="
293 mds_capability_timeout() {
294 [ $# -lt 1 ] && echo "Miss mds capability timeout value" && return 1
296 echo "Set mds capability timeout as $1 seconds"
297 do_facet $SINGLEMDS "lctl set_param -n $CAPA_TIMEOUT=$1"
301 mds_sec_level_switch() {
302 [ $# -lt 1 ] && echo "Miss mds sec level switch value" && return 1
305 0) echo "Disable capa for all clients";;
306 1) echo "Enable capa for remote client";;
307 3) echo "Enable capa for all clients";;
308 *) echo "Invalid mds sec level switch value" && return 2;;
311 do_facet $SINGLEMDS "lctl set_param -n $MDSSECLEVEL=$1"
315 oss_sec_level_switch() {
316 [ $# -lt 1 ] && echo "Miss oss sec level switch value" && return 1
319 0) echo "Disable capa for all clients";;
320 1) echo "Enable capa for remote client";;
321 3) echo "Enable capa for all clients";;
322 *) echo "Invalid oss sec level switch value" && return 2;;
325 for i in `seq $OSTCOUNT`; do
326 local j=`expr $i - 1`
327 local OST="`do_facet ost$i "lctl get_param -N obdfilter.\*OST\*$j/stats 2>/dev/null | cut -d"." -f2" || true`"
328 [ -z "$OST" ] && return 3
329 do_facet ost$i "lctl set_param -n obdfilter.$OST.sec_level=$1"
334 mds_capability_switch() {
335 [ $# -lt 1 ] && echo "Miss mds capability switch value" && return 1
338 0) echo "Turn off mds capability";;
339 3) echo "Turn on mds capability";;
340 *) echo "Invalid mds capability switch value" && return 2;;
343 do_facet $SINGLEMDS "lctl set_param -n $MDSCAPA=$1"
347 oss_capability_switch() {
348 [ $# -lt 1 ] && echo "Miss oss capability switch value" && return 1
351 0) echo "Turn off oss capability";;
352 1) echo "Turn on oss capability";;
353 *) echo "Invalid oss capability switch value" && return 2;;
356 for i in `seq $OSTCOUNT`; do
357 local j=`expr $i - 1`
358 local OST="`do_facet ost$i "lctl get_param -N obdfilter.\*OST\*$j/stats 2>/dev/null | cut -d"." -f2" || true`"
359 [ -z "$OST" ] && return 3
360 do_facet ost$i "lctl set_param -n obdfilter.$OST.capa=$1"
366 mds_capability_switch 3 || return 1
367 mds_sec_level_switch 3 || return 2
372 oss_capability_switch 1 || return 1
373 oss_sec_level_switch 3 || return 2
377 turn_capability_on() {
378 local capa_timeout=${1:-"1800"}
380 # To turn on fid capability for the system,
381 # there is a requirement that fid capability
382 # is turned on on all MDS/OSS servers before
385 turn_mds_capa_on || return 1
386 turn_oss_capa_on || return 2
387 mds_capability_timeout $capa_timeout || return 3
388 remount_client $MOUNT || return 4
392 turn_mds_capa_off() {
393 mds_sec_level_switch 0 || return 1
394 mds_capability_switch 0 || return 2
398 turn_oss_capa_off() {
399 oss_sec_level_switch 0 || return 1
400 oss_capability_switch 0 || return 2
404 turn_capability_off() {
405 # to turn off fid capability, you can just do
406 # it in a live system. But, please turn off
407 # capability of all OSS servers before MDS servers.
409 turn_oss_capa_off || return 1
410 turn_mds_capa_off || return 2
414 # We demonstrate that access to the objects in the filesystem are not
415 # accessible without supplying secrets from the MDS by disabling a
416 # proc variable on the mds so that it does not supply secrets. We then
417 # try and access objects which result in failure.
421 [ $GSS_SUP = 0 ] && skip "without GSS support." && return
422 if ! remote_mds; then
423 skip "client should be separated from server."
431 error "turn_capability_off"
437 error "turn_oss_capa_on"
441 if [ "$CLIENT_TYPE" = "remote" ]; then
442 remount_client $MOUNT && return 3
446 remount_client $MOUNT || return 4
449 # proc variable disabled -- access to the objects in the filesystem
451 echo "Should get Write error here : (proc variable are disabled "\
452 "-- access to the objects in the filesystem is denied."
455 error "Write worked well even though secrets not supplied."
461 error "turn_capability_on"
467 # proc variable enabled, secrets supplied -- write should work now
468 echo "Should not fail here : (proc variable enabled, secrets supplied "\
469 "-- write should work now)."
472 error "Write failed even though secrets supplied."
478 error "turn_capability_off"
483 run_test 5 "capa secrets ========================="
485 # Expiry: A test program is performing I/O on a file. It has credential
486 # with an expiry half a minute later. While the program is running the
487 # credentials expire and no automatic extensions or renewals are
488 # enabled. The program will demonstrate an I/O failure.
492 [ $GSS_SUP = 0 ] && skip "without GSS support." && return
493 if ! remote_mds; then
494 skip "client should be separated from server."
500 error "turn_capability_off"
506 turn_capability_on 30
508 error "turn_capability_on 30"
515 error "$WTL $file 60"
519 # Reset MDS capability timeout
520 mds_capability_timeout 30
522 error "mds_capability_timeout 30"
530 # To disable automatic renew, only need turn capa off on MDS.
533 error "turn_mds_capa_off"
537 echo "We expect I/O failure."
540 echo "no I/O failure got."
546 error "turn_capability_off"
551 run_test 6 "capa expiry ========================="
553 log "cleanup: ======================================================"
556 for num in `seq $MDSCOUNT`; do
557 if [ "${identity_old[$num]}" = 1 ]; then
558 switch_identity $num false || identity_old[$num]=$?
562 $RUNAS -u $ID0 ls $DIR
563 $RUNAS -u $ID1 ls $DIR
569 echo '=========================== finished ==============================='
570 [ -f "$SANITYSECLOG" ] && \
571 cat $SANITYSECLOG && grep -q FAIL $SANITYSECLOG && exit 1 || true