Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .changeset/sharing-floor-private-objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
'@objectstack/plugin-security': patch
'@objectstack/plugin-sharing': patch
'@objectstack/plugin-dev': patch
---

fix(plugin-security)!: a kernel that serves an object with a private sharing model boots only with an enforcing record-sharing service

Clause-②: no (narrowing — refuses a composition that was accepted)
Metadata-protocol: none
Skills-docs: skills/objectstack-platform/SKILL.md (the `queues` / `assignmentRules` note now names private objects on a boot with `auth`) and its `config-plugins-ops` eval

<!-- adr-0087: not-required (runtime-interface-only packages/plugins/plugin-sharing/src/sharing-plugin.ts#SharingPluginOptions) No authorable key, accepted value or metadata type changes, and every metadata document that parsed before parses the same. What moves is a plugin constructor's options interface, which no metadata reads, and which compositions boot: no stored row or authored value has to be rewritten. -->

**BREAKING — upgrade note.** Two rules now hold on every kernel:

- **A kernel that composes the security plugin and registers an object whose effective sharing model is `private` (declared `private`, or undeclared on a custom object) boots only with an enforcing record-sharing service.** Otherwise `bootstrap()` is refused with `PrivateObjectsWithoutSharingError` (exported by `@objectstack/plugin-security`), naming every such object. It is judged per kernel at `kernel:bootstrapped`, before any socket opens; there is no switch that turns it off. The built-in tasks and notes (`sys_task`, `sys_note`) are private objects.
- **`SharingServicePlugin` has no `enforce` option.** Its enforcement middleware and sharing-rule hooks are always installed; the share-link service is registered as before.

What to do:

- `os serve` with the default preset: nothing. `sharing` is on the always-on slate.
- `os serve --preset minimal` with `auth`: list `sharing` in `requires` (`requires: ['auth', 'sharing']`).
- A hand-composed kernel: mount `SharingServicePlugin` from `@objectstack/plugin-sharing` on every kernel that composes `SecurityPlugin` and serves a private object. On a host that runs one kernel per environment, mount it on each environment kernel that serves such objects; a kernel that registers none is not affected.
- `new SharingServicePlugin({ enforce: false })` → `new SharingServicePlugin()`. Remove the key: it no longer compiles.

`DevPlugin` (`@objectstack/plugin-dev`) now composes `SharingServicePlugin` beside `SecurityPlugin`: a dev stack serving a private object boots as before, and record sharing is now enforced in that stack.
6 changes: 5 additions & 1 deletion content/docs/deployment/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@ os serve --preset minimal # Skip auto-loaded auth/i18n/ui plugins (production:
- `--preset minimal | default | full` — Override the auto-registration
tier (see below). `minimal` composes no `auth` tier, so a production boot
(no `--dev`) with it is refused, with or without `--server`, unless the
stack mounts `AuthPlugin` in its own `plugins`.
stack mounts `AuthPlugin` in its own `plugins`. `minimal` also drops the
always-on capabilities, `sharing` among them, and a kernel that composes the
security plugin and serves an object with a private sharing model (the
built-in tasks and notes are) boots only with the record-sharing service:
list `sharing` in `requires`, or the boot is refused, naming those objects.

**Probes.** A served process exposes `GET /api/v1/health` (liveness — process
only, and deliberately blind to configuration and credentials, so a
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/test/permission-set-zero-row.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { MetadataPlugin } from '@objectstack/metadata';
import { PlatformObjectsPlugin } from '@objectstack/platform-objects/plugin';
import { AuthPlugin } from '@objectstack/plugin-auth';
import { SecurityPlugin, appSecurityPluginOptions } from '@objectstack/plugin-security';
import { SharingServicePlugin } from '@objectstack/plugin-sharing';

const ENV = 'env_zero_row';
const TABLE = 'sys_permission_set';
Expand All @@ -66,6 +67,9 @@ async function boot(kind: Kind, dbFile: string, rootDir: string): Promise<any> {
await kernel.use(new PlatformObjectsPlugin() as any);
await kernel.use(new AuthPlugin({ secret: 'zero-row-secret-zero-row-secret-zero' }) as any);
await kernel.use(new SecurityPlugin(appSecurityPluginOptions(stack)) as any);
// A kernel serving private objects (the platform's tasks and notes) boots only
// with an enforcing sharing service, as `os serve` composes it.
await kernel.use(new SharingServicePlugin({ registerShareLinkRoutes: false }) as any);
await kernel.bootstrap();
return kernel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { MetadataPlugin } from '@objectstack/metadata';
import { PlatformObjectsPlugin } from '@objectstack/platform-objects/plugin';
import { AuthPlugin } from '@objectstack/plugin-auth';
import { SecurityPlugin, appSecurityPluginOptions } from '@objectstack/plugin-security';
import { SharingServicePlugin } from '@objectstack/plugin-sharing';
import { securityCatalogReaderOf, resolveAuthzContext, assembleExecutionContext } from '@objectstack/core';

const ENV = 'env_catalog_echo';
Expand All @@ -65,7 +66,9 @@ const STACK_POSITION = 'echo_stack_position';

const stack: any = {
manifest: { id: 'com.example.catalog_echo', name: 'catalog_echo', version: '0.0.1', type: 'app' },
objects: [{ name: 'echo_doc', label: 'Echo Doc', fields: { title: { type: 'text', label: 'Title' } } }],
// Org-wide readable: this fixture's subject is the security catalog, not row
// sharing, and its seeded row carries no owner.
objects: [{ name: 'echo_doc', label: 'Echo Doc', sharingModel: 'public_read', fields: { title: { type: 'text', label: 'Title' } } }],
permissions: [{ name: DECLARED_SET, label: 'Declared reader', objects: { echo_doc: { allowRead: true } } }],
positions: [{ name: STACK_POSITION, label: 'Stack position', permissionSets: [DECLARED_SET] }],
};
Expand All @@ -91,6 +94,9 @@ async function boot(kind: Kind, dbFile: string, rootDir: string, app: any): Prom
await kernel.use(new PlatformObjectsPlugin() as any);
await kernel.use(new AuthPlugin({ secret: 'catalog-echo-secret-catalog-echo-secret' }) as any);
await kernel.use(new SecurityPlugin(appSecurityPluginOptions(app)) as any);
// A kernel serving private objects (the platform's tasks and notes) boots only
// with an enforcing sharing service, as `os serve` composes it.
await kernel.use(new SharingServicePlugin({ registerShareLinkRoutes: false }) as any);
await kernel.bootstrap();
return kernel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
// The auth plugin's reach loads this dynamically inside a case; pay it at collection.
import '@objectstack/core/egress';
import {
ObjectKernel,
resolvePluginOrder,
Expand Down Expand Up @@ -79,7 +81,9 @@ function appPlugin(): Plugin {
version: '1.0.0',
type: 'app',
name: 'Kit App',
objects: [{ name: 'kit_account', label: 'Account', fields: { name: Field.text({ label: 'Name' }) } }],
// Org-wide readable: these cases are about identity and boot, not row
// sharing, and a private object boots only with a sharing service.
objects: [{ name: 'kit_account', label: 'Account', sharingModel: 'public_read', fields: { name: Field.text({ label: 'Name' }) } }],
});
},
};
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/plugin-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@objectstack/plugin-auth": "workspace:*",
"@objectstack/plugin-hono-server": "workspace:*",
"@objectstack/plugin-security": "workspace:*",
"@objectstack/plugin-sharing": "workspace:*",
"@objectstack/rest": "workspace:*",
"@objectstack/runtime": "workspace:*",
"@objectstack/service-i18n": "workspace:*",
Expand Down
15 changes: 15 additions & 0 deletions packages/plugins/plugin-dev/src/dev-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,21 @@ export class DevPlugin implements Plugin {
outcome: 'skipping security',
});
}
// The record-sharing service, beside the plugin that admits members: a
// kernel serving a private object boots only with it (plugin-security's
// sharing floor refuses the boot otherwise).
try {
const { SharingServicePlugin } = await import('@objectstack/plugin-sharing') as any;
this.childPlugins.push(new SharingServicePlugin());
ctx.logger.info(' ✔ Sharing plugin enabled (record sharing for private objects)');
} catch (err) {
reportOptionalLoadFailure(ctx, err, {
packages: ['@objectstack/plugin-sharing'],
absent: ' ℹ @objectstack/plugin-sharing not installed — skipping record sharing',
absentLevel: 'warn',
outcome: 'skipping record sharing',
});
}
}

