@camunda/ccma-shared-types 18.15.0 → 19.1.0

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.
@@ -1,11 +1,13 @@
1
1
  /**
2
2
  * The agent tokens of ccmacli: machine credentials that a Camundi creates in
3
- * Camunda Control for an agent, with read access only.
3
+ * Camunda Control for an agent. A token has `read` or `write` access.
4
4
  *
5
5
  * control-backend stores the clients. token-issuer exchanges the credentials
6
6
  * for an Auth0 token of the agent audience. control-backend, console-backend
7
- * and accounts-ng accept that token on their read routes. Every type and
8
- * rule that two of these services share is in this file.
7
+ * and accounts-ng accept that token on their read routes. A `write` token
8
+ * also acts on the other routes, with the live permissions of its creator,
9
+ * except the routes of `AGENT_WRITE_DENY`. Every type and rule that two of
10
+ * these services share is in this file.
9
11
  */
10
12
  /** AGENT_CLAIM is the claim of an agent token that names the client. */
11
13
  export declare const AGENT_CLAIM = "https://camunda.com/agent";
@@ -40,8 +42,48 @@ export declare const AGENT_TOKENS_ACTIVE_MAX = 10;
40
42
  * Slack channel: it has no secret, and a grant gives it a token.
41
43
  */
42
44
  export type AgentTokenKind = 'secret' | 'slack';
43
- /** Phase 1 has read access only. Phase 2 adds `write`. */
44
- export type AgentAccess = 'read';
45
+ /**
46
+ * `read` can call the read allowlists only. `write` acts as its creator, with
47
+ * the creator's live permissions, except on the routes of `AGENT_WRITE_DENY`.
48
+ * The access is set at create and does not change.
49
+ */
50
+ export type AgentAccess = 'read' | 'write';
51
+ /** AGENT_ACCESSES lists every value of `AgentAccess`. */
52
+ export declare const AGENT_ACCESSES: readonly ["read", "write"];
53
+ /**
54
+ * AGENT_WRITE_TOKENS_FEATURE_FLAG closes the create of a `write` token while
55
+ * it is off. A `write` token that exists then acts as a `read` token.
56
+ */
57
+ export declare const AGENT_WRITE_TOKENS_FEATURE_FLAG = "control.agentWriteTokens";
58
+ /** AGENT_WRITE_TOKEN_EXPIRY_DAYS lists the lifetimes of a `write` token. */
59
+ export declare const AGENT_WRITE_TOKEN_EXPIRY_DAYS: readonly [7, 30];
60
+ /**
61
+ * AGENT_WRITE_TOKEN_MAX_AGE_DAYS is the age limit of a `write` token, counted
62
+ * from `createdAt`, also across extends.
63
+ */
64
+ export declare const AGENT_WRITE_TOKEN_MAX_AGE_DAYS = 90;
65
+ /**
66
+ * AGENT_READ_STATUS_CACHE_MS is how long a backend keeps the status of a
67
+ * `read` token.
68
+ */
69
+ export declare const AGENT_READ_STATUS_CACHE_MS = 60000;
70
+ /**
71
+ * AGENT_WRITE_STATUS_CACHE_MS is how long a backend keeps the status of a
72
+ * `write` token, for a GET, HEAD or OPTIONS request.
73
+ */
74
+ export declare const AGENT_WRITE_STATUS_CACHE_MS = 10000;
75
+ /** The agent part of the principal of a `write` token. */
76
+ export interface AgentPrincipalAgent {
77
+ uuid: string;
78
+ access: AgentAccess;
79
+ }
80
+ /**
81
+ * True when a `write` agent token made the principal. Its permissions come
82
+ * from the status of the client, which reads the HiBob role of the creator
83
+ * live. A HiBob augmenter must not add to them: its own cache can still hold
84
+ * a role that the creator lost. It can still set `isManager`.
85
+ */
86
+ export declare function isWriteAgentPrincipal(principal: unknown): boolean;
45
87
  /** The value of `AGENT_CLAIM` in a verified agent token. */
46
88
  export interface AgentClaim {
47
89
  uuid: string;
@@ -90,6 +132,8 @@ export interface CreateAgentTokenDto {
90
132
  expiresInDays: AgentTokenExpiryDays;
91
133
  /** Set it to make a binding to this channel. Then there is no secret. */
92
134
  slackChannelId?: string;
135
+ /** `write` is for `secret` clients only. The default is `read`. */
136
+ access?: AgentAccess;
93
137
  }
94
138
  /** The body of `POST /api/agent-tokens/:uuid/extend`. */
95
139
  export interface ExtendAgentTokenDto {
@@ -133,13 +177,24 @@ export interface AgentVerifyResponse {
133
177
  /**
134
178
  * The answer of `GET /internal/agent-clients/:uuid/status`.
135
179
  *
136
- * `permissions` is `AGENT_READ_PERMISSIONS` of all backends, intersected with
137
- * the permissions of the creator at the create or the last extend. It is empty
138
- * when `active` is false.
180
+ * `access` is the access of the stored client. A backend trusts it and not the
181
+ * claim of the token.
182
+ *
183
+ * For a `read` client, `permissions` is `AGENT_READ_PERMISSIONS` of all
184
+ * backends, intersected with the permissions of the creator at the create or
185
+ * the last extend. For a `write` client, it is the live permissions of the
186
+ * creator. It is empty when `active` is false.
187
+ *
188
+ * `creator` is present for an active `write` client.
139
189
  */
140
190
  export interface AgentStatusResponse {
141
191
  active: boolean;
142
192
  permissions: string[];
193
+ access: AgentAccess;
194
+ creator?: {
195
+ userId: string;
196
+ email: string;
197
+ };
143
198
  }
144
199
  /**
145
200
  * AGENT_READ_PERMISSIONS is the most that an agent token can do in each
@@ -158,10 +213,14 @@ export declare const AGENT_READ_PERMISSIONS: Readonly<{
158
213
  }>;
159
214
  /** agentReadPermissionUnion is the union of the three backend sets. */
160
215
  export declare function agentReadPermissionUnion(): string[];
161
- /** The codes of the two denials that only an agent token can get. */
216
+ /** The codes of the denials that only an agent token can get. */
162
217
  export declare const AGENT_ERROR: {
163
218
  readonly readOnly: "auth.agent_read_only";
164
219
  readonly inactive: "auth.agent_inactive";
220
+ /** The access of the claim differs from the access of the stored client. */
221
+ readonly accessMismatch: "auth.agent_access_mismatch";
222
+ /** A `write` token called a route of `AGENT_WRITE_DENY`. */
223
+ readonly writeDenied: "auth.agent_write_denied";
165
224
  };
166
225
  /**
167
226
  * parseAgentClaim reads `AGENT_CLAIM` from the payload of a VERIFIED token.
@@ -169,3 +228,75 @@ export declare const AGENT_ERROR: {
169
228
  * the caller must then refuse the token.
170
229
  */
171
230
  export declare function parseAgentClaim(payload: Record<string, unknown>): AgentClaim | undefined;
231
+ /** What a backend does with an agent token after the status answer. */
232
+ export type AgentAccessResolution = {
233
+ kind: 'mismatch';
234
+ } | {
235
+ kind: 'inactive';
236
+ } | {
237
+ kind: 'read';
238
+ } | {
239
+ kind: 'write';
240
+ creator: {
241
+ userId: string;
242
+ email: string;
243
+ };
244
+ };
245
+ /**
246
+ * resolveAgentAccess decides how a backend treats an agent token. It trusts
247
+ * the stored client (`status`) and not the claim. A `write` client acts as
248
+ * `read` while `writeTokensOn` is false. A `write` client with no creator is
249
+ * `inactive`, so the gate fails closed.
250
+ */
251
+ export declare function resolveAgentAccess(input: {
252
+ claim: Pick<AgentClaim, 'access'>;
253
+ status: AgentStatusResponse;
254
+ writeTokensOn: boolean;
255
+ }): AgentAccessResolution;
256
+ /**
257
+ * agentStatusCacheMs is how long a backend may keep a status answer. A `write`
258
+ * token that makes a request with a method that changes data (not GET, HEAD
259
+ * or OPTIONS) gets no cache, so a revoke or a change of the creator's
260
+ * permissions applies at once.
261
+ */
262
+ export declare function agentStatusCacheMs(access: AgentAccess, method: string): number;
263
+ /** One route that a `write` token must not call. */
264
+ export interface AgentWriteDenyRule {
265
+ /** An HTTP method in upper case. `*` means any method. */
266
+ method: string;
267
+ /** It matches the whole path, without the query string. */
268
+ path: RegExp;
269
+ why: string;
270
+ }
271
+ /**
272
+ * AGENT_WRITE_DENY lists, for each backend, the routes that a `write` token
273
+ * never calls, whatever its creator may do. No agent token makes or changes
274
+ * agent tokens, and none changes who may do what.
275
+ *
276
+ * control-backend has no direct route for a role, a member or an API client.
277
+ * It reaches them through approval requests, and an approval request only
278
+ * records the change: so the denied routes are the ones that make such a
279
+ * request. The key of a feature flag is in the body of its write routes, so
280
+ * all of them are denied.
281
+ *
282
+ * console-backend and accounts-ng have direct routes for API clients, cluster
283
+ * credentials, members and roles, so their lists name those routes. Express
284
+ * matches a path with no regard to case, so their rules ignore case too.
285
+ * Console API clients are made and deleted in console-backend only. The
286
+ * `/api/consoleApi` routes of accounts-ng take only the tokens of Console API
287
+ * clients, and no agent gate runs there, so no rule names them.
288
+ */
289
+ export declare const AGENT_WRITE_DENY: Readonly<{
290
+ control: readonly AgentWriteDenyRule[];
291
+ console: readonly AgentWriteDenyRule[];
292
+ accounts: readonly AgentWriteDenyRule[];
293
+ }>;
294
+ /**
295
+ * isAgentWriteDenied returns the rule that denies this call of a `write`
296
+ * token, or `undefined` when no rule does. `path` has no query string.
297
+ *
298
+ * Fastify routes on the decoded path, so `api%2Dclients` reaches the
299
+ * `api-clients` route. Thus a rule matches the path as sent or as decoded,
300
+ * and a path that does not decode is denied.
301
+ */
302
+ export declare function isAgentWriteDenied(backend: keyof typeof AGENT_WRITE_DENY, method: string, path: string): AgentWriteDenyRule | undefined;
@@ -10,6 +10,22 @@ const AGENT_GRANTS_PER_HOUR_MAX = 10;
10
10
  const AGENT_TOKEN_EXPIRY_DAYS = [7, 30, 90];
11
11
  const AGENT_TOKEN_NAME_MAX = 64;
12
12
  const AGENT_TOKENS_ACTIVE_MAX = 10;
13
+ const AGENT_ACCESSES = [
14
+ "read",
15
+ "write"
16
+ ];
17
+ const AGENT_WRITE_TOKENS_FEATURE_FLAG = "control.agentWriteTokens";
18
+ const AGENT_WRITE_TOKEN_EXPIRY_DAYS = [7, 30];
19
+ const AGENT_WRITE_TOKEN_MAX_AGE_DAYS = 90;
20
+ const AGENT_READ_STATUS_CACHE_MS = 6e4;
21
+ const AGENT_WRITE_STATUS_CACHE_MS = 1e4;
22
+ function isWriteAgentPrincipal(principal) {
23
+ if (!principal || typeof principal !== "object") {
24
+ return false;
25
+ }
26
+ const { agent } = principal;
27
+ return agent?.access === "write";
28
+ }
13
29
  const AGENT_TOKEN_STATUSES = [
14
30
  "active",
15
31
  "expired",
@@ -37,7 +53,11 @@ function agentReadPermissionUnion() {
37
53
  }
38
54
  const AGENT_ERROR = {
39
55
  readOnly: "auth.agent_read_only",
40
- inactive: "auth.agent_inactive"
56
+ inactive: "auth.agent_inactive",
57
+ /** The access of the claim differs from the access of the stored client. */
58
+ accessMismatch: "auth.agent_access_mismatch",
59
+ /** A `write` token called a route of `AGENT_WRITE_DENY`. */
60
+ writeDenied: "auth.agent_write_denied"
41
61
  };
42
62
  const UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
43
63
  function parseAgentClaim(payload) {
@@ -46,18 +66,237 @@ function parseAgentClaim(payload) {
46
66
  return void 0;
47
67
  }
48
68
  const { uuid, access, createdByUserId } = claim;
49
- if (typeof uuid !== "string" || !UUID_SHAPE.test(uuid) || access !== "read" || typeof createdByUserId !== "string" || createdByUserId.length === 0) {
69
+ if (typeof uuid !== "string" || !UUID_SHAPE.test(uuid) || access !== "read" && access !== "write" || typeof createdByUserId !== "string" || createdByUserId.length === 0) {
50
70
  return void 0;
51
71
  }
52
72
  return { uuid, access, createdByUserId };
53
73
  }
74
+ function resolveAgentAccess(input) {
75
+ const { claim, status, writeTokensOn } = input;
76
+ if (!status.active) {
77
+ return { kind: "inactive" };
78
+ }
79
+ if (claim.access !== status.access) {
80
+ return { kind: "mismatch" };
81
+ }
82
+ if (status.access === "read" || !writeTokensOn) {
83
+ return { kind: "read" };
84
+ }
85
+ if (status.creator === void 0) {
86
+ return { kind: "inactive" };
87
+ }
88
+ return { kind: "write", creator: status.creator };
89
+ }
90
+ const SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
91
+ function agentStatusCacheMs(access, method) {
92
+ if (access === "read") {
93
+ return AGENT_READ_STATUS_CACHE_MS;
94
+ }
95
+ return SAFE_METHODS.has(method.toUpperCase()) ? AGENT_WRITE_STATUS_CACHE_MS : 0;
96
+ }
97
+ const AGENT_TOKEN_UUID = "[^/]+";
98
+ const WRITE_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
99
+ function writes(path, why) {
100
+ return WRITE_METHODS.map((method) => ({ method, path, why }));
101
+ }
102
+ const AGENT_WRITE_DENY = {
103
+ control: [
104
+ {
105
+ method: "POST",
106
+ path: /^\/api\/agent-tokens\/?$/,
107
+ why: "No agent token makes an agent token."
108
+ },
109
+ {
110
+ method: "POST",
111
+ path: new RegExp(`^/api/agent-tokens/${AGENT_TOKEN_UUID}/rotate/?$`),
112
+ why: "No agent token rotates a secret."
113
+ },
114
+ {
115
+ method: "POST",
116
+ path: new RegExp(`^/api/agent-tokens/${AGENT_TOKEN_UUID}/extend/?$`),
117
+ why: "No agent token extends its own life or the life of another token."
118
+ },
119
+ {
120
+ method: "DELETE",
121
+ path: new RegExp(`^/api/agent-tokens/${AGENT_TOKEN_UUID}/?$`),
122
+ why: "No agent token revokes an agent token."
123
+ },
124
+ {
125
+ method: "*",
126
+ path: /^\/internal\/agent-(grants|clients)(\/.*)?$/,
127
+ why: "The internal routes of agent grants and clients are for services."
128
+ },
129
+ {
130
+ method: "POST",
131
+ path: /^\/api\/feature-flags\/?$/,
132
+ why: "The key of a flag is in the body, and a flag can close the agent controls."
133
+ },
134
+ {
135
+ method: "PATCH",
136
+ path: /^\/api\/feature-flags\/[^/]+\/?$/,
137
+ why: "The key of a flag is not in the path, and a flag can close the agent controls."
138
+ },
139
+ {
140
+ method: "DELETE",
141
+ path: /^\/api\/feature-flags\/[^/]+\/?$/,
142
+ why: "The key of a flag is not in the path, and a flag can close the agent controls."
143
+ },
144
+ {
145
+ method: "POST",
146
+ path: /^\/api\/approvals\/(change-feature-flag|disable-feature-flag|engage-kill-switch)\/?$/,
147
+ why: "The key of a flag is in the body, and a flag can close the agent controls."
148
+ },
149
+ {
150
+ method: "POST",
151
+ path: /^\/api\/approvals\/change-platform-roles\/?$/,
152
+ why: "No agent token changes the roles of a person."
153
+ },
154
+ {
155
+ method: "POST",
156
+ path: /^\/api\/approvals\/remove-org-member\/?$/,
157
+ why: "No agent token changes the members of an organization."
158
+ },
159
+ {
160
+ method: "POST",
161
+ path: /^\/api\/approvals\/delete-api-client\/?$/,
162
+ why: "No agent token changes the API clients of an organization."
163
+ },
164
+ {
165
+ method: "POST",
166
+ path: /^\/api\/approvals\/grant-approval-override\/?$/,
167
+ why: "No agent token gives approval rights."
168
+ },
169
+ {
170
+ method: "POST",
171
+ path: /^\/api\/approvals\/[^/]+\/override\/?$/,
172
+ why: "An override runs a request with no second person. An agent is never the second person."
173
+ },
174
+ {
175
+ method: "POST",
176
+ path: /^\/api\/approvals\/(update-user-metadata|change-user-email|create-sso-connection|update-sso-connection|delete-sso-connection|create-early-access-feature)\/?$/,
177
+ why: "No agent token changes the roles, the organizations or the sign-in of a person."
178
+ },
179
+ {
180
+ method: "POST",
181
+ path: /^\/api\/approvals\/automated-enterprise-onboarding\/?$/,
182
+ why: "An enterprise onboarding invites a person as the owner of new organizations."
183
+ }
184
+ ],
185
+ console: [
186
+ ...writes(
187
+ /^\/(api|cli\/v1)\/orgs\/[^/]+\/api-clients(\/[^/]+)?\/?$/i,
188
+ "No agent token makes, changes or deletes an API client of an organization."
189
+ ),
190
+ ...writes(
191
+ /^\/api\/admin\/(apiClients\/[^/]+\/client|approvals\/orgs\/[^/]+\/api-clients)\/[^/]+\/?$/i,
192
+ "No agent token deletes an API client of an organization."
193
+ ),
194
+ ...writes(
195
+ /^\/(api|cli\/v1)\/orgs\/[^/]+\/clusters\/[^/]+\/(monitoring\/)?clients(\/[^/]+(\/(rotate|rotate-secret))?)?\/?$/i,
196
+ "No agent token makes, changes, rotates or deletes the credentials of a cluster."
197
+ ),
198
+ ...writes(
199
+ /^\/external\/organizations\/[^/]+\/clusters\/[^/]+\/internalClient\/?$/i,
200
+ "No agent token makes the internal client of a cluster."
201
+ ),
202
+ ...writes(
203
+ /^\/api\/admin\/clusters\/org\/[^/]+\/litellm-secrets(\/(repoint|rotate))?\/?$/i,
204
+ "No agent token makes, rotates or deletes the LLM secrets of an organization."
205
+ ),
206
+ ...writes(
207
+ /^\/(api|cli\/v1)\/orgs\/[^/]+\/clusters\/[^/]+\/external-idp(\/secret)?\/?$/i,
208
+ "No agent token changes who can sign in to a cluster."
209
+ ),
210
+ ...writes(
211
+ /^\/api\/admin\/(approvals\/)?clusters\/[^/]+\/owner\/?$/i,
212
+ "No agent token gives a cluster to another owner."
213
+ )
214
+ ],
215
+ accounts: [
216
+ ...writes(
217
+ /^\/api\/(admin\/approvals\/)?users\/[^/]+\/(organization\/[^/]+\/)?roles\/?$/i,
218
+ "No agent token changes the roles of a person."
219
+ ),
220
+ ...writes(
221
+ /^\/cli\/v1\/orgs\/[^/]+\/members\/[^/]+(\/roles)?\/?$/i,
222
+ "No agent token changes the members of an organization or their roles."
223
+ ),
224
+ ...writes(
225
+ /^\/api\/users\/[^/]+\/organization\/[^/]+(\/stale)?\/?$/i,
226
+ "No agent token adds a person to an organization or removes one."
227
+ ),
228
+ ...writes(
229
+ /^\/api\/admin\/approvals\/organizations\/[^/]+\/members\/[^/]+\/?$/i,
230
+ "No agent token removes a member of an organization."
231
+ ),
232
+ ...writes(
233
+ /^\/api\/organizations\/[^/]+\/owner\/[^/]+\/?$/i,
234
+ "No agent token gives an organization to another owner."
235
+ ),
236
+ ...writes(
237
+ /^\/(api\/organizations|cli\/v1\/orgs|external\/organizations)\/[^/]+\/invites(\/[^/]+(\/resend)?)?\/?$/i,
238
+ "No agent token invites a person to an organization."
239
+ ),
240
+ ...writes(
241
+ /^\/(external\/onboarding|api\/admin\/approvals\/organizations\/enterprise-onboarding)\/?$/i,
242
+ "An enterprise onboarding invites a person as the owner of new organizations."
243
+ ),
244
+ ...writes(
245
+ /^\/api\/organizations\/[^/]+\/auto-join\/?$/i,
246
+ "No agent token changes who joins an organization by email domain."
247
+ ),
248
+ ...writes(
249
+ /^\/api\/(users\/[^/]+\/(app|user)metadata|admin\/approvals\/users\/[^/]+\/metadata\/[^/]+)\/?$/i,
250
+ "No agent token changes the metadata of a person. The app metadata can hold roles and permissions."
251
+ ),
252
+ ...writes(
253
+ /^\/api\/admin\/approvals\/organizations\/[^/]+\/owner-check\/?$/i,
254
+ "The owner check is a step of an approval. An agent token takes no part in an approval."
255
+ ),
256
+ ...writes(
257
+ /^\/api\/(admin\/approvals\/)?users\/[^/]+\/email\/?$/i,
258
+ "No agent token changes the email, and thus the sign-in, of a person."
259
+ ),
260
+ ...writes(
261
+ /^\/api\/users\/[^/]+\/blocks\/?$/i,
262
+ "No agent token removes the sign-in blocks of a person."
263
+ ),
264
+ ...writes(
265
+ /^\/api\/(admin\/approvals\/)?connections\/[^/]+(\/[^/]+)?\/?$/i,
266
+ "No agent token changes the SSO connections, and thus who can sign in."
267
+ ),
268
+ ...writes(
269
+ /^\/api\/(earlyaccessfeatures(\/.*)?|admin\/approvals\/early-access-features)\/?$/i,
270
+ "Early access features are feature flags, and an agent token writes no flag."
271
+ )
272
+ ]
273
+ };
274
+ const UNDECODABLE_PATH_RULE = {
275
+ method: "*",
276
+ path: /%/,
277
+ why: "The path has a percent sign that does not decode."
278
+ };
279
+ function isAgentWriteDenied(backend, method, path) {
280
+ const upper = method.toUpperCase();
281
+ let decoded;
282
+ try {
283
+ decoded = decodeURIComponent(path);
284
+ } catch {
285
+ return UNDECODABLE_PATH_RULE;
286
+ }
287
+ return AGENT_WRITE_DENY[backend].find(
288
+ (rule) => (rule.method === "*" || rule.method === upper) && (rule.path.test(path) || rule.path.test(decoded))
289
+ );
290
+ }
54
291
  export {
292
+ AGENT_ACCESSES,
55
293
  AGENT_CLAIM,
56
294
  AGENT_CLIENT_ID_PREFIX,
57
295
  AGENT_ERROR,
58
296
  AGENT_GRANTS_PER_HOUR_MAX,
59
297
  AGENT_GRANT_TTL_MS,
60
298
  AGENT_READ_PERMISSIONS,
299
+ AGENT_READ_STATUS_CACHE_MS,
61
300
  AGENT_SLACK_CHANNEL_PATTERN,
62
301
  AGENT_SLACK_GRANTS_FEATURE_FLAG,
63
302
  AGENT_TOKENS_ACTIVE_MAX,
@@ -65,7 +304,16 @@ export {
65
304
  AGENT_TOKEN_EXPIRY_DAYS,
66
305
  AGENT_TOKEN_NAME_MAX,
67
306
  AGENT_TOKEN_STATUSES,
307
+ AGENT_WRITE_DENY,
308
+ AGENT_WRITE_STATUS_CACHE_MS,
309
+ AGENT_WRITE_TOKENS_FEATURE_FLAG,
310
+ AGENT_WRITE_TOKEN_EXPIRY_DAYS,
311
+ AGENT_WRITE_TOKEN_MAX_AGE_DAYS,
68
312
  agentReadPermissionUnion,
69
- parseAgentClaim
313
+ agentStatusCacheMs,
314
+ isAgentWriteDenied,
315
+ isWriteAgentPrincipal,
316
+ parseAgentClaim,
317
+ resolveAgentAccess
70
318
  };
71
319
  //# sourceMappingURL=agent-tokens.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/agent-tokens/agent-tokens.ts"],
4
- "sourcesContent": ["/*\n * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH\n * under one or more contributor license agreements. Licensed under a commercial license.\n * You may not use this file except in compliance with the commercial license.\n */\n\nimport { AccountsPermissions } from '../permissions/accounts.permissions.js'\nimport { ConsolePermissions } from '../permissions/console.permissions.js'\n\n/**\n * The agent tokens of ccmacli: machine credentials that a Camundi creates in\n * Camunda Control for an agent, with read access only.\n *\n * control-backend stores the clients. token-issuer exchanges the credentials\n * for an Auth0 token of the agent audience. control-backend, console-backend\n * and accounts-ng accept that token on their read routes. Every type and\n * rule that two of these services share is in this file.\n */\n\n/** AGENT_CLAIM is the claim of an agent token that names the client. */\nexport const AGENT_CLAIM = 'https://camunda.com/agent'\n\n/** AGENT_CLIENT_ID_PREFIX starts every client id of an agent client. */\nexport const AGENT_CLIENT_ID_PREFIX = 'ccma_'\n\n/** AGENT_TOKENS_FEATURE_FLAG closes create and rotate while it is off. */\nexport const AGENT_TOKENS_FEATURE_FLAG = 'control.agentTokens'\n\n/**\n * AGENT_SLACK_GRANTS_FEATURE_FLAG closes the create and the extend of a\n * binding, and the create of a grant, while it is off. The redeem stays open:\n * a code made before the flag went off works until it expires (`AGENT_GRANT_TTL_MS`).\n */\nexport const AGENT_SLACK_GRANTS_FEATURE_FLAG = 'control.agentSlackGrants'\n\n/**\n * The form of a Slack channel ID: public (`C`) or private (`G`) channel.\n * A binding stores the ID, never the name.\n */\nexport const AGENT_SLACK_CHANNEL_PATTERN = /^[CG][A-Z0-9]{8,}$/\n\n/** AGENT_GRANT_TTL_MS is the time in which a grant code can be redeemed. */\nexport const AGENT_GRANT_TTL_MS = 120_000\n\n/** AGENT_GRANTS_PER_HOUR_MAX is the limit of new grants for one binding. */\nexport const AGENT_GRANTS_PER_HOUR_MAX = 10\n\n/** AGENT_TOKEN_EXPIRY_DAYS lists the lifetimes that a creator can choose. */\nexport const AGENT_TOKEN_EXPIRY_DAYS = [7, 30, 90] as const\n\nexport type AgentTokenExpiryDays = (typeof AGENT_TOKEN_EXPIRY_DAYS)[number]\n\n/** AGENT_TOKEN_NAME_MAX is the length limit of a name, after the trim. */\nexport const AGENT_TOKEN_NAME_MAX = 64\n\n/** AGENT_TOKENS_ACTIVE_MAX is the limit of active clients for one creator. */\nexport const AGENT_TOKENS_ACTIVE_MAX = 10\n\n/**\n * `secret` is a client with an id and a secret. `slack` is a binding to one\n * Slack channel: it has no secret, and a grant gives it a token.\n */\nexport type AgentTokenKind = 'secret' | 'slack'\n\n/** Phase 1 has read access only. Phase 2 adds `write`. */\nexport type AgentAccess = 'read'\n\n/** The value of `AGENT_CLAIM` in a verified agent token. */\nexport interface AgentClaim {\n uuid: string\n access: AgentAccess\n /** The `sub` of the Camundi who created the client. */\n createdByUserId: string\n}\n\n/** `inactive` means that the creator is no longer a Camundi. */\nexport type AgentTokenStatus = 'active' | 'expired' | 'revoked' | 'inactive'\n\n/** AGENT_TOKEN_STATUSES lists every value of `AgentTokenStatus`. */\nexport const AGENT_TOKEN_STATUSES = [\n 'active',\n 'expired',\n 'revoked',\n 'inactive',\n] as const satisfies readonly AgentTokenStatus[]\n\n/** One agent client, as its creator sees it. It never holds the secret. */\nexport interface AgentToken {\n uuid: string\n clientId: string\n name: string\n access: AgentAccess\n kind: AgentTokenKind\n /** The channel ID of a binding. It is absent when `kind` is `secret`. */\n slackChannelId?: string\n status: AgentTokenStatus\n createdAt: string\n expiresAt: string\n lastUsedAt?: string\n revokedAt?: string\n}\n\n/**\n * AgentTokenCreated is the answer of create and rotate. It is the only answer\n * that holds `clientSecret`, and the backend cannot show the secret again.\n */\nexport interface AgentTokenCreated extends AgentToken {\n /** Absent for a binding, which has no secret. */\n clientSecret?: string\n}\n\n/** One agent client, as the admin list shows it. */\nexport interface AgentTokenAdmin extends AgentToken {\n createdBy: { userId: string; email: string }\n revokedByUserId?: string\n}\n\n/** The body of `POST /api/agent-tokens`. */\nexport interface CreateAgentTokenDto {\n name: string\n expiresInDays: AgentTokenExpiryDays\n /** Set it to make a binding to this channel. Then there is no secret. */\n slackChannelId?: string\n}\n\n/** The body of `POST /api/agent-tokens/:uuid/extend`. */\nexport interface ExtendAgentTokenDto {\n expiresInDays: AgentTokenExpiryDays\n}\n\n/** The body of `POST /internal/agent-grants`. CloudBot sends it. */\nexport interface CreateAgentGrantDto {\n slackChannelId: string\n slackThreadTs: string\n requestedBySlackUserId: string\n requestedByEmail: string\n /** The S256 challenge of the PKCE verifier that only ccmacli knows. */\n codeChallenge: string\n}\n\n/** The answer of `POST /internal/agent-grants`. */\nexport interface AgentGrantCreated {\n code: string\n expiresAt: string\n}\n\n/** Why control-backend refuses a grant. CloudBot words the reply from it. */\nexport type AgentGrantRefusalReason =\n | 'no_binding'\n | 'expired'\n | 'revoked'\n | 'inactive'\n | 'requester_unknown'\n | 'rate_limited'\n | 'thread_busy'\n | 'feature_off'\n\n/** The body of the 409 answer of `POST /internal/agent-grants`. */\nexport interface AgentGrantRefusal {\n code: string\n message: string\n reason: AgentGrantRefusalReason\n expiredAt?: string\n ownerEmail?: string\n}\n\n/** The body of `POST /internal/agent-grants/redeem`. token-issuer sends it. */\nexport interface RedeemAgentGrantDto {\n code: string\n codeVerifier: string\n}\n\n/** The answer of `POST /internal/agent-clients/verify`. */\nexport interface AgentVerifyResponse {\n uuid: string\n access: AgentAccess\n createdByUserId: string\n}\n\n/**\n * The answer of `GET /internal/agent-clients/:uuid/status`.\n *\n * `permissions` is `AGENT_READ_PERMISSIONS` of all backends, intersected with\n * the permissions of the creator at the create or the last extend. It is empty\n * when `active` is false.\n */\nexport interface AgentStatusResponse {\n active: boolean\n permissions: string[]\n}\n\n/**\n * AGENT_READ_PERMISSIONS is the most that an agent token can do in each\n * backend. A backend intersects its set with the `permissions` of the status\n * answer, so an agent never holds a permission that its creator did not hold.\n *\n * `crtp` is a publish permission. It is here for one read only, the\n * release-train sanity check. The agent allowlist of console-backend, which a\n * later change of epic #10804 adds, must be the bound. Never add a route to\n * that allowlist that `crtp` guards for a write.\n */\nexport const AGENT_READ_PERMISSIONS: Readonly<{\n control: readonly string[]\n console: readonly string[]\n accounts: readonly string[]\n}> = {\n control: [AccountsPermissions.READ_ALL],\n console: [\n ConsolePermissions.CHANNELS_AND_GENERATIONS_ADMIN_SEE,\n ConsolePermissions.CLUSTERS_READALLCLUSTERINFO,\n ConsolePermissions.CLUSTER_PLAN_SEE_ALL,\n ConsolePermissions.RELEASE_TRAIN_PUBLISH,\n ],\n accounts: [AccountsPermissions.READ_ALL],\n}\n\n/** agentReadPermissionUnion is the union of the three backend sets. */\nexport function agentReadPermissionUnion(): string[] {\n return [\n ...new Set([\n ...AGENT_READ_PERMISSIONS.control,\n ...AGENT_READ_PERMISSIONS.console,\n ...AGENT_READ_PERMISSIONS.accounts,\n ]),\n ]\n}\n\n/** The codes of the two denials that only an agent token can get. */\nexport const AGENT_ERROR = {\n readOnly: 'auth.agent_read_only',\n inactive: 'auth.agent_inactive',\n} as const\n\nconst UUID_SHAPE =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\n/**\n * parseAgentClaim reads `AGENT_CLAIM` from the payload of a VERIFIED token.\n * It returns `undefined` when the claim is absent or has a wrong shape, and\n * the caller must then refuse the token.\n */\nexport function parseAgentClaim(\n payload: Record<string, unknown>,\n): AgentClaim | undefined {\n const claim = payload[AGENT_CLAIM]\n if (typeof claim !== 'object' || claim === null || Array.isArray(claim)) {\n return undefined\n }\n const { uuid, access, createdByUserId } = claim as Record<string, unknown>\n if (\n typeof uuid !== 'string' ||\n !UUID_SHAPE.test(uuid) ||\n access !== 'read' ||\n typeof createdByUserId !== 'string' ||\n createdByUserId.length === 0\n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,gBAAgB;AACzC;",
4
+ "sourcesContent": ["/*\n * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH\n * under one or more contributor license agreements. Licensed under a commercial license.\n * You may not use this file except in compliance with the commercial license.\n */\n\nimport { AccountsPermissions } from '../permissions/accounts.permissions.js'\nimport { ConsolePermissions } from '../permissions/console.permissions.js'\n\n/**\n * The agent tokens of ccmacli: machine credentials that a Camundi creates in\n * Camunda Control for an agent. A token has `read` or `write` access.\n *\n * control-backend stores the clients. token-issuer exchanges the credentials\n * for an Auth0 token of the agent audience. control-backend, console-backend\n * and accounts-ng accept that token on their read routes. A `write` token\n * also acts on the other routes, with the live permissions of its creator,\n * except the routes of `AGENT_WRITE_DENY`. Every type and rule that two of\n * these services share is in this file.\n */\n\n/** AGENT_CLAIM is the claim of an agent token that names the client. */\nexport const AGENT_CLAIM = 'https://camunda.com/agent'\n\n/** AGENT_CLIENT_ID_PREFIX starts every client id of an agent client. */\nexport const AGENT_CLIENT_ID_PREFIX = 'ccma_'\n\n/** AGENT_TOKENS_FEATURE_FLAG closes create and rotate while it is off. */\nexport const AGENT_TOKENS_FEATURE_FLAG = 'control.agentTokens'\n\n/**\n * AGENT_SLACK_GRANTS_FEATURE_FLAG closes the create and the extend of a\n * binding, and the create of a grant, while it is off. The redeem stays open:\n * a code made before the flag went off works until it expires (`AGENT_GRANT_TTL_MS`).\n */\nexport const AGENT_SLACK_GRANTS_FEATURE_FLAG = 'control.agentSlackGrants'\n\n/**\n * The form of a Slack channel ID: public (`C`) or private (`G`) channel.\n * A binding stores the ID, never the name.\n */\nexport const AGENT_SLACK_CHANNEL_PATTERN = /^[CG][A-Z0-9]{8,}$/\n\n/** AGENT_GRANT_TTL_MS is the time in which a grant code can be redeemed. */\nexport const AGENT_GRANT_TTL_MS = 120_000\n\n/** AGENT_GRANTS_PER_HOUR_MAX is the limit of new grants for one binding. */\nexport const AGENT_GRANTS_PER_HOUR_MAX = 10\n\n/** AGENT_TOKEN_EXPIRY_DAYS lists the lifetimes that a creator can choose. */\nexport const AGENT_TOKEN_EXPIRY_DAYS = [7, 30, 90] as const\n\nexport type AgentTokenExpiryDays = (typeof AGENT_TOKEN_EXPIRY_DAYS)[number]\n\n/** AGENT_TOKEN_NAME_MAX is the length limit of a name, after the trim. */\nexport const AGENT_TOKEN_NAME_MAX = 64\n\n/** AGENT_TOKENS_ACTIVE_MAX is the limit of active clients for one creator. */\nexport const AGENT_TOKENS_ACTIVE_MAX = 10\n\n/**\n * `secret` is a client with an id and a secret. `slack` is a binding to one\n * Slack channel: it has no secret, and a grant gives it a token.\n */\nexport type AgentTokenKind = 'secret' | 'slack'\n\n/**\n * `read` can call the read allowlists only. `write` acts as its creator, with\n * the creator's live permissions, except on the routes of `AGENT_WRITE_DENY`.\n * The access is set at create and does not change.\n */\nexport type AgentAccess = 'read' | 'write'\n\n/** AGENT_ACCESSES lists every value of `AgentAccess`. */\nexport const AGENT_ACCESSES = [\n 'read',\n 'write',\n] as const satisfies readonly AgentAccess[]\n\n/**\n * AGENT_WRITE_TOKENS_FEATURE_FLAG closes the create of a `write` token while\n * it is off. A `write` token that exists then acts as a `read` token.\n */\nexport const AGENT_WRITE_TOKENS_FEATURE_FLAG = 'control.agentWriteTokens'\n\n/** AGENT_WRITE_TOKEN_EXPIRY_DAYS lists the lifetimes of a `write` token. */\nexport const AGENT_WRITE_TOKEN_EXPIRY_DAYS = [7, 30] as const\n\n/**\n * AGENT_WRITE_TOKEN_MAX_AGE_DAYS is the age limit of a `write` token, counted\n * from `createdAt`, also across extends.\n */\nexport const AGENT_WRITE_TOKEN_MAX_AGE_DAYS = 90\n\n/**\n * AGENT_READ_STATUS_CACHE_MS is how long a backend keeps the status of a\n * `read` token.\n */\nexport const AGENT_READ_STATUS_CACHE_MS = 60_000\n\n/**\n * AGENT_WRITE_STATUS_CACHE_MS is how long a backend keeps the status of a\n * `write` token, for a GET, HEAD or OPTIONS request.\n */\nexport const AGENT_WRITE_STATUS_CACHE_MS = 10_000\n\n/** The agent part of the principal of a `write` token. */\nexport interface AgentPrincipalAgent {\n uuid: string\n access: AgentAccess\n}\n\n/**\n * True when a `write` agent token made the principal. Its permissions come\n * from the status of the client, which reads the HiBob role of the creator\n * live. A HiBob augmenter must not add to them: its own cache can still hold\n * a role that the creator lost. It can still set `isManager`.\n */\nexport function isWriteAgentPrincipal(principal: unknown): boolean {\n if (!principal || typeof principal !== 'object') {\n return false\n }\n const { agent } = principal as { agent?: { access?: unknown } }\n return agent?.access === 'write'\n}\n\n/** The value of `AGENT_CLAIM` in a verified agent token. */\nexport interface AgentClaim {\n uuid: string\n access: AgentAccess\n /** The `sub` of the Camundi who created the client. */\n createdByUserId: string\n}\n\n/** `inactive` means that the creator is no longer a Camundi. */\nexport type AgentTokenStatus = 'active' | 'expired' | 'revoked' | 'inactive'\n\n/** AGENT_TOKEN_STATUSES lists every value of `AgentTokenStatus`. */\nexport const AGENT_TOKEN_STATUSES = [\n 'active',\n 'expired',\n 'revoked',\n 'inactive',\n] as const satisfies readonly AgentTokenStatus[]\n\n/** One agent client, as its creator sees it. It never holds the secret. */\nexport interface AgentToken {\n uuid: string\n clientId: string\n name: string\n access: AgentAccess\n kind: AgentTokenKind\n /** The channel ID of a binding. It is absent when `kind` is `secret`. */\n slackChannelId?: string\n status: AgentTokenStatus\n createdAt: string\n expiresAt: string\n lastUsedAt?: string\n revokedAt?: string\n}\n\n/**\n * AgentTokenCreated is the answer of create and rotate. It is the only answer\n * that holds `clientSecret`, and the backend cannot show the secret again.\n */\nexport interface AgentTokenCreated extends AgentToken {\n /** Absent for a binding, which has no secret. */\n clientSecret?: string\n}\n\n/** One agent client, as the admin list shows it. */\nexport interface AgentTokenAdmin extends AgentToken {\n createdBy: { userId: string; email: string }\n revokedByUserId?: string\n}\n\n/** The body of `POST /api/agent-tokens`. */\nexport interface CreateAgentTokenDto {\n name: string\n expiresInDays: AgentTokenExpiryDays\n /** Set it to make a binding to this channel. Then there is no secret. */\n slackChannelId?: string\n /** `write` is for `secret` clients only. The default is `read`. */\n access?: AgentAccess\n}\n\n/** The body of `POST /api/agent-tokens/:uuid/extend`. */\nexport interface ExtendAgentTokenDto {\n expiresInDays: AgentTokenExpiryDays\n}\n\n/** The body of `POST /internal/agent-grants`. CloudBot sends it. */\nexport interface CreateAgentGrantDto {\n slackChannelId: string\n slackThreadTs: string\n requestedBySlackUserId: string\n requestedByEmail: string\n /** The S256 challenge of the PKCE verifier that only ccmacli knows. */\n codeChallenge: string\n}\n\n/** The answer of `POST /internal/agent-grants`. */\nexport interface AgentGrantCreated {\n code: string\n expiresAt: string\n}\n\n/** Why control-backend refuses a grant. CloudBot words the reply from it. */\nexport type AgentGrantRefusalReason =\n | 'no_binding'\n | 'expired'\n | 'revoked'\n | 'inactive'\n | 'requester_unknown'\n | 'rate_limited'\n | 'thread_busy'\n | 'feature_off'\n\n/** The body of the 409 answer of `POST /internal/agent-grants`. */\nexport interface AgentGrantRefusal {\n code: string\n message: string\n reason: AgentGrantRefusalReason\n expiredAt?: string\n ownerEmail?: string\n}\n\n/** The body of `POST /internal/agent-grants/redeem`. token-issuer sends it. */\nexport interface RedeemAgentGrantDto {\n code: string\n codeVerifier: string\n}\n\n/** The answer of `POST /internal/agent-clients/verify`. */\nexport interface AgentVerifyResponse {\n uuid: string\n access: AgentAccess\n createdByUserId: string\n}\n\n/**\n * The answer of `GET /internal/agent-clients/:uuid/status`.\n *\n * `access` is the access of the stored client. A backend trusts it and not the\n * claim of the token.\n *\n * For a `read` client, `permissions` is `AGENT_READ_PERMISSIONS` of all\n * backends, intersected with the permissions of the creator at the create or\n * the last extend. For a `write` client, it is the live permissions of the\n * creator. It is empty when `active` is false.\n *\n * `creator` is present for an active `write` client.\n */\nexport interface AgentStatusResponse {\n active: boolean\n permissions: string[]\n access: AgentAccess\n creator?: { userId: string; email: string }\n}\n\n/**\n * AGENT_READ_PERMISSIONS is the most that an agent token can do in each\n * backend. A backend intersects its set with the `permissions` of the status\n * answer, so an agent never holds a permission that its creator did not hold.\n *\n * `crtp` is a publish permission. It is here for one read only, the\n * release-train sanity check. The agent allowlist of console-backend, which a\n * later change of epic #10804 adds, must be the bound. Never add a route to\n * that allowlist that `crtp` guards for a write.\n */\nexport const AGENT_READ_PERMISSIONS: Readonly<{\n control: readonly string[]\n console: readonly string[]\n accounts: readonly string[]\n}> = {\n control: [AccountsPermissions.READ_ALL],\n console: [\n ConsolePermissions.CHANNELS_AND_GENERATIONS_ADMIN_SEE,\n ConsolePermissions.CLUSTERS_READALLCLUSTERINFO,\n ConsolePermissions.CLUSTER_PLAN_SEE_ALL,\n ConsolePermissions.RELEASE_TRAIN_PUBLISH,\n ],\n accounts: [AccountsPermissions.READ_ALL],\n}\n\n/** agentReadPermissionUnion is the union of the three backend sets. */\nexport function agentReadPermissionUnion(): string[] {\n return [\n ...new Set([\n ...AGENT_READ_PERMISSIONS.control,\n ...AGENT_READ_PERMISSIONS.console,\n ...AGENT_READ_PERMISSIONS.accounts,\n ]),\n ]\n}\n\n/** The codes of the denials that only an agent token can get. */\nexport const AGENT_ERROR = {\n readOnly: 'auth.agent_read_only',\n inactive: 'auth.agent_inactive',\n /** The access of the claim differs from the access of the stored client. */\n accessMismatch: 'auth.agent_access_mismatch',\n /** A `write` token called a route of `AGENT_WRITE_DENY`. */\n writeDenied: 'auth.agent_write_denied',\n} as const\n\nconst UUID_SHAPE =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\n/**\n * parseAgentClaim reads `AGENT_CLAIM` from the payload of a VERIFIED token.\n * It returns `undefined` when the claim is absent or has a wrong shape, and\n * the caller must then refuse the token.\n */\nexport function parseAgentClaim(\n payload: Record<string, unknown>,\n): AgentClaim | undefined {\n const claim = payload[AGENT_CLAIM]\n if (typeof claim !== 'object' || claim === null || Array.isArray(claim)) {\n return undefined\n }\n const { uuid, access, createdByUserId } = claim as Record<string, unknown>\n if (\n typeof uuid !== 'string' ||\n !UUID_SHAPE.test(uuid) ||\n (access !== 'read' && access !== 'write') ||\n typeof createdByUserId !== 'string' ||\n createdByUserId.length === 0\n ) {\n return undefined\n }\n return { uuid, access, createdByUserId }\n}\n\n/** What a backend does with an agent token after the status answer. */\nexport type AgentAccessResolution =\n | { kind: 'mismatch' }\n | { kind: 'inactive' }\n | { kind: 'read' }\n | { kind: 'write'; creator: { userId: string; email: string } }\n\n/**\n * resolveAgentAccess decides how a backend treats an agent token. It trusts\n * the stored client (`status`) and not the claim. A `write` client acts as\n * `read` while `writeTokensOn` is false. A `write` client with no creator is\n * `inactive`, so the gate fails closed.\n */\nexport function resolveAgentAccess(input: {\n claim: Pick<AgentClaim, 'access'>\n status: AgentStatusResponse\n writeTokensOn: boolean\n}): AgentAccessResolution {\n const { claim, status, writeTokensOn } = input\n if (!status.active) {\n return { kind: 'inactive' }\n }\n if (claim.access !== status.access) {\n return { kind: 'mismatch' }\n }\n if (status.access === 'read' || !writeTokensOn) {\n return { kind: 'read' }\n }\n if (status.creator === undefined) {\n return { kind: 'inactive' }\n }\n return { kind: 'write', creator: status.creator }\n}\n\nconst SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS'])\n\n/**\n * agentStatusCacheMs is how long a backend may keep a status answer. A `write`\n * token that makes a request with a method that changes data (not GET, HEAD\n * or OPTIONS) gets no cache, so a revoke or a change of the creator's\n * permissions applies at once.\n */\nexport function agentStatusCacheMs(\n access: AgentAccess,\n method: string,\n): number {\n if (access === 'read') {\n return AGENT_READ_STATUS_CACHE_MS\n }\n return SAFE_METHODS.has(method.toUpperCase())\n ? AGENT_WRITE_STATUS_CACHE_MS\n : 0\n}\n\n/** One route that a `write` token must not call. */\nexport interface AgentWriteDenyRule {\n /** An HTTP method in upper case. `*` means any method. */\n method: string\n /** It matches the whole path, without the query string. */\n path: RegExp\n why: string\n}\n\nconst AGENT_TOKEN_UUID = '[^/]+'\n\nconst WRITE_METHODS = ['POST', 'PUT', 'PATCH', 'DELETE'] as const\n\n/**\n * writes gives one rule for each write method. A GET of the same path stays\n * open, because the creator can read it.\n */\nfunction writes(path: RegExp, why: string): AgentWriteDenyRule[] {\n return WRITE_METHODS.map((method) => ({ method, path, why }))\n}\n\n/**\n * AGENT_WRITE_DENY lists, for each backend, the routes that a `write` token\n * never calls, whatever its creator may do. No agent token makes or changes\n * agent tokens, and none changes who may do what.\n *\n * control-backend has no direct route for a role, a member or an API client.\n * It reaches them through approval requests, and an approval request only\n * records the change: so the denied routes are the ones that make such a\n * request. The key of a feature flag is in the body of its write routes, so\n * all of them are denied.\n *\n * console-backend and accounts-ng have direct routes for API clients, cluster\n * credentials, members and roles, so their lists name those routes. Express\n * matches a path with no regard to case, so their rules ignore case too.\n * Console API clients are made and deleted in console-backend only. The\n * `/api/consoleApi` routes of accounts-ng take only the tokens of Console API\n * clients, and no agent gate runs there, so no rule names them.\n */\nexport const AGENT_WRITE_DENY: Readonly<{\n control: readonly AgentWriteDenyRule[]\n console: readonly AgentWriteDenyRule[]\n accounts: readonly AgentWriteDenyRule[]\n}> = {\n control: [\n {\n method: 'POST',\n path: /^\\/api\\/agent-tokens\\/?$/,\n why: 'No agent token makes an agent token.',\n },\n {\n method: 'POST',\n path: new RegExp(`^/api/agent-tokens/${AGENT_TOKEN_UUID}/rotate/?$`),\n why: 'No agent token rotates a secret.',\n },\n {\n method: 'POST',\n path: new RegExp(`^/api/agent-tokens/${AGENT_TOKEN_UUID}/extend/?$`),\n why: 'No agent token extends its own life or the life of another token.',\n },\n {\n method: 'DELETE',\n path: new RegExp(`^/api/agent-tokens/${AGENT_TOKEN_UUID}/?$`),\n why: 'No agent token revokes an agent token.',\n },\n {\n method: '*',\n path: /^\\/internal\\/agent-(grants|clients)(\\/.*)?$/,\n why: 'The internal routes of agent grants and clients are for services.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/feature-flags\\/?$/,\n why: 'The key of a flag is in the body, and a flag can close the agent controls.',\n },\n {\n method: 'PATCH',\n path: /^\\/api\\/feature-flags\\/[^/]+\\/?$/,\n why: 'The key of a flag is not in the path, and a flag can close the agent controls.',\n },\n {\n method: 'DELETE',\n path: /^\\/api\\/feature-flags\\/[^/]+\\/?$/,\n why: 'The key of a flag is not in the path, and a flag can close the agent controls.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/approvals\\/(change-feature-flag|disable-feature-flag|engage-kill-switch)\\/?$/,\n why: 'The key of a flag is in the body, and a flag can close the agent controls.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/approvals\\/change-platform-roles\\/?$/,\n why: 'No agent token changes the roles of a person.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/approvals\\/remove-org-member\\/?$/,\n why: 'No agent token changes the members of an organization.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/approvals\\/delete-api-client\\/?$/,\n why: 'No agent token changes the API clients of an organization.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/approvals\\/grant-approval-override\\/?$/,\n why: 'No agent token gives approval rights.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/approvals\\/[^/]+\\/override\\/?$/,\n why: 'An override runs a request with no second person. An agent is never the second person.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/approvals\\/(update-user-metadata|change-user-email|create-sso-connection|update-sso-connection|delete-sso-connection|create-early-access-feature)\\/?$/,\n why: 'No agent token changes the roles, the organizations or the sign-in of a person.',\n },\n {\n method: 'POST',\n path: /^\\/api\\/approvals\\/automated-enterprise-onboarding\\/?$/,\n why: 'An enterprise onboarding invites a person as the owner of new organizations.',\n },\n ],\n console: [\n ...writes(\n /^\\/(api|cli\\/v1)\\/orgs\\/[^/]+\\/api-clients(\\/[^/]+)?\\/?$/i,\n 'No agent token makes, changes or deletes an API client of an organization.',\n ),\n ...writes(\n /^\\/api\\/admin\\/(apiClients\\/[^/]+\\/client|approvals\\/orgs\\/[^/]+\\/api-clients)\\/[^/]+\\/?$/i,\n 'No agent token deletes an API client of an organization.',\n ),\n ...writes(\n /^\\/(api|cli\\/v1)\\/orgs\\/[^/]+\\/clusters\\/[^/]+\\/(monitoring\\/)?clients(\\/[^/]+(\\/(rotate|rotate-secret))?)?\\/?$/i,\n 'No agent token makes, changes, rotates or deletes the credentials of a cluster.',\n ),\n ...writes(\n /^\\/external\\/organizations\\/[^/]+\\/clusters\\/[^/]+\\/internalClient\\/?$/i,\n 'No agent token makes the internal client of a cluster.',\n ),\n ...writes(\n /^\\/api\\/admin\\/clusters\\/org\\/[^/]+\\/litellm-secrets(\\/(repoint|rotate))?\\/?$/i,\n 'No agent token makes, rotates or deletes the LLM secrets of an organization.',\n ),\n ...writes(\n /^\\/(api|cli\\/v1)\\/orgs\\/[^/]+\\/clusters\\/[^/]+\\/external-idp(\\/secret)?\\/?$/i,\n 'No agent token changes who can sign in to a cluster.',\n ),\n ...writes(\n /^\\/api\\/admin\\/(approvals\\/)?clusters\\/[^/]+\\/owner\\/?$/i,\n 'No agent token gives a cluster to another owner.',\n ),\n ],\n accounts: [\n ...writes(\n /^\\/api\\/(admin\\/approvals\\/)?users\\/[^/]+\\/(organization\\/[^/]+\\/)?roles\\/?$/i,\n 'No agent token changes the roles of a person.',\n ),\n ...writes(\n /^\\/cli\\/v1\\/orgs\\/[^/]+\\/members\\/[^/]+(\\/roles)?\\/?$/i,\n 'No agent token changes the members of an organization or their roles.',\n ),\n ...writes(\n /^\\/api\\/users\\/[^/]+\\/organization\\/[^/]+(\\/stale)?\\/?$/i,\n 'No agent token adds a person to an organization or removes one.',\n ),\n ...writes(\n /^\\/api\\/admin\\/approvals\\/organizations\\/[^/]+\\/members\\/[^/]+\\/?$/i,\n 'No agent token removes a member of an organization.',\n ),\n ...writes(\n /^\\/api\\/organizations\\/[^/]+\\/owner\\/[^/]+\\/?$/i,\n 'No agent token gives an organization to another owner.',\n ),\n ...writes(\n /^\\/(api\\/organizations|cli\\/v1\\/orgs|external\\/organizations)\\/[^/]+\\/invites(\\/[^/]+(\\/resend)?)?\\/?$/i,\n 'No agent token invites a person to an organization.',\n ),\n ...writes(\n /^\\/(external\\/onboarding|api\\/admin\\/approvals\\/organizations\\/enterprise-onboarding)\\/?$/i,\n 'An enterprise onboarding invites a person as the owner of new organizations.',\n ),\n ...writes(\n /^\\/api\\/organizations\\/[^/]+\\/auto-join\\/?$/i,\n 'No agent token changes who joins an organization by email domain.',\n ),\n ...writes(\n /^\\/api\\/(users\\/[^/]+\\/(app|user)metadata|admin\\/approvals\\/users\\/[^/]+\\/metadata\\/[^/]+)\\/?$/i,\n 'No agent token changes the metadata of a person. The app metadata can hold roles and permissions.',\n ),\n ...writes(\n /^\\/api\\/admin\\/approvals\\/organizations\\/[^/]+\\/owner-check\\/?$/i,\n 'The owner check is a step of an approval. An agent token takes no part in an approval.',\n ),\n ...writes(\n /^\\/api\\/(admin\\/approvals\\/)?users\\/[^/]+\\/email\\/?$/i,\n 'No agent token changes the email, and thus the sign-in, of a person.',\n ),\n ...writes(\n /^\\/api\\/users\\/[^/]+\\/blocks\\/?$/i,\n 'No agent token removes the sign-in blocks of a person.',\n ),\n ...writes(\n /^\\/api\\/(admin\\/approvals\\/)?connections\\/[^/]+(\\/[^/]+)?\\/?$/i,\n 'No agent token changes the SSO connections, and thus who can sign in.',\n ),\n ...writes(\n /^\\/api\\/(earlyaccessfeatures(\\/.*)?|admin\\/approvals\\/early-access-features)\\/?$/i,\n 'Early access features are feature flags, and an agent token writes no flag.',\n ),\n ],\n}\n\nconst UNDECODABLE_PATH_RULE: AgentWriteDenyRule = {\n method: '*',\n path: /%/,\n why: 'The path has a percent sign that does not decode.',\n}\n\n/**\n * isAgentWriteDenied returns the rule that denies this call of a `write`\n * token, or `undefined` when no rule does. `path` has no query string.\n *\n * Fastify routes on the decoded path, so `api%2Dclients` reaches the\n * `api-clients` route. Thus a rule matches the path as sent or as decoded,\n * and a path that does not decode is denied.\n */\nexport function isAgentWriteDenied(\n backend: keyof typeof AGENT_WRITE_DENY,\n method: string,\n path: string,\n): AgentWriteDenyRule | undefined {\n const upper = method.toUpperCase()\n let decoded: string\n try {\n decoded = decodeURIComponent(path)\n } catch {\n return UNDECODABLE_PATH_RULE\n }\n return AGENT_WRITE_DENY[backend].find(\n (rule) =>\n (rule.method === '*' || rule.method === upper) &&\n (rule.path.test(path) || rule.path.test(decoded)),\n )\n}\n"],
5
+ "mappings": "AAMA,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AAe5B,MAAM,cAAc;AAGpB,MAAM,yBAAyB;AAG/B,MAAM,4BAA4B;AAOlC,MAAM,kCAAkC;AAMxC,MAAM,8BAA8B;AAGpC,MAAM,qBAAqB;AAG3B,MAAM,4BAA4B;AAGlC,MAAM,0BAA0B,CAAC,GAAG,IAAI,EAAE;AAK1C,MAAM,uBAAuB;AAG7B,MAAM,0BAA0B;AAgBhC,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AACF;AAMO,MAAM,kCAAkC;AAGxC,MAAM,gCAAgC,CAAC,GAAG,EAAE;AAM5C,MAAM,iCAAiC;AAMvC,MAAM,6BAA6B;AAMnC,MAAM,8BAA8B;AAcpC,SAAS,sBAAsB,WAA6B;AACjE,MAAI,CAAC,aAAa,OAAO,cAAc,UAAU;AAC/C,WAAO;AAAA,EACT;AACA,QAAM,EAAE,MAAM,IAAI;AAClB,SAAO,OAAO,WAAW;AAC3B;AAcO,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AA+HO,MAAM,yBAIR;AAAA,EACH,SAAS,CAAC,oBAAoB,QAAQ;AAAA,EACtC,SAAS;AAAA,IACP,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,EACrB;AAAA,EACA,UAAU,CAAC,oBAAoB,QAAQ;AACzC;AAGO,SAAS,2BAAqC;AACnD,SAAO;AAAA,IACL,GAAG,oBAAI,IAAI;AAAA,MACT,GAAG,uBAAuB;AAAA,MAC1B,GAAG,uBAAuB;AAAA,MAC1B,GAAG,uBAAuB;AAAA,IAC5B,CAAC;AAAA,EACH;AACF;AAGO,MAAM,cAAc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,MACD;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,MAAM,wBAA4C;AAAA,EAChD,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,KAAK;AACP;AAUO,SAAS,mBACd,SACA,QACA,MACgC;AAChC,QAAM,QAAQ,OAAO,YAAY;AACjC,MAAI;AACJ,MAAI;AACF,cAAU,mBAAmB,IAAI;AAAA,EACnC,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO,iBAAiB,OAAO,EAAE;AAAA,IAC/B,CAAC,UACE,KAAK,WAAW,OAAO,KAAK,WAAW,WACvC,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,KAAK,OAAO;AAAA,EACnD;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ import { type AgentWriteDenyRule } from '../agent-tokens/agent-tokens.js';
1
2
  import type { ApprovalJobDto, ApprovalOverrideGrantDto, ApprovalUseCaseDto } from '../dtos/ApprovalJob.dto.js';
2
3
  /**
3
4
  * The rules of the approval mechanism, as pure functions.
@@ -23,6 +24,14 @@ import type { ApprovalJobDto, ApprovalOverrideGrantDto, ApprovalUseCaseDto } fro
23
24
  /** Who is asking. See the note above on why this is an interface. */
24
25
  export interface ApprovalActorView {
25
26
  userId: string;
27
+ /**
28
+ * Set when a `write` agent token acts as this person. The agent and the
29
+ * person are one eyepair: `userId` and `email` are the ones of the person.
30
+ */
31
+ viaAgent?: {
32
+ uuid: string;
33
+ name?: string;
34
+ };
26
35
  /**
27
36
  * The email of the actor. It is the SECOND identity of the four-eyes rule.
28
37
  *
@@ -106,6 +115,12 @@ export type ApprovalDecision = {
106
115
  code: ApprovalDenialCode;
107
116
  message: string;
108
117
  };
118
+ /**
119
+ * The rule of `AGENT_WRITE_DENY.control` that keeps a write agent from
120
+ * requests of this type, or `undefined`. The rule denies the route that opens
121
+ * such a request, and to approve or to run one gives the same power.
122
+ */
123
+ export declare function agentDeniedApprovalType(type: string): AgentWriteDenyRule | undefined;
109
124
  /**
110
125
  * Reports whether the time to answer a request has passed.
111
126
  *