Whamcloud - gitweb
LU-11297 lnet: MR Routing Feature
[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 # Need to remove trailing '.' when SELinux is enabled
18
19         $ mkdir d
20         $ cd d
21         $ umask 027
22         $ touch f
23         $ chown nobody:nobody f
24         $ ls -l f | awk -- '{ sub(/\\.$/, "", $1); print $1, $3, $4 }'
25         > -rw-r----- nobody nobody
26         $ su nobody
27         $ echo nobody > f
28
29
30 Verify that the user bin don't have enough permission to set
31 extended attributes in user.* namespace.
32
33         $ su bin
34         $ setfattr -n user.test.xattr -v 123456 f
35         > setfattr: f: Permission denied
36
37
38 Now, add an ACL entry for user bin that grants him rw- access. File
39 owners and users capable of CAP_FOWNER are allowed to change ACLs.
40
41         $ su nobody
42         $ setfacl -m g:bin:rw f
43         $ getfacl --omit-header f
44         > user::rw-
45         > group::r--
46         > group:bin:rw-
47         > mask::rw-
48         > other::---
49         >
50
51
52 Verify that the additional ACL entry grants user bin permission
53 to set extended attributes in user.* namespace for files.
54
55         $ su bin
56         $ setfattr -n user.test.xattr -v 123456 f
57         $ getfattr -d f
58         > # file: f
59         > user.test.xattr="123456"
60         >
61
62
63 Test if symlinks are properly followed.
64 # Need to remove trailing '.' when SELinux is enabled
65
66         $ su
67         $ ln -s f l
68         $ ls -l l | awk -- '{ sub(/\\.$/, "", $1); print $1, $3, $4 }'
69         > lrwxrwxrwx root root
70         $ su bin
71         $ getfattr -d l
72         > # file: l
73         > user.test.xattr="123456"
74         >
75
76
77 Test the sticky directories. Only the owner and privileged user can
78 write attributes.
79 # Need to remove trailing '.' when SELinux is enabled
80
81         $ su
82         $ mkdir t
83         $ chown nobody:nobody t
84         $ chmod 1750 t
85         $ ls -dl t | awk -- '{ sub(/\\.$/, "", $1); print $1, $3, $4 }'
86         > drwxr-x--T nobody nobody
87         $ su nobody
88         $ setfacl -m g:bin:rwx t
89         $ getfacl --omit-header t
90         > user::rwx
91         > group::r-x
92         > group:bin:rwx
93         > mask::rwx
94         > other::---
95         >
96         $ su bin
97         $ setfattr -n user.test.xattr -v 654321 t
98         > setfattr: t: Operation not permitted
99
100
101 Verify that the additional ACL entry grants user bin permission
102 to set extended attributes in user.* namespace for directories.
103 # Need to remove trailing '.' when SELinux is enabled
104
105         $ su
106         $ mkdir d
107         $ chown nobody:nobody d
108         $ chmod 750 d
109         $ ls -dl d | awk -- '{ sub(/\\.$/, "", $1); print $1, $3, $4 }'
110         > drwxr-x--- nobody nobody
111         $ su nobody
112         $ setfacl -m g:bin:rwx d
113         $ getfacl --omit-header d
114         > user::rwx
115         > group::r-x
116         > group:bin:rwx
117         > mask::rwx
118         > other::---
119         >
120         $ su bin
121         $ setfattr -n user.test.xattr -v 654321 d
122         $ getfattr -d d
123         > # file: d
124         > user.test.xattr="654321"
125         >
126
127
128 Test that in user.* namespace, only regular files and directories can have
129 extended attributes.
130
131         $ su
132         $ mknod -m 0660 hdt b 91 64     # /dev/hdt
133         $ mknod -m 0660 null c 1 3      # /dev/null
134         $ mkfifo -m 0660 fifo
135         $ setfattr -n user.test.xattr -v 123456 hdt
136         > setfattr: hdt: Operation not permitted
137         $ setfattr -n user.test.xattr -v 123456 null
138         > setfattr: null: Operation not permitted
139         $ setfattr -n user.test.xattr -v 123456 fifo
140         > setfattr: fifo: Operation not permitted
141
142
143 Clean up.
144
145         $ su
146         $ cd ..
147         $ rm -rf d