Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# THIS ENV FILE EXAMPLE ONLY FOR DOCKER COMPOSE
# SEE https://docs.docker.com/compose/environment-variables/#the-env-file
# Set a private instance secret (at least 32 characters for V2). Preserve an existing value.
# Required: a private JWT secret of at least 32 characters. Preserve an existing value.
JWT_SECRET=
ALLOWED_ORIGINS=innei.ren,www.innei.ren

# Must be 64 hexadecimal characters. Keep the existing key when upgrading.
# Required: 64 hexadecimal characters. Keep the existing key when upgrading.
# New instances only: openssl rand -hex 32; persist this value before starting.
ENCRYPT_KEY=
# Temporary legacy plaintext escape hatch; v18 will require encryption.
ENCRYPT_ENABLE=false

# Comma-separated HTTPS origins that mx-core may contact for Push Relay.
MX_PUSH_RELAY_ORIGINS=
Expand All @@ -22,6 +21,3 @@ PG_URL=
# Throttle
THROTTLE_TTL=10
THROTTLE_LIMIT=20

# Enable only after every replica has the compatible secret reader; see docs/security-secret-storage.md
MX_SECRET_STORAGE_V2=false
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test
env:
JWT_SECRET: test-docker-jwt-secret-at-least-32-characters
MX_ENCRYPT_KEY: '593f62860255feb0a914534a43814b9809cc7534da7f5485cd2e3d3c8609acab'
run: |
bash ./scripts/workflow/test-docker.sh
sudo rm -rf ./data
Expand Down Expand Up @@ -121,7 +124,8 @@ jobs:
PG_DATABASE: mx_core
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379
JWT_SECRET: test-bundle-server-jwt-secret
JWT_SECRET: test-bundle-server-jwt-secret-at-least-32-characters
MX_ENCRYPT_KEY: '593f62860255feb0a914534a43814b9809cc7534da7f5485cd2e3d3c8609acab'
MIGRATIONS_DIR: ${{ github.workspace }}/apps/core/src/database/migrations

e2e:
Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ jobs:
PG_DATABASE: mx_core
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379
JWT_SECRET: test-bundle-server-jwt-secret
JWT_SECRET: test-bundle-server-jwt-secret-at-least-32-characters
MX_ENCRYPT_KEY: '593f62860255feb0a914534a43814b9809cc7534da7f5485cd2e3d3c8609acab'
MIGRATIONS_DIR: ${{ github.workspace }}/apps/core/src/database/migrations
run: |
bash scripts/workflow/test-server.sh
Expand All @@ -106,7 +107,7 @@ jobs:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body_path: apps/core/RELEASE_NOTES.md
prerelease: ${{ contains(fromJSON('["alpha", "beta"]'), github.ref_name) }}
prerelease: ${{ contains(github.ref_name, '-') }}
files: release-linux.zip


Expand Down Expand Up @@ -149,6 +150,9 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}

- name: Test
env:
JWT_SECRET: test-docker-jwt-secret-at-least-32-characters
MX_ENCRYPT_KEY: '593f62860255feb0a914534a43814b9809cc7534da7f5485cd2e3d3c8609acab'
run: |
bash ./scripts/workflow/test-docker.sh
sudo rm -rf ./data
Expand Down Expand Up @@ -214,13 +218,15 @@ jobs:
uses: docker/metadata-action@v6
with:
images: ${{ env.IMAGE }}
flavor: |
latest=false
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}},enable=${{ !contains(github.ref_name, '-') }}
type=semver,pattern={{major}},enable=${{ !contains(github.ref_name, '-') }}
type=sha
type=raw,value=latest
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }}

- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
Expand All @@ -236,6 +242,7 @@ jobs:
name: Trigger Dokploy Redeploy
runs-on: ubuntu-latest
needs: merge
if: ${{ !contains(github.ref_name, '-') }}
env:
DOKPLOY_WEBHOOK_URL: ${{ secrets.DOKPLOY_WEBHOOK_URL }}
steps:
Expand Down
67 changes: 67 additions & 0 deletions apps/admin/src/api/options.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { afterEach, describe, expect, it, vi } from 'vitest'

import { type ConfigFormSchema, getAllOptions } from './options'

afterEach(() => vi.unstubAllGlobals())

