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
17 changes: 17 additions & 0 deletions .changeset/33224-setup-audit-log-entry-audience.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/platform-objects': patch
'@objectstack/plugin-audit': patch
---

fix(platform-objects, plugin-audit)!: a member who holds `view_all_audit_log` and not `manage_platform_settings` (a separation-of-duties auditor) now finds the Audit Log entry in Setup › Diagnostics (#33224)

Clause-②: yes (narrowing) — `GET /meta/app/setup` now serves `group_diagnostics` with the Audit Log entry (`nav_audit_logs`) to a member who holds `view_all_audit_log` without `manage_platform_settings`; before, the whole group was withheld from them. Every shipped permission set is served what it was before: `admin_full_access` holds both capabilities and still sees Sessions, Notification Events and Audit Log; `organization_admin` and the member sets hold neither and still see no Diagnostics group. One custom-set audience narrows: a set granting `manage_platform_settings` without `view_all_audit_log` is no longer served the Audit Log entry. A gate is all-of, so the entry cannot be gated on either capability.
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) No key of any authorable schema, accepted value or metadata type is added, removed, renamed or re-shaped. What moves is which entries of the platform's own Setup app the served app read lists for a caller, so nothing is stored for a migration to rewrite and nothing needs a tombstone. -->

**BREAKING** for a custom permission set that grants `manage_platform_settings` without `view_all_audit_log`. Its holders were served the Setup › Diagnostics › Audit Log entry and no longer are. The Audit Log page itself is unchanged: it still opens by URL and still shows them the organization-attributed ledger rows it showed before. What to do: grant `view_all_audit_log` to that set if its holders should keep the menu entry, or open the page by URL. A third-party package that contributes an entry into `group_diagnostics` without its own `requiredPermissions` is now shown to every member who can open Setup, where before only `manage_platform_settings` holders saw it: declare `requiredPermissions` on the entry (see below).

**What moved.** The Setup app's `group_diagnostics` slot carried `requiredPermissions: ['manage_platform_settings']`, and a group's gate prunes its whole subtree before any child is judged, so the audit entry contributed into it could never reach an auditor. The slot now carries no gate, and each entry carries its own: Sessions (`nav_sessions`) and Notification Events (`nav_notifications`) keep `manage_platform_settings`, and Audit Log is gated on `view_all_audit_log`, the ledger's own read capability.

**If you contribute into `group_diagnostics`.** The slot no longer gates what you put in it. An entry that should stay admin-only declares `requiredPermissions` on the entry itself, as the platform's own entries now do.
176 changes: 176 additions & 0 deletions packages/cli/test/setup-diagnostics-audience.pin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
//
// Setup → Diagnostics, served per AUDIENCE: each entry reaches the members who
// hold its own gate, and no one else.
//
// ---------------------------------------------------------------------------
// What this pins
// ---------------------------------------------------------------------------
// A group's `requiredPermissions` prunes its whole subtree before any child is
// judged (`filterAppForUserWithReason`, `@objectstack/rest`). `group_diagnostics`
// used to carry `manage_platform_settings`, so the Audit Log entry
// (`nav_audit_logs`, contributed by `@objectstack/plugin-audit`) never reached
// an auditor who holds `view_all_audit_log` — the ledger's own read capability —
// and no platform-settings power: the separation-of-duties audit officer found
// no audit entry in Setup, while the page itself answered by URL.
//
// The gate moved off the group and onto the entries: Audit Log on
// `view_all_audit_log`, Sessions and Notification Events on the
// `manage_platform_settings` the group carried. Read over the wire, per caller:
//
// - `view_all_audit_log` alone → Diagnostics holds Audit Log, only;
// - `manage_platform_settings` alone → Sessions and Notification Events, and
// NOT Audit Log (no entry reaches a
// member who lacks its own gate);
// - neither → no Diagnostics group at all;
// - the platform administrator → all three, as before.
//
// ---------------------------------------------------------------------------
// Why it lives in `packages/cli/test/`
// ---------------------------------------------------------------------------
// The reason `console-page-nav-entries.pin.test.ts` beside it gives: this is a
// composed fact across the Setup shell (`@objectstack/platform-objects`), the
// audit plugin's contribution, the registry fold (`@objectstack/objectql`) and
// the per-request filter (`@objectstack/rest`), and `packages/cli` is the one
// workspace package that depends on all of them. `@objectstack/plugin-audit`
// resolves to its source here (this package's `vitest.config.ts` aliases it).

