import m, {MithrilComponent} from '@garage44/mithril' import {Badge, Button, Card, FieldText} from '@garage44/mithril/components' import {who} from '@/components/who' import {act} from '@/lib/actions' import {api} from '@/lib/api' import {age, when} from '@/lib/format' import {makeKey, passkeyHere, signGrant} from '@/lib/passkey' import {bind, local} from '@/lib/reactive' import {$s} from '@/lib/store' import type {AdminRequest} from '@/lib/types' /** * Admin windows (src/admin.rs): a session asks for root on the hub's machine, * and the person's passkey signs the grant — who, for how long, why — which * root checks before sudo works. The hub only carries the signature. */ const rpId = () => $s.admin?.setup?.rp_id ?? location.hostname async function allow(r: AdminRequest) { // Hub's time in the grant: root checks it against its own clock. const s = await api.adminToSign(r.id) const assertion = await signGrant(s.challenge, s.rp_id, s.keys) await api.adminGrant(r.id, s.grant.issued_at, assertion) } /** One request, under Needs you: what for, how long, and Allow (the passkey) or No. */ export function adminRequestRow(r: AdminRequest): m.Children { const blocked = $s.role !== 'admin' ? 'an admin grants root' : passkeyHere(rpId()) return (
root {r.reason}
{who(r.session, {max: 40})} asks for root on the hub's machine for {r.minutes} min · {age(r.at)} ago. Root then can change anything there; the machine closes it on time, or when the session ends.
{blocked ?

{blocked}

: null}
) } /** The window while it is open: whose, until when, and Close. */ export function adminOpenRow(): m.Children { const w = $s.admin?.window if (!w) return null return (
root open {who(w.session, {max: 40})} until {when(w.until)}: {w.reason}
) } /** Settings ▸ Admin: the machine's setup, the passkeys that may grant, making one. */ export class AdminPasskey extends MithrilComponent { s = local({label: '', line: '', error: ''}) async make() { const setup = $s.admin?.setup if (!setup) return try { this.s.line = await makeKey(setup.rp_id, this.s.label, setup.keys.map((k) => k.id)) this.s.error = '' } catch (e) { this.s.error = (e as Error).message } } view() { const setup = $s.admin?.setup if (!setup) return (

As root there, once: sudo midas hub admin-setup --user agent --rp-id {location.hostname}. The agents then log in as that user, which is root only in a window you allow.

) const blocked = passkeyHere(setup.rp_id) const cmd = this.s.line ? `sudo midas hub admin-enroll '${this.s.line}'` : '' return ( void this.make()}> Make a passkey on this device , ]} > {setup.keys.length ? ( ) : (

No passkey yet: until there is one, no session can be given root.

)} {blocked ?

{blocked}

: null} {this.s.error ?

{this.s.error}

: null} {cmd ? (

Made. The machine trusts it only once you install it yourself, as root, from your own login (not a session's): run this there.

{cmd}
) : null}
) } }