describe('settings values and form schema', () => {
it('restores declared acronym keys after wire camelization so fields display and save the existing values', async () => {
vi.stubGlobal(
'fetch',
vi.fn(
async () =>
new Response(
JSON.stringify({
data: {
comment_upload_options: {
single_file_size_mb: 7,
reader_total_active_bytes_mb: 70,
enable: true,
},
opaque: { customField: { APIKey: 'preserved' } },
},
}),
{ status: 200, headers: { 'content-type': 'application/json' } },
),
),
)
const schema: ConfigFormSchema = {
title: 'Settings',
defaults: {},
groups: [
{
key: 'storage',
title: 'Storage',
description: '',
icon: 'database',
sections: [
{
key: 'commentUploadOptions',
title: 'Comment uploads',
fields: [
{
key: 'singleFileSizeMB',
title: 'File limit',
ui: { component: 'number' },
},
{
key: 'readerTotalActiveBytesMB',
title: 'Total limit',
ui: { component: 'number' },
},
],
},
],
},
],
}
expect(await getAllOptions(schema)).toEqual({
commentUploadOptions: {
singleFileSizeMB: 7,
readerTotalActiveBytesMB: 70,
enable: true,
},
opaque: { customField: { APIKey: 'preserved' } },
})
})
})
34 changes: 32 additions & 2 deletions apps/admin/src/api/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,38 @@ export interface UpdateOwnerData {
username?: string
}

