]> piware.de Git - talk-cockpit-auth-anywhere.git/blob - cockpit-auth-anywhere.md
bc8783d7f8c4e8b4e86425826f6c7f29e0bff1af
[talk-cockpit-auth-anywhere.git] / cockpit-auth-anywhere.md
1 ---
2 title: Authenticate to Cockpit from anywhere
3 subtitle:
4 author: Martin Pitt <<mpitt@redhat.com>>
5 email: mpitt@redhat.com
6 date: DevConv.CZ 2020
7 theme: Singapore
8 header-includes:
9  - \setbeameroption{show notes}
10 ...
11
12 # Cockpit what?
13
14 - Interactive Server admin web interface
15 - Easy setup and troubleshooting for one or a few machines
16 - Included in all major distros
17
18 :::notes
19 - Conceptually: Linux session running in a web browser; technically very similar to ssh/VT/GNOME login
20 - Aimed at admins who are new to Linux, e. g. coming from the Windows world and familiar with the concepts, but not Linux terminology
21 - but also to experienced ones for infrequent tasks; not just setup, but also investigating “what is wrong with this machine”
22 :::
23
24
25 # Extending LVM
26
27 ```sh
28 pvcreate /dev/sdb2
29 vgextend vg0 /dev/sdb2
30 lvresize --extents '+100%FREE' vg0/data1
31 resize2fs /dev/vg0/data1
32 ```
33
34 :::notes
35 - for example, adding a new PV to an LV and resizing the file system you can spend some time coming up with these commands
36 - lots of possibilities for screwing up
37 - you can do it simply and safely with Cockpit like this → go to local browser
38 - Storage page, vg0 in Devices (top right), + in Physical Volumes, add sdb2
39 - expand data1 table line, click grow
40 :::
41
42 # Accessible from any browser
43
44  - Windows/Edge
45  - Mobile devices
46  - Simple install
47  - Zero configuration
48
49 :::notes
50 - Switch to Windows virt-viewer, open Edge, show Cockpit
51 - Quit virt-viewer
52 - Move to local browser, enable mobile mode (Ctrl+Shift+M)
53 - Zero configuration so far, other than possibly installing cockpit pkg and enabling cockpit.socket
54 - But wait, you say -- want to admin that server over there, but not allowed to
55   open new port and system service?
56 - In larger environments it's impractical to install cockpit server on hundreds
57   of machines and using the login web page; better solution: piggyback on ssh
58 - Glimpse of how to customize how cockpit runs and how to authenticate to it
59 :::
60
61 # Anatomy: cockpit-ws
62
63 ![ws-session](ws-session.pdf)\ 
64
65 - TCP http+WebSocket $\leftrightarrow$ JSON pipe
66 - collect credentials
67
68 :::notes
69 - for configuring, extending, and embedding Cockpit you need to coarsely understand the components of it
70 - this: simplest structure, what I just showed you and what you will most probably see the first time you try it
71 - browser only speaks HTTP and WebSocket, so you always need a web server, cockpit-ws
72 - all components in cockpit communicate to each other via a JSON protocol on standard pipes, usually stdio
73 - this provides a lot of flexibility and extensibility, as we'll see shortly
74 - ws roles: communicate with the browser for getting credentials: login page, krb negotiation, client cert
75 - ws: deliver HTML/js content, connects JSON protocol on the WebSocket to pipes to the other components; runs as unprivileged system user
76 :::
77
78 # Anatomy: cockpit-session
79
80 ![ws-session](ws-session.pdf)\ 
81
82 - ws credentials → PAM session
83 - forward JSON pipe to session leader
84
85 :::notes
86 - need some root helper to actually start session: use creds from ws to start PAM login session, connect pipe to it
87 - standard is cockpit-session: very small, auditable
88 - but doesn't have to be, that's the flexible part
89 :::
90
91 # Anatomy: cockpit-bridge
92
93 ![ws-session](ws-session.pdf)\ 
94
95 - session leader, cockpit's "bash"
96 - JSON on stdio $\leftrightarrow$ system APIs
97
98 :::notes
99 - bridge: session leader, moral equivalent of what bash is in ssh session
100 - JSON protocol on stdio to system APIs: exec programs, call D-Bus, work with files or sockets
101 - runs as target user in login session; complex, but no special privileges
102 :::
103
104 # SSH sessions
105
106 ![ssh-session](ssh-session.pdf)\ 
107
108 nothing Cockpit specific running outside of the user session
109
110 :::notes
111 - ws and the login session don't need to run on the same machine
112 - cockpit-session is meant to be customizable for your purposes
113 - most obvious replacement is to let ssh start a session; that already does the
114   PAM bits and forward its initial stdio to the session lead; it would just
115   launch cockpit-bridge instead of bash
116 - browser: go to Dashboard, add cockpit.dev:2201
117 - interesting property: nothing Cockpit specific running in the system, no ws,
118   no extra open port; only bit is bridge, but that's uninteresting from security POV
119 :::
120
121 # Bastion host
122
123 ![bastion-host](bastion-host.pdf)\ 
124
125 Enforce using ssh in cockpit.conf(5):
126 ```ini
127 [WebService]
128 RequireHost=true
129 ```
130
131 :::notes
132 - further illustrated by a mode that we call "bastion host"
133 - disable cockpit-session and local logins, only use ssh
134 - can run in container
135 - no ws on critical machines, don't trust cockpit-session
136 - switch to browser; log out, use "connect to" for cockpit.dev:2201
137 :::
138
139 # Other authentication setups
140
141 - SSO/Kerberos in Identity Management domains
142 - smart card/client certificate authentication
143 - OAuth (external embedding)
144 - Foreman: included cockpit-ws with dynamic configuration
145
146 TODO: foreman screenshot
147
148 :::notes
149 - Cockpit supports common authentication systems out of the box
150 - IdM is very common; if you have a krb ticket, you get a session immediately
151   without the login page
152 - browsers can ask for TLS client certificates, commonly with smart cards, and
153   present them to the web server; latest Cockpit versions supports that
154 - Foreman has a "Web Console" button; interesting case for seamless transition
155   between Foreman and Cockpit
156 - already has ssh to all maintained machines
157 - runs a single cockpit-ws process on its server, and dynamically configures it
158   for selected target machine
159 - custom cockpit session helper to do OAuth between Foreman session and
160   cockpit-ws, and wrap cockpit-ssh session starter
161 - not enough time to demo and explain all of this; just keep in mind that it's
162   possible
163 :::
164
165 # Embedding into existing session
166
167 ![local-session-unsafe](local-session-unsafe.pdf){height=60%}\ 
168
169 \footnotesize \verb!cockpit-ws -p 9999 --no-tls --local-session=/usr/bin/cockpit-bridge!
170
171 `firefox http://localhost:9999`
172
173 :::notes
174 - what I do want to show: opposite direction; "replace cockpit-session" can
175   also mean "by nothing"
176 - due to common JSON protocol, we can connect ws directly to a cockpit-bridge
177 - take a step back: if I want to admin this very machine, it's in a running
178   Linux session, it knows who I am
179 - put the whole auth structure inside out and instead run cockpit-ws as my user
180   inside my session
181 - open localhost:9999 in firefox
182 - alarm bells: exposes my session to a TCP port without any auth
183 :::
184
185
186 # Embedding into existing session: once more with safety!
187
188 ![local-session-unsafe](local-session.pdf){height=60%}\ 
189
190 \footnotesize \verb! !
191
192 `/usr/libexec/cockpit-desktop [page]`
193
194 :::notes
195 - need to hide that port; put browser and cockpit-ws into network namespace,
196   then they live in a completely isolated world
197 - do some work to hide browser chrome, use webkit if available
198 - cockpit-desktop /
199 - wants to run priv bridge, can accept or decline
200 - decline, R/O view
201 - can show an individual iframe, "page"
202 - suddenly you end up with a halfway decent desktop app
203 - just the storage page, replacement for gnome-disks
204 - cockpit-desktop podman
205 :::
206
207 # Conclusion
208
209 - Authentication is very flexible
210 - Works with zero configuration
211 - Can be arbitrarily embedded
212
213 :::notes
214 - Cockpit provides a set of standard auth protocols that are being used in
215   today's modern deployments
216 - Once you know about the structure, you can combine ssh, web servers, reverse
217   proxies, and custom auth helpers to embed Cockpit anywhere you want
218 :::
219
220
221 # Q & A
222
223 Contact:
224
225 - `#cockpit` on Freenode
226 - https://cockpit-project.org
227
228 Useful links:
229
230  * [Authentication configuration](https://cockpit-project.org/guide/latest/authentication.html)
231  * [Authentication protocol](https://github.com/cockpit-project/cockpit/blob/master/doc/authentication.md)
232
233 :::notes
234 - Home page leads to mailing lists, documentation
235 - thanks for your attention; Q+A
236 :::