]> piware.de Git - talk-cockpit-auth-anywhere.git/blob - cockpit-auth-anywhere.md
8fed3aef7219d21d8e40bebbc45cbb09168ccc23
[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 - 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 LV 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 - browser only speaks HTTP and WebSocket, so you always need a web server, cockpit-ws
73 - all components in cockpit communicate to each other via a JSON protocol on standard pipes, usually stdio
74 - this provides a lot of flexibility and extensibility, as we'll see shortly
75 - ws roles: communicate with the browser for getting credentials: login page, krb negotiation, client cert
76 - ws: deliver HTML/js content, connects JSON protocol on the WebSocket to pipes to the other components; runs as unprivileged system user
77 :::
78
79 # Anatomy: cockpit-session
80
81 ![ws-session](ws-session.pdf)\ 
82
83 - ws credentials → PAM session
84 - forward JSON pipe to session leader
85
86 :::notes
87 - need some root helper to actually start session: use creds from ws to start PAM login session, connect pipe to it
88 - standard is cockpit-session: very small, auditable
89 - but doesn't have to be, that's the flexible part
90 :::
91
92 # Anatomy: cockpit-bridge
93
94 ![ws-session](ws-session.pdf)\ 
95
96 - session leader, cockpit's "bash"
97 - JSON on stdio $\leftrightarrow$ system APIs
98
99 :::notes
100 - bridge: session leader, moral equivalent of what bash is in ssh session
101 - JSON protocol on stdio to system APIs: exec programs, call D-Bus, work with files or sockets
102 - runs as target user in login session; complex, but no special privileges
103 :::
104
105 # SSH sessions
106
107 ![ssh-session](ssh-session.pdf)\ 
108
109 nothing Cockpit specific running outside of the user session
110
111 :::notes
112 - ws and the login session don't need to run on the same machine
113 - cockpit-session is meant to be customizable for your purposes
114 - most obvious replacement is to let ssh start a session; that already does the
115   PAM bits and forward 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 TODO: foreman screenshot
149
150 :::notes
151 - Cockpit supports common authentication systems out of the box
152 - IdM is very common; if you have a krb ticket, you get a session immediately
153   without the login page
154 - browsers can ask for TLS client certificates, commonly with smart cards, and
155   present them to the web server; latest Cockpit versions supports that
156 - Foreman has a "Web Console" button; interesting case for seamless transition
157   between Foreman and Cockpit
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 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 :::
208
209 # Conclusion
210
211 - Authentication is very flexible
212 - Works with zero configuration
213 - Can be arbitrarily embedded
214
215 :::notes
216 - Cockpit provides a set of standard auth protocols that are being used in
217   today's modern deployments
218 - Once you know about the structure, you can combine ssh, web servers, reverse
219   proxies, and custom auth helpers to embed Cockpit anywhere you want
220 :::
221
222
223 # Q & A
224
225 Contact:
226
227 - `#cockpit` on Freenode
228 - https://cockpit-project.org
229
230 Useful links:
231
232  * [Authentication configuration](https://cockpit-project.org/guide/latest/authentication.html)
233  * [Authentication protocol](https://github.com/cockpit-project/cockpit/blob/master/doc/authentication.md)
234
235 :::notes
236 - Home page leads to mailing lists, documentation
237 - thanks for your attention; Q+A
238 :::