summaryrefslogtreecommitdiff
path: root/lectures/05-advanced-access-control.org
blob: 2fc801dd70fda7c54e95e60529f5b6f023b95a62 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#+title: Advanced Access Control
#+date: 2026-04-13 Mon
#+author: W. Kosior
#+email: wkosior@agh.edu.pl

* BSD securelevel
- FreeBSD, OpenBSD, macOS
- normally booted system (securelevel 1):
  - disallows writes to =/dev/mem=
  - raw writes to mounted filesystems forbidden
- securelevel 2
  - raw writes to filesystems forbidden
  - backwards clock changes forbidden
  - firewall rule changes forbidden
- assumption of compromised root account

* Apple System Integrity Protection ("rootless")
- not really "rootless"
- root powers restricted for usual root processes
- no write access to
  - =/System=
  - =/sbin=
  - =/bin=
  - =/usr=
  - =/Applications=

* DAC → MAC
- Discretionary Access Control
  - based on users and their permissions
  - identified with UNIX traditional model
- Mandatory Access Control
  - user's access limited to work on specific task
  - identified with later extensions to UNIX-like OSes
    - Linux kernel: post-2000
- DAC / MAC — naming from US government framework (70s)
  - meaningful wrt OS access controls?

* LSMs
- Linux Security Modules
  - not really "modules"
    - compiled-in extensions
  - supplement normal UNIX controls
  - major & minor LSMs
    - possibly multiple LSMs active simultaneously
    - at most one major LSM at a time

* LSMs, Cont.
- Linux Security Modules
  - not really "modules"
    - compiled-in extensions
  - supplement normal UNIX controls
  - major & minor LSMs (+ capabilities)
    - possibly multiple LSMs active simultaneously
    - at most one major LSM at a time
- =security=LIST_OF_MODULES= kernel arg
  - or compiled-in default list

* LSMs, Cont…
- Linux Security Modules
  - not really "modules"
    - compiled-in extensions
  - supplement normal UNIX controls
  - major & minor LSMs (+ capabilities)
    - possibly multiple LSMs active simultaneously
    - at most one major LSM at a time
- =security=LIST_OF_MODULES= kernel arg
  - or compile-in default list
- =/sys/kernel/security/=
- =/sys/kernel/security/lsm=
- =/proc/$PID/attr/$MODULE_NAME=

* Selected LSMs
- /Capabilities (formely not an LSM)/
- /Lockdown/
- Integrity Policy Enforcement
- Landlock
- LoadPin
- SafeSetID
- TOMOYO
- Yama
- AppArmor
- SMACK
- SELinux

* Selected LSMs, Cont.
- /Capabilities (formely not an LSM)/
- /Lockdown/
- Integrity Policy Enforcement (access control based on file origin)
- Landlock (sandboxing, inode-based)
- LoadPin (modules from RO devices only)
- SafeSetID (restricted =setuid()= as non-root)
- Yama (ptrace restrictions)
- AppArmor
- SMACK
- SELinux
- TOMOYO

* Selected LSMs, Cont…
- /Capabilities (formely not an LSM)/
- /Lockdown/
- Integrity Policy Enforcement (access control based on file origin)
- Landlock (sandboxing, inode-based)
- LoadPin (modules from RO devices only)
- SafeSetID (restricted =setuid()= as non-root)
- Yama (ptrace restrictions)
- *SMACK* (legacy major)
- *AppArmor* (legacy major)
- *SELinux* (legacy major)
- TOMOYO (former legacy major)

* Legacy Major LSMs
- *SMACK*
  - used in Tizen OS (Samsung TVs)
  - low complexity, policies based on file labels (xattrs)

* Legacy Major LSMs, Cont.
- *SMACK*
  - used in Tizen OS (Samsung TVs)
  - low complexity, policies based on file labels (xattrs)
- *AppArmor*
  - *presently* developed by Canonical
  - on by default in Ubuntu
  - moderately complex, policies based on paths (xattrs)

