Files
spark-control/package/startos/actions/showPublicKey.ts
T
Grant 51804b2e5e 0.1.0:2 - remove '<spark-user>' default everywhere (it's Alice's username, not factory)
Per user correction: '<spark-user>' is not the DGX Spark factory default. Generic-ize:
- configureSparks: no default user; placeholder 'your SSH username'
- sparkConfig schema: empty string defaults
- main.ts env fallback: empty
- showPublicKey: drop the '<spark-user>' fallback; skip Spark if user not configured
- Update feedback memory with the correction
2026-05-12 10:39:57 -05:00

84 lines
2.9 KiB
TypeScript

import { sdk } from '../sdk'
import { promises as fs } from 'fs'
import * as path from 'path'
import { sparkConfigYaml } from '../fileModels/sparkConfig.yaml'
export const showPublicKey = sdk.Action.withoutInput(
'show-public-key',
async () => ({
name: 'Show Public Key',
description:
'Display the SSH public key and a ready-to-paste install command for granting this package SSH access to your Sparks.',
warning: null,
visibility: 'enabled',
allowedStatuses: 'any',
group: null,
}),
async ({ effects }) => {
// The container generates the key under /data/ssh/id_ed25519.pub on first boot.
const pubKeyPath = path.join(
sdk.volumes.main.path,
'ssh',
'id_ed25519.pub',
)
let key: string
try {
key = (await fs.readFile(pubKeyPath, 'utf8')).trim()
} catch (e) {
return {
version: '1' as const,
title: 'Public Key Not Ready',
message:
'The service has not generated its SSH keypair yet. Start the service from the dashboard, wait a few seconds, then run this action again.',
result: null,
}
}
// If hosts are configured, construct a ready-to-paste one-liner.
const cfg = await sparkConfigYaml.read().once()
const hosts: Array<{ user: string; host: string }> = []
if (cfg) {
if (cfg.spark1_host && cfg.spark1_user)
hosts.push({ user: cfg.spark1_user, host: cfg.spark1_host })
if (cfg.spark2_host && cfg.spark2_user)
hosts.push({ user: cfg.spark2_user, host: cfg.spark2_host })
}
let message: string
if (hosts.length > 0) {
const sshLines = hosts
.map(
(h) =>
`ssh ${h.user}@${h.host} "mkdir -p ~/.ssh && echo '$KEY' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"`,
)
.join('\n')
const oneLiner = `KEY='${key}'\n${sshLines}`
message =
'Paste this block into any machine that already has SSH access to your Sparks (your laptop or one of the Sparks itself). It grants this Spark Control service permission to log in.\n\n' +
oneLiner +
'\n\nYou will be prompted for the SSH password of each Spark once. After both commands succeed, run "Test Connection" or open the Web Interface to verify.'
} else {
message =
'Run the "Configure Sparks" action first, then come back to this one — once your Spark hostnames are saved, this message will include a ready-to-paste install command.\n\nFor reference, the raw public key is:\n\n' +
key
}
return {
version: '1' as const,
title: 'SSH Public Key',
message,
result: {
type: 'single' as const,
name: 'Raw Public Key',
description:
'The bare public key line. Copy the full message above for the ready-to-paste install command.',
value: key,
masked: false,
copyable: true,
qr: false,
},
}
},
)