summaryrefslogtreecommitdiff
path: root/lua-wshop2013.pin
blob: 11cf886f3c4d6f23efc9a299f4f62150fb1f4568 (plain)
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
# Lua Workshop Pinpoint talk about Gitano

[backing.png]
[center]
[font=Sans 50px]
[stretch]

-- [backing-cat-flop.png]

-- [backing-cat-flop.png] [no-markup]

Gitano - A Git service written in Lua

Daniel Silverstone <dsilvers@digital-scurf.org>

# Burble like a tard about who you are

-- [backing-cat-eat-you.png]

What is it?

# Git Server
# Written in Lua
# Configured in Git where plausible
# To do this I needed to write a bunch of libs

-- [backing-cat-inelegant.png] [text-align=center]

Technology choices
(or things was too lazy to write)

# Git - odd to list, but I mean configuration is in git
#       rulesets are in git, etc.etc.etc.
# Lua - I like Lua, it's easy to prototype and write stuff
# Luxio
# libgit2/luagit2 - Way faster than invoking git commands
# although Gitano *can* operate without them
# cgit rather than gitweb - much faster, caches, prettier

# 6. Future - explain how background task stuff looks plausible using the
#    nanomsg stuff recently talked about on list.  Explain how currently I'm
#    testing Gitano using a testing tool written in Python, but want to write
#    a Lua equivalent of it.

-- [backing-cat-sunbathing.png]

Gall - Git Abstraction Layer (in) Lua

# Git abstraction - obviously necessary.  Uses Luxio's
# subprocess to run git commandline and luagit2/libgit2 via
# LuaNativeObjects to work in process.  Show a simple
# example

-- [backing-cat-sunbathing.png] [font=Monospace 50px]

r = gall.repository.new("/path/to/gitano-admin.git")
c = r:get(r.HEAD).content
t = gall.tree.flatten(c.tree.content)
b = t['site.conf']
print(b.obj.content)

-- [backing-cat-sunbathing.png]

Lace - Lua Access Control Engine

# Lace - Access control lists.  No syntax I came up with in
# Lua was neat enough for non-Lua programmers to accept.
# Turing complete ACLs are also a fairly bad idea.  Show
# example, show that Lace comes with instructions

-- [font=Monospace 50px]

define success equals want_to_pass yes
allow "Ok" success

# Simple example showing definition, match type, and arguments.
# list of defined predicates on the allow line must all pass

-- [backing-cat-sunbathing.png]

Clod - Configuration Language Organised (by) Dots

# Designed to keep track of ordering of entries (and spaces)
# Currently doesn't track comments (because that's super
# hard) Humans and the library tend to edit files in similar
# ways meaning diffs are sane

-- [font=Monospace 50px]

project.head "refs/heads/master"
project.description "Black box testing of Unix programs"
project.owner "liw"

# Three simple string entries as might be found in a
# repository configuration in Gitano.

-- [font=Monospace 50px]

description "Gitano Instance Administrators"

members["*"] "dsilvers"

# Clod also supports lists which remain ordered.  This is an
# example group file in a Gitano repository

-- [backing-cat-sunbathing.png]

Supple - Sandbox [(for) Untrusted Procedure Partitioning (in) Lua] Engine

# Supple allows me to run hooks provided by project owners
# safely without risking them gaining access to the server
# in any unusual way.

# Hooks are run as Lua code with a limited set of functions
# and only the data relevant to the event they're hooking
# (along with a read-only repository object they can use to
# interrogate other things a bit)

-- [backing-cat-sunbathing.png]

To limit the attack surface...

The "untrusted" code runs in a (limited) Lua sandbox.

That sandbox is soft-limited in terms of VM opcodes and memory.

The sandbox is monitored and IO marshalled externally.

# Your "untrusted" code is run inside a Lua sandbox which
# has only a limited set of Lua's functionality exposed to
# it.

# That sandbox is soft-limited (optionally) in terms of VM
# opcodes and memory allocated by Lua

# The sandbox is run inside a monitoring Lua VM instance
# which is responsible for carefully marshalling calls etc
# into and out of the sandbox. All your comms go via this
# monitor.

-- [backing-cat-sunbathing.png]

Just in case...

The monitor is a Lua VM anyway, and it's all inside a separate process.

The sandbox process is in an ephemeral chroot.

# The monitor is, itself, a Lua VM anyway, inside a process
# which is separate from the process you're doing untrusted
# work on behalf of.

# The sandbox process is created using a rootly helper so
# that it's put into an isolation state consisting of a
# directory which is owned by root which is set as your root
# via the chroot call, but which is also rmdir'd so it's
# ephemeral. Your process drops privileges back to the
# calling UID so it cannot do anything inside its CWD
# anyway.

-- [backing-cat-sunbathing.png]

And if that's not enough...

Solid rlimits in terms of memory and open FDs

And on Linux, memory is pre-allocated and we enter seccomp mode 1.

# On top of that, the sandbox has some pretty solid rlimits
# set in terms of max CPU usage, max VM size, max FDs open,
# and max size of any file it writes. As such, it can't
# create > 0 byte files in the directory it doesn't have
# access to, and could only do that if it closed the FD to
# the host process which is its only communications avenue.

