mirror of
https://github.com/nestriness/nestri.git
synced 2026-11-29 18:46:13 +02:00
feat(auth): an installer device client whose session lasts one step
A host installer needs a signed-in session for exactly one call: trading it for a single-use host token. It runs as root, on a machine that may not belong to the person signing in, so a 30-day session with a year of refresh behind it is far more than it should ever hold. The issuer gains `clientTTL`, a per-client override of token lifetimes that wins over what the sign-in asks for, and a refresh lifetime of 0 now means no refresh token is issued at all rather than one that expires immediately. The `installer` client is allowed to start a device grant and gets 15 minutes and no refresh token. The desktop client keeps its defaults.
This commit is contained in:
+19
-2
@@ -45,7 +45,23 @@ type Env = {
|
||||
* ours: the identifier ends up on the issued token, and without this anything
|
||||
* on the internet could mint a grant naming anything at all.
|
||||
*/
|
||||
const DEVICE_CLIENTS = new Set(['desktop']);
|
||||
const DEVICE_CLIENTS = new Set(['desktop', 'installer']);
|
||||
|
||||
export const allowDeviceClient = async (clientID: string) => DEVICE_CLIENTS.has(clientID);
|
||||
|
||||
/**
|
||||
* How long a session for each device client lasts, where it is not the
|
||||
* default.
|
||||
*
|
||||
* The installer signs in for one step — trading the session for a single host
|
||||
* token — and runs as root on a machine that may not be the person's own, so
|
||||
* it gets a quarter of an hour and no refresh token: nothing it could leave
|
||||
* behind outlives the install.
|
||||
*
|
||||
* Exported, like the list above, so both can be tested against a real grant.
|
||||
*/
|
||||
export const clientTTL = (clientID: string) =>
|
||||
clientID === 'installer' ? { access: 15 * 60, refresh: 0 } : undefined;
|
||||
|
||||
/**
|
||||
* The zone every user-owned host is reached under, and the one path on it that
|
||||
@@ -192,7 +208,8 @@ export default {
|
||||
codeStore: PostgresCodeStore(),
|
||||
refreshStore: PostgresRefreshStore(),
|
||||
deviceStore: PostgresDeviceStore(),
|
||||
allowDeviceClient: async (clientID) => DEVICE_CLIENTS.has(clientID),
|
||||
allowDeviceClient,
|
||||
clientTTL,
|
||||
// The default rule allows a redirect back to whatever hostname the
|
||||
// request arrived on, which is right for a site served beside this
|
||||
// one and refuses the proxy in front of user-owned hosts — it
|
||||
|
||||
Reference in New Issue
Block a user