* Legacy Major LSMs, Cont…
- *SMACK*
  - used in Tizen OS (Samsung TVs)
  - low complexity, policies based on file labels (xattrs)
- *AppArmor*
  - *presently* developed by Canonical
  - on by default in Ubuntu
  - moderately complex, policies based on paths (xattrs)
- *SELinux*
  - *initiated* by NSA
  - on by default in Fedora & Red Hat
  - high complexity, policies based on file labels (xattrs)

* SMACK
- objects
  - processes
  - files
  - IP packet sources/targets
- subjects
  - processes

* SMACK, Cont.
- objects
  - processes
  - files
  - IP packet sources/targets
- subjects
  - processes
- object / subject labels
- operations (actions of subjects on objects)
  - read
  - write
  - execute
  - append (on files)

* SMACK, Cont…
- objects
  - processes
  - files
  - IP packet sources/targets
- subjects
  - processes
- object / subject labels
- operations (actions of subjects on objects)
  - read
  - write
  - execute
  - append (on files)
- access rules (additional restrictions on top of DAC)
  - =label_X label_Y rwx=
  - =/sys/fs/smackfs/=

* SMACK Labels
- e.g., =Puppy3=, =my:label=, =a,b,c=
  - ASCII, except =/=, =\=, ='=​, ="=, and unprintables
  - no assumed structure
  - length up to 255 (or 23)
- processes
  - =CAP_MAC_ADMIN= process can change to any label
  - unprivileged process is restricted in label changes

* SMACK Labels, Cont.
- e.g., =Puppy3=, =my:label=, =a,b,c=
  - ASCII, except =/=, =\=, ='=​, ="=, and unprintables
  - no assumed structure
  - length up to 255 (or 23)
- processes
  - =CAP_MAC_ADMIN= process can change to any label
  - unprivileged process restricted in label changes
- files / directories
  - =security.SMACK64= xattr — resource's label
  - =security.SMACK64EXEC= xattr — process' label after =exec()=
    - similar to SET-UID binaries; files only
  - =security.SMACK64TRANSMUTE= — new file's label
    - similar to SET-GID directories; directories only

* SMACK Labels, Cont…
- e.g., =Puppy3=, =my:label=, =a,b,c=
  - ASCII, except =/=, =\=, ='=​, ="=, and unprintables
  - no assumed structure
  - length up to 255 (or 23)
- processes
  - =CAP_MAC_ADMIN= process can change to any label
  - unprivileged process restricted in label changes
- files / directories
  - =security.SMACK64= xattr — resource's label
    - normally set to file creator process' label
  - =security.SMACK64EXEC= xattr — process' label after =exec()=
    - similar to SET-UID binaries; files only
  - =security.SMACK64TRANSMUTE= — new child file's label
    - similar to SET-GID directories; dirs only
- network packets can use label from IP CIPSO option
  - configured through =/sys/fs/smackfs/netlabel=

* SMACK Access Control Rules
- =subjectlabel objectlabel permissions=, e.g.,
  - =tiger musli rx=
    - proces labeled =tiger= can read & execute objects labeled =musli=
  - =:) tulip,bulb rawt-=
    - =:)= can read & append & write to =tulip,bulb=
    - =SMACK64TRANSMUTE= of =tulip,bulb= dirs takes effect (=t=)
    - minus ("=-=") — placeholder (omittable)
  - =Americano Bands -=
    - =Americano= has no access to =Bands=

* SMACK Access Control Rules, Cont.
- =subjectlabel objectlabel permissions=, e.g.,
  - =tiger musli rx=
    - proces labeled =tiger= can read & execute objects labeled =musli=
  - =:) tulip,bulb raw-=
    - =:)= can read & append & write to =tulip,bulb=
    - minus ("=-=") — placeholder (omittable)
  - =Americano Bands -=
    - =Americano= has no access to =Bands=
- =/sys/fs/smackfs/load2= — configure rules
  - one rule per subject-object labels pair
  - =echo 's_lbl o_lbl rwx' > /sys/fs/smackfs/load2= overrides old
  - persistence typically in =/etc/smack/accesses=