import { describe, expect, it, vi } from 'vitest';
import { SchemaRegistry } from '@objectstack/objectql';
import { SETUP_APP, SETUP_NAV_CONTRIBUTIONS } from '@objectstack/platform-objects/apps';
import { AuditPlugin } from '@objectstack/plugin-audit';
import { RestServer } from '@objectstack/rest';
import { ADMIN_FULL_ACCESS_CAPABILITIES } from '@objectstack/spec';

type AnyRec = Record<string, any>;

const GROUP = 'group_diagnostics';

/**
* The manifests a plugin registers from `init()`, captured off a context that
* serves exactly the `manifest` service, with inert stand-ins for the rest of
* the interface (`packages/core/src/types.ts`).
*/
async function manifestsRegisteredBy(plugin: { init(ctx: any): Promise<void> | void }): Promise<AnyRec[]> {
const manifests: AnyRec[] = [];
const ctx = {
getService: (name: string) => (name === 'manifest' ? { register: (m: AnyRec) => manifests.push(m) } : undefined),
registerService: () => {},
registerServiceFactory: () => {},
replaceService: () => {},
getServiceScoped: async () => undefined,
getServices: () => new Map(),
hook: () => {},
trigger: async () => {},
logger: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} },
getKernel: () => undefined,
};
await plugin.init(ctx);
return manifests;
}

/**
* The Setup shell, `@objectstack/platform-objects`' own contributions and the
* audit plugin's, through the real registry fold. `structuredClone` because
* `registerApp` writes the `_lock` envelope onto what it is handed.
*/
async function composedRegistry(): Promise<SchemaRegistry> {
const registry = new SchemaRegistry({ multiTenant: false, collisionPolicy: 'error' });
(registry as AnyRec).logLevel = 'silent';
registry.registerApp(structuredClone(SETUP_APP), '@objectstack/platform-objects');
for (const contribution of SETUP_NAV_CONTRIBUTIONS) {
registry.registerAppNavContribution(structuredClone(contribution) as any, '@objectstack/platform-objects');
}
const audit = await manifestsRegisteredBy(new AuditPlugin());
expect(audit).toHaveLength(1);
for (const contribution of audit[0].navigationContributions ?? []) {
registry.registerAppNavContribution(structuredClone(contribution), audit[0].id);
}
return registry;
}

function createMockServer() {
return {
get: vi.fn(), post: vi.fn(), put: vi.fn(), delete: vi.fn(), patch: vi.fn(), use: vi.fn(),
listen: vi.fn().mockResolvedValue(undefined), close: vi.fn().mockResolvedValue(undefined),
};
}

function makeRes() {
const res: AnyRec = { statusCode: 200, body: undefined };
res.status = vi.fn((c: number) => { res.statusCode = c; return res; });
res.json = vi.fn((b: unknown) => { res.body = b; return res; });
res.header = vi.fn(); res.setHeader = vi.fn(); res.write = vi.fn(); res.end = vi.fn();
return res;
}

/** `GET /api/v1/meta/apps/setup` as a caller holding exactly `systemPermissions`. */
async function servedSetup(systemPermissions: readonly string[]): Promise<AnyRec> {
const registry = await composedRegistry();
const protocol: AnyRec = {
getDiscovery: vi.fn().mockResolvedValue({
version: 'v0', routes: { data: '', metadata: '', ui: '', auth: '/auth' },
}),
getMetaTypes: vi.fn().mockResolvedValue([]),
getMetaItems: vi.fn(async ({ type }: AnyRec) => {
const t = String(type ?? '');
return t === 'app' || t === 'apps' ? registry.getAllApps() : [];
}),
getMetaItem: vi.fn(async ({ name }: AnyRec) => {
const item = registry.getApp(String(name));
return item ? { type: 'app', name, item } : undefined;
}),
findData: vi.fn().mockResolvedValue([]),
};
const rest: AnyRec = new RestServer(
createMockServer() as any, protocol as any, { api: { requireAuth: false } } as any,
);
rest.resolveExecCtx = async () => ({ userId: 'u1', systemPermissions: [...systemPermissions] });
rest.registerRoutes();
const route = rest.getRoutes().find(
(r: AnyRec) => r.method === 'GET' && r.path === '/api/v1/meta/:type/:name',
);
if (!route) throw new Error('meta/:type/:name route not registered');
const res = makeRes();
await route.handler(
{ method: 'GET', params: { type: 'apps', name: 'setup' }, query: {}, body: {}, headers: {} }, res,
);
expect(res.statusCode).toBe(200);
return res.body?.item;
}

