@tipeline/core 0.1.0 → 0.1.1
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/dist/backup/BackupService.js +7 -4
- package/dist/database/models/Task.d.ts +3 -1
- package/dist/database/models/Task.js +14 -0
- package/dist/database/models/TaskRevision.d.ts +3 -1
- package/dist/database/models/TaskRevision.js +14 -0
- package/dist/database/services/ConnectionService.d.ts +5 -0
- package/dist/database/services/ConnectionService.js +28 -4
- package/dist/database/services/HubService.js +12 -1
- package/dist/database/services/PipelineRunnerService.js +1 -1
- package/dist/database/services/PipelineService.d.ts +13 -0
- package/dist/database/services/PipelineService.js +36 -3
- package/dist/database/services/RunHistorySecrets.d.ts +5 -0
- package/dist/database/services/RunHistorySecrets.js +98 -0
- package/dist/database/services/SecretSweep.d.ts +2 -0
- package/dist/database/services/SecretSweep.js +51 -2
- package/dist/database/services/TaskService.js +7 -2
- package/dist/engine/Core.d.ts +4 -1
- package/dist/engine/Core.js +21 -4
- package/dist/engine/Server.js +7 -0
- package/dist/engine/actionExamples.generated.js +3 -3
- package/dist/engine/runner/BreeRunner.d.ts +3 -0
- package/dist/engine/runner/BreeRunner.js +61 -0
- package/dist/engine/worker/JobExecutor.js +0 -1
- package/dist/pipeline/Block.d.ts +11 -0
- package/dist/pipeline/Block.js +48 -31
- package/dist/pipeline/Pipeline.d.ts +10 -1
- package/dist/pipeline/Pipeline.js +24 -8
- package/dist/utils/secretBox.d.ts +8 -0
- package/dist/utils/secretBox.js +37 -0
- package/dist/utils/secretText.d.ts +15 -0
- package/dist/utils/secretText.js +69 -0
- package/package.json +3 -3
|
@@ -4,8 +4,8 @@ export const ACTION_EXAMPLES = {
|
|
|
4
4
|
"ai.prompt": "# Summarize a document with DeepSeek using a system message and moderate temperature\n- group: ai\n name: prompt\n params:\n provider: deepseek\n apiKey: '{{ deepseekKey }}'\n prompt: 'Summarize the following document: {{ documentText }}'\n systemMessage: 'You are a concise technical writer. Return plain text only.'\n temperature: 0.5\n maxTokens: 300\n",
|
|
5
5
|
"alert.raise": "# Alert on a traffic spike; clear it once traffic is back to normal\n- group: flow\n name: ifConditional\n params:\n firstOperand: '{{ visits }}'\n compareAs: number\n operator: gt\n secondOperand: '{{ threshold }}'\n actions:\n - group: alert\n name: raise\n params:\n title: 'Traffic spike: {{ site }}'\n message: '{{ visits }} visits in the last hour (usual {{ baseline }})'\n level: warning\n key: 'spike-{{ site }}'\n- group: flow\n name: elseConditional\n params:\n actions:\n - group: alert\n name: resolve\n params:\n key: 'spike-{{ site }}'\n",
|
|
6
6
|
"alert.resolve": "- group: alert\n name: resolve\n params:\n key: 'spike-{{ site }}'\n",
|
|
7
|
-
"api.auth": "# Authenticate with Google OAuth2, reusing/refreshing the token stored in a global\n# variable
|
|
8
|
-
"api.basicAuth": "# Build a Basic Auth header value and persist it for reuse across every call to the site\n- group: api\n name: basicAuth\n params:\n username: '{{
|
|
7
|
+
"api.auth": "# Authenticate with Google OAuth2, reusing/refreshing the token stored in a global\n# variable. Create the secret globals googleClientId, googleClientSecret and\n# googleGmailToken once on the Variables page before first use.\n- group: api\n name: auth\n params:\n type: oauth2\n clientId: '{{ _global.googleClientId }}'\n clientSecret: '{{ _global.googleClientSecret }}'\n scopes:\n - 'https://www.googleapis.com/auth/gmail.readonly'\n - 'https://www.googleapis.com/auth/calendar.readonly'\n authEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth'\n tokenEndpoint: 'https://oauth2.googleapis.com/token'\n token: '{= _global.googleGmailToken =}'\n destination: _global.googleGmailToken\n",
|
|
8
|
+
"api.basicAuth": "# Build a Basic Auth header value from secret globals and persist it for reuse across\n# every call to the site\n- group: api\n name: basicAuth\n params:\n username: '{{ _global.drupalUser }}'\n password: '{{ _global.drupalPassword }}'\n destination: _global.drupalBasicAuth\n",
|
|
9
9
|
"api.invoke": "# Call the get-linode-instances endpoint loaded from the Linode OpenAPI spec\n- group: api\n name: invoke\n params:\n endpoints: '{= linodeAPI =}'\n method: get-linode-instances\n headers:\n Authorization: 'Bearer {{ myToken }}'\n args:\n apiVersion: v4\n destination: instances\n",
|
|
10
10
|
"api.load": "# Load the Linode API spec — include only the list-instances endpoint\n- group: api\n name: load\n params:\n url: 'https://raw.githubusercontent.com/linode/linode-api-docs/refs/heads/development/openapi.json'\n include:\n - get-linode-instances\n destination: linodeAPI\n",
|
|
11
11
|
"api.request": "# Fetch the 5 most recent Gmail messages using an OAuth2 token\n- group: api\n name: request\n params:\n url: 'https://gmail.googleapis.com/gmail/v1/users/me/messages'\n method: GET\n headers:\n Authorization: 'Bearer {{ googleToken.access_token }}'\n parameters:\n maxResults: 5\n destination: gmailMessages\n",
|
|
@@ -288,7 +288,7 @@ export const ACTION_EXAMPLES = {
|
|
|
288
288
|
"spreadsheet.writeCell": "# Update the status cell at row 3, column 1\n- group: spreadsheet\n name: writeCell\n params:\n workbook: '{= workbook =}'\n sheet: '{{ sheetName }}'\n row: 3\n col: 1\n value: completed\n destination: workbook\n",
|
|
289
289
|
"spreadsheet.writeRange": "# Write a header row and two data rows starting at A1\n- group: spreadsheet\n name: writeRange\n params:\n workbook: '{= workbook =}'\n sheet: '{{ sheetName }}'\n startCell: A1\n values:\n - [Name, Age, Active]\n - [Alice, 30, true]\n - [Bob, 25, false]\n destination: workbook\n",
|
|
290
290
|
"ssh.close": "# Close the SSH connection after all remote commands have finished\n- group: ssh\n name: close\n params:\n connection: '{= connection =}'\n",
|
|
291
|
-
"ssh.connect": "# Open an SSH connection using a private key and store it for later use\n- group: ssh\n name: connect\n params:\n config:\n host: '{{
|
|
291
|
+
"ssh.connect": "# Open an SSH connection using a private key and store it for later use. The host and\n# user come from global variables, the passphrase from a secret one.\n- group: ssh\n name: connect\n params:\n config:\n host: '{{ _global.sshHost }}'\n username: '{{ _global.sshUser }}'\n privateKeyPath: '{{ _global.sshKeyPath }}'\n passphrase: '{{ _global.sshPassphrase }}'\n destination: connection\n",
|
|
292
292
|
"ssh.exec": "# Run a shell command and capture its stdout output\n- group: ssh\n name: exec\n params:\n connection: '{= connection =}'\n command: 'ls -lsa /var/log'\n destination: result\n",
|
|
293
293
|
"string.camelCase": "# Convert task name to camelCase — useful for generating variable identifiers\n- group: string\n name: camelCase\n params:\n string: '{{ taskName }}'\n",
|
|
294
294
|
"string.capitalize": "# Capitalize action label — useful for display in UI headings\n- group: string\n name: capitalize\n params:\n string: '{{ actionLabel }}'\n",
|
|
@@ -5,6 +5,9 @@ export declare class BreeRunner implements IJobRunner {
|
|
|
5
5
|
private broadcastFn;
|
|
6
6
|
private streamListeners;
|
|
7
7
|
private running;
|
|
8
|
+
private workers;
|
|
9
|
+
private topRuns;
|
|
10
|
+
private cancels;
|
|
8
11
|
private onceJobs;
|
|
9
12
|
setBroadcast(fn: (event: string, data: any) => void): void;
|
|
10
13
|
constructor(_concurrency?: number);
|
|
@@ -11,6 +11,9 @@ import IPCMessage from '../IPCMessage.js';
|
|
|
11
11
|
const WORKER_PATH = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../worker/TaskWorker.js');
|
|
12
12
|
// How long running jobs get to end after being canceled, before they're ended for them.
|
|
13
13
|
const STOP_GRACE_MS = 5000;
|
|
14
|
+
// How long a canceled run gets to end by itself. A step that keeps the worker thread busy
|
|
15
|
+
// (a CPU-bound script) never reads the cancel message, so after this its worker is ended.
|
|
16
|
+
const CANCEL_GRACE_MS = 3000;
|
|
14
17
|
export class BreeRunner {
|
|
15
18
|
bree;
|
|
16
19
|
pending = new Map();
|
|
@@ -22,6 +25,13 @@ export class BreeRunner {
|
|
|
22
25
|
// Jobs running now (correlationId → the runs they started: the workflow's, then any
|
|
23
26
|
// sync sub-workflow's), so a run can be canceled by its pipelineIdentifier.
|
|
24
27
|
running = new Map();
|
|
28
|
+
// The worker thread of each running job, and the start of its top-level run (what a
|
|
29
|
+
// taskEnd for it needs, if its worker has to be ended for it).
|
|
30
|
+
workers = new Map();
|
|
31
|
+
topRuns = new Map();
|
|
32
|
+
// Canceled jobs: the timer that ends the worker if it doesn't stop by itself, and whether
|
|
33
|
+
// that happened (then its runs end as canceled, not as a crash).
|
|
34
|
+
cancels = new Map();
|
|
25
35
|
// Bree job names of one-time schedules: removed from Bree once their run ends.
|
|
26
36
|
onceJobs = new Set();
|
|
27
37
|
setBroadcast(fn) {
|
|
@@ -39,6 +49,7 @@ export class BreeRunner {
|
|
|
39
49
|
const correlationId = name.replace(/^job-/, '');
|
|
40
50
|
const runs = new Set();
|
|
41
51
|
this.running.set(correlationId, runs);
|
|
52
|
+
this.workers.set(correlationId, worker);
|
|
42
53
|
// For cron jobs: wire a TaskStreamListener so events reach IPC/WS clients.
|
|
43
54
|
if (name.startsWith('cron-') && this.broadcastFn) {
|
|
44
55
|
const listener = new TaskStreamListener(correlationId, this.broadcastFn);
|
|
@@ -62,9 +73,16 @@ export class BreeRunner {
|
|
|
62
73
|
else if (msg.type === 'taskStart') {
|
|
63
74
|
if (msg.data?.pipelineIdentifier)
|
|
64
75
|
runs.add(msg.data.pipelineIdentifier);
|
|
76
|
+
if (!this.topRuns.has(correlationId)) {
|
|
77
|
+
this.topRuns.set(correlationId, { start: msg.data ?? {}, ended: false });
|
|
78
|
+
}
|
|
65
79
|
coreEvents.emit(`taskStart:${correlationId}`, msg.data);
|
|
66
80
|
}
|
|
67
81
|
else if (msg.type === 'taskEnd') {
|
|
82
|
+
const top = this.topRuns.get(correlationId);
|
|
83
|
+
if (top && (msg.data?.pipelineIdentifier ?? '') === (top.start.pipelineIdentifier ?? '')) {
|
|
84
|
+
top.ended = true;
|
|
85
|
+
}
|
|
68
86
|
coreEvents.emit(`taskEnd:${correlationId}`, msg.data);
|
|
69
87
|
}
|
|
70
88
|
else if (msg.type === 'paused') {
|
|
@@ -121,6 +139,13 @@ export class BreeRunner {
|
|
|
121
139
|
const correlationId = name.replace(/^job-/, '');
|
|
122
140
|
const runs = [...(this.running.get(correlationId) ?? [])];
|
|
123
141
|
this.running.delete(correlationId);
|
|
142
|
+
this.workers.delete(correlationId);
|
|
143
|
+
const top = this.topRuns.get(correlationId);
|
|
144
|
+
this.topRuns.delete(correlationId);
|
|
145
|
+
const cancel = this.cancels.get(correlationId);
|
|
146
|
+
if (cancel)
|
|
147
|
+
clearTimeout(cancel.timer);
|
|
148
|
+
this.cancels.delete(correlationId);
|
|
124
149
|
debugCleanups.get(correlationId)?.();
|
|
125
150
|
debugCleanups.delete(correlationId);
|
|
126
151
|
// Clean up a self-created stream listener (cron or detached subtask job) if one exists.
|
|
@@ -135,6 +160,29 @@ export class BreeRunner {
|
|
|
135
160
|
}
|
|
136
161
|
const err = workerErrors.get(name);
|
|
137
162
|
workerErrors.delete(name);
|
|
163
|
+
// Ended for a cancel it couldn't take in: its runs end as canceled, and the job
|
|
164
|
+
// finishes the way a canceled run's job does — normally, with a canceled taskEnd.
|
|
165
|
+
if (cancel?.ended) {
|
|
166
|
+
const ended = PipelineService.cancelAbandoned(runs, cancel.canceledBy).catch((error) => {
|
|
167
|
+
console.error(`[BreeRunner] Failed to end the runs of ${name}:`, error);
|
|
168
|
+
});
|
|
169
|
+
void ended.then(() => {
|
|
170
|
+
if (top && !top.ended) {
|
|
171
|
+
coreEvents.emit(`taskEnd:${correlationId}`, {
|
|
172
|
+
name: top.start.name,
|
|
173
|
+
pipelineIdentifier: top.start.pipelineIdentifier ?? '',
|
|
174
|
+
taskIdentifier: top.start.taskIdentifier,
|
|
175
|
+
status: 'canceled',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
const pending = this.pending.get(name);
|
|
179
|
+
if (!pending)
|
|
180
|
+
return;
|
|
181
|
+
this.pending.delete(name);
|
|
182
|
+
pending.resolve();
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
138
186
|
// A run that ended normally already says so; one still running lost its worker
|
|
139
187
|
// (a crash) and would otherwise show as running forever, with nothing to cancel.
|
|
140
188
|
const message = `The run stopped unexpectedly${err?.message ? `: ${err.message}` : ''}`;
|
|
@@ -239,6 +287,19 @@ export class BreeRunner {
|
|
|
239
287
|
if (!this.running.has(correlationId))
|
|
240
288
|
return false;
|
|
241
289
|
coreEvents.emit(`run:cancel:${correlationId}`, { canceledBy });
|
|
290
|
+
// A step that keeps the worker busy never reads the cancel: end the worker for it.
|
|
291
|
+
if (!this.cancels.has(correlationId)) {
|
|
292
|
+
const timer = setTimeout(() => {
|
|
293
|
+
const entry = this.cancels.get(correlationId);
|
|
294
|
+
const worker = this.workers.get(correlationId);
|
|
295
|
+
if (!entry || !worker)
|
|
296
|
+
return;
|
|
297
|
+
entry.ended = true;
|
|
298
|
+
worker.terminate();
|
|
299
|
+
}, CANCEL_GRACE_MS);
|
|
300
|
+
timer.unref?.();
|
|
301
|
+
this.cancels.set(correlationId, { canceledBy, timer, ended: false });
|
|
302
|
+
}
|
|
242
303
|
return true;
|
|
243
304
|
}
|
|
244
305
|
findJob(pipelineIdentifier) {
|
|
@@ -7,7 +7,6 @@ import { coerceVariableValue } from '../../utils/coerceVariableValue.js';
|
|
|
7
7
|
import { assertNotDraft } from '../../task/Draft.js';
|
|
8
8
|
import { toStartedBy } from '../../utils/runInfo.js';
|
|
9
9
|
export async function executeJob(job) {
|
|
10
|
-
console.log('== executeJob ==', job);
|
|
11
10
|
const { type } = job;
|
|
12
11
|
if (type === 'exec') {
|
|
13
12
|
const record = await TaskService.getByIdentifier(job.identifier);
|
package/dist/pipeline/Block.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class Block {
|
|
|
9
9
|
private lastResult;
|
|
10
10
|
private shouldSave;
|
|
11
11
|
private servedFromCache;
|
|
12
|
+
private cacheSkipped;
|
|
12
13
|
constructor(actions: Array<Action>, task: Task, blockId: number);
|
|
13
14
|
run(): Promise<void>;
|
|
14
15
|
/** This block's workflow and how many sub-workflows deep it runs, for the debugger. */
|
|
@@ -43,9 +44,19 @@ export declare class Block {
|
|
|
43
44
|
private buildDisplayParams;
|
|
44
45
|
private buildDisplayResult;
|
|
45
46
|
private assertGlobalsExist;
|
|
47
|
+
/**
|
|
48
|
+
* How a step's `_global.NAME` references resolve. `forDisplay` gives a global secret the
|
|
49
|
+
* placeholder instead of its value, as buildDisplayParams does for secret variables.
|
|
50
|
+
*/
|
|
46
51
|
private buildGlobalVarLookup;
|
|
47
52
|
private getVariableByName;
|
|
48
53
|
private redactSecrets;
|
|
54
|
+
/**
|
|
55
|
+
* What a step's record keeps: its input and result as shown (secrets replaced), never the
|
|
56
|
+
* real values. Run history is read by the run page and by apps; resuming only needs the
|
|
57
|
+
* step's status, and the variables keep their values in their own sealed rows.
|
|
58
|
+
*/
|
|
59
|
+
private storedRecord;
|
|
49
60
|
setLastResult(lastResult: unknown): void;
|
|
50
61
|
getLastResult(): unknown;
|
|
51
62
|
getBlockId(): number;
|
package/dist/pipeline/Block.js
CHANGED
|
@@ -12,6 +12,8 @@ import { declaredReturnType } from '../action/declaredReturnType.js';
|
|
|
12
12
|
import { parseTtl } from '@tipeline/schemas';
|
|
13
13
|
import { stepCacheKey, canonicalJson } from '../cache/CacheKey.js';
|
|
14
14
|
import { CacheService } from '../database/services/CacheService.js';
|
|
15
|
+
import { PipelineService } from '../database/services/PipelineService.js';
|
|
16
|
+
import { REDACTED, redactSecretTexts } from '../utils/secretText.js';
|
|
15
17
|
// Failures a debugger run already paused at (and let fail): the blocks around the step
|
|
16
18
|
// see the same error on its way out and must not pause at it again.
|
|
17
19
|
const pausedFailures = new WeakSet();
|
|
@@ -25,6 +27,8 @@ export class Block {
|
|
|
25
27
|
shouldSave;
|
|
26
28
|
// Set by runAction: whether the step it just ran was served from the result cache.
|
|
27
29
|
servedFromCache = null;
|
|
30
|
+
// Set by runAction: the step has `cache:` but its result held a secret, so it wasn't kept.
|
|
31
|
+
cacheSkipped = null;
|
|
28
32
|
constructor(actions, task, blockId) {
|
|
29
33
|
this.actions = actions;
|
|
30
34
|
this.task = task;
|
|
@@ -183,8 +187,7 @@ export class Block {
|
|
|
183
187
|
const result = isStopStep ? signal.reason || null : null;
|
|
184
188
|
if (this.shouldSave) {
|
|
185
189
|
await PipelineActionService.updateStatus(this.pipeline.getId(), this.blockId, action.identifier, 'completed', {
|
|
186
|
-
result,
|
|
187
|
-
params: action.getParamsPlain(),
|
|
190
|
+
...(await this.storedRecord(action, result)),
|
|
188
191
|
finishedAt: new Date(),
|
|
189
192
|
});
|
|
190
193
|
}
|
|
@@ -220,8 +223,7 @@ export class Block {
|
|
|
220
223
|
const result = await this.runAction(action);
|
|
221
224
|
if (this.shouldSave) {
|
|
222
225
|
await PipelineActionService.updateStatus(pipelineId, this.blockId, action.identifier, 'completed', {
|
|
223
|
-
result,
|
|
224
|
-
params: action.getParamsPlain(),
|
|
226
|
+
...(await this.storedRecord(action, result)),
|
|
225
227
|
finishedAt: new Date(),
|
|
226
228
|
...(this.servedFromCache ? { cached: true } : {}),
|
|
227
229
|
});
|
|
@@ -233,7 +235,7 @@ export class Block {
|
|
|
233
235
|
if (error instanceof ApprovalPendingSignal) {
|
|
234
236
|
if (this.shouldSave) {
|
|
235
237
|
await PipelineActionService.updateStatus(pipelineId, this.blockId, action.identifier, 'paused', {
|
|
236
|
-
|
|
238
|
+
...(await this.storedRecord(action)),
|
|
237
239
|
});
|
|
238
240
|
}
|
|
239
241
|
throw error;
|
|
@@ -243,8 +245,8 @@ export class Block {
|
|
|
243
245
|
if (error instanceof ApprovalRejectedSignal || error instanceof RunCanceledSignal) {
|
|
244
246
|
if (this.shouldSave) {
|
|
245
247
|
await PipelineActionService.updateStatus(pipelineId, this.blockId, action.identifier, 'canceled', {
|
|
246
|
-
error: error.message,
|
|
247
|
-
|
|
248
|
+
error: this.redactSecrets(error.message),
|
|
249
|
+
...(await this.storedRecord(action)),
|
|
248
250
|
});
|
|
249
251
|
}
|
|
250
252
|
throw error;
|
|
@@ -257,8 +259,8 @@ export class Block {
|
|
|
257
259
|
}
|
|
258
260
|
if (this.shouldSave) {
|
|
259
261
|
await PipelineActionService.updateStatus(pipelineId, this.blockId, action.identifier, 'failed', {
|
|
260
|
-
error: error.message || String(error),
|
|
261
|
-
|
|
262
|
+
error: this.redactSecrets(error.message || String(error)),
|
|
263
|
+
...(await this.storedRecord(action)),
|
|
262
264
|
finishedAt: new Date(),
|
|
263
265
|
});
|
|
264
266
|
}
|
|
@@ -397,7 +399,8 @@ export class Block {
|
|
|
397
399
|
.filter((v) => v.getValue() !== beforeValues.get(v.getName()))
|
|
398
400
|
.map((v) => ({
|
|
399
401
|
name: v.getName(),
|
|
400
|
-
|
|
402
|
+
// Shown live (the run page, the debugger): a secret's value never is.
|
|
403
|
+
value: isNonSerializableVariableType(v.getType()) ? null : this.redactSecrets(v.getValue()),
|
|
401
404
|
}));
|
|
402
405
|
coreEvents.emit(`action:${correlationId}`, {
|
|
403
406
|
name: `${action.group}.${action.name}`,
|
|
@@ -414,6 +417,7 @@ export class Block {
|
|
|
414
417
|
identifier: action.identifier,
|
|
415
418
|
taskIdentifier: this.task.getIdentifier(),
|
|
416
419
|
...(this.servedFromCache ? { cached: true, cachedAt: this.servedFromCache.createdAt } : {}),
|
|
420
|
+
...(this.cacheSkipped ? { cacheSkipped: this.cacheSkipped } : {}),
|
|
417
421
|
});
|
|
418
422
|
return result;
|
|
419
423
|
}
|
|
@@ -426,6 +430,7 @@ export class Block {
|
|
|
426
430
|
*/
|
|
427
431
|
async executeOrServeFromCache(action) {
|
|
428
432
|
this.servedFromCache = null;
|
|
433
|
+
this.cacheSkipped = null;
|
|
429
434
|
const mode = this.task.getCacheMode();
|
|
430
435
|
const ttl = action.cache ? parseTtl(action.cache.ttl) : null;
|
|
431
436
|
const key = ttl && mode !== 'bypass' ? stepCacheKey(action, action.getParams(), action.cache?.key) : null;
|
|
@@ -444,6 +449,16 @@ export class Block {
|
|
|
444
449
|
const result = await action.execute(this.task, this.lastResult);
|
|
445
450
|
// onError: continue turns a failure into undefined — never store that, nor
|
|
446
451
|
// anything that isn't plain data (it couldn't come back as what it was).
|
|
452
|
+
// The cache is plain text by design (results are reused as they are), so a result that
|
|
453
|
+
// holds a secret's value is not kept: the step runs again next time instead, and the run
|
|
454
|
+
// says so (cacheSkipped) rather than leaving someone to wonder why it never caches.
|
|
455
|
+
if (result !== undefined && this.pipeline.containsSecret(result)) {
|
|
456
|
+
this.cacheSkipped = 'secret';
|
|
457
|
+
if (this.shouldSave && this.pipeline.getId()) {
|
|
458
|
+
await PipelineService.noteCacheSkipped(this.pipeline.getId(), action.identifier).catch(() => { });
|
|
459
|
+
}
|
|
460
|
+
return result;
|
|
461
|
+
}
|
|
447
462
|
if (result !== undefined && canonicalJson(result) !== null) {
|
|
448
463
|
await CacheService.set({
|
|
449
464
|
key,
|
|
@@ -476,14 +491,14 @@ export class Block {
|
|
|
476
491
|
// non-secret variable that happens to share a secret's literal value is
|
|
477
492
|
// never falsely redacted. Like getParamsPlain, it returns plain data only.
|
|
478
493
|
async buildDisplayParams(action) {
|
|
479
|
-
if (
|
|
494
|
+
if (this.pipeline.secretTexts().length === 0) {
|
|
480
495
|
return action.getParamsPlain();
|
|
481
496
|
}
|
|
482
497
|
const fresh = safeClone(action.getRawParams());
|
|
483
498
|
const displayVariables = this.variables.map((variable) => variable.isSecret()
|
|
484
499
|
? { getName: () => variable.getName(), getValue: () => '[REDACTED]' }
|
|
485
500
|
: variable);
|
|
486
|
-
const getGlobalVar = await this.buildGlobalVarLookup(fresh);
|
|
501
|
+
const getGlobalVar = await this.buildGlobalVarLookup(fresh, undefined, { forDisplay: true });
|
|
487
502
|
parseStepParams(action.group, fresh, displayVariables, getGlobalVar, this.lastResult, this.task.getRunContext());
|
|
488
503
|
// The re-render resolves {= connection =} back to the live object (an SSH or
|
|
489
504
|
// database connection, a browser): make it plain like getParamsPlain, or the
|
|
@@ -525,11 +540,17 @@ export class Block {
|
|
|
525
540
|
}
|
|
526
541
|
// Only hits the DB if the params actually reference {{ _global.* }} or {= _global.* =}.
|
|
527
542
|
// Given the step about to run, it also stops that step if a global it reads is missing.
|
|
528
|
-
|
|
543
|
+
/**
|
|
544
|
+
* How a step's `_global.NAME` references resolve. `forDisplay` gives a global secret the
|
|
545
|
+
* placeholder instead of its value, as buildDisplayParams does for secret variables.
|
|
546
|
+
*/
|
|
547
|
+
async buildGlobalVarLookup(params, action, options = {}) {
|
|
529
548
|
if (!params || !JSON.stringify(params).includes('_global.'))
|
|
530
549
|
return undefined;
|
|
531
550
|
const records = await GlobalVariableService.getAll();
|
|
532
|
-
|
|
551
|
+
// A global secret changed during the run is still kept out of what's shown and stored.
|
|
552
|
+
this.pipeline.setSecretGlobals(records.filter((r) => r.secret).map((r) => r.value));
|
|
553
|
+
const map = new Map(records.map((r) => [r.name, options.forDisplay && r.secret ? REDACTED : (r.value ?? '')]));
|
|
533
554
|
if (action)
|
|
534
555
|
this.assertGlobalsExist(action, params, map);
|
|
535
556
|
return (name) => map.get(name) ?? '';
|
|
@@ -541,25 +562,21 @@ export class Block {
|
|
|
541
562
|
// broadcast to the UI (action params/results, error messages) — those
|
|
542
563
|
// values come from env/global lookups and must never reach the renderer
|
|
543
564
|
// in plain text, even inside a larger interpolated string.
|
|
565
|
+
// Global secrets' values too: a step can read one without a workflow variable.
|
|
544
566
|
redactSecrets(data) {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (value && typeof value === 'object') {
|
|
558
|
-
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, redactDeep(v)]));
|
|
559
|
-
}
|
|
560
|
-
return value;
|
|
567
|
+
return redactSecretTexts(data, this.pipeline.secretTexts());
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* What a step's record keeps: its input and result as shown (secrets replaced), never the
|
|
571
|
+
* real values. Run history is read by the run page and by apps; resuming only needs the
|
|
572
|
+
* step's status, and the variables keep their values in their own sealed rows.
|
|
573
|
+
*/
|
|
574
|
+
async storedRecord(action, result) {
|
|
575
|
+
const params = await this.buildDisplayParams(action).catch(() => null);
|
|
576
|
+
return {
|
|
577
|
+
params,
|
|
578
|
+
...(result !== undefined ? { result: this.buildDisplayResult(result, action.getParamsPlain(), params) } : {}),
|
|
561
579
|
};
|
|
562
|
-
return redactDeep(data);
|
|
563
580
|
}
|
|
564
581
|
setLastResult(lastResult) {
|
|
565
582
|
this.lastResult = lastResult;
|
|
@@ -19,7 +19,16 @@ export declare class Pipeline {
|
|
|
19
19
|
getVariables(): Variable[];
|
|
20
20
|
getIdentifier(): string;
|
|
21
21
|
getId(): number;
|
|
22
|
-
|
|
22
|
+
private secretGlobalValues;
|
|
23
|
+
/** Takes the global secrets' current values (Block calls it whenever it reads the globals). */
|
|
24
|
+
setSecretGlobals(values: unknown[]): void;
|
|
25
|
+
private loadSecretGlobals;
|
|
26
|
+
/**
|
|
27
|
+
* The texts this run must never show or store in the clear: its secret variables' values
|
|
28
|
+
* and the global secrets', longest first.
|
|
29
|
+
*/
|
|
30
|
+
secretTexts(): string[];
|
|
31
|
+
/** Whether a value holds a secret's value (a variable's or a global's), even inside longer text. */
|
|
23
32
|
containsSecret(value: unknown): boolean;
|
|
24
33
|
getVariableByName(name: string): Variable | undefined;
|
|
25
34
|
/**
|
|
@@ -6,6 +6,8 @@ import { coreEvents } from '../engine/CoreEvents.js';
|
|
|
6
6
|
import { DebugController } from '../engine/DebugController.js';
|
|
7
7
|
import { coreInfo } from '../utils/runInfo.js';
|
|
8
8
|
import { isNonSerializableVariableType } from '../utils/nonSerializableTypes.js';
|
|
9
|
+
import { containsSecretText, secretStringsOf } from '../utils/secretText.js';
|
|
10
|
+
import { GlobalVariableService } from '../database/services/GlobalVariableService.js';
|
|
9
11
|
import { ApprovalPendingSignal, ApprovalRejectedSignal, RunCanceledSignal, RunStoppedSignal, } from '../utils/errors.js';
|
|
10
12
|
export class Pipeline {
|
|
11
13
|
actions;
|
|
@@ -49,15 +51,28 @@ export class Pipeline {
|
|
|
49
51
|
getId() {
|
|
50
52
|
return this.id;
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
// The values of the global secrets, which a step can read without a workflow variable
|
|
55
|
+
// ({{ _global.NAME }}): as secret here as the workflow's own. See secretTexts.
|
|
56
|
+
secretGlobalValues = [];
|
|
57
|
+
/** Takes the global secrets' current values (Block calls it whenever it reads the globals). */
|
|
58
|
+
setSecretGlobals(values) {
|
|
59
|
+
this.secretGlobalValues = values;
|
|
60
|
+
}
|
|
61
|
+
async loadSecretGlobals() {
|
|
62
|
+
const records = await GlobalVariableService.getAll().catch(() => []);
|
|
63
|
+
this.setSecretGlobals(records.filter((r) => r.secret).map((r) => r.value));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The texts this run must never show or store in the clear: its secret variables' values
|
|
67
|
+
* and the global secrets', longest first.
|
|
68
|
+
*/
|
|
69
|
+
secretTexts() {
|
|
70
|
+
const own = this.variables.filter((variable) => variable.isSecret()).map((variable) => variable.getValue());
|
|
71
|
+
return secretStringsOf([...own, ...this.secretGlobalValues]);
|
|
72
|
+
}
|
|
73
|
+
/** Whether a value holds a secret's value (a variable's or a global's), even inside longer text. */
|
|
53
74
|
containsSecret(value) {
|
|
54
|
-
|
|
55
|
-
if (text === undefined)
|
|
56
|
-
return false;
|
|
57
|
-
return this.variables.some((variable) => {
|
|
58
|
-
const secret = variable.isSecret() ? variable.getValue() : null;
|
|
59
|
-
return typeof secret === 'string' && secret.length > 0 && text.includes(JSON.stringify(secret).slice(1, -1));
|
|
60
|
-
});
|
|
75
|
+
return containsSecretText(value, this.secretTexts());
|
|
61
76
|
}
|
|
62
77
|
getVariableByName(name) {
|
|
63
78
|
return this.variables.find((variable) => variable.getName() === name);
|
|
@@ -143,6 +158,7 @@ export class Pipeline {
|
|
|
143
158
|
await Promise.all(this.variables.map((variable) => variable.cleanup()));
|
|
144
159
|
}
|
|
145
160
|
async executeBlock(blockId) {
|
|
161
|
+
await this.loadSecretGlobals();
|
|
146
162
|
const block = new Block(this.actions, this.task, blockId);
|
|
147
163
|
await block.run();
|
|
148
164
|
}
|
|
@@ -17,3 +17,11 @@ export declare function redactSecretValues<T>(source: T, placeholder?: string):
|
|
|
17
17
|
source: T;
|
|
18
18
|
count: number;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* A workflow source (JSON text) with each secret variable's written-in value sealed, for the
|
|
22
|
+
* table: the workflow keeps its secrets, the database file doesn't show them. Already sealed
|
|
23
|
+
* values and empty ones stay as they are. Not JSON (or no variables): unchanged.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sealSourceSecrets(source: string | null | undefined): string | null | undefined;
|
|
26
|
+
/** The reverse of sealSourceSecrets: what the rest of Core works with. A value that can't be read (lost key) is null. */
|
|
27
|
+
export declare function openSourceSecrets(source: string | null | undefined): string | null | undefined;
|
package/dist/utils/secretBox.js
CHANGED
|
@@ -84,3 +84,40 @@ export function redactSecretValues(source, placeholder = '') {
|
|
|
84
84
|
count,
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* A workflow source (JSON text) with each secret variable's written-in value sealed, for the
|
|
89
|
+
* table: the workflow keeps its secrets, the database file doesn't show them. Already sealed
|
|
90
|
+
* values and empty ones stay as they are. Not JSON (or no variables): unchanged.
|
|
91
|
+
*/
|
|
92
|
+
export function sealSourceSecrets(source) {
|
|
93
|
+
return mapSecretValues(source, (value) => isSealed(value) || value === undefined || value === null || value === '' ? value : seal(JSON.stringify(value)));
|
|
94
|
+
}
|
|
95
|
+
/** The reverse of sealSourceSecrets: what the rest of Core works with. A value that can't be read (lost key) is null. */
|
|
96
|
+
export function openSourceSecrets(source) {
|
|
97
|
+
return mapSecretValues(source, (value) => (isSealed(value) ? JSON.parse(unseal(value)) : value));
|
|
98
|
+
}
|
|
99
|
+
function mapSecretValues(source, map) {
|
|
100
|
+
if (!source || !source.includes('"secret"'))
|
|
101
|
+
return source;
|
|
102
|
+
let parsed;
|
|
103
|
+
try {
|
|
104
|
+
parsed = JSON.parse(source);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return source;
|
|
108
|
+
}
|
|
109
|
+
const variables = parsed?.pipeline?.variables;
|
|
110
|
+
if (!Array.isArray(variables))
|
|
111
|
+
return source;
|
|
112
|
+
let changed = false;
|
|
113
|
+
const next = variables.map((variable) => {
|
|
114
|
+
if (!variable?.secret || !('value' in variable))
|
|
115
|
+
return variable;
|
|
116
|
+
const value = map(variable.value);
|
|
117
|
+
if (value === variable.value)
|
|
118
|
+
return variable;
|
|
119
|
+
changed = true;
|
|
120
|
+
return { ...variable, value };
|
|
121
|
+
});
|
|
122
|
+
return changed ? JSON.stringify({ ...parsed, pipeline: { ...parsed.pipeline, variables: next } }) : source;
|
|
123
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding a secret's value in text that's about to be shown or stored: a step's filled-in
|
|
3
|
+
* input, its result, an error message. A secret that's a string is looked for as a whole; one
|
|
4
|
+
* that's an object or a list (an OAuth token, a connection) by the texts inside it long enough
|
|
5
|
+
* not to be common words ("Bearer" stays, the token itself goes).
|
|
6
|
+
*/
|
|
7
|
+
export declare const REDACTED = "[REDACTED]";
|
|
8
|
+
/** The texts to look for when `value` is a secret, longest first. */
|
|
9
|
+
export declare function secretStrings(value: unknown): string[];
|
|
10
|
+
/** Every secret text in `values`, without repeats, longest first (so a longer one is replaced whole). */
|
|
11
|
+
export declare function secretStringsOf(values: unknown[]): string[];
|
|
12
|
+
/** `data` with every occurrence of the given secret texts replaced, at any depth. */
|
|
13
|
+
export declare function redactSecretTexts<T>(data: T, secrets: string[]): T;
|
|
14
|
+
/** Whether a secret text appears anywhere in `value`, even inside longer text. */
|
|
15
|
+
export declare function containsSecretText(value: unknown, secrets: string[]): boolean;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding a secret's value in text that's about to be shown or stored: a step's filled-in
|
|
3
|
+
* input, its result, an error message. A secret that's a string is looked for as a whole; one
|
|
4
|
+
* that's an object or a list (an OAuth token, a connection) by the texts inside it long enough
|
|
5
|
+
* not to be common words ("Bearer" stays, the token itself goes).
|
|
6
|
+
*/
|
|
7
|
+
export const REDACTED = '[REDACTED]';
|
|
8
|
+
const MIN_INNER_LENGTH = 8;
|
|
9
|
+
/** The texts to look for when `value` is a secret, longest first. */
|
|
10
|
+
export function secretStrings(value) {
|
|
11
|
+
const found = new Set();
|
|
12
|
+
if (typeof value === 'string') {
|
|
13
|
+
if (value.length > 0)
|
|
14
|
+
found.add(value);
|
|
15
|
+
}
|
|
16
|
+
else if (typeof value === 'number' && String(value).length >= MIN_INNER_LENGTH) {
|
|
17
|
+
found.add(String(value));
|
|
18
|
+
}
|
|
19
|
+
else if (value && typeof value === 'object') {
|
|
20
|
+
const walk = (inner) => {
|
|
21
|
+
if (typeof inner === 'string') {
|
|
22
|
+
if (inner.length >= MIN_INNER_LENGTH)
|
|
23
|
+
found.add(inner);
|
|
24
|
+
}
|
|
25
|
+
else if (Array.isArray(inner)) {
|
|
26
|
+
inner.forEach(walk);
|
|
27
|
+
}
|
|
28
|
+
else if (inner && typeof inner === 'object') {
|
|
29
|
+
Object.values(inner).forEach(walk);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
walk(value);
|
|
33
|
+
}
|
|
34
|
+
return [...found];
|
|
35
|
+
}
|
|
36
|
+
/** Every secret text in `values`, without repeats, longest first (so a longer one is replaced whole). */
|
|
37
|
+
export function secretStringsOf(values) {
|
|
38
|
+
const all = new Set();
|
|
39
|
+
for (const value of values)
|
|
40
|
+
for (const text of secretStrings(value))
|
|
41
|
+
all.add(text);
|
|
42
|
+
return [...all].sort((a, b) => b.length - a.length);
|
|
43
|
+
}
|
|
44
|
+
/** `data` with every occurrence of the given secret texts replaced, at any depth. */
|
|
45
|
+
export function redactSecretTexts(data, secrets) {
|
|
46
|
+
if (secrets.length === 0)
|
|
47
|
+
return data;
|
|
48
|
+
const redactString = (text) => secrets.reduce((acc, secret) => acc.split(secret).join(REDACTED), text);
|
|
49
|
+
const redactDeep = (value) => {
|
|
50
|
+
if (typeof value === 'string')
|
|
51
|
+
return redactString(value);
|
|
52
|
+
if (Array.isArray(value))
|
|
53
|
+
return value.map(redactDeep);
|
|
54
|
+
if (value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
|
|
55
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, redactDeep(v)]));
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
};
|
|
59
|
+
return redactDeep(data);
|
|
60
|
+
}
|
|
61
|
+
/** Whether a secret text appears anywhere in `value`, even inside longer text. */
|
|
62
|
+
export function containsSecretText(value, secrets) {
|
|
63
|
+
if (secrets.length === 0)
|
|
64
|
+
return false;
|
|
65
|
+
const text = JSON.stringify(value);
|
|
66
|
+
if (text === undefined)
|
|
67
|
+
return false;
|
|
68
|
+
return secrets.some((secret) => text.includes(JSON.stringify(secret).slice(1, -1)));
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tipeline/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Tipeline Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"@apidevtools/swagger-parser": "^10.1.1",
|
|
60
60
|
"@date-fns/tz": "^1.5.0",
|
|
61
61
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
62
|
-
"@tipeline/schemas": "0.1.
|
|
63
|
-
"@tipeline/utils": "0.1.
|
|
62
|
+
"@tipeline/schemas": "0.1.1",
|
|
63
|
+
"@tipeline/utils": "0.1.1",
|
|
64
64
|
"archiver": "^7.0.1",
|
|
65
65
|
"axios": "^1.9.0",
|
|
66
66
|
"better-sqlite3": "^12.9.0",
|