@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { redactSecretValues, seal, unseal } from '../utils/secretBox.js';
|
|
1
|
+
import { openSourceSecrets, redactSecretValues, seal, sealSourceSecrets, unseal } from '../utils/secretBox.js';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import nodePath from 'path';
|
|
4
4
|
import archiver from 'archiver';
|
|
@@ -145,7 +145,8 @@ export class BackupService {
|
|
|
145
145
|
const taskFiles = readableFileNames(rows.tasks, 'workflow');
|
|
146
146
|
const tasks = [];
|
|
147
147
|
for (const row of rows.tasks) {
|
|
148
|
-
|
|
148
|
+
// Read straight from the table, where secret values are sealed (see the Task model).
|
|
149
|
+
const source = parseJson(openSourceSecrets(row.source));
|
|
149
150
|
if (!source)
|
|
150
151
|
continue;
|
|
151
152
|
const file = `tasks/${taskFiles.get(row.identifier)}.yml`;
|
|
@@ -498,7 +499,8 @@ export class BackupService {
|
|
|
498
499
|
version: t.version ?? null,
|
|
499
500
|
platform: t.platform ?? null,
|
|
500
501
|
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
501
|
-
|
|
502
|
+
// Written straight to the table: secret values sealed, as the Task model does.
|
|
503
|
+
source: sealSourceSecrets(JSON.stringify(t.source)),
|
|
502
504
|
};
|
|
503
505
|
let id;
|
|
504
506
|
if (existing) {
|
|
@@ -510,7 +512,8 @@ export class BackupService {
|
|
|
510
512
|
[id] = await trx('task').insert({ identifier: t.identifier, ...data });
|
|
511
513
|
result.tasks.added++;
|
|
512
514
|
}
|
|
513
|
-
|
|
515
|
+
// The plain source: the revision model seals it, and compares it with the last one.
|
|
516
|
+
await TaskRevisionService.record(existing ?? { id }, JSON.stringify(t.source), 'backup', { trx });
|
|
514
517
|
await this.setTags(trx, id, t.tags ?? []);
|
|
515
518
|
await joinProjects('task', id, t);
|
|
516
519
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Model } from 'objection';
|
|
1
|
+
import { Model, type Pojo } from 'objection';
|
|
2
2
|
export declare class Task extends Model {
|
|
3
3
|
id: number;
|
|
4
4
|
identifier: string;
|
|
@@ -11,6 +11,8 @@ export declare class Task extends Model {
|
|
|
11
11
|
source?: string;
|
|
12
12
|
created_at: Date;
|
|
13
13
|
updated_at: Date;
|
|
14
|
+
$parseDatabaseJson(json: Pojo): Pojo;
|
|
15
|
+
$formatDatabaseJson(json: Pojo): Pojo;
|
|
14
16
|
static get tableName(): string;
|
|
15
17
|
static get jsonAttributes(): string[];
|
|
16
18
|
static get jsonSchema(): {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Model } from 'objection';
|
|
2
|
+
import { openSourceSecrets, sealSourceSecrets } from '../../utils/secretBox.js';
|
|
2
3
|
export class Task extends Model {
|
|
3
4
|
id;
|
|
4
5
|
identifier;
|
|
@@ -11,6 +12,19 @@ export class Task extends Model {
|
|
|
11
12
|
source;
|
|
12
13
|
created_at;
|
|
13
14
|
updated_at;
|
|
15
|
+
// A secret variable's value is sealed in the table and plain everywhere else (see sealSourceSecrets).
|
|
16
|
+
$parseDatabaseJson(json) {
|
|
17
|
+
const parsed = super.$parseDatabaseJson(json);
|
|
18
|
+
if (typeof parsed.source === 'string')
|
|
19
|
+
parsed.source = openSourceSecrets(parsed.source);
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
$formatDatabaseJson(json) {
|
|
23
|
+
const formatted = super.$formatDatabaseJson(json);
|
|
24
|
+
if (typeof formatted.source === 'string')
|
|
25
|
+
formatted.source = sealSourceSecrets(formatted.source);
|
|
26
|
+
return formatted;
|
|
27
|
+
}
|
|
14
28
|
static get tableName() {
|
|
15
29
|
return 'task';
|
|
16
30
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Model } from 'objection';
|
|
1
|
+
import { Model, type Pojo } from 'objection';
|
|
2
2
|
import type { RevisionOrigin } from '../services/RevisionHistory.js';
|
|
3
3
|
export type { RevisionOrigin };
|
|
4
4
|
export declare class TaskRevision extends Model {
|
|
@@ -9,5 +9,7 @@ export declare class TaskRevision extends Model {
|
|
|
9
9
|
summary: string | null;
|
|
10
10
|
restored_from: number | null;
|
|
11
11
|
created_at: string;
|
|
12
|
+
$parseDatabaseJson(json: Pojo): Pojo;
|
|
13
|
+
$formatDatabaseJson(json: Pojo): Pojo;
|
|
12
14
|
static get tableName(): string;
|
|
13
15
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Model } from 'objection';
|
|
2
|
+
import { openSourceSecrets, sealSourceSecrets } from '../../utils/secretBox.js';
|
|
2
3
|
export class TaskRevision extends Model {
|
|
3
4
|
id;
|
|
4
5
|
task_id;
|
|
@@ -7,6 +8,19 @@ export class TaskRevision extends Model {
|
|
|
7
8
|
summary;
|
|
8
9
|
restored_from;
|
|
9
10
|
created_at;
|
|
11
|
+
// A secret variable's value is sealed in the table and plain everywhere else (see sealSourceSecrets).
|
|
12
|
+
$parseDatabaseJson(json) {
|
|
13
|
+
const parsed = super.$parseDatabaseJson(json);
|
|
14
|
+
if (typeof parsed.source === 'string')
|
|
15
|
+
parsed.source = openSourceSecrets(parsed.source);
|
|
16
|
+
return parsed;
|
|
17
|
+
}
|
|
18
|
+
$formatDatabaseJson(json) {
|
|
19
|
+
const formatted = super.$formatDatabaseJson(json);
|
|
20
|
+
if (typeof formatted.source === 'string')
|
|
21
|
+
formatted.source = sealSourceSecrets(formatted.source);
|
|
22
|
+
return formatted;
|
|
23
|
+
}
|
|
10
24
|
static get tableName() {
|
|
11
25
|
return 'task_revision';
|
|
12
26
|
}
|
|
@@ -2,6 +2,11 @@ import { Connection } from '../models/Connection.js';
|
|
|
2
2
|
export declare class ConnectionService {
|
|
3
3
|
static list(): Promise<Connection[]>;
|
|
4
4
|
static add(name: string, host: string, token: string): Promise<Connection>;
|
|
5
|
+
/**
|
|
6
|
+
* A connection is picked by its name, so names must be unique (ignoring case), and
|
|
7
|
+
* "local" always means this machine. Returns the trimmed name.
|
|
8
|
+
*/
|
|
9
|
+
private static checkName;
|
|
5
10
|
static remove(id: string): Promise<void>;
|
|
6
11
|
static getActiveId(): Promise<string | null>;
|
|
7
12
|
static getActive(): Promise<Connection | null>;
|
|
@@ -17,7 +17,24 @@ export class ConnectionService {
|
|
|
17
17
|
if (parsedHost.protocol !== 'ws:' && parsedHost.protocol !== 'wss:') {
|
|
18
18
|
throw new Error(`Invalid host: "${host}" must use the ws:// or wss:// protocol`);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
const cleanName = await ConnectionService.checkName(name);
|
|
21
|
+
return Connection.query().insertAndFetch({ id: generateIdentifier(), name: cleanName, host, token });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A connection is picked by its name, so names must be unique (ignoring case), and
|
|
25
|
+
* "local" always means this machine. Returns the trimmed name.
|
|
26
|
+
*/
|
|
27
|
+
static async checkName(name, exceptId) {
|
|
28
|
+
const clean = (name ?? '').trim();
|
|
29
|
+
if (!clean)
|
|
30
|
+
throw new Error('Give the connection a name.');
|
|
31
|
+
if (clean.toLowerCase() === 'local') {
|
|
32
|
+
throw new Error('"local" means this machine, so a connection can\'t be named that.');
|
|
33
|
+
}
|
|
34
|
+
const taken = (await Connection.query()).some((c) => c.id !== exceptId && c.name.trim().toLowerCase() === clean.toLowerCase());
|
|
35
|
+
if (taken)
|
|
36
|
+
throw new Error(`A connection named "${clean}" already exists. Pick another name.`);
|
|
37
|
+
return clean;
|
|
21
38
|
}
|
|
22
39
|
static async remove(id) {
|
|
23
40
|
const count = await Connection.query().deleteById(id);
|
|
@@ -38,6 +55,8 @@ export class ConnectionService {
|
|
|
38
55
|
return (await Connection.query().findById(id)) ?? null;
|
|
39
56
|
}
|
|
40
57
|
static async update(id, data) {
|
|
58
|
+
if (data.name !== undefined)
|
|
59
|
+
data = { ...data, name: await ConnectionService.checkName(data.name, id) };
|
|
41
60
|
return Connection.query().patchAndFetchById(id, data);
|
|
42
61
|
}
|
|
43
62
|
static async setActive(idOrName) {
|
|
@@ -50,9 +69,14 @@ export class ConnectionService {
|
|
|
50
69
|
await SettingsService.set(ACTIVE_KEY, byId.id);
|
|
51
70
|
return;
|
|
52
71
|
}
|
|
53
|
-
const
|
|
54
|
-
|
|
72
|
+
const wanted = idOrName.trim().toLowerCase();
|
|
73
|
+
const byName = (await Connection.query()).filter((c) => c.name.trim().toLowerCase() === wanted);
|
|
74
|
+
if (byName.length === 0)
|
|
55
75
|
throw new Error(`Connection "${idOrName}" not found`);
|
|
56
|
-
|
|
76
|
+
// Saved before names had to be unique: say which ones, rather than pick one.
|
|
77
|
+
if (byName.length > 1) {
|
|
78
|
+
throw new Error(`${byName.length} connections are named "${idOrName}". Use one's ID instead: ${byName.map((c) => c.id).join(', ')}`);
|
|
79
|
+
}
|
|
80
|
+
await SettingsService.set(ACTIVE_KEY, byName[0].id);
|
|
57
81
|
}
|
|
58
82
|
}
|
|
@@ -35,6 +35,12 @@ function assertValidHubTarget(type, target) {
|
|
|
35
35
|
throw new Error(`Unknown hub type "${type}". Use remote or local_folder.`);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
/** A token is only sent to a remote hub's own host: on a folder it would do nothing. */
|
|
39
|
+
function assertTokenFits(type, token) {
|
|
40
|
+
if (type === 'local_folder' && token?.trim()) {
|
|
41
|
+
throw new Error('A local_folder hub is read from disk, so it takes no token. Tokens are for remote hubs.');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
38
44
|
/**
|
|
39
45
|
* The official hub. Every Core has it from the first start, under this fixed id, so items
|
|
40
46
|
* installed from it keep the same hub link on every machine. Like the Local workspace it
|
|
@@ -81,6 +87,7 @@ export class HubService {
|
|
|
81
87
|
static async add(data) {
|
|
82
88
|
const target = normalizeHubTarget(data.type, data.target);
|
|
83
89
|
assertValidHubTarget(data.type, target);
|
|
90
|
+
assertTokenFits(data.type, data.token);
|
|
84
91
|
return Hub.query().insertAndFetch({
|
|
85
92
|
id: generateIdentifier(),
|
|
86
93
|
name: data.name,
|
|
@@ -94,15 +101,19 @@ export class HubService {
|
|
|
94
101
|
static async update(id, data) {
|
|
95
102
|
assertEditableHub(id, 'edited');
|
|
96
103
|
const patch = { ...data };
|
|
97
|
-
if (data.type !== undefined || data.target !== undefined) {
|
|
104
|
+
if (data.type !== undefined || data.target !== undefined || data.token) {
|
|
98
105
|
const current = await Hub.query().findById(id);
|
|
99
106
|
if (!current)
|
|
100
107
|
throw new Error(`Hub "${id}" not found`);
|
|
101
108
|
const type = data.type ?? current.type;
|
|
102
109
|
const target = normalizeHubTarget(type, data.target ?? current.target);
|
|
103
110
|
assertValidHubTarget(type, target);
|
|
111
|
+
assertTokenFits(type, data.token);
|
|
104
112
|
if (data.target !== undefined)
|
|
105
113
|
patch.target = target;
|
|
114
|
+
// A hub turned into a folder has nothing to send its old token to.
|
|
115
|
+
if (type === 'local_folder' && !('token' in patch))
|
|
116
|
+
patch.token = null;
|
|
106
117
|
}
|
|
107
118
|
if ('token' in patch)
|
|
108
119
|
patch.token = patch.token?.trim() || null;
|
|
@@ -52,7 +52,7 @@ export class PipelineRunnerService {
|
|
|
52
52
|
task_id: task.id,
|
|
53
53
|
identifier: generateIdentifier(),
|
|
54
54
|
status: 'completed',
|
|
55
|
-
source: task.source,
|
|
55
|
+
source: PipelineRunnerService.snapshotSource(task.source),
|
|
56
56
|
started_at: now,
|
|
57
57
|
finished_at: now,
|
|
58
58
|
metadata: {
|
|
@@ -12,6 +12,11 @@ export declare class PipelineService {
|
|
|
12
12
|
}): Promise<PipelineModel | undefined>;
|
|
13
13
|
/** Shallow-merges `patch` into a pipeline's metadata (a null value removes the key). */
|
|
14
14
|
static mergeMetadata(id: number, patch: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
15
|
+
/**
|
|
16
|
+
* A step with `cache:` whose result held a secret, so it wasn't cached: kept in the run's
|
|
17
|
+
* metadata (`cacheSkipped`, step identifiers) for the run page to say so.
|
|
18
|
+
*/
|
|
19
|
+
static noteCacheSkipped(id: number, stepIdentifier: string): Promise<void>;
|
|
15
20
|
/** Runs a Core restart would interrupt, including paused ones. */
|
|
16
21
|
static countActive(): Promise<number>;
|
|
17
22
|
/** Paused runs waiting for an approval decision, newest first. */
|
|
@@ -42,6 +47,14 @@ export declare class PipelineService {
|
|
|
42
47
|
* Returns the identifiers it ended.
|
|
43
48
|
*/
|
|
44
49
|
static failAbandoned(identifiers: string[], message: string): Promise<string[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Runs whose job was ended for them after a cancel they couldn't take in (a step busy
|
|
52
|
+
* on the CPU, say): they and their running steps end as canceled, saying who asked.
|
|
53
|
+
* Returns the identifiers it ended.
|
|
54
|
+
*/
|
|
55
|
+
static cancelAbandoned(identifiers: string[], canceledBy: string): Promise<string[]>;
|
|
56
|
+
/** Ends the given runs that still say running, and their running steps, with `status`. */
|
|
57
|
+
private static endAbandoned;
|
|
45
58
|
/**
|
|
46
59
|
* A resume that broke before its steps could run (or outside them): the run ends as
|
|
47
60
|
* failed with the error, like a failing step, instead of staying running. Only a run
|
|
@@ -56,6 +56,18 @@ export class PipelineService {
|
|
|
56
56
|
await PipelineModel.query().findById(id).patch({ metadata });
|
|
57
57
|
return metadata;
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* A step with `cache:` whose result held a secret, so it wasn't cached: kept in the run's
|
|
61
|
+
* metadata (`cacheSkipped`, step identifiers) for the run page to say so.
|
|
62
|
+
*/
|
|
63
|
+
static async noteCacheSkipped(id, stepIdentifier) {
|
|
64
|
+
const current = await PipelineModel.query().findById(id).select('metadata');
|
|
65
|
+
const skipped = current?.metadata?.cacheSkipped;
|
|
66
|
+
const list = Array.isArray(skipped) ? skipped : [];
|
|
67
|
+
if (list.includes(stepIdentifier))
|
|
68
|
+
return;
|
|
69
|
+
await PipelineService.mergeMetadata(id, { cacheSkipped: [...list, stepIdentifier] });
|
|
70
|
+
}
|
|
59
71
|
/** Runs a Core restart would interrupt, including paused ones. */
|
|
60
72
|
static async countActive() {
|
|
61
73
|
return await PipelineModel.query().whereIn('status', ['running', 'paused']).resultSize();
|
|
@@ -136,6 +148,23 @@ export class PipelineService {
|
|
|
136
148
|
* Returns the identifiers it ended.
|
|
137
149
|
*/
|
|
138
150
|
static async failAbandoned(identifiers, message) {
|
|
151
|
+
return PipelineService.endAbandoned(identifiers, 'failed', { reason: 'worker_exit', message }, message);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Runs whose job was ended for them after a cancel they couldn't take in (a step busy
|
|
155
|
+
* on the CPU, say): they and their running steps end as canceled, saying who asked.
|
|
156
|
+
* Returns the identifiers it ended.
|
|
157
|
+
*/
|
|
158
|
+
static async cancelAbandoned(identifiers, canceledBy) {
|
|
159
|
+
const message = canceledBy ? `Canceled by ${canceledBy}` : 'Canceled';
|
|
160
|
+
return PipelineService.endAbandoned(identifiers, 'canceled', {
|
|
161
|
+
reason: 'user_canceled',
|
|
162
|
+
message,
|
|
163
|
+
canceledBy,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/** Ends the given runs that still say running, and their running steps, with `status`. */
|
|
167
|
+
static async endAbandoned(identifiers, status, metadata, stepError) {
|
|
139
168
|
if (identifiers.length === 0)
|
|
140
169
|
return [];
|
|
141
170
|
const runs = await PipelineModel.query()
|
|
@@ -149,14 +178,18 @@ export class PipelineService {
|
|
|
149
178
|
await PipelineModel.query()
|
|
150
179
|
.whereIn('id', ids)
|
|
151
180
|
.where('status', 'running')
|
|
152
|
-
.patch({ status
|
|
181
|
+
.patch({ status, finished_at: now });
|
|
153
182
|
for (const id of ids) {
|
|
154
|
-
await PipelineService.mergeMetadata(id,
|
|
183
|
+
await PipelineService.mergeMetadata(id, metadata);
|
|
155
184
|
}
|
|
156
185
|
await PipelineActionModel.query()
|
|
157
186
|
.whereIn('pipeline_id', ids)
|
|
158
187
|
.where('status', 'running')
|
|
159
|
-
.patch({
|
|
188
|
+
.patch({
|
|
189
|
+
status,
|
|
190
|
+
...(stepError ? { error: stepError } : {}),
|
|
191
|
+
finished_at: now,
|
|
192
|
+
});
|
|
160
193
|
return runs.map((run) => run.identifier);
|
|
161
194
|
}
|
|
162
195
|
/**
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
import { isSealed, seal, unseal } from '../../utils/secretBox.js';
|
|
3
|
+
import { containsSecretText, redactSecretTexts, secretStringsOf } from '../../utils/secretText.js';
|
|
4
|
+
/**
|
|
5
|
+
* Once, for run history written before a step's record kept only what's shown: each step's
|
|
6
|
+
* filled-in input, result and error held the real values, secrets included. Every secret
|
|
7
|
+
* Core knows (the global secrets, and each run's sealed variable values) is replaced with the
|
|
8
|
+
* placeholder there, in run messages and in variable rows that weren't sealed; cached step
|
|
9
|
+
* results holding one are dropped. A secret that has since changed, and isn't kept anywhere
|
|
10
|
+
* any more, can't be recognised.
|
|
11
|
+
*/
|
|
12
|
+
const DONE_KEY = 'run_history_secrets_masked_v1';
|
|
13
|
+
const BATCH = 500;
|
|
14
|
+
const parseJson = (text) => {
|
|
15
|
+
if (text == null)
|
|
16
|
+
return text;
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(text);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return text;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/** A JSON column's text with the secrets replaced, or null when there's nothing to replace. */
|
|
25
|
+
function maskedJson(text, secrets) {
|
|
26
|
+
if (text == null || !containsSecretText(parseJson(text), secrets))
|
|
27
|
+
return null;
|
|
28
|
+
return JSON.stringify(redactSecretTexts(parseJson(text), secrets));
|
|
29
|
+
}
|
|
30
|
+
/** Which secrets were found and how many rows changed, for the log. */
|
|
31
|
+
export async function maskSecretsInRunHistory() {
|
|
32
|
+
const knex = Model.knex();
|
|
33
|
+
if (await knex('settings').where({ key: DONE_KEY }).first())
|
|
34
|
+
return { secrets: 0, changed: 0 };
|
|
35
|
+
const known = [];
|
|
36
|
+
for (const row of await knex('global_variable').where({ secret: true }).select('value')) {
|
|
37
|
+
if (row.value != null)
|
|
38
|
+
known.push(parseJson(unseal(row.value)));
|
|
39
|
+
}
|
|
40
|
+
for (const row of await knex('pipeline_variable').select('value')) {
|
|
41
|
+
if (isSealed(row.value))
|
|
42
|
+
known.push(parseJson(unseal(row.value)));
|
|
43
|
+
}
|
|
44
|
+
const secrets = secretStringsOf(known);
|
|
45
|
+
let changed = 0;
|
|
46
|
+
if (secrets.length) {
|
|
47
|
+
await knex.transaction(async (trx) => {
|
|
48
|
+
for (let lastId = 0;;) {
|
|
49
|
+
const rows = await trx('pipeline_action')
|
|
50
|
+
.where('id', '>', lastId)
|
|
51
|
+
.orderBy('id')
|
|
52
|
+
.limit(BATCH)
|
|
53
|
+
.select('id', 'params', 'result', 'error');
|
|
54
|
+
if (rows.length === 0)
|
|
55
|
+
break;
|
|
56
|
+
lastId = rows[rows.length - 1].id;
|
|
57
|
+
for (const row of rows) {
|
|
58
|
+
const params = maskedJson(row.params, secrets);
|
|
59
|
+
const result = maskedJson(row.result, secrets);
|
|
60
|
+
const error = row.error && containsSecretText(row.error, secrets) ? redactSecretTexts(row.error, secrets) : null;
|
|
61
|
+
if (params === null && result === null && error === null)
|
|
62
|
+
continue;
|
|
63
|
+
await trx('pipeline_action')
|
|
64
|
+
.where({ id: row.id })
|
|
65
|
+
.update({ ...(params !== null ? { params } : {}), ...(result !== null ? { result } : {}), ...(error !== null ? { error } : {}) });
|
|
66
|
+
changed++;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const row of await trx('pipeline').whereNotNull('metadata').select('id', 'metadata')) {
|
|
70
|
+
const metadata = maskedJson(row.metadata, secrets);
|
|
71
|
+
if (metadata === null)
|
|
72
|
+
continue;
|
|
73
|
+
await trx('pipeline').where({ id: row.id }).update({ metadata });
|
|
74
|
+
changed++;
|
|
75
|
+
}
|
|
76
|
+
// A variable a step filled with a secret, saved before such values were sealed.
|
|
77
|
+
for (const row of await trx('pipeline_variable').select('id', 'value')) {
|
|
78
|
+
if (row.value == null || isSealed(row.value) || !containsSecretText(parseJson(row.value), secrets))
|
|
79
|
+
continue;
|
|
80
|
+
await trx('pipeline_variable').where({ id: row.id }).update({ value: seal(row.value) });
|
|
81
|
+
changed++;
|
|
82
|
+
}
|
|
83
|
+
for (const row of await trx('cache_entries').select('key', 'value')) {
|
|
84
|
+
if (!containsSecretText(parseJson(row.value), secrets))
|
|
85
|
+
continue;
|
|
86
|
+
await trx('cache_entries').where({ key: row.key }).delete();
|
|
87
|
+
changed++;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
await knex('settings').insert({ key: DONE_KEY, value: '1' }).onConflict('key').merge();
|
|
92
|
+
// Overwritten rows stay readable in the file's free pages and write-ahead log until both are rewritten.
|
|
93
|
+
if (changed) {
|
|
94
|
+
await knex.raw('VACUUM');
|
|
95
|
+
await knex.raw('PRAGMA wal_checkpoint(TRUNCATE)');
|
|
96
|
+
}
|
|
97
|
+
return { secrets: secrets.length, changed };
|
|
98
|
+
}
|
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
* Each part runs once, for data written before it was encrypted. Secrets: global secrets, the
|
|
3
3
|
* secret values of past runs, and the token in old logs; finished runs lose them, ones that can
|
|
4
4
|
* still resume keep them sealed. Credentials: API keys and tokens in settings, hubs and remotes.
|
|
5
|
+
* Workflows: the values written into their secret variables, in workflows, their saved
|
|
6
|
+
* versions and the Trash.
|
|
5
7
|
*/
|
|
6
8
|
export declare function sealExistingSecrets(): Promise<void>;
|
|
@@ -3,9 +3,10 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { Pipeline } from '../../database/models/Pipeline.js';
|
|
5
5
|
import { SettingsService, isCredentialSetting } from '../services/SettingsService.js';
|
|
6
|
-
import { REDACTED_JSON, isSealed, redactSecretValues, seal } from '../../utils/secretBox.js';
|
|
6
|
+
import { REDACTED_JSON, isSealed, redactSecretValues, seal, sealSourceSecrets } from '../../utils/secretBox.js';
|
|
7
7
|
const DONE_KEY = 'secrets_sealed_v1';
|
|
8
8
|
const CREDENTIALS_DONE_KEY = 'credentials_sealed_v1';
|
|
9
|
+
const WORKFLOW_SECRETS_DONE_KEY = 'workflow_secrets_sealed_v1';
|
|
9
10
|
/** Core used to log its API token on every start. */
|
|
10
11
|
function scrubTokenFromLogs() {
|
|
11
12
|
const logs = path.join(os.homedir(), '.tipeline', 'logs');
|
|
@@ -25,15 +26,63 @@ function scrubTokenFromLogs() {
|
|
|
25
26
|
* Each part runs once, for data written before it was encrypted. Secrets: global secrets, the
|
|
26
27
|
* secret values of past runs, and the token in old logs; finished runs lose them, ones that can
|
|
27
28
|
* still resume keep them sealed. Credentials: API keys and tokens in settings, hubs and remotes.
|
|
29
|
+
* Workflows: the values written into their secret variables, in workflows, their saved
|
|
30
|
+
* versions and the Trash.
|
|
28
31
|
*/
|
|
29
32
|
export async function sealExistingSecrets() {
|
|
30
|
-
const changed = (await sealRunSecrets()) + (await sealCredentials());
|
|
33
|
+
const changed = (await sealRunSecrets()) + (await sealCredentials()) + (await sealWorkflowSecrets());
|
|
31
34
|
// Overwritten rows stay readable in the file's free pages and write-ahead log until both are rewritten.
|
|
32
35
|
if (changed) {
|
|
33
36
|
await Pipeline.knex().raw('VACUUM');
|
|
34
37
|
await Pipeline.knex().raw('PRAGMA wal_checkpoint(TRUNCATE)');
|
|
35
38
|
}
|
|
36
39
|
}
|
|
40
|
+
/** What the Task and TaskRevision models now seal on write, for rows written before they did. */
|
|
41
|
+
async function sealWorkflowSecrets() {
|
|
42
|
+
if (await SettingsService.get(WORKFLOW_SECRETS_DONE_KEY))
|
|
43
|
+
return 0;
|
|
44
|
+
let changed = 0;
|
|
45
|
+
await Pipeline.knex().transaction(async (trx) => {
|
|
46
|
+
for (const table of ['task', 'task_revision']) {
|
|
47
|
+
for (const row of await trx(table).select('id', 'source')) {
|
|
48
|
+
const sealed = sealSourceSecrets(row.source);
|
|
49
|
+
if (sealed === row.source)
|
|
50
|
+
continue;
|
|
51
|
+
await trx(table).where({ id: row.id }).update({ source: sealed });
|
|
52
|
+
changed++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// A trashed workflow is a snapshot of its row and versions, restored as it is.
|
|
56
|
+
for (const item of await trx('trash_item').where({ kind: 'task' }).select('id', 'data')) {
|
|
57
|
+
let data;
|
|
58
|
+
try {
|
|
59
|
+
data = JSON.parse(item.data);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
let touched = false;
|
|
65
|
+
const sealIn = (holder) => {
|
|
66
|
+
if (typeof holder?.source !== 'string')
|
|
67
|
+
return;
|
|
68
|
+
const sealed = sealSourceSecrets(holder.source);
|
|
69
|
+
if (sealed !== holder.source) {
|
|
70
|
+
holder.source = sealed;
|
|
71
|
+
touched = true;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
sealIn(data?.row);
|
|
75
|
+
for (const revision of data?.revisions ?? [])
|
|
76
|
+
sealIn(revision);
|
|
77
|
+
if (!touched)
|
|
78
|
+
continue;
|
|
79
|
+
await trx('trash_item').where({ id: item.id }).update({ data: JSON.stringify(data) });
|
|
80
|
+
changed++;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
await SettingsService.set(WORKFLOW_SECRETS_DONE_KEY, '1');
|
|
84
|
+
return changed;
|
|
85
|
+
}
|
|
37
86
|
async function sealCredentials() {
|
|
38
87
|
if (await SettingsService.get(CREDENTIALS_DONE_KEY))
|
|
39
88
|
return 0;
|
|
@@ -7,6 +7,7 @@ import { generateIdentifier } from '@tipeline/utils';
|
|
|
7
7
|
import { ProjectMembership, parseProjects, projectsSubquery } from '../../database/services/ProjectMembership.js';
|
|
8
8
|
import { AlertService } from '../../database/services/AlertService.js';
|
|
9
9
|
import { sourceHash } from '../../utils/workflowFingerprint.js';
|
|
10
|
+
import { openSourceSecrets } from '../../utils/secretBox.js';
|
|
10
11
|
const TASK_TAGS_SUBQUERY = `(
|
|
11
12
|
SELECT COALESCE(json_group_array(tag.label), '[]')
|
|
12
13
|
FROM task_tag
|
|
@@ -59,7 +60,8 @@ export class TaskService {
|
|
|
59
60
|
createdAt: row.created_at,
|
|
60
61
|
fileFingerprint: metadata?.fileFingerprint,
|
|
61
62
|
// null: not installed from a file (made in the builder, by the assistant, a copy, ...).
|
|
62
|
-
|
|
63
|
+
// Read straight from the table: the secrets are sealed there (see the Task model).
|
|
64
|
+
edited: installedSourceHash ? sourceHash(openSourceSecrets(row.source) ?? '') !== installedSourceHash : null,
|
|
63
65
|
};
|
|
64
66
|
});
|
|
65
67
|
}
|
|
@@ -177,6 +179,8 @@ export class TaskService {
|
|
|
177
179
|
return row
|
|
178
180
|
? {
|
|
179
181
|
...row,
|
|
182
|
+
// Read straight from the table: the secrets are sealed there (see the Task model).
|
|
183
|
+
source: openSourceSecrets(row.source),
|
|
180
184
|
tags: JSON.parse(row.tags),
|
|
181
185
|
projects: parseProjects(row.projects),
|
|
182
186
|
metadata: row.metadata ? JSON.parse(row.metadata) : row.metadata,
|
|
@@ -189,11 +193,12 @@ export class TaskService {
|
|
|
189
193
|
}
|
|
190
194
|
static async getByHubRef(hubId, hubTaskIdentifier) {
|
|
191
195
|
const knex = TaskModel.knex();
|
|
192
|
-
|
|
196
|
+
const row = await knex('task')
|
|
193
197
|
.innerJoin('task_hub_link as thl', 'thl.task_id', 'task.id')
|
|
194
198
|
.where({ 'thl.hub_id': hubId, 'thl.hub_task_identifier': hubTaskIdentifier })
|
|
195
199
|
.select('task.*', 'thl.hub_id', 'thl.hub_task_identifier', 'thl.hub_version', 'thl.hub_status', 'thl.auto_update')
|
|
196
200
|
.first();
|
|
201
|
+
return row ? { ...row, source: openSourceSecrets(row.source) } : row;
|
|
197
202
|
}
|
|
198
203
|
/** Every task installed from a given hub — used to detect ones whose catalog entry disappeared. */
|
|
199
204
|
static async getInstalledForHub(hubId) {
|
package/dist/engine/Core.d.ts
CHANGED
|
@@ -672,7 +672,10 @@ export default class Core {
|
|
|
672
672
|
private static addActionsIdentifiers;
|
|
673
673
|
/**
|
|
674
674
|
* Like addActionsIdentifiers but preserves existing identifiers — only assigns new ones
|
|
675
|
-
* to actions that don't already have one. Used by taskReload to keep stable
|
|
675
|
+
* to actions that don't already have one. Used by taskReload and saves to keep stable
|
|
676
|
+
* action references (run history, breakpoints). An empty identifier counts as missing, and
|
|
677
|
+
* so does one a step before it in the workflow already has (a pasted copy): a run keys its
|
|
678
|
+
* steps by identifier, and two the same collide.
|
|
676
679
|
*/
|
|
677
680
|
private static addActionsIdentifiersIfMissing;
|
|
678
681
|
static taskReload(identifier: string, path: string): Promise<import("../database/models/Task.js").Task | null | undefined>;
|
package/dist/engine/Core.js
CHANGED
|
@@ -325,6 +325,10 @@ export default class Core {
|
|
|
325
325
|
if (actionTypeErrors.length > 0) {
|
|
326
326
|
throw new Error(`task.validationFailed\n${actionTypeErrors.join('\n')}`);
|
|
327
327
|
}
|
|
328
|
+
// Steps typed or pasted in the code view come without identifiers; the ones they have are kept.
|
|
329
|
+
if (validatedTask.pipeline?.actions) {
|
|
330
|
+
validatedTask.pipeline.actions = this.addActionsIdentifiersIfMissing(validatedTask.pipeline.actions);
|
|
331
|
+
}
|
|
328
332
|
return await TaskService.updateSource(identifier, JSON.stringify(validatedTask));
|
|
329
333
|
}
|
|
330
334
|
/** Saved versions of a workflow, newest first, without their sources. */
|
|
@@ -1004,20 +1008,25 @@ export default class Core {
|
|
|
1004
1008
|
}
|
|
1005
1009
|
/**
|
|
1006
1010
|
* Like addActionsIdentifiers but preserves existing identifiers — only assigns new ones
|
|
1007
|
-
* to actions that don't already have one. Used by taskReload to keep stable
|
|
1011
|
+
* to actions that don't already have one. Used by taskReload and saves to keep stable
|
|
1012
|
+
* action references (run history, breakpoints). An empty identifier counts as missing, and
|
|
1013
|
+
* so does one a step before it in the workflow already has (a pasted copy): a run keys its
|
|
1014
|
+
* steps by identifier, and two the same collide.
|
|
1008
1015
|
*/
|
|
1009
|
-
static addActionsIdentifiersIfMissing(actions) {
|
|
1016
|
+
static addActionsIdentifiersIfMissing(actions, seen = new Set()) {
|
|
1010
1017
|
if (!Array.isArray(actions))
|
|
1011
1018
|
return actions;
|
|
1012
1019
|
return actions.map((action) => {
|
|
1020
|
+
const kept = typeof action?.identifier === 'string' && action.identifier !== '' && !seen.has(action.identifier);
|
|
1013
1021
|
const actionWithId = {
|
|
1014
1022
|
...action,
|
|
1015
|
-
identifier: action.identifier
|
|
1023
|
+
identifier: kept ? action.identifier : generateIdentifier(),
|
|
1016
1024
|
};
|
|
1025
|
+
seen.add(actionWithId.identifier);
|
|
1017
1026
|
if (actionWithId.params?.actions && Array.isArray(actionWithId.params.actions)) {
|
|
1018
1027
|
actionWithId.params = {
|
|
1019
1028
|
...actionWithId.params,
|
|
1020
|
-
actions: this.addActionsIdentifiersIfMissing(actionWithId.params.actions),
|
|
1029
|
+
actions: this.addActionsIdentifiersIfMissing(actionWithId.params.actions, seen),
|
|
1021
1030
|
};
|
|
1022
1031
|
}
|
|
1023
1032
|
return actionWithId;
|
|
@@ -1129,6 +1138,14 @@ export default class Core {
|
|
|
1129
1138
|
const pipeline = await PipelineService.getByIdentifierWithActions(pipelineIdentifier);
|
|
1130
1139
|
if (!pipeline)
|
|
1131
1140
|
return pipeline;
|
|
1141
|
+
// Steps with `cache:` whose result held a secret, so it wasn't cached (see Block).
|
|
1142
|
+
const skipped = pipeline.metadata?.cacheSkipped;
|
|
1143
|
+
if (Array.isArray(skipped) && Array.isArray(pipeline.actions)) {
|
|
1144
|
+
for (const action of pipeline.actions) {
|
|
1145
|
+
if (skipped.includes(action.identifier))
|
|
1146
|
+
action.cacheSkipped = 'secret';
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1132
1149
|
return Object.assign(pipeline, {
|
|
1133
1150
|
variables: await Core.pipelineVariableValues(pipeline),
|
|
1134
1151
|
// The runs its sub-workflow steps started, for the run page to nest and link them.
|
package/dist/engine/Server.js
CHANGED
|
@@ -40,6 +40,7 @@ import { TrashPurger } from './TrashPurger.js';
|
|
|
40
40
|
import { ApprovalTimeoutService } from './ApprovalTimeoutService.js';
|
|
41
41
|
import Core from './Core.js';
|
|
42
42
|
import { sealExistingSecrets } from '../database/services/SecretSweep.js';
|
|
43
|
+
import { maskSecretsInRunHistory } from '../database/services/RunHistorySecrets.js';
|
|
43
44
|
const WS_PORT = parseInt(process.env.TIPELINE_WS_PORT ?? '4000', 10);
|
|
44
45
|
const MCP_PORT = parseInt(process.env.TIPELINE_MCP_PORT ?? '4002', 10);
|
|
45
46
|
// This machine only, unless someone asks for more: both ports accept Core's full-access token.
|
|
@@ -90,6 +91,12 @@ process.on('uncaughtException', (err, origin) => {
|
|
|
90
91
|
await initializeDatabase();
|
|
91
92
|
fs.rmSync(newerDatabaseMarker(), { force: true });
|
|
92
93
|
await sealExistingSecrets().catch((err) => logSync('ERROR', 'Could not seal existing secrets:', err));
|
|
94
|
+
await maskSecretsInRunHistory()
|
|
95
|
+
.then(({ secrets, changed }) => {
|
|
96
|
+
if (changed)
|
|
97
|
+
logSync('LOG', `Masked ${secrets} known secret value(s) in ${changed} run history row(s)`);
|
|
98
|
+
})
|
|
99
|
+
.catch((err) => logSync('ERROR', 'Could not mask secrets in run history:', err));
|
|
93
100
|
await DatabaseManager.enableAutoVacuum();
|
|
94
101
|
await Core.init();
|
|
95
102
|
const tz = await SettingsService.get('timezone');
|