@sentropic/artifacts 0.2.9 → 0.2.12
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/CHANGELOG.md +52 -0
- package/dist/adapters/postgres-management.js +31 -8
- package/dist/adapters/postgres.js +16 -5
- package/dist/content/handler.d.ts +6 -1
- package/dist/content/handler.js +7 -2
- package/dist/http.d.ts +5 -1
- package/dist/http.js +52 -8
- package/dist/mcp-core.d.ts +1 -1
- package/dist/mcp-core.js +1 -1
- package/dist/profile/contracts.d.ts +2 -0
- package/dist/profile/index.js +3 -1
- package/dist/server/access.d.ts +70 -10
- package/dist/server/access.js +91 -8
- package/dist/server/lifecycle.d.ts +2 -2
- package/dist/server/lifecycle.js +2 -2
- package/dist/server/management.d.ts +17 -5
- package/dist/server/management.js +51 -11
- package/dist/server/ports.d.ts +27 -0
- package/dist/server/ports.js +28 -0
- package/dist/server/publication.d.ts +35 -0
- package/dist/server/publication.js +88 -11
- package/dist/server/runtime.d.ts +7 -1
- package/dist/server/runtime.js +2 -1
- package/dist/server/summary.d.ts +2 -1
- package/dist/server/summary.js +2 -2
- package/migrations/0006_sharing.sql +107 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.12
|
|
4
|
+
|
|
5
|
+
- Bounded concurrency in multi-file publication blob staging (#art-conc, P1):
|
|
6
|
+
`publishFinalized` no longer issues one `putBlob` per file in a sequential
|
|
7
|
+
loop and `verifyStagedBlobs` no longer issues one `getBlob` per file
|
|
8
|
+
sequentially. Both now run through a shared worker pool with a default of 6
|
|
9
|
+
in-flight operations, configurable via `blobConcurrency` on the publication
|
|
10
|
+
service deps and clamped to at most 8 (`MAX_BLOB_CONCURRENCY`), so no
|
|
11
|
+
unbounded parallelism is possible. On slow S3 hosts (e.g. OVH BHS at
|
|
12
|
+
1.1–1.5 s per request) a 30-file `artifacts_publish` now takes about
|
|
13
|
+
ceil(n/k) round trips instead of n, staying inside the host blob budget
|
|
14
|
+
instead of returning 503 `provider_unavailable`.
|
|
15
|
+
- The pool keeps the sequential loop's guarantees: all-or-nothing publication
|
|
16
|
+
(intent, pins, cleanup and finalization paths unchanged), the same
|
|
17
|
+
per-operation error projection (the first fatal error is rethrown unchanged,
|
|
18
|
+
so provider error codes and failure mapping are identical), and one shared
|
|
19
|
+
deadline across the whole batch when `blobDeadlineMs` is configured — no new
|
|
20
|
+
blob operation starts after it, and expiry classifies exactly like a
|
|
21
|
+
provider timeout (503 `provider_unavailable`). MCP tool definitions are
|
|
22
|
+
byte-identical.
|
|
23
|
+
|
|
24
|
+
## 0.2.10
|
|
25
|
+
|
|
26
|
+
- G1 sharing access model: artifacts carry an explicit `access_mode`
|
|
27
|
+
(`restricted` by default, `platform`, `public`) managed through
|
|
28
|
+
`artifacts_set_access` with sentinel transitions (`grant sentropic:platform`
|
|
29
|
+
degrades public→platform, `revoke sentropic:platform` on public is a no-op).
|
|
30
|
+
`restricted` mode allows at most one nominative `source` (collab) grant, and
|
|
31
|
+
widening the mode while a `source` grant is live is rejected. Migration
|
|
32
|
+
`0006_sharing.sql` is additive: `access_mode` column with CHECK, legacy
|
|
33
|
+
`is_public=true` backfilled to `platform` (zero artifacts become `public`),
|
|
34
|
+
an append-only `artifact_access_events` audit table (UPDATE/DELETE rejected by
|
|
35
|
+
trigger) and the Q1 schema guards (partial unique index, mode/grant triggers).
|
|
36
|
+
- Sharing policy is double-locked: profile rule `allowPublicSharing` (absent ⇒
|
|
37
|
+
false, covered by `profileDigest`) AND a runtime `SharingPolicyPort` resolved
|
|
38
|
+
fail-closed inside the commit transaction; public anonymous reads require the
|
|
39
|
+
policy to allow them. Approval freshness is enforced on read paths (suspension
|
|
40
|
+
cuts the next read, reactivation resumes automatically).
|
|
41
|
+
- D1: `set_access` visibility closes the existence oracle — a non-reader actor
|
|
42
|
+
gets `not_found` unless it is an approved platform admin of the same storage
|
|
43
|
+
scope; the management right itself (owner, or admin-reduce-only) is still
|
|
44
|
+
decided inside the transaction (403 otherwise).
|
|
45
|
+
- D2: `0006_sharing.sql` deterministically dedupes legacy multi-`source` grants
|
|
46
|
+
before the unique index (oldest `created_at`, tie-break `principal_id` stays
|
|
47
|
+
`source`; later duplicates demote to `read`; no row deleted), and
|
|
48
|
+
`putArtifactAcl` demotes a stale `source` grant to `read` when rewriting a
|
|
49
|
+
non-restricted ACL.
|
|
50
|
+
- MCP tool definitions stay byte-identical (new fields only, never edits).
|
|
51
|
+
- 0.2.10 stays inside the existing cluster-mesh `>=0.2.0 <0.3.0` peer range
|
|
52
|
+
(conductor allocation: #896=0.2.9, #901=0.2.10, #891=0.2.11; merge order
|
|
53
|
+
896 > 901 > 891).
|
|
54
|
+
|
|
3
55
|
## 0.2.9
|
|
4
56
|
|
|
5
57
|
- Make every `artifacts_*` MCP tool definition byte-stable across deployments,
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { applyModeTransition, PLATFORM_PRINCIPAL, PUBLIC_PRINCIPAL } from '../server/access.js';
|
|
1
2
|
/** Parent lock serializes ACL inserts, lifecycle changes and publication FKs. */
|
|
2
3
|
export function createPostgresManagementUnit(client) {
|
|
4
|
+
const listGrants = async (id) => {
|
|
5
|
+
const { rows } = await client.query('SELECT principal_id, permission FROM artifacts.artifact_access WHERE artifact_id = $1 ORDER BY principal_id', [id]);
|
|
6
|
+
return rows.map((row) => ({ principalId: row.principal_id, grant: row.permission }));
|
|
7
|
+
};
|
|
3
8
|
return {
|
|
4
9
|
async lock(id) {
|
|
5
10
|
await client.query('SELECT id FROM artifacts.artifacts WHERE id = $1 FOR UPDATE', [id]);
|
|
@@ -7,30 +12,48 @@ export function createPostgresManagementUnit(client) {
|
|
|
7
12
|
await client.query('SELECT release_id FROM artifacts.artifact_current WHERE artifact_id = $1 FOR UPDATE', [id]);
|
|
8
13
|
},
|
|
9
14
|
async read(id) {
|
|
10
|
-
const { rows } = await client.query(`SELECT a.owner_id, a.storage_scope_id, a.lifecycle_state, a.is_public, a.terminal_deleted_at, c.release_id
|
|
15
|
+
const { rows } = await client.query(`SELECT a.owner_id, a.storage_scope_id, a.lifecycle_state, a.is_public, a.access_mode, a.terminal_deleted_at, c.release_id
|
|
11
16
|
FROM artifacts.artifacts a LEFT JOIN artifacts.artifact_current c ON c.artifact_id = a.id WHERE a.id = $1`, [id]);
|
|
12
17
|
const row = rows[0];
|
|
13
18
|
if (!row)
|
|
14
19
|
return undefined;
|
|
20
|
+
// G1: access_mode is authoritative; is_public is its legacy projection.
|
|
21
|
+
const accessMode = (row.access_mode ?? (row.is_public ? 'platform' : 'restricted'));
|
|
15
22
|
const acl = { ownerId: row.owner_id, storageScopeId: row.storage_scope_id,
|
|
16
|
-
isPublic:
|
|
23
|
+
isPublic: accessMode !== 'restricted', accessMode, withdrawn: row.lifecycle_state === 'withdrawn', grants: [] };
|
|
17
24
|
return { acl, state: row.lifecycle_state, terminal: row.terminal_deleted_at !== null,
|
|
18
25
|
currentReleaseId: row.release_id };
|
|
19
26
|
},
|
|
20
27
|
async setAccess(id, principalId, action, updatedAt) {
|
|
28
|
+
const modeRow = await client.query('SELECT access_mode, is_public FROM artifacts.artifacts WHERE id = $1', [id]);
|
|
29
|
+
const current = (modeRow.rows[0] === undefined ? 'restricted'
|
|
30
|
+
: (modeRow.rows[0].access_mode ?? (modeRow.rows[0].is_public ? 'platform' : 'restricted')));
|
|
31
|
+
if (principalId === PLATFORM_PRINCIPAL || principalId === PUBLIC_PRINCIPAL) {
|
|
32
|
+
// Wide-audience sentinels move the mode through the normative transitions;
|
|
33
|
+
// is_public follows as projection (never forced to false).
|
|
34
|
+
const transition = applyModeTransition(current, action, principalId);
|
|
35
|
+
if (transition.changed) {
|
|
36
|
+
await client.query(`UPDATE artifacts.artifacts SET access_mode = $2, is_public = ($2 <> 'restricted'), updated_at = $3 WHERE id = $1`, [id, transition.mode, updatedAt]);
|
|
37
|
+
}
|
|
38
|
+
return { grants: await listGrants(id), updatedAt, accessMode: transition.mode, changed: transition.changed };
|
|
39
|
+
}
|
|
21
40
|
const changed = action === 'grant' ? await client.query(`INSERT INTO artifacts.artifact_access (artifact_id, principal_id, permission) VALUES ($1, $2, 'read')
|
|
22
41
|
ON CONFLICT (artifact_id, principal_id) DO NOTHING`, [id, principalId])
|
|
23
42
|
: await client.query('DELETE FROM artifacts.artifact_access WHERE artifact_id = $1 AND principal_id = $2', [id, principalId]);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
43
|
+
if (changed.rowCount > 0) {
|
|
44
|
+
await client.query('UPDATE artifacts.artifacts SET updated_at = $2 WHERE id = $1', [id, updatedAt]);
|
|
45
|
+
}
|
|
27
46
|
const stamp = await client.query('SELECT updated_at FROM artifacts.artifacts WHERE id = $1', [id]);
|
|
28
|
-
return { grants:
|
|
29
|
-
|
|
47
|
+
return { grants: await listGrants(id), updatedAt: stamp.rows[0]?.updated_at?.toISOString() ?? null,
|
|
48
|
+
accessMode: current, changed: changed.rowCount > 0 };
|
|
49
|
+
},
|
|
50
|
+
async recordEvent(event) {
|
|
51
|
+
await client.query(`INSERT INTO artifacts.artifact_access_events (artifact_id, actor_id, action, audience, principal_id, policy_revision)
|
|
52
|
+
VALUES ($1, $2, $3, $4, $5, $6)`, [event.artifactId, event.actorId, event.action, event.audience, event.principalId, event.policyRevision]);
|
|
30
53
|
},
|
|
31
54
|
async delete(id, deletedAt) {
|
|
32
55
|
await client.query(`UPDATE artifacts.artifacts SET lifecycle_state = 'deleted', terminal_deleted_at = $2,
|
|
33
|
-
updated_at = $2
|
|
56
|
+
updated_at = $2 WHERE id = $1`, [id, deletedAt]);
|
|
34
57
|
},
|
|
35
58
|
};
|
|
36
59
|
}
|
|
@@ -196,7 +196,7 @@ export function createPostgresArtifactStore(pool) {
|
|
|
196
196
|
return rows.map((row) => row.digest);
|
|
197
197
|
},
|
|
198
198
|
async getArtifactAcl(artifactId) {
|
|
199
|
-
const { rows } = await pool.query(`SELECT owner_id, storage_scope_id, is_public, lifecycle_state, binding_name, created_at,
|
|
199
|
+
const { rows } = await pool.query(`SELECT owner_id, storage_scope_id, is_public, access_mode, lifecycle_state, binding_name, created_at,
|
|
200
200
|
to_jsonb(a)->>'updated_at' AS updated_at, to_jsonb(a)->'metadata' AS metadata
|
|
201
201
|
FROM artifacts.artifacts a WHERE id = $1`, [artifactId]);
|
|
202
202
|
const row = rows[0];
|
|
@@ -204,12 +204,15 @@ export function createPostgresArtifactStore(pool) {
|
|
|
204
204
|
return undefined;
|
|
205
205
|
const grants = await pool.query(`SELECT principal_id, permission FROM artifacts.artifact_access
|
|
206
206
|
WHERE artifact_id = $1 ORDER BY principal_id`, [artifactId]);
|
|
207
|
+
// G1: access_mode is authoritative; is_public is its legacy projection.
|
|
208
|
+
const accessMode = (row.access_mode ?? (row.is_public ? 'platform' : 'restricted'));
|
|
207
209
|
return {
|
|
208
210
|
bindingName: row.binding_name, createdAt: row.created_at.toISOString(), updatedAt: row.updated_at,
|
|
209
211
|
...(row.metadata ?? {}),
|
|
210
212
|
ownerId: row.owner_id,
|
|
211
213
|
storageScopeId: row.storage_scope_id,
|
|
212
|
-
isPublic:
|
|
214
|
+
isPublic: accessMode !== 'restricted',
|
|
215
|
+
accessMode,
|
|
213
216
|
withdrawn: row.lifecycle_state === 'withdrawn',
|
|
214
217
|
grants: grants.rows.map((grant) => ({
|
|
215
218
|
principalId: grant.principal_id,
|
|
@@ -219,17 +222,25 @@ export function createPostgresArtifactStore(pool) {
|
|
|
219
222
|
};
|
|
220
223
|
},
|
|
221
224
|
async putArtifactAcl(artifactId, acl) {
|
|
222
|
-
|
|
225
|
+
// G1: write access_mode; is_public stays as its projection (never forced false).
|
|
226
|
+
const accessMode = acl.accessMode ?? (acl.isPublic ? 'platform' : 'restricted');
|
|
227
|
+
await pool.query(`UPDATE artifacts.artifacts SET access_mode = $2, is_public = ($2 <> 'restricted'), metadata = $4,
|
|
223
228
|
lifecycle_state = CASE WHEN $3 THEN 'withdrawn'
|
|
224
229
|
WHEN lifecycle_state = 'withdrawn' THEN 'active'
|
|
225
230
|
ELSE lifecycle_state END
|
|
226
|
-
WHERE id = $1`, [artifactId,
|
|
231
|
+
WHERE id = $1`, [artifactId, accessMode, acl.withdrawn, JSON.stringify(acl.metadata ?? {})]);
|
|
227
232
|
await pool.query(`DELETE FROM artifacts.artifact_access WHERE artifact_id = $1`, [
|
|
228
233
|
artifactId,
|
|
229
234
|
]);
|
|
230
235
|
for (const grant of acl.grants) {
|
|
236
|
+
// Q1 schema invariant: a source grant exists only in restricted mode. A
|
|
237
|
+
// legacy platform/public artifact (migrated by 0006 from is_public=true)
|
|
238
|
+
// may still carry one; rewriting its ACL (e.g. withdraw) must not trip
|
|
239
|
+
// the source guard on re-insert, so the stale source grant is demoted
|
|
240
|
+
// to read — the grant row is kept, never dropped.
|
|
241
|
+
const permission = grant.grant === 'source' && accessMode !== 'restricted' ? 'read' : grant.grant;
|
|
231
242
|
await pool.query(`INSERT INTO artifacts.artifact_access (artifact_id, principal_id, permission)
|
|
232
|
-
VALUES ($1, $2, $3)`, [artifactId, grant.principalId,
|
|
243
|
+
VALUES ($1, $2, $3)`, [artifactId, grant.principalId, permission]);
|
|
233
244
|
}
|
|
234
245
|
},
|
|
235
246
|
async listArtifactIds() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AclStore } from '../server/access.js';
|
|
2
2
|
import type { LifecycleService } from '../server/lifecycle.js';
|
|
3
|
+
import { type SharingPolicyPort } from '../server/ports.js';
|
|
3
4
|
import type { PublicationBlobStore, PublicationService } from '../server/publication.js';
|
|
4
5
|
import { type GrantSigner, type TicketService } from './grants.js';
|
|
5
6
|
export interface ContentRequest {
|
|
@@ -25,7 +26,11 @@ export interface ContentHandlerDeps {
|
|
|
25
26
|
grants: GrantSigner;
|
|
26
27
|
tickets: TicketService;
|
|
27
28
|
baseDomain: string;
|
|
28
|
-
isApprovedAccount?: (principalId: string) => boolean
|
|
29
|
+
isApprovedAccount?: (principalId: string) => boolean | Promise<boolean>;
|
|
30
|
+
/** G1 lock 2 (runtime): sharing policy per scope, fail-closed when absent. */
|
|
31
|
+
sharingPolicy?: SharingPolicyPort;
|
|
32
|
+
/** G1 lock 1 (deployment capability), absent ⇒ closed. */
|
|
33
|
+
allowPublicSharing?: boolean;
|
|
29
34
|
assetCacheSeconds?: number;
|
|
30
35
|
}
|
|
31
36
|
/** Create the content handler over injected host ports (no server). */
|
package/dist/content/handler.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* Unknown/unreadable → same 404; bad grants → 401.
|
|
15
15
|
*/
|
|
16
16
|
import { errorBody } from '../http.js';
|
|
17
|
+
import { combineSharingPolicy, resolveSharingPolicy } from '../server/ports.js';
|
|
17
18
|
import { CONTENT_GRANT_TTL_SECONDS } from './grants.js';
|
|
18
19
|
import { contentHeaders, grantCookie, parseGrantCookie } from './headers.js';
|
|
19
20
|
import { isServiceWorkerPath, parseContentHost, resolveContentPath } from './routing.js';
|
|
@@ -29,13 +30,17 @@ function fail(status) {
|
|
|
29
30
|
}
|
|
30
31
|
/** Create the content handler over injected host ports (no server). */
|
|
31
32
|
export function createContentHandler(deps) {
|
|
32
|
-
const isApproved = deps.isApprovedAccount ?? (() => false);
|
|
33
33
|
async function canReadNow(artifactId, subjectId) {
|
|
34
34
|
const acl = await deps.acls.getArtifactAcl(artifactId);
|
|
35
35
|
if (acl === undefined)
|
|
36
36
|
return false;
|
|
37
37
|
const state = await deps.lifecycle.stateOf(artifactId);
|
|
38
|
-
|
|
38
|
+
// G1 double lock, fail-closed: public mode serves anonymous reads only
|
|
39
|
+
// when the profile capability AND the live runtime policy both allow it.
|
|
40
|
+
const policy = acl.storageScopeId === undefined ? undefined : combineSharingPolicy(deps.allowPublicSharing, await resolveSharingPolicy(deps.sharingPolicy, acl.storageScopeId));
|
|
41
|
+
// G1 owner Q2: fresh account approval at every read; the host predicate may be async (live DB check).
|
|
42
|
+
const approved = (await deps.isApprovedAccount?.(subjectId)) ?? false;
|
|
43
|
+
return deps.lifecycle.canRead({ artifactId, state }, acl, subjectId, 'read', () => approved, policy);
|
|
39
44
|
}
|
|
40
45
|
async function serveFile(artifactId, manifest, filePath) {
|
|
41
46
|
const acl = await deps.acls.getArtifactAcl(artifactId);
|
package/dist/http.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type CompiledArtifactsProfile } from './profile/index.js';
|
|
2
2
|
import { type ArtifactKeyDerivationBinding } from './server/command-identity.js';
|
|
3
3
|
import { type GuardedEnsureHost } from './server/service.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type KvPort, type SharingPolicyPort } from './server/ports.js';
|
|
5
5
|
import { type GuardedPublicationDeps, type PublicationService } from './server/publication.js';
|
|
6
6
|
import type { AclStore } from './server/access.js';
|
|
7
7
|
import type { LifecycleService } from './server/lifecycle.js';
|
|
@@ -51,6 +51,10 @@ export interface HttpAppDeps {
|
|
|
51
51
|
acls: AclStore;
|
|
52
52
|
lifecycle: Pick<LifecycleService, 'stateOf' | 'canRead' | 'getReleaseState'>;
|
|
53
53
|
isApprovedAccount?: (principalId: string) => boolean;
|
|
54
|
+
/** G1 lock 2 (runtime, revocable): sharing policy per scope, resolved fail-closed. */
|
|
55
|
+
sharingPolicy?: SharingPolicyPort;
|
|
56
|
+
/** G1: server-resolved platform admin predicate (never a tool argument). */
|
|
57
|
+
actorIsAdmin?: (actorId: string, storageScopeId: string) => boolean | Promise<boolean>;
|
|
54
58
|
/** One trusted URL policy shared by HTTP and MCP receipts: the artifact page and the exact version page. */
|
|
55
59
|
publicationUrls?: (artifactId: string, releaseId: string) => {
|
|
56
60
|
stableUrl: string;
|
package/dist/http.js
CHANGED
|
@@ -5,6 +5,7 @@ import { assertCompiledArtifactsProfile, ArtifactProfileInputError } from './pro
|
|
|
5
5
|
import { createArtifactCommand } from './server/command-identity.js';
|
|
6
6
|
import { createGuardedEnsureService } from './server/service.js';
|
|
7
7
|
import { assertArtifactReplayMigration } from './server/idempotency.js';
|
|
8
|
+
import { combineSharingPolicy, resolveSharingPolicy } from './server/ports.js';
|
|
8
9
|
import { createGuardedPublicationService } from './server/publication.js';
|
|
9
10
|
import { applyEdits } from './server/edits.js';
|
|
10
11
|
import { CommitQuarantineError } from './server/commit/types.js';
|
|
@@ -70,6 +71,10 @@ export function createHttpArtifactApp(deps) {
|
|
|
70
71
|
return receipt;
|
|
71
72
|
},
|
|
72
73
|
} });
|
|
74
|
+
/** G1 double lock: profile capability (lock 1) AND runtime port (lock 2), fail-closed. */
|
|
75
|
+
async function sharingPolicyContext(storageScopeId) {
|
|
76
|
+
return combineSharingPolicy(profile.rules.allowPublicSharing, await resolveSharingPolicy(deps.sharingPolicy, storageScopeId));
|
|
77
|
+
}
|
|
73
78
|
async function visible(artifactId, invocation, action = 'read') {
|
|
74
79
|
const acl = await deps.acls.getArtifactAcl(artifactId);
|
|
75
80
|
if (!acl || acl.storageScopeId !== invocation.storageScopeId)
|
|
@@ -81,11 +86,39 @@ export function createHttpArtifactApp(deps) {
|
|
|
81
86
|
return acl;
|
|
82
87
|
throw new ArtifactOperationError('gone');
|
|
83
88
|
}
|
|
84
|
-
|
|
89
|
+
const policy = await sharingPolicyContext(invocation.storageScopeId);
|
|
90
|
+
if (!deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, action === true ? 'read' : action, deps.isApprovedAccount, policy)) {
|
|
85
91
|
throw new ArtifactOperationError('not_found');
|
|
86
92
|
}
|
|
87
93
|
return acl;
|
|
88
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* G1 management visibility for `set_access` (converged-r2 §2.3 order (2)):
|
|
97
|
+
* readers pass as before; any other actor gets `not_found` unless it is an
|
|
98
|
+
* APPROVED platform admin of the SAME storageScopeId. The predicate is
|
|
99
|
+
* evaluated per call — never inferred from merely being wired — so a
|
|
100
|
+
* non-reader non-admin cannot distinguish an existing artifact (403) from a
|
|
101
|
+
* missing one (404): the existence oracle is closed. The management right
|
|
102
|
+
* itself (owner, or admin-reduce-only) is decided inside the transaction by
|
|
103
|
+
* `canManageAccess` (403 otherwise). The exception never makes the admin a
|
|
104
|
+
* content reader.
|
|
105
|
+
*/
|
|
106
|
+
async function visibleForManagement(artifactId, invocation) {
|
|
107
|
+
const acl = await deps.acls.getArtifactAcl(artifactId);
|
|
108
|
+
if (!acl || acl.storageScopeId !== invocation.storageScopeId)
|
|
109
|
+
throw new ArtifactOperationError('not_found');
|
|
110
|
+
const state = await deps.lifecycle.stateOf(artifactId);
|
|
111
|
+
if (acl.ownerId === invocation.actorId && (state === 'deleted' || state === 'purged'))
|
|
112
|
+
return acl;
|
|
113
|
+
const policy = await sharingPolicyContext(invocation.storageScopeId);
|
|
114
|
+
if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount, policy)) {
|
|
115
|
+
return acl;
|
|
116
|
+
}
|
|
117
|
+
if (await deps.actorIsAdmin?.(invocation.actorId, invocation.storageScopeId) === true &&
|
|
118
|
+
deps.isApprovedAccount?.(invocation.actorId) === true)
|
|
119
|
+
return acl;
|
|
120
|
+
throw new ArtifactOperationError('not_found');
|
|
121
|
+
}
|
|
89
122
|
/** Display metadata fields present on validated args (ensure/publish). */
|
|
90
123
|
function metadataOf(normalized) {
|
|
91
124
|
const meta = {};
|
|
@@ -258,7 +291,8 @@ export function createHttpArtifactApp(deps) {
|
|
|
258
291
|
const acl = await visible(artifactId, invocation);
|
|
259
292
|
const summary = artifactSummary({ artifactId, acl, actorId: invocation.actorId,
|
|
260
293
|
state: await deps.lifecycle.stateOf(artifactId), current: await deps.publication.getCurrent(artifactId),
|
|
261
|
-
urls: deps.publicationUrls, approved: deps.isApprovedAccount
|
|
294
|
+
urls: deps.publicationUrls, approved: deps.isApprovedAccount,
|
|
295
|
+
policy: await sharingPolicyContext(invocation.storageScopeId) });
|
|
262
296
|
return { ...outcome, result: { status: 201, body: profile.resultEnvelopeVersion === 2
|
|
263
297
|
? { ...summary, ...outcome.result } : { ...outcome.result, ...acl.metadata } } };
|
|
264
298
|
}
|
|
@@ -269,7 +303,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
269
303
|
authorize: async () => {
|
|
270
304
|
const acl = await visible(artifactId, invocation);
|
|
271
305
|
const state = await deps.lifecycle.stateOf(artifactId);
|
|
272
|
-
if (!deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'source', deps.isApprovedAccount)) {
|
|
306
|
+
if (!deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'source', deps.isApprovedAccount, await sharingPolicyContext(invocation.storageScopeId))) {
|
|
273
307
|
throw new ArtifactOperationError('access_denied');
|
|
274
308
|
}
|
|
275
309
|
}, getCurrent: deps.publication.getCurrent, getRelease: deps.publication.getRelease,
|
|
@@ -280,13 +314,20 @@ export function createHttpArtifactApp(deps) {
|
|
|
280
314
|
commitState: 'not_committed', replayed: false };
|
|
281
315
|
}
|
|
282
316
|
if (capability === 'artifacts_set_access' || capability === 'artifacts_delete') {
|
|
283
|
-
const
|
|
284
|
-
|
|
317
|
+
const artifactId = normalized.artifactId;
|
|
318
|
+
const acl = capability === 'artifacts_set_access'
|
|
319
|
+
? await visibleForManagement(artifactId, invocation)
|
|
320
|
+
: await visible(artifactId, invocation, true);
|
|
321
|
+
if (capability === 'artifacts_delete' && acl.ownerId !== invocation.actorId) {
|
|
285
322
|
throw new ArtifactOperationError('access_denied');
|
|
323
|
+
}
|
|
286
324
|
const outcome = await manageArtifact({ coordinator: deps.coordinator,
|
|
287
325
|
createUnit: deps.management?.createUnit ?? createPostgresManagementUnit,
|
|
288
326
|
confirmation: deps.management?.confirmation, readPolicyRevision: () => deps.ensureHost.readPolicyRevision(),
|
|
289
327
|
isApprovedPrincipal: deps.isApprovedAccount ?? (() => false),
|
|
328
|
+
sharingPolicy: deps.sharingPolicy,
|
|
329
|
+
profileAllowPublicSharing: profile.rules.allowPublicSharing,
|
|
330
|
+
actorIsAdmin: deps.actorIsAdmin,
|
|
290
331
|
validateNewCommand: () => { profile.validate(capability, args, request.idempotencyKey); },
|
|
291
332
|
}, invocation, command, normalized.confirmationRef);
|
|
292
333
|
return outcome.ok ? { ...outcome, result: { status: 200, body: outcome.result } } : outcome;
|
|
@@ -355,7 +396,8 @@ export function createHttpArtifactApp(deps) {
|
|
|
355
396
|
const current = await deps.publication.getCurrent(artifactId);
|
|
356
397
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
357
398
|
result: { status: 200, body: { ...artifactSummary({ artifactId, acl, state, current,
|
|
358
|
-
actorId: invocation.actorId, urls: deps.publicationUrls, approved: deps.isApprovedAccount
|
|
399
|
+
actorId: invocation.actorId, urls: deps.publicationUrls, approved: deps.isApprovedAccount,
|
|
400
|
+
policy: await sharingPolicyContext(invocation.storageScopeId) }),
|
|
359
401
|
...(acl.metadata !== undefined ? { metadata: acl.metadata } : {}),
|
|
360
402
|
...(acl.ownerId === invocation.actorId ? { grants: acl.grants } : {}) } } };
|
|
361
403
|
}
|
|
@@ -385,14 +427,16 @@ export function createHttpArtifactApp(deps) {
|
|
|
385
427
|
result: { status: 200, body: { artifactId, total: releases.length, releases } } };
|
|
386
428
|
}
|
|
387
429
|
const visibleArtifacts = [];
|
|
430
|
+
const listPolicy = await sharingPolicyContext(invocation.storageScopeId);
|
|
388
431
|
for (const artifactId of await deps.acls.listArtifactIds()) {
|
|
389
432
|
const acl = await deps.acls.getArtifactAcl(artifactId);
|
|
390
433
|
if (!acl || acl.storageScopeId !== invocation.storageScopeId)
|
|
391
434
|
continue;
|
|
392
435
|
const state = await deps.lifecycle.stateOf(artifactId);
|
|
393
|
-
if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount)) {
|
|
436
|
+
if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount, listPolicy)) {
|
|
394
437
|
visibleArtifacts.push(artifactSummary({ artifactId, acl, state, actorId: invocation.actorId,
|
|
395
|
-
current: await deps.publication.getCurrent(artifactId), urls: deps.publicationUrls,
|
|
438
|
+
current: await deps.publication.getCurrent(artifactId), urls: deps.publicationUrls,
|
|
439
|
+
approved: deps.isApprovedAccount, policy: listPolicy }));
|
|
396
440
|
}
|
|
397
441
|
}
|
|
398
442
|
const offset = normalized.offset;
|
package/dist/mcp-core.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
|
10
10
|
export type { ArtifactKeyDerivationBinding } from './server/command-identity.js';
|
|
11
11
|
export declare const ARTIFACTS_PROVIDER_ID = "sentropic.artifacts";
|
|
12
12
|
export declare const ARTIFACTS_APP_ID = "sentropic-artifacts";
|
|
13
|
-
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.
|
|
13
|
+
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.12";
|
|
14
14
|
export declare const ARTIFACTS_TOOL_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert"];
|
|
15
15
|
export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
|
|
16
16
|
export interface ArtifactsToolDefinition {
|
package/dist/mcp-core.js
CHANGED
|
@@ -6,7 +6,7 @@ export * from './profile/index.js';
|
|
|
6
6
|
export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
7
7
|
export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
|
|
8
8
|
export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
|
|
9
|
-
export const ARTIFACTS_PROVIDER_VERSION = '0.2.
|
|
9
|
+
export const ARTIFACTS_PROVIDER_VERSION = '0.2.12';
|
|
10
10
|
export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// Byte-stable tool definitions (MCP tool-definition stability rule).
|
|
@@ -20,6 +20,8 @@ export interface ArtifactProfileRules {
|
|
|
20
20
|
readonly forbiddenPathPattern: string;
|
|
21
21
|
readonly reservedFirstSegments: readonly string[];
|
|
22
22
|
readonly mimeTypes: readonly string[];
|
|
23
|
+
/** G1 lock 1 (deployment): allow the `public` sharing mode; absent ⇒ closed. */
|
|
24
|
+
readonly allowPublicSharing?: boolean;
|
|
23
25
|
}
|
|
24
26
|
export interface ArtifactProviderProfile {
|
|
25
27
|
/** Trusted public contract revision; independent from the host policy revision. */
|
package/dist/profile/index.js
CHANGED
|
@@ -66,9 +66,11 @@ export function compileArtifactsProfile(input) {
|
|
|
66
66
|
}
|
|
67
67
|
const rules = profile.rules;
|
|
68
68
|
const ruleKeys = ['lengthUnit', 'textEncoding', 'callerKeyNormalization', 'rejectLoneSurrogates',
|
|
69
|
-
'provenance', 'keyDerivationAlgorithm', 'pathMaxBytes', 'forbiddenPathPattern', 'reservedFirstSegments', 'mimeTypes'
|
|
69
|
+
'provenance', 'keyDerivationAlgorithm', 'pathMaxBytes', 'forbiddenPathPattern', 'reservedFirstSegments', 'mimeTypes',
|
|
70
|
+
'allowPublicSharing'];
|
|
70
71
|
if (!rules || rules.lengthUnit !== 'utf16' || rules.textEncoding !== 'utf8' || rules.callerKeyNormalization !== 'none' ||
|
|
71
72
|
Object.keys(rules).some((key) => !ruleKeys.includes(key)) ||
|
|
73
|
+
(rules.allowPublicSharing !== undefined && typeof rules.allowPublicSharing !== 'boolean') ||
|
|
72
74
|
rules.rejectLoneSurrogates !== true || rules.provenance !== 'inline-original' ||
|
|
73
75
|
typeof rules.keyDerivationAlgorithm !== 'string' || !rules.keyDerivationAlgorithm ||
|
|
74
76
|
!Number.isSafeInteger(rules.pathMaxBytes) || rules.pathMaxBytes < 1 || rules.pathMaxBytes > 1024 ||
|
package/dist/server/access.d.ts
CHANGED
|
@@ -1,16 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L-5c — access control (spec-v8 §9 5c).
|
|
2
|
+
* L-5c/G1 — access control (spec-v8 §9 5c, converged-r2 §2.1 + owner answers).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* Three-mode sharing model. `restricted` (default): owner + nominative grants.
|
|
5
|
+
* `platform`: every approved account of the scope reads, never anonymous,
|
|
6
|
+
* never source. `public`: anonymous read only while the sharing policy allows
|
|
7
|
+
* it (§2.2 double lock, fail-closed). The legacy `isPublic` flag maps to
|
|
8
|
+
* `platform`, never `public`. Nominative grants coexist orthogonally with the
|
|
9
|
+
* wide mode. Owner Q1: the collab (`source`) right is nominative only — one
|
|
10
|
+
* named colleague, restricted mode only, never a `sentropic:` sentinel; the
|
|
11
|
+
* schema mirrors this. Owner Q2: grants and platform reads require fresh
|
|
12
|
+
* approval at every read — a paused share resumes automatically once the
|
|
13
|
+
* account is approved again and reports `blockedBy:'account_inactive'`
|
|
14
|
+
* meanwhile; the grant row is kept, never deleted. Owner Q3: the ACL is per
|
|
15
|
+
* artifact, so a share covers all retained versions (no version-scoped state
|
|
16
|
+
* exists here). Withdrawal suspends reader grants (kept for audit, inactive)
|
|
17
|
+
* while the owner keeps access. Grant management is owner-only (duplicates
|
|
18
|
+
* refused); `canManageAccess` adds the server-resolved platform admin, which
|
|
19
|
+
* may revoke and degrade only — never widen, never place a nominative grant.
|
|
11
20
|
*/
|
|
12
21
|
export type AccessGrant = 'read' | 'source';
|
|
13
22
|
export type AccessAction = 'read' | 'source';
|
|
23
|
+
export type AccessMode = 'restricted' | 'platform' | 'public';
|
|
24
|
+
export type AccessAudience = 'user' | 'platform' | 'public';
|
|
25
|
+
export type ModeAction = 'grant' | 'revoke';
|
|
26
|
+
/** Reserved principal namespace: wide-audience sentinels, never nominative. */
|
|
27
|
+
export declare const RESERVED_PRINCIPAL_PREFIX = "sentropic:";
|
|
28
|
+
export declare const PLATFORM_PRINCIPAL = "sentropic:platform";
|
|
29
|
+
export declare const PUBLIC_PRINCIPAL = "sentropic:public";
|
|
30
|
+
/** Live sharing policy context (fail-closed when absent). */
|
|
31
|
+
export interface SharingPolicyContext {
|
|
32
|
+
allowPublicSharing?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Append-only audit event recorded in the same transaction as the mutation. */
|
|
35
|
+
export interface AccessEvent {
|
|
36
|
+
artifactId: string;
|
|
37
|
+
actorId: string;
|
|
38
|
+
action: ModeAction;
|
|
39
|
+
audience: AccessAudience;
|
|
40
|
+
/** Target principal for user audience, null for the wide audiences. */
|
|
41
|
+
principalId: string | null;
|
|
42
|
+
policyRevision: string;
|
|
43
|
+
}
|
|
14
44
|
export interface GrantRecord {
|
|
15
45
|
principalId: string;
|
|
16
46
|
grant: AccessGrant;
|
|
@@ -34,6 +64,8 @@ export interface ArtifactAcl {
|
|
|
34
64
|
isPublic: boolean;
|
|
35
65
|
withdrawn: boolean;
|
|
36
66
|
grants: GrantRecord[];
|
|
67
|
+
/** Wide sharing mode; absent on legacy ACLs, which read as platform when isPublic. */
|
|
68
|
+
accessMode?: AccessMode;
|
|
37
69
|
/** Display metadata returned by get/list; persisted by the host store. */
|
|
38
70
|
metadata?: ArtifactMetadata;
|
|
39
71
|
}
|
|
@@ -45,9 +77,37 @@ export interface AclStore {
|
|
|
45
77
|
}
|
|
46
78
|
/** In-memory AclStore double for unit tests. */
|
|
47
79
|
export declare function createMemoryAclStore(): AclStore;
|
|
80
|
+
/** Effective wide mode; the legacy isPublic flag reads as platform, never public. */
|
|
81
|
+
export declare function accessModeOf(acl: ArtifactAcl): AccessMode;
|
|
48
82
|
/** True when the actor may perform the action (deny by default). */
|
|
49
|
-
export declare function evaluateAccess(acl: ArtifactAcl, actorId: string, action: AccessAction, isApproved?: (principalId: string) => boolean): boolean;
|
|
50
|
-
/**
|
|
83
|
+
export declare function evaluateAccess(acl: ArtifactAcl, actorId: string, action: AccessAction, isApproved?: (principalId: string) => boolean, policy?: SharingPolicyContext): boolean;
|
|
84
|
+
/** Dormancy report for one nominative grant (owner Q2 paused display). */
|
|
85
|
+
export declare function evaluateGrant(acl: ArtifactAcl, principalId: string, isApproved?: (principalId: string) => boolean): {
|
|
86
|
+
effective: boolean;
|
|
87
|
+
blockedBy?: 'account_inactive';
|
|
88
|
+
};
|
|
89
|
+
/** Owner-only: add a grant (duplicates refused; owner Q1 enforced in pure form). */
|
|
51
90
|
export declare function grantAccess(acl: ArtifactAcl, actorId: string, grant: GrantRecord): ArtifactAcl;
|
|
52
91
|
/** Owner-only: remove a grant (kept for audit by the caller if needed). */
|
|
53
92
|
export declare function revokeAccess(acl: ArtifactAcl, actorId: string, principalId: string): ArtifactAcl;
|
|
93
|
+
/** Normative mode transitions (converged-r2 §2.1): sentinels only move the wide mode. */
|
|
94
|
+
export declare function applyModeTransition(mode: AccessMode, action: ModeAction, principalId: string): {
|
|
95
|
+
mode: AccessMode;
|
|
96
|
+
changed: boolean;
|
|
97
|
+
};
|
|
98
|
+
/** Audience class of a principal: the two sentinels are wide, anything else is a user. */
|
|
99
|
+
export declare function audienceOf(principalId: string): AccessAudience;
|
|
100
|
+
/**
|
|
101
|
+
* Management right over one (action, principal) pair. The owner manages every
|
|
102
|
+
* audience; the platform admin — a server-resolved flag only, never a tool
|
|
103
|
+
* argument — may revoke any grant and degrade modes, including the unique
|
|
104
|
+
* `grant sentropic:platform` on a `public` artifact (a strict reduction). The
|
|
105
|
+
* admin never widens a mode and never places a nominative grant.
|
|
106
|
+
*/
|
|
107
|
+
export declare function canManageAccess(args: {
|
|
108
|
+
acl: ArtifactAcl;
|
|
109
|
+
actorId: string;
|
|
110
|
+
action: ModeAction;
|
|
111
|
+
principalId: string;
|
|
112
|
+
actorIsAdmin?: boolean;
|
|
113
|
+
}): boolean;
|