A guest login: temporary, look-only, revocable
Users -> Guest logins makes a throwaway user name and password, good for half an hour by default, to hand to somebody who wants to see the console. It is a normal account with `guest: true` and an expiry, so login, sessions and the saved look need no special case, and it is left out of the account list, out of "the last account can't be removed", and out of the one account an empty user name means. What a guest may do is one allow-list, checked in the auth middleware, rather than a flag ~190 handlers have to remember. The list is matched by asking the router which handler a request would reach, so it cannot drift from the routes it names, and it is checked against the scoped path — /api/nodes/grid/procs is /api/procs on grid — because the hub proxies to a node with a token that is full control of that node. The node cannot tell a guest from its owner, so the only place it can be stopped is here, before the request leaves. A guest gets the dashboard, containers, stacks, disks, hardware, ZFS and usage, on this machine and on any managed one, and nothing else: no terminal (attaching is a GET, and it is a root shell), no files, no container logs or environments, no stack files, no alert channels, no cron, no tokens, no settings, no power. Expiry is enforced on every request and swept once a minute, so a console left open on a visitor's phone stops within the minute rather than at their next click; revoking signs them out at once. The console hides what a guest cannot use and says how long is left where the power button would be. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
4450f1285d
commit
8a7167bf03
@@ -0,0 +1,42 @@
|
||||
// Whether this console is being looked at through a guest login, kept here so any page can
|
||||
// ask without it being threaded through every prop. Set from /api/me when the app loads.
|
||||
//
|
||||
// This is politeness, not security: a guest is stopped by the server, which answers 403 to
|
||||
// everything but the handful of reads it allows (internal/api/guests.go). What it buys is a
|
||||
// console that doesn't offer a visitor buttons that would only fail.
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
let guest = false
|
||||
let until = ''
|
||||
|
||||
export function setGuest(on: boolean, expires?: string) {
|
||||
guest = on
|
||||
until = expires ?? ''
|
||||
}
|
||||
|
||||
export const isGuest = () => guest
|
||||
|
||||
// msLeft is how long this guest login has, or null when it isn't one.
|
||||
export function msLeft(): number | null {
|
||||
if (!guest || !until) return null
|
||||
return Math.max(0, new Date(until).getTime() - Date.now())
|
||||
}
|
||||
|
||||
// fmtLeft says how long is left, in the roundest terms that are still honest.
|
||||
export function fmtLeft(ms: number): string {
|
||||
const min = Math.floor(ms / 60000)
|
||||
if (min >= 120) return `${Math.floor(min / 60)} h ${min % 60} min`
|
||||
if (min >= 1) return `${min} min`
|
||||
return 'under a minute'
|
||||
}
|
||||
|
||||
// useCountdown re-renders the caller every 15 seconds, for a clock that has to keep up.
|
||||
export function useCountdown(active: boolean): number {
|
||||
const [, tick] = useState(0)
|
||||
useEffect(() => {
|
||||
if (!active) return
|
||||
const t = setInterval(() => tick((n) => n + 1), 15000)
|
||||
return () => clearInterval(t)
|
||||
}, [active])
|
||||
return msLeft() ?? 0
|
||||
}
|
||||
Reference in New Issue
Block a user