Commit Graph

500 Commits

Author SHA1 Message Date
Kartik K. Agaram 5e976554dd drop the lfs library
I can't feel confident about its sandboxing story yet. And if we can't
build a file navigator, what are we even doing with it.
2022-03-14 17:26:13 -07:00
Kartik K. Agaram b68405fe31 delete debug library
There's security issues here, and they're subtle. Dropping for now until
I or someone else finds a need for them.
2022-03-13 17:36:01 -07:00
Kartik K. Agaram ee7f893a7e drop string.dump, clean up docs around it 2022-03-13 14:41:41 -07:00
Kartik K. Agaram 1017e80fe5 less confusing error when apps get past main 2022-03-13 12:12:19 -07:00
Kartik K. Agaram 04a65e05f8 leak check 2022-03-10 09:56:37 -08:00
Kartik K. Agaram 0fa83e1d94 support fixing >1 test failure from within Teliva
This bug was caused by me forgetting that lua_setglobal affects the
stack.
2022-03-10 09:47:10 -08:00
Kartik K. Agaram e627114751 zet.tlv: first screen tests
In the process I found a couple of bugs in fake screen primitives.
2022-03-10 04:30:58 -08:00
Kartik K. Agaram 08c49b5a0a protect framework files from apps
There's a separate open question here of where Teliva should store files
like teliva_editor_state and teliva_editor_buffer. One school of thought
is that apps should never be dropping crud into people's directories. On
the other hand, I'm kinda encouraging people so far to just run apps
from Teliva's directory. Perhaps that makes it ok?
2022-03-08 19:20:53 -08:00
Kartik K. Agaram 2b47f76308 just always temp files to be created
Implication: os.rename now needs to be sandboxed. Hopefully it's
tractable to treat it as conceptually identical to opening two files.
2022-03-07 21:57:11 -08:00
Kartik K. Agaram 2d393bfb80 stop loading libraries after app code
This whole approach of disallowing overriding is suspect.
2022-03-07 21:43:00 -08:00
Kartik K. Agaram dd8730920a purge all support for per-function permissions
We're now back to the problem of how to transparently allow Teliva to
create temporary filenames without every app having to explicitly allow
them.

I think I may need to define start_writing in C, so that it can use a
non-sandboxed version of io.open.
2022-03-07 20:50:41 -08:00
Kartik K. Agaram a0674f7b85 hokey primitive to create temporary file
The trouble with os.tmpname() is that it always creates in /tmp.
If /tmp is in a different volume from our real filename, os.rename()
will fail.

This new primitive doesn't support primitive paths yet.

I'm also again nervous about the security implications of my whole
approach. What if we create an inner function called start_writing?
Would we be able to do anything inside it? I'm starting to suspect this
whole approach of going by caller name is broken. An app could also
create inner functions called 'main'..
2022-03-07 19:14:02 -08:00
Kartik K. Agaram 88827db20d slightly firm up phases in pmain 2022-03-07 16:01:19 -08:00
Kartik K. Agaram f268015ac0 fix the security vulnerability
We now have a notion of libraries that we load after app code, to
prevent them from getting overridden.

Should I just load all libraries after the app? There might be value in
allowing apps to override library functions. Disallowing that too much
may be going against Lua's dynamic nature.
2022-03-07 15:40:28 -08:00
Kartik K. Agaram cfb7cff4c1 call app's main() from within Lua pmain 2022-03-07 15:34:20 -08:00
Kartik K. Agaram 38063812b6 zet.tlv: switch file writes to new API
The interface for apps looks much nicer now, see 'main' in zet.tlv.
However there are some open issues:

- It can still be confusing to the computer owner that an app tries to
  write to some temporary file that isn't mentioned anywhere.

- File renames can fail if /tmp is on a different volume.

- What happens if an app overrides start_writing()? The computer owner
  may think they've audited the caller of start_writing and give it
  blanket file permissions. Teliva tunnels through start_writing when
  computing the caller. If the app can control what start_writing does,
  the app could be performing arbitrary malicious file operations.

  Right now things actually seem perfectly secure. Overriding
  start_writing has no effect. Our approach for loading .tlv files (in
  reverse chronological order, preventing older versions from overriding
  newer ones) has the accidentally _great_ property that Teliva apps can
  never override system definitions.

  So we have a new reason to put standard libraries in a .lua file: if
  we need to prevent apps from overriding it.

  This feels like something that needs an automated test, both to make
  sure I'm running the right experiment and to ensure I don't
  accidentally cause a regression in the future. I can totally imagine a
  future rewrite that tried a different approach than
  reverse-chronological.
2022-03-07 10:55:18 -08:00
Kartik K. Agaram 7a315e3d9f extract a common function call 2022-03-07 08:52:41 -08:00
Kartik K. Agaram 503ad706fb zet.tlv: switch file reads to new API
In the process I found a couple of bugs in parsing JSON string escapes.
2022-03-07 08:22:37 -08:00
Kartik K. Agaram d388cc1f22 decode json from channels 2022-03-06 23:50:58 -08:00
Kartik K. Agaram 6a3098d0e9 use method syntax where possible
Perhaps this is a bad idea. It feels arbitrary, what methods Lua happens
to include in string and table objects without having to go through the
respective modules.
2022-03-06 16:38:49 -08:00
Kartik K. Agaram 5758f6c082 reading from file a character at a time 2022-03-06 09:52:37 -08:00
Kartik K. Agaram f07eb03492 local functions broke start_reading/start_writing
Looks like Lua's local functions lose access to outer scopes (upvalues)
or something like that..
2022-03-06 09:49:33 -08:00
Kartik K. Agaram 38ff2ddf11 move start_reading/start_writing out of template
When should code go in the template used by new apps vs the .lua files
distributed with Teliva?

- from a privilege perspective there's no difference
- from a compatibility perspective stuff in .tlv will not get upgraded
  with Teliva.
- for me the maintainer, functions in .lua files are easier to upgrade
  in a single place.
- for the reader of an app, functions in .lua files will not show up to
  be edited. They can still be overloaded, but the current version isn't
  as discoverable. Putting something in the app is a slight nudge to
  readers that they're encouraged to mess with it.
- Stuff in .lua files can use local functions and so have more internal
  complexity. Apps can also hide details within functions, but that'll
  make them more likely to run into limitations with Teliva's editing
  environment.

I'm not yet sure how to reason about the second point in practice.
  - Stuff in .tlv files I don't have to worry about compatibility
    guarantees for.
  - Stuff in .lua files I _do_ have to worry about compatibility
    guarantees for.

Perhaps this means I'm doing things exactly wrong in this commit?
Functions like map/reduce/filter/append seem more timeless, whereas I'm
still just feeling my way around with start_reading and start_writing.

We'll see. For now I'm ruled by the fourth point. Messing with tasks and
the scheduler is much more advanced than anything else in template.tlv;
it seems to make sense to add some friction to modifying them.

Bottomline: Complex sub-systems go in .lua files. Simple, self-contained
definitions go into apps. Both are probably equally burdensome now from
a compatibility perspective.
2022-03-06 09:21:32 -08:00
Kartik K. Agaram db7fd08e05 extract a helper
I'm starting to get quite indisciplined about where I introduce global
bindings. Seems reasonable since any modules in Teliva will come from
within the framework.
2022-03-06 08:41:45 -08:00
Kartik K. Agaram f2d29c22f8 a simple hack to make caller apparent
Teliva isn't yet smart enough to know the caller of an indirect function
where the function being called goes through a local variable.

I'd expected fixing this to be a long death march. However, there's a
shockingly easy fix: just make every indirect call go through an
additional direct function call.

My policy for zet.tlv was that function 'main' could open any file. This
stopped working since I introduced spawn_main. But with this commit it's
working again.

I can also drop all my special-casing of 'main' since it's now a regular
Lua call.

We still can't rely on the caller of an indirect call. That affects
start_reading and start_writing, which really need to be part of the
framework.
2022-03-05 22:38:00 -08:00
Kartik K. Agaram 52ae23784b new API for file operations
File operations now always return a channel (or nil on error or
permission denied).

When start_reading() from a filename, you can repeatedly :recv() from
the channel it returns.
When :recv() returns nil, you're at the end of the file. Stop.

When you start_writing() to a filename, you can repeatedly :send() to
the channel it returns.
When you're done writing, :close() the channel. Writes to the file won't
be externally visible until you do.

To make this work I'm now always starting up the scheduler, so I need to
fix sieve.tlv.

Transparently running the scheduler is an abstraction, and whenever I
create an abstraction I always worry about how it might fail. There's
a hopefully-clear error when you read past end of a file.
2022-03-05 18:04:35 -08:00
Kartik K. Agaram 43dd1f382e some dead code 2022-03-05 14:47:03 -08:00
Kartik K. Agaram 5530995188 reliably exit on confirmation
Until now you had to press ctrl-x twice in rapid succession to exit if
an app turned on non-blocking keyboard with nodelay(true). This became
particularly noticeable after the previous change to anagrams.tlv, which
could no longer exit.
2022-03-05 14:44:37 -08:00
Kartik K. Agaram f72340cc37 fixup! no further confirmation once editing commences 2022-03-05 14:40:42 -08:00
Kartik K. Agaram 057f4a2870 anagrams.tlv: slightly more responsive
Now we cancel screen-painting if any key is pressed.

