Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

auth rescope --client: --operations all drops the operation snapshot

Howard Park0916b546ce5d
diff --git a/docs/guides/hosted-harness-access.md b/docs/guides/hosted-harness-access.md
index ef2c3dea56..1a391b734a 100644
--- a/docs/guides/hosted-harness-access.md
+++ b/docs/guides/hosted-harness-access.md
@@ -119,7 +119,7 @@ are one principal. See [shared brain skills](shared-brain-skills.md).
A **profile grants authority**. A **surface selects visible tools**. Full surface does not bypass a grant, and `admin` does not imply delegation, the named shared-skill scopes, or owner dashboard/client-management authority. Starter includes authorized skill discovery and membership; the exact seven-tool `verbs` surface is memory-only. Thin CLI adapters use the full surface while retaining their source, operation, and write restrictions. Direct local CLI access is trusted access to the local computer; OAuth profiles do not confine a local shell.
-New grants snapshot operation names and source access. A later server upgrade does not silently give a snapshot-bound client new operations. Explicitly regrant to include them: `gbrain auth rescope-client <client_id> --allowed-operations …` for OAuth clients, or `gbrain auth rescope-token <name> --refresh-operations` (preview) then `--add <op,...>` for legacy tokens. A `bootstrap harness` re-run carries the replaced token's grants and does not widen its snapshot ([legacy token grants](../mcp/ADMIN.md#legacy-token-grants)). Archived sources are excluded. Legacy clients with a `NULL` operation snapshot retain their prior operation behavior.
+New grants snapshot operation names and source access. A later server upgrade does not silently give a snapshot-bound client new operations. Explicitly regrant to include them: `gbrain auth rescope-client <client_id> --allowed-operations …` for OAuth clients, or `gbrain auth rescope-token <name> --refresh-operations` (preview) then `--add <op,...>` for legacy tokens. `gbrain auth rescope --client <client_id> --operations all` stores no snapshot and clears the profile instead, so the scopes and the surface alone decide, including operations later upgrades add. A `bootstrap harness` re-run carries the replaced token's grants and does not widen its snapshot ([legacy token grants](../mcp/ADMIN.md#legacy-token-grants)). Archived sources are excluded. Legacy clients with a `NULL` operation snapshot retain their prior operation behavior.
Snapshot-bound clients write through approved MCP operations such as `remember`, `capture`, or `put_page`. They cannot use the legacy `POST /ingest` webhook, whose queued writes do not yet enforce operation snapshots. Existing webhook clients with a `NULL` snapshot keep their legacy behavior.
diff --git a/docs/mcp/ADMIN.md b/docs/mcp/ADMIN.md
index 51c2a968c0..3535f17752 100644
--- a/docs/mcp/ADMIN.md
+++ b/docs/mcp/ADMIN.md
@@ -250,7 +250,7 @@ gbrain auth rescope --client CLIENT_ID --sources workspace,default --operations
| `--sources` | `a,b` or `none` | Source grant; the first id is the write source, the list is the read set. `default` is the source named `default`; to restore the no-grant floor use `--reset-default sources`. Tokens: `none` grants no source, so reads and writes to every source are refused (`permission_denied`, `fence=no_source_grant`), including writes accepted before the change. Clients: `none` refuses (`client_sources_none_unsupported`); cut a client off with `gbrain auth revoke-client <client_id>`. |
| `--read-sources` | `a,b` | Client only: a read set that differs from `--sources`. |
| `--takes-holders` | `a,b` or `none` | Token only: takes-holder allow-list; `none` hides every take. |
-| `--operations` | `op,...` or `none` | Operation snapshot; `none` refuses every operation. |
+| `--operations` | `op,...`, `none` or `all` | Operation snapshot; `none` refuses every operation. Client only: `all` stores no snapshot and clears the profile, so the scopes and the surface alone decide, including operations later upgrades add (tokens: `--reset-default operations`). |
| `--scopes` | `read,write,...` | Replaces the scopes. |
| `--reset-default` | `sources,takes-holders,operations` | Token only: restores the `auth create` default for those axes: no source grant (the historical `default` floor), holders `world`, no operation snapshot. |
| `--refresh-operations` | with optional `--add op,...` or `--all-new` | Token only: previews operations added since the snapshot. Without `--add` or `--all-new` nothing is widened. |
@@ -396,7 +396,8 @@ mutations; owner maintenance on the same process (startup migrations, hook
IPC banking) is a separate control. The default is `--access full`.
`gbrain serve --http --access read-only` refuses: narrow HTTP access per token
with `gbrain auth rescope-token <name> --operations <op,...>` or
-`gbrain auth rescope-client <client_id> --allowed-operations <op,...>`.
+`gbrain auth rescope-client <client_id> --allowed-operations <op,...>`
+(`all` removes a client's snapshot again).
## Invalidate tokens, revoke, or delete
diff --git a/src/commands/auth.ts b/src/commands/auth.ts
index 68ea876fdb..1a49f5490a 100644
--- a/src/commands/auth.ts
+++ b/src/commands/auth.ts
@@ -1125,7 +1125,10 @@ Usage:
tokens only — revoke a client with revoke-client)
--read-sources <id1,id2,...> Client only: a read set that differs from --sources
--takes-holders <h1,h2,...|none> Token only: takes-holder allow-list ('none' = deny-all)
- --operations <op1,op2,...|none> Operation snapshot ('none' = deny-all)
+ --operations <op1,op2,...|none|all> Operation snapshot ('none' = deny-all). Client only:
+ 'all' = no snapshot: every operation the scopes and the
+ surface allow, including ones later upgrades add; clears
+ the profile (tokens: --reset-default operations)
--scopes <read,write,...> Replace the scopes
--reset-default <sources,takes-holders,operations> Token only: restore the auth create default for those axes
--refresh-operations [--add <op,...>|--all-new] Token only: preview operations added since the snapshot;
diff --git a/src/commands/serve-http-grants.ts b/src/commands/serve-http-grants.ts
index 8952bee839..711231d4e1 100644
--- a/src/commands/serve-http-grants.ts
+++ b/src/commands/serve-http-grants.ts
@@ -23,6 +23,8 @@ export function parseAdminGrantRequest(body: Record<string, unknown>, existing?:
if (!Array.isArray(value) || !value.every(v => typeof v === 'string')) invalid(field, 'an array of strings');
patch[field] = value as string[];
}
+ // A null operation list is valid only without a profile: the profile is where the snapshot came from.
+ if (body.allowedOperations === null && body.profile === undefined) patch.profile = null;
const source = body.sourceId ?? body.source;
if (source !== undefined) {
if (typeof source !== 'string' || !source.trim()) invalid('sourceId', 'a non-empty source ID');
diff --git a/src/core/grants/cli.ts b/src/core/grants/cli.ts
index 3038e8d8a4..54598087b8 100644
--- a/src/core/grants/cli.ts
+++ b/src/core/grants/cli.ts
@@ -31,7 +31,10 @@ function parseRescopeGrantFlags(args: string[]): RescopeGrantArgs {
case '--federated-read': result.patch.federatedRead = csv(value); break;
case '--scopes': result.patch.scopes = parseScopeString(value.replaceAll(',', ' ')); assertAllowedScopes(result.patch.scopes); break;
case '--bound-slug-prefixes': result.patch.boundSlugPrefixes = value === 'none' ? null : csv(value); break;
- case '--allowed-operations': result.patch.allowedOperations = csv(value); break;
+ case '--allowed-operations':
+ if (value === 'all') clearOperationSnapshot(result.patch);
+ else result.patch.allowedOperations = csv(value);
+ break;
case '--bound-tools': result.patch.boundTools = csv(value); break;
case '--bound-source': result.patch.boundSourceId = value; break;
case '--bound-brain': result.patch.boundBrainId = value === 'current' || value === 'host' ? null : value; break;
@@ -59,9 +62,27 @@ function parseRescopeGrantFlags(args: string[]): RescopeGrantArgs {
default: throw new GrantError('invalid_grant', `Unknown flag: ${flag}`);
}
}
+ assertProfileKept(result, '--allowed-operations all');
return result;
}
+/**
+ * `all`: store no operation snapshot, so the scopes and the surface alone
+ * decide, including operations later releases add. A null list is valid only
+ * without a profile (the profile is where the snapshot came from), so the
+ * profile is cleared with it, matching a fresh `register-client`.
+ */
+function clearOperationSnapshot(patch: GrantPatch): void {
+ patch.allowedOperations = null;
+ patch.profile = null;
+}
+
+function assertProfileKept(result: RescopeGrantArgs, flag: string): void {
+ if (result.profile && result.patch.profile === null) {
+ throw new GrantError('invalid_grant', `${flag} clears the grant profile and its operation snapshot; pass it or --profile, not both`);
+ }
+}
+
// ---------------------------------------------------------------------------
// F3: `gbrain auth rescope`, one command for legacy tokens and OAuth clients.
// ---------------------------------------------------------------------------
@@ -124,7 +145,7 @@ const TOKEN_ONLY_FLAGS: Record<string, string> = {
/**
* Client flags of `auth rescope --client`: the unified `--sources a,b`
* (element 0 = write source, the list = read set unless `--read-sources`
- * names a different one), `--read-sources`, `--operations a,b|none` and every
+ * names a different one), `--read-sources`, `--operations a,b|none|all` and every
* `auth rescope-client` flag. `--sources none` refuses (decision 4: client
* deny-all is `auth revoke-client`).
*/
@@ -132,7 +153,7 @@ export function parseClientRescopeArgs(clientId: string, args: string[]): Rescop
const legacy: string[] = [];
let sources: string[] | undefined;
let readSources: string[] | undefined;
- let operations: string[] | undefined;
+ let operations: string[] | 'all' | undefined;
const csv = (value: string): string[] => [...new Set(value.split(',').map(s => s.trim()).filter(Boolean))];
for (let i = 0; i < args.length; i++) {
const flag = args[i];
@@ -148,7 +169,7 @@ export function parseClientRescopeArgs(clientId: string, args: string[]): Rescop
if (value === undefined || value.startsWith('--')) throw new GrantError('invalid_grant', `${flag} requires a value`);
if (flag === '--sources') sources = value === 'none' ? [] : csv(value);
if (flag === '--read-sources') readSources = csv(value);
- if (flag === '--operations') operations = value === 'none' ? [] : csv(value);
+ if (flag === '--operations') operations = value === 'none' ? [] : value === 'all' ? 'all' : csv(value);
}
const result = parseRescopeGrantFlags(legacy);
if (sources !== undefined) {
@@ -161,7 +182,10 @@ export function parseClientRescopeArgs(clientId: string, args: string[]): Rescop
}
if (readSources !== undefined && readSources.length === 0) throw new GrantError('invalid_grant', '--read-sources needs at least one source id');
if (sources !== undefined || readSources !== undefined) result.patch.federatedRead = readSources ?? sources;
- if (operations !== undefined) result.patch.allowedOperations = operations;
+ if (operations === 'all') {
+ clearOperationSnapshot(result.patch);
+ assertProfileKept(result, '--operations all');
+ } else if (operations !== undefined) result.patch.allowedOperations = operations;
if (!result.profile && Object.keys(result.patch).length === 0) throw new GrantError('invalid_grant', 'Pass a grant field or --profile to rescope');
return result;
}
diff --git a/src/core/grants/legacy-token.ts b/src/core/grants/legacy-token.ts
index 6cabbaf834..9f8be741ac 100644
--- a/src/core/grants/legacy-token.ts
+++ b/src/core/grants/legacy-token.ts
@@ -109,7 +109,10 @@ export function parseRescopeTokenArgs(args: string[]): RescopeTokenArgs {
break;
case '--sources': out.sources = csvOrNone(value); break;
case '--takes-holders': out.takesHolders = csvOrNone(value); break;
- case '--operations': out.operations = csvOrNone(value); break;
+ case '--operations':
+ if (value === 'all') throw new GrantError('invalid_grant', '--operations all applies to OAuth clients; to give a token every operation again, use --reset-default operations');
+ out.operations = csvOrNone(value);
+ break;
case '--add': out.add = csvOrNone(value); break;
case '--scopes':
out.scopes = csvOrNone(value.replaceAll(' ', ','));
diff --git a/test/access-token-grants.test.ts b/test/access-token-grants.test.ts
index b7b58d612c..89ba91369e 100644
--- a/test/access-token-grants.test.ts
+++ b/test/access-token-grants.test.ts
@@ -208,6 +208,11 @@ describe('5. lazy migration on rescope', () => {
await rescope(t.name, '--sources', 'other', '--dry-run');
expect((await rowOf(t.id)).source_grant).toBeNull();
});
+
+ test('--operations all is client-only and points a token at --reset-default operations', () => {
+ expect(() => parseRescopeTokenArgs(['tok-example', '--operations', 'all'])).toThrow('--reset-default operations');
+ expect(parseRescopeTokenArgs(['tok-example', '--reset-default', 'operations']).reset).toEqual(['operations']);
+ });
});
describe('6. drift: an older binary edits the JSONB after migration', () => {
diff --git a/test/auth-rescope-unified.serial.test.ts b/test/auth-rescope-unified.serial.test.ts
index c24e77a34c..0625f905fd 100644
--- a/test/auth-rescope-unified.serial.test.ts
+++ b/test/auth-rescope-unified.serial.test.ts
@@ -25,6 +25,7 @@ import { sqlQueryForEngine, executeRawJsonb } from '../src/core/sql-query.ts';
import { mintHarnessToken } from '../src/core/bootstrap/harness.ts';
import { mintLegacyToken } from '../src/core/token-mint.ts';
import { grantFromTokenRow } from '../src/core/grants/model.ts';
+import { resolveGrantProfile } from '../src/core/grants/profiles.ts';
import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { withEnv } from './helpers/with-env.ts';
@@ -168,6 +169,27 @@ describe('9. OAuth clients', () => {
expect(holders.stderr).toContain('--takes-holders applies to legacy tokens only');
}, 180_000);
+ test('--operations all drops a profile snapshot on both client spellings; a token refuses it', async () => {
+ const [a, b] = await withBrain(async engine => {
+ const provider = new GBrainOAuthProvider({ sql: sqlQueryForEngine(engine), transaction: fn => engine.transaction(tx => fn(sqlQueryForEngine(tx))) });
+ const register = (name: string) => provider.registerClientManual(name, ['client_credentials'], 'read write', [], 'default', undefined, undefined, undefined,
+ resolveGrantProfile({ profile: 'memory-writer', sourceId: 'default' }));
+ return [await register('client-all-a-example'), await register('client-all-b-example')];
+ });
+ const grantRow = (id: string) => withBrain(async engine =>
+ (await engine.executeRaw<Record<string, unknown>>('SELECT grant_profile, allowed_operations, scope FROM oauth_clients WHERE client_id = $1', [id]))[0]);
+ expect((await grantRow(a.clientId)).grant_profile).toBe('memory-writer');
+ expect((await cli('auth', 'rescope', '--client', a.clientId, '--operations', 'all')).exitCode).toBe(0);
+ expect((await cli('auth', 'rescope-client', b.clientId, '--allowed-operations', 'all')).exitCode).toBe(0);
+ for (const id of [a.clientId, b.clientId]) expect(await grantRow(id)).toEqual({ grant_profile: null, allowed_operations: null, scope: 'read write' });
+
+ expect((await cli('auth', 'create', 'tok-all')).exitCode).toBe(0);
+ const token = await cli('auth', 'rescope', '--token', 'tok-all', '--operations', 'all');
+ expect(token.exitCode).toBe(1);
+ expect(token.stderr).toContain('--reset-default operations');
+ expect((await tokenRow('tok-all')).allowed_operations).toBeNull();
+ }, 180_000);
+
test('a bare name that matches both a token and a client refuses as ambiguous', async () => {
const client = await withBrain(async engine => {
const provider = new GBrainOAuthProvider({ sql: sqlQueryForEngine(engine), transaction: fn => engine.transaction(tx => fn(sqlQueryForEngine(tx))) });
diff --git a/test/client-grants.test.ts b/test/client-grants.test.ts
index 577e114ed4..c5406d4074 100644
--- a/test/client-grants.test.ts
+++ b/test/client-grants.test.ts
@@ -7,7 +7,7 @@ import { hashToken } from '../src/core/utils.ts';
import { hasScope } from '../src/core/scope.ts';
import { readClientGrant, rescopeClientGrant, resolveGrantProfile, intersectGrantedScopes, grantValidationContext, delegationReasons } from '../src/core/grants/service.ts';
import { repairLegacyClientGrants } from '../src/core/grants/migration.ts';
-import { parseRescopeGrantArgs } from '../src/core/grants/cli.ts';
+import { parseClientRescopeArgs, parseRescopeGrantArgs } from '../src/core/grants/cli.ts';
import type { AuthInfo } from '../src/core/ops/contract.ts';
import type { Response } from 'express';
import { opAllowedForBoundClient } from '../src/core/ops/context.ts';
@@ -327,6 +327,38 @@ describe('client capability grants', () => {
expect(parsed.dryRun).toBe(true);
expect(() => parseRescopeGrantArgs(['--if-version', '-1'])).toThrow('non-negative');
});
+
+ test('operations all drops the snapshot and the profile; a csv still sets a snapshot', () => {
+ expect(parseRescopeGrantArgs(['--allowed-operations', 'all']).patch).toEqual({ allowedOperations: null, profile: null });
+ expect(parseClientRescopeArgs('client-example', ['--operations', 'all']).patch).toEqual({ allowedOperations: null, profile: null });
+ expect(parseClientRescopeArgs('client-example', ['--allowed-operations', 'all']).patch).toEqual({ allowedOperations: null, profile: null });
+ expect(parseRescopeGrantArgs(['--allowed-operations', 'get_page,search']).patch).toEqual({ allowedOperations: ['get_page', 'search'] });
+ expect(() => parseRescopeGrantArgs(['--profile', 'memory-writer', '--allowed-operations', 'all'])).toThrow('not both');
+ expect(() => parseClientRescopeArgs('client-example', ['--profile', 'memory-writer', '--operations', 'all'])).toThrow('not both');
+ });
+
+ test('admin API: a null operation list clears the profile unless a profile is named', () => {
+ expect(parseAdminGrantRequest({ allowedOperations: null }).patch).toEqual({ allowedOperations: null, profile: null });
+ const named = parseAdminGrantRequest({ allowedOperations: null, profile: 'memory-writer' }).patch;
+ expect(named.profile).toBe('memory-writer');
+ expect(named.scopes).toEqual(['read', 'write']);
+ expect(parseAdminGrantRequest({ allowedOperations: ['get_page'] }).patch.profile).toBeUndefined();
+ });
+
+ test('a profile-snapshot client rescoped to operations all returns to the unrestricted grant', async () => {
+ const created = await memoryClient('operations-all-example');
+ const before = await readClientGrant(engine, created.clientId);
+ expect(before.profile).toBe('memory-writer');
+ expect(before.allowedOperations!.length).toBeGreaterThan(0);
+ await expect(rescopeClientGrant(engine, created.clientId, { allowedOperations: null }, { actor: 'test' })).rejects.toThrow();
+ const result = await rescopeClientGrant(engine, created.clientId, parseClientRescopeArgs(created.clientId, ['--operations', 'all']).patch,
+ { actor: 'test', expectedRevision: before.revision });
+ expect(result.after).toMatchObject({ profile: null, allowedOperations: null, scopes: before.scopes, surface: before.surface });
+ const [row] = await engine.executeRaw('SELECT grant_profile, allowed_operations FROM oauth_clients WHERE client_id = $1', [created.clientId]);
+ expect(row).toEqual({ grant_profile: null, allowed_operations: null });
+ const tokens = await provider.exchangeClientCredentials(created.clientId, created.clientSecret!);
+ await expect(provider.verifyAccessToken(tokens.access_token)).resolves.toBeDefined();
+ });
});
describe('OAuth code and refresh grant boundaries', () => {