mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-13 08:23:18 +08:00
fix(uds-auth): emergency login workspaces, Desktop key prompts, persistent sessions
Emergency (fallback / sealed-box) admins lost the workspace sidebar and saw "sign-in failed / add API key" on DSH Desktop because the remote.mux opens anonymously at boot and every early call was rejected terminally. - gateway: anonymous workspace/follow reaches dsh-acl's empty baseline; anonymous streams are parked until the carrier aborts instead of failing; anonymous workspace/initializeDefault answers "nothing created" - request-auth: a dead UDS_SESSION cookie no longer shadows a valid WS ticket or bridge (sync + async variants used by all callers) - dsh-acl: /api/* waits (bounded 15s) for the gateway ACL during Host startup instead of 403, so the Desktop welcome read no longer fails - desktop-bootstrap: key/account projection is best-effort per reference - client: emit connection/reset after login so boot-time caches (settings describe mirror -> Settings > Models) re-read under the real principal - sessions: absolute lifetime fixed at 7 days (was min(ttl, 7d) = 30 min); bridge expiry slides with its session; MemoryStore persisted to sessions.json (bearer hash only, userData AES-256-GCM sealed) - README: session lifetime/persistence and DSH compatibility notes Also includes previously uncommitted uds-auth 0.3.x work in this tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fa4d5d6d97
commit
df97c5e042
72 changed files with 8436 additions and 1192 deletions
45
uds-auth/scripts/generate-sbom.mjs
Normal file
45
uds-auth/scripts/generate-sbom.mjs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { readFile, writeFile, mkdir } from 'node:fs/promises'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { resolve, join } from 'node:path'
|
||||
const root = resolve(import.meta.dirname, '..')
|
||||
const pkg = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'))
|
||||
const lock = JSON.parse(await readFile(join(root, 'package-lock.json'), 'utf8'))
|
||||
const bundle = await readFile(join(root, 'lib/qrcode-bundled.cjs'))
|
||||
const sourceFiles = [...bundle.toString().matchAll(/^\/\/ node_modules\/(.+)$/gm)].map(m => m[1].trim())
|
||||
if (!sourceFiles.length) throw new Error('bundle source inventory missing')
|
||||
const names = [...new Set(sourceFiles.map(path => path.startsWith('@') ? path.split('/').slice(0, 2).join('/') : path.split('/')[0]))].sort()
|
||||
const components = [], notices = []
|
||||
for (const name of names) {
|
||||
const row = lock.packages['node_modules/' + name]
|
||||
const manifest = JSON.parse(await readFile(join(root, 'node_modules', name, 'package.json'), 'utf8'))
|
||||
if (!row?.integrity || row.version !== manifest.version || !manifest.license) throw new Error('unlocked/unlicensed bundle component: ' + name)
|
||||
let license
|
||||
for (const file of ['LICENSE', 'LICENSE.md', 'LICENSE.txt', 'LICENSE-MIT', 'license']) {
|
||||
try { license = await readFile(join(root, 'node_modules', name, file), 'utf8'); break } catch (err) { if (err.code !== 'ENOENT') throw err }
|
||||
}
|
||||
if (!license) throw new Error('missing third-party license: ' + name)
|
||||
notices.push(`${name} ${row.version} (${manifest.license})\n\n${license.trim()}\n`)
|
||||
const hashes = []
|
||||
for (const file of sourceFiles.filter(file => file.startsWith(name + '/'))) {
|
||||
const data = await readFile(join(root, 'node_modules', file))
|
||||
hashes.push({ file, sha256: createHash('sha256').update(data).digest('hex') })
|
||||
}
|
||||
const purl = `pkg:npm/${name.replace('@', '%40')}@${row.version}`
|
||||
components.push({ type: 'library', name, version: row.version, purl, 'bom-ref': purl,
|
||||
licenses: [{ license: { id: manifest.license } }],
|
||||
properties: [{ name: 'uds-auth:delivery', value: 'bundled in lib/qrcode-bundled.cjs' },
|
||||
{ name: 'npm:integrity', value: row.integrity }, { name: 'uds-auth:source-files', value: JSON.stringify(hashes) }] })
|
||||
}
|
||||
const mainRef = `pkg:npm/uds-auth@${pkg.version}`
|
||||
const bom = { bomFormat: 'CycloneDX', specVersion: '1.5', version: 1,
|
||||
metadata: { component: { type: 'application', name: pkg.name, version: pkg.version, 'bom-ref': mainRef,
|
||||
licenses: [{ license: { id: pkg.license } }] }, properties: [
|
||||
{ name: 'uds-auth:bundle-sha256', value: createHash('sha256').update(bundle).digest('hex') },
|
||||
{ name: 'uds-auth:external-peer', value: 'React supplied by DSH; audit its exact version in the Host SBOM' },
|
||||
{ name: 'uds-auth:scope', value: 'Actual vendored runtime bundle; development dependency audit is a separate npm audit --include=dev gate' },
|
||||
] }, components, dependencies: [{ ref: mainRef, dependsOn: components.map(c => c['bom-ref']) },
|
||||
...components.map(c => ({ ref: c['bom-ref'], dependsOn: [] }))] }
|
||||
await mkdir(join(root, 'docs'), { recursive: true })
|
||||
await writeFile(join(root, 'docs/sbom.cdx.json'), JSON.stringify(bom, null, 2) + '\n')
|
||||
await writeFile(join(root, 'docs/THIRD-PARTY-NOTICES.txt'), notices.join('\n---\n\n'))
|
||||
console.log(`SBOM: ${components.length} bundled components, ${sourceFiles.length} source files`)
|
||||
110
uds-auth/scripts/pack-check.mjs
Normal file
110
uds-auth/scripts/pack-check.mjs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/env node
|
||||
/**
|
||||
* SEC-24: verify npm pack file list before publish.
|
||||
* Usage: node scripts/pack-check.mjs
|
||||
*/
|
||||
import { execSync } from 'node:child_process'
|
||||
import { readFileSync, existsSync } from 'node:fs'
|
||||
import { join, dirname } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { createHash } from 'node:crypto'
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const forbidden = [
|
||||
/(?:^|\/)node_modules\//,
|
||||
/(?:^|\/)__pycache__\//,
|
||||
/\.pyc$/,
|
||||
/(?:^|\/)skill-credentials\.json$/,
|
||||
/(?:^|\/)session-bridge\.json$/,
|
||||
/(?:^|\/)session-owners\.json/,
|
||||
/(?:^|\/)user-workspaces\.json$/,
|
||||
/(?:^|\/)roles\.json$/,
|
||||
/(?:^|\/)config\.runtime\.json$/,
|
||||
/\.uds-auth-secret-key$/,
|
||||
/\.tgz$/,
|
||||
]
|
||||
|
||||
const required = [
|
||||
'package.json',
|
||||
'LICENSE',
|
||||
'lib/index.js',
|
||||
'lib/qrcode-bundled.cjs',
|
||||
'scripts/seal-local-admin.mjs',
|
||||
'skills/uds-skill-auth/scripts/uds_skill_auth.py',
|
||||
'skill-helpers/python/uds_skill_auth.py',
|
||||
'README.md',
|
||||
'README.zh.md',
|
||||
'docs/sbom.cdx.json',
|
||||
'docs/THIRD-PARTY-NOTICES.txt',
|
||||
'docs/upgrade-0.3.10.zh.md',
|
||||
'docs/upgrade-0.3.11.zh.md',
|
||||
'lib/desktop-bootstrap.js',
|
||||
]
|
||||
|
||||
function listPackFiles() {
|
||||
// --ignore-scripts avoids prepack (bun bundle) polluting stdout / requiring bun.
|
||||
const raw = execSync('npm pack --dry-run --json --ignore-scripts', {
|
||||
cwd: root,
|
||||
encoding: 'utf8',
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
env: { ...process.env, npm_config_loglevel: 'error' },
|
||||
})
|
||||
|
||||
const start = raw.indexOf('[')
|
||||
const end = raw.lastIndexOf(']')
|
||||
if (start < 0 || end <= start) {
|
||||
throw new Error('npm pack --json produced no array')
|
||||
}
|
||||
const parsed = JSON.parse(raw.slice(start, end + 1))
|
||||
const entry = Array.isArray(parsed) ? parsed[0] : parsed
|
||||
return (entry?.files || []).map((f) => String(f.path || f).replace(/\\/g, '/'))
|
||||
}
|
||||
|
||||
const files = listPackFiles()
|
||||
let failed = false
|
||||
|
||||
if (!files.length) {
|
||||
console.error('[pack-check] empty pack file list')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
for (const f of files) {
|
||||
for (const re of forbidden) {
|
||||
if (re.test(f)) {
|
||||
console.error('[pack-check] FORBIDDEN in package:', f)
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const need of required) {
|
||||
const norm = need.replace(/\\/g, '/')
|
||||
const ok = files.some((f) => f === norm || f.endsWith('/' + norm))
|
||||
if (!ok && !existsSync(join(root, need))) {
|
||||
console.error('[pack-check] MISSING required path on disk:', need)
|
||||
failed = true
|
||||
} else if (!ok) {
|
||||
console.error('[pack-check] MISSING from pack list:', need)
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
|
||||
const a = readFileSync(join(root, 'skills/uds-skill-auth/scripts/uds_skill_auth.py'), 'utf8')
|
||||
const b = readFileSync(join(root, 'skill-helpers/python/uds_skill_auth.py'), 'utf8')
|
||||
if (a !== b) {
|
||||
console.error('[pack-check] Python helpers diverged')
|
||||
failed = true
|
||||
}
|
||||
|
||||
const sbom = JSON.parse(readFileSync(join(root, 'docs/sbom.cdx.json'), 'utf8'))
|
||||
const metadata = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
|
||||
const bundleHash = createHash('sha256').update(readFileSync(join(root, 'lib/qrcode-bundled.cjs'))).digest('hex')
|
||||
if (sbom.metadata?.component?.version !== metadata.version
|
||||
|| !sbom.metadata?.properties?.some(p => p.name === 'uds-auth:bundle-sha256' && p.value === bundleHash)) {
|
||||
console.error('[pack-check] SBOM version/bundle hash differs; rebuild bundle and SBOM')
|
||||
failed = true
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
process.exit(1)
|
||||
}
|
||||
console.log('[pack-check] OK —', files.length, 'files')
|
||||
|
|
@ -3,22 +3,93 @@
|
|||
* Generate UDS_AUTH_LOCAL_ADMIN_BOX for local decrypt-to-unlock admin.
|
||||
*
|
||||
* Usage:
|
||||
* node scripts/seal-local-admin.mjs "your-passphrase-here"
|
||||
* node scripts/seal-local-admin.mjs
|
||||
* # prompts for passphrase on stdin (hidden when TTY)
|
||||
* node scripts/seal-local-admin.mjs --stdin # read one line from stdin
|
||||
*
|
||||
* Then set the printed env on the Harness process (keep the passphrase offline).
|
||||
* Passphrase on argv is rejected (R10) so it does not land in shell history.
|
||||
*/
|
||||
import { createInterface } from 'node:readline'
|
||||
import { stdin as input, stdout as output, stderr } from 'node:process'
|
||||
import { sealLocalAdminBox, LOCAL_ADMIN_BOX_ENV } from '../lib/local-admin.js'
|
||||
|
||||
const passphrase = process.argv[2]
|
||||
if (!passphrase) {
|
||||
console.error('Usage: node scripts/seal-local-admin.mjs "<passphrase>"')
|
||||
async function readPassphrase() {
|
||||
if (process.argv.includes('--stdin') || !process.stdin.isTTY) {
|
||||
const rl = createInterface({ input, crlfDelay: Infinity })
|
||||
const line = await new Promise((resolve) => {
|
||||
rl.once('line', (l) => resolve(l))
|
||||
rl.once('close', () => resolve(''))
|
||||
})
|
||||
rl.close()
|
||||
return String(line || '').replace(/\r$/, '')
|
||||
}
|
||||
// Interactive: do not echo
|
||||
stderr.write('Passphrase (input hidden): ')
|
||||
return await new Promise((resolve, reject) => {
|
||||
const wasRaw = input.isRaw
|
||||
try { input.setRawMode?.(true) } catch { /* ignore */ }
|
||||
input.resume()
|
||||
let buf = ''
|
||||
const onData = (chunk) => {
|
||||
const s = chunk.toString('utf8')
|
||||
for (const ch of s) {
|
||||
if (ch === '\n' || ch === '\r' || ch === '\u0004') {
|
||||
cleanup()
|
||||
stderr.write('\n')
|
||||
resolve(buf)
|
||||
return
|
||||
}
|
||||
if (ch === '\u0003') {
|
||||
cleanup()
|
||||
reject(new Error('cancelled'))
|
||||
return
|
||||
}
|
||||
if (ch === '\u007f' || ch === '\b') {
|
||||
buf = buf.slice(0, -1)
|
||||
continue
|
||||
}
|
||||
buf += ch
|
||||
}
|
||||
}
|
||||
const cleanup = () => {
|
||||
input.off('data', onData)
|
||||
try { input.setRawMode?.(!!wasRaw) } catch { /* ignore */ }
|
||||
input.pause()
|
||||
}
|
||||
input.on('data', onData)
|
||||
})
|
||||
}
|
||||
|
||||
if (process.argv[2] && process.argv[2] !== '--stdin') {
|
||||
console.error('Do not pass the passphrase on argv (shell history risk).')
|
||||
console.error('Usage: node scripts/seal-local-admin.mjs')
|
||||
console.error(' or: echo passphrase | node scripts/seal-local-admin.mjs --stdin')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
try {
|
||||
const passphrase = await readPassphrase()
|
||||
if (!passphrase || passphrase.length < 12) {
|
||||
console.error('Passphrase required (min 12 characters).')
|
||||
process.exit(1)
|
||||
}
|
||||
const box = sealLocalAdminBox(passphrase)
|
||||
console.log(`# Keep the passphrase secret. Only the box goes into the process env.`)
|
||||
console.log('# Keep the passphrase secret. Only the box goes into env and/or profile file.')
|
||||
console.log(`${LOCAL_ADMIN_BOX_ENV}=${box}`)
|
||||
console.log('# Also durable for Desktop Host (often misses User env after reinstall):')
|
||||
console.log(`# write the box string into %USERPROFILE%\\.uds-auth\\local-admin.box`)
|
||||
try {
|
||||
const { writeFileSync, mkdirSync } = await import('node:fs')
|
||||
const { homedir } = await import('node:os')
|
||||
const { join } = await import('node:path')
|
||||
const dir = join(homedir(), '.uds-auth')
|
||||
mkdirSync(dir, { recursive: true })
|
||||
const file = join(dir, 'local-admin.box')
|
||||
writeFileSync(file, box + '\n', { encoding: 'utf8', mode: 0o600 })
|
||||
console.log(`# Wrote ${file}`)
|
||||
} catch (writeErr) {
|
||||
console.error('# Could not write ~/.uds-auth/local-admin.box:', writeErr.message || writeErr)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err.message || err)
|
||||
process.exit(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue