demo: each session's transcript, kept 7 days in a write-only drop box (#192)

Ruled 2026-11-21, "Write-only drop box": console.py writes each session's transcript, mode 0600,
into /var/lib/starshipos-demo-transcripts (the owner's, group starshipos-demo, mode 1730: a session
adds a file but cannot list or read the directory). transcripts-tidy.sh, run as root every 5 minutes
by starshipos-demo-transcripts.timer, hands each file to the owner and deletes those over 7 days.
starshipos-demo.service gets the directory writable and DEMO_TRANSCRIPTS; DEPLOY.md step 4 has the
server steps and the check.

"Nothing you do is kept" was no longer true. Ruled 2026-11-24, "Machine not kept; log 7 days": the
session's banner, the Try it page and the old wiki page say nothing is kept on the machine and a
transcript is kept for up to 7 days, then deleted, and the page says so before the console.

demo/test_transcripts.py failed first (logs/20261121-demo-transcripts/before.txt) and passes its
10 checks (after.txt).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-24 09:19:03 +00:00
parent 552d76595d
commit 6ebe706351
14 changed files with 199 additions and 5 deletions
+25
View File
@@ -59,6 +59,31 @@ ss -ltnp | grep 7681 # the ttyd of starshipos-demo, not
The service expects the checkout's `demo/` at `/opt/starshipos-demo/demo` (step 1 put it there).
**The transcripts (#192, ruled 2026-11-21: "Write-only drop box").** Each session writes what the
visitor typed and what the machine answered to `/var/lib/starshipos-demo-transcripts`, one file per
session, mode 0600 (`console.py`). The directory is yours, group `starshipos-demo`, mode 1730: a
session can add a file, but cannot list the directory or read anything in it. A root timer hands each
file to you and deletes every one older than 7 days (`transcripts-tidy.sh`). The Try it page says so.
Before (re)starting the service, with `OWNER` your own login:
```bash
OWNER=<your login>
install -d -o "$OWNER" -g starshipos-demo -m 1730 /var/lib/starshipos-demo-transcripts
sed "s/^Environment=OWNER=CHANGE-ME$/Environment=OWNER=$OWNER/" \
demo/starshipos-demo-transcripts.service > /etc/systemd/system/starshipos-demo-transcripts.service
cp demo/starshipos-demo-transcripts.timer /etc/systemd/system/
systemctl daemon-reload && systemctl enable --now starshipos-demo-transcripts.timer
systemctl restart starshipos-demo # its unit now writes the transcripts directory
systemctl list-timers starshipos-demo-transcripts --no-pager
```
Then the check: open a session, type a line, close it; within 5 minutes its file is in
`/var/lib/starshipos-demo-transcripts`, owned by you, mode `-rw-------`, and `sudo -u
starshipos-demo ls /var/lib/starshipos-demo-transcripts` is refused. A file older than 7 days
(`touch -d '8 days ago' FILE.log`) is gone at the next run (`systemctl start
starshipos-demo-transcripts` runs it at once). Apache must not serve the directory: nothing in
`apache-demo.conf` maps it, and nothing should.
## 5. TLS and Apache for try.starshipos-f18.com (~10 min)
DNS: `try.starshipos-f18.com` must point at this server (an A record) before certbot.
+7
View File
@@ -21,6 +21,9 @@ XWiki "Try it" page (iframe) -> Apache: TLS, websocket -> ttyd -> start-session.
| `console.py` | Joins the visitor's terminal to the machine only once it runs, discarding keys typed while it loads |
| `qemu-args.sh` | The machine, shared by the two above: a resumed machine must match the saved one exactly |
| `starshipos-demo.service` | ttyd as a systemd service, on localhost; two guests at once, a busy message for the rest (#114, #116) |
| `transcripts-tidy.sh` | Hands each session's transcript to its owner, mode 0600, and deletes those over 7 days (#192) |
| `starshipos-demo-transcripts.service`, `.timer` | Runs `transcripts-tidy.sh` as root every 5 minutes (#192) |
| `test_transcripts.py` | Tests the transcript and the tidy, with a stand-in machine: `python3 demo/test_transcripts.py` |
| `DEPLOY.md` | Putting it on the server, step by step |
| `apache-demo.conf` | Example vhost: TLS, the websocket, framing allowed for the `.com` only (#115) |
| `xwiki-try-it.xwiki` | The "Try it" page, its own page on the `.com` XWiki (`TryIt`), in the landing page's style |
@@ -33,6 +36,10 @@ seccomp sandbox (no spawning, no privilege changes), as an unprivileged user, in
that fences memory, CPU and the file system. A session lasts at most `DEMO_SESSION_LIMIT` seconds
(1800).
What is kept: a transcript of each session -- what the visitor typed and what the machine answered
-- for up to 7 days, readable by the server's owner only, then deleted (#192; `DEPLOY.md`, step 4).
The Try it page and the session's first lines say so.
## Setting it up
From a checkout of the most recent green commit -- the latest that passed acceptance, `master`
+21
View File
@@ -10,6 +10,13 @@ A resumed machine takes a moment to load. Anything typed meanwhile would reach a
whose state is about to be replaced, and be lost half-way through a line ("3 4 + ." arriving as
"4 + ."). So: wait until QEMU says the machine is running, throw away what was typed before,
say so, and only then pass bytes both ways. Ends when either side closes.
The transcript (#192, ruled 2026-11-13 and 2026-11-21): what the machine sends -- its prompt, the visitor's
line as it echoes it, what it prints -- is also written to DEMO_TRANSCRIPTS
(/var/lib/starshipos-demo-transcripts), one file a session, named by its UTC start and this process, mode 0600.
The directory is a drop box this user can write in but not list or read (DEPLOY.md); transcripts-tidy.sh
hands each file to its owner and deletes it after 7 days. The Try It page says so. If it cannot be written,
the session goes on without one.
"""
import json, os, select, socket, sys, termios, time, tty
@@ -38,6 +45,14 @@ while True: # until the machine runs
time.sleep(0.1)
con = connect(con_path)
transcript = None
try:
tdir = os.environ.get("DEMO_TRANSCRIPTS", "/var/lib/starshipos-demo-transcripts")
name = os.path.join(tdir, time.strftime("%Y%m%d-%H%M%S", time.gmtime()) + "-%d.log" % os.getpid())
transcript = os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
os.write(transcript, ("# StarshipOS demo session, %s UTC\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())).encode())
except OSError:
transcript = None # no transcript, the session as before
stdin, stdout = sys.stdin.fileno(), sys.stdout.fileno()
saved = None
if os.isatty(stdin):
@@ -56,7 +71,13 @@ try:
data = con.recv(4096)
if not data: break
os.write(stdout, data)
if transcript is not None:
try: os.write(transcript, data)
except OSError: transcript = None
except OSError:
pass # the visitor's terminal went away
finally:
if saved: termios.tcsetattr(stdin, termios.TCSADRAIN, saved)
if transcript is not None:
os.write(transcript, ("\n# ended %s UTC\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())).encode())
os.close(transcript)
+12
View File
@@ -0,0 +1,12 @@
# starshipos-demo-transcripts.service -- the demo's transcripts (#192, ruled 2026-11-21: "Write-only drop box").
# Each session (console.py) writes its transcript, mode 0600, into /var/lib/starshipos-demo-transcripts:
# owned by Captain Bob, group starshipos-demo, mode 1730, so a session can add a file but not list or
# read the directory. This hands each file to the owner and deletes every one older than 7 days.
# Run by starshipos-demo-transcripts.timer. Set OWNER below to the owner's login (DEPLOY.md, step 4).
[Unit]
Description=StarshipOS demo transcripts: hand them to their owner, delete those over 7 days
[Service]
Type=oneshot
Environment=OWNER=CHANGE-ME
ExecStart=/opt/starshipos-demo/demo/transcripts-tidy.sh /var/lib/starshipos-demo-transcripts ${OWNER}
+10
View File
@@ -0,0 +1,10 @@
# starshipos-demo-transcripts.timer -- runs starshipos-demo-transcripts.service every 5 minutes (#192).
[Unit]
Description=StarshipOS demo transcripts, every 5 minutes
[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
[Install]
WantedBy=timers.target
+3
View File
@@ -14,6 +14,8 @@ Group=starshipos-demo
Environment=DEMO_STATE=/var/lib/starshipos-demo
Environment=DEMO_SESSION_LIMIT=1800
Environment=DEMO_MAX_GUESTS=2
# each session's transcript (console.py, #192): a write-only drop box, kept 7 days
Environment=DEMO_TRANSCRIPTS=/var/lib/starshipos-demo-transcripts
# the guests' slot locks (start-session.sh): /run/starshipos-demo, made for this user, gone at stop
RuntimeDirectory=starshipos-demo
# --max-clients: the guests and a few more, so a visitor over the limit reaches the busy message
@@ -30,6 +32,7 @@ ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ReadOnlyPaths=/var/lib/starshipos-demo
ReadWritePaths=/var/lib/starshipos-demo-transcripts
# Sized for this server (3.8 GiB, two cores; both wikis, Gitea, Nexus, CI). Since #151 an idle guest
# halts (1% of a core at the prompt, was 100%), so a session costs CPU only while its visitor runs
# something. All sessions together get 1.5 cores at the lowest priority (Captain Bob, 2026-11-08):
+2 -1
View File
@@ -42,7 +42,8 @@ trap 'rm -rf "$tmp"' EXIT
cp "$dir/vars.fd" "$tmp/vars.fd"
demo_qemu_args "$dir" "$tmp/vars.fd"
printf '\r\nStarshipOS -- starting a throwaway machine, yours for up to %d minutes. Nothing you do is kept.\r\n' $((limit / 60))
printf '\r\nStarshipOS -- starting a throwaway machine, yours for up to %d minutes. Nothing you do is kept on it.\r\n' $((limit / 60))
printf 'A transcript of this session is kept for up to 7 days, then deleted.\r\n'
printf 'Try: 3 4 + . : SQUARE DUP * ; 7 SQUARE .\r\n\r\n'
# QEMU is a tracked child, not exec'd, so that whatever ends the session ends the machine: ttyd
# hangs up (it signals this script only), the service stops, or the time runs out. Its console is
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LicenseRef-Starship-1.0
# Copyright (c) 2023-2026 Robert A. James
"""test_transcripts.py -- the demo's transcripts (#192, ruled 2026-11-13 and 2026-11-21): console.py writes each
session's console into DEMO_TRANSCRIPTS, one dated file a session, readable only by its writer; and
transcripts-tidy.sh hands each to the directory's owner and deletes those older than 7 days. No QEMU: a fake QMP
socket that says the machine runs, and a fake console that echoes. Prints PASS:/FAIL: and RESULT:."""
import json, os, socket, subprocess, sys, tempfile, threading, time, glob
HERE = os.path.dirname(os.path.abspath(__file__))
ok = True
def check(what, cond):
global ok
print(("PASS: " if cond else "FAIL: ") + what)
ok = ok and bool(cond)
def qmp_server(path):
s = socket.socket(socket.AF_UNIX); s.bind(path); s.listen(1)
def run():
c, _ = s.accept(); f = c.makefile("rw")
f.write(json.dumps({"QMP": {}}) + "\n"); f.flush()
for line in f:
f.write(json.dumps({"return": {"status": "running"}} if "query-status" in line else {"return": {}}) + "\n"); f.flush()
threading.Thread(target=run, daemon=True).start()
def console_server(path):
s = socket.socket(socket.AF_UNIX); s.bind(path); s.listen(1)
def run():
c, _ = s.accept()
c.sendall(b"[zuse@Hera] ok> ")
while True:
d = c.recv(1024)
if not d: break
c.sendall(d) # the machine echoes
if b"\r" in d: c.sendall(b"7 ok\r\n[zuse@Hera] ok> ")
threading.Thread(target=run, daemon=True).start()
with tempfile.TemporaryDirectory() as t:
tr = os.path.join(t, "transcripts"); os.mkdir(tr, 0o730)
qmp_server(os.path.join(t, "qmp.sock")); console_server(os.path.join(t, "con.sock"))
env = dict(os.environ, DEMO_TRANSCRIPTS=tr)
p = subprocess.Popen([sys.executable, "-I", os.path.join(HERE, "console.py"), os.path.join(t, "qmp.sock"), os.path.join(t, "con.sock")],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=env)
time.sleep(1.0); p.stdin.write(b"3 4 + .\r"); p.stdin.flush(); time.sleep(1.0); p.stdin.close()
out = p.stdout.read(); p.wait(timeout=10)
files = glob.glob(os.path.join(tr, "*.log"))
check("the visitor still sees the session: %r" % out[-40:], b"7 ok" in out)
check("one transcript for the session (%d)" % len(files), len(files) == 1)
if files:
f = files[0]; text = open(f, "rb").read()
check("named by its date, UTC: %s" % os.path.basename(f), os.path.basename(f)[:8].isdigit())
check("it holds what was typed, as the machine echoed it, and what it printed", b"3 4 + ." in text and b"7 ok" in text)
check("readable by its writer only (mode %o)" % (os.stat(f).st_mode & 0o777), os.stat(f).st_mode & 0o777 == 0o600)
# a directory it cannot write: the session goes on, without a transcript
ro = os.path.join(t, "nowhere")
env2 = dict(os.environ, DEMO_TRANSCRIPTS=ro)
os.unlink(os.path.join(t, "qmp.sock")); os.unlink(os.path.join(t, "con.sock"))
qmp_server(os.path.join(t, "qmp.sock")); console_server(os.path.join(t, "con.sock"))
p = subprocess.Popen([sys.executable, "-I", os.path.join(HERE, "console.py"), os.path.join(t, "qmp.sock"), os.path.join(t, "con.sock")],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=env2)
time.sleep(1.0); p.stdin.write(b"3 4 + .\r"); p.stdin.flush(); time.sleep(1.0); p.stdin.close()
out = p.stdout.read(); p.wait(timeout=10)
check("with no directory to write in, the session still works", b"7 ok" in out)
# transcripts-tidy.sh: handed to the owner, the old deleted
box = os.path.join(t, "box"); os.mkdir(box)
new, old = os.path.join(box, "20261121-000000-1.log"), os.path.join(box, "20261101-000000-2.log")
for f in (new, old): open(f, "w").write("x"); os.chmod(f, 0o600)
eight_days = time.time() - 8 * 86400; os.utime(old, (eight_days, eight_days))
r = subprocess.run(["bash", os.path.join(HERE, "transcripts-tidy.sh"), box, "nobody"], capture_output=True, text=True)
check("the tidy succeeds: %s" % (r.stderr.strip() or "ok"), r.returncode == 0)
check("a transcript older than 7 days is deleted", not os.path.exists(old))
check("a newer one is kept", os.path.exists(new))
if os.path.exists(new):
import pwd
st = os.stat(new)
check("and handed to the directory's owner (%s), mode 600" % pwd.getpwuid(st.st_uid).pw_name,
pwd.getpwuid(st.st_uid).pw_name == "nobody" and st.st_mode & 0o777 == 0o600)
print("RESULT: " + ("PASS" if ok else "FAIL"))
sys.exit(0 if ok else 1)
+12
View File
@@ -0,0 +1,12 @@
#!/bin/bash
# SPDX-License-Identifier: LicenseRef-Starship-1.0
# Copyright (c) 2023-2026 Robert A. James
# transcripts-tidy.sh DIR OWNER -- the demo's transcripts (#192): each handed to OWNER, mode 0600, so only OWNER
# reads it (the session's user wrote it, and cannot list the directory); every one older than 7 days deleted.
# Run as root by starshipos-demo-transcripts.timer every 5 minutes. Tests: demo/test_transcripts.py.
set -euo pipefail
dir=${1:?usage: transcripts-tidy.sh DIR OWNER}
owner=${2:?usage: transcripts-tidy.sh DIR OWNER}
[ -d "$dir" ] || { echo "transcripts-tidy: no $dir" >&2; exit 1; }
find "$dir" -maxdepth 1 -type f -name '*.log' -mmin +10080 -delete # 7 days
find "$dir" -maxdepth 1 -type f -name '*.log' ! -user "$owner" -exec chown "$owner:" {} + -exec chmod 0600 {} +
+2 -1
View File
@@ -13,7 +13,8 @@ This is a real StarshipOS machine, started just for you and already at its promp
simulation of StarshipOS and not a recording: the console below is the serial console of an
amd64 machine running the same image the project publishes every night. You are logged in as
**Zuse**, the superuser -- of a machine that exists only for your session. There is nothing to
break, and nothing you do is kept. Close the page and it is gone.
break, and nothing you do is kept on it. Close the page and it is gone. A transcript of your
session -- what you type and what the machine answers -- is kept for up to 7 days, then deleted.
{{html clean="false"}}
<iframe src="https://try.starshipos-f18.com/" title="StarshipOS console"
+11
View File
@@ -0,0 +1,11 @@
PASS: the visitor still sees the session: b'era] ok> 3 4 + .\r7 ok\r\n[zuse@Hera] ok> '
PASS: one transcript for the session (1)
PASS: named by its date, UTC: 20261124-091837-323.log
PASS: it holds what was typed, as the machine echoed it, and what it printed
PASS: readable by its writer only (mode 600)
PASS: with no directory to write in, the session still works
PASS: the tidy succeeds: ok
PASS: a transcript older than 7 days is deleted
PASS: a newer one is kept
PASS: and handed to the directory's owner (nobody), mode 600
RESULT: PASS
@@ -0,0 +1,8 @@
PASS: the visitor still sees the session: b'era] ok> 3 4 + .\r7 ok\r\n[zuse@Hera] ok> '
FAIL: one transcript for the session (0)
PASS: with no directory to write in, the session still works
FAIL: the tidy succeeds: bash: /home/user/LithosAnanke/demo/transcripts-tidy.sh: No such file or directory
FAIL: a transcript older than 7 days is deleted
PASS: a newer one is kept
FAIL: and handed to the directory's owner (root), mode 600
RESULT: FAIL
+2 -1
View File
@@ -42,10 +42,11 @@ html, body, #xwikimaincontainer, #xwikimaincontainerinner, #contentcontainer, #c
<section style="max-width: 1120px; margin: 0 auto; padding: 80px 24px 32px">
<p style="margin: 0 0 12px; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: #4FD1B0 !important">ok&gt; try it</p>
<h1 style="margin: 0 0 16px; font-family: 'Exo 2', sans-serif; font-size: clamp(36px, 5vw, 56px); line-height: 1.1">A StarshipOS machine of your own.</h1>
<p style="margin: 0; max-width: 680px; font-size: 18px; color: #C8D1DE !important">Not a recording, not a simulation of StarshipOS: the console below is a real machine, started just for you and already at its prompt. You are Zuse, the superuser — of a machine that exists only for your session. There is nothing to break, and nothing you do is kept.</p>
<p style="margin: 0; max-width: 680px; font-size: 18px; color: #C8D1DE !important">Not a recording, not a simulation of StarshipOS: the console below is a real machine, started just for you and already at its prompt. You are Zuse, the superuser — of a machine that exists only for your session. There is nothing to break, and nothing you do is kept on it. A transcript of your session may be kept for up to 7 days, then deleted.</p>
</section>
<section aria-label="The console" style="max-width: 1120px; margin: 0 auto; padding: 24px 24px 48px">
<p style="margin: 0 0 12px; font-size: 13px; color: #A3AEC2 !important">A transcript of your session — what you type and what the machine answers — is kept for up to 7 days, then deleted.</p>
<div style="background: #050A14 !important; border: 1px solid #34486A !important; border-radius: 8px; overflow: hidden">
<div style="display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid #22324D !important; background: #0E182B !important; font-size: 13px; color: #A3AEC2 !important">
<span style="display: flex; align-items: center; gap: 10px"><span aria-hidden="true" style="display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #4FD1B0 !important"></span>StarshipOS &#183; amd64 &#183; your session</span>
+4 -2
View File
@@ -34,17 +34,19 @@ a{color:#F5891F}a:hover{color:#FFB061}
<section style="max-width: 1120px; margin: 0 auto; padding: 80px 24px 32px">
<p style="margin: 0 0 12px; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: #4FD1B0">ok&gt; try it</p>
<h1 style="margin: 0 0 16px; font-family: 'Exo 2', sans-serif; font-size: clamp(36px, 5vw, 56px); line-height: 1.1">A StarshipOS machine of your own.</h1>
<p style="margin: 0; max-width: 680px; font-size: 18px; color: #C8D1DE">Not a recording, not a simulation of StarshipOS: the console below is a real machine, started just for you and already at its prompt. You are Zuse, the superuser — of a machine that exists only for your session. There is nothing to break, and nothing you do is kept.</p>
<p style="margin: 0; max-width: 680px; font-size: 18px; color: #C8D1DE">Not a recording, not a simulation of StarshipOS: the console below is a real machine, started just for you and already at its prompt. You are Zuse, the superuser — of a machine that exists only for your session. There is nothing to break, and nothing you do is kept on it. A transcript of your session may be kept for up to 7 days, then deleted.</p>
</section>
<section aria-label="The console" style="max-width: 1120px; margin: 0 auto; padding: 24px 24px 48px">
<p style="margin: 0 0 12px; font-size: 13px; color: #A3AEC2">A transcript of your session — what you type and what the machine answers — is kept for up to 7 days, then deleted.</p>
<div style="background: #050A14; border: 1px solid #34486A; border-radius: 8px; overflow: hidden">
<div style="display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid #22324D; background: #0E182B; font-size: 13px; color: #A3AEC2">
<span style="display: flex; align-items: center; gap: 10px"><span aria-hidden="true" style="display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #4FD1B0"></span>StarshipOS · amd64 · your session</span>
<span>try.starshipos-f18.com</span>
</div>
<div style="padding: 24px; min-height: 360px; font-size: 15px; line-height: 1.7; color: #EEF2F7; overflow-x: auto">
<div style="color: #A3AEC2">StarshipOS -- starting a throwaway machine, yours for up to 30 minutes. Nothing you do is kept.</div>
<div style="color: #A3AEC2">StarshipOS -- starting a throwaway machine, yours for up to 30 minutes. Nothing you do is kept on it.</div>
<div style="color: #A3AEC2">A transcript of this session is kept for up to 7 days, then deleted.</div>
<div style="color: #A3AEC2">Try: 3 4 + . : SQUARE DUP * ; 7 SQUARE .</div>
<div style="color: #A3AEC2; margin-bottom: 12px">Ready -- type a line and press Enter.</div>
<div><span style="color: #FFA500">[zuse@Hera]</span> <span style="color: #55FFFF">ok&gt;</span> 3 4 + .</div>