However it looks like just computing the list of anagrams can take a
long time.
2022-03-05 09:47:47 -08:00
Kartik K. Agaram 520cc09997 include caller in sandboxing messages 2022-03-04 21:25:38 -08:00
Kartik K. Agaram 2cfdad3381 simplify permissions model for file operations
We don't care to distinguish modes like "rw" or "a+". An app is
permitted to perform either just reads or both reads and writes.
2022-03-03 22:28:01 -08:00
Kartik K. Agaram 9722f44a94 clearer copy for confirmation dialog 2022-03-03 22:25:43 -08:00
Kartik K. Agaram 983285c6b2 more unobtrusive skip message
In particular, the periods looked like passing tests.
2022-03-03 22:06:44 -08:00
Kartik K. Agaram 2b50b7289e no further confirmation once editing commences 2022-03-03 21:43:22 -08:00
Kartik K. Agaram dd5bc9e3ac ask for confirmation on _any_ teliva shortcut
This feels more intrusive. Let's see how we like it. Will I start having
ctrl-x ctrl-x in my muscle memory?
2022-03-03 18:34:15 -08:00
Kartik K. Agaram 101c59d8cb experiment: drop -Wshadow
I'm totally fine with lexical scope in other languages. Why does it feel
like such a big deal in C?
2022-03-03 18:15:26 -08:00
Kartik K. Agaram afb3f46db7 always ask for confirmation on exit
Let's see if we can live with this rather than some way to let apps
indicate if they want confirmation or not..
2022-03-01 23:10:46 -08:00
Kartik K. Agaram 891bced544 always run unit tests for channels and tasks 2022-02-26 22:57:48 -08:00
Kartik K. Agaram 42526cb15d import https://github.com/majek/lua-channels
Also a little test program to demo channels in action.
2022-02-26 22:48:48 -08:00
Kartik K. Agaram 061e6a21a5 duplicate keypress on failing test 2022-02-26 19:47:06 -08:00
Kartik K. Agaram 52372d1812 delete curses primitives to read whole lines
They make it seem like you can use them to create simple REPL apps, but
you can't, because standard Teliva shortcuts won't work.

I _could_ make them work by emulating them using getch(), but that feels
like an unnecessary abstraction for now.
2022-02-21 17:06:34 -08:00
Kartik K. Agaram f8f1ec666a stop letting apps change directory
I introduced this ability when I packaged up the lfs directory, but it
can enable apps to circumvent sandboxing rules in some situations. If
you can socially engineer someone to allow reading a file called
'passwd' in the current directory, you can now change directory to /etc
and read something sensitive.

Protecting against stuff like this gets subtle. It's easy for people to
create policies that aren't robust to changing directories. Requiring
absolute paths is also pretty unfriendly. So the whole notion of current
directory is perhaps implicit state that is confusing to manage. Fix it
in the context of a single session.
2022-02-20 05:01:28 -08:00
Kartik K. Agaram b8cba84d20 bring back pcall and xpcall
They aren't evaluating strings after all.
2022-02-18 18:00:58 -08:00
Kartik K. Agaram 9421ea7151 'doc:blurb': a place to briefly describe an app
This is for what the app does, as opposed to 'doc:main', which is also
intended to include commentary about the internal organization of the
app.
2022-02-17 20:16:36 -08:00
Kartik K. Agaram 272d7532dc disable non-portable ASan flags 2022-02-16 20:53:53 -08:00
Kartik K. Agaram 5e200cf96a zet.tlv: some more editor shortcuts 2022-02-12 15:56:12 -08:00
Kartik K. Agaram 6a485ae4b4 stop aborting if audit log fills up
When I started logging getch() events (which are just to help the reader
orient on the log), this suddenly became more urgent.

Now the log is larger, and it's also a circular buffer that rolls back
to the start when it fills up.

The next failure mode will be if we see the buffer filled up with just
getch() calls, reducing visibility over real file and network
operations. In which case we'll need to start coalescing getch() events.
2022-02-12 15:45:04 -08:00
Kartik K. Agaram 2d3cad5945 fix build on Mac OS 2022-02-10 23:42:09 -08:00
Kartik K. Agaram feb10708ae hacky support for caller main in file permissions 2022-02-10 16:40:40 -08:00