Heimdall/src/app-profiles.ts
Meta Vens 707da368b1 Retire the Spotiverse profile; keep the spotify provider intact for restore
Spotiverse was lost with the E: drive and has no repository in the swarm,
but /v1/oauth/spotify/start stayed publicly reachable and
GC_ACCESS_PROVIDER_SPOTIFY_CLIENT_ID/_SECRET stayed configured on
yggdrasil. That path would have run a real OAuth handshake against a real
secret and taken custody of a user's Spotify refresh token for a consumer
that could not use it.

The seam is supportsProvider(profile, provider): a provider with no app
behind it is unreachable. So the registry entry is what had to go, not the
provider.

Removed: spotiverseProfile and its registry entry, the spotiverse slug
from appSlugs, the hardcoded callback arm in app.ts, and three
spotiverse-specific tests. Removed from the host: the two spotify env
vars, backed up to /root/heimdall-service.env.bak-20260906-spotify. Nine
other provider vars and the file's 0600 heimdall:heimdall ownership are
untouched.

Kept deliberately: the entire spotify provider -- the providers.ts catalog
entry, spotifyRuntime and its token/profile exchange in oauth.ts, and
"spotify" in the providers union. It is intact and unreferenced, which is
what makes restoring a registry change rather than protocol work. The
capability is wanted back; a Persona managing the queue during a stream is
the motivating case.

