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

+188 -5
View File
@@ -1,5 +1,4 @@
import type { PluginSurfaceProps } from "@getpaseo/plugin/client";
import { useRpc, useSettings } from "@getpaseo/plugin/client";
import { openExternalUrl, type PluginSurfaceProps, useRpc, useSettings } from "@getpaseo/plugin/client";
import {
ScrollView,
SettingsAction,
@@ -19,6 +18,7 @@ import {
flySpritesSettings,
type FlySpritesSettings,
} from "../shared/settings";
import { useOpenBaoAuth } from "./use-openbao-auth";
const MODE_OPTIONS: readonly { label: string; value: FlySpritesSettings["defaultProviderMode"] }[] = [
{ label: "Remote Shell Worker (bash -lc)", value: "shell" },
@@ -29,6 +29,7 @@ export function FlySpritesSettingsScreen({ theme, layout, host }: PluginSurfaceP
const settings = useSettings(flySpritesSettings);
const testConnection = useRpc(testConnectionRpc);
const toast = useToast();
const openbao = useOpenBaoAuth();
const [draft, setDraft] = useState<FlySpritesSettings>(defaultFlySpritesSettings);
const [testing, setTesting] = useState(false);
@@ -118,11 +119,37 @@ export function FlySpritesSettingsScreen({ theme, layout, host }: PluginSurfaceP
}
}
async function handleStartZitadel() {
if (isDirty) {
await settings.save(draft, revision);
}
await openbao.startLogin();
}
async function handlePullOpenBao() {
if (isDirty) {
await settings.save(draft, revision);
}
await openbao.pullNow();
}
const baoStatus = openbao.status;
const pendingFlow = baoStatus?.pendingAuth?.status === "pending" ? baoStatus.pendingAuth : null;
const baoSummary = baoStatus?.authenticated
? `Signed in as ${baoStatus.displayName ?? "Zitadel user"}${
baoStatus.tokenPresent ? " · Token loaded" : " · Token not loaded"
}`
: "Not signed in";
return (
<ScrollView style={styles.screen} contentContainerStyle={styles.body}>
<SettingsSection
title="Fly Sprites authentication"
info={<Text style={styles.muted}>Host settings for {host.label}. Leave token blank to use SPRITES_TOKEN.</Text>}
info={
<Text style={styles.muted}>
Host settings for {host.label}. Leave Sprites API token blank to pull from OpenBao or host env.
</Text>
}
>
{isInvalid ? (
<SettingsCard>
@@ -133,9 +160,9 @@ export function FlySpritesSettingsScreen({ theme, layout, host }: PluginSurfaceP
<SettingsCard key={`auth-${revision}`}>
<SettingsInput
label="Sprites API token"
hint="Used by the provider, agent tools, and worker manager."
hint="Optional direct override. Leave blank to pull FLY_TOKEN from OpenBao."
initialValue={draft.token}
placeholder="SPRITES_TOKEN (leave blank to read host env)"
placeholder="Leave blank to use OpenBao or SPRITES_TOKEN"
secureTextEntry
disabled={settings.saving}
onChangeText={(token) => {
@@ -164,6 +191,162 @@ export function FlySpritesSettingsScreen({ theme, layout, host }: PluginSurfaceP
</SettingsCard>
</SettingsSection>
<SettingsSection
title="OpenBao + Zitadel OIDC"
info={
<Text style={styles.muted}>
Pulls {draft.openbaoSecretKey || "FLY_TOKEN"} from {draft.openbaoKvMount || "secret"}/
{draft.openbaoSecretPath || "paseo"} via Zitadel Device Code auth.
</Text>
}
>
<SettingsCard key={`openbao-${revision}`}>
<SettingsSwitch
label="Pull token from OpenBao"
hint="Uses your Zitadel OpenBao session when direct token is blank."
value={draft.openbaoEnabled}
disabled={settings.saving}
onValueChange={(openbaoEnabled) => {
const next = { ...draft, openbaoEnabled };
setDraft(next);
void saveDraft(next);
}}
/>
<SettingsRow
label="OpenBao session"
hint={baoStatus?.lastError ?? baoSummary}
error={baoStatus?.lastError ?? undefined}
/>
{pendingFlow ? (
<SettingsAction
label={`Waiting for Zitadel approval (Code: ${pendingFlow.userCode})`}
hint={pendingFlow.verificationUriComplete || pendingFlow.verificationUri}
actionLabel="Open Zitadel"
onPress={() =>
void openExternalUrl(pendingFlow.verificationUriComplete || pendingFlow.verificationUri)
}
/>
) : null}
<SettingsAction
label="Zitadel OIDC sign-in"
hint="Opens Zitadel Device Code authorization in your browser and exchanges JWT with OpenBao."
actionLabel={
openbao.busy
? "Working…"
: baoStatus?.authenticated
? "Re-authenticate"
: "Sign in with Zitadel"
}
disabled={openbao.busy || settings.saving || !draft.openbaoEnabled}
onPress={() => void handleStartZitadel()}
/>
{baoStatus?.authenticated ? (
<>
<SettingsAction
label="Refresh token from OpenBao"
hint={`Reads ${draft.openbaoKvMount}/${draft.openbaoSecretPath} (${draft.openbaoSecretKey}).`}
actionLabel="Pull now"
disabled={openbao.busy || settings.saving || !draft.openbaoEnabled}
onPress={() => void handlePullOpenBao()}
/>
<SettingsAction
label="Sign out of OpenBao"
hint="Clears saved OpenBao token for this host."
actionLabel="Sign out"
disabled={openbao.busy}
onPress={() => void openbao.logout()}
/>
</>
) : null}
<SettingsInput
label="OpenBao URL"
initialValue={draft.openbaoAddr}
placeholder="https://bao.site.latha.org"
disabled={settings.saving}
onChangeText={(openbaoAddr) => {
setStatusMessage(null);
setDraft((prev) => ({ ...prev, openbaoAddr }));
}}
/>
<SettingsInput
label="OpenBao KV mount"
initialValue={draft.openbaoKvMount}
placeholder="secret"
disabled={settings.saving}
onChangeText={(openbaoKvMount) => {
setStatusMessage(null);
setDraft((prev) => ({ ...prev, openbaoKvMount }));
}}
/>
<SettingsInput
label="OpenBao secret path"
initialValue={draft.openbaoSecretPath}
placeholder="paseo"
disabled={settings.saving}
onChangeText={(openbaoSecretPath) => {
setStatusMessage(null);
setDraft((prev) => ({ ...prev, openbaoSecretPath }));
}}
/>
<SettingsInput
label="OpenBao secret key"
initialValue={draft.openbaoSecretKey}
placeholder="FLY_TOKEN"
disabled={settings.saving}
onChangeText={(openbaoSecretKey) => {
setStatusMessage(null);
setDraft((prev) => ({ ...prev, openbaoSecretKey }));
}}
/>
<SettingsInput
label="OpenBao auth mount & role"
hint={`Mount: ${draft.openbaoAuthMount} · Role: ${draft.openbaoRole}`}
initialValue={`${draft.openbaoAuthMount}:${draft.openbaoRole}`}
placeholder="jwt:admin"
disabled={settings.saving}
onChangeText={(val) => {
const [mount, role] = val.split(":");
setStatusMessage(null);
setDraft((prev) => ({
...prev,
openbaoAuthMount: (mount ?? "jwt").trim() || "jwt",
openbaoRole: (role ?? "admin").trim() || "admin",
}));
}}
/>
<SettingsInput
label="Zitadel issuer URL"
initialValue={draft.zitadelIssuer}
placeholder="https://auth.site.latha.org"
disabled={settings.saving}
onChangeText={(zitadelIssuer) => {
setStatusMessage(null);
setDraft((prev) => ({ ...prev, zitadelIssuer }));
}}
/>
<SettingsInput
label="Zitadel client ID"
initialValue={draft.zitadelClientId}
placeholder="400222693598691513"
disabled={settings.saving}
onChangeText={(zitadelClientId) => {
setStatusMessage(null);
setDraft((prev) => ({ ...prev, zitadelClientId }));
}}
/>
<SettingsInput
label="Zitadel scope"
initialValue={draft.zitadelScope}
placeholder="openid profile email"
disabled={settings.saving}
onChangeText={(zitadelScope) => {
setStatusMessage(null);
setDraft((prev) => ({ ...prev, zitadelScope }));
}}
/>
</SettingsCard>
</SettingsSection>
<SettingsSection title="Sprite defaults & provider">
<SettingsCard key={`defaults-${revision}`}>
<SettingsSelect
+133
View File
@@ -0,0 +1,133 @@
import { openExternalUrl, useRpc } from "@getpaseo/plugin/client";
import { useToast } from "@getpaseo/plugin/client/ui";
import { useCallback, useEffect, useState } from "react";
import {
type OpenBaoStatus,
openbaoAuthStartRpc,
openbaoLogoutRpc,
openbaoPullRpc,
openbaoStatusRpc,
} from "../shared/contracts";
interface UseOpenBaoAuthOptions {
onConnected?: () => void | Promise<void>;
}
export function useOpenBaoAuth(options: UseOpenBaoAuthOptions = {}) {
const { onConnected } = options;
const toast = useToast();
const fetchStatus = useRpc(openbaoStatusRpc);
const startAuth = useRpc(openbaoAuthStartRpc);
const pullRpc = useRpc(openbaoPullRpc);
const logoutRpc = useRpc(openbaoLogoutRpc);
const [status, setStatus] = useState<OpenBaoStatus | null>(null);
const [busy, setBusy] = useState(false);
const refreshStatus = useCallback(async () => {
try {
const next = await fetchStatus({});
setStatus(next);
return next;
} catch {
return null;
}
}, [fetchStatus]);
useEffect(() => {
void refreshStatus();
}, [refreshStatus]);
const pendingStatus = status?.pendingAuth?.status;
useEffect(() => {
if (pendingStatus !== "pending") return;
let cancelled = false;
const timer = setInterval(() => {
void (async () => {
const next = await refreshStatus();
if (cancelled || !next) return;
const flow = next.pendingAuth;
if (flow?.status === "complete") {
toast.show(
next.tokenPresent
? `Connected to OpenBao as ${next.displayName ?? "Zitadel user"} and loaded token.`
: `Signed in as ${next.displayName ?? "Zitadel user"}, but token pull failed.`,
{ variant: next.tokenPresent ? "success" : "error" },
);
await onConnected?.();
} else if (flow?.status === "error" && flow.error) {
toast.error(flow.error);
}
})();
}, 2000);
return () => {
cancelled = true;
clearInterval(timer);
};
}, [pendingStatus, refreshStatus, onConnected, toast]);
const startLogin = useCallback(async () => {
setBusy(true);
try {
const res = await startAuth({});
if (!res.ok) {
toast.error(res.error);
return null;
}
await refreshStatus();
if (res.pendingAuth.verificationUriComplete) {
await openExternalUrl(res.pendingAuth.verificationUriComplete).catch(() => undefined);
}
return res.pendingAuth;
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
return null;
} finally {
setBusy(false);
}
}, [startAuth, refreshStatus, toast]);
const pullNow = useCallback(async () => {
setBusy(true);
try {
const res = await pullRpc({});
if (!res.ok) {
toast.error(res.error);
await refreshStatus();
return false;
}
setStatus(res.status);
toast.show("Pulled Fly token from OpenBao.", { variant: "success" });
await onConnected?.();
return true;
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
return false;
} finally {
setBusy(false);
}
}, [pullRpc, refreshStatus, onConnected, toast]);
const logout = useCallback(async () => {
setBusy(true);
try {
await logoutRpc({});
await refreshStatus();
toast.show("Signed out of OpenBao.");
await onConnected?.();
} catch (error) {
toast.error(error instanceof Error ? error.message : String(error));
} finally {
setBusy(false);
}
}, [logoutRpc, refreshStatus, onConnected, toast]);
return {
status,
busy,
refreshStatus,
startLogin,
pullNow,
logout,
};
}
+62 -2
View File
@@ -1,5 +1,6 @@
import {
type PluginHostProps,
openExternalUrl,
useRpc,
useSubscription,
} from "@getpaseo/plugin/client";
@@ -9,6 +10,7 @@ import { Pressable, Text, View } from "react-native";
import {
type CheckpointSummary,
type SpriteSummary,
type TokenSource,
type WorkerSummary,
createCheckpointRpc,
createSpriteRpc,
@@ -22,6 +24,7 @@ import {
watchWorkersSub,
workerLogsRpc,
} from "../shared/contracts";
import { useOpenBaoAuth } from "./use-openbao-auth";
interface WorkersScreenProps extends PluginHostProps {
workspaceName?: string;
@@ -49,7 +52,7 @@ export function FlySpritesWorkersScreen({
const restoreCheckpoint = useRpc(restoreCheckpointRpc);
const [configured, setConfigured] = useState(false);
const [tokenSource, setTokenSource] = useState<"settings" | "env" | "none">("none");
const [tokenSource, setTokenSource] = useState<TokenSource>("none");
const [remoteError, setRemoteError] = useState<string | null>(null);
const [sprites, setSprites] = useState<SpriteSummary[]>([]);
const [workers, setWorkers] = useState<WorkerSummary[]>([]);
@@ -98,6 +101,10 @@ export function FlySpritesWorkersScreen({
void refresh();
}, [refresh]);
const openbao = useOpenBaoAuth({ onConnected: refresh });
const pendingFlow =
openbao.status?.pendingAuth?.status === "pending" ? openbao.status.pendingAuth : null;
const selectedWorker = useMemo(
() => workers.find((w) => w.workerId === selectedWorkerId) ?? null,
[workers, selectedWorkerId],
@@ -357,8 +364,61 @@ export function FlySpritesWorkersScreen({
{!configured ? (
<View style={styles.card}>
<Text style={styles.error}>
No Fly Sprites API token configured. Open Settings → Fly Sprites Workers or set SPRITES_TOKEN on the host.
No Fly Sprites API token loaded. Sign in with Zitadel to pull FLY_TOKEN from OpenBao, or configure a token in Settings → Fly Sprites Workers.
</Text>
{openbao.status?.lastError ? (
<Text style={styles.error}>OpenBao: {openbao.status.lastError}</Text>
) : null}
{pendingFlow ? (
<View style={{ gap: 6 }}>
<Text style={styles.muted}>
Waiting for Zitadel approval · Code: {pendingFlow.userCode}
</Text>
<View style={styles.row}>
<Pressable
style={styles.btnPrimary}
onPress={() =>
void openExternalUrl(
pendingFlow.verificationUriComplete || pendingFlow.verificationUri,
)
}
>
<Text style={styles.btnPrimaryText}>Open Zitadel Login</Text>
</Pressable>
<Pressable
style={styles.btnSecondary}
onPress={() => void copyText(pendingFlow.userCode)}
>
<Text style={styles.btnSecondaryText}>Copy Code</Text>
</Pressable>
</View>
</View>
) : (
<View style={styles.row}>
<Pressable
style={styles.btnPrimary}
onPress={() => void openbao.startLogin()}
disabled={openbao.busy}
>
<Text style={styles.btnPrimaryText}>
{openbao.busy
? "Starting…"
: openbao.status?.authenticated
? "Re-authenticate Zitadel"
: "Sign in with Zitadel"}
</Text>
</Pressable>
{openbao.status?.authenticated ? (
<Pressable
style={styles.btnSecondary}
onPress={() => void openbao.pullNow()}
disabled={openbao.busy}
>
<Text style={styles.btnSecondaryText}>Pull from OpenBao</Text>
</Pressable>
) : null}
</View>
)}
</View>
) : null}