A stateless private gist service in Go, similar to GitHub Gists. Everything
lives in S3. The binary embeds the templates, the stylesheet, the fonts, and
the vendored JavaScript, so it needs no files on disk and makes no external
requests at runtime — Mermaid and MathJax ship in the binary, not from a
CDN. go build is the whole build.
-
Authentication: OIDC login, tested with Dex. The app derives an opaque per-user ID by hashing the ID token's
subclaim; that is the storage namespace. Theemailclaim is carried for display only. The session cookie is the ID token and expires one hour after login. The app has no logout page; clear the cookie or wait for the expiry. -
Storage: S3 only, no database. Any path-style S3 provider works: AWS, Exoscale SOS, s3mock.
-
Versioning: Gist history is S3 object versioning. The app enables versioning on your bucket at startup. You cannot turn versioning off afterwards, so the
s3.bucketsetting must name a bucket the app owns alone. -
Rendering: Markdown rendering and sanitizing come from petroglyph, a separate Go module. It gives GFM tables, strikethrough, task lists, autolinks for URLs and mail addresses, footnotes,
:emoji:shortcodes, GitHub alerts (> [!NOTE]-style blockquotes), heading permalink anchors built by GitHub's anchor rule,image sizing, and YAML front matter rendered as a table. Raw HTML is sanitized to a safe subset like GitHub:<details>collapsibles,<kbd>, and friends survive; scripts, frames, and event handlers don't. Code files get syntax highlighting with line numbers, driven by the file extension. Fenced code blocks in Markdown get highlighting too. Every line of a text file is an anchor:#L5, the range#L5-L9, and#file-{name}-L5for a file in a multi-file gist, where{name}is the file name with non-alphanumerics as dashes. The line number in the gutter is the link: clicking it sets the fragment and highlights the target without scrolling — the scroll happens only when the page loads with the fragment. The anchor survives switching versions, and shift-clicking another number extends the range from the last clicked line. -
Naming: The first file's name titles the gist. A submitted file without a name becomes
gistfile.txt,gistfile.1.txt, and so on. Two files with the same name are a save error; the app never renames a file silently. The description is optional and shows under the name. -
Preview: A Markdown file on the create or edit page gets Edit and Preview tabs. Preview sends your unsaved draft, including the typed file name, to the server and shows exactly what saving would render. This needs JavaScript; without it the form works and the tabs stay hidden. The row Preview and Remove buttons are click-only; editor settings remain keyboard accessible.
-
Editor settings: Each text file has a settings icon that opens controls for line wrapping, indentation (spaces or tabs), and indent size (2, 4, or 8). Files start with no wrapping, spaces, and size 2; settings are independent per file and reset on reload. Wrapping keeps logical line numbers aligned and never inserts newlines into the saved file. Tab inserts indentation or indents selected lines; Shift+Tab outdents. Press Escape, then Tab (or Shift+Tab) to leave the editor. Changing settings does not convert existing whitespace or mark the draft as changed.
-
Diagrams and math: A
```mermaidfence becomes a rendered diagram. Math uses the delimiters GitHub documents:$...$for inline and$$...$$for display. The binary ships Mermaid (12.1.0) and MathJax (3.2.2) bundled, and loads them only on pages that need them. -
Raw access:
GET /raw/{id}serves the first file andGET /raw/{id}/{filename}serves a named one astext/plain. An attached file answers with a redirect straight to S3 (see Inline media). A Copy button sits on each file row and on each fenced code block in rendered Markdown. Scripts can send the ID token in a header instead of a cookie:curl -H "Authorization: Bearer <id-token>" http://localhost:8080/raw/{id}A
Bearertoken is a full session, not a scoped API key: it is accepted on every route the cookie session reaches. Treat leaked tokens as leaked logins. -
Attachments: Drop files onto the create or edit form, or paste them. Text-ish files (no NUL byte in the first 8 KiB, up to 8 MiB) fill the textarea as editable content. Everything else uploads from the browser straight to S3 over a presigned URL, so the bytes never reach the app server. The app infers the file name; a paste that carries no name becomes
pasted-1.pngand counting. The row then shows an "attached" badge. A drop or a single-file paste on a row targets that row; a paste of several files behaves like a drop on the page. There, each file goes to the row that already carries its name, so dropping or pasting a file again updates that row instead of storing two files under one name. A file with no row of its name takes the first empty row, and extra files get new rows. The app overwrites a matched row without asking when an earlier drop or paste put its content there and no typing changed it. A drop or paste that would replace a row you filled shows a chip first, with Replace, Add as new, and Cancel; empty rows and new rows fill without asking. The#grip reorders rows before you save. This all needs JavaScript; the text flow works without it. -
Inline media: On the gist page, images embed inline and audio and video get native players. A PDF renders in an iframe, and any other binary gets a download link that keeps the file name. The bytes come from S3 directly:
/rawfor an attachment answers with a redirect to a presigned URL that is valid for ten minutes. The bucket answers the Range requests for video seeking, so the app server forwards no file bytes. -
Sharing: Every signed-in user can view any gist by URL. Only the owner can edit or delete one.
-
Delete and recover: Deleting hides a gist everywhere but the Deleted page, where the owner can restore it — with its full version history — for as long as it stays recoverable (7 days by default). A daily
dolmen scrubrun erases what has aged out, permanently. No bucket lifecycle rules involved. -
List page: Each row shows the title, the description, and the modification time, newest first. Title search runs in the browser over the whole list, so typing sends no server request. Timestamps render relative ("3 days ago"), with the absolute time in the tooltip. Listing reads one JSON object per gist. That is acceptable at personal scale, and it is the first thing to optimize if the list grows large. The key listing paginates, so the gist count is not capped at 1000.
-
Size limit: A request body over 16 MiB gets status 413, and the storage layer refuses a gist above 16 MiB. Attachments escape both limits: their bytes never pass through the app, so their only limit is the bucket itself.
Configuration is a YAML file passed with -config (default: config.yaml
in the current directory). configs/example.yaml documents every key with
values matching the docker-compose dev stack.
Non-secret values live in the file. A secret appears only as a reference:
oidc.client_secret names the environment variable that holds the client
secret; if the key is present and that variable is unset, startup fails. S3
credentials are not configuration at all; the standard AWS SDK credential
chain applies (environment variables, shared config file, instance profile).
| Key | Required | Meaning |
|---|---|---|
oidc.issuer |
yes | OIDC issuer URL |
oidc.client_id |
yes | OAuth client id |
oidc.client_secret |
no | Name of the environment variable holding the OAuth client secret |
s3.bucket |
yes | Bucket that holds the gists; the app enables its versioning and CORS on boot |
s3.endpoint |
no | Custom endpoint, for example https://sos-de-fra-1.exo.io. Empty means AWS |
s3.cache_size |
no | Memory budget for the read cache, for example 128MB or 512MiB. A bare number is bytes. Defaults to 128MB, and 0 turns caching off |
deleted_retention |
no | How long a deleted gist stays recoverable, as a Go duration such as 168h. The scrub job erases gists past this age and sweeps orphan uploads of the same age. Defaults to 168h |
listen |
no | Listen address. Defaults to :8080 |
base_url |
no | Externally reachable origin; builds the OAuth redirect URI. Defaults to http://localhost<listen> |
oidc.client_secret is only needed for the app's own login flow. Without
it, /login and /callback answer 503 and the app serves only requests
carrying a token from elsewhere — typically an authenticating proxy (for
example oauth2-proxy) that forwards the ID token as an
Authorization: Bearer header. Requests without a valid token then answer
401 instead of redirecting to /login, which is what a proxy watches for
to trigger re-authentication. Every token is still verified against
oidc.issuer and oidc.client_id: signature, audience, and expiry. That
is why both stay required. In this mode the app never sets a session
cookie, so the proxy owns the session lifetime entirely; the app only
enforces the token's own exp claim.
The app always sends path-style S3 requests and pins the SDK region to
us-east-1. S3-compatible providers route by endpoint, so this works.
The app keeps an LRU cache of gist objects in RAM, bounded by
s3.cache_size. The app never answers a read from it without proof: a HEAD
request confirms that the object still has the ETag of the cached bytes. The
app refetches a rewritten object and answers 404 for a deleted one. So the
cache removes object transfer and JSON parsing, while the request rate stays
the same. A warm view of one gist still costs two HEAD requests, and S3 bills
a HEAD like a GET.
Requests go down in two other places. Parallel requests for one object share a
single fetch, so a burst against one hot gist reads that object once instead of
once per request. A listing also carries the ETag of every key in it. A return
visit to /gists then costs one ListObjectsV2 call, however many gists you
have, because the app reads again only the objects whose ETag changed. Writes
through this process refresh the cache immediately, so you always see your own
save.
The budget covers cached bytes, not the whole process. Set GOMEMLIMIT for
that.
The compose file starts the same two dependencies the e2e suite uses: s3mock and Dex with two static users.
-
Start the stack:
docker compose up -dDex listens on
http://localhost:5556/dexand s3mock onhttp://localhost:9090with a bucket namedgists. The app enables versioning on it at startup. s3mock has no CORS API, so the app logs a warning about it and continues; s3mock answers every preflight anyway. -
Copy
configs/example.yamltoconfig.yaml(the defaults already match the stack) and export the client secret the config references:export OIDC_CLIENT_SECRET=secret -
Run the app:
go run . -
Open
http://localhost:8080and log in asalice@example.comorbob@example.comwith the passwordpassword. Both users live in the bcrypt hashes ofdex-config.yaml. The two users let you test sharing: bob can view alice's gists but cannot edit them.
dex-config.yaml carries a fixed client secret, test passwords, and
in-memory storage. Do not reuse it in production.
Unit tests:
go test ./...
node --test web/editor_settings_test.cjs
End-to-end tests against real s3mock and Dex containers (Docker required):
go test -tags e2e ./e2e/
- Build:
go build -o dolmen . - Write a config file;
configs/example.yamlis the starting point. Export the environment variables for the client secret and the S3 credentials. - Run
./dolmen -config /etc/dolmen/config.yamlfrom any directory. The binary needs no other file../dolmen -versionprints the build stamp.
SIGINT and SIGTERM drain in-flight requests for up to 10 seconds before the
process exits. An unauthenticated GET /healthz answers ok for container
supervisors.
A distroless, multi-arch (linux/amd64, linux/arm64) image is published to
ghcr.io: pushes to main publish :latest, version tags publish
:vX.Y.Z.
docker run -d \
-v /etc/dolmen/config.yaml:/config/dolmen.yaml:ro \
-e OIDC_CLIENT_SECRET=... \
-e AWS_ACCESS_KEY_ID=... -e AWS_SECRET_ACCESS_KEY=... \
-p 8080:8080 \
ghcr.io/brutasse/dolmen:latestThe image runs as nonroot and contains nothing but the binary. The config
file is mounted read-only at the path the entrypoint expects; override the
command arguments to point -config elsewhere. S3 credentials come from
the usual AWS environment variables (or any other SDK credential provider).
At startup the app configures the bucket it needs. It enables object
versioning, because gist history is S3 versions. It also ensures a CORS rule
that lets the browser PUT attachments directly, with the Content-Type
header, from the base_url origin. CORS rules written by others stay in
place. These operations need the s3:GetBucketVersioning,
s3:PutBucketVersioning, s3:GetBucketCORS, and s3:PutBucketCORS
permissions on the app's credentials. A backend without the CORS API, such
as s3mock, only logs a warning; you must configure attachment CORS yourself
there.
gists/{user}/{gist-id}.json— the gist: description, files, owner. This JSON holds text files inline; an attached file appears as{name, key, mime, size}. Each save creates a new S3 object version.index/{gist-id}— a pointer object whose content is the owner id. It makes the owner lookup for cross-user views cheap. If the pointer is missing, the gist answers 404. The app never scans thegists/user prefixes to recover an owner, because one view could then cost about 1000 requests.uploads/{user}/{uuid}— dropped attachments, one object per file with the content type pinned by the server. A gist can reference an upload only under the saving user's own prefix, and only if the object exists. A replaced attachment or a never-saved upload leaves an orphan object. Thescrubjob sweeps them: any upload older thandeleted_retentionthat no surviving gist references is erased, so no bucket lifecycle rule is needed. The sweep reads every surviving gist first and stops if any gist is unreadable, so a partial listing can never misjudge a live attachment as orphaned.deleted/{user}/{gist-id}— the tombstone of a deleted gist. Its presence is the sole record that a gist is deleted (the gist and index objects stay in place so recovery is possible); its content is the UTC deletion time. The recoverability window andscrub's purge both key off that timestamp. See Delete and recover below.
Deleting a gist writes a deleted/{user}/{id} tombstone and then hides the
owner index pointer, so the gist 404s on every route and drops off the list.
The gist object itself is left untouched, which is what makes recovery
possible: the owner restores it from the Deleted page (/gists/deleted)
within the deleted_retention window, exactly as it was, history included.
Restoration and erasure are driven by that tombstone, and every step is ordered and idempotent so a crash never leaves a dangling index or lost data that was still recoverable:
- Restore rewrites the index pointer, then removes the tombstone. If it stops in between, the gist stays hidden but the retry is identical — never a half-restored state.
- Erasure runs index → gist → tombstone. Removing the index first means an index can never outlive its gist and dangle; removing the tombstone last means an interrupted purge is still a visible, re-runnable deletion. The worst an interrupted purge can leave is a gist that has already stopped existing and so cannot be recovered — the accepted worst case.
./dolmen -config /etc/dolmen/config.yaml scrub is a one-shot command: it
permanently erases gists whose tombstone is older than deleted_retention,
including every stored version and the tombstone itself, then sweeps
uploads/ for orphans older than that window. It is idempotent, safe to run
any time, and exits non-zero if any purge left work for the next run. Run it
daily from cron or a systemd timer; it uses the same config and credentials
as the server.
# nightly purge and orphan sweep
17 3 * * * /usr/local/bin/dolmen -config /etc/dolmen/config.yaml scrubFor the container image, a Kubernetes CronJob (or equivalent) runs the same
binary: set the container command to ["-config", "/config/dolmen.yaml", "scrub"] and the schedule to once a day.
Scrub needs s3:ListBucketVersions on the bucket in addition to the read and
write permissions the server uses, since purging a deleted gist means listing
and deleting its object versions.
The binary embeds everything the UI needs — templates, stylesheet, fonts,
MathJax, Mermaid. There is no build step and no external request:
go build is the whole thing.
web/assets/app.cssis hand-written. Colors arelight-dark()custom properties resolved bycolor-scheme::rootfollows the OS, andhtml[data-theme]forces one theme. The header button cycles system, light, dark, and the choice survives reloads under thethemekey inlocalStorage— the layout head reads it in a small inline script that runs before the stylesheets, so a forced theme never flashes the other palette first. Keep the plain light tokens in:root: they are what a browser withoutlight-dark()(before Chrome 123, Safari 17.5, Firefox 120) renders, since custom properties do not fail at parse time.- Fonts are Inter (text) and JetBrains Mono (code): self-hosted variable
woff2 subsets under
web/assets/fonts/, each with its OFL license. - Mermaid 12.1.0 (MIT) and MathJax 3.2.2 (Apache-2.0) are vendored under
web/assets/vendor/, each with its license file. Mermaid is the client-side diagram renderer. It has no theme hook here — the vendored build paints mermaid's default theme, whose colours assume a white ground — so eachpre.mermaidis a white card in both themes rather than a diagram that inherits the dark page. - Markdown rendering is not in this repository. It is the
petroglyph Go module,
github.com/brutasse/petroglyph, pinned ingo.mod;handlers/renderer.gocallspetroglyph.Convertand acts on the math and mermaid flags it returns. - The highlight colors in
web/assets/chroma.cssare GitHub's prettylights palette, hand-written as one--code-*custom property per token family with alight-dark()pair each, so code follows the samecolor-schemeswitch as the rest of the page and the sheet carries no theme selectors of its own. A token rule names a variable and never a colour;TestChromaPaletteholds both halves of the palette to the same variable list and checks each colour against the code surface for WCAG AA contrast.
Exoscale's On-Demand Inference provided tokens that enabled this app to exist.