docs/app-profiles/spotiverse.md is now the restore spec rather than an
archive: what was removed, what was kept, the base commit 5a15f71 to
recover the profile verbatim, and the daemon's callback URL
(http://127.0.0.1:8796/auth/heimdall/callback), which existed only in a
hardcoded allowlist arm and would otherwise have been lost with it.

Before deleting the three tests I checked their routes keep coverage:
managed-credential resolve is exercised twice via streampixels, and
backend_callback handoff at three other sites. The generic
untrusted_backend_callback negative test was retargeted to bifrost rather
than deleted. 35 pass, 9 files; tsc clean.

Verified the deployed build still boots without the vars --
readProviderConfig returns an empty config rather than throwing, so the
running release fails that route at request time instead of at startup.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-06 01:47:10 +02:00

229 lines
6.6 KiB
TypeScript

import { type AppSlug, type LinkedIdentityInput, type Provider } from "./contracts.js";
import { entitlementFacts, grantFacts, identityFacts } from "./facts.js";
export type CapabilityMode = "shared" | "hybrid";
export interface CapabilityDefinition {
key: string;
mode: CapabilityMode;
summary: string;
sharedRule?: string;
localRequirement?: string;
}
export interface ClaimEvaluationContext {
accountId: string;
facts: Set<string>;
identities: LinkedIdentityInput[];
}
export interface AppProfile {
slug: AppSlug;
displayName: string;
profileVersion: string;
identityProviders: Provider[];
entitlementSources: Provider[];
managedConnectionProviders: Provider[];
capabilities: CapabilityDefinition[];
evaluateSharedCapabilities(context: ClaimEvaluationContext): string[];
}
function hasAnyFact(facts: Set<string>, values: readonly string[]): boolean {
return values.some((value) => facts.has(value));
}
const repixelizerProfile: AppProfile = {
slug: "repixelizer",
displayName: "Repixelizer",
profileVersion: "2026-04-26.1",
identityProviders: ["discord", "patreon"],
entitlementSources: ["discord", "patreon"],
managedConnectionProviders: [],
capabilities: [
{
key: "app_access",
mode: "shared",
summary: "May load the protected hosted GUI.",
sharedRule: "entitlement.app_access || grant.global_member || grant.app_access",
},
{
key: "queue_submit",
mode: "shared",
summary: "May create a repixelizer job.",
sharedRule: "app_access",
},
{
key: "job_read_own",
mode: "hybrid",
summary: "May read own job state, event stream, and final output.",
localRequirement: "Host app must combine app_access with job ownership.",
},
{
key: "job_cancel_own",
mode: "hybrid",
summary: "May cancel own queued or running job.",
localRequirement: "Host app must combine app_access with job ownership.",
},
{
key: "admin_access",
mode: "shared",
summary: "May inspect grant/admin surfaces.",
sharedRule: "grant.operator || grant.admin_access",
},
],
evaluateSharedCapabilities(context) {
const capabilities: string[] = [];
const appAccess = hasAnyFact(context.facts, [
entitlementFacts.appAccess,
grantFacts.globalMember,
grantFacts.appAccess,
]);
if (appAccess) {
capabilities.push("app_access", "queue_submit");
}
if (hasAnyFact(context.facts, [grantFacts.operator, grantFacts.adminAccess])) {
capabilities.push("admin_access");
}
return capabilities;
},
};
const streampixelsProfile: AppProfile = {
slug: "streampixels",
displayName: "StreamPixels",
profileVersion: "2026-04-26",
identityProviders: ["twitch", "youtube"],
entitlementSources: [],
managedConnectionProviders: ["twitch", "youtube"],
capabilities: [
{
key: "viewer_access",
mode: "shared",
summary: "Authenticated viewer session for control-plane surfaces.",
sharedRule: identityFacts.authenticated,
},
{
key: "creator_access",
mode: "hybrid",
summary: "Creator-scoped route access.",
localRequirement:
"Host app must combine authenticated session claims with local creator membership.",
},
{
key: "creator_admin",
mode: "hybrid",
summary: "Creator-scoped write/admin access.",
localRequirement:
"Host app must combine authenticated session claims with local creator admin membership.",
},
{
key: "operator_access",
mode: "shared",
summary: "Global operator access.",
sharedRule: grantFacts.operator,
},
],
evaluateSharedCapabilities(context) {
const capabilities: string[] = [];
if (context.facts.has(identityFacts.authenticated)) {
capabilities.push("viewer_access");
}
if (context.facts.has(grantFacts.operator)) {
capabilities.push("operator_access");
}
return capabilities;
},
};
const bifrostProfile: AppProfile = {
slug: "bifrost",
displayName: "Bifrost",
profileVersion: "2026-06-08",
identityProviders: ["discord", "patreon"],
entitlementSources: ["discord", "patreon"],
managedConnectionProviders: [],
capabilities: [
{
key: "member_access",
mode: "shared",
summary: "May enter the Bifrost member alpha through a Heimdall-verified GameCult membership signal.",
sharedRule: "entitlement.app_access || grant.global_member || grant.app_access",
},
],
evaluateSharedCapabilities(context) {
return hasAnyFact(context.facts, [
entitlementFacts.appAccess,
grantFacts.globalMember,
grantFacts.appAccess,
])
? ["member_access"]
: [];
},
};
const ghostlightProfile: AppProfile = {
slug: "ghostlight",
displayName: "Ghostlight Dungeon",
profileVersion: "2026-08-22",
identityProviders: ["discord"],
entitlementSources: ["discord"],
managedConnectionProviders: [],
capabilities: [
{
key: "app_access",
mode: "shared",
summary: "May enter Ghostlight Dungeon after Heimdall verifies the app-supplied GameCult Discord role policy.",
sharedRule: "entitlement.app_access || grant.global_member || grant.app_access",
},
{
key: "campaign_play",
mode: "hybrid",
summary: "May play campaigns owned by the authenticated Ghostlight account.",
localRequirement: "Ghostlight must combine app_access with local campaign ownership.",
},
],
evaluateSharedCapabilities(context) {
return hasAnyFact(context.facts, [
entitlementFacts.appAccess,
grantFacts.globalMember,
grantFacts.appAccess,
]) ? ["app_access"] : [];
},
};
export const appProfiles: Record<AppSlug, AppProfile> = {
repixelizer: repixelizerProfile,
streampixels: streampixelsProfile,
bifrost: bifrostProfile,
ghostlight: ghostlightProfile,
};
export function getAppProfile(appSlug: AppSlug): AppProfile {
return appProfiles[appSlug];
}
export function serializeAppProfile(profile: AppProfile): Record<string, unknown> {
return {
slug: profile.slug,
displayName: profile.displayName,
profileVersion: profile.profileVersion,
identityProviders: profile.identityProviders,
entitlementSources: profile.entitlementSources,
managedConnectionProviders: profile.managedConnectionProviders,
capabilities: profile.capabilities,
};
}
export function supportsProvider(profile: AppProfile, provider: Provider): boolean {
return (
profile.identityProviders.includes(provider) ||
profile.managedConnectionProviders.includes(provider) ||
profile.entitlementSources.includes(provider)
);
}