export function getAllOptions() {
return getJson<SystemOptions>('/options')
function restoreFormFieldKeys(
value: unknown,
fields: ConfigFormField[],
): unknown {
if (!value || typeof value !== 'object' || Array.isArray(value)) return value
const source = value as Record<string, unknown>
const keys = new Map(
Object.keys(source).map((key) => [key.toLowerCase(), key]),
)
const result = { ...source }
for (const field of fields) {
const key = keys.get(field.key.toLowerCase())
if (key === undefined) continue
result[field.key] = field.fields?.length
? restoreFormFieldKeys(source[key], field.fields)
: source[key]
if (key !== field.key) delete result[key]
}
return result
}

export async function getAllOptions(schema?: ConfigFormSchema) {
const options = await getJson<SystemOptions>('/options')
if (!schema) return options
const result = { ...options }
for (const group of schema.groups)
for (const section of group.sections)
result[section.key] = restoreFormFieldKeys(
options[section.key],
section.fields,
)
return result
}

export function getFormSchema() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function SystemSettings(props: {

const optionsQuery = useQuery({
enabled: Boolean(props.schema),
queryFn: getAllOptions,
queryFn: () => getAllOptions(props.schema),
queryKey: adminQueryKeys.settings.options(),
})

Expand Down
26 changes: 14 additions & 12 deletions apps/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pnpm test:watch # watch mode

| Variable | Description | Default |
|----------|-------------|---------|
| `JWT_SECRET` | Secret for JWT signing | Required |
| `JWT_SECRET` | Explicit secret for JWT signing and OAuth encryption, at least 32 characters | Required |
| `ALLOWED_ORIGINS` | CORS allowed origins (comma-separated) | — |
| `PG_URL` | Full PostgreSQL connection string | — |
| `PG_HOST` | PostgreSQL host | `127.0.0.1` |
Expand All @@ -238,15 +238,18 @@ pnpm test:watch # watch mode
| `REDIS_PORT` | Redis port | `6379` |
| `REDIS_PASSWORD` | Redis password | — |
| `SNOWFLAKE_WORKER_ID` | Snowflake ID worker ID (0–1023) | Required |
| `ENCRYPT_ENABLE` | Enable field encryption; `false` is a temporary v17 plaintext escape hatch. Encryption is required starting in v18 | `false` |
| `ENCRYPT_KEY` | 64-char hex encryption key | — |
| `MX_SECRET_STORAGE_V2` | Enable new secret formats after all replicas are upgraded; see [rollout guide](../../docs/security-secret-storage.md) | `false` |
| `ENCRYPT_KEY` / `MX_ENCRYPT_KEY` | Required explicit 64-char hex field key; preserve the existing key | — |
| `ENCRYPT_ENABLE` / `MX_ENCRYPT_ENABLE` / `MX_SECRET_STORAGE_V2` | Deprecated: remove these flags. Old true values are ignored; false values refuse startup | — |
| `THROTTLE_TTL` | Rate limit window (seconds) | `10` |
| `THROTTLE_LIMIT` | Max requests per window | `100` |
| `PORT` | Server port | `2333` |
| `TZ` | Timezone | `Asia/Shanghai` |
| `DISABLE_CACHE` | Disable Redis caching | `false` |

In v18, run the mandatory configuration data migration via `node migrate.mjs` before startup, after stopping all old replicas/background writers. Runtime configuration accepts only the current schema; retired sections and unknown declared fields are rejected. See the [migration guide](../../docs/v18-preparation.md).

Field encryption and V2 writes are mandatory; `JWT_SECRET` must have at least 32 characters. See the [upgrade guide](../../docs/v18-preparation.md) before deploying to an existing instance.

For managed Redis providers such as Upstash, pass the provider URI as
`REDIS_CONNECTION_STRING=rediss://user:password@host:port`. The `rediss://`
scheme enables TLS. If the provider exposes the same URI as `REDIS_URL`, it is
Expand Down Expand Up @@ -300,16 +303,15 @@ Inspired in part by [nodepress](https://github.com/surmon-china/nodepress).

Since 2021-08-31.

## Preparing for v18 with v17.1.0
## Upgrading to v18

Core v17.1.0 adds standalone `upgrade:check`, `upgrade:prepare` and
`upgrade:rotate-jwt` tooling. Deploy this release to every replica before
preparing existing data; v17.0.5 and earlier do not contain these commands.
v17 behavior remains compatible, including legacy GET actions and SDK 5.x
signatures. No columns are dropped in this phase. Minimum client versions for
v18 will be recorded after separate release verification.
v18 ships standalone `upgrade:check` and `upgrade:rotate-jwt` tooling.
Configuration, credential and metric backfills run through the mandatory
release-phase `migrate` command. Upgrade from v17.1.0. Legacy GET actions and
SDK 5.x signatures remain, while v18 requires encryption and canonical
configuration. No columns are dropped in this release.

See the [preparation runbook](../../docs/v18-preparation.md) for read-only
diagnostics, dry-run/transactional preparation, original-secret requirements
diagnostics, release-phase migration, original-secret requirements
and offline JWT rotation. Do not change an existing encryption key or JWT
to fix decryption failures.
2 changes: 1 addition & 1 deletion apps/core/ecosystem.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
watch: false,
instances: cpuLen,
max_memory_restart: '520M',
args: '--color --encrypt_enable',
args: '--color',
env: {
NODE_ENV: 'production',
NODE_PATH: nodePath,
Expand Down
3 changes: 2 additions & 1 deletion apps/core/ecosystem.dev.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { execSync } = require('node:child_process')

const nodePath = execSync(`npm root --quiet -g`, { encoding: 'utf-8' }).split(
'\n',
)[0]
Expand All @@ -13,7 +14,7 @@ module.exports = {
watch: false,
instances: 2,
max_memory_restart: '220M',
args: '--color --encrypt_enable',
args: '--color',
env: {
NODE_ENV: 'development',
NODE_PATH: nodePath,
Expand Down
4 changes: 0 additions & 4 deletions apps/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"prebuild": "rimraf dist",
"build": "npm run bundle",
"dev": "cross-env NODE_ENV=development nodemon --signal SIGKILL --watch src --ext ts,json --exec \"vite-node src/dev.ts\"",
"dev:encrypt": "npm run dev -- --encrypt_enable --encrypt_key=33b9405ac49f63ef4ccbf6b338aeeff8152e844d942ef22278abbec2b1f93b5e",
"migrate": "vite-node src/migrate.ts",
"migrate:secrets": "cross-env MX_SECRET_STORAGE_V2=1 MX_MIGRATE_SECRETS=1 vite-node src/app-migrate.ts",
"migrate:app": "cross-env NODE_ENV=development vite-node src/app-migrate.ts",
"lint:migrations": "tsx --tsconfig tsconfig.json scripts/lint-migrations.ts",
"openapi:export": "vite-node scripts/export-openapi.ts",
Expand Down Expand Up @@ -48,7 +46,6 @@
"docs": "npx @compodoc/compodoc -p tsconfig.json -s -d docs",
"publish": "bump",
"upgrade:check": "vite-node --config vite.upgrade.config.ts src/upgrade.ts check",
"upgrade:prepare": "vite-node --config vite.upgrade.config.ts src/upgrade.ts prepare",
"upgrade:rotate-jwt": "vite-node --config vite.upgrade.config.ts src/upgrade.ts rotate-jwt"
},
"bump": {
Expand Down Expand Up @@ -136,7 +133,6 @@
"mime-types": "^3.0.2",
"mkdirp": "^3.0.1",
"nanoid": "6.0.2",
"node-machine-id": "1.1.12",
"nodemailer": "10.2.1",
"object-scan": "^20.0.4",
"octokit": "^5.0.5",
Expand Down
2 changes: 0 additions & 2 deletions apps/core/src/app.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ export const DEBUG_MODE = {
httpRequestVerbose: false,
}

export const SECRET_STORAGE_V2 = true
export const ENCRYPT = {
key: '593f62860255feb0a914534a43814b9809cc7534da7f5485cd2e3d3c8609acab',
enable: true,
}

export const THROTTLE_OPTIONS = {
Expand Down
Loading
Loading