/** The served children of `GROUP` by id, or `undefined` when the group is not served. */
function diagnostics(app: AnyRec): string[] | undefined {
const found = ((app?.navigation ?? []) as AnyRec[]).find((g) => g?.id === GROUP);
return found ? ((found.children ?? []) as AnyRec[]).map((c) => String(c?.id)) : undefined;
}

/** Every served entry id at any depth: an entry cannot be hiding in another group. */
function allIds(items: AnyRec[] | undefined): string[] {
return (items ?? []).flatMap((i) => [String(i?.id), ...allIds(i?.children)]);
}

describe('Setup → Diagnostics: each entry is served to the holders of its own gate', () => {
it('a member holding view_all_audit_log, and no platform-settings power, is served the Audit Log entry', async () => {
const setup = await servedSetup(['setup.access', 'view_all_audit_log']);
expect(diagnostics(setup)).toEqual(['nav_audit_logs']);
});

it('a member without view_all_audit_log is not served the Audit Log entry, anywhere in Setup', async () => {
const settingsOnly = await servedSetup(['setup.access', 'manage_platform_settings']);
expect(diagnostics(settingsOnly)?.sort()).toEqual(['nav_notifications', 'nav_sessions']);
expect(allIds(settingsOnly.navigation)).not.toContain('nav_audit_logs');

const neither = await servedSetup(['setup.access']);
expect(diagnostics(neither)).toBeUndefined();
expect(allIds(neither.navigation)).not.toContain('nav_audit_logs');
// Control: the app itself is served to this member, so the absence above
// is the entry's gate and not a withheld app.
expect(allIds(neither.navigation).length).toBeGreaterThan(0);
});

it('the platform administrator is served all three entries, as before', async () => {
const admin = await servedSetup(ADMIN_FULL_ACCESS_CAPABILITIES.systemPermissions ?? []);
expect(diagnostics(admin)?.sort()).toEqual(['nav_audit_logs', 'nav_notifications', 'nav_sessions']);
});
});
10 changes: 7 additions & 3 deletions packages/platform-objects/src/apps/setup-nav.contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ export const SETUP_NAV_CONTRIBUTIONS: NavigationContribution[] = [
priority: BASE_PRIORITY,
items: [
// Audit Logs (sys_audit_log) is contributed by @objectstack/plugin-audit
// which now owns it (ADR-0029 K2).
{ id: 'nav_sessions', type: 'object', label: 'Sessions', objectName: 'sys_session', viewName: 'all_sessions', icon: 'monitor' },
{ id: 'nav_notifications', type: 'object', label: 'Notification Events', objectName: 'sys_notification', viewName: 'recent', icon: 'bell', requiresObject: 'sys_notification' },
// which now owns it (ADR-0029 K2), gated on its own read capability.
//
// `group_diagnostics` carries no gate of its own, so each entry here
// carries the `manage_platform_settings` gate the group used to: the
// two entries are served to exactly the members they were before.
{ id: 'nav_sessions', type: 'object', label: 'Sessions', objectName: 'sys_session', viewName: 'all_sessions', icon: 'monitor', requiredPermissions: ['manage_platform_settings'] },
{ id: 'nav_notifications', type: 'object', label: 'Notification Events', objectName: 'sys_notification', viewName: 'recent', icon: 'bell', requiresObject: 'sys_notification', requiredPermissions: ['manage_platform_settings'] },
],
},
{
Expand Down
12 changes: 11 additions & 1 deletion packages/platform-objects/src/apps/setup.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@ export const SETUP_APP: App = {
type: 'group',
label: 'Diagnostics',
icon: 'stethoscope',
requiredPermissions: ['manage_platform_settings'],
// No group gate: each entry carries its own. A group's
// `requiredPermissions` prunes its whole subtree before any child is
// judged (`filterAppForUserWithReason` in `@objectstack/rest`, and the
// console's sidebar guard alike), so a group gate here hid the Audit
// Log entry from a holder of `view_all_audit_log`, its own read
// capability, who does not also hold `manage_platform_settings` — the
// separation-of-duties auditor. The gate moved down onto the entries
// that need it (`setup-nav.contributions.ts`; `@objectstack/plugin-audit`
// gates its entry on `view_all_audit_log`), as `group_configuration`
// already does. ⛔ A contributor into this slot gates its own entry: the
// slot no longer gates it.
children: [],
},
{
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/plugin-audit/src/audit-nav-contribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
//
// Why here and not in `@objectstack/platform-objects`: the page reads
// `sys_audit_log`, which this plugin owns (ADR-0029 K2), so its entry lives and
// dies with this plugin — and needs no item gate for the same reason.
// dies with this plugin. Its one gate is the ledger's own read capability
// (`view_all_audit_log`); who it is served to, read over the wire per caller,
// is pinned in `packages/cli/test/setup-diagnostics-audience.pin.test.ts`.

import { describe, it, expect } from 'vitest';
import { SchemaRegistry } from '@objectstack/objectql';
import { SETUP_APP, SETUP_NAV_CONTRIBUTIONS } from '@objectstack/platform-objects/apps';
import { NavigationContributionSchema } from '@objectstack/spec/ui';
import { AuditPlugin } from './audit-plugin.js';
import { LEDGER_AUDIT_CAPABILITY } from './audit-log-read-visibility.js';

type NavItem = {
id?: string;
Expand All @@ -33,6 +36,7 @@ type NavItem = {
url?: string;
requiresService?: string;
requiresObject?: string;
requiredPermissions?: string[];
children?: NavItem[];
};

Expand Down Expand Up @@ -111,10 +115,16 @@ describe('AuditPlugin — one Setup audit entry (#23890)', () => {
// The list is reached from the page's "Open as list" link, so the entry
// names no object. A component item has no object route to gate, and a
// contribution exists only while this plugin is installed — which is
// exactly when the page's `sys_audit_log` reads can answer. No gate.
// exactly when the page's `sys_audit_log` reads can answer. No
// runtime-capability gate (`requiresObject` / `requiresService`).
expect(entry.objectName).toBeUndefined();
expect(entry.requiresObject).toBeUndefined();
expect(entry.requiresService).toBeUndefined();
// Its audience is the ledger's own read capability, never the Setup
// slot's admin power: `view_all_audit_log` alone, so an auditor who holds
// no `manage_platform_settings` is served the entry.
expect(entry.requiredPermissions).toEqual([LEDGER_AUDIT_CAPABILITY]);
expect(LEDGER_AUDIT_CAPABILITY).toBe('view_all_audit_log');
});

it('the rendered Setup nav has exactly one entry whose target is an audit surface', async () => {
Expand Down
14 changes: 11 additions & 3 deletions packages/plugins/plugin-audit/src/audit-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import { installActivityReadVisibility } from './activity-read-visibility.js';
import { installActivityFieldRedaction } from './activity-field-redaction.js';
import { installActivitySummaryLocale } from './activity-summary-message.js';
import { installAuditLogFieldRedaction } from './audit-log-field-redaction.js';
import { installAuditLogReadVisibility } from './audit-log-read-visibility.js';
import { installAuditLogReadVisibility, LEDGER_AUDIT_CAPABILITY } from './audit-log-read-visibility.js';
import type { FieldVisibilitySource } from './served-fields.js';
import { installParentFieldQueryGuards } from './parent-field-query-guard.js';
import type { ParentObjectReadAdmission } from './parent-record-read-gate.js';
Expand Down Expand Up @@ -350,7 +350,15 @@ export class AuditPlugin implements Plugin {
pages: [SysAuditLogDetailPage],
// ADR-0029 D7 — contribute the one Audit Log entry into the Setup app's
// `group_diagnostics` slot. The plugin owns sys_audit_log (K2), so the
// entry lives and dies with this plugin and needs no item gate.
// entry lives and dies with this plugin.
//
// The entry is gated on `view_all_audit_log`, the ledger's own read
// capability (`LEDGER_AUDIT_CAPABILITY`), not on the slot's: the slot
// carries no gate, because a group gate prunes every child before the
// child is judged, and `manage_platform_settings` there hid the entry
// from an auditor who holds the read capability and no platform-settings
// power (separation of duties). Platform administrators hold both by
// default (`ADMIN_FULL_ACCESS_CAPABILITIES`), so they still see it.
//
// #23890 — ONE entry, and it opens the console's audit browser (the
// `audit:log` registry key, objectui `registerSystemComponents.tsx`):
Expand All @@ -372,7 +380,7 @@ export class AuditPlugin implements Plugin {
group: 'group_diagnostics',
priority: 100,
items: [
{ id: 'nav_audit_logs', type: 'component', label: 'Audit Log', componentRef: 'audit:log', icon: 'scroll-text' },
{ id: 'nav_audit_logs', type: 'component', label: 'Audit Log', componentRef: 'audit:log', icon: 'scroll-text', requiredPermissions: [LEDGER_AUDIT_CAPABILITY] },
],
},
],
Expand Down
Loading