]> piware.de Git - talk-cockpit-auth-anywhere.git/blob - cockpit-auth-anywhere.md
3845cdedc961c592d4e32dc0464a765ceb6506ef
[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; better solution: piggyback on ssh
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: simplest 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 roles: 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 root 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
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 - cockpit-session is meant to be customizable for your purposes
115 - most obvious replacement is to let ssh start a session; that already does the
116   PAM bits and forward its initial stdio to the session lead; it would just
117   launch cockpit-bridge instead of bash
118 - browser: go to Dashboard, add cockpit.dev:2201
119 - interesting property: nothing Cockpit specific running in the system, no ws,
120   no extra open port; only bit is bridge, but that's uninteresting from security POV
121 :::
122
123 # Bastion host
124
125 ![bastion-host](bastion-host.pdf)\ 
126
127 Enforce using ssh in cockpit.conf(5):
128 ```ini
129 [WebService]
130 RequireHost=true
131 ```
132
133 :::notes
134 - further illustrated by a mode that we call "bastion host"
135 - disable cockpit-session and local logins, only use ssh
136 - can run in container
137 - no ws on critical machines, don't trust cockpit-session
138 - switch to browser; log out, use "connect to" for cockpit.dev:2201
139 - finish the demo script, press Enter
140 :::
141
142 # Other authentication setups
143
144 - SSO/Kerberos in Identity Management domains
145 - smart card/client certificate authentication
146 - OAuth (external embedding)
147 - Foreman: included cockpit-ws with dynamic configuration
148
149 :::notes
150 - Cockpit supports common authentication systems out of the box
151 - IdM is very common; if you have a krb ticket, you get a session immediately
152   without the login page
153 - browsers can ask for TLS client certificates, commonly with smart cards, and
154   present them to the web server; latest Cockpit versions supports that
155 - Foreman has a "Web Console" button; interesting case for seamless transition
156   between Foreman and Cockpit
157 - Show video
158 - already has ssh to all maintained machines
159 - runs a single cockpit-ws process on its server, and dynamically configures it
160   for selected target machine
161 - custom cockpit session helper to do OAuth between Foreman session and
162   cockpit-ws, and wrap cockpit-ssh session starter
163 - not enough time to demo and explain all of this; just keep in mind that it's
164   possible
165 :::
166
167 # Embedding into existing session
168
169 ![local-session-unsafe](local-session-unsafe.pdf){height=60%}\ 
170
171 \footnotesize \verb!cockpit-ws -p 9999 --no-tls --local-session=/usr/bin/cockpit-bridge!
172
173 `firefox http://localhost:9999`
174
175 :::notes
176 - what I do want to show: opposite direction; "replace cockpit-session" can
177   also mean "by nothing"
178 - due to common JSON protocol, we can connect ws directly to a cockpit-bridge
179 - take a step back: if I want to admin this very machine, it's in a running
180   Linux session, it knows who I am
181 - put the whole auth structure inside out and instead run cockpit-ws as my user
182   inside my session
183 - open --local-session in shell
184 - open localhost:9999 in firefox
185 - alarm bells: exposes my session to a TCP port without any auth
186 :::
187
188
189 # Embedding into existing session: once more with safety!
190
191 ![local-session-unsafe](local-session.pdf){height=60%}\ 
192
193 \footnotesize \verb! !
194
195 `/usr/libexec/cockpit-desktop [page]`
196
197 :::notes
198 - need to hide that port; put browser and cockpit-ws into network namespace,
199   then they live in a completely isolated world
200 - do some work to hide browser chrome, use webkit if available
201 - cockpit-desktop /
202 - wants to run priv bridge, can accept or decline
203 - decline, R/O view
204 - can show an individual iframe, "page"
205 - suddenly you end up with a halfway decent desktop app
206 - just the storage page, replacement for gnome-disks
207 - cockpit-desktop podman
208 - cockpit-desktop is small shell script, feel free to inspect and bend to your will
209 :::
210
211 # Conclusion
212
213 - Authentication is very flexible
214 - Works with zero configuration
215 - Can be arbitrarily embedded and customized
216
217 :::notes
218 - Cockpit provides a set of standard auth protocols that are being used in
219   today's modern deployments
220 - Once you know about the structure, you can combine ssh, web servers, reverse
221   proxies, and custom auth helpers to embed Cockpit anywhere you want
222 :::
223
224
225 # Q & A
226
227 Contact:
228
229 - `#cockpit` on Freenode
230 - https://cockpit-project.org
231
232 Useful links:
233
234  * [Authentication configuration](https://cockpit-project.org/guide/latest/authentication.html)
235  * [Authentication protocol](https://github.com/cockpit-project/cockpit/blob/master/doc/authentication.md)
236
237 :::notes
238 - Home page leads to mailing lists, documentation
239 - thanks for your attention; Q+A
240 :::