Whamcloud - gitweb
04accac2a8aab5591ace90c55275229e420475b7
[fs/lustre-release.git] / lustre / tests / acl / permissions.test
1 This script tests if file permissions are properly checked with and
2 without ACLs. The script must be run as root to allow switching users.
3 The following users are required. They must be a member in the groups
4 listed in parentheses.
5
6         bin (bin)
7         daemon (bin, daemon)
8
9
10 Cry immediately if we are not running as root.
11
12         $ id -u
13         > 0
14
15
16 First, set up a temporary directory and create a regular file with
17 defined permissions.
18
19         $ mkdir d
20         $ cd d
21         $ umask 027
22         $ touch f
23         $ ls -l f | awk -- '{ print $1, $3, $4 }'
24         > -rw-r----- root root
25
26
27 Make sure root has access to the file.  Verify that user daemon does not
28 have access to the file owned by root.
29
30         $ echo root > f
31
32         $ su daemon
33         $ echo daemon >> f
34         > f: Permission denied
35
36         $ su
37
38
39 Now, change the ownership of the file to bin:bin and verify that this
40 gives user bin write access.
41
42         $ chown bin:bin f
43         $ ls -l f | awk -- '{ print $1, $3, $4 }'
44         > -rw-r----- bin bin
45         $ su bin
46         $ echo bin >> f
47
48
49 User daemon is a member in the owning group, which has only read access.
50 Verify this.
51
52         $ su daemon
53         $ cat f
54         > root
55         > bin
56
57         $ echo daemon >> f
58         > f: Permission denied
59
60
61 Now, add an ACL entry for user daemon that grants him rw- access. File
62 owners and users capable of CAP_FOWNER are allowed to change ACLs.
63
64         $ su bin
65         $ setfacl -m u:daemon:rw f
66         $ getfacl --omit-header f
67         > user::rw-
68         > user:daemon:rw-
69         > group::r--
70         > mask::rw-
71         > other::---
72         >
73
74
75 Verify that the additional ACL entry grants user daemon write access.
76
77         $ su daemon
78         $ echo daemon >> f
79         $ cat f
80         > root
81         > bin
82         > daemon
83
84
85 Remove write access from the group class permission bits, and
86 verify that this masks daemon's write permission.
87
88         $ su bin
89         $ chmod g-w f
90         $ getfacl --omit-header f
91         > user::rw-
92         > user:daemon:rw-       #effective:r--
93         > group::r--
94         > mask::r--
95         > other::---
96         >
97
98         $ su daemon
99         $ echo daemon >> f
100         > f: Permission denied
101
102
103 Add an entry for group daemon with rw- access, and change the
104 permissions for user daemon to r--. Also change the others permissions t
105 rw-. The user entry should take precedence, so daemon should be denied
106 access.
107
108         $ su bin
109         $ setfacl -m u:daemon:r,g:daemon:rw-,o::rw- f
110
111         $ su daemon
112         $ echo daemon >> f
113         > f: Permission denied
114
115
116 Remove the entry for user daemon. The group daemon permissions should
117 now give user daemon rw- access.
118
119         $ su bin
120         $ setfacl -x u:daemon f
121
122         $ su daemon
123         $ echo daemon2 >> f
124         $ cat f
125         > root
126         > bin
127         > daemon
128         > daemon2
129
130
131 Set the group daemon permissions to r-- and verify that after than, user
132 daemon does not have write access anymore.
133
134         $ su bin
135         $ setfacl -m g:daemon:r f
136
137         $ su daemon
138         $ echo daemon3 >> f
139         > f: Permission denied
140
141
142 Now, remove the group daemon entry. Because user daemon is a member in
143 the owning group, he should still have no write access.
144
145         $ su bin
146         $ setfacl -x g:daemon f
147
148         $ su daemon
149         $ echo daemon4 >> f
150         > f: Permission denied
151
152
153 Change the owning group. The other permissions should now grant user
154 daemon write access.
155
156         $ su
157         $ chgrp root f
158
159         $ su daemon
160         $ echo daemon5 >> f
161         $ cat f
162         > root
163         > bin
164         > daemon
165         > daemon2
166         > daemon5
167
168
169 Verify that permissions in separate matching ACL entries do not
170 accumulate.
171
172         $ su
173         $ setfacl -m g:bin:r,g:daemon:w f
174
175         $ su daemon
176         $ : < f  # open for reading
177         $ : > f  # open for writing
178         $ : <> f  # open for read-write
179         > f: Permission denied
180
181
182 Test if directories can have ACLs.  We assume that only one access check
183 algorithm is used for all file types the file system, so these tests
184 only need to verify that ACL permissions make a difference.
185
186         $ su
187         $ mkdir -m 750 e
188         $ touch e/h
189
190         $ su bin
191         $ shopt -s nullglob ; echo e/*
192         >
193
194         $ echo i > e/i
195         > e/i: Permission denied
196
197         $ su
198         $ setfacl -m u:bin:rx e
199
200         $ su bin
201         $ echo e/*
202         > e/h
203 following 2 lines seems not valid, which also failed on ext3 in FC3 enviroment,
204 although it pass in FC2. commented out by CFS (agreed with HP)
205 Replaced "echo" with "touch" can resolve such problem.
206 #       $ echo i > e/i
207 #       > e/i: Permission denied
208         $ touch e/i
209         > touch: cannot touch `e/i': Permission denied
210
211         $ su
212         $ setfacl -m u:bin:rwx e
213
214         $ su bin
215         $ echo i > e/i
216
217
218 Test if symlinks are properly followed.
219
220         $ su
221         $ touch g
222         $ ln -s g l
223         $ setfacl -m u:bin:rw l
224         $ ls -l g | awk -- '{ print $1, $3, $4 }'
225         > -rw-rw----+ root root
226
227
228 Test if ACLs are effective for block and character special files, fifos,
229 sockets. This is done by creating special files locally. The devices do
230 not need to exist: The access check is earlier in the code path than the
231 test if the device exists.
232
233
234         $ mknod -m 0660 hdt b 91 64     # /dev/hdt
235         $ mknod -m 0660 null c 1 3      # /dev/null
236         $ mkfifo -m 0660 fifo
237
238         $ su bin
239         $ : < hdt
240         > hdt: Permission denied
241         $ : < null
242         > null: Permission denied
243         $ : < fifo
244         > fifo: Permission denied
245
246         $ su
247         $ setfacl -m u:bin:rw hdt null fifo
248
249         $ su bin
250         $ : < hdt
251         > hdt: No such device or address
252         $ : < null
253         $ ( echo blah > fifo & ) ; cat fifo
254         > blah
255
256
257 Test if CAP_FOWNER is properly honored for directories. This addresses a
258 specific bug in XFS 1.2, which does not grant root access to files in
259 directories if the file has an ACL and only CAP_FOWNER would grant them.
260
261         $ su
262         $ mkdir -m 600 x
263         $ chown daemon:daemon x
264         $ echo j > x/j
265         $ ls -l x/j | awk -- '{ print $1, $3, $4 }'
266         > -rw-r----- root root
267
268         $ setfacl -m u:daemon:r x
269
270         $ ls -l x/j | awk -- '{ print $1, $3, $4 }'
271         > -rw-r----- root root
272         (With the bug this gives: `ls: x/j: Permission denied'.)
273
274         $ echo k > x/k
275         (With the bug this gives: `x/k: Permission denied'.)
276
277         $ chmod 750 x
278
279
280 Clean up.
281
282         $ su
283         $ cd ..
284         $ rm -rf d