@north-light/cli 0.3.749 → 0.3.750
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/grants/owner.d.ts +7 -0
- package/dist/core/grants/owner.js +1 -0
- package/dist/core/graph/reader.js +3 -3
- package/dist/core/import/load/bind.d.ts +1 -1
- package/dist/core/import/load/bind.js +11 -8
- package/dist/core/spaces/permissions.js +1 -1
- package/dist/core/spaces/process.js +1 -1
- package/package.json +3 -3
- package/packages/crouter-api/dist/core/grants/owner.js +15 -0
- package/packages/crouter-api/dist/core/graph/reader.js +8 -5
- package/packages/crouter-api/dist/core/spaces/permissions.js +10 -4
- package/packages/crouter-api/dist/core/spaces/process.js +5 -3
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Scope } from '@north-light/identity';
|
|
2
|
+
/** Whether `sub` lies in `grantee`'s own namespace (`app:x` for `app:x` and `app:x/…`). A namespace owns itself and needs no grant row. */
|
|
3
|
+
export declare function isNamespaceOwner(grantee: string, sub: string): boolean;
|
|
4
|
+
/** Whether a run with no grant row may proceed as its namespace owner: `sub` is in the grantee's namespace and no grant id is named (a named grant that is gone or revoked still refuses). */
|
|
5
|
+
export declare function ownsWithoutRow(grantee: string, sub: string, grantId: string | null | undefined): boolean;
|
|
6
|
+
/** The scopes an owner principal holds with no grant row: the app's declared scopes (its `crtr_app_` token's), none when it declares none. */
|
|
7
|
+
export declare function ownerScopes(grantee: string): Scope[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var r=(p,e)=>o(p,"name",{value:e,configurable:!0});import{parsePrincipal as t,parseScope as i}from"@north-light/identity";import{pluginAppToken as a}from"../secrets.js";function c(p,e){const n=t(e);return n!==null&&n.kind==="app"&&n.namespace===p}r(c,"isNamespaceOwner");function l(p,e,n){return!n&&c(p,e)}r(l,"ownsWithoutRow");function f(p){return(a(p.replace(/^app:/,""))?.scopes??[]).map(e=>i(e))}r(f,"ownerScopes");export{c as isNamespaceOwner,f as ownerScopes,l as ownsWithoutRow};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
sub, grant_id, scopes_json, cwd, profile_id, app FROM nodes WHERE node_id = ?`).get(e);if(!a||!l)throw new Error(`no node ${e}`);const{grantee:p,sub:c,grant_id:d,scopes_json:f,cwd:
|
|
3
|
-
WHERE i.scheme = 'profile' AND i.external_id = ?`).get(e)??await
|
|
1
|
+
var D=Object.defineProperty;var s=(o,e)=>D(o,"name",{value:e,configurable:!0});import{coveredByAny as _,isSandboxedNode as B}from"../../shared/env.js";import{projectPaths as J}from"../../api/dto/profiles.js";import{existsSync as b}from"node:fs";import{CrtrError as P}from"../errors.js";import{getCachedProfile as x}from"../scoped-state/person-store.js";import{parseScope as A}from"@north-light/identity";import{isNamespaceOwner as N,ownerScopes as F}from"../grants/owner.js";import{activeGrant as L,grantFor as M,runtimeScope as k}from"../grants/mirror.js";import{withCanvasWrite as G}from"../canvas/db.js";import{ApiError as q}from"../../api/errors.js";import{pluginAppToken as U}from"../secrets.js";import{loadExactProfileManifest as Y}from"../profiles/manifest.js";import{ensureOwner as T,getById as z,nodeObject as K,ownerForGrantee as Q,profileHandle as V}from"./objects.js";import{personId as X,personIdAsync as Z}from"../canvas/person.js";import{OBJECT_TYPE as I}from"../permissions/builtin.js";import{warmCheckoutDirs as H}from"../checkout-identities.js";import{fillProfileProjectRepo as ee}from"../profiles/manifest.js";import{emitEvent as oe}from"../events/emit.js";import{isCloudRole as R}from"../canvas/person-state.js";import{loadReadAccess as ne,readableAmong as te,prefetchRepoReads as re,reposForCwd as ae,warmCheckoutIdentities as v}from"./repo-sync/repos.js";async function W(o,e,n,r,t,a){const l=n===null?[]:t.projects(n),p=l.length===0?void 0:a??await Z(),c=p===void 0?void 0:await ne(o,p);c!==void 0&&p!==void 0&&await re(o,p,[e,...l.flatMap(i=>i.path!==void 0&&(R()||b(i.path))?[i.path]:[])],c);const d=l.flatMap(i=>i.repo===void 0?[]:[i.repo]),f=p===void 0?new Set:await te(o,p,d,c),h=await r(e,a,c),w=new Set(h.map(i=>i.repo.id)),E=[],m=[];for(const i of l){if(i.repo!==void 0&&!w.has(i.repo)){const u=await t.object(i.repo);u!==null&&u.type==="repo"&&u.deleted_at===null&&f.has(u.id)&&(w.add(u.id),E.push(u))}if(i.path===void 0||!R()&&!b(i.path))continue;let O;try{O=await r(i.path,a,c)}catch(u){if(u instanceof P&&u.code==="git-lookup-failed")continue;throw u}for(const u of O)w.has(u.repo.id)||(w.add(u.repo.id),E.push(u.repo),m.push(u))}return{repos:h.map(i=>i.repo),checkouts:h,projectRepos:E,projectCheckouts:m}}s(W,"viewRepos");async function Le(o,e){const n=await o.prepare("SELECT cwd, profile_id FROM nodes WHERE node_id = ?").get(e);if(n===void 0)return;const r=n.profile_id?J(j(o).projects(n.profile_id)):[];if(R()){await se(n.profile_id,[n.cwd,...r]);return}await v(n.cwd);for(const t of r)b(t)&&await v(t)}s(Le,"warmNodeRepos");async function se(o,e){if(await H(o,e),o!==null){for(const n of x(o)?.manifest.projects??[])if(!(n.path===void 0||n.repo!==void 0))try{const r=(await G(async t=>await ae(t,n.path)))[0];r!==void 0&&await ee(o,n.path,r.id)}catch(r){oe({level:"warn",event:"repo.identify.fill_failed",error:r,fields:{profile:o,path:n.path}})}}}s(se,"warmCloudNodeCheckouts");async function Me(o,e,n){if(!R()){for(const t of n)await v(t);return}const r=e===void 0?void 0:await o.prepare("SELECT profile_id FROM nodes WHERE node_id = ?").get(e);await H(r?.profile_id,n)}s(Me,"warmNodeDirs");async function Te(o,e,n){if(e.class==="anonymous")throw new Error("a publish token cannot read as a principal");if(e.class==="person")return{class:"person",person:await C(o)};if(e.class==="app")return{class:"app",app:await S(o,e.app),scopes:e.scopes,...e.sub===void 0?{}:{sub:e.sub}};if(e.class==="machine"||e.class==="import")throw new Error(`a ${e.class} token cannot read as a principal`);if(e.class==="forwarded"){if(e.actor.kind==="person")return{class:"person",person:await C(o)};const p=await M(e.actor.app,e.sub),c=p?p.resolved:N(e.actor.app,e.sub)?F(e.actor.app):null;if(c===null)throw new q(403,"app_not_granted",`${e.actor.app} holds no active grant for ${e.sub} on this machine`);const d=e.actor.node_scopes;return{class:"app",app:await S(o,e.actor.app),sub:e.sub,place:e.actor.place,launched:d,scopes:d===null?c:d.filter(f=>_(c,f))}}if(e.class==="cron"){const p=e.grant?(await L(e.grant))?.resolved??[]:[],c=e.scopes;return{class:"app",app:await S(o,e.app),scopes:c===null?p:c.filter(d=>_(p,d)),launched:c,place:{run:e.origin_run??"",isolated:e.isolated}}}const r=j(o),t=await K(o,e.node),a=await o.prepare("SELECT cwd, profile_id, app FROM nodes WHERE node_id = ?").get(e.node),l=a.app===null?null:await r.object(a.app);if(!l)throw new Error(`node ${e.node} has no app`);return{class:"node",node:t,app:l,scopes:await $(e.app,e.sub,e.grant,e.scopes,r),launched:e.scopes,cwd:a.cwd,...await W(o,a.cwd,a.profile_id,n,r,e.sub||void 0),profile:a.profile_id===null?null:await r.profile(a.profile_id,l)}}s(Te,"readerFor");async function pe(o,e,n,r=j(o),t=!1){const a=await o.prepare("SELECT o.* FROM objects o WHERE o.id = ? AND o.type = 'node'").get(e),l=await o.prepare(`SELECT (SELECT external_id FROM identities WHERE object = nodes.app) AS grantee,
|
|
2
|
+
sub, grant_id, scopes_json, cwd, profile_id, app FROM nodes WHERE node_id = ?`).get(e);if(!a||!l)throw new Error(`no node ${e}`);const{grantee:p,sub:c,grant_id:d,scopes_json:f,cwd:h,profile_id:w,app:E}=l,m=E===null?null:await r.object(E);if(!m)throw new Error(`node ${e} has no app`);const i=f===null?null:JSON.parse(f);return{class:"node",node:a,app:m,scopes:await $(p,c??"",d,i,r,t),launched:i,cwd:h,...await W(o,h,w,n,r,c||void 0),profile:w===null?null:await r.profile(w,m)}}s(pe,"readerForNode");class ce extends Error{static{s(this,"NoOwningAppError")}constructor(){super("no terminal app or person object"),this.name="NoOwningAppError"}}async function He(o,e,n=async()=>[],r=j(o)){const t=await o.prepare("SELECT envelope_json FROM peer_stubs WHERE object = ?").get(e.id);if(t!==void 0)return await ie(o,e,t.envelope_json===null?null:JSON.parse(t.envelope_json),r);if(e.type==="node")return await pe(o,e.id,n,r,!0);const a=e.owner===null?null:await r.object(e.owner);if(!a)throw new Error(`watcher ${e.id} has no owner`);const p=(a.type==="app"?a:a.type==="profile"&&a.owner!==null?await r.object(a.owner):null)??await o.prepare("SELECT o.* FROM identities i JOIN objects o ON o.id = i.object WHERE i.external_id = 'app:terminal' AND i.scheme = 'app'").get()??await o.prepare("SELECT * FROM objects WHERE type = 'person' AND name = 'user' AND home_machine IS NULL").get();if(!p)throw new ce;const c=(await o.prepare("SELECT external_id FROM identities WHERE object = ? AND scheme = 'app'").get(p.id))?.external_id??"app:terminal",d=k(),f=await o.prepare(`SELECT sub, resolved_scopes_json FROM grants WHERE grantee = ? AND status = 'active'${d.sql}`).all(c,...d.args),h=s(g=>JSON.parse(g.resolved_scopes_json).filter(y=>y.mode==="always").map(y=>A(y.scope)),"always"),w=f.length>1&&(a.type==="app"||a.type==="repo")?new Set((await o.prepare("SELECT subject_id FROM relations WHERE resource_type = ? AND resource_id = ? AND relation = 'acts_for' AND subject_type = 'user'").all(I,a.type==="repo"?a.id:e.id)).map(g=>g.subject_id)):null,E=w===null?void 0:f.find(g=>w.has(g.sub.replace(/^user:/,"")))?.sub,m=E===void 0?null:await r.grantFor(c,E),i=a.type==="person"?null:f.length===0?r.pluginScopes(c):f.length===1?h(f[0]):m?.resolved??null,u=(a.type==="person"?(await o.prepare("SELECT external_id FROM identities WHERE object = ? AND scheme = 'user'").get(a.id))?.external_id:void 0)??(f.length===1?f[0].sub:m?.sub);return{class:"object",object:e,node:e,owner:a,app:p,scopes:i,...u===void 0?{}:{sub:u},repos:a.type==="repo"?[a]:[]}}s(He,"readerForObject");async function We(o,e,n){const r=(await o.prepare("SELECT external_id FROM identities WHERE object = ? AND scheme = 'app'").get(e.id))?.external_id;if(r===void 0)return null;const t=await o.prepare("SELECT resolved_scopes_json FROM grants WHERE grantee = ? AND status = 'active'").all(r);return t.length===0?n.pluginScopes(r):t.length>1?null:JSON.parse(t[0].resolved_scopes_json).filter(a=>a.mode==="always").map(a=>A(a.scope))}s(We,"appScopesNow");async function ie(o,e,n,r){const t=await C(o);if(n!==null&&n.app===null)return{class:"object",object:e,node:e,owner:t,app:t,scopes:null,repos:[]};const a=n?.app==null?null:await S(o,n.app),l=n?.app==null?null:await r.grantFor(n.app,n.sub),p=l!==null?l.resolved:n?.app!=null&&N(n.app,n.sub)?F(n.app):null,c=n===null||p===null?null:n.node_scopes===null?p:n.node_scopes.filter(f=>_(p,f)),d=a??(e.owner===null?t:await r.object(e.owner)??t);return{class:"object",object:e,node:e,owner:d,app:d,scopes:c,launched:n?.node_scopes??null,repos:[],...n?.place==null?{}:{place:n.place}}}s(ie,"readerForStub");function j(o){return{grantById:L,grantFor:M,pluginScopes:s(e=>U(e.replace(/^app:/,""))?.scopes??null,"pluginScopes"),object:s(async e=>await z(o,e),"object"),profile:s(async(e,n)=>await le(o,e,n),"profile"),projects:s(e=>B()?[]:x(e)?.manifest.projects??[],"projects")}}s(j,"liveLookups");function $e(o){const e=j(o),n=new Map,r=s((t,a)=>(n.has(t)||n.set(t,a()),n.get(t)),"memo");return{grantById:s(t=>r(`g\0${t}`,()=>e.grantById(t)),"grantById"),grantFor:s((t,a)=>r(`a\0${t}\0${a}`,()=>e.grantFor(t,a)),"grantFor"),pluginScopes:s(t=>r(`t\0${t}`,()=>e.pluginScopes(t)),"pluginScopes"),object:s(async t=>await r(`o\0${t}`,async()=>await e.object(t)),"object"),profile:s(async(t,a)=>await r(`p\0${t}\0${a.id}`,async()=>await e.profile(t,a)),"profile"),projects:s(t=>r(`j\0${t}`,()=>e.projects(t)),"projects")}}s($e,"publishLookups");async function $(o,e,n,r,t,a=!1){const l=n?await t.grantById(n):await t.grantFor(o,e),p=l&&l.grantee===o?l.resolved:l===null&&n===null&&N(o,e)?F(o):null;if(p===null){if(a)return null;throw new Error(`the grant of ${o} is not active`)}return r===null?p:r.filter(c=>_(p,c))}s($,"nodeScopes");async function C(o){return await Q(o,X())}s(C,"personObject");async function S(o,e){return await T(o,"app","app",e,e.replace(/^app:/,""))}s(S,"appObject");async function le(o,e,n){return await o.prepare(`SELECT o.* FROM identities i JOIN objects o ON o.id = i.object
|
|
3
|
+
WHERE i.scheme = 'profile' AND i.external_id = ?`).get(e)??await T(o,"profile","profile",e,V(e,Y(e).manifest.name),n)}s(le,"profileObject");export{ce as NoOwningAppError,We as appScopesNow,j as liveLookups,le as profileObject,$e as publishLookups,Te as readerFor,pe as readerForNode,He as readerForObject,W as viewRepos,se as warmCloudNodeCheckouts,Me as warmNodeDirs,Le as warmNodeRepos};
|
|
@@ -8,7 +8,7 @@ export declare function checkSourcePerson(db: CanvasDb, target: string, source:
|
|
|
8
8
|
* (`crtr/group` relations). Returns rows dropped per table. */
|
|
9
9
|
export declare function checkStagedPersons(input: RewriteInput): Promise<Record<string, number>>;
|
|
10
10
|
/** After rewrite 2 and the drop: every reference from a staged row to a target row reaches a row the run's person owns or acts for (an app, a shipped
|
|
11
|
-
* document, the person's own object, an object with an `acts_for` fact for the person, an object this person's earlier run of the same install inserted,
|
|
11
|
+
* document, the person's own object, an object with an `acts_for` fact for the person, an object a group the person is a member of is granted (a repo document its team shares), an object this person's earlier run of the same install inserted,
|
|
12
12
|
* or anything below those that is not directly under an app), and no profile or grant the rows name belongs to another person.
|
|
13
13
|
*
|
|
14
14
|
* The earlier run's objects are the person's by construction, and a re-load must accept them: the drop step removes every staged document the target already
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var P=Object.defineProperty;var c=(n,t)=>P(n,"name",{value:t,configurable:!0});import{parseBlobKey as
|
|
2
|
-
UNION ALL SELECT 'grants' FROM ${
|
|
3
|
-
UNION ALL SELECT 'nodes' FROM ${
|
|
4
|
-
WHERE adapter_json::jsonb #>> '{principal,sub}' IS NOT NULL AND adapter_json::jsonb #>> '{principal,sub}' NOT IN (?, ?) LIMIT 5`,p,
|
|
5
|
-
WHERE m.table_name = 'objects' AND r.source_install_id = ? AND r.person = ? AND r.run_id <> ? AND r.state IN ('committed', 'done', 'failed')`,t.installId,t.person,t.runId)).flatMap(p=>J(p.inserted_keys).map(
|
|
6
|
-
AND ${f(
|
|
1
|
+
var P=Object.defineProperty;var c=(n,t)=>P(n,"name",{value:t,configurable:!0});import{parseBlobKey as w}from"../bundle/blob-keys.js";import{q as f}from"./catalog.js";import{decodeKeys as J}from"./copy.js";import{objectIdColumns as Y}from"./rewrite.js";import{ImportLaneError as F}from"./stage.js";const K=/^user:[A-Za-z0-9._-]+$/,C=c(n=>n.replace(/^user:/,""),"bare"),g=c((n,t)=>`${f(n)}.${f(t)}`,"sq"),N=c(async(n,t,...a)=>await n.prepareUncached(t).all(...a),"all");function T(n,t){return new F("bind","person_mismatch",n,t)}c(T,"mismatch");function se(n,t,a,p){if(n===t||n===a)return a;throw T(`${p} names ${n}, which is neither the bundle's person nor the importing person`,{where:p,value:n})}c(se,"boundSub");async function ne(n,t,a,p){if(!K.test(a))throw T(`the bundle's person ${JSON.stringify(a)} is not a user:<id> principal`,{where:"source.json person",value:a});if(a===p)return;const u=c(r=>g(t,r),"T"),o=await n.prepareUncached(`SELECT 'identities' AS tbl FROM ${u("identities")} WHERE scheme IN ('user', 'local-user') AND external_id = ?
|
|
2
|
+
UNION ALL SELECT 'grants' FROM ${u("grants")} WHERE sub = ? UNION ALL SELECT 'profiles' FROM ${u("profiles")} WHERE person = ?
|
|
3
|
+
UNION ALL SELECT 'nodes' FROM ${u("nodes")} WHERE sub = ? LIMIT 1`).get(a,a,a,a);if(o!==void 0)throw T(`the bundle's person ${a} is already a person in the target (${o.tbl}), not the importing person ${p}`,{where:`${o.tbl}`,value:a})}c(ne,"checkSourcePerson");const B=[["nodes","sub"],["crons","sub"],["grants","sub"],["profiles","person"],["charges","sub"],["limits","sub"],["audit_rows","sub"],["provider_approvals","sub"],["uploads","sub"],["files","sub"],["shares","sub"]],z=[["charges","payer"],["limits","payer"],["audit_rows","payer"],["audit_rows","grantee"],["charges","grantee"],["run_events","grantee"],["idempotency_keys","grantee"],["uploads","grantee"],["files","grantee"],["provider_approvals","grantee"],["profiles","grantee"],["crons","grantee"]];async function re(n){const{db:t,schema:a,sourcePerson:p,targetPerson:u}=n,o=c(s=>g(a,s),"S"),r=c((s,d)=>{throw T(`${s} names ${d.join(", ")}, who is neither the bundle's person ${p} nor the importing person ${u}`,{where:s,values:d})},"refuse");for(const[s,d]of B){const _=await N(t,`SELECT DISTINCT ${f(d)} AS v FROM ${o(s)} WHERE ${f(d)} IS NOT NULL AND ${f(d)} <> '' AND ${f(d)} NOT IN (?, ?) LIMIT 5`,p,u);_.length>0&&r(`${s}.${d}`,_.map($=>$.v))}for(const[s,d]of z){const _=await N(t,`SELECT DISTINCT ${f(d)} AS v FROM ${o(s)} WHERE ${f(d)} LIKE 'user:%' AND ${f(d)} NOT IN (?, ?) LIMIT 5`,p,u);_.length>0&&r(`${s}.${d}`,_.map($=>$.v))}const b=await N(t,`SELECT DISTINCT external_id AS v FROM ${o("identities")} WHERE scheme IN ('user', 'local-user') AND external_id NOT IN (?, ?) LIMIT 5`,p,u);b.length>0&&r("identities.external_id",b.map(s=>s.v));const h=await N(t,`SELECT DISTINCT adapter_json::jsonb #>> '{principal,sub}' AS v FROM ${o("daemon_actions")}
|
|
4
|
+
WHERE adapter_json::jsonb #>> '{principal,sub}' IS NOT NULL AND adapter_json::jsonb #>> '{principal,sub}' NOT IN (?, ?) LIMIT 5`,p,u);h.length>0&&r("daemon_actions principal.sub",h.map(s=>s.v));const l=await N(t,`SELECT DISTINCT subject_id AS v FROM ${o("relations")} WHERE relation = 'acts_for' AND subject_type = 'user' AND subject_id NOT IN (?, ?) LIMIT 5`,C(p),C(u));l.length>0&&r("relations acts_for subject",l.map(s=>s.v));const E=Number((await t.prepareUncached(`DELETE FROM ${o("relations")} WHERE resource_type = 'crtr/group'`).run()).changes);return E>0?{relations:E}:{}}c(re,"checkStagedPersons");async function G(n,t){return(await N(n,`SELECT m.inserted_keys FROM import_manifest m JOIN import_runs r ON r.run_id = m.run_id
|
|
5
|
+
WHERE m.table_name = 'objects' AND r.source_install_id = ? AND r.person = ? AND r.run_id <> ? AND r.state IN ('committed', 'done', 'failed')`,t.installId,t.person,t.runId)).flatMap(p=>J(p.inserted_keys).map(u=>u[0]))}c(G,"earlierImportedObjects");async function ae(n,t){const{db:a,schema:p,catalog:u,targetPerson:o}=n,r=await H(n,t);if(r.length>0)throw T(`the bundle refers to objects that are not ${o}'s: ${r.slice(0,10).map(b=>`${b.tbl}.${b.col}=${b.value}`).join(", ")}`,{references:r.slice(0,10)});await V(n)}c(ae,"checkStagedReferences");async function ie(n,t){const{db:a,schema:p,catalog:u}=n;if(!u.tables.has("messages"))return{};const o=c(s=>g(p,s),"S"),r=[...new Set((await H(n,t)).filter(s=>s.tbl==="messages").map(s=>s.value))];if(r.length===0)return{};const b="(object_id = ANY(?::text[]) OR actor_id = ANY(?::text[]))",h=`(SELECT message_id FROM ${o("messages")} WHERE ${b})`,l={};for(const[s,d]of[["deliveries","message_id"],["message_causes","message_id"]]){if(!u.tables.has(s))continue;const _=Number((await a.prepareUncached(`DELETE FROM ${o(s)} WHERE ${d} IN ${h}`).run(r,r)).changes);_>0&&(l[s]=_)}const E=Number((await a.prepareUncached(`DELETE FROM ${o("messages")} WHERE ${b}`).run(r,r)).changes);return E>0&&(l.messages=E),l}c(ie,"dropRefusedMessages");async function H(n,t){const{db:a,schema:p,target:u,catalog:o,targetPerson:r}=n,b=c(_=>g(p,_),"S"),h=c(_=>g(u,_),"T"),l=C(r);await a.exec(`CREATE TABLE ${b("_refs")} (tbl text NOT NULL, col text NOT NULL, value text NOT NULL)`);const E=[];for(const[_,$]of Y(o))if(!(!o.tables.has(_)||_==="relations"))for(const m of $)!(_==="nodes"&&m==="profile_id")&&!(_==="crons"&&m==="profile")&&E.push([_,m,""]);E.push(["relations","resource_id","WHERE resource_type = 'crtr/object'"]);for(const[_,$,m]of E)await a.prepareUncached(`INSERT INTO ${b("_refs")} SELECT ?, ?, ${f($)}::text FROM ${b(_)} ${m===""?"WHERE":`${m} AND`} ${f($)} IS NOT NULL
|
|
6
|
+
AND ${f($)}::text NOT IN (SELECT id FROM ${b("objects")}) AND ${f($)}::text IN (SELECT id FROM ${h("objects")})`).run(_,$);const s=await G(a,t),d=await N(a,`WITH RECURSIVE chain(start, id) AS (
|
|
7
7
|
SELECT DISTINCT value, value FROM ${b("_refs")}
|
|
8
8
|
UNION SELECT c.start, o.owner FROM chain c JOIN ${h("objects")} o ON o.id = c.id JOIN ${h("objects")} up ON up.id = o.owner AND up.type <> 'app'),
|
|
9
9
|
ok(id) AS (
|
|
@@ -11,7 +11,10 @@ var P=Object.defineProperty;var c=(n,t)=>P(n,"name",{value:t,configurable:!0});i
|
|
|
11
11
|
UNION SELECT d.object FROM ${h("documents")} d WHERE d.source_path IS NOT NULL
|
|
12
12
|
UNION SELECT i.object FROM ${h("identities")} i WHERE i.scheme IN ('user', 'local-user') AND i.external_id = ?
|
|
13
13
|
UNION SELECT r.resource_id FROM ${h("relations")} r WHERE r.resource_type = 'crtr/object' AND r.relation = 'acts_for' AND r.subject_type = 'user' AND r.subject_id = ?
|
|
14
|
+
UNION SELECT r.resource_id FROM ${h("relations")} r JOIN ${h("relations")} m ON m.resource_type = 'crtr/group' AND m.relation = 'member' AND m.resource_id = r.subject_id
|
|
15
|
+
AND m.subject_type = 'user' AND m.subject_id = ?
|
|
16
|
+
WHERE r.resource_type = 'crtr/object' AND r.relation IN ('reader', 'editor', 'messenger', 'user_of') AND r.subject_type = 'crtr/group' AND r.subject_relation = 'member'
|
|
14
17
|
UNION SELECT unnest(?::text[]))
|
|
15
18
|
SELECT r.tbl, r.col, r.value FROM ${b("_refs")} r
|
|
16
|
-
WHERE NOT EXISTS (SELECT 1 FROM chain c JOIN ok ON ok.id = c.id WHERE c.start = r.value)`,r,l,s);return await a.exec(`DROP TABLE ${b("_refs")}`),
|
|
17
|
-
JOIN ${r("grants")} g ON g.id = d.adapter_json::jsonb #>> '{principal,grant_id}' WHERE g.sub <> ? LIMIT 5`,
|
|
19
|
+
WHERE NOT EXISTS (SELECT 1 FROM chain c JOIN ok ON ok.id = c.id WHERE c.start = r.value)`,r,l,l,s);return await a.exec(`DROP TABLE ${b("_refs")}`),d}c(H,"foreignReferences");async function V(n){const{db:t,schema:a,target:p,targetPerson:u}=n,o=c(l=>g(a,l),"S"),r=c(l=>g(p,l),"T"),b=[["nodes","profile_id"],["crons","profile"],["profiles","id"]];for(const[l,E]of b){const s=await N(t,`SELECT DISTINCT s.${f(E)} AS v FROM ${o(l)} s JOIN ${r("profiles")} p ON p.id = s.${f(E)} WHERE p.person <> ? LIMIT 5`,u);if(s.length>0)throw T(`${l}.${E} names profiles that belong to another person: ${s.map(d=>d.v).join(", ")}`,{where:`${l}.${E}`,values:s.map(d=>d.v)})}for(const[l,E]of[["nodes","grant_id"],["crons","grant_id"]]){const s=await N(t,`SELECT DISTINCT s.${f(E)} AS v FROM ${o(l)} s JOIN ${r("grants")} g ON g.id = s.${f(E)} WHERE g.sub <> ? LIMIT 5`,u);if(s.length>0)throw T(`${l}.${E} names grants that belong to another person: ${s.map(d=>d.v).join(", ")}`,{where:`${l}.${E}`,values:s.map(d=>d.v)})}const h=await N(t,`SELECT DISTINCT d.adapter_json::jsonb #>> '{principal,grant_id}' AS v FROM ${o("daemon_actions")} d
|
|
20
|
+
JOIN ${r("grants")} g ON g.id = d.adapter_json::jsonb #>> '{principal,grant_id}' WHERE g.sub <> ? LIMIT 5`,u);if(h.length>0)throw T(`a queued action names grants that belong to another person: ${h.map(l=>l.v).join(", ")}`,{where:"daemon_actions principal.grant_id",values:h.map(l=>l.v)})}c(V,"checkStagedProfilesAndGrants");const k=c((n,t)=>new F("bind","bundle_invalid",n,t),"bundleInvalid");async function ce(n){const{db:t,schema:a,target:p,targetPerson:u}=n,o=c(e=>g(a,e),"S"),r=new Set((await N(t,`SELECT node_id AS v FROM ${o("nodes")}`)).map(e=>e.v)),b=await N(t,`SELECT conversation_id, seq::text AS seq, blob_key FROM ${o("conversation_parts")}`),h=await N(t,`SELECT run_id, path, blob_key FROM ${o("upload_uses")} WHERE blob_key IS NOT NULL`),l=await N(t,`SELECT object, output_key FROM ${o("jobs")} WHERE output_key IS NOT NULL`),E=c(e=>e.split("/")[1]??"","jobOwner"),s=c((e,i,S,O)=>{const D=w(i);if(D===null||D.kind!==S||O!==void 0&&i!==O)throw k(`${e} holds ${JSON.stringify(i)}, which is not a ${S} blob key${O===void 0?"":` of the shape ${O}`}`,{where:e,value:i})},"shaped");for(const e of b)if(s("conversation_parts.blob_key",e.blob_key,"conversation"),e.blob_key.split("/")[2]!==e.conversation_id)throw k(`conversation_parts.blob_key ${e.blob_key} is not under its conversation ${e.conversation_id}`,{where:"conversation_parts.blob_key",value:e.blob_key});for(const e of h)s("upload_uses.blob_key",e.blob_key,"attachment");for(const e of l)s("jobs.output_key",e.output_key,"job",`jobs/${E(e.output_key)}/${e.object}/output`);const d=new Set;for(const{blob_key:e}of b){const i=w(e);i!==null&&i.kind==="conversation"&&!r.has(i.owner)&&d.add(i.owner)}for(const{blob_key:e}of h){const i=w(e);i!==null&&i.kind==="attachment"&&!r.has(i.owner)&&d.add(i.owner)}for(const{output_key:e}of l)r.has(E(e))||d.add(E(e));const _=new Map((d.size===0?[]:await N(t,`SELECT node_id, sub FROM ${g(p,"nodes")} WHERE node_id = ANY(?::text[])`,[...d])).map(e=>[e.node_id,e.sub])),$=c(e=>r.has(e)||_.get(e)===u,"held"),m=c(e=>!r.has(e)&&!_.has(e),"gone"),A={},I=c((e,i)=>{i>0&&(A[e]=(A[e]??0)+i)},"count"),R=c(async(e,...i)=>Number((await t.prepareUncached(e).run(...i)).changes),"drop"),W=new Set((await N(t,`SELECT DISTINCT session_id AS v FROM ${o("sessions")} WHERE session_id IS NOT NULL`)).map(e=>e.v)),L=new Map;for(const{conversation_id:e,blob_key:i}of b){const S=w(i),O=L.get(e);O!==null&&(S===null||S.kind!=="conversation"?L.set(e,null):L.set(e,[...O??[],S.owner]))}const v=[...L].filter(([e,i])=>i!==null&&!W.has(e)&&i.every(m)).map(([e])=>e);v.length>0&&(I("conversation_parts",await R(`DELETE FROM ${o("conversation_parts")} WHERE conversation_id = ANY(?::text[])`,v)),I("conversation_entries",await R(`DELETE FROM ${o("conversation_entries")} WHERE conversation_id = ANY(?::text[])`,v)));const U=new Set(v),j=c((e,i)=>{const S=w(i).owner;if(!$(S))throw T(`${e} holds ${i}, which belongs to node ${S}, who is not in the bundle`,{where:e,value:i})},"owned");for(const e of b)U.has(e.conversation_id)||j("conversation_parts.blob_key",e.blob_key);const y=h.filter(e=>{const i=w(e.blob_key);return i!==null&&i.kind==="attachment"&&m(i.owner)&&!r.has(e.run_id)});y.length>0&&I("upload_uses",await R(`DELETE FROM ${o("upload_uses")} u USING unnest(?::text[], ?::text[]) d(run_id, path) WHERE u.run_id = d.run_id AND u.path = d.path`,y.map(e=>e.run_id),y.map(e=>e.path)));const x=new Set(y);for(const e of h)x.has(e)||j("upload_uses.blob_key",e.blob_key);const M=l.filter(e=>e.output_key===`jobs/${E(e.output_key)}/${e.object}/output`&&m(E(e.output_key)));M.length>0&&I("jobs",await R(`DELETE FROM ${o("jobs")} WHERE object = ANY(?::text[])`,M.map(e=>e.object)));const q=new Set(M);for(const e of l)q.has(e)||j("jobs.output_key",e.output_key);return A}c(ce,"checkStagedBlobKeys");async function ue(n){const{db:t,schema:a}=n;for(const p of await N(t,`SELECT request_id, request_dir, presentation_dir, file FROM ${g(a,"human_requests")}`))for(const u of["request_dir","presentation_dir","file"]){const o=p[u];if(o===null||!o.startsWith("requests/"))continue;const r=w(o.includes("/",9)?o:`${o}/x`);if(r===null||r.kind!=="request")throw k(`human_requests.${u} holds ${JSON.stringify(o)}, which is not a request blob key`,{where:`human_requests.${u}`,value:o});if(r.owner!==p.request_id)throw T(`human_requests.${u} of ${p.request_id} holds ${o}, which belongs to request ${r.owner}`,{where:`human_requests.${u}`,value:o})}}c(ue,"checkStagedRequestKeys");export{se as boundSub,ne as checkSourcePerson,ce as checkStagedBlobKeys,re as checkStagedPersons,ae as checkStagedReferences,ue as checkStagedRequestKeys,ie as dropRefusedMessages};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var b=Object.defineProperty;var f=(r,n)=>b(r,"name",{value:n,configurable:!0});import{parseScope as A}from"@north-light/identity";import{coveredByAny as p}from"../../shared/env.js";import{activeGrant as E,grantFor as F}from"../grants/mirror.js";import{isNamespaceOwner as j,ownerScopes as z}from"../grants/owner.js";import{appSpace as h,userFilesRoot as N}from"../layout.js";import{contains as y}from"./file-root.js";import{join as R,resolve as l}from"node:path";import{lstatSync as Z,realpathSync as d}from"node:fs";async function D(r,n,o,t){const e=o?await E(o):await F(r,n);if(o&&!e)throw new Error(`no active grant for ${r}`);return _(r,n,e,t)}f(D,"permissionsForRun");function _(r,n,o,t){if(o?o.grantee!==r||o.sub!==n:!j(r,n))throw new Error(`no active grant for ${r}`);if(t!==null&&!Array.isArray(t))throw new Error("invalid launched scopes");const e=[],s=[];let c=t===null;const m=o?o.resolved:z(r),$=t??m;for(const i of $){if(typeof i!="string")throw new Error("invalid launched scope");A(i);const v=i===`crtr:memory:read:${r}`||i===`crtr:memory:rw:${r}`||i.startsWith(`crtr:memory:read:${r}:`)||i.startsWith(`crtr:memory:rw:${r}:`);if(t!==null&&!v&&!p(m,i))throw new Error(`launched scope not in grant: ${i}`);const w=/^crtr:files:(read|rw):(user|app:[A-Za-z0-9_-]{1,64}):(.+)$/.exec(i);if(w){const[,x,u,S]=w;if(u===r)throw new Error(`own-app files cannot narrow a run: ${i}`);e.push({holder:u,path:S,writable:x==="rw"})}const a=/^crtr:objects:read:(app:[A-Za-z0-9_-]{1,64})$/.exec(i);a&&a[1]!==r&&s.push(a[1])}return{app:r,ownNodes:c,otherFiles:e,otherNodes:s}}f(_,"permissionsForGrant");function k(r,n){const o=l(r);for(const t of n){const e=l(t);if(y(e,o))try{if(d(o)!==o||d(e)!==e)continue;let s=o;for(;y(e,s)&&!Z(s).isSymbolicLink();){if(s===e)return!0;s=l(s,"..")}}catch{}}return!1}f(k,"readableProject");function H(r,n,o,t){const e=[h(n).files];for(const s of t??o){if(t!==null&&!p(o,s))continue;const c=/^crtr:files:(?:read|rw):(user|app:[A-Za-z0-9_-]{1,64}):(.+)$/.exec(s);c&&e.push(R(c[1]==="user"?N():h(c[1]).files,c[2]==="."?"":c[2]))}return k(r,e)}f(H,"readableProjectForScopes");import{fileRoot as M}from"./file-root.js";export{M as fileRoot,_ as permissionsForGrant,D as permissionsForRun,k as readableProject,H as readableProjectForScopes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var N=Object.defineProperty;var u=(e,r)=>N(e,"name",{value:r,configurable:!0});import{existsSync as R}from"node:fs";import{assertGranteeRunsHere as O}from"../runtime/unsandboxed.js";import{randomUUID as k}from"node:crypto";import{join as h}from"node:path";import{getNode as S}from"../canvas/canvas.js";import{nodeAgentDir as H,nodeHome as K,nodeRunDir as B}from"../canvas/paths.js";import{appSpace as F}from"../layout.js";import{activeGrant as g,activeGrantForApp as y,grantFor as I,grantsGeneration as G}from"../grants/mirror.js";import{ownsWithoutRow as b}from"../grants/owner.js";import{emitEvent as A}from"../events/emit.js";import{ensureAppSpace as M}from"./space.js";import{compileLaunch as D,launchStillGranted as j}from"./mounts.js";import{pinSandboxRuntimeHome as q}from"./runtime-home.js";import{sandboxCacheEnv as U}from"./cache-env.js";import{launcherRequest as E}from"../../launcher/client.js";import{LAUNCHER_SOCKET as L}from"../../launcher/spec.js";import{isCloudRole as W}from"../canvas/person.js";import{launchSub as x}from"../runs/node-sub.js";function z(e){return`cron-${e}`}u(z,"cronLaunchId");function we(){if(process.platform!=="linux")return!1;if(R(L))return!0;throw new Error("root launcher socket is unavailable; refusing an unsandboxed app process")}u(we,"appProcessSandboxed");function pe(){return P??(process.platform==="linux"&&R(L))}u(pe,"appProcessesSandboxed");let P;function he(e){P=e}u(he,"__setAppProcessesSandboxedForTest");async function ge(e,r,n,o=!1,i,d){const a=n===void 0?null:await S(n),s=d!==void 0?d.grantId?await g(d.grantId):await I(e,d.sub):a?null:await y(e);if(d!==void 0?!s&&!b(e,d.sub,d.grantId):!a&&!s)throw new Error(`no active grant for ${e}`);return(await D({nodeId:n??"proc-cwd-check",app:e,...d!==void 0?{sub:d.sub,grantId:s?.id??null,scopes:d.scopes}:{sub:a?x(a.sub,a.node_id):s.sub,grantId:a?a.grant_id??null:s.id,scopes:a?.scopes??null},command:["true"],env:{},...n===void 0?{withoutNode:!0}:{},...i===void 0?{}:{folder:i},isolated:a?.isolated===!0||o,auditMissing:u(()=>{},"auditMissing")})).mounts.some(({source:c})=>r===c||r.startsWith(c==="/"?"/":`${c}/`))}u(ge,"cwdIsMounted");async function C(e,r="SIGKILL",n){if(!("ok"in await E({operation:"stop",pid:e,signal:r,...n===void 0?{}:{nodeId:n}})))throw new Error("launcher did not stop process")}u(C,"stopAppProcess");function J(e,r,n,o,i){return o?i??H(e,r):n}u(J,"appProcessCwd");async function Ie(e){if(W())throw new Error("a cloud role launches no app process; the node runs in its sandbox");if(e.cron!==void 0&&(e.nodeId!==void 0||e.principal===void 0))throw new Error("a cron launch has a stored principal and no node");const r=e.nodeId===void 0?null:await S(e.nodeId);if(e.nodeId!==void 0&&!r)throw new Error(`missing node ${e.nodeId}`);const n=r?.grantee??e.app??"app:terminal";if(O(n),e.app!==void 0&&e.app!==n)throw new Error("app does not match node");const o=e.principal;let i=null;if(o!==void 0){if(i=o.grantId?await g(o.grantId):await I(n,o.sub),i?i.grantee!==n||i.sub!==o.sub:!b(n,o.sub,o.grantId))throw new Error(`no active grant for ${n}`)}else if(r){const t=x(r.sub,r.node_id);if(n!=="app:terminal"&&!b(n,t,r.grant_id)&&!(r.grant_id?await g(r.grant_id):await I(n,t)))throw new Error(`no active grant for ${n}`)}else if(i=await y(n),!i)throw new Error(`no active grant for ${n}`);await M(n);const d=e.cron===void 0?e.nodeId??`proc-${k()}`:z(e.cron.executionId),a=r?.isolated===!0||e.isolated===!0;if(a&&!r&&e.folder===void 0)throw new Error("isolated process requires a live node");const s=F(n),m=J(d,n,e.cwd,a,e.folder),c=r?K(d,n,a):a&&e.folder!==void 0?h(e.folder,"home"):s.home,T=q(Object.fromEntries(Object.entries({...e.env,...process.platform==="linux"?U(n):{},HOME:c,PI_CODING_AGENT_DIR:h(c,".pi","agent"),PWD:m,...e.nodeId===void 0&&e.cron===void 0?{}:{CRTR_API_SOCKET:h(B(d),"cli.sock")}}).filter(t=>t[1]!==void 0))),v=o!==void 0?{nodeId:d,app:n,sub:o.sub,grantId:i?.id??null,scopes:o.scopes}:{nodeId:d,app:n,sub:r?x(r.sub,r.node_id):i.sub,grantId:r?r.grant_id??null:i.id,scopes:r?.scopes??null},$=u(async()=>{const t=await D({...v,command:e.command,env:T,...e.nodeId===void 0?{withoutNode:!0}:{},isolated:a,cwd:m,...e.folder===void 0?{}:{folder:e.folder},...e.cron===void 0?{}:{cron:e.cron.anchorDir===void 0?{}:{anchorDir:e.cron.anchorDir}},...e.pluginRoot===void 0?{}:{pluginRoot:e.pluginRoot},auditMissing:u(p=>A({level:"warn",event:"process.mount.missing",...e.nodeId===void 0?{}:{node_id:e.nodeId},fields:{source:p}}),"auditMissing")});if(e.pluginRoot!==void 0&&(t.pluginRoot=e.pluginRoot),e.capture===!1){if(e.nodeId===void 0||e.stdin!==void 0)throw new Error("uncaptured process requires a node and no stdin")}else t.capture={stdoutBytes:e.stdoutBytes??256*1024,stderrBytes:e.stderrBytes??256*1024,...e.stderrTail?{stderrTail:!0}:{},...e.stdin===void 0?{}:{stdin:e.stdin}};return t},"compile");let f;for(let t=0;t<2&&f===void 0;t++){const p=await G(),_=await $(),l=await E({operation:"launch",spec:_});if(!("pid"in l))throw new Error("launcher did not return a process id");if(await G()===p||await j(v,_)){f=l.pid;break}A({level:"info",event:"process.launch.regranted",...e.nodeId===void 0?{}:{node_id:e.nodeId},fields:{pid:l.pid}}),await C(l.pid,"SIGKILL").catch(()=>{})}if(f===void 0)throw new Error("grant changed during every launch attempt");const w=f;return{pid:w,get completion(){return E({operation:"wait",pid:w}).then(t=>{if(!("result"in t))throw new Error("launcher did not return process completion");return t.result})},stop:u((t="SIGKILL")=>C(w,t,e.cron===void 0?e.nodeId:d),"stop")}}u(Ie,"launchAppProcess");export{he as __setAppProcessesSandboxedForTest,J as appProcessCwd,we as appProcessSandboxed,pe as appProcessesSandboxed,z as cronLaunchId,ge as cwdIsMounted,Ie as launchAppProcess,C as stopAppProcess};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.750",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -158,8 +158,8 @@
|
|
|
158
158
|
},
|
|
159
159
|
"license": "UNLICENSED",
|
|
160
160
|
"dependencies": {
|
|
161
|
-
"@north-light/identity": "0.3.
|
|
162
|
-
"@north-light/plugin": "0.3.
|
|
161
|
+
"@north-light/identity": "0.3.750",
|
|
162
|
+
"@north-light/plugin": "0.3.750",
|
|
163
163
|
"@earendil-works/chord": "1.5.2",
|
|
164
164
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
165
165
|
"@earendil-works/pi-ai": "1.5.2",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { parsePrincipal, parseScope } from '@north-light/identity';
|
|
2
|
+
import { pluginAppToken } from '../secrets.js';
|
|
3
|
+
/** Whether `sub` lies in `grantee`'s own namespace (`app:x` for `app:x` and `app:x/…`). A namespace owns itself and needs no grant row. */
|
|
4
|
+
export function isNamespaceOwner(grantee, sub) {
|
|
5
|
+
const principal = parsePrincipal(sub);
|
|
6
|
+
return principal !== null && principal.kind === 'app' && principal.namespace === grantee;
|
|
7
|
+
}
|
|
8
|
+
/** Whether a run with no grant row may proceed as its namespace owner: `sub` is in the grantee's namespace and no grant id is named (a named grant that is gone or revoked still refuses). */
|
|
9
|
+
export function ownsWithoutRow(grantee, sub, grantId) {
|
|
10
|
+
return !grantId && isNamespaceOwner(grantee, sub);
|
|
11
|
+
}
|
|
12
|
+
/** The scopes an owner principal holds with no grant row: the app's declared scopes (its `crtr_app_` token's), none when it declares none. */
|
|
13
|
+
export function ownerScopes(grantee) {
|
|
14
|
+
return (pluginAppToken(grantee.replace(/^app:/, ''))?.scopes ?? []).map((scope) => parseScope(scope));
|
|
15
|
+
}
|
|
@@ -4,6 +4,7 @@ import { existsSync } from 'node:fs';
|
|
|
4
4
|
import { CrtrError } from '../errors.js';
|
|
5
5
|
import { getCachedProfile } from '../scoped-state/person-store.js';
|
|
6
6
|
import { parseScope } from '@north-light/identity';
|
|
7
|
+
import { isNamespaceOwner, ownerScopes } from '../grants/owner.js';
|
|
7
8
|
import { activeGrant, grantFor, runtimeScope } from '../grants/mirror.js';
|
|
8
9
|
import { withCanvasWrite } from '../canvas/db.js';
|
|
9
10
|
import { ApiError } from '../../api/errors.js';
|
|
@@ -125,11 +126,12 @@ export async function readerFor(db, principal, reposFn) {
|
|
|
125
126
|
if (principal.actor.kind === 'person')
|
|
126
127
|
return { class: 'person', person: await personObject(db) };
|
|
127
128
|
const grant = await grantFor(principal.actor.app, principal.sub);
|
|
128
|
-
|
|
129
|
+
const resolved = grant ? grant.resolved : isNamespaceOwner(principal.actor.app, principal.sub) ? ownerScopes(principal.actor.app) : null;
|
|
130
|
+
if (resolved === null)
|
|
129
131
|
throw new ApiError(403, 'app_not_granted', `${principal.actor.app} holds no active grant for ${principal.sub} on this machine`);
|
|
130
132
|
const stored = principal.actor.node_scopes;
|
|
131
133
|
return { class: 'app', app: await appObject(db, principal.actor.app), sub: principal.sub, place: principal.actor.place, launched: stored,
|
|
132
|
-
scopes: stored === null ?
|
|
134
|
+
scopes: stored === null ? resolved : stored.filter((scope) => coveredByAny(resolved, scope)) };
|
|
133
135
|
}
|
|
134
136
|
if (principal.class === 'cron') {
|
|
135
137
|
// A cron has no node: it reads as its app, bounded by its stored scopes, each kept while the grant's current set covers it.
|
|
@@ -242,8 +244,9 @@ async function readerForStub(db, stub, identity, lookups) {
|
|
|
242
244
|
return { class: 'object', object: stub, node: stub, owner: person, app: person, scopes: null, repos: [] };
|
|
243
245
|
const app = identity?.app == null ? null : await appObject(db, identity.app);
|
|
244
246
|
const grant = identity?.app == null ? null : await lookups.grantFor(identity.app, identity.sub);
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
+
const resolved = grant !== null ? grant.resolved : identity?.app != null && isNamespaceOwner(identity.app, identity.sub) ? ownerScopes(identity.app) : null;
|
|
248
|
+
const scopes = identity === null || resolved === null ? null
|
|
249
|
+
: identity.node_scopes === null ? resolved : identity.node_scopes.filter((scope) => coveredByAny(resolved, scope));
|
|
247
250
|
const owner = app ?? (stub.owner === null ? person : await lookups.object(stub.owner) ?? person);
|
|
248
251
|
return { class: 'object', object: stub, node: stub, owner, app: owner, scopes, launched: identity?.node_scopes ?? null, repos: [],
|
|
249
252
|
...(identity?.place == null ? {} : { place: identity.place }) };
|
|
@@ -277,7 +280,7 @@ export function publishLookups(db) {
|
|
|
277
280
|
/** What the run may reach beyond its own app: the active grant, narrowed by the launched scope list. */
|
|
278
281
|
async function nodeScopes(app, sub, grantId, launched, lookups, allowRevoked = false) {
|
|
279
282
|
const grant = grantId ? await lookups.grantById(grantId) : await lookups.grantFor(app, sub);
|
|
280
|
-
const resolved = grant && grant.grantee === app ? grant.resolved : null;
|
|
283
|
+
const resolved = grant && grant.grantee === app ? grant.resolved : grant === null && grantId === null && isNamespaceOwner(app, sub) ? ownerScopes(app) : null;
|
|
281
284
|
if (resolved === null) {
|
|
282
285
|
if (allowRevoked)
|
|
283
286
|
return null;
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
import { parseScope } from '@north-light/identity';
|
|
2
2
|
import { coveredByAny } from '../../shared/env.js';
|
|
3
3
|
import { activeGrant, grantFor } from '../grants/mirror.js';
|
|
4
|
+
import { isNamespaceOwner, ownerScopes } from '../grants/owner.js';
|
|
4
5
|
import { appSpace, userFilesRoot } from '../layout.js';
|
|
5
6
|
import { contains } from './file-root.js';
|
|
6
7
|
import { join, resolve } from 'node:path';
|
|
7
8
|
import { lstatSync, realpathSync } from 'node:fs';
|
|
8
9
|
/** Only the active mirror and the launched scope list determine a run's mounts. */
|
|
9
10
|
export async function permissionsForRun(app, sub, grantId, launched) {
|
|
10
|
-
|
|
11
|
+
const grant = grantId ? await activeGrant(grantId) : await grantFor(app, sub);
|
|
12
|
+
// A revoked grant named by id never falls back to namespace ownership.
|
|
13
|
+
if (grantId && !grant)
|
|
14
|
+
throw new Error(`no active grant for ${app}`);
|
|
15
|
+
return permissionsForGrant(app, sub, grant, launched);
|
|
11
16
|
}
|
|
12
17
|
/** The same computation over a given grant record, e.g. the mirror before a sync replaced it. */
|
|
13
18
|
export function permissionsForGrant(app, sub, grant, launched) {
|
|
14
|
-
if (
|
|
19
|
+
if (grant ? grant.grantee !== app || grant.sub !== sub : !isNamespaceOwner(app, sub))
|
|
15
20
|
throw new Error(`no active grant for ${app}`);
|
|
16
21
|
if (launched !== null && !Array.isArray(launched))
|
|
17
22
|
throw new Error('invalid launched scopes');
|
|
18
23
|
const otherFiles = [];
|
|
19
24
|
const otherNodes = [];
|
|
20
25
|
let ownNodes = launched === null;
|
|
21
|
-
const
|
|
26
|
+
const resolved = grant ? grant.resolved : ownerScopes(app);
|
|
27
|
+
const scopes = launched ?? resolved;
|
|
22
28
|
for (const scope of scopes) {
|
|
23
29
|
if (typeof scope !== 'string')
|
|
24
30
|
throw new Error('invalid launched scope');
|
|
25
31
|
parseScope(scope);
|
|
26
32
|
const own = scope === `crtr:memory:read:${app}` || scope === `crtr:memory:rw:${app}` ||
|
|
27
33
|
scope.startsWith(`crtr:memory:read:${app}:`) || scope.startsWith(`crtr:memory:rw:${app}:`);
|
|
28
|
-
if (launched !== null && !own && !coveredByAny(
|
|
34
|
+
if (launched !== null && !own && !coveredByAny(resolved, scope))
|
|
29
35
|
throw new Error(`launched scope not in grant: ${scope}`);
|
|
30
36
|
const files = /^crtr:files:(read|rw):(user|app:[A-Za-z0-9_-]{1,64}):(.+)$/.exec(scope);
|
|
31
37
|
if (files) {
|
|
@@ -6,6 +6,7 @@ import { getNode } from '../canvas/canvas.js';
|
|
|
6
6
|
import { nodeAgentDir, nodeHome, nodeRunDir } from '../canvas/paths.js';
|
|
7
7
|
import { appSpace } from '../layout.js';
|
|
8
8
|
import { activeGrant, activeGrantForApp, grantFor, grantsGeneration } from '../grants/mirror.js';
|
|
9
|
+
import { ownsWithoutRow } from '../grants/owner.js';
|
|
9
10
|
import { emitEvent } from '../events/emit.js';
|
|
10
11
|
import { ensureAppSpace } from './space.js';
|
|
11
12
|
import { compileLaunch, launchStillGranted } from './mounts.js';
|
|
@@ -44,7 +45,7 @@ export async function cwdIsMounted(app, cwd, nodeId, isolated = false, folder, p
|
|
|
44
45
|
// A stored principal decides the grant and scopes even for an anchored run (see launchAppProcess).
|
|
45
46
|
const grant = principal !== undefined ? (principal.grantId ? await activeGrant(principal.grantId) : await grantFor(app, principal.sub))
|
|
46
47
|
: row ? null : await activeGrantForApp(app);
|
|
47
|
-
if (principal !== undefined ? !grant : !row && !grant)
|
|
48
|
+
if (principal !== undefined ? !grant && !ownsWithoutRow(app, principal.sub, principal.grantId) : !row && !grant)
|
|
48
49
|
throw new Error(`no active grant for ${app}`);
|
|
49
50
|
const spec = await compileLaunch({ nodeId: nodeId ?? `proc-cwd-check`, app,
|
|
50
51
|
...(principal !== undefined
|
|
@@ -88,11 +89,12 @@ export async function launchAppProcess(options) {
|
|
|
88
89
|
let grant = null;
|
|
89
90
|
if (stored !== undefined) {
|
|
90
91
|
grant = stored.grantId ? await activeGrant(stored.grantId) : await grantFor(app, stored.sub);
|
|
91
|
-
if (
|
|
92
|
+
if (grant ? grant.grantee !== app || grant.sub !== stored.sub : !ownsWithoutRow(app, stored.sub, stored.grantId))
|
|
92
93
|
throw new Error(`no active grant for ${app}`);
|
|
93
94
|
}
|
|
94
95
|
else if (row) {
|
|
95
|
-
|
|
96
|
+
const rowSub = launchSub(row.sub, row.node_id);
|
|
97
|
+
if (app !== 'app:terminal' && !ownsWithoutRow(app, rowSub, row.grant_id) && !(row.grant_id ? await activeGrant(row.grant_id) : await grantFor(app, rowSub))) {
|
|
96
98
|
throw new Error(`no active grant for ${app}`);
|
|
97
99
|
}
|
|
98
100
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.750",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.750",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@north-light/api": "0.3.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.750",
|
|
31
|
+
"@north-light/identity": "0.3.750"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.750",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.750",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.750",
|
|
32
|
+
"@north-light/plugin": "0.3.750",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -11902,17 +11902,17 @@
|
|
|
11902
11902
|
},
|
|
11903
11903
|
"packages/crouter-api": {
|
|
11904
11904
|
"name": "@north-light/api",
|
|
11905
|
-
"version": "0.3.
|
|
11905
|
+
"version": "0.3.750",
|
|
11906
11906
|
"license": "UNLICENSED"
|
|
11907
11907
|
},
|
|
11908
11908
|
"packages/crouter-env-docker": {
|
|
11909
11909
|
"name": "@north-light/env-docker",
|
|
11910
|
-
"version": "0.3.
|
|
11910
|
+
"version": "0.3.750",
|
|
11911
11911
|
"license": "UNLICENSED"
|
|
11912
11912
|
},
|
|
11913
11913
|
"packages/crouter-identity": {
|
|
11914
11914
|
"name": "@north-light/identity",
|
|
11915
|
-
"version": "0.3.
|
|
11915
|
+
"version": "0.3.750",
|
|
11916
11916
|
"license": "UNLICENSED",
|
|
11917
11917
|
"dependencies": {
|
|
11918
11918
|
"jose": "^6.2.1"
|
|
@@ -11920,21 +11920,21 @@
|
|
|
11920
11920
|
},
|
|
11921
11921
|
"packages/crouter-plugin": {
|
|
11922
11922
|
"name": "@north-light/plugin",
|
|
11923
|
-
"version": "0.3.
|
|
11923
|
+
"version": "0.3.750",
|
|
11924
11924
|
"license": "UNLICENSED",
|
|
11925
11925
|
"dependencies": {
|
|
11926
|
-
"@north-light/api": "0.3.
|
|
11927
|
-
"@north-light/identity": "0.3.
|
|
11926
|
+
"@north-light/api": "0.3.750",
|
|
11927
|
+
"@north-light/identity": "0.3.750"
|
|
11928
11928
|
}
|
|
11929
11929
|
},
|
|
11930
11930
|
"packages/crouter-sdk": {
|
|
11931
11931
|
"name": "@north-light/sdk",
|
|
11932
|
-
"version": "0.3.
|
|
11932
|
+
"version": "0.3.750",
|
|
11933
11933
|
"license": "UNLICENSED",
|
|
11934
11934
|
"dependencies": {
|
|
11935
|
-
"@north-light/api": "0.3.
|
|
11936
|
-
"@north-light/identity": "0.3.
|
|
11937
|
-
"@north-light/plugin": "0.3.
|
|
11935
|
+
"@north-light/api": "0.3.750",
|
|
11936
|
+
"@north-light/identity": "0.3.750",
|
|
11937
|
+
"@north-light/plugin": "0.3.750",
|
|
11938
11938
|
"jose": "^6.2.1"
|
|
11939
11939
|
},
|
|
11940
11940
|
"bin": {
|