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
45 changes: 45 additions & 0 deletions .github/workflows/sqlpad-security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: SQLPad security runtime
on:
workflow_dispatch:
pull_request:
paths:
- 'ops/sqlpad/**'
- '.github/workflows/sqlpad-security.yml'
push:
branches: [main]
paths:
- 'ops/sqlpad/**'
- '.github/workflows/sqlpad-security.yml'
permissions:
contents: read
jobs:
build-and-test:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- name: Build, test, and audit immutable runtime
run: |
chmod 600 ops/sqlpad/{server,client}/package*.json
docker build --progress=plain -t ossinsight-sqlpad:security ops/sqlpad
- name: Check unprivileged runtime and native SQLite
run: |
test "$(docker image inspect --format '{{.Config.User}}' ossinsight-sqlpad:security)" = node
docker run --rm --network none --read-only --entrypoint node ossinsight-sqlpad:security -e "require('fs').accessSync('/usr/app/package.json',require('fs').constants.R_OK);const s=require('sqlite3');const d=new s.Database(':memory:');d.get('SELECT sqlite_version() AS v',(e,r)=>{if(e)throw e;if(!r.v.startsWith('3.52.'))throw Error('Unexpected SQLite version');console.log(r);d.close()})"
- name: Test offline connection-key migration and rollback
run: |
docker run --rm --network none --read-only --tmpfs /tmp:rw,nosuid,nodev,size=64m,mode=1777 --mount "type=bind,src=${{ github.workspace }}/ops/sqlpad,dst=/usr/app/maintenance,readonly" --entrypoint node ossinsight-sqlpad:security --test /usr/app/maintenance/rekey-connections.test.mjs
- name: Boot the actual server with a read-only root filesystem
run: |
name=sqlpad-security-smoke
trap 'docker logs "$name"; docker rm -f "$name"' EXIT
docker run -d --name "$name" --network none --read-only --cap-drop ALL --security-opt no-new-privileges --tmpfs /tmp:rw,nosuid,nodev,size=64m,mode=1777 --tmpfs /var/lib/sqlpad:rw,nosuid,nodev,size=64m,mode=0700,uid=1000,gid=1000 ossinsight-sqlpad:security
ready=false
for attempt in $(seq 1 30); do
if docker exec "$name" node -e "(async()=>{const r=await fetch('http://127.0.0.1:3000/');if(r.status!==200||!(await r.text()).includes('SQLPad'))process.exit(1);const q=await fetch('http://127.0.0.1:3000/api/queries');if(![401,403].includes(q.status))process.exit(1)})().catch(()=>process.exit(1))"; then
ready=true
break
fi
sleep 1
done
test "$ready" = true
3 changes: 3 additions & 0 deletions ops/sqlpad/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/node_modules
**/npm-debug.log
**/.env*
32 changes: 32 additions & 0 deletions ops/sqlpad/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG NODE_IMAGE=node:24.22.2-bookworm-slim@sha256:a43f7fc3e52e87d12a905f46eea0275def84ca8f2981a5b53fed44d7fb398ee0
FROM ${NODE_IMAGE} AS build
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl patch python3 make g++ && rm -rf /var/lib/apt/lists/*
WORKDIR /src
RUN curl --fail --location --silent --show-error https://codeload.github.com/sqlpad/sqlpad/tar.gz/ab1f0c03269f0178b9449d34505ce3462271f340 -o /tmp/sqlpad.tar.gz && printf '%s /tmp/sqlpad.tar.gz\n' 'f89a0f541bc20e771f5f9fc970bc2678c9fbfce39a918057664b4ea11b0c3243' | sha256sum --check - && tar -xzf /tmp/sqlpad.tar.gz --strip-components=1 && rm /tmp/sqlpad.tar.gz
COPY security.patch /tmp/security.patch
RUN patch -p1 < /tmp/security.patch
COPY server/package*.json ./server/
COPY client/package*.json ./client/
COPY audit-check.mjs /src/audit-check.mjs
RUN npm ci --prefix server --ignore-scripts --omit=optional --no-audit --no-fund && npm_config_build_from_source=true npm_config_jobs=2 npm rebuild sqlite3 --prefix server
RUN SQLPAD_BACKEND_DB_URI='' AWS_EC2_METADATA_DISABLED=true npm test --prefix server
RUN npm prune --prefix server --omit=dev --omit=optional --ignore-scripts --no-audit --no-fund
RUN (npm audit --prefix server --omit=dev --json > /src/server-audit.json || true) && node audit-check.mjs server server-audit.json
RUN npm ci --prefix client --legacy-peer-deps --no-audit --no-fund && npm run build --prefix client
RUN (npm audit --prefix client --omit=dev --json > /src/client-audit.json || true) && node audit-check.mjs client client-audit.json
RUN rm -rf server/public server/test && mkdir server/public && cp -a client/build/. server/public/

FROM ${NODE_IMAGE} AS runtime
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /usr/app
COPY --from=build /src/server ./
# Private build contexts may supply mode-0600 manifests; runtime code is public.
RUN mv /usr/app/public/index.html /usr/app/public/index-template.html && chmod -R a+rX /usr/app
COPY --from=build /src/LICENSE.md /usr/share/doc/sqlpad/LICENSE
COPY --from=build /src/server-audit.json /src/client-audit.json /usr/share/doc/sqlpad/
ENV NODE_ENV=production SQLPAD_DB_PATH=/var/lib/sqlpad SQLPAD_PORT=3000
LABEL org.opencontainers.image.title="SQLPad OSSInsight security runtime" org.opencontainers.image.version="7.5.7+ossinsight.20261104" org.opencontainers.image.source="https://github.com/pingcap/ossinsight" org.opencontainers.image.revision="upstream:ab1f0c03269f0178b9449d34505ce3462271f340"
USER node
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 CMD node -e "fetch('http://127.0.0.1:3000/api/app').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
CMD ["node", "/usr/app/server.js"]
37 changes: 37 additions & 0 deletions ops/sqlpad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# OSSInsight SQLPad runtime

This builds SQLPad 7.5.7 on Node 24.22.2 with patched dependencies, replacing the legacy SQLPad container. SQLPad upstream is archived; this recipe pins its source commit, archive checksum, Linux amd64 Node image digest, and both npm dependency graphs.

Build from the repository root:

```sh
docker build -t ossinsight/sqlpad:security-20261104 ops/sqlpad
```

The build runs the upstream server suite plus region-validation regression tests, the client TypeScript check and production build, and production dependency audits. ODBC remains optional and excluded, as in the standard upstream deployment. Native SQLite is compiled against the same base image used at runtime. The runtime runs as uid 1000 and includes the audit reports under `/usr/share/doc/sqlpad`.

The client audit has no findings. The server audit permits only AWS's low-severity informational advisory [GHSA-j965-2qgj-vjmq](https://github.com/advisories/GHSA-j965-2qgj-vjmq), whose documented input-sanitization mitigation is applied before all Athena operations. All other findings, audit failures, and incomplete reports fail the build. AWS SDK v2 remains unsupported upstream; migrating the unused Athena driver to SDK v3 remains a maintenance consideration.

For rollout, first take a consistent SQLite backup and a private copy of the complete data directory. Test migration on that copy, preserving user/query/connection identities and password hashes, and verify authenticated MySQL connectivity with a read-only query. Never start a staging container against the live data directory. Keep credentials and encryption keys in private host files, outside this repository and image.

Stop the old container before taking the final copy. Use the migrated copy for the replacement; retain the old container and its original data as the rollback pair. Bind staging only to loopback and production only to the existing private origin address. Run with a read-only root filesystem, writable data mount and `/tmp` tmpfs, dropped capabilities, `no-new-privileges`, and bounded memory/CPU. Confirm login, saved queries, database connectivity, anonymous-access rejection, and container health before disabling the old container's restart policy. Rollback requires stopping the replacement and restarting the old container with its original data; do not point the old image at a migrated database.

To update dependencies, edit the manifests and regenerate their npm locks with scripts disabled (the client retains upstream's legacy peer-dependency resolution). Review changes and rebuild the full image. Do not use upstream's Yarn Dockerfile: it does not apply these npm overrides or audits.


## Replacing the shared default encryption key

`rekey-connections.mjs` re-encrypts connection data inside one SQLite transaction while preserving its plaintext and all unrelated metadata. It defaults to a dry run, verifies the expected connection count, and rolls back every row if any decryption or update fails. Tests cover ciphertext preservation in dry runs, successful rekeying, preservation of user password hashes and timestamps, corrupt later rows, wrong source keys, and incorrect counts.

Run it only against an offline data copy, with the original database retained for rollback. Mount this directory read-only at `/usr/app/maintenance` in the built image, mount the offline copy at `/var/lib/sqlpad`, disable container networking, and supply these values through a private environment file (never command-line key values or committed files):

- `SQLPAD_DB_PATH=/var/lib/sqlpad`
- `SQLPAD_REKEY_OFFLINE_COPY=1`
- `SQLPAD_REKEY_EXPECTED_CONNECTIONS` set to the verified count
- `SQLPAD_REKEY_SOURCE_PASSPHRASE` set to the original encryption key
- `SQLPAD_PASSPHRASE` set to the new random key, at least 32 characters
- `SQLPAD_REKEY_MODE=check` for validation, then `apply` for the copied database

Use `node /usr/app/maintenance/rekey-connections.mjs` as the container entry point. The replacement service must retain the new `SQLPAD_PASSPHRASE`; keep a separate private key backup. Never use that key with the original rollback database. Give the new service its own random `SQLPAD_COOKIE_SECRET` as well; changing this signing key requires users to sign in again but does not change their passwords.

MySQL2 connections now explicitly verify the certificate hostname when server-certificate validation is enabled. Production connections must enable TLS and leave “Do not validate server certificate” unchecked; retain the trusted CA and require TLS 1.2 or newer.
17 changes: 17 additions & 0 deletions ops/sqlpad/audit-check.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
const [component, file] = process.argv.slice(2);
assert(['server', 'client'].includes(component));
const report = JSON.parse(readFileSync(file, 'utf8'));
assert(!report.error, 'Dependency audit failed');
assert(report.metadata?.dependencies?.total > 100, 'Incomplete dependency audit');
assert(report.vulnerabilities && report.metadata.vulnerabilities);
const accepted = [];
for (const [name, finding] of Object.entries(report.vulnerabilities)) {
const mitigated = component === 'server' && name === 'aws-sdk' &&
finding.severity === 'low' && finding.via.length === 1 &&
finding.via[0].url === 'https://github.com/advisories/GHSA-j965-2qgj-vjmq';
assert(mitigated, `Unmitigated ${component} dependency advisory: ${name}`);
accepted.push(finding.via[0].url);
}
console.log(JSON.stringify({ component, vulnerabilities: report.metadata.vulnerabilities, inputSanitizationMitigations: accepted }));
Loading
Loading