summaryrefslogtreecommitdiff
path: root/talk.org
blob: 4ad63361fb4c1a2fb4d9df8b8568468d5eedcc2f (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
#+TODO: TODO(t) IN-PROGRESS DONE
#+STARTUP: indent
#+OPTIONS: ':nil *:t -:t ::t <:t H:2 \n:nil ^:t arch:headline
#+OPTIONS: author:t broken-links:nil c:nil creator:nil
#+OPTIONS: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t
#+OPTIONS: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t
#+OPTIONS: timestamp:t title:t toc:t todo:t |:t
#+TITLE: Securing Kopano with Apparmor
#+SUBTITLE: Kopano Conference 2017, Arnhem NL
#+DATE: 2017-09-28
#+AUTHOR: Guido Günther
#+EMAIL: agx@sigxcpu.org
#+LANGUAGE: en
#+SELECT_TAGS: export
#+EXCLUDE_TAGS: noexport
#+CREATOR: Emacs 25.2.2 (Org mode 9.0.9)
#+latex_header: \mode<beamer>{\usetheme{Copenhagen}}
#+latex_header: \setbeamertemplate{headline}{}
#+latex_header: \AtBeginSection[]{\begin{frame}<beamer>\frametitle{Topic}\tableofcontents[currentsection]\end{frame}}
#+COLUMNS: %40ITEM %10BEAMER_env(Env) %9BEAMER_envargs(Env Args) %4BEAMER_col(Col) %10BEAMER_extra(Extra)

* Who am I
:PROPERTIES:
:UNNUMBERED: t
:END:

** About me

- Debian Developer (libvirt et al., gbp, LTS, ...)
- GNOME contributor
- FSFE Fellow
- Freelancing Free Software Developer

** Intro
:PROPERTIES:
:BEAMER_env: note
:END:
- Purpose: learn what apparmor is, how to use it, how to debug, status of kopano apparmor

* What is Apparmor
  
** What is Apparmor

- pathname based Mandatory access control (MAC)
- Linux LSM, userspace tools and profiles
- Confines application to a limited set of resources via *profiles*
- These control
   - file read, write, execute, lock
   - Network access
   - raw socket access
   - allowed capabilities
   - rlimits
   - tracing
   - (dbus, signals)

** Apparmor Policy Example I
:PROPERTIES:
:BEAMER_ENVARGS: [t]
:END:

*** Apparmor Policy Example I :B_ignoreheading:
:PROPERTIES:
:BEAMER_env: ignoreheading
:END:
#+BEAMER: \fontsize{9}{7.2}\selectfont
#+name: Policy example
#+BEGIN_EXAMPLE
 
/usr/sbin/kopano-server { 
  #include <abstractions/base> 
  #include <abstractions/nameservice> 
  #include <abstractions/user-tmp> 
 
  capability chown, 
  ...
  capability setuid, 
 
  network tcp, 
 
  /etc/kopano/debian-db.cfg r, 
  /etc/kopano/server.cfg r, 
 
  @{PROC}/@{pid}/task/@{tid}/comm rw, 
  ...
 
#+END_EXAMPLE

** Apparmor Policy Example II
*** Apparmor Policy Example II :B_ignoreheading:
:PROPERTIES:
:BEAMER_env: ignoreheading
:END:
#+BEAMER: \fontsize{8}{7.2}\selectfont
#+BEGIN_EXAMPLE
  ...
  /run/kopano/prio.sock rw, 
  /run/kopano/server.pid rw, 
  /run/kopano/server.sock rw, 
 
  /usr/lib/x86_64-linux-gnu/kopano/*.so m, 

  ...
  profile kopano_userscripts { 
    file, 
    network, 
  } 
  ...
} 
#+END_EXAMPLE

** Building and Debugging profiles

- Denials are logged in kernel log, use *dmesg*
- aa-complain <program>
- aa-genprof <program>

** Apparmor Distro Support
#+BEAMER: \pause
*** Enabled by default in

- Ubuntu (lots of code upstreamed in 4.13)
- OpenSuSE
  
#+BEAMER: \pause
*** Installation on Debian
https://wiki.debian.org/AppArmor/HowToUse

#+BEGIN_SRC sh
  sudo apt install apparmor apparmor-{utils,profiles}
  mkdir /etc/default/grub.d
  echo 'GRUB_CMDLINE_LINUX_DEFAULT="'      \
           '$GRUB_CMDLINE_LINUX_DEFAULT'   \
           'apparmor=1 security=apparmor"' \
       > /etc/default/grub.d/apparmor.cfg
  update-grub && reboot

  aa-enabled && sudo aa-status
#+END_SRC

* Apparmor and Kopano
** Security Precautions in Kopano

- Services run as user kopano nowadays
- Built with hardening support (in Debian)

- But all services run as the _same_ user

** Why is MAC useful

- Webapp listens on the internet
- Z-Push listens on the internet
- e.g. kopano-dagent and kopano-search process untrusted input
- ...

** Restricting the MariaDB/Mysql I
*** Add and activate the profile

#+BEGIN_SRC sh
wget 'https://raw.githubusercontent.com/MariaDB/' \
     'server/10.2/' \
     'support-files/policy/apparmor/usr.sbin.mysqld'
touch /etc/apparmor.d/local/usr.sbin.mysqld
apparmor_parser -a /etc/apparmor.d/usr.sbin.mysqld
#+END_SRC

Needs current git version

*** Output
#+BEGIN_EXAMPLE
1 processes are unconfined but have a profile defined.
   /usr/sbin/mysqld (592) 
#+END_EXAMPLE

** Restricting the MariaDB/Mysql II
*** Restart the service
#+BEGIN_SRC sh
/etc/init.d/mysql restart
#+END_SRC

*** Output
#+BEGIN_EXAMPLE
1 processes are in complain mode.
   /usr/sbin/mysqld (2461) 
#+END_EXAMPLE

** Restricting the MariaDB/Mysql III
*** Enforce the policy
#+BEGIN_SRC sh
aa-enforce /usr/sbin/mysqld
#+END_SRC

*** Output
#+BEGIN_EXAMPLE
1 processes are in enforce mode.
   /usr/sbin/mysqld (2461) 
#+END_EXAMPLE

** Restricting kapano-server
- new profile created from scratch
*** Add the apparmor policy
#+BEGIN_SRC sh
  cd /etc/apparmor.d
  cp profiles/usr.sbin.kopano-server .
  touch local/usr.sbin.kopano-server
  apparmor_parser -a usr.sbin.kopano-server
  systemctl restart kopano-server
#+END_SRC

** Restricting kopano-dagent

***  kopano-dagent
- Reads untrusted network traffic
- Similar to the server but far less permissions
- New profile created from scratch

*** Add the apparmor policy
#+BEGIN_SRC sh
  cp profiles/usr.sbin.kopano-dagent /etc/apparmor.d/
  touch /etc/apparmor.d/local/usr.sbin.kopano-dagent
  apparmor_parser -a /etc/apparmor.d/usr.sbin.kopano-dagent
#+END_SRC

** Restricting kopano-search
- Indexes untrusted data
- Basic profile
*** Kopano Search

#+BEGIN_SRC 
touch local/usr.sbin.kopano-search
cp profiles/usr/sbin.kopano-search /etc/apparmor.d
apparmor_parser -a /etc/apparmor.d/usr.sbin.kopano-search
#+END_SRC

** TODO Other core services and helpers

kopano-archiver, kopano-backup, kopano-gateway, kopano-ical,
kopnao-monitor, kopano-spooler

** Restricting Webapp (Apache)
*** Restricting Apache itself

#+BEGIN_SRC sh
apt-get install libapache2-mod-apparmor
rm /etc/apparmor.d/disable/usr.sbin.apache2
apparmor_parser -r /etc/apparmor.d/usr.sbin.apache2
aa-status
#+END_SRC

** Restricting Webapp (Webapp)
- New profile created from scratch
- Add AAHatName to /etc/kopano/apache2.conf
- Enable profile
*** Restricting Webapp
#+BEGIN_SRC sh
 cp profiles/kopano-webapp /etc/apparmor.d/apache2.d/
 apparmor_parser -r /etc/apparmor.d/usr.sbin.apache2
 a2enmod apparmor
 systemctl restart apache2
#+END_SRC

** TODO Other Kopano Components

- +Z-Push+
- +Deskapp+
  (but see http://bugs.debian.org/742829 for chromium)
- +Mattermost+

** How you can help

See above

** Upstreaming Status
- [-] mariadb profile fixes
  - [X] https://github.com/MariaDB/server/pull/447
  - [ ] https://bugs.debian.org/875890
- [ ] apache2 profile fixes
  - [ ] https://code.launchpad.net/~intrigeri/apparmor/apache2-attach_disconnected/+merge/331065
  - [ ] http://bugs.debian.org/875892
- [-] kopanocore profiles
  - [ ] Upstream https://github.com/Kopano-mirror/kopano-core/pull/1
  - [X] Debian Package
- [X] kopano-webapp profile
  - [ ] Upstream not yet submitted
  - [X] Debian: Pushed to git
- [ ] dh-apparmor
  - Support /etc/apparmor.d/apache/: http://bugs.debian.org/876647

* Appendix							 :B_appendix:
  :PROPERTIES:
  :BEAMER_env: appendix
  :END:

** Thanks

- Send profile updates to <pkg-giraffe-discuss@lists.alioth.debian.org>
- Questions?

** Links
- http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference

** Status of Kopano in Debian

- kopanocore 8.3.4 is in Buster/testing 
- z-push 2.3.8 is in experimental
- Webapp 3.3.1 in waiting in new

# Local Variables:
# org-src-preserve-indentation: t
# End: