-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemd-security.tex
365 lines (289 loc) · 7.79 KB
/
systemd-security.tex
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
\documentclass[serif]{beamer}
%\usepackage[utopia]{mathdesign}
%\usepackage[no-math]{fontspec}
%\setmainfont{Liberation Serif}
\usepackage{minted}
\usepackage{hyperref}
\usepackage{ccicons}
%gets rid of bottom navigation bars
\setbeamertemplate{footline}[page number]{}
%gets rid of navigation symbols
\setbeamertemplate{navigation symbols}{}
\title[Systemd security features]{Securing your daemons using systemd}
\author{Zbigniew Jędrzejewski-Szmek}
\institute{%
\includegraphics{beamer-themeredhat/redhat.png}\\
\medskip
\textit{[email protected]}\\
\medskip
\ccbysa
}
\date{\tiny FOSDEM, Brussels, 2020.2.2}
\begin{document}
\begin{frame}
\titlepage % Print the title page as the first slide
\end{frame}
\begin{frame}
\frametitle{About me}
systemd upstream\\
Fedora (FESCo, systemd maint., Python SIG, Rust SIG)
\end{frame}
\begin{frame}[fragile]
\frametitle{Before we begin...\\Why use systemd for this at all?}
\begin{itemize}
\item centralization
\item abstraction of hardware architecture / kernel version
\item unprivileged operation
\end{itemize}
\pause
\bigskip
Numbers:
\begin{minted}{bash}
$ dnf repoquery --releasever=32 -l --whatprovides \
'/usr/lib/systemd/system/*' \
rg -i '^/usr/lib/systemd/system/[a-z0-9_@.\\-]+$' | \
sort -u | wc -l
1740!!!
\end{minted}
\end{frame}
\begin{frame}[fragile]
\frametitle{Before we begin...\\Unit files}
\pause
\begin{minted}{ini}
# /etc/systemd/system/mydaemon.service
[Service]
ExecStart=/usr/local/bin/mydaemon
\end{minted}
\begin{minted}{console}
$ sudo systemctl start mydaemon.service
\end{minted}
\medskip
\pause
\begin{minted}{console}
$ sudo /usr/local/bin/mydameon
\end{minted}
\medskip
\pause
\begin{minted}{console}
$ sudo systemd-run /usr/local/bin/mydameon
$ sudo systemd-run -t /usr/local/bin/mydameon
\end{minted}
\end{frame}
\begin{frame}[fragile]
\frametitle{Basics}
\pause
\texttt{User=}
\medskip
\pause
\begin{minted}{console}
$ systemd-run whoami
root
$ systemd-run --uid=zbyszek whoami
zbyszek
$ systemd-run -p User=zbyszek whoami
zbyszek
\end{minted}
\end{frame}
\begin{frame}
\frametitle{Limiting access to the file system}
\begin{itemize}
\item \texttt{ProtectHome=yes|read-only}
\item \texttt{ProtectSystem=yes|full|strict}
\pause
\item \texttt{InaccessiblePaths=}
\item \texttt{ReadOnlyPaths=}
\item \texttt{ReadWritePaths=}
\pause
\item \texttt{\textcolor{gray}{BindPaths=}}
\item \texttt{\textcolor{gray}{ReadOnlyBindPaths=}}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Limiting access to the file system}
\begin{itemize}
\item \texttt{PrivateTmp=yes}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Limiting access to the file system\\a better way}
\pause
\begin{columns}
\begin{column}{0.6\textwidth}
\begin{itemize}
\item \texttt{RuntimeDirectory=\textit{foo}}
\item \texttt{StateDirectory=\textit{foo}}
\item \texttt{CacheDirectory=\textit{foo}}
\item \texttt{LogsDirectory=\textit{foo}}
\item \texttt{ConfigurationDirectory=\textit{foo}}
\end{itemize}
\end{column}
\color{gray}
\begin{column}{0.4\textwidth}
/run/\textit{foo}/ \\[.32em]
/var/lib/\textit{foo}/ \\[.32em]
/var/cache/\textit{foo}/ \\[.32em]
/var/log/\textit{foo}/ \\[.32em]
/etc/\textit{foo}/
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\begin{minted}{console}
$ sudo systemd-run -t -p User=zbyszek \
-p RuntimeDirectory=foo \
ls -ld /run/foo
\end{minted}
\begin{itemize}
\item automatic \textit{creation} and \textit{ownership}
\item automatic \textit{removal}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{User creation on demand?}
\pause
\begin{itemize}
\item \texttt{DynamicUser=yes}
\end{itemize}
\pause
\begin{minted}{console}
$ systemd-run -p DynamicUser=1 -t whoami
\end{minted}
\pause
\begin{minted}{console}
run-u215640
\end{minted}
\pause
\begin{minted}{console}
$ echo -e 'asdf\nasdf' | \
\end{minted}
\pause
\begin{minted}{bash}
systemd-run --pipe -p DynamicUser=1 \
bash -c 'grep .; whoami' | \
\end{minted}
\pause
\begin{minted}{bash}
systemd-run --pipe -p DynamicUser=1 \
bash -c 'grep .; whoami' | \
\end{minted}
\pause
\begin{minted}{bash}
systemd-run --pipe -p DynamicUser=1 \
bash -c 'grep .; whoami'
\end{minted}
\end{frame}
\begin{frame}
\frametitle{What about the network?}
\pause
\begin{itemize}
\item \texttt{PrivateNetwork=yes}
\end{itemize}
\pause
``\texttt{PrivateNetwork=yes} is the recommeded way to run network services''
\end{frame}
\begin{frame}[c]
\frametitle{Socket Activation}
A daemon does not open a socket itself, it receives a socket from the manager
\medskip
\pause
\centering
Two types of socket activation:
\medskip
\begin{columns}
\begin{column}{0.5\textwidth}
\texttt{Accept=yes}\\
→ a single instance of the service is started for each connection\\
→ ``wait'' under inetd/xinetd
\end{column}
\begin{column}{0.5\textwidth}
\texttt{Accept=no}\\
→ a single instance of the service is started for each connection\\
→ ``nowait'' under inetd/xinetd
\end{column}
\end{columns}
\end{frame}
\begin{frame}
\frametitle{Per-service network firewall}
\begin{itemize}
\item \texttt{IPAddressAllow=\color{gray}10.20.30.0/24 1.2.3.4}
\item \texttt{IPAddressDeny=\color{gray}*}
\item \texttt{IP\{Ingress,Egress\}FilterPath=}
\end{itemize}
\bigskip
BPF!
\end{frame}
\begin{frame}[c]
\Huge{Low-level stuff}
\end{frame}
\begin{frame}
\begin{itemize}
\item \texttt{MemoryDenyWriteExecute=yes}
\item \texttt{PrivateDevices=yes}
\item \texttt{NoNewPrivileges=yes}
\item \texttt{RestrictSUIDSGID=yes}
\item \texttt{ProtectKernelTunables=yes}
\item \texttt{ProtectClock=yes}
\item \texttt{ProtectHostname=yes}
\item \texttt{ProtectKernelLogs=yes}
\item \texttt{LockPersonality=yes}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Capability limits}
\begin{itemize}
\item \texttt{CapabilityBoundingSet=}
\item \texttt{\textcolor{gray}{Capability=}}
\item \texttt{\textcolor{gray}{DropCapability=}}
\item \texttt{AmbientCapabilities=}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{System call filtering}
\framesubtitle{``seccomp mode 2''}
\pause
\begin{itemize}
\item \texttt{SyscallFilter=...}\\
implemented using \texttt{libseccomp}
\item \texttt{syscall1 | syscall2 | @group}
\item \texttt{@basic-io}
\item \texttt{\~@obsolete}
\medskip
\pause
\item \texttt{SystemCallArchitectures=native\color{gray}|x86\_64|i386|...}
\item \texttt{RestrictAddressFamilies=AF\_UNIX|AF\_INET|AF\_INET6
\color{gray}|AF\_CAN|AF\_APPLETALK|...}
\end{itemize}
\medskip
\pause
\begin{minted}{console}
$ systemd-analyze syscall-filter @obsolete
\end{minted}
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{systemd-analyze security}}
\begin{minted}{console}
$ systemd-analyze security systemd-resolved.service
\end{minted}
\end{frame}
\begin{frame}
\frametitle{Fedora 32: \texttt{systemd-analyze security *}}
\includegraphics[width=\textwidth]{images/fedora-scores.png}
\end{frame}
\begin{frame}
\frametitle{Stacking}
the application\\
systemd sandboxing\\
selinux | apparmor | ...\\
kernel
\end{frame}
\begin{frame}[fragile]
\textcolor{gray}{The End}
\bigskip
\url{https://github.com/systemd/systemd}\\
docs: \url{https://systemd.io/}\\
\phantom{docs: }\url{https://www.freedesktop.org/wiki/Software/systemd/}\hspace*{-5cm}\\
\medskip
this:\\
\url{https://github.com/keszybz/systemd-security-talk/blob/master/systemd-security.pdf}
\end{frame}
\end{document}