docs: fix example secrets

This commit is contained in:
2026-09-26 15:26:00 -04:00
parent b304d8ac9f
commit ee8b8f239d
5 changed files with 77 additions and 28 deletions
+32 -10
View File
@@ -26,15 +26,33 @@ The easiest way to run SharpbinV3 is using Docker Compose.
git clone https://github.com/whoswhip/Sharpbin.git
```
3. Run the following command in the root directory:
3. In the repository root, copy `backend.env.example` to `backend.env` and `frontend.env.example` to `frontend.env`.
4. Replace the secret placeholders and configure your domain and Turnstile keys. Set `ORIGIN` to the public frontend URL, including the scheme. For local Docker testing, use `ORIGIN=http://localhost:5173`, `Domain=localhost:5173`, `Https=false`, and `AllowedCorsOrigins__0=http://localhost:5173`.
5. Run the following command in the root directory:
```bash
docker-compose up -d
docker compose up -d --build
```
### Configuration
You can configure Sharpbin using environment variables or `appsettings.json`. When using Docker Compose, these can be set in the `docker-compose.yml` file.
Configure the backend in `backend.env` and the frontend in `frontend.env` when using Docker Compose. The backend also loads `appsettings.json`, with environment variables taking precedence.
Compose explicitly sets `ConnectionStrings__DefaultConnection`, `DATA_PROTECTION_KEY_PATH`, and the frontend's `VITE_API_URL`. These override values from the environment files; change `docker-compose.yml` to override them.
The example secrets are placeholders, not secure defaults. Generate a separate secret for JWT signing, API-key hashing, and view hashing, plus one shared internal API key. This command generates a 64-character random hex value; run it once for each secret:
```bash
docker run --rm node:24-alpine node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
```
or use openSSL:
```bash
openssl rand -hex 32
```
Set the same shared value in `PasteSettings__View_Internal_API_Key` in `backend.env` and `VIEW_INTERNAL_API_KEY` in `frontend.env`. Keep generated secrets across restarts and updates. Changing the API-key HMAC secret invalidates existing API keys.
> When configuring via `appsettings.json` instead of for example `ConnectionStrings__DefaultConnection` it would be:
@@ -47,9 +65,10 @@ You can configure Sharpbin using environment variables or `appsettings.json`. Wh
#### Backend (SharpbinV3.Server)
- `Domain`: The domain your instance of Sharpbin will be hosted at (e.g., example.com)
- `Https`: Whether or not your instance is behind https. Used when sendings emails.
- `Https`: Whether the public instance uses HTTPS. Used when generating email links; this does not enable TLS on the server.
- `AllowedCorsOrigins__0`: An allowed browser origin for the backend API (e.g., `https://example.com`). Use numbered entries for additional origins.
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=/app/data/sharpbin.db`).
- `JwtSettings__Secret`: A secure string used for signing JWT tokens.
- `JwtSettings__Secret`: A random secret of 32-128 characters used for signing JWT tokens.
- `AuthSettings__CF_Turnstile_SecretKey`: Your Cloudflare Turnstile secret key.
- `AuthSettings__CF_Turnstile_SiteKey`: Your Cloudflare Turnstile site key.
- `AuthSettings__Registration_Enabled`:**true**: Enables/disables registration.
@@ -60,14 +79,17 @@ You can configure Sharpbin using environment variables or `appsettings.json`. Wh
- `PasteSettings__MaxPasteSizeInBytes`:**1_048_576** (1MB): Max Paste Size set in bytes.
- `PasteSettings__EnablePasteCompression`:**true**: Enables/Disables server-side paste compression.
- `PasteSettings__RequiresVerification`:**true**: Enables/Disables CAPTCHA verification when creating pastes.
- `PasteSettings__View_HMAC_Secret`: Required to securely hash viewer identifiers
- `PasteSettings__View_Internal_API_Key`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Match the frontend's `VIEW_INTERNAL_API_KEY`.
#### Frontend (SharpbinV3.Client)
- `VITE_API_URL`: The URL of the backend API (e.g., `http://localhost:8080`).
- `VITE_ALLOWED_HOSTS`: A comma separated list of allowed hosts (e.g., `localhost,sharpbin.cc`)
- `VIEW_INTERNAL_API_KEY`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `VITE_API_URL`: The backend URL reachable from the frontend server. Defaults to `http://localhost:5050`; Compose overrides it with `http://backend:8080`. Browser requests use the frontend's `/api` proxy.
- `ORIGIN`: The public frontend URL, including its scheme (e.g., `https://example.com`). Used by the production Node server; see [SvelteKit's Node adapter documentation](https://svelte.dev/docs/kit/adapter-node#ORIGIN-PROTOCOL_HEADER-HOST_HEADER-and-PORT_HEADER).
- `VITE_ALLOWED_HOSTS`: A comma-separated list used only by Vite dev/preview (e.g., `localhost,sharpbin.cc`). Export it in the shell before starting Vite; the config reads `process.env` directly. It does not configure production host restrictions.
- `VIEW_INTERNAL_API_KEY`: The production frontend's shared view-recording key. Falls back to `View_HMAC_Internal_API_Key` if unset. The frontend does not read `PasteSettings__View_Internal_API_Key`.
When `NODE_ENV=development`, the frontend uses a fixed development-only internal key matching the backend's checked-in development configuration and ignores both environment key names. See the [client README](SharpbinV3.Client/README.md) for development and standalone production setup.
The frontend will be accessible at http://localhost:5173.
+23 -5
View File
@@ -6,7 +6,7 @@ This is the SvelteKit frontend for SharpbinV3.
### Prerequisites
- Node.js (v20 or newer recommended)
- Node.js 24
- npm
### Installation
@@ -19,11 +19,12 @@ npm install
### Environment Configuration
The frontend requires an environment variable to point to the backend API. Create a `.env` file in this directory or set the variable in your environment:
The frontend defaults to the backend at `http://localhost:5050`. SvelteKit loads `.env` files during development, but `vite.config.ts` reads shell environment variables directly for its proxy and allowed hosts:
- `VITE_API_URL`: The URL of the backend API (e.g., `http://localhost:8080`).
- `VITE_ALLOWED_HOSTS`: A comma separated list of allowed hosts (e.g., `localhost,sharpbin.whoswhip.dev`)
- `VIEW_INTERNAL_API_KEY`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `VITE_API_URL`: The backend URL reachable from the frontend server. Export this in the shell when changing the development backend URL so the Vite proxy and server-side requests use the same value.
- `VITE_ALLOWED_HOSTS`: A comma-separated list of hosts for Vite dev/preview. Export this in the shell before starting Vite. It does not configure the production Node server.
In development, the frontend uses a fixed internal view-recording key matching `appsettings.Development.json`. It ignores `VIEW_INTERNAL_API_KEY` and `View_HMAC_Internal_API_Key` while `NODE_ENV=development`.
### Running in Development
@@ -35,6 +36,23 @@ npm run dev
The frontend will be available at http://localhost:5173.
### Running in Production
Docker Compose loads `frontend.env` and runs the built Node server on port 5173. Set these runtime variables:
- `VITE_API_URL`: Backend URL. Compose sets `http://backend:8080` directly, overriding `frontend.env`.
- `ORIGIN`: Public frontend URL, such as `https://example.com` or `http://localhost:5173` for local Docker testing.
- `VIEW_INTERNAL_API_KEY`: Same generated value as the backend's `PasteSettings__View_Internal_API_Key`. If unset, the frontend reads `View_HMAC_Internal_API_Key`; it does not read the backend setting name.
For a standalone Node deployment, `.env` is not loaded automatically. Build the frontend, then load your environment file explicitly:
```bash
npm run build
node --env-file=.env build
```
Set `PORT=5173` in that file to use the same port as Docker; the Node adapter otherwise defaults to port 3000. See the [Node adapter documentation](https://svelte.dev/docs/kit/adapter-node#Environment-variables) for runtime configuration.
## Script Reference
- `npm run dev`: Start the Vite development server.
+7 -5
View File
@@ -13,14 +13,16 @@ This is the backend API for SharpbinV3, built with ASP.NET Core and Entity Frame
The server configuration is managed in `appsettings.json`. For development, ensure you have set the following in `appsettings.Development.json` or as environment variables:
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=/app/data/sharpbin.db`).
- `JwtSettings__Secret`: A secure string used for signing JWT tokens.
- `PasteSettings__View_HMAC_Secret`: Required to securely hash viewer identifiers
- `PasteSettings__View_Internal_API_Key`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=sharpbin.db` locally). Compose sets `Data Source=/app/data/sharpbin.db` directly.
- `JwtSettings__Secret`: A random secret of 32–128 characters used for signing JWT tokens.
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Match the production frontend's `VIEW_INTERNAL_API_KEY`.
The development frontend uses a fixed internal key matching the checked-in `appsettings.Development.json`. Changing only the backend key will break development view recording. Use generated secrets for deployment; see the [root configuration guide](../README.md#configuration).
### Database Migrations
Apply the database migrations to initialize the SQLite database:
The backend applies database migrations automatically on startup. To apply them manually before starting it:
```bash
dotnet ef database update
+7 -4
View File
@@ -1,23 +1,26 @@
# Replace every replace_with_ value before running. See README.md for secret generation.
# Use a different random secret for each setting, except the shared frontend/backend key.
# Required Misc. Variables
Domain=example.com
Https=true
AllowedCorsOrigins__0=https://example.com
JwtSettings__Secret=totally_random_and_secure_string
JwtSettings__Secret=replace_with_a_unique_random_jwt_secret_before_running
ConnectionStrings__DefaultConnection=Data Source=/app/data/sharpbin.db
# Auth Settings
# These Turnstile keys are for testing. Use your own site and secret keys in production.
AuthSettings__CF_Turnstile_SecretKey=1x0000000000000000000000000000000AA
AuthSettings__CF_Turnstile_SiteKey=3x00000000000000000000FF
AuthSettings__Registration_Enabled=true
AuthSettings__Admins_Require_2FA=true
AuthSettings__API_Key_HMAC_Secret=another_random_and_secure_string
AuthSettings__API_Key_HMAC_Secret=replace_with_a_unique_random_api_key_hmac_secret_before_running
# Paste Settings
PasteSettings__MaxTitleLength=500
PasteSettings__MaxPasteSizeInBytes=1048576
PasteSettings__EnablePasteCompression=true
PasteSettings__RequiresVerification=true
PasteSettings__View_HMAC_Secret=random_minimum_32_char_string
PasteSettings__View_HMAC_Secret=replace_with_a_unique_random_view_hmac_secret_before_running
# Used so that views are only counted from the frontend
# Must be the same on both the frontend and backend environment
PasteSettings__View_Internal_API_Key=another_random_minimum_32_char_string
PasteSettings__View_Internal_API_Key=replace_with_the_same_random_internal_api_key_in_both_files
+7 -3
View File
@@ -1,6 +1,10 @@
# Docker Compose sets this URL directly; change docker-compose.yml to override it.
VITE_API_URL=http://backend:8080
VITE_ALLOWED_HOSTS=localhost,example.com
# Public frontend URL, including the scheme. Use http://localhost:5173 for local Docker testing.
ORIGIN=https://example.com
# VITE_ALLOWED_HOSTS only affects Vite dev/preview, not the production Node server.
# Used so that views are only counted from the frontend
# Must be the same on both the frontend and backend environment
# The frontend will also try to parse 'PasteSettings__View_Internal_API_Key'
VIEW_INTERNAL_API_KEY=another_random_minimum_32_char_string
# Production fallback: View_HMAC_Internal_API_Key (not PasteSettings__View_Internal_API_Key).
# Replace this placeholder with the same generated value as the backend setting.
VIEW_INTERNAL_API_KEY=replace_with_the_same_random_internal_api_key_in_both_files