@fabrika/iam 0.9.0-dev.35 → 0.9.0-dev.36
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/migrations/0035_grant_requests.sql +41 -0
- package/migrations-postgres/0035_grant_requests.sql +41 -0
- package/package.json +11 -11
- package/src/admin/app-people.ts +54 -1
- package/src/admin/grant-requests.ts +253 -0
- package/src/admin/grants.ts +73 -4
- package/src/admin/rpc.ts +36 -0
- package/src/db.ts +4 -0
- package/src/oauth-http.ts +22 -2
- package/src/oauth.ts +52 -6
- package/src/repositories/audit.ts +5 -2
- package/src/repositories/grant-requests.ts +134 -0
- package/src/repositories/grants.ts +105 -0
- package/src/tokens.ts +1 -1
- package/types/src/admin/grant-requests.d.ts +42 -0
- package/types/src/admin/grants.d.ts +4 -4
- package/types/src/db.d.ts +3 -0
- package/types/src/oauth.d.ts +20 -6
- package/types/src/repositories/audit.d.ts +2 -0
- package/types/src/repositories/grant-requests.d.ts +64 -0
- package/types/src/repositories/grants.d.ts +16 -0
- package/types/src/tokens.d.ts +7 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type SqlDatabase } from '@fabrika/platform';
|
|
2
|
+
import { type AuditEventInput, AuditWriter } from './audit';
|
|
3
|
+
/**
|
|
4
|
+
* One requested grant change at an application whose console grants wait for approval (ADR-0083). Nothing that resolves
|
|
5
|
+
* permissions reads it; `GrantRepository.applyRequest` writes the change when a person approves it.
|
|
6
|
+
*/
|
|
7
|
+
export interface GrantRequestRow {
|
|
8
|
+
id: string;
|
|
9
|
+
app: string;
|
|
10
|
+
kind: 'create' | 'update' | 'revoke';
|
|
11
|
+
principal_id: string;
|
|
12
|
+
/** The grant an `update` edits or a `revoke` removes; null for `create`. */
|
|
13
|
+
grant_id: string | null;
|
|
14
|
+
role_key: string | null;
|
|
15
|
+
/** Inline action-pattern set (JSON array); XOR `role_key`. */
|
|
16
|
+
permissions: string | null;
|
|
17
|
+
scope_type: string | null;
|
|
18
|
+
scope_value: string | null;
|
|
19
|
+
grant_expires_at: number | null;
|
|
20
|
+
requested_by: string;
|
|
21
|
+
requested_at: number;
|
|
22
|
+
expires_at: number;
|
|
23
|
+
status: 'pending' | 'approved' | 'rejected' | 'failed';
|
|
24
|
+
/** The approval that claimed it, which the change it wrote carries in its guard. */
|
|
25
|
+
decision_id: string | null;
|
|
26
|
+
decided_by: string | null;
|
|
27
|
+
decided_at: number | null;
|
|
28
|
+
}
|
|
29
|
+
export interface CreateGrantRequestInput {
|
|
30
|
+
app: string;
|
|
31
|
+
kind: GrantRequestRow['kind'];
|
|
32
|
+
principalId: string;
|
|
33
|
+
grantId: string | null;
|
|
34
|
+
roleKey: string | null;
|
|
35
|
+
permissions: string[] | null;
|
|
36
|
+
scopeType: string | null;
|
|
37
|
+
scopeValue: string | null;
|
|
38
|
+
grantExpiresAt: number | null;
|
|
39
|
+
requestedBy: string;
|
|
40
|
+
requestedAt: number;
|
|
41
|
+
expiresAt: number;
|
|
42
|
+
}
|
|
43
|
+
export declare class GrantRequestRepository {
|
|
44
|
+
private readonly db;
|
|
45
|
+
private readonly writer;
|
|
46
|
+
constructor(db: SqlDatabase, writer?: AuditWriter);
|
|
47
|
+
/** Whether a grant change at `app` waits for approval. */
|
|
48
|
+
grantsWait(app: string): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Set whether grant changes at `app` wait, as of Control's protection `revision`. An older revision than the stored one
|
|
51
|
+
* changes nothing, so a caller that lost the environment's lease cannot undo its successor's gate. The record is written
|
|
52
|
+
* only when `required` changes.
|
|
53
|
+
*/
|
|
54
|
+
setGrantsWait(app: string, required: boolean, revision: number, now: number, audit: AuditEventInput): Promise<{
|
|
55
|
+
required: boolean;
|
|
56
|
+
revision: number;
|
|
57
|
+
}>;
|
|
58
|
+
create(input: CreateGrantRequestInput, audit: (requestId: string) => AuditEventInput): Promise<GrantRequestRow>;
|
|
59
|
+
get(id: string): Promise<GrantRequestRow | null>;
|
|
60
|
+
/** Every request still open at `now`, the oldest first. */
|
|
61
|
+
listOpen(now: number): Promise<GrantRequestRow[]>;
|
|
62
|
+
/** Reject an open request; null when it was decided or lapsed meanwhile. */
|
|
63
|
+
reject(id: string, decidedBy: string, now: number, audit: AuditEventInput): Promise<GrantRequestRow | null>;
|
|
64
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type SqlDatabase, type SqlStatement } from '@fabrika/platform';
|
|
2
2
|
import { type AuditEventInput, AuditWriter, type SqlChange, type SqlDialect } from './audit';
|
|
3
|
+
import type { GrantRequestRow } from './grant-requests';
|
|
3
4
|
/** A grant written for a workload principal: its authority is its declared actions, never a grant. */
|
|
4
5
|
export declare class WorkloadGrantError extends Error {
|
|
5
6
|
readonly name = "WorkloadGrantError";
|
|
@@ -163,6 +164,21 @@ export declare class GrantRepository {
|
|
|
163
164
|
/** The INSERT of one grant with a caller-generated id, for a batch that also writes its principal and record. */
|
|
164
165
|
grantStatement(id: string, input: CreateGrantInput, onConflict?: string): SqlStatement;
|
|
165
166
|
private grantChange;
|
|
167
|
+
/**
|
|
168
|
+
* Write the change an approved grant request asks for (ADR-0083), in one transaction with the approval's claim: the
|
|
169
|
+
* request moves `pending` → `approved` under `decision.id`, and the change carries a guard on that claim, so of two
|
|
170
|
+
* approvals one claims and writes, the other writes nothing. `current` is the grant an `update` edits as the approver's
|
|
171
|
+
* checks read it; the edit applies only over it. `claimed` false: decided or lapsed meanwhile. `changed` null with
|
|
172
|
+
* `claimed`: the change wrote nothing (a role grant already held, an ineligible grant, a grant gone or edited since).
|
|
173
|
+
*/
|
|
174
|
+
applyRequest(request: GrantRequestRow, current: GrantRow | null, decision: {
|
|
175
|
+
readonly id: string;
|
|
176
|
+
readonly by: string;
|
|
177
|
+
readonly at: number;
|
|
178
|
+
}, audit: (grantId: string) => AuditEventInput): Promise<{
|
|
179
|
+
claimed: boolean;
|
|
180
|
+
changed: GrantRow | null;
|
|
181
|
+
}>;
|
|
166
182
|
/** Keep the audit's before-value true if another administrator edited this grant after it was read. */
|
|
167
183
|
updateGrant(grant: GrantRow, input: CreateGrantInput, audit: AuditEventInput): Promise<GrantRow | null>;
|
|
168
184
|
/** Delete a grant, after its principal's revision. */
|
package/types/src/tokens.d.ts
CHANGED
|
@@ -99,6 +99,13 @@ export type ResolvedCredential = {
|
|
|
99
99
|
* app, that is a downscope and is enforced the same way.
|
|
100
100
|
*/
|
|
101
101
|
export declare function resolveCredential(services: Services, cred: CredentialRow, app: string): Promise<ResolvedCredential>;
|
|
102
|
+
/**
|
|
103
|
+
* A user's mailbox for its token: `principals.email`, normalized by `PrincipalRepository`, the address the person signs
|
|
104
|
+
* in with. An application mails it as `ctx.principal.email`, so it is never `label`, the spelling the person sees.
|
|
105
|
+
*/
|
|
106
|
+
export declare function mailboxClaim(principal: PrincipalRow): {
|
|
107
|
+
email?: string;
|
|
108
|
+
};
|
|
102
109
|
/**
|
|
103
110
|
* The signed token, or null — with a warning naming the subject and the size — when it is above `who.bytes`
|
|
104
111
|
* (`MAX_ACCESS_TOKEN_BYTES` unless given). Every bearer IAM issues passes here: native tokens and OAuth resource tokens.
|