Files
T
helix-nine 8397c7b1eb adopt 0.4's persistent key store and browser setup form
The earlier bump took 0.4.1 for its model catalog and status page but
left PPQ_DATA_DIR unset, which disabled the key form the release exists
to add. Enable it, and let the proxy own the key outright.

PPQ_API_KEY is no longer passed. The volume's `proxy/` subpath mounts at
/data as PPQ_DATA_DIR, so upstream's key store is the single source of
truth: the Status Page and the Configure PPQ API Key action write the
same config.json, and there is no StartOS-side copy to revert what the
browser saved. A chown oneshot hands /data to the image's `node` user so
the page can write there.

Verbose Logging moves to store.json outside the mount, because upstream
rewrites config.json wholesale when a key is saved and would drop it.

main.ts watches config.json — upstream loads it once at startup, so the
watch is what makes the action take effect: the write restarts the
daemon, which reloads the file. A key saved on the page applies
immediately and converges through the same restart.

The task drops from critical to important. A critical task suspends
every other control, so it would have left the user unable to start the
service and reach the page's own form — and with PPQ_DATA_DIR set the
proxy no longer exits keyless; it attests, serves the page, and answers
401 until a key exists. main.ts clears the task when a key appears,
since saving on the page never touches the action that would clear it.

The action's key field is now validated against upstream's own
^sk-[A-Za-z0-9]{16,64}$ shape and no longer refuses a blank submission,
a key having become optional.
2026-08-12 09:58:35 -06:00

76 lines
2.5 KiB
TypeScript

import { i18n } from './i18n'
import { sdk } from './sdk'
import { manifest } from './manifest'
import { apiPort, dataDir } from './utils'
import { configureApiKey } from './actions/configureApiKey'
import { configJson } from './fileModels/config.json'
import { storeJson } from './fileModels/store.json'
export const main = sdk.setupMain(async ({ effects }) => {
console.info(i18n('Starting PPQ Private Mode!'))
// The proxy reads config.json once at startup, so watching it is what makes a
// key saved by the Configure PPQ API Key action take effect: the write
// restarts the daemon, which reloads the file. PPQ_API_KEY is left unset so
// the proxy's own key store is the only thing that owns the key.
const apiKey = await configJson.read((c) => c.apiKey).const(effects)
const debug = await storeJson.read((s) => s.debug).const(effects)
// Running the action clears its own task, but a key saved on the Status Page
// never touches the action — so clear it here, on the restart that same save
// triggers. Otherwise StartOS keeps asking for a key the user already set.
if (apiKey) {
await sdk.action.clearTask(effects, `${manifest.id}:${configureApiKey.id}`)
}
const subcontainer = sdk.SubContainer.of(
effects,
{ imageId: 'proxy' },
sdk.Mounts.of().mountVolume({
volumeId: 'main',
subpath: 'proxy',
mountpoint: dataDir,
readonly: false,
}),
'proxy-sub',
)
return sdk.Daemons.of(effects)
.addOneshot('chown', {
subcontainer,
exec: {
command: ['chown', '-R', 'node:node', dataDir],
user: 'root',
},
requires: [],
})
.addDaemon('proxy', {
subcontainer,
exec: {
command: ['node', '/app/dist/bin/server.js'],
env: {
PPQ_DATA_DIR: dataDir,
HOST: '0.0.0.0',
PORT: apiPort.toString(),
DEBUG: debug ? 'true' : 'false',
},
},
// The proxy only binds its port after remote attestation of the enclave
// succeeds, so a listening port means the encrypted channel is verified
// and ready.
ready: {
display: i18n('Encrypted Proxy'),
fn: () =>
sdk.healthCheck.checkPortListening(effects, apiPort, {
successMessage: i18n(
'The proxy is ready — enclave attestation verified',
),
errorMessage: i18n(
'The proxy is not ready (enclave attestation pending)',
),
}),
},
requires: ['chown'],
})
})