# 0104: Package apps act as a hidden profile derived from their publisher - **Status:** accepted (on for everyone; the `profiles` flag is gone) - **Date:** 2026-11-28 **In short:** every package app acts as one hidden profile of its last publisher. Publish reconciles the profile's grants from what that version calls (new grants for a public app or an uncertain scan wait for an owner's approval, and an approval carries forward when a publish asks for nothing new), every call still needs the publisher's live access, and anything missing fails closed. There is no runs-as pick; to change who an app acts as, publish it again as that person. User-facing behavior: [Who the app runs as](../../guides/package-apps.md#who-the-app-runs-as). ## Context A package app called capabilities as a person: an Owner's explicit runs-as pick, else the last publisher, else a personal org's owner. That person's whole access backed every call, so an app reached far more than it touches. ## Decision Kent decided on 2026-11-28: 1. **One hidden profile per app.** Every package app acts as a profile ([ADR 0092](./0092-profiles-are-scoped-agent-identities.md)) in its owning org whose acting person is its publisher. `profiles.package_app_id` marks it; `package_app_authority.profile_id` points at it. Nobody picks it, no profile surface lists or changes it, and there is no "Runs as" panel. A new publisher gets a new profile and the old one is revoked. 2. **Grants come from publish, never from runs.** Finalize reconciles the profile before the new commit serves. A private app with a clean static scan of the published commit (every Kody call in it and its import closure is a literal declared name; no run-time names, unresolved imports, or timeout) gets exactly the grants that version needs: the credentials and package storage its capability set reaches, `package:execute` on the packages it imports, and allowlisted org-level permissions for capabilities no concrete grant covers. Each added grant writes a `package_app.profile_grant.added` audit row. If the publisher does not hold any of it live, the publish fails naming each missing permission. 3. **Uncertain or public apps grant nothing new until an owner approves.** Every publish records the grants that version needs (`package_app_authority.profile_grants_json`, for that commit; an uncertain scan uses the declared names). They join the capability set as `profile-grant` entries, so the approved fingerprint covers them. An uncertain scan or an internet-visible app keeps the profile's current grants until an owner approves that set, and approval applies only grants the publisher still holds live. Going public approves the current set, so it re-approves the grants. Visitors never approve a profile. 4. **Site-admin capabilities go through a site-role grant.** A version that declares a capability gated by a site role (`requiredRole`) needs that role as the profile's site-role grant (`profiles.site_role`), recorded per commit in `package_app_authority.profile_site_role` and approved with the rest of the set. Both the publisher and approver must hold the role when approval applies it. Each site-role-gated call checks the profile's site-role grant and the publisher's live role; losing the role denies the next such call. The [site-role tests](../../../packages/worker/src/package-runtime/package-app-profile.node.test.ts) cover both checks. The `grants` table only names org resources. 5. **Declared names stay the outer cap.** A call must be declared, then pass the profile layer and the publisher's live access. 6. **Fail closed.** A missing, revoked, expired, or other-org profile, or a publisher who left, makes the app unavailable with no fallback to a person. 7. **The owner hears about a denied call.** A call the profile or the publisher's live access refuses leaves a `profile_denied` row in `package_app_authority_rejections` (no handle, name, or value). Owners get an `app-call-denied` waiting item for it until the profile's grants are set again (`package_app_authority.profile_grants_applied_at`), telling them to approve its access or publish it again as the person the app should act as. 8. **A carried-forward approval carries its grants.** When an approved public app's next publish asks for nothing new, its approval carries forward, and the approved grants are applied to the new commit's profile, which is new when the publisher changed. Publishing an approved commit again keeps its approval the same way. Both the publisher and the original approver must still hold the access live; otherwise calls stay denied and the owner gets the waiting item. 9. **No runs-as pick.** The Owner's runs-as pick (`packageAppRunsAsSet`, `packageAppRunsAsGet`, and `package_app_authority.runs_as_person_id`) is gone. An app that had a pick now acts as its publisher and fails closed on what the publisher lacks. To change who an app acts as, publish it again as that person. The column was dropped (migration 0312) after a one-off site-admin report listed the apps that switched. ### Amendment (2026-11-30): site-admin capabilities follow the publisher Kent confirmed on 2026-11-30 that this is not a special case: an app is a profile derived from its publisher, so it can use the subset of what the publisher can do, including site-admin capabilities when the publisher is a site admin. There is no separate admin opt-in and no rule that the visitor must be an admin. The app gets a site-admin capability only when it declares it in `kody.app.capabilities`, its profile holds the site-role grant from publish (decision 4), and the publisher holds the role live. The bridge's caller carries no site roles; `shouldDeferSiteAccessToActor` defers the check to `assertTriggeredRunCanAccessSiteCapability`, which re-reads the publisher's roles on every call, and each call writes an `admin` audit row with `trigger=package-app`. Losing the role denies the next call. ### Why org-level surface grants stay within the ADR 0092 allowlist A capability's surface check is org-wide, but a profile passes it through any concrete grant of that permission, so concrete grants usually cover it. A capability whose permission no concrete grant covers and the allowlist does not include stays ungranted, and its calls are denied at run time. Profiles never hold resource-family-wide access.