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