- =/sys/fs/smackfs/access2= — check for access
- =/sys/fs/smackfs/load-self2= — extra restrictions, per-process

* SMACK Special Labels
- =*= — can be accessed by all, cannot access any
- =^= — can read / execute everything
- =_= — can be read / executed by everyone
- mount options → default label for unlabeled files

* SMACK Access Logic
- allow if subject has =CAP_MAC_OVERRIDE=
- deny if subject is labeled =*=, otherwise
- allow if this is a read / execution by =^=, otherwise
- allow if this is a read / execution on =_=, otherwise
- allow it object is labeled =*=, otherwise
- allow if =subject_label = object_label=
- deny if per-process rules configured and lack the permission
- allow if currently loaded (global) rules allow
- deny by default

* SMACK Access Types
- process -> file
- process -> process (signal, ptrace)
  - extra configuration regarding ptrace available
- process or remote subject -> process or remote subject
  - packet sending = writing to target process
  - can be configured differently
    - socket attributes

* SMACK Bringup Mode
- =CONFIG_SECURITY_SMACK_BRINGUP= kernel config option
- permit & log certain accesses normally blocked
  - rule with =b= "permission"
  - processes with label written to =/sys/fs/smackfs/unconfined=
- rule set development
  - run new application with =b= rules or unconfined label
  - see what accesses are logged
  - prepare the rules adequately
  - make rules effective

* SMACK Process Relabeling
- =/proc/self/attr/{,smack/}current= — current process label
  - readable
  - writeable with =CAP_MAC_ADMIN=
  - writeable *without* =CAP_MAC_ADMIN= *if*:
    - target label written to =relabel-self=
- =/sys/fs/smackfs/relabel-self= — available target labels list
  - writeable with =CAP_MAC_ADMIN=

* SMACK — Summary
- simple
  - can be configured from ground up by the administrator
- uses files' extended attributes
  - can handle filesystems without these
- can be incrementally configured
- used in embedded systems
- suitable for securing containers
- not included in many distro's kernel binaries

* AppArmor
- objects use labels *internally* (not visible to the administrator)
- rules in profiles, written in =/etc/apparmor.d=
  - usually per-application
- userspace utilities used to (re)load profiles
- accesses allowed or blocked by path

* AppArmor Profile Syntax
#+begin_example
# This is a comment.
# File should be named `/etc/apparmor.d/usr.local.bin.foo'.
# The following is not a comment.
#include <tunables/global>
/usr/local/bin/foo flags=(complain) {
  # `complain' above inhibits blocking of access.  Would-be
  # violations are just logged.  "Learning mode".

  #include <abstractions/base>

  capability mknod, # Note the necessary comma.
  mount /dev/sd*,
  /bin/local/bin/foo mixr,
  /var/lib/foo/*     rw,
  /mnt/foobar/*      rw,
  link /var/lib/foo -> /mnt/foobar/,
}
#+end_example

* AppArmor Permission Types
- =k= — lock file
- =l= — create hard links
- =m= — memory map as executable
- =r= — read
- =w= — write
- =x= — execute
  - qualifiers: =p=, =P=, =c=, =C=, =u=, =U=, =i=
    - uppercase letter = environment variable scrubbing
  - fallbacks from =[pPcC]= to =[iuU]= possible

* AppArmor Profile Changes
- subprofiles
- hats
  - Apache =mod_apparmor=, dedicated profiles for
    - virtualhosts
    - URLs
    - paths, CGI applications

* AppArmor — Summary
- does not rely on extended attributes
  - can optionally use them
- relatively complex
  - configuration shipped with distro
  - easy to extend / supplement
- according to some, suitable for web servers
- widely available (Debian, Ubuntu, (Open)Suse)

* SELinux
- subects and objects have contexts
  #+begin_example
  foobar_u:foobar_r:foobar_t:=
  ^^^^     ^^^^     ^^^^
  user     role     type
  #+end_example
- subjects & objects can be
  - processes
  - files & directories
  - ports
- context stored in xattrs
  - relabeling needed when configuring SELinux