// 6. Hono HTTP Server
Expand Down
4 changes: 4 additions & 0 deletions packages/plugins/plugin-dev/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export default defineConfig({
},
{ find: /^@objectstack\/platform-objects$/, replacement: path.resolve(__dirname, '../../platform-objects/src/index.ts') },
{ find: /^@objectstack\/plugin-security$/, replacement: path.resolve(__dirname, '../plugin-security/src/index.ts') },
// `dev-plugin.ts` composes the record-sharing plugin beside the security
// plugin through a literal `import('@objectstack/plugin-sharing')`: same
// reason as the entry above.
{ find: /^@objectstack\/plugin-sharing$/, replacement: path.resolve(__dirname, '../plugin-sharing/src/index.ts') },
// [#20376] The setup / account app packages. `dev-plugin.ts` names them with
// literal `import('…')` specifiers now, so `check:test-source-alias` sees
// both and, unaliased, both resolve through `exports` to `dist/`. Every
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,12 @@ describe('[ADR-0131 D3/D4] SecurityPlugin runs the report at kernel:bootstrapped
]);

const handlers = b.hooks.get('kernel:bootstrapped') ?? [];
// The platform baseline seam's window close (it re-derives the everyone
// anchor only when a set joined after the derivation began — none here),
// then this report, last. The grant-name backfill that ran ahead of it is
// retired (ADR-0131 D10).
expect(handlers).toHaveLength(2);
// The sharing floor (a kernel serving a private object boots only with an
// enforcing sharing service), the platform baseline seam's window close (it
// re-derives the everyone anchor only when a set joined after the
// derivation began — none here), then this report, last. The grant-name
// backfill that ran ahead of it is retired (ADR-0131 D10).
expect(handlers).toHaveLength(3);
for (const handler of handlers.slice(0, -1)) await handler();
const writes = [
vi.spyOn(b.engine, 'insert'), vi.spyOn(b.engine, 'update'), vi.spyOn(b.engine, 'delete'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ function objectsPlugin(): Plugin {
const parent = (name: string, label: string) => ({
name,
label,
// Org-wide readable: this fixture's subject is the permission-set grants, not
// row sharing, and a private object boots only with a sharing service.
sharingModel: 'public_read',
fields: { name: { type: 'text', label: 'Name' } },
});
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ function objectsPlugin(): Plugin {
const parent = (name: string, label: string) => ({
name,
label,
// Org-wide readable: this fixture's subject is the permission-set grants, not
// row sharing, and a private object boots only with a sharing service.
sharingModel: 'public_read',
fields: { name: { type: 'text', label: 'Name' } },
});
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,17 @@ function objectsPlugin(): Plugin {
{
name: ACCOUNT,
label: 'Account',
// Org-wide readable: this fixture's subject is the permission-set grants, not
// row sharing, and a private object boots only with a sharing service.
sharingModel: 'public_read',
fields: {
name: { type: 'text', label: 'Name' },
region: { type: 'text', label: 'Region' },
status: { type: 'text', label: 'Status' },
secret: { type: 'text', label: 'Secret' },
},
},
{ name: BOARD, label: 'Board', fields: { name: { type: 'text', label: 'Name' } } },
{ name: BOARD, label: 'Board', sharingModel: 'public_read', fields: { name: { type: 'text', label: 'Name' } } },
],
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function objectsPlugin(): Plugin {
{
name: MATERIAL,
label: 'Material',
// Org-wide readable: this fixture's subject is the permission-set grants, not
// row sharing, and a private object boots only with a sharing service.
sharingModel: 'public_read',
fields: {
title: { type: 'text', label: 'Title' },
uom: { type: 'text', label: 'Unit' },
Expand Down
7 changes: 5 additions & 2 deletions packages/plugins/plugin-security/src/explain-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,11 @@ function owdForPrincipal(
};
}

/** D1-equivalent OWD reading (mirrors plugin-sharing's effectiveSharingModel). */
function describeOwd(schema: any): { model: string; declared: boolean; effect: 'private' | 'read' | 'public' } {
/**
* D1-equivalent OWD reading (mirrors plugin-sharing's effectiveSharingModel).
* Also read by the sharing floor (`private-object-sharing-floor.ts`).
*/
export function describeOwd(schema: any): { model: string; declared: boolean; effect: 'private' | 'read' | 'public' } {
const m = schema?.sharingModel ?? schema?.security?.sharingModel;
if (m === 'private') return { model: 'private', declared: true, effect: 'private' };
if (m === 'public_read') return { model: 'public_read', declared: true, effect: 'read' };
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/plugin-security/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/

export { SecurityPlugin } from './security-plugin.js';
// The boot refusal for a kernel that serves a private object without an enforcing record-sharing service.
export { PrivateObjectsWithoutSharingError, SharingFloorRegistryUnreadableError } from './private-object-sharing-floor.js';
// [#33132] The shape of `SecurityPluginOptions.platformBaselineOverrides`, for a host that declares one.
export type { PlatformBaselineOverride, PlatformBaselineOverrides } from './platform-baseline-sets.js';
export { PermissionEvaluator } from './permission-evaluator.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ function objectsPlugin(): Plugin {
const appObject = (name: string, label: string, extra: Record<string, unknown> = {}) => ({
name,
label,
// Org-wide readable: this fixture's subject is the permission-set grants, not
// row sharing, and a private object boots only with a sharing service.
sharingModel: 'public_read',
fields: {
name: { type: 'text', label: 'Name' },
requester_id: { type: 'text', label: 'Requester' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ function sqliteDriverPlugin(): Plugin {
};
}

const textObject = (name: string) => ({ name, label: name, fields: { name: { type: 'text', label: 'Name' } } });
// Org-wide readable: this fixture's subject is the baseline sets, not row
// sharing, and a private object boots only with a sharing service.
const textObject = (name: string) => ({ name, label: name, sharingModel: 'public_read', fields: { name: { type: 'text', label: 'Name' } } });

/** The identity objects and the other package's object. */
function appPlugin(): Plugin {
Expand Down
Loading
Loading