Debian Codegraph @

autotests/input/test.apparmor

raw
1 # kate: syntax AppArmor Security Profile; replace-tabs off;
2
3 #
4 # Sample AppArmor Profile.
5 # License: Public Domain
6 #
7 # NOTE: This profile is not fully functional, since
8 # it is designed to test the syntax highlighting
9 # for the KDE's KSyntaxHighlighting framework.
10 #
11
12 include <tunables/global>
13
14 # Variable assignment
15 @{FOO_LIB}=/usr/lib{,32,64}/foo
16 @{USER_DIR}
17 = @{HOME}/Public @{HOME}/Desktop #No-Comment
18 @{USER_DIR} += @{HOME}/Hello \
19 deny owner #No-comment aa#aa
20 ${BOOL} = true
21
22 # Alias
23 alias /usr/ -> /mnt/usr/,
24
25 # ABI feature
26 abi <abi/3.0>,
27 abi <"includes/abi/4.19">,
28 abi "simple_tests/includes/abi/4.19",
29 abi simple_tests/includes/abi/4.19,
30
31 # Profile for /usr/bin/foo
32 profile foo /usr/bin/foo flags=(attach_disconnected enforce) xattrs=(myvalue=foo user.bar=* user.foo="bar" ) {
33 #include <abstractions/ubuntu-helpers>
34 #include<abstractions/wayland>
35 #include"/etc/apparmor.d/abstractions/ubuntu-konsole"
36 include "/etc/apparmor.d/abstractions/openssl"
37
38 include if exists <path with spaces>
39 include <include_tests/includes_okay_helper.include> #include <includes/base>
40 /some/file mr, #include <includes/base> /bin/true Px,
41
42 # File rules
43 /{,**/} r,
44 owner /{home,media,mnt,srv,net}/** r,
45 owner @{USER_DIR}/** rw,
46 audit deny owner /**/* mx,
47 /**.[tT][xX][tT] r, # txt
48
49 owner file @{HOME}/.local/share/foo/{,**} rwkl,
50 owner @{HOME}/.config/*.[a-zA-Z0-9]* rwk,
51
52 "/usr/share/**" r,
53 "/var/lib/flatpak/exports/share/**" r,
54 "/var/lib/{spaces in
55 string,hello}/a[^ a]a/**" r,
56
57 allow file /etc/nsswitch.conf r,
58 allow /etc/fstab r,
59 deny /etc/xdg/{autostart,systemd}/** r,
60 deny /boot/** rwlkmx,
61
62 owner @{PROC}/@{pid}/{cmdline,mountinfo,mounts,stat,status,vmstat} r,
63 /sys/devices/**/uevent r,
64 @{FOO_LIB}/{@{multiarch},64}/** mr,
65
66 /usr/bin/foo ixr,
67 /usr/bin/dolphin pUx,
68 /usr/bin/* Pixr,
69 /usr/bin/khelpcenter Cx -> sanitized_helper,
70 /usr/bin/helloworld cxr ->
71 hello_world,
72 /bin/** px -> profile,
73
74 # Dbus rules
75 dbus (send) #No-Comment
76 bus=system
77 path=/org/freedesktop/NetworkManager
78 interface=org.freedesktop.DBus.Introspectable
79 peer=(name=org.freedesktop.NetworkManager label=unconfined),
80 dbus (send receive)
81 bus=system
82 path=/org/freedesktop/NetworkManager
83 interface=org.freedesktop.NetworkManager
84 member={Introspect,state}
85 peer=(name=(org.freedesktop.NetworkManager|org.freedesktop.DBus)),
86 dbus (send)
87 bus=session
88 path=/org/gnome/GConf/Database/*
89 member={AddMatch,AddNotify,AllEntries,LookupExtended,RemoveNotify},
90 dbus (bind)
91 bus=system
92 name=org.bluez,
93
94 # Signal rules
95 signal (send) set=(term) peer="/usr/lib/hello/world// foo helper",
96 signal (send, receive) set=(int exists rtmin+8) peer=/usr/lib/hello/world//foo-helper,
97
98 # Child profile
99 profile hello_world {
100 # File rules (three different ways)
101 file /usr/lib{,32,64}/helloworld/**.so mr,
102 /usr/lib{,32,64}/helloworld/** r,
103 rk /usr/lib{,32,64}/helloworld/hello,file,
104
105 # Link rules (two ways)
106 l /foo1 -> /bar,
107 link /foo2 -> bar,
108 link subset /link* -> /**,
109
110 # Network rules
111 network inet6 tcp,
112 network netlink dgram,
113 network bluetooth,
114 network unspec dgram,
115
116 # Capability rules
117 capability dac_override,
118 capability sys_admin,
119 capability sys_chroot,
120
121 # Mount rules
122 mount options=(rw bind remount nodev noexec) vfstype=ecryptfs /home/*/.helloworld/ -> /home/*/helloworld/,
123 mount options in (rw, bind) / -> /run/hellowordd/*.mnt,
124 mount options=read-only fstype=btrfs /dev/sd[a-z][1-9]* -> /media/*/*,
125 umount /home/*/helloworld/,
126
127 # Pivot Root rules
128 pivot_root oldroot=/mnt/root/old/ /mnt/root/,
129 pivot_root /mnt/root/,
130
131 # Ptrace rules
132 ptrace (trace) peer=unconfined,
133 ptrace (read, trace, tracedby) peer=/usr/lib/hello/helloword,
134
135 # Unix rules
136 unix (connect receive send) type=(stream) peer=(addr=@/tmp/ibus/dbus-*,label=unconfined),
137 unix (send,receive) type=(stream) protocol=0 peer=(addr=none),
138 unix peer=(label=@{profile_name},addr=@helloworld),
139
140 # Rlimit rule
141 set rlimit data <= 100M,
142 set rlimit nproc <= 10,
143 set rlimit memlock <= 2GB,
144 set rlimit rss <= infinity,
145 set rlimit nice <= -12,
146
147 # Change Profile rules
148 change_profile unsafe /** -> [^u/]**,
149 change_profile unsafe /** -> {u,un,unc,unco,uncon,unconf,unconfi,unconfin,unconfine},
150 change_profile /bin/bash ->
151 new_profile//hat,
152 }
153
154 # Hat
155 ^foo-helper\/ {
156 network unix stream,
157 unix stream,
158
159 /usr/hi\"esc\x23esc\032es\477esc\*es\{esc\ rw r, # Escape expressions
160
161 # Text after a variable is highlighted as path
162 file /my/path r,
163 @{FOO_LIB}file r,
164 @{FOO_LIB}#my/path r, #Comment
165 @{FOO_LIB}ñ* r,
166 unix (/path\t{aa}*,*a @{var}*path,* @{var},*),
167 }
168 }
169
170 # Syntax Error
171 /usr/bin/error (complain, audit) {
172 file #include /hello r,
173
174 # Error: Variable open or with characters not allowed
175 @{var
176 @{sdf&s}
177
178 # Error: Open brackets
179 /{hello{ab,cd}world kr,
180 /{abc{abc kr,
181 /[abc kr,
182 /(abc kr,
183
184 # Error: Empty brackets
185 /hello[]hello{}hello()he kr,
186
187 # Comments not allowed
188 dbus (send) #No comment
189 path=/org/hello
190 #No comment
191 interface=org.hello #No comment
192 peer=(name=org.hello #No comment
193 label=unconfined), #Comment
194
195 # Don't allow assignment of variables within profiles
196 @{VARIABLE} = val1 val2 val3 # Comment
197
198 # Alias rules not allowed within profiles
199 alias /run/ -> /mnt/run/,
200
201 # Error: Open rule
202 /home/*/file rw
203 capability dac_override
204 deny file /etc/fstab w
205 audit network ieee802154,
206
207 dbus (receive
208 unix stream,
209 unix stream,
210 }
211
212 profile other_tests {
213 # set rlimit
214 set rlimit nice <= 3,
215 rlimit nice <= 3, # Without "set"
216 set #comment
217 rlimit
218 nice <= 3,
219
220 # "remount" keyword
221 mount remount
222 remount,
223 remount remount
224 remount,
225 dbus remount
226 remount,
227 unix remount
228 remount,
229 # "unix" keyword
230 network unix
231 unix,
232 ptrace unix
233 unix,
234 unix unix
235 unix,
236
237 # Transition rules
238 /usr/bin/foo cx -> hello*, # profile name
239 /usr/bin/foo Cx -> path/, # path
240 /usr/bin/foo cx -> ab[ad/]hello, # profile name
241 /usr/bin/foo Cx -> ab[cd/]a[ad/]hello/path, # path
242 /usr/bin/foo Cx -> ab[hello/path, # profile name
243
244 /usr/bin/foo cx -> "hello*", # profile name
245 /usr/bin/foo Cx -> "path/", # path
246 /usr/bin/foo cx -> "ab[ad/]hello", # profile name
247 /usr/bin/foo Cx -> "ab[cd/]a[ad/]hello/path", # path
248 /usr/bin/foo Cx -> "ab[hello/path", # profile name
249
250 /usr/bin/foo cx -> holas//hello/sa, # path
251 /usr/bin/foo cx -> df///dd//hat, # path + hat
252 /usr/bin/foo cx -> holas,#sd\323fsdf, # profile name
253
254 # Access modes
255 /hello/lib/foo rwklms, # s invalid
256 /hello/lib/foo rwmaix, # w & a incompatible
257 /hello/lib/foo kalmw,
258 /hello/lib/foo wa,
259 # OK
260 /hello/lib/foo rrwrwwrwrw,
261 /hello/lib/foo ixixix,
262 # Incompatible exec permissions
263 ixixux, uxuxUxux, ixixixPixix, ixixpx uxuxuxPuxux, UxUxcUxUx,
264 pixpixcixix, cxcxcxix, pixpixpux pixpixix xxix xxpux ixixx puxpuxx,
265 Cuxcux Pixpix, puxpUx puxPUx xxpix xxcx,
266 # Test valid permissions
267 r w a k l m l x ix ux Ux px Px cx Cx ,
268 pix Pix cix Cix pux Pux cux Cux pUx PUx cUx CUx,
269 rwklmx raklmx,
270 r rw rwk rwkl rwklm,
271 rwlmix rwlmUx rwlmPx rwlmcx rwlmPUx,
272 rwixixixkl rwUxUxUxkl rwuxuxuxk rwpxpxpxk rwPxPxkl rwcxcxlm rwCxCxk,
273 rwpixpixk rwPixPixkl wrpuxpuxk rwpUxpUxk rwcixcixcixml rwCixCixk rwCuxCuxk rwCUxCUxl,
274
275 # Profile name
276 profile holas { ... }
277 profile { ... }
278 profile /path { ... }
279 profile holas/abc { ... }
280 profile holas\/abc { ... }
281 profile
282 #holas { ... }
283
284 profile flags=(complain)#asd { ... }
285 profile flags flags=(complain) { ... }
286 profile flags(complain) { ... }
287 }