Whamcloud - gitweb
LU-1482 mdd: Setting xattr are properly checked with and without ACLs
[fs/lustre-release.git] / lustre / tests / acl / permissions_xattr.test
1 This script tests if extended attributes permissions are properly checked
2 with and without ACLs. The script must be run as root to allow switching
3 users. The following users are required.
4
5         bin
6         nobody
7
8
9 Cry immediately if we are not running as root.
10
11         $ id -u
12         > 0
13
14
15 First, set up a temporary directory and create a regular file with
16 defined permissions.
17
18         $ mkdir d
19         $ cd d
20         $ umask 027
21         $ touch f
22         $ chown nobody:nobody f
23         $ ls -l f | awk -- '{ print $1, $3, $4 }'
24         > -rw-r----- nobody nobody
25         $ su nobody
26         $ echo nobody > f
27
28
29 Verify that the user bin don't have enough permission to set
30 extended attributes in user.* namespace.
31
32         $ su bin
33         $ setfattr -n user.test.xattr -v 123456 f
34         > setfattr: f: Permission denied
35
36
37 Now, add an ACL entry for user bin that grants him rw- access. File
38 owners and users capable of CAP_FOWNER are allowed to change ACLs.
39
40         $ su nobody
41         $ setfacl -m g:bin:rw f
42         $ getfacl --omit-header f
43         > user::rw-
44         > group::r--
45         > group:bin:rw-
46         > mask::rw-
47         > other::---
48         >
49
50
51 Verify that the additional ACL entry grants user bin permission
52 to set extended attributes in user.* namespace for files.
53
54         $ su bin
55         $ setfattr -n user.test.xattr -v 123456 f
56         $ getfattr -d f
57         > # file: f
58         > user.test.xattr="123456"
59         >
60
61
62 Test if symlinks are properly followed.
63
64         $ su
65         $ ln -s f l
66         $ ls -l l | awk -- '{ print $1, $3, $4 }'
67         > lrwxrwxrwx root root
68         $ su bin
69         $ getfattr -d l
70         > # file: l
71         > user.test.xattr="123456"
72         >
73
74
75 Test the sticky directories. Only the owner and privileged user can
76 write attributes.
77
78         $ su
79         $ mkdir t
80         $ chown nobody:nobody t
81         $ chmod 1750 t
82         $ ls -dl t | awk -- '{ print $1, $3, $4 }'
83         > drwxr-x--T nobody nobody
84         $ su nobody
85         $ setfacl -m g:bin:rwx t
86         $ getfacl --omit-header t
87         > user::rwx
88         > group::r-x
89         > group:bin:rwx
90         > mask::rwx
91         > other::---
92         >
93         $ su bin
94         $ setfattr -n user.test.xattr -v 654321 t
95         > setfattr: t: Operation not permitted
96
97
98 Verify that the additional ACL entry grants user bin permission
99 to set extended attributes in user.* namespace for directories.
100
101         $ su
102         $ mkdir d
103         $ chown nobody:nobody d
104         $ chmod 750 d
105         $ ls -dl d | awk -- '{ print $1, $3, $4 }'
106         > drwxr-x--- nobody nobody
107         $ su nobody
108         $ setfacl -m g:bin:rwx d
109         $ getfacl --omit-header d
110         > user::rwx
111         > group::r-x
112         > group:bin:rwx
113         > mask::rwx
114         > other::---
115         >
116         $ su bin
117         $ setfattr -n user.test.xattr -v 654321 d
118         $ getfattr -d d
119         > # file: d
120         > user.test.xattr="654321"
121         >
122
123
124 Test that in user.* namespace, only regular files and directories can have
125 extended attributes.
126
127         $ su
128         $ mknod -m 0660 hdt b 91 64     # /dev/hdt
129         $ mknod -m 0660 null c 1 3      # /dev/null
130         $ mkfifo -m 0660 fifo
131         $ setfattr -n user.test.xattr -v 123456 hdt
132         > setfattr: hdt: Operation not permitted
133         $ setfattr -n user.test.xattr -v 123456 null
134         > setfattr: null: Operation not permitted
135         $ setfattr -n user.test.xattr -v 123456 fifo
136         > setfattr: fifo: Operation not permitted
137
138
139 Clean up.
140
141         $ su
142         $ cd ..
143         $ rm -rf d