feat: add OpenBao + Zitadel OIDC device-code token integration

This commit is contained in:
nandi committed 2026-11-18 16:43:42 -08:00
1 parent d399919690
commit 9188bfc277
9 files changed
+1232 -15

No files matched your search

+14 -4
View File
@@ -15,15 +15,17 @@ import {
import type {
CheckpointSummary,
SpriteSummary,
TokenSource,
WorkerSummary,
} from "../shared/contracts";
import type { FlySpritesSettings } from "../shared/settings";
import type { OpenBaoClient } from "./openbao-client";
const execFileAsync = promisify(nodeExecFile);
const MAX_OUTPUT_BYTES = 256 * 1024;
const TAIL_CHARS = 4000;
export type TokenSource = "settings" | "env" | "none";
export type { TokenSource };
export interface TrackedWorker {
workerId: string;
@@ -93,13 +95,15 @@ function formatCheckpointStreamMessage(msg: StreamMessage): string {
export class SpritesManager {
private readonly getSettings: () => Promise<FlySpritesSettings>;
private readonly openbao: OpenBaoClient;
private cachedClient: { key: string; client: SpritesClient } | null = null;
private readonly workers = new Map<string, TrackedWorker>();
private readonly listeners = new Set<(workers: WorkerSummary[]) => void>();
private notifyTimer: ReturnType<typeof setTimeout> | null = null;
constructor(getSettings: () => Promise<FlySpritesSettings>) {
constructor(getSettings: () => Promise<FlySpritesSettings>, openbao: OpenBaoClient) {
this.getSettings = getSettings;
this.openbao = openbao;
}
async resolveToken(): Promise<{ token: string; source: TokenSource; baseUrl: string }> {
@@ -109,6 +113,12 @@ export class SpritesManager {
if (fromSettings) {
return { token: fromSettings, source: "settings", baseUrl };
}
if (settings.openbaoEnabled) {
const fromOpenBao = await this.openbao.getSecretToken();
if (fromOpenBao) {
return { token: fromOpenBao, source: "openbao", baseUrl };
}
}
const fromEnv =
process.env.SPRITES_TOKEN?.trim() ||
process.env.FLY_TOKEN?.trim() ||
@@ -120,12 +130,12 @@ export class SpritesManager {
return { token: "", source: "none", baseUrl };
}
async getClient(): Promise<{ client: SpritesClient; source: "settings" | "env"; settings: FlySpritesSettings }> {
async getClient(): Promise<{ client: SpritesClient; source: Exclude<TokenSource, "none">; settings: FlySpritesSettings }> {
const settings = await this.getSettings();
const { token, source, baseUrl } = await this.resolveToken();
if (!token || source === "none") {
throw new Error(
"Fly Sprites token is not configured. Set it in Fly Sprites Workers settings or SPRITES_TOKEN.",
"Fly Sprites token is not configured. Sign in with Zitadel (OpenBao), set it in Fly Sprites Workers settings, or export FLY_TOKEN / SPRITES_TOKEN.",
);
}
const key = `${baseUrl}::${token}`;