Replace Quartz with a read-only SilverBullet for public /notes/ #6

Merged
adamf merged 1 commits from silverbullet-public-notes into main 2026-10-01 14:47:54 +01:00
8 changed files with 200 additions and 84 deletions
+12 -10
View File
@@ -7,7 +7,7 @@
# it parses the file, before any container exists. This is how container # it parses the file, before any container exists. This is how container
# names, published ports and the Hasura database URL are built. # names, published ports and the Hasura database URL are built.
# 2. `env_file: ./.env` on a service. Injects the WHOLE file as environment # 2. `env_file: ./.env` on a service. Injects the WHOLE file as environment
# variables inside that container. nginx, backend, db, icecast2, quartz, # variables inside that container. nginx, backend, db, icecast2,
# certbot and gitea all do this. # certbot and gitea all do this.
# The `python` service deliberately does neither wholesale — it uses an # The `python` service deliberately does neither wholesale — it uses an
# explicit `environment:` allow-list of three variables, so it never sees the # explicit `environment:` allow-list of three variables, so it never sees the
@@ -91,14 +91,15 @@ EMAIL_SYNC_ENABLED=
# Kept because nginx/entrypoint.sh lists them in its envsubst allow-list; no # Kept because nginx/entrypoint.sh lists them in its envsubst allow-list; no
# compose service uses them today. Harmless if blank. # compose service uses them today. Harmless if blank.
# --- Quartz (notes site at /notes/) ------------------------------------------ # --- SilverBullet (notes) ---------------------------------------------------
QUARTZ_HOST=quartz # Two instances over the same vault: the admin-only editor at /sb/, and the
QUARTZ_PORT=8080 # public read-only notes site at /notes/ (which replaced Quartz). All four
# default in nginx/entrypoint.sh and docker-compose.yml, so they can be left
# SilverBullet, the notes editor at /sb/. Both default in nginx/entrypoint.sh, # blank.
# so they can be left blank.
SILVERBULLET_HOST=silverbullet SILVERBULLET_HOST=silverbullet
SILVERBULLET_PORT=3000 SILVERBULLET_PORT=3000
SILVERBULLET_PUBLIC_HOST=silverbullet-public
SILVERBULLET_PUBLIC_PORT=3000
# Seconds between notes commit/push cycles (default 300). # Seconds between notes commit/push cycles (default 300).
SILVERBULLET_GIT_INTERVAL= SILVERBULLET_GIT_INTERVAL=
@@ -114,9 +115,10 @@ BACKEND_SECRET=
BACKEND_ENDPOINT=/api BACKEND_ENDPOINT=/api
# --- Obsidian vault ---------------------------------------------------------- # --- Obsidian vault ----------------------------------------------------------
# HOST path, interpolated straight into two bind mounts: read-write into the # HOST path, interpolated straight into the bind mounts: read-write into the
# backend, read-only into quartz. Must be an absolute path that exists on the # backend, silverbullet and silverbullet-git, read-only into
# host or the stack will not start. # silverbullet-public. Must be an absolute path that exists on the host or the
# stack will not start.
OBSIDIAN_DIR= OBSIDIAN_DIR=
# --- Spotify ----------------------------------------------------------------- # --- Spotify -----------------------------------------------------------------
+17 -10
View File
@@ -30,7 +30,7 @@ Only three things are reachable from outside the Pi: nginx on 80/443, Gitea on
| | | | | | | as icecast2) | | | | | | | as icecast2)
v v v v v v | | v v v v v v | |
/api/ /radio/ /gitea/ /hasura/ /notes/ /py/ | | /api/ /radio/ /gitea/ /hasura/ /notes/ /py/ | |
backend icecast2 gitea hasura quartz python | | backend icecast2 gitea hasura sb-pub python | |
| ^ | | | | ^ | | |
| | | | | | | | | |
| +------------------|--------------------|---------------+ | +------------------|--------------------|---------------+
@@ -54,8 +54,8 @@ backend icecast2 gitea hasura quartz python | |
| backend (Go) | `${BACKEND_HOST}` | `${BACKEND_PORT}` (8080) | `${BACKEND_ENDPOINT}` = `/api/` | no | | backend (Go) | `${BACKEND_HOST}` | `${BACKEND_PORT}` (8080) | `${BACKEND_ENDPOINT}` = `/api/` | no |
| db (Postgres 16) | `${POSTGRES_HOST}` | 5432 | none | no | | db (Postgres 16) | `${POSTGRES_HOST}` | 5432 | none | no |
| hasura | `${HASURA_HOST}` | `${HASURA_PORT}` | `/hasura/` (admin-gated) | no | | hasura | `${HASURA_HOST}` | `${HASURA_PORT}` | `/hasura/` (admin-gated) | no |
| quartz (notes) | `${QUARTZ_HOST}` | `${QUARTZ_PORT}` | `/notes/` (admin-gated) | no | | silverbullet (editor) | `${SILVERBULLET_HOST}` | `${SILVERBULLET_PORT}` | `/sb/` (admin-gated) | no |
| silverbullet | `${SILVERBULLET_HOST}` | `${SILVERBULLET_PORT}` | `/sb/` (admin-gated) | no | | silverbullet-public (notes site) | `${SILVERBULLET_PUBLIC_HOST}` | `${SILVERBULLET_PUBLIC_PORT}` | `/notes/` (**public**, read-only) | no |
| silverbullet-git | n/a | n/a | none (timer loop) | no | | silverbullet-git | n/a | n/a | none (timer loop) | no |
| python (FastAPI) | `${PYTHON_HOST}` | `${PYTHON_PORT}` | `/py/`, docs at `/py/docs` | no | | python (FastAPI) | `${PYTHON_HOST}` | `${PYTHON_PORT}` | `/py/`, docs at `/py/docs` | no |
| icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** | | icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** |
@@ -72,17 +72,24 @@ in one step — never change one without the other.**
- **Canonical host.** `http://` → `https://`, and apex → `www`. The SPA, the - **Canonical host.** `http://` → `https://`, and apex → `www`. The SPA, the
cookies and the CORS rules all assume `www.<DOMAIN>`. cookies and the CORS rules all assume `www.<DOMAIN>`.
- **Prefix stripping.** `/api`, `/radio`, `/gitea`, `/notes`, `/py` are stripped - **Prefix stripping.** `/api`, `/radio`, `/gitea`, `/py` are stripped
— but `/sb/` deliberately is NOT: SilverBullet is told its own base path via — but `/sb/` and `/notes/` deliberately are NOT: SilverBullet is told its own base path via
`SB_URL_PREFIX` and builds its service-worker scope from it, so stripping the `SB_URL_PREFIX` and builds its service-worker scope from it, so stripping the
prefix serves a blank page with nothing in the log. prefix serves a blank page with nothing in the log.
by a `rewrite ... break` before proxying; each upstream serves from `/`. by a `rewrite ... break` before proxying; each upstream serves from `/`.
- **Per-request DNS.** Upstreams go through `set $upstream_* ...` variables with - **Per-request DNS.** Upstreams go through `set $upstream_* ...` variables with
`resolver 127.0.0.11`, so names resolve per request. nginx boots fine with a `resolver 127.0.0.11`, so names resolve per request. nginx boots fine with a
backend down (502s until it appears) instead of refusing to start. backend down (502s until it appears) instead of refusing to start.
- **Admin gate.** `/hasura/`, `/notes/` and `/sb/` are protected by an `auth_request` - **Admin gate.** `/hasura/`, `/sb/`, `/radio/admin/` and `/uploads/private/` are protected by an `auth_request`
subrequest to the backend's `/auth/validate-admin`; a failure redirects to the subrequest to the backend's `/auth/validate-admin`; a failure redirects to the
SPA login. Neither service has any auth of its own at that path. SPA login. None of these services has any auth of its own at that path.
- **Public notes privacy boundary.** `/notes/` is public, and the only thing
keeping `private/` (and `templates/`, `.git`, `.obsidian`) off it is a pair of
nginx deny blocks. SilverBullet's `SB_SPACE_IGNORE` only hides paths from its
file *list*; direct `/.fs/` fetches and server-rendered page URLs still serve
them. Adding a folder to `SB_SPACE_IGNORE` on `silverbullet-public` without
adding it to the deny regex in both nginx templates publishes it. See the
comment above `location /notes/` in `nginx.conf.template`.
- **Uploads served directly.** `/uploads/` is an alias onto the shared `uploads` - **Uploads served directly.** `/uploads/` is an alias onto the shared `uploads`
volume with `nosniff`, `Content-Disposition: inline` and a deny-all CSP, so volume with `nosniff`, `Content-Disposition: inline` and a deny-all CSP, so
user-supplied files cannot execute anything on our origin. user-supplied files cannot execute anything on our origin.
@@ -212,10 +219,10 @@ of deleting the directory:
| `./gitea/config` | Gitea's live `app.ini` | Gitignored; generated from the template on first boot and then owned by Gitea | | `./gitea/config` | Gitea's live `app.ini` | Gitignored; generated from the template on first boot and then owned by Gitea |
| `./logs` | Backend logs | | | `./logs` | Backend logs | |
| `./icecast2/fallback_music` | Radio fallback MP3s | Synced by `sync-secrets.sh`, not git | | `./icecast2/fallback_music` | Radio fallback MP3s | Synced by `sync-secrets.sh`, not git |
| `${OBSIDIAN_DIR}` | The Obsidian vault (a git clone of the notes repo) | Read-write to backend and silverbullet, **read-only** to quartz | | `${OBSIDIAN_DIR}` | The Obsidian vault (a git clone of the notes repo) | Read-write to backend and silverbullet, **read-only** to silverbullet-public |
**Ephemeral:** anything else inside a container. Notably the Vue build, the **Ephemeral:** anything else inside a container. Notably the Vue build, the
rendered nginx/icecast/quartz configs, and the Gitea runner's downloaded binary rendered nginx/icecast configs, and the Gitea runner's downloaded binary
are all regenerated. are all regenerated.
--- ---
@@ -230,7 +237,7 @@ Two distinct mechanisms read it, and services use both:
- **`${VAR}` in `docker-compose.yml`** — substituted by the compose CLI at parse - **`${VAR}` in `docker-compose.yml`** — substituted by the compose CLI at parse
time. Builds container names, published ports, the Hasura database URL. time. Builds container names, published ports, the Hasura database URL.
- **`env_file: ./.env`** — injects the whole file into the container. Used by - **`env_file: ./.env`** — injects the whole file into the container. Used by
nginx, backend, db, icecast2, quartz, certbot. nginx, backend, db, icecast2, certbot.
`gitea` instead receives explicit `GITEA__section__KEY` variables (Gitea's own `gitea` instead receives explicit `GITEA__section__KEY` variables (Gitea's own
convention for overriding `app.ini` keys), and `python` receives an explicit convention for overriding `app.ini` keys), and `python` receives an explicit
+14 -11
View File
@@ -23,8 +23,8 @@ backend (8080) ── Go API (GraphQL + REST)
db (5432) ── PostgreSQL 16 db (5432) ── PostgreSQL 16
icecast2 (8000) ── Audio Streaming (Icecast2 + Liquidsoap) icecast2 (8000) ── Audio Streaming (Icecast2 + Liquidsoap)
gitea (3000) ── Self-Hosted Git gitea (3000) ── Self-Hosted Git
quartz (8080) ── Obsidian Notes Publisher (Quartz v4.4.0)
silverbullet (3000) ── Obsidian Notes Editor (SilverBullet 2.11.0) silverbullet (3000) ── Obsidian Notes Editor (SilverBullet 2.11.0)
silverbullet-public (3000) ── Public read-only notes site (same image, SB_READ_ONLY)
silverbullet-git ── Commits/pushes notes edits to the notes repo silverbullet-git ── Commits/pushes notes edits to the notes repo
python (8000) ── Python API (FastAPI) python (8000) ── Python API (FastAPI)
hasura (8080) ── Hasura GraphQL Engine (Docker profile: hasura) hasura (8080) ── Hasura GraphQL Engine (Docker profile: hasura)
@@ -46,7 +46,7 @@ certbot ── SSL Certificate Management (disabled in dev)
- Spotify integration (currently playing, recently played) - Spotify integration (currently playing, recently played)
- Steam integration (online status, recent games) - Steam integration (online status, recent games)
- Obsidian note viewer via Quartz, editable from any browser via SilverBullet - Public Obsidian notes site via a read-only SilverBullet, editable from any browser via a second, admin-only SilverBullet
- Live radio streaming via Icecast2 + Liquidsoap - Live radio streaming via Icecast2 + Liquidsoap
- Real-time chat over WebSockets with image/video uploads - Real-time chat over WebSockets with image/video uploads
- Blog with admin panel (CRUD) - Blog with admin panel (CRUD)
@@ -73,7 +73,7 @@ certbot ── SSL Certificate Management (disabled in dev)
| `/cv` | Curriculum Vitae (printable) | | `/cv` | Curriculum Vitae (printable) |
| `/cv/jobs` | Job application tracker (admin-only, hidden print) | | `/cv/jobs` | Job application tracker (admin-only, hidden print) |
| `/bookmarks` | Bookmarks (database-backed, grouped by category) | | `/bookmarks` | Bookmarks (database-backed, grouped by category) |
| `/notes/:path` | Obsidian note viewer (via Quartz, admin-only) | | `/notes/:path` | Obsidian notes (read-only SilverBullet, public; `private/` excluded) |
| `/sb/` | Obsidian note editor (via SilverBullet, admin-only) | | `/sb/` | Obsidian note editor (via SilverBullet, admin-only) |
| `/shrines` | Fan shrine index + individual shrines | | `/shrines` | Fan shrine index + individual shrines |
@@ -184,16 +184,16 @@ Access tokens are valid for 7 days; refresh tokens for 365 days. `ValidateAdmin`
| `/radio` | icecast:8000 | Audio streaming | | `/radio` | icecast:8000 | Audio streaming |
| `/gitea` | gitea:3000 | Git service | | `/gitea` | gitea:3000 | Git service |
| `/hasura` | hasura:8080 | GraphQL console + WebSocket (admin-only) | | `/hasura` | hasura:8080 | GraphQL console + WebSocket (admin-only) |
| `/notes` | quartz:8080 | Obsidian notes (admin-only) | | `/notes` | silverbullet-public:3000 | Obsidian notes (public, read-only) |
| `/sb` | silverbullet:3000 | Obsidian notes editor (admin-only) | | `/sb` | silverbullet:3000 | Obsidian notes editor (admin-only) |
| `/py` | python:8000 | Python API (FastAPI; docs at `/py/docs`) | | `/py` | python:8000 | Python API (FastAPI; docs at `/py/docs`) |
| `/uploads` | local alias | User-uploaded files | | `/uploads` | local alias | User-uploaded files |
`/hasura` and `/notes` are protected by `auth_request` to `GET /api/auth/validate-admin`. Requests without a valid admin JWT are rejected with 401. `/hasura` and `/sb` are protected by `auth_request` to `GET /api/auth/validate-admin`. Requests without a valid admin JWT are rejected with 401.
### Deprecated Endpoints ### Deprecated Endpoints
**Backend note API** (`GET /api/notes/*path`) - The backend has a REST endpoint that serves note files directly from the mounted Obsidian vault. This is superseded by the Quartz service which now handles note rendering at `/notes/`. The backend endpoint still exists in code but is no longer the primary note serving path. **Backend note API** (`GET /api/notes/*path`) - The backend has a REST endpoint that serves note files directly from the mounted Obsidian vault. This is superseded by the public SilverBullet instance which now handles note rendering at `/notes/`. The backend endpoint still exists in code but is no longer the primary note serving path.
## Setup ## Setup
@@ -218,10 +218,10 @@ Create a `.env` file in the project root. All services read from this file.
| `UPTIMEKUMA_PORT` | Uptime Kuma port (planned) | | `UPTIMEKUMA_PORT` | Uptime Kuma port (planned) |
| `WALLABAG_HOST` | Wallabag hostname (planned) | | `WALLABAG_HOST` | Wallabag hostname (planned) |
| `WALLABAG_PORT` | Wallabag port (planned) | | `WALLABAG_PORT` | Wallabag port (planned) |
| `QUARTZ_HOST` | Quartz hostname (use `quartz` for Docker) |
| `QUARTZ_PORT` | Quartz port (typically `8080`) |
| `SILVERBULLET_HOST` | SilverBullet hostname (defaults to `silverbullet`) | | `SILVERBULLET_HOST` | SilverBullet hostname (defaults to `silverbullet`) |
| `SILVERBULLET_PORT` | SilverBullet port (defaults to `3000`) | | `SILVERBULLET_PORT` | SilverBullet port (defaults to `3000`) |
| `SILVERBULLET_PUBLIC_HOST` | Public notes SilverBullet hostname (defaults to `silverbullet-public`) |
| `SILVERBULLET_PUBLIC_PORT` | Public notes SilverBullet port (defaults to `3000`) |
| `SILVERBULLET_GIT_INTERVAL` | Seconds between notes commit/push cycles (defaults to `300`) | | `SILVERBULLET_GIT_INTERVAL` | Seconds between notes commit/push cycles (defaults to `300`) |
| `GITEA_RUNNER_HOST` | Gitea runner hostname | | `GITEA_RUNNER_HOST` | Gitea runner hostname |
| `GITEA_RUNNER_NAME` | Gitea runner display name | | `GITEA_RUNNER_NAME` | Gitea runner display name |
@@ -274,9 +274,12 @@ Populate `LFS_JWT_SECRET`, `SECRET_KEY`, `INTERNAL_TOKEN`, `JWT_SECRET`, and the
### Obsidian Notes Setup ### Obsidian Notes Setup
1. Set `OBSIDIAN_DIR` in `.env` to the absolute path of your Obsidian vault on the host machine 1. Set `OBSIDIAN_DIR` in `.env` to the absolute path of your Obsidian vault on the host machine
2. The vault is mounted read-only into the Quartz container at `/quartz/content`, and 2. The vault is mounted read-write into `silverbullet` at `/data`, which serves it as an
read-write into SilverBullet at `/data`, which serves it as an editor at `/sb/` editor at `/sb/`, and read-only into `silverbullet-public`, which serves it publicly at
3. Quartz builds a static site from the vault on startup and serves it at `/notes/` `/notes/` with `SB_READ_ONLY`
3. `private/` and `templates/` (at any depth), and dot-folders such as `.git`, are kept off
`/notes/` by `SB_SPACE_IGNORE` **and** nginx deny blocks — the nginx blocks are the ones that
actually enforce it. See `DEPLOYMENT.md` ("Public notes privacy boundary")
4. The backend also mounts the vault at `/backend/notes` (legacy, see deprecated endpoints above) 4. The backend also mounts the vault at `/backend/notes` (legacy, see deprecated endpoints above)
### SSL Certificates (Certbot) ### SSL Certificates (Certbot)
+68 -32
View File
@@ -22,7 +22,7 @@
# #
# Required by this file: POSTGRES_{USER,PASSWORD,DB,PORT,HOST}, # Required by this file: POSTGRES_{USER,PASSWORD,DB,PORT,HOST},
# POSTGRES_GITEA_DB, BACKEND_HOST, HASURA_HOST, HASURA_GRAPHQL_ADMIN_SECRET, # POSTGRES_GITEA_DB, BACKEND_HOST, HASURA_HOST, HASURA_GRAPHQL_ADMIN_SECRET,
# ICECAST_HOST, QUARTZ_HOST, GITEA_HOST, OBSIDIAN_DIR, and the GITEA_* # ICECAST_HOST, GITEA_HOST, OBSIDIAN_DIR, and the GITEA_*
# secrets. PYTHON_HOST/PYTHON_PORT/TFL_APP_KEY/LIQUIDSOAP_HARBOR_PORT have # secrets. PYTHON_HOST/PYTHON_PORT/TFL_APP_KEY/LIQUIDSOAP_HARBOR_PORT have
# inline defaults. # inline defaults.
# #
@@ -36,7 +36,7 @@
# WHAT IS PUBLISHED TO THE HOST # WHAT IS PUBLISHED TO THE HOST
# Only nginx (80, 443), gitea (3000 HTTP, 2222 SSH) and the liquidsoap harbor # Only nginx (80, 443), gitea (3000 HTTP, 2222 SSH) and the liquidsoap harbor
# port. Everything else is reachable only from inside app-network, which is # port. Everything else is reachable only from inside app-network, which is
# why the backend, db, hasura, quartz and python have no `ports:` — they are # why the backend, db, hasura, silverbullet and python have no `ports:` — they are
# deliberately not exposed and are reached through nginx. # deliberately not exposed and are reached through nginx.
# ============================================================================= # =============================================================================
@@ -112,8 +112,8 @@ services:
- icecast2 - icecast2
- gitea - gitea
- hasura - hasura
- quartz
- silverbullet - silverbullet
- silverbullet-public
- python - python
networks: networks:
- app-network - app-network
@@ -178,7 +178,8 @@ services:
# deploy. Gitignored (it is a credential). # deploy. Gitignored (it is a credential).
- ./backend/token/:/backend/token - ./backend/token/:/backend/token
# The Obsidian vault on the host, read by the backend for the notes API. # The Obsidian vault on the host, read by the backend for the notes API.
# Same directory is mounted read-only into quartz to build the notes site. # Same directory is mounted read-write into silverbullet (the editor) and
# read-only into silverbullet-public (the /notes/ site).
- ${OBSIDIAN_DIR}:/backend/notes - ${OBSIDIAN_DIR}:/backend/notes
- ./logs:/backend/logs - ./logs:/backend/logs
# Same named volume nginx serves at /uploads/ — backend writes, nginx reads. # Same named volume nginx serves at /uploads/ — backend writes, nginx reads.
@@ -304,33 +305,16 @@ services:
ports: ports:
- "${LIQUIDSOAP_HARBOR_PORT:-8001}:${LIQUIDSOAP_HARBOR_PORT:-8001}" - "${LIQUIDSOAP_HARBOR_PORT:-8001}:${LIQUIDSOAP_HARBOR_PORT:-8001}"
# Quartz renders the Obsidian vault into the notes site at /notes/ (also # Browser-based editor for the vault, so notes are editable from a phone.
# behind the nginx admin auth_request). The vault is mounted READ-ONLY so a # Proxied at /sb/ behind the nginx admin gate. The public site at /notes/ is
# bug in Quartz can never write into the real notes. Quartz is run in # a SECOND, read-only SilverBullet over the same folder (silverbullet-public,
# `build --serve` watch mode, so edits to the vault on the host appear # below).
# without restarting the container.
quartz:
build:
context: ./quartz
dockerfile: Dockerfile
container_name: "${QUARTZ_HOST}"
restart: always
networks:
- app-network
env_file:
- ./.env
volumes:
- ${OBSIDIAN_DIR}:/quartz/content:ro
# Browser-based editor for the SAME vault quartz renders read-only at /notes/.
# Quartz is a static site generator with no write path; this is what makes the
# notes editable from a phone. Proxied at /sb/ behind the same nginx admin gate.
# #
# SINGLE-SPACE MODE is auto-detected because the mounted folder is not empty # SINGLE-SPACE MODE is auto-detected because the mounted folder is not empty
# (the alternative, multi-space, expects /data to be a SilverBullet-owned # (the alternative, multi-space, expects /data to be a SilverBullet-owned
# folder of spaces). In this mode it treats the mount as the space itself and # folder of spaces). In this mode it treats the mount as the space itself and
# writes NO database or metadata files into the vault — the folder stays a # writes NO database or metadata files into the vault — the folder stays a
# plain directory of markdown that quartz and Obsidian still understand. # plain directory of markdown that Obsidian still understands.
silverbullet: silverbullet:
image: ghcr.io/silverbulletmd/silverbullet:2.11.0 image: ghcr.io/silverbulletmd/silverbullet:2.11.0
container_name: "${SILVERBULLET_HOST:-silverbullet}" container_name: "${SILVERBULLET_HOST:-silverbullet}"
@@ -344,12 +328,11 @@ services:
SB_URL_PREFIX: /sb SB_URL_PREFIX: /sb
# Only .obsidian: it is editor config and plugin JS, not notes. # Only .obsidian: it is editor config and plugin JS, not notes.
# #
# Deliberately NOT quartz's ignorePatterns, which also lists private/ and # Deliberately NOT silverbullet-public's list, which also hides private/
# templates/. Those two settings answer different questions: quartz hides # and templates/. The two answer different questions: the public
# private/ because it must never be PUBLISHED, whereas this is the editor, # instance hides private/ because it must never be PUBLISHED, whereas
# reachable only through the admin gate, and hiding notes from it just # this is the editor, reachable only through the admin gate, and hiding
# stops you editing them. Quartz keeps its own ignorePatterns, so nothing # notes from it just stops you editing them.
# here changes what /notes/ publishes.
# #
# MUST be newline separated: a comma separated list is accepted silently # MUST be newline separated: a comma separated list is accepted silently
# and does nothing. # and does nothing.
@@ -364,6 +347,59 @@ services:
volumes: volumes:
- ${OBSIDIAN_DIR}:/data - ${OBSIDIAN_DIR}:/data
# The PUBLIC notes site at /notes/ (replaced Quartz): the same SilverBullet
# image in read-only mode over the same vault, with no auth. Visitors get the
# full client — navigation, backlinks, live queries — but cannot write.
# Edits made in the /sb/ editor show up here live, since both watch one folder.
#
# KEEPING private/ PRIVATE takes three layers, because none is enough alone:
# 1. SB_SPACE_IGNORE hides the paths from the file LIST, so they are
# never indexed, searched or shown. It does NOT stop
# a direct fetch of /.fs/private/x.md, nor the page
# URL /notes/private/x (server-rendered with the
# note's content), nor /.fs/.git/ — SilverBullet
# only applies it to listing (checked in 2.11.0).
# 2. nginx deny blocks 404 any private/ or templates/ segment and any
# nested dot-folder under /notes/; this is what
# actually closes those holes. Keep its folder list
# in step with the one below.
# 3. SB_REVISIONS the default ("unmanaged") serves history from the
# vault's own .git, i.e. every version of every file
# including private/ and deleted ones. Disabled here,
# and nginx blocks /notes/.revisions as well.
#
# SB_READ_ONLY rejects writes server-side and also disables the shell and the
# /.proxy endpoint (otherwise an open fetch proxy). The :ro mount is a second
# lock on writes. It is flagged "legacy" upstream in favour of multi-space
# mode's per-space publish setting, which cannot exclude a folder and would
# mean migrating the editor too — revisit if single-space mode is removed.
#
# Keep the image tag in lockstep with the editor above.
silverbullet-public:
image: ghcr.io/silverbulletmd/silverbullet:2.11.0
container_name: "${SILVERBULLET_PUBLIC_HOST:-silverbullet-public}"
restart: always
networks:
- app-network
environment:
SB_PORT: "${SILVERBULLET_PUBLIC_PORT:-3000}"
# Same reason as the editor's SB_URL_PREFIX: nginx must not strip /notes/.
SB_URL_PREFIX: /notes
SB_READ_ONLY: "true"
SB_REVISIONS: disabled
# Newline separated (commas are silently ignored). Gitignore semantics,
# so these match at any depth. Must match the folder list in the
# /notes/ deny regex in BOTH nginx templates, or a new entry here is
# hidden from the list but still publicly fetchable.
SB_SPACE_IGNORE: |
private/
templates/
.obsidian
PUID: "1000"
PGID: "1000"
volumes:
- ${OBSIDIAN_DIR}:/data:ro
# SilverBullet has no concept of git, so this commits and pushes what it # SilverBullet has no concept of git, so this commits and pushes what it
# writes, and pulls what Obsidian pushes from elsewhere. # writes, and pulls what Obsidian pushes from elsewhere.
# #
+5 -2
View File
@@ -68,8 +68,9 @@
# ICECAST_HOST / ICECAST_PORT radio stream upstream # ICECAST_HOST / ICECAST_PORT radio stream upstream
# GITEA_HOST / GITEA_PORT git server upstream # GITEA_HOST / GITEA_PORT git server upstream
# HASURA_HOST / HASURA_PORT Hasura console upstream # HASURA_HOST / HASURA_PORT Hasura console upstream
# QUARTZ_HOST / QUARTZ_PORT notes site upstream
# SILVERBULLET_HOST / _PORT notes editor upstream (defaulted below) # SILVERBULLET_HOST / _PORT notes editor upstream (defaulted below)
# SILVERBULLET_PUBLIC_HOST / _PORT
# public notes viewer upstream (defaulted below)
# PYTHON_HOST / PYTHON_PORT FastAPI upstream (defaulted below) # PYTHON_HOST / PYTHON_PORT FastAPI upstream (defaulted below)
# DEV_MODE "true" only via docker-compose.dev.yml # DEV_MODE "true" only via docker-compose.dev.yml
# CERT_WATCH_INTERVAL optional, seconds between certificate-watch # CERT_WATCH_INTERVAL optional, seconds between certificate-watch
@@ -89,11 +90,13 @@ export PYTHON_HOST="${PYTHON_HOST:-python}"
export PYTHON_PORT="${PYTHON_PORT:-8000}" export PYTHON_PORT="${PYTHON_PORT:-8000}"
export SILVERBULLET_HOST="${SILVERBULLET_HOST:-silverbullet}" export SILVERBULLET_HOST="${SILVERBULLET_HOST:-silverbullet}"
export SILVERBULLET_PORT="${SILVERBULLET_PORT:-3000}" export SILVERBULLET_PORT="${SILVERBULLET_PORT:-3000}"
export SILVERBULLET_PUBLIC_HOST="${SILVERBULLET_PUBLIC_HOST:-silverbullet-public}"
export SILVERBULLET_PUBLIC_PORT="${SILVERBULLET_PUBLIC_PORT:-3000}"
# The envsubst allow-list, defined once and reused by both full-config branches # The envsubst allow-list, defined once and reused by both full-config branches
# so the two lists cannot drift apart. It MUST stay single-quoted here and be # so the two lists cannot drift apart. It MUST stay single-quoted here and be
# passed as "$ENVSUBST_VARS" (one argument) below. # passed as "$ENVSUBST_VARS" (one argument) below.
ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${HASURA_HOST} ${HASURA_PORT} ${QUARTZ_HOST} ${QUARTZ_PORT} ${SILVERBULLET_HOST} ${SILVERBULLET_PORT} ${PYTHON_HOST} ${PYTHON_PORT}' ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${HASURA_HOST} ${HASURA_PORT} ${SILVERBULLET_HOST} ${SILVERBULLET_PORT} ${SILVERBULLET_PUBLIC_HOST} ${SILVERBULLET_PUBLIC_PORT} ${PYTHON_HOST} ${PYTHON_PORT}'
# Check if DEV_MODE # Check if DEV_MODE
if [ "$DEV_MODE" = "true" ]; then if [ "$DEV_MODE" = "true" ]; then
+56 -11
View File
@@ -11,7 +11,7 @@
# TEMPLATING # TEMPLATING
# Only the names in the envsubst allow-list in nginx/entrypoint.sh are # Only the names in the envsubst allow-list in nginx/entrypoint.sh are
# substituted: DOMAIN, BACKEND_HOST/PORT/ENDPOINT, ICECAST_*, GITEA_*, # substituted: DOMAIN, BACKEND_HOST/PORT/ENDPOINT, ICECAST_*, GITEA_*,
# HASURA_*, QUARTZ_*, PYTHON_*, UPTIMEKUMA_*, WALLABAG_*. Every other dollar # HASURA_*, SILVERBULLET_*, PYTHON_*, UPTIMEKUMA_*, WALLABAG_*. Every other dollar
# token in this file is an nginx RUNTIME variable (host, remote_addr, uri, # token in this file is an nginx RUNTIME variable (host, remote_addr, uri,
# http_upgrade, proxy_add_x_forwarded_for, binary_remote_addr, request_uri, # http_upgrade, proxy_add_x_forwarded_for, binary_remote_addr, request_uri,
# scheme, http_cookie) and must be left alone — that restriction is the whole # scheme, http_cookie) and must be left alone — that restriction is the whole
@@ -165,8 +165,8 @@ http {
set $upstream_icecast http://$ICECAST_HOST:$ICECAST_PORT; set $upstream_icecast http://$ICECAST_HOST:$ICECAST_PORT;
set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT; set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT;
set $upstream_hasura http://$HASURA_HOST:$HASURA_PORT; set $upstream_hasura http://$HASURA_HOST:$HASURA_PORT;
set $upstream_quartz http://$QUARTZ_HOST:$QUARTZ_PORT;
set $upstream_silverbullet http://$SILVERBULLET_HOST:$SILVERBULLET_PORT; set $upstream_silverbullet http://$SILVERBULLET_HOST:$SILVERBULLET_PORT;
set $upstream_silverbullet_public http://$SILVERBULLET_PUBLIC_HOST:$SILVERBULLET_PUBLIC_PORT;
set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT; set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT;
root /etc/nginx/html; root /etc/nginx/html;
@@ -205,7 +205,7 @@ http {
# PRIVATE attachments (admin-only). Attachments on *private* chat # PRIVATE attachments (admin-only). Attachments on *private* chat
# messages are written by the backend to /backend/uploads/private/ and # messages are written by the backend to /backend/uploads/private/ and
# must not be readable by the public, so this subpath is put behind the # must not be readable by the public, so this subpath is put behind the
# same admin `auth_request` used for /hasura/ and /notes/. nginx picks # same admin `auth_request` used for /hasura/ and /sb/. nginx picks
# the LONGEST matching prefix location, so this block wins over the # the LONGEST matching prefix location, so this block wins over the
# public /uploads/ block below for /uploads/private/* regardless of # public /uploads/ block below for /uploads/private/* regardless of
# ordering. Same three hardening headers as the public block, because # ordering. Same three hardening headers as the public block, because
@@ -279,8 +279,7 @@ http {
# #
# 1. THE PREFIX-STRIP REWRITE # 1. THE PREFIX-STRIP REWRITE
# rewrite ^<PREFIX>/(.*)$ /$1 break; # rewrite ^<PREFIX>/(.*)$ /$1 break;
# The public URL carries a prefix (/api, /radio, /gitea, /notes, # The public URL carries a prefix (/api, /radio, /gitea, /py) but the upstream service serves its routes from /. The
# /py) but the upstream service serves its routes from /. The
# rewrite strips the prefix and `break` stops rewrite processing so # rewrite strips the prefix and `break` stops rewrite processing so
# the request stays in this location and goes to proxy_pass with the # the request stays in this location and goes to proxy_pass with the
# rewritten URI. (This is why proxy_pass here has no trailing path — # rewritten URI. (This is why proxy_pass here has no trailing path —
@@ -377,7 +376,7 @@ http {
# surface — kick sources, change metadata — protected only by the # surface — kick sources, change metadata — protected only by the
# icecast admin password, and it was reachable from the public # icecast admin password, and it was reachable from the public
# internet through this proxy. Put it behind the same admin # internet through this proxy. Put it behind the same admin
# `auth_request` as /hasura/ and /notes/ so an admin session cookie is # `auth_request` as /hasura/ and /sb/ so an admin session cookie is
# required before the request ever reaches icecast. Longest-prefix # required before the request ever reaches icecast. Longest-prefix
# matching means this wins over /radio/ below; listener traffic # matching means this wins over /radio/ below; listener traffic
# (/radio/$ICECAST_MOUNT, /radio/status.xsl) is untouched. # (/radio/$ICECAST_MOUNT, /radio/status.xsl) is untouched.
@@ -436,9 +435,55 @@ http {
return 301 /notes/; return 301 /notes/;
} }
# PUBLIC notes viewer: a second, read-only SilverBullet over the same
# vault the /sb/ editor edits. No auth_request — this is the public
# site. See the silverbullet-public service in docker-compose.yml.
#
# THE DENY BLOCKS BELOW ARE THE PRIVACY BOUNDARY, not decoration.
# SB_SPACE_IGNORE only hides paths from the file LIST. Everything else
# happily serves them (all verified against 2.11.0 with curl):
# /notes/.fs/private/x.md raw file, straight off disk
# /notes/private/x the page URL: the server pre-renders the
# note's content into the HTML shell
# /notes/.fs/.git/... the vault's whole git repo, i.e. every
# version of every private note ever
# and gitignore semantics mean `private/` in SB_SPACE_IGNORE hides a
# private/ folder at ANY depth from the list, so the block must too.
#
# 1. private/ or templates/ as any path segment, page URL or /.fs/.
# ~* so Private/ is caught; (/|$) so the folder itself matches.
# 2. Any dot-segment below the first: .git, .obsidian, .env, ... The
# first segment is exempt because that is where SilverBullet's own
# endpoints live (/.fs, /.config, /.client, /.events ...). Nothing
# the client legitimately loads has a dot-segment deeper than that.
# nginx matches against the normalised URI (percent-decoded, `..`
# resolved, slashes merged), so %2F, // or ../ tricks cannot slip past.
# Keep the folder list in step with SB_SPACE_IGNORE on
# silverbullet-public. 404 rather than 403 so the response does not
# confirm a private path exists.
location ~* ^/notes/(.*/)?(private|templates)(/|$) {
return 404;
}
location ~ ^/notes/.+/\. {
return 404;
}
# Revisions are read from the vault's own .git, i.e. the full history
# of every file INCLUDING private/ and anything ever deleted.
# SB_REVISIONS=disabled already turns this off upstream; this is the
# second lock in case that env var is ever dropped. ^~ so no regex
# location can take precedence.
location ^~ /notes/.revisions {
return 404;
}
# Same as /sb/: deliberately NO prefix-strip rewrite. The app is told
# its base path via SB_URL_PREFIX=/notes and builds its service worker
# scope and asset URLs from it; strip the prefix and it loads blank.
# Upgrade/Connection are for its live-update event stream.
location /notes/ { location /notes/ {
rewrite ^/notes/(.*)$ /$1 break; proxy_pass $upstream_silverbullet_public;
proxy_pass $upstream_quartz;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "upgrade";
@@ -452,7 +497,7 @@ http {
return 301 /sb/; return 301 /sb/;
} }
# SilverBullet: the editor for the same vault quartz renders at /notes/. # SilverBullet: the admin-only EDITOR for the vault /notes/ publishes.
# Deliberately NO prefix-strip rewrite, unlike every other proxied app # Deliberately NO prefix-strip rewrite, unlike every other proxied app
# here. SilverBullet is a PWA told its own base path via SB_URL_PREFIX=/sb, # here. SilverBullet is a PWA told its own base path via SB_URL_PREFIX=/sb,
# and its service worker scope and asset URLs are built from that. Strip # and its service worker scope and asset URLs are built from that. Strip
@@ -506,11 +551,11 @@ http {
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
# ---- Admin gate for /hasura/ and /notes/ ------------------------------ # ---- Admin gate (/hasura/, /sb/, /radio/admin/, /uploads/private/) ----
# `auth_request` makes nginx fire a subrequest here before serving the # `auth_request` makes nginx fire a subrequest here before serving the
# real one; a 2xx lets it through, 401/403 triggers error_page -> # real one; a 2xx lets it through, 401/403 triggers error_page ->
# @auth_denied -> redirect to the SPA login. This puts the Go backend's # @auth_denied -> redirect to the SPA login. This puts the Go backend's
# session cookie in front of two services that have no idea it exists. # session cookie in front of services that have no idea it exists.
# internal; - unreachable from outside, subrequest only. # internal; - unreachable from outside, subrequest only.
# proxy_pass_request_body off + Content-Length "" # proxy_pass_request_body off + Content-Length ""
# - the subrequest must not replay the # - the subrequest must not replay the
+22 -8
View File
@@ -28,14 +28,14 @@
set $upstream_icecast http://$ICECAST_HOST:$ICECAST_PORT; set $upstream_icecast http://$ICECAST_HOST:$ICECAST_PORT;
set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT; set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT;
set $upstream_hasura http://$HASURA_HOST:$HASURA_PORT; set $upstream_hasura http://$HASURA_HOST:$HASURA_PORT;
set $upstream_quartz http://$QUARTZ_HOST:$QUARTZ_PORT;
set $upstream_silverbullet http://$SILVERBULLET_HOST:$SILVERBULLET_PORT; set $upstream_silverbullet http://$SILVERBULLET_HOST:$SILVERBULLET_PORT;
set $upstream_silverbullet_public http://$SILVERBULLET_PUBLIC_HOST:$SILVERBULLET_PUBLIC_PORT;
set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT; set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT;
# PRIVATE attachments (admin-only). Attachments on *private* chat # PRIVATE attachments (admin-only). Attachments on *private* chat
# messages are written by the backend to /backend/uploads/private/ and # messages are written by the backend to /backend/uploads/private/ and
# must not be readable by the public, so this subpath is put behind the # must not be readable by the public, so this subpath is put behind the
# same admin `auth_request` used for /hasura/ and /notes/. nginx picks # same admin `auth_request` used for /hasura/ and /sb/. nginx picks
# the LONGEST matching prefix location, so this block wins over the # the LONGEST matching prefix location, so this block wins over the
# public /uploads/ block below for /uploads/private/* regardless of # public /uploads/ block below for /uploads/private/* regardless of
# ordering. Same three hardening headers as the public block, because # ordering. Same three hardening headers as the public block, because
@@ -118,7 +118,7 @@
# surface — kick sources, change metadata — protected only by the # surface — kick sources, change metadata — protected only by the
# icecast admin password, and it was reachable from the public # icecast admin password, and it was reachable from the public
# internet through this proxy. Put it behind the same admin # internet through this proxy. Put it behind the same admin
# `auth_request` as /hasura/ and /notes/ so an admin session cookie is # `auth_request` as /hasura/ and /sb/ so an admin session cookie is
# required before the request ever reaches icecast. Longest-prefix # required before the request ever reaches icecast. Longest-prefix
# matching means this wins over /radio/ below; listener traffic # matching means this wins over /radio/ below; listener traffic
# (/radio/$ICECAST_MOUNT, /radio/status.xsl) is untouched. # (/radio/$ICECAST_MOUNT, /radio/status.xsl) is untouched.
@@ -177,11 +177,25 @@
return 301 /notes/; return 301 /notes/;
} }
# PUBLIC notes viewer (read-only SilverBullet). The deny blocks are
# the privacy boundary: SB_SPACE_IGNORE hides files from the list but
# NOT from a direct /.fs/ fetch, a page URL (server-rendered), or
# /.fs/.git/. Full explanation in nginx.conf.template; keep the two in
# step.
location ~* ^/notes/(.*/)?(private|templates)(/|$) {
return 404;
}
location ~ ^/notes/.+/\. {
return 404;
}
location ^~ /notes/.revisions {
return 404;
}
location /notes/ { location /notes/ {
auth_request /internal/auth/admin-validate; proxy_pass $upstream_silverbullet_public;
error_page 401 403 = @auth_denied;
rewrite ^/notes/(.*)$ /$1 break;
proxy_pass $upstream_quartz;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "upgrade";
@@ -195,7 +209,7 @@
return 301 /sb/; return 301 /sb/;
} }
# SilverBullet: the editor for the same vault quartz renders at /notes/. # SilverBullet: the admin-only EDITOR for the vault /notes/ publishes.
# Deliberately NO prefix-strip rewrite, unlike every other proxied app # Deliberately NO prefix-strip rewrite, unlike every other proxied app
# here. SilverBullet is a PWA told its own base path via SB_URL_PREFIX=/sb, # here. SilverBullet is a PWA told its own base path via SB_URL_PREFIX=/sb,
# and its service worker scope and asset URLs are built from that. Strip # and its service worker scope and asset URLs are built from that. Strip
+6
View File
@@ -1,6 +1,12 @@
# ============================================================================= # =============================================================================
# Quartz image — builds the Obsidian notes site. # Quartz image — builds the Obsidian notes site.
# #
# STATUS: RETIRED (not live). /notes/ is now served by the read-only
# silverbullet-public service; this directory is no longer referenced by
# docker-compose.yml or nginx. Kept for reference / rollback: restoring it means
# re-adding the service, the QUARTZ_* vars to nginx/entrypoint.sh's allow-list,
# and pointing /notes/ back at it (with the prefix-strip rewrite Quartz needs).
#
# HOW THE SOURCE IS OBTAINED: Quartz is not an npm package you depend on, it is # HOW THE SOURCE IS OBTAINED: Quartz is not an npm package you depend on, it is
# an application you clone and configure. So the image `git clone`s the # an application you clone and configure. So the image `git clone`s the
# upstream repo at build time, which is why `git` is installed. --depth 1 # upstream repo at build time, which is why `git` is installed. --depth 1