# Then, if you're on Linux, we go one step further and
# pre-allocate enough memory for the interpreter to not hit
# the rlimit and then enter seccomp mode 1 which limits the
# syscalls permissible to read, write, _exit and sigreturn
# so even if you could have circumvented any/all of the
# limits above, you now can't make syscalls to take
# advantage of them.

# If that's not sandbox enough, please tell me how to
# improve matters further.

-- [backing-cat-sunbathing.png]

Objects here, objects there, we send objects everywhere.

Proxying values (incl. functions and tables)

# Talk about how Supple proxies values across the link so
# that the sandboxed code can have do whatever it likes and
# it looks and feels like it's running in the host.

# e.g. next() works, calling things works etc.

-- [font=Monospace 50px]

local repo, ref, oldsha, newsha = ...

local branch = ref:match("^refs/heads/(.+)$")
if branch then
   log.state("Looking at commit history on: " .. branch)

   local commit = repo:get(newsha)

   while commit.sha ~= oldsha do
      commit = commit.content
      local parents = commit.parents
      if #parents &#60; 2 then
         error("Detected non-merge-commit during parent walk, at " .. commit.sha)
      end
      commit = parents[1]
   end
   
   log.state("Commits between old and new sha seem to all be merge commits")
else
   log.state("Skipping commit history check on: " .. ref)
end

-- [font=Monospace 50px]

local <span foreground="green" font_weight="heavy">repo, ref, oldsha, newsha = ...</span>

local branch = ref:match("^refs/heads/(.+)$")
if branch then
   <span foreground="red" font_weight="heavy">log</span>.state("Looking at commit history on: " .. branch)

   local commit = repo:get(newsha)

   while commit.sha ~= oldsha do
      commit = commit.content
      local parents = commit.parents
      if #parents &#60; 2 then
         error("Detected non-merge-commit during parent walk, at " .. commit.sha)
      end
      commit = parents[1]
   end
   
   <span foreground="red" font_weight="heavy">log</span>.state("Commits between old and new sha seem to all be merge commits")
else
   <span foreground="red" font_weight="heavy">log</span>.state("Skipping commit history check on: " .. ref)
end

-- [font=Monospace 50px]

local repo, ref, oldsha, newsha = ...

local branch = ref:match("^refs/heads/(.+)$")
if branch then
   <span foreground="yellow" font_weight="heavy">log.state(</span>"Looking at commit history on: " .. branch)

   local commit = <span foreground="yellow" font_weight="heavy">repo:get(</span>newsha)

   while <span foreground="red" font_weight="heavy">commit.sha</span> ~= oldsha do
      commit = <span foreground="red" font_weight="heavy">commit.content</span>
      local parents = <span foreground="red" font_weight="heavy">commit.parents</span>
      if #parents &#60; 2 then
         error("Detected non-merge-commit during parent walk, at " .. <span foreground="red" font_weight="heavy">commit.sha</span>)
      end
      commit = <span foreground="red" font_weight="heavy">parents[1]</span>
   end
   
   <span foreground="yellow" font_weight="heavy">log.state(</span>"Commits between old and new sha seem to all be merge commits")
else
   <span foreground="yellow" font_weight="heavy">log.state(</span>"Skipping commit history check on: " .. ref)
end

-- [font=Monospace 50px]

local repo, ref, oldsha, newsha = ...

local branch = ref:match("^refs/heads/(.+)$")
if branch then
   log.state("Looking at commit history on: " .. branch)

   local commit = repo:get(newsha)

   while commit.sha ~= oldsha do
      commit = commit.content
      local parents = commit.parents
      if #parents &#60; 2 then
         <span foreground="purple" font_weight="heavy">error(</span>"Detected non-merge-commit during parent walk, at " .. commit.sha)
      end
      commit = parents[1]
   end
   
   log.state("Commits between old and new sha seem to all be merge commits")
else
   log.state("Skipping commit history check on: " .. ref)
end

-- [backing-cat-shocked.png]

Real users of Gitano

 - git.gitano.org.uk, git.liw.fi
 - git.netsurf-browser.org, richard.maw.name/git
 - Codethink and Baserock

# Equally horrifyingly, people use this crap what I wrote.

# But, it's not enough (sound stern)

-- [backing-cat-stern.png]

Future plans

Lots of ideas for future content, see the Trello

 - https://trello.com/b/l4Id6iiC/gitanow
 - (Link is on www.gitano.org.uk)

# I would welcome contributions to Gitano or the libraries
# behind it.  I would especially welcome contributions which
# increase the scenario test suite coverage.

-- [backing-cat-sat.png]

Mailing list: <span font="Monospace 50px">gitano-dev@gitano.org.uk</span>
IRC Channel: <span font="Monospace 50px">#gitano</span> on Freenode
Website: <span font="Monospace 50px">http://www.gitano.org.uk/</span>

Any questions?

# Intrusive cat says "Enough with the talkings"

-- [backing-cat-sat.png]

Mailing list: <span font="Monospace 50px">gitano-dev@gitano.org.uk</span>
IRC Channel: <span font="Monospace 50px">#gitano</span> on Freenode
Website: <span font="Monospace 50px">http://www.gitano.org.uk/</span>

Thank you for listening