@terreno/api 57.9.0 → 57.11.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.
- package/LICENSE +1 -0
- package/dist/api.js +44 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/notifiers/slackWebApi.d.ts +83 -0
- package/dist/notifiers/slackWebApi.js +453 -0
- package/dist/rbac/roleModel.js +28 -0
- package/dist/rbac/statements.d.ts +15 -0
- package/dist/rbac/statements.js +83 -1
- package/package.json +3 -3
- package/src/api.arrayOperations.test.ts +38 -0
- package/src/api.query.test.ts +15 -4
- package/src/api.ts +57 -7
- package/src/index.ts +1 -0
- package/src/notifiers/slackWebApi.test.ts +357 -0
- package/src/notifiers/slackWebApi.ts +567 -0
- package/src/rbac/roleModel.test.ts +85 -1
- package/src/rbac/roleModel.ts +40 -0
- package/src/rbac/statements.test.ts +60 -0
- package/src/rbac/statements.ts +91 -0
package/src/rbac/roleModel.ts
CHANGED
|
@@ -4,11 +4,14 @@ import type {APIErrorConstructor} from "../errors";
|
|
|
4
4
|
import {createdUpdatedPlugin, findExactlyOne, findOneOrNone} from "../plugins";
|
|
5
5
|
import {
|
|
6
6
|
expandRolePermissions as expandRolePermissionSpec,
|
|
7
|
+
mergeMissingResourcePermissions,
|
|
8
|
+
OBSERVABILITY_RBAC_RESOURCES,
|
|
7
9
|
type PermissionSet,
|
|
8
10
|
READ_ACTIONS,
|
|
9
11
|
READ_ONLY_ROLE_PERMISSIONS,
|
|
10
12
|
type RolePermissionSpec,
|
|
11
13
|
type Statements,
|
|
14
|
+
terrenoStatements,
|
|
12
15
|
} from "./statements";
|
|
13
16
|
|
|
14
17
|
export interface RoleDefinition {
|
|
@@ -48,6 +51,27 @@ export type RbacRoleModel = Model<RbacRoleDocument> & {
|
|
|
48
51
|
|
|
49
52
|
export {READ_ONLY_ROLE_PERMISSIONS} from "./statements";
|
|
50
53
|
|
|
54
|
+
const observabilityAdminPermissionSpec = (): PermissionSet => ({
|
|
55
|
+
aiDataset: [...terrenoStatements.aiDataset],
|
|
56
|
+
aiEvaluator: [...terrenoStatements.aiEvaluator],
|
|
57
|
+
aiExperiment: [...terrenoStatements.aiExperiment],
|
|
58
|
+
aiPrompt: [...terrenoStatements.aiPrompt],
|
|
59
|
+
aiReview: [...terrenoStatements.aiReview],
|
|
60
|
+
aiTrace: [...terrenoStatements.aiTrace],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const observabilityReadOnlyPermissionSpec = (statements: Statements): PermissionSet => {
|
|
64
|
+
const expanded = expandRolePermissions(READ_ONLY_ROLE_PERMISSIONS, statements);
|
|
65
|
+
const defaults: PermissionSet = {};
|
|
66
|
+
for (const resource of OBSERVABILITY_RBAC_RESOURCES) {
|
|
67
|
+
const actions = expanded[resource];
|
|
68
|
+
if (actions && actions.length > 0) {
|
|
69
|
+
defaults[resource] = [...actions];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return defaults;
|
|
73
|
+
};
|
|
74
|
+
|
|
51
75
|
/**
|
|
52
76
|
* Insert missing default roles. Existing unsealed roles are left unchanged so admin
|
|
53
77
|
* customizations survive process restarts. Sealed roles are refreshed from code.
|
|
@@ -61,6 +85,21 @@ const upsertSeededRole = async (
|
|
|
61
85
|
const existing = await model.findOneOrNone({name: role.name});
|
|
62
86
|
if (existing) {
|
|
63
87
|
if (!existing.isSealed) {
|
|
88
|
+
if (role.name === "admin") {
|
|
89
|
+
existing.permissions = mergeMissingResourcePermissions(
|
|
90
|
+
existing.permissions,
|
|
91
|
+
permissions,
|
|
92
|
+
OBSERVABILITY_RBAC_RESOURCES
|
|
93
|
+
);
|
|
94
|
+
await existing.save();
|
|
95
|
+
} else if (role.name === "auditor") {
|
|
96
|
+
existing.permissions = mergeMissingResourcePermissions(
|
|
97
|
+
existing.permissions,
|
|
98
|
+
observabilityReadOnlyPermissionSpec(statements),
|
|
99
|
+
OBSERVABILITY_RBAC_RESOURCES
|
|
100
|
+
);
|
|
101
|
+
await existing.save();
|
|
102
|
+
}
|
|
64
103
|
return;
|
|
65
104
|
}
|
|
66
105
|
existing.description = role.description;
|
|
@@ -121,6 +160,7 @@ export const terrenoDefaultRoles: RoleDefinition[] = [
|
|
|
121
160
|
adminAnnouncementImpression: ["read"],
|
|
122
161
|
configuration: ["read", "update"],
|
|
123
162
|
user: ["create", "list", "read", "update"],
|
|
163
|
+
...observabilityAdminPermissionSpec(),
|
|
124
164
|
},
|
|
125
165
|
},
|
|
126
166
|
{
|
|
@@ -3,10 +3,17 @@ import {assert} from "chai";
|
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
ADMIN_PAGE_PERMISSION,
|
|
6
|
+
AI_EXPERIMENT_ACTIONS,
|
|
7
|
+
AI_PROMPT_ACTIONS,
|
|
8
|
+
AI_REVIEW_ACTIONS,
|
|
9
|
+
AI_TRACE_ACTIONS,
|
|
6
10
|
expandRolePermissions,
|
|
11
|
+
mergeMissingResourcePermissions,
|
|
7
12
|
mergeStatements,
|
|
13
|
+
OBSERVABILITY_RBAC_RESOURCES,
|
|
8
14
|
READ_ACTIONS,
|
|
9
15
|
READ_ONLY_ROLE_PERMISSIONS,
|
|
16
|
+
terrenoStatementDescriptions,
|
|
10
17
|
terrenoStatements,
|
|
11
18
|
} from "./statements";
|
|
12
19
|
|
|
@@ -83,4 +90,57 @@ describe("rbac statements", () => {
|
|
|
83
90
|
|
|
84
91
|
expect(expanded).toEqual(permissions);
|
|
85
92
|
});
|
|
93
|
+
|
|
94
|
+
it("exports observability RBAC vocabulary (Q62/Q63)", () => {
|
|
95
|
+
expect(terrenoStatements.aiPrompt).toEqual([...AI_PROMPT_ACTIONS]);
|
|
96
|
+
expect(terrenoStatements.aiTrace).toEqual([...AI_TRACE_ACTIONS]);
|
|
97
|
+
expect(terrenoStatements.aiReview).toEqual([...AI_REVIEW_ACTIONS]);
|
|
98
|
+
expect(terrenoStatements.aiExperiment).toEqual([...AI_EXPERIMENT_ACTIONS]);
|
|
99
|
+
expect(terrenoStatements.aiDataset).toEqual(["create", "list", "read", "update", "delete"]);
|
|
100
|
+
expect(terrenoStatements.aiEvaluator).toEqual(["create", "list", "read", "update", "delete"]);
|
|
101
|
+
expect(OBSERVABILITY_RBAC_RESOURCES).toEqual([
|
|
102
|
+
"aiPrompt",
|
|
103
|
+
"aiTrace",
|
|
104
|
+
"aiReview",
|
|
105
|
+
"aiDataset",
|
|
106
|
+
"aiExperiment",
|
|
107
|
+
"aiEvaluator",
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("expands read-only sentinel to observability list and read actions", () => {
|
|
112
|
+
const expanded = expandRolePermissions(
|
|
113
|
+
READ_ONLY_ROLE_PERMISSIONS,
|
|
114
|
+
terrenoStatements,
|
|
115
|
+
READ_ACTIONS
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(expanded.aiPrompt).toEqual(["list", "read"]);
|
|
119
|
+
expect(expanded.aiTrace).toEqual(["list", "read"]);
|
|
120
|
+
expect(expanded.aiReview).toEqual(["list", "read"]);
|
|
121
|
+
expect(expanded.aiDataset).toEqual(["list", "read"]);
|
|
122
|
+
expect(expanded.aiEvaluator).toEqual(["list", "read"]);
|
|
123
|
+
expect(expanded.aiExperiment).toEqual(["list", "read"]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("includes human-readable descriptions for observability resources", () => {
|
|
127
|
+
expect(terrenoStatementDescriptions.aiPrompt?.promote).toContain("production");
|
|
128
|
+
expect(terrenoStatementDescriptions.aiReview?.score).toContain("review");
|
|
129
|
+
expect(Object.keys(terrenoStatementDescriptions.aiTrace ?? {})).toEqual(["list", "read"]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("mergeMissingResourcePermissions adds actions without removing custom grants", () => {
|
|
133
|
+
const defaults = {
|
|
134
|
+
aiPrompt: [...terrenoStatements.aiPrompt],
|
|
135
|
+
user: [...terrenoStatements.user],
|
|
136
|
+
};
|
|
137
|
+
const merged = mergeMissingResourcePermissions(
|
|
138
|
+
{aiPrompt: ["read"], user: ["read", "impersonate"]},
|
|
139
|
+
defaults,
|
|
140
|
+
["aiPrompt"]
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(merged.aiPrompt?.toSorted()).toEqual([...terrenoStatements.aiPrompt].toSorted());
|
|
144
|
+
expect(merged.user).toEqual(["read", "impersonate"]);
|
|
145
|
+
});
|
|
86
146
|
});
|
package/src/rbac/statements.ts
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
const MODEL_CRUD = ["create", "list", "read", "update", "delete"] as const;
|
|
2
2
|
export const ADMIN_MODEL_ACCESS = ["read", "write", "writeOwned"] as const;
|
|
3
3
|
|
|
4
|
+
export const AI_PROMPT_ACTIONS = [
|
|
5
|
+
"list",
|
|
6
|
+
"read",
|
|
7
|
+
"create",
|
|
8
|
+
"update",
|
|
9
|
+
"promote",
|
|
10
|
+
"playground",
|
|
11
|
+
] as const;
|
|
12
|
+
export const AI_TRACE_ACTIONS = ["list", "read"] as const;
|
|
13
|
+
export const AI_REVIEW_ACTIONS = ["list", "read", "score", "assign"] as const;
|
|
14
|
+
export const AI_EXPERIMENT_ACTIONS = ["list", "read", "create", "promote"] as const;
|
|
15
|
+
|
|
16
|
+
export const OBSERVABILITY_RBAC_RESOURCES = [
|
|
17
|
+
"aiPrompt",
|
|
18
|
+
"aiTrace",
|
|
19
|
+
"aiReview",
|
|
20
|
+
"aiDataset",
|
|
21
|
+
"aiExperiment",
|
|
22
|
+
"aiEvaluator",
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
export type ObservabilityRbacResource = (typeof OBSERVABILITY_RBAC_RESOURCES)[number];
|
|
26
|
+
|
|
4
27
|
/** Resource/action that opens the admin panel. Other admin permissions do not grant entry. */
|
|
5
28
|
export const ADMIN_PAGE_RESOURCE = "admin" as const;
|
|
6
29
|
export const ADMIN_PAGE_ACTION = "access" as const;
|
|
@@ -27,6 +50,12 @@ export const terrenoStatements = {
|
|
|
27
50
|
adminConsentForm: ADMIN_MODEL_ACCESS,
|
|
28
51
|
adminConsentResponse: ADMIN_MODEL_ACCESS,
|
|
29
52
|
adminFeatureFlag: ADMIN_MODEL_ACCESS,
|
|
53
|
+
aiDataset: MODEL_CRUD,
|
|
54
|
+
aiEvaluator: MODEL_CRUD,
|
|
55
|
+
aiExperiment: AI_EXPERIMENT_ACTIONS,
|
|
56
|
+
aiPrompt: AI_PROMPT_ACTIONS,
|
|
57
|
+
aiReview: AI_REVIEW_ACTIONS,
|
|
58
|
+
aiTrace: AI_TRACE_ACTIONS,
|
|
30
59
|
announcement: MODEL_CRUD,
|
|
31
60
|
announcementAcknowledgement: ["list", "read"],
|
|
32
61
|
announcementImpression: ["list", "read"],
|
|
@@ -63,6 +92,68 @@ export const mergeStatements = <S extends Statements>(appStatements: S): Stateme
|
|
|
63
92
|
};
|
|
64
93
|
};
|
|
65
94
|
|
|
95
|
+
export const terrenoStatementDescriptions: Record<string, Record<string, string>> = {
|
|
96
|
+
aiDataset: {
|
|
97
|
+
create: "Create datasets",
|
|
98
|
+
delete: "Delete datasets",
|
|
99
|
+
list: "List datasets",
|
|
100
|
+
read: "View dataset detail and items",
|
|
101
|
+
update: "Update datasets and items",
|
|
102
|
+
},
|
|
103
|
+
aiEvaluator: {
|
|
104
|
+
create: "Create evaluators",
|
|
105
|
+
delete: "Delete evaluators",
|
|
106
|
+
list: "List evaluators and templates",
|
|
107
|
+
read: "View evaluator detail",
|
|
108
|
+
update: "Update evaluators",
|
|
109
|
+
},
|
|
110
|
+
aiExperiment: {
|
|
111
|
+
create: "Start experiments and run estimates",
|
|
112
|
+
list: "List experiments",
|
|
113
|
+
promote: "Promote a passing prompt version to production",
|
|
114
|
+
read: "View experiment results",
|
|
115
|
+
},
|
|
116
|
+
aiPrompt: {
|
|
117
|
+
create: "Create prompts",
|
|
118
|
+
list: "List prompts",
|
|
119
|
+
playground: "Run the prompt playground",
|
|
120
|
+
promote: "Move production or staging labels",
|
|
121
|
+
read: "View prompt detail and versions",
|
|
122
|
+
update: "Create new prompt versions",
|
|
123
|
+
},
|
|
124
|
+
aiReview: {
|
|
125
|
+
assign: "Assign review items and enqueue traces for review",
|
|
126
|
+
list: "List the review queue",
|
|
127
|
+
read: "Open review items",
|
|
128
|
+
score: "Submit or skip review scores",
|
|
129
|
+
},
|
|
130
|
+
aiTrace: {
|
|
131
|
+
list: "List traces and observability status",
|
|
132
|
+
read: "View trace detail and run trace test helpers",
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** Add missing actions for selected resources without removing consumer-defined grants. */
|
|
137
|
+
export const mergeMissingResourcePermissions = (
|
|
138
|
+
existing: PermissionSet,
|
|
139
|
+
defaults: PermissionSet,
|
|
140
|
+
resources: readonly string[]
|
|
141
|
+
): PermissionSet => {
|
|
142
|
+
const merged: PermissionSet = {...existing};
|
|
143
|
+
for (const resource of resources) {
|
|
144
|
+
const defaultActions = defaults[resource];
|
|
145
|
+
if (!defaultActions || defaultActions.length === 0) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const current = new Set(merged[resource] ?? []);
|
|
149
|
+
for (const action of defaultActions) {
|
|
150
|
+
current.add(action);
|
|
151
|
+
}
|
|
152
|
+
merged[resource] = [...current];
|
|
153
|
+
}
|
|
154
|
+
return merged;
|
|
155
|
+
};
|
|
156
|
+
|
|
66
157
|
export const expandRolePermissions = (
|
|
67
158
|
spec: RolePermissionSpec,
|
|
68
159
|
statements: Statements,
|