Whamcloud - gitweb
bcf947cb0ebddd5248204a9c1aa9f156e11f2823
[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 #       $ echo i > e/i
206 #       > e/i: Permission denied
207
208         $ su
209         $ setfacl -m u:bin:rwx e
210
211         $ su bin
212         $ echo i > e/i
213
214
215 Test if symlinks are properly followed.
216
217         $ su
218         $ touch g
219         $ ln -s g l
220         $ setfacl -m u:bin:rw l
221         $ ls -l g | awk -- '{ print $1, $3, $4 }'
222         > -rw-rw----+ root root
223
224
225 Test if ACLs are effective for block and character special files, fifos,
226 sockets. This is done by creating special files locally. The devices do
227 not need to exist: The access check is earlier in the code path than the
228 test if the device exists.
229
230
231         $ mknod -m 0660 hdt b 91 64     # /dev/hdt
232         $ mknod -m 0660 null c 1 3      # /dev/null
233         $ mkfifo -m 0660 fifo
234
235         $ su bin
236         $ : < hdt
237         > hdt: Permission denied
238         $ : < null
239         > null: Permission denied
240         $ : < fifo
241         > fifo: Permission denied
242
243         $ su
244         $ setfacl -m u:bin:rw hdt null fifo
245
246         $ su bin
247         $ : < hdt
248         > hdt: No such device or address
249         $ : < null
250         $ ( echo blah > fifo & ) ; cat fifo
251         > blah
252
253
254 Test if CAP_FOWNER is properly honored for directories. This addresses a
255 specific bug in XFS 1.2, which does not grant root access to files in
256 directories if the file has an ACL and only CAP_FOWNER would grant them.
257
258         $ su
259         $ mkdir -m 600 x
260         $ chown daemon:daemon x
261         $ echo j > x/j
262         $ ls -l x/j | awk -- '{ print $1, $3, $4 }'
263         > -rw-r----- root root
264
265         $ setfacl -m u:daemon:r x
266
267         $ ls -l x/j | awk -- '{ print $1, $3, $4 }'
268         > -rw-r----- root root
269         (With the bug this gives: `ls: x/j: Permission denied'.)
270
271         $ echo k > x/k
272         (With the bug this gives: `x/k: Permission denied'.)
273
274         $ chmod 750 x
275
276
277 Clean up.
278
279         $ su
280         $ cd ..
281         $ rm -rf d