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