-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
622 lines (590 loc) · 23.8 KB
/
index.html
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Theo Presentation</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/blood.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match(/print-pdf/gi) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
<!-- custom css -->
<link rel="stylesheet" href="css/theo.css">
<link rel="icon" type="image/png" href="/assets/favicon.png">
</head>
<body>
<div class="theo-fish"><img class="plain" src="assets/theo-logo.png" alt="Theo The Fish"/></div>
<section class="reveal">
<section class="slides">
<!-- slide 0 -->
<section>
<img class="logo plain" src="assets/theo-logo.png" alt="Theo Logo" style="max-width: 400px"/>
<h4>The Authorized_Keys Manager</h4>
<a href="https://github.com/theoapp" target="_blank">https://github.com/theoapp</a>
<hr/>
Michele Azzolari<br/>
<a href="https://github.com/macno" target="_blank">@macno</a>
</section>
<!-- slide 1 -->
<section>
<h4>GET /api/v1/users/me</h4>
<pre class="fragment" data-fragment-index="1"><code class="hljs json">{
"fullname": "Michele Azzolari",
"description": "Dad, Full Stack Developer, Avid music listener",
"nickname": "macno",
"created_at": "1977-04-11T18:40Z",
"current_job": "CTO and co-founder Fluidware srl",
"city": "Milan, Italy"
}</code></pre>
</section>
<!-- slide 2 -->
<section>
<h2>GLOSSARY</h2>
<dl class="dl-horizontal">
<dt>host</dt>
<dd>the computer you want to connect to via SSH (where sshd is running)</dd>
<dt>user</dt>
<dd>the login name (OS User) you want to connect to via SSH</dd>
<dt>account</dt>
<dd>whoever connects, physical person or virtual account (the private key owner)</dd>
</dl>
</section>
<!-- slide 3 -->
<section>
<section>
<h2>WHY THEO?</h2>
<ul class="fragment ">
<li >I use several laptops</li>
<li >I manage several servers</li>
<li >I work with different teams</li>
</ul>
</section>
<section>
<h3>And what happens when...</h3>
<div class="fragment ">
<ul >
<li >A new laptop/desktop has to be activated</li>
<li >An old laptop/desktop has to be dismissed</li>
<li >A new server has to be installed</li>
<li >A new member joins the team</li>
<li >A current member leaves the team</li>
</ul>
<p>?</p>
</div>
</section>
<section>
<h3>You need to update <span class="green">authorized_keys</span> EVERYWHERE!</h3>
<p class="fragment" data-fragment-index="1">Of course if you use them</p>
<p class="red fragment" data-fragment-index="2">And if you don't... you should!</p>
</section>
<section>
<h3>I hate doing this stuff</h3>
</section>
<section>
<h5>Error prone</h5>
<ul>
<li>Files are scattered in several places (a full matrix of hosts/users)</li>
</ul>
</section>
<section>
<h5>Critical but monkey work</h5>
<ul>
<li>I do the same thing over and over again</li>
<li>If I forget to add a key, someone will complain she can't do her job</li>
<li>If I forget to remove a key, someone will have access to hosts while she shouldn't</li>
</ul>
</section>
<section>
<h5>You miss the full picture</h5>
<ul>
<li>Did I forget something? There's no way to verify but checking everything</li>
<li>Who can access what?</li>
</ul>
</section>
</section>
<!-- slide 4 -->
<section>
<section>
<h2>So?</h2>
<h4 class="fragment green" data-fragment-index="1">I definitely want a single place to manage
all that stuff!</h4>
</section>
<section>
<h2>Then?</h2>
<h4 class="fragment green" data-fragment-index="1">Ansible/Puppet/Chef or config management
tool of your choice can help or...</h4>
</section>
<section>
<p>
Since openssh 6.2 (2013-03-22) a new option is available
</p>
<p class="fragment" data-fragment-index="1">
<em>AuthorizedKeysCommand</em>
</p>
<p class="fragment" data-fragment-index="2">
which supports fetching authorized_keys from a command's stdout besides (or
instead of) the filesystem.
<br/>
<small><a href="https://www.openssh.com/txt/release-6.2" target="_blank">https://www.openssh.com/txt/release-6.2</a>
</small>
</p>
</section>
<section>
<h2 class="green">EUREKA!</h2>
<p class="fragment">
<small>Thanks <a href="https://github.com/johnnyrun" target="_blank">@johnnyrun</a> for heading me
there
</small>
</p>
</section>
</section>
<!-- slide 5 -->
<section>
<section>
<h3>The idea</h3>
<p>Store <em>accounts/public keys/permissons</em> in a single place and serve them via HTTPS to the
hosts</p>
</section>
<section>
<img src="assets/laptop.png" class="laptop"/><br/>
Account connects to host:
<pre>ssh a.user@server1</pre>
</section>
<section>
<img src="assets/server.svg" class="server"/><br/>
Host fetches authorized_keys from external server by passing its hostname and the user:
<pre>GET /authorized_keys/server1/a.user</pre>
</section>
<section>
<img src="assets/server.svg" class="server"/><br/>
Server looks up for keys which are authorized for user <em>a.user</em> on host <em>server1</em>:<br/>
</section>
<section>
<img src="assets/server.svg" class="server"/><br/>
If it finds any, it returns them to the host:<br/>
<pre><code>
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD[....]GQWv5CcHIe1kQljCzz [email protected]
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQ[....]rhAdoKKhbGfAdUw0xv macno@gruff
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQ[....]347PRq7LplS03D7xUw== macno@habanero</code></pre>
</section>
</section>
<!-- slide 6 -->
<section>
<section>
<h3>Theo</h3>
<p>Involves 3 components</p>
<ul>
<li class="fragment">Theo Server</li>
<li class="fragment">Theo Agent</li>
<li class="fragment">Theo CLI</li>
</ul>
</section>
<!-- slide 6.1 -->
<section>
<h3>Theo Server</h3>
<ul>
<li class="fragment">Available as docker image <a href="https://hub.docker.com/r/theoapp/theo/"
target="_blank">theoapp/theo</a></li>
<li class="fragment">Uses sqlite3 or MariaDB to store data</li>
<li class="fragment">Supports caching per-user/host authorized_keys
with memcached or redis
</li>
<li class="fragment">Written in node.js</li>
</ul>
</section>
<!-- slide 6.2 -->
<section>
<h3>Theo Server</h3>
Exposes several REST APIs for manipulating:
<ul>
<li class="fragment">Accounts</li>
<li class="fragment">Groups</li>
<li class="fragment">Authorized_keys</li>
<li class="fragment">Permissions</li>
</ul>
<p class="fragment green">Consumed by Theo CLI</p>
</section>
<!-- slide 6.3 -->
<section>
<h3>Theo Server</h3>
Exposes an endpoint for fetching authorized_keys
<p class="fragment green">Consumed by Theo Agent</p>
</section>
<!-- slide 6.4 -->
<section>
<h3>Theo Agent</h3>
<ul>
<li class="fragment">Easy-to-use self-install feature</li>
<li class="fragment">Keeps a per-user local copy of authorized_keys in the event that Theo Server is
unreachable
</li>
<li class="fragment">Can verify authorized keys signatures (and discard them if not valid)</li>
<li class="fragment">Written in go</li>
</ul>
</section>
<!-- slide 6.5 -->
<section>
We wrote an agent, but it can be replaced by a shell script that curls Theo Server <sup>1</sup>
<div class="fragment" style="margin-top: 100px">
<small><strong>1</strong> Sigthly harder when signature verification is needed</small>
</div>
</section>
<!-- slide 6.6 -->
<section>
<h3>Theo CLI</h3>
<ul>
<li class="fragment">Available as npm package <a
href="https://www.npmjs.com/package/theoapp-cli"
target="_blank">theoapp-cli</a></li>
<li class="fragment">Supports authorized keys signatures</li>
<li class="fragment">Written in node.js</li>
</ul>
</section>
</section>
<section>
<section>
<h3>What is Authorized Keys Signing?</h3>
<p class="fragment">
To avoid unauthorized keys to be returned to SSHD, Theo CLI and Theo Agent both support
a way to sign (Theo CLI) and to verify (Theo Agent) each key.
</p>
</section>
<section>
<h3>Theo CLI</h3>
<p>
Using a private key, when it sends a public key to Theo Server, it attaches also a digital signature
of the key.
</p>
</section>
<section>
<h3>Theo Agent</h3>
<p>
Using the corresponding public key of the certificate used by Theo CLI, it verifies each retrieved
public key with its signature.
</p>
</section>
</section>
<!-- slide 7 -->
<section>
<h3>Let's put everything together!</h3>
<p>
To test it locally, you need a machine with node, docker and a virtualization software<br/>
In the next slides I will use macos with node 8.9.4, docker 18.06.1-ce and virtualbox 5.2.20 (with
vagrant 2.2.1). The VM <code>test-server</code> has been created using <a href="vagrant/Vagrantfile"
target="_blank">this
Vagrantfile</a>.
</p>
</section>
<!-- slide 8 -->
<section>
<h3>Theo Server</h3>
<section>
Let's generate some tokens for administration and client authentication
<pre><code class="hljs bash">$ head -1 /dev/urandom | base64 | head -3
AWPJQZDWIG8/RgRvJQf7oBOpbt2deEVv/79+O5DTL6wEZC33HsaefORMRhx3ocDQ8X3LsA79MNIU
vW0bhte0SDI4ZtL26m7O4+W3Z44pWfdjHnrZorOtOlvHlqBM6O/UW+dNIDK/GEy8bURlTjpjEHvG
SooEMhppFnYZofmG2Fx438L9i7fM1keXbWQdRWGN+ipmMZ2VP+pQGywNpCIq4K6mdDHfKeLzCEcB</code></pre>
<small>We will use the first string as administration token and the last two as client tokens</small>
</section>
<section>
Run Theo Server as container
<pre><code class="hljs bash">$ docker run --rm -v /tmp/theo:/data \
--name theo-server \
-e DATA_PATH=/data/theo.db \
-e ADMIN_TOKEN="AWPJQZDWIG8/RgRvJQf7oBOpbt2deEVv/79+O5DTL6wEZC33HsaefORMRhx3ocDQ8X3LsA79MNIU" \
-e CLIENT_TOKENS="vW0bhte0SDI4ZtL26m7O4+W3Z44pWfdjHnrZorOtOlvHlqBM6O/UW+dNIDK/GEy8bURlTjpjEHvG,SooEMhppFnYZofmG2Fx438L9i7fM1keXbWQdRWGN+ipmMZ2VP+pQGywNpCIq4K6mdDHfKeLzCEcB" \
-p 9100:9100 theoapp/theo
> [email protected] start /usr/src/app
> node ./build/index.js
theo/0.12.0 listening at http://[::]:9100
</code></pre>
</section>
<section><h4 class="green">That's it!</h4></section>
</section>
<!-- slide 9 -->
<section>
<h3>Theo CLI</h3>
<section>
Let's install <span class="green">Theo CLI</span> using npm:
<pre><code class="hljs bash">$ npm i -g theoapp-cli</code></pre>
</section>
<section>
Let's set the environment variables:
<pre><code class="hljs bash smaller">
$ export THEO_URL=http://localhost:9100
$ export THEO_TOKEN="AWPJQZDWIG8/RgRvJQf7oBOpbt2deEVv/79+O5DTL6wEZC33HsaefORMRhx3ocDQ8X3LsA79MNIU"
</code></pre>
<small>We can also put these variables in a file and save it as<br/>
<code>~/.theo/env</code><br/>or<br/>
<code>/etc/theo/env</code>
</small>
</section>
<section>
Let's create few of accounts
<pre><code class="hljs bash smaller">
$ theo accounts add \
--name "Developer 1" \
--email "[email protected]"
+------------------------------------+
{
"id": 1,
"name": "Developer 1",
"email": "[email protected]",
"active": 1,
"expire_at": 0,
"public_keys": [],
"groups": [
{
"id": 1,
"name": "[email protected]",
"active": 1
}
],
"permissions": []
}
+------------------------------------+
$ theo keys add [email protected] \
--key "$(cat ~/.ssh/id_rsa.pub)"
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
{
"account_id": 1,
"public_keys": [
{
"id": 1,
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQD4DaQVgWsexxOabTPxnDau5UsQj5eGUgXLD+28rtWMEAIzehiCcM5y0aOVZO/dBHA7NyHo/jWcw6Dew/Ty/J2WAQwXtV0xFTuA+6TpWBl35UeRJwjuuGnk0nCuvxQL9qs8+7CPis9SNlIQ38wXnsHWuWKEqnTAoO5YdRsjoGtILw== macno@habanero"
}
]
}
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
$ theo accounts add \
--name "Developer 2" \
--email "[email protected]"
[...]
$ theo keys add [email protected] \
--key "$(cat ~/.ssh/id_rsa.pub)"
$ theo accounts add \
--name "Sysop A" \
--email "[email protected]"
[...]
$ theo keys add [email protected] \
--key "$(cat ~/.ssh/id_rsa.pub)"
[...]</code></pre>
</section>
<section>
Let's create a group:
<pre><code class="hljs bash smaller">
$ theo groups add --name developers
+------------------------+
{
"id": 4,
"name": "developers",
"active": 1,
"accounts": [],
"permissions": []
}
+------------------------+
</code></pre>
</section>
<section>
Let's add accounts to the group <em>developers</em>:
<pre><code class="hljs bash smaller">
$ theo groups edit developers --add [email protected] [email protected]
+----------------+
{
"status": 201
}
+----------------+
</code></pre>
</section>
<section>
Let's add permission to <em>developers</em> to login as <em>node</em> on host <em>test-server</em>:
<pre><code class="hljs bash smaller">
$ theo permissions add --group developers --host test-server --user node
+---------------------+
{
"group_id": 4,
"permission_id": 1
}
+---------------------+
</code></pre>
</section>
<section>
Let's add permission to <em>[email protected]</em> to login as <em>admin</em> on host
<em>test-server</em>:
<pre><code class="hljs bash smaller">
$ theo permissions add --account [email protected] --host test-server --user admin
+---------------------+
{
"account_id": 3,
"permission_id": 2
}
+---------------------+
</code></pre>
</section>
<section>
Let's check <em>developers</em> status:
<pre><code class="hljs bash smaller">
$ theo groups get developers
+-------------------------------------+
{
"id": 4,
"name": "developers",
"active": 1,
"accounts": [
{
"id": 1,
"name": "Developer 1",
"email": "[email protected]",
"active": 1
},
{
"id": 2,
"name": "Developer 2",
"email": "[email protected]",
"active": 1
}
],
"permissions": [
{
"id": 1,
"user": "node",
"host": "test-server",
"created_at": 1542702951350
}
]
}
+-------------------------------------+</code></pre>
</section>
<section>
Let's check <em>[email protected]</em> status:
<pre><code class="hljs bash smaller">
$ theo accounts get [email protected]
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
{
"id": 3,
"name": "Sysop A",
"email": "[email protected]",
"active": 1,
"expire_at": 0,
"public_keys": [
{
"id": 3,
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCtKaAI2AoNoA9gvd0THROZavXoYVa0DoIfrVmBW+FTh8/79yPyf3ZilZVEVpGYJixxneAk1S/k/KsMt68GrG1qaiGLh/pbtT3l6MkHXYqDZI7soi0plUtczXlX8GTyZKML+H/ZOzoltBmV02yUCnSvFecgMvoLzqg1ExGIb1/5AQ== macno@habanero",
"public_key_sig": null,
"created_at": 1542702914738
}
],
"groups": [
{
"id": 3,
"name": "[email protected]",
"active": 1
}
],
"permissions": [
{
"id": 2,
"user": "admin",
"host": "test-server",
"created_at": 1542702964294
}
]
}
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+</code></pre>
</section>
<section>
<h3 class="green">Great!</h3>
<p> Let's move to Theo Agent</p>
</section>
</section>
<section>
<h3>Theo Agent</h3>
<section>
Connect to the host you want to use (for example a VM running on your host), download <em>Theo
agent</em> and make it executable:
<pre><code class="smaller hljs bash">vagrant@test-server:~$ sudo curl -L -o /usr/sbin/theo-agent \
https://github.com/theoapp/theo-agent/releases/download/v0.5.2/theo-agent-linux-amd64
vagrant@test-server:~$ sudo chmod 755 /usr/sbin/theo-agent
</code></pre>
</section>
<section>
Create a Theo Agent user:
<pre><code class="smaller hljs bash">vagrant@test-server:~$ sudo useradd --comment 'Theo Agent' \
--create-home theo-agent --shell /bin/false</code></pre>
</section>
<section>
Self-configure <em>Theo Agent</em> and restart sshd:
<pre><code class="smaller hljs bash">vagrant@test-server:~$ sudo theo-agent -install -no-interactive \
-sshd-config \
-url http://192.168.56.1:9100 \
-token vW0bhte0SDI4ZtL26m7O4+W3Z44pWfdjHnrZorOtOlvHlqBM6O/UW+dNIDK/GEy8bURlTjpjEHvG
vagrant@test-server:~$ sudo systemctl reload ssh
</code></pre>
</section>
<section>
Let's give Theo Agent a test:
<pre><code class="smaller hljs bash">vagrant@test-server:~$ sudo su theo-agent -s /bin/sh -c "/usr/sbin/theo-agent admin"
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDOul6NpEnQdRRlt9ALhWjcf1tDkK8VSwtK4FMsDcl8knAr3Ap7oj3/fBhLmlFl9e7AW9J2XFEf6jK+8Sv/N2+vxCMdg6APEsfSa0/gnTnv0JRRmMxBr0kKI/DfrCwGm0075uNmr6JegrLOiGtU/PfmHCgdNJiHqD7Z8301h+XNFQ== macno@habanero
</code></pre>
</section>
<section>
And now from your host... connect!
<pre><code class="smaller hljs bash">macno@habanero:~$ ssh admin@test-server
admin@test-server: ~$
</code></pre>
</section>
</section>
<section>
<h3 class="green">CONGRATULATIONS!!!</h3>
<h5>You made it!</h5>
</section>
<section>
<h3>Acknolegments</h3>
<section>
<p class="fragment">I would like to thank <a href="https://github.com/gizero"
target="_blank">@gizero</a> for his patience, hints and
support.<br/>
It's always a pleasure to work with you.
</p>
</section>
<section>
<p>To Tommaso for his beautiful artwork on Theo's logos
</p>
</section>
<section>
<p>Also I want to apologise to my wife and my daughters for the nights and weekends I
spent working on this project...<br/>
Thanks I love you <span class="red">❤</span></p>
</section>
</section>
</section>
</section>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
history: true,
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{src: 'plugin/notes/notes.js', async: true},
{
src: 'plugin/highlight/highlight.js', async: true,
callback: function () {
hljs.initHighlightingOnLoad();
}
}
]
});
</script>
</body>
</html>