hammerkit 2.0.0-next.17 → 2.0.0-next.18
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/cache/backends/registry/registry-client.js +8 -2
- package/dist/docker/stream.js +15 -7
- package/dist/environment/replace-env-variables.js +1 -1
- package/dist/executer/execute-command.js +9 -15
- package/dist/optimizer/check-keys.js +15 -3
- package/dist/optimizer/get-work-cache-stats.js +19 -7
- package/dist/optimizer/work-task-cache-description.js +36 -7
- package/dist/planner/work-secret.js +4 -3
- package/dist/secrets/secret-catalog.js +7 -1
- package/dist/server/plan.js +22 -1
- package/dist/server/policy.js +14 -7
- package/dist/server/repo-access.js +4 -3
- package/dist/server/server-config.js +5 -4
- package/dist/server/server.js +23 -6
- package/dist/server/service-runs.js +42 -4
- package/dist/utils/line-splitter.js +52 -0
- package/package.json +1 -1
|
@@ -114,15 +114,21 @@ class RegistryClient {
|
|
|
114
114
|
// on some Node versions.
|
|
115
115
|
async request(method, urlOrPath, init = {}) {
|
|
116
116
|
const url = urlOrPath.startsWith('http') ? urlOrPath : this.url(urlOrPath);
|
|
117
|
+
// the credentials are the registry's: an upload location or a next page elsewhere (another
|
|
118
|
+
// host, another port, or http in place of https) gets none, as fetch does on a redirect
|
|
119
|
+
const own = new URL(url).origin === new URL(this.url('')).origin;
|
|
117
120
|
const send = () => fetch(url, {
|
|
118
121
|
method,
|
|
119
|
-
headers: {
|
|
122
|
+
headers: {
|
|
123
|
+
...(init.headers ?? {}),
|
|
124
|
+
...(own && this.authorization ? { authorization: this.authorization } : {}),
|
|
125
|
+
},
|
|
120
126
|
// BodyInit of Node's fetch, also when the dashboard checks these types with the DOM's
|
|
121
127
|
body: init.body?.(),
|
|
122
128
|
redirect: init.redirect ?? 'follow',
|
|
123
129
|
});
|
|
124
130
|
let response = await send();
|
|
125
|
-
if (response.status === 401 && (await this.authenticate(response.headers.get('www-authenticate')))) {
|
|
131
|
+
if (own && response.status === 401 && (await this.authenticate(response.headers.get('www-authenticate')))) {
|
|
126
132
|
await response.body?.cancel();
|
|
127
133
|
response = await send();
|
|
128
134
|
}
|
package/dist/docker/stream.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.logStream = exports.awaitStream = void 0;
|
|
4
|
-
const
|
|
4
|
+
const line_splitter_1 = require("../utils/line-splitter");
|
|
5
5
|
async function awaitStream(status, stream) {
|
|
6
6
|
return new Promise((resolve, reject) => {
|
|
7
7
|
logStream(status, stream);
|
|
@@ -12,15 +12,23 @@ async function awaitStream(status, stream) {
|
|
|
12
12
|
}
|
|
13
13
|
exports.awaitStream = awaitStream;
|
|
14
14
|
function logStream(status, stream) {
|
|
15
|
-
|
|
15
|
+
const stdout = writeLog(status, 'stdout');
|
|
16
|
+
const stderr = writeLog(status, 'stderr');
|
|
17
|
+
demuxStream(stream, (buffer) => stdout.write(buffer), (buffer) => stderr.write(buffer));
|
|
18
|
+
// what is left of a last line without a line feed
|
|
19
|
+
const end = () => {
|
|
20
|
+
stdout.end();
|
|
21
|
+
stderr.end();
|
|
22
|
+
};
|
|
23
|
+
const events = stream;
|
|
24
|
+
events.on('end', end);
|
|
25
|
+
events.on('close', end);
|
|
16
26
|
}
|
|
17
27
|
exports.logStream = logStream;
|
|
28
|
+
// A line docker split between two frames is logged once it ends, whole: a secret value in it
|
|
29
|
+
// is masked per line.
|
|
18
30
|
function writeLog(status, level) {
|
|
19
|
-
return
|
|
20
|
-
for (const log of (0, log_1.getLogs)(buffer)) {
|
|
21
|
-
status.console(level, log.endsWith('\n') ? log.substring(0, log.length - 1) : log);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
31
|
+
return (0, line_splitter_1.lineSplitter)((line) => status.console(level, line));
|
|
24
32
|
}
|
|
25
33
|
function demuxStream(stream, stdoutFn, stderrFn) {
|
|
26
34
|
let nextDataType = null;
|
|
@@ -7,7 +7,7 @@ const INTERPOLATION = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
|
|
|
7
7
|
// an empty string is set, as in a shell: CI providers leave many empty (a merge
|
|
8
8
|
// request id on a branch pipeline).
|
|
9
9
|
function resolveReference(name, environment, context, fromProcess) {
|
|
10
|
-
const processValue = environment.processEnvs[name];
|
|
10
|
+
const processValue = (environment.hosted?.buildFileEnvs ?? environment.processEnvs)[name];
|
|
11
11
|
if (processValue !== undefined && processValue !== null) {
|
|
12
12
|
fromProcess?.add(name);
|
|
13
13
|
return processValue;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.executeCommand = exports.processEnv = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const os_1 = require("os");
|
|
6
|
-
const
|
|
6
|
+
const line_splitter_1 = require("../utils/line-splitter");
|
|
7
7
|
const abort_1 = require("./abort");
|
|
8
8
|
const abort_event_1 = require("../utils/abort-event");
|
|
9
9
|
const environment_config_1 = require("../utils/environment-config");
|
|
@@ -43,25 +43,19 @@ async function executeCommand(status, abortSignal, cwd, command, envs, environme
|
|
|
43
43
|
// they would keep running and holding the output open
|
|
44
44
|
detached: !windows,
|
|
45
45
|
});
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
ps.stdout?.on('data',
|
|
51
|
-
|
|
52
|
-
status.console('stdout', log);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
ps.stderr?.on('data', async (data) => {
|
|
56
|
-
for (const log of (0, log_1.getLogs)(data)) {
|
|
57
|
-
status.console('stderr', log);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
46
|
+
// a line that two chunks split is logged once it ends, whole: a multi-byte character
|
|
47
|
+
// stays intact, and so does a secret value, which is masked per line
|
|
48
|
+
const stdout = (0, line_splitter_1.lineSplitter)((line) => status.console('stdout', line));
|
|
49
|
+
const stderr = (0, line_splitter_1.lineSplitter)((line) => status.console('stderr', line));
|
|
50
|
+
ps.stdout?.on('data', (data) => stdout.write(data));
|
|
51
|
+
ps.stderr?.on('data', (data) => stderr.write(data));
|
|
60
52
|
ps.on('error', (err) => {
|
|
61
53
|
reject(err);
|
|
62
54
|
});
|
|
63
55
|
ps.on('close', (code) => {
|
|
64
56
|
abortListener.close();
|
|
57
|
+
stdout.end();
|
|
58
|
+
stderr.end();
|
|
65
59
|
if (abortSignal.aborted) {
|
|
66
60
|
reject(new abort_1.AbortError());
|
|
67
61
|
return;
|
|
@@ -42,6 +42,18 @@ directory) {
|
|
|
42
42
|
}
|
|
43
43
|
exports.getCheckKeys = getCheckKeys;
|
|
44
44
|
// Every provider and account name resolves, to a definition nothing runs.
|
|
45
|
+
// A record that holds an entry under any name, as its own property: the catalog is looked up by
|
|
46
|
+
// own properties only.
|
|
47
|
+
function anyRecord(make) {
|
|
48
|
+
const entry = (name) => (typeof name === 'string' ? make(name) : undefined);
|
|
49
|
+
return new Proxy({}, {
|
|
50
|
+
get: (_target, name) => entry(name),
|
|
51
|
+
has: (_target, name) => typeof name === 'string',
|
|
52
|
+
getOwnPropertyDescriptor: (_target, name) => typeof name === 'string'
|
|
53
|
+
? { value: make(name), writable: false, enumerable: true, configurable: true }
|
|
54
|
+
: undefined,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
45
57
|
function anyCatalog() {
|
|
46
58
|
const provider = (name) => ({
|
|
47
59
|
name,
|
|
@@ -54,12 +66,12 @@ function anyCatalog() {
|
|
|
54
66
|
const account = (name) => ({
|
|
55
67
|
name,
|
|
56
68
|
default: false,
|
|
57
|
-
providers:
|
|
69
|
+
providers: anyRecord(() => ({ env: {} })),
|
|
58
70
|
declaredIn: 'the server',
|
|
59
71
|
});
|
|
60
72
|
return {
|
|
61
|
-
providers:
|
|
62
|
-
accounts:
|
|
73
|
+
providers: anyRecord(provider),
|
|
74
|
+
accounts: anyRecord(account),
|
|
63
75
|
explicitAccounts: true,
|
|
64
76
|
};
|
|
65
77
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stateKeyDigest = exports.getStateKey = exports.getWorkItemCheckoutStats = exports.getWorkItemCacheStats = exports.getWorkCacheStats = void 0;
|
|
3
|
+
exports.stateKeyDigest = exports.encodeStateEntries = exports.getStateKey = exports.getWorkItemCheckoutStats = exports.getWorkItemCacheStats = exports.getWorkCacheStats = void 0;
|
|
4
4
|
const calculate_checksum_1 = require("./calculate-checksum");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
@@ -39,9 +39,11 @@ async function visitPath(cwd, path, matcher, context, root) {
|
|
|
39
39
|
if (!matcher(path)) {
|
|
40
40
|
return { type: 'none' };
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
// `l` and the digest of its target, a kind of entry of its own: no checksum of a file
|
|
43
|
+
// starts with a letter past `f`
|
|
44
|
+
const checksum = `l${(0, crypto_1.createHash)('sha256')
|
|
43
45
|
.update(`link:${await (0, promises_1.readlink)(path)}`)
|
|
44
|
-
.digest('hex')
|
|
46
|
+
.digest('hex')}`;
|
|
45
47
|
return { type: 'file', key, lastModified: link.mtimeMs, checksum };
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -121,20 +123,30 @@ function dependencyOutputs(item) {
|
|
|
121
123
|
return [...outputs];
|
|
122
124
|
}
|
|
123
125
|
function getStateKey(stats, cacheMethod) {
|
|
124
|
-
const
|
|
126
|
+
const entries = [];
|
|
125
127
|
// Sorted: the walk follows the filesystem's listing order, which differs
|
|
126
128
|
// between machines (ext4 and overlayfs list in hash order).
|
|
127
129
|
for (const key of Object.keys(stats.files).sort()) {
|
|
128
130
|
if (cacheMethod === 'checksum') {
|
|
129
|
-
|
|
131
|
+
entries.push([key, stats.files[key].checksum]);
|
|
130
132
|
}
|
|
131
133
|
else if (cacheMethod === 'modify-date') {
|
|
132
|
-
|
|
134
|
+
entries.push([key, `${stats.files[key].lastModified}`]);
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
|
-
return stateKeyDigest(
|
|
137
|
+
return stateKeyDigest(encodeStateEntries(entries));
|
|
136
138
|
}
|
|
137
139
|
exports.getStateKey = getStateKey;
|
|
140
|
+
// The paths and values of a tree as one text that names no other tree. `path:value,...` as
|
|
141
|
+
// before while no path holds `:` or `,` (a value is hex digits or a date), so those keys stay
|
|
142
|
+
// what they were; else JSON after a NUL, which no path holds.
|
|
143
|
+
function encodeStateEntries(entries) {
|
|
144
|
+
if (entries.some(([path]) => /[:,]/.test(path))) {
|
|
145
|
+
return `\0${JSON.stringify(entries)}`;
|
|
146
|
+
}
|
|
147
|
+
return entries.map(([path, value]) => `${path}:${value}`).join(',');
|
|
148
|
+
}
|
|
149
|
+
exports.encodeStateEntries = encodeStateEntries;
|
|
138
150
|
// A state key is also the value of the `hammerkit.dev/state` label on Kubernetes, which
|
|
139
151
|
// takes at most 63 characters: the sha256 in base 36 has 50.
|
|
140
152
|
function stateKeyDigest(content) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.storedCacheDescription = exports.getWorkServiceCacheIdentity = exports.getWorkTaskCacheDescription = void 0;
|
|
3
|
+
exports.storedCacheDescription = exports.getWorkServiceCacheIdentity = exports.getSecretSources = exports.getWorkTaskCacheDescription = void 0;
|
|
4
4
|
const os_1 = require("os");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const replace_env_variables_1 = require("../environment/replace-env-variables");
|
|
@@ -24,6 +24,7 @@ function getWorkTaskCacheDescription(item) {
|
|
|
24
24
|
.filter((secret) => secret.cache)
|
|
25
25
|
.map((secret) => `${(0, work_secret_1.getPortableSecretName)(task.projectRoot, secret)}=${secret.digest()}`)
|
|
26
26
|
.sort();
|
|
27
|
+
const secretSources = getSecretSources(task.projectRoot, task.secrets);
|
|
27
28
|
return {
|
|
28
29
|
shell: task.shell ?? undefined,
|
|
29
30
|
platform: task.type === 'container-task' ? task.image : (0, os_1.platform)(),
|
|
@@ -44,11 +45,26 @@ function getWorkTaskCacheDescription(item) {
|
|
|
44
45
|
cwd: portable(task.cwd),
|
|
45
46
|
deps: item.deps.length > 0 ? item.deps.map((dep) => dep.id()).sort() : undefined,
|
|
46
47
|
secrets: cachedSecrets.length > 0 ? cachedSecrets : undefined,
|
|
48
|
+
secretSources: secretSources.length > 0 ? secretSources : undefined,
|
|
47
49
|
claimLayout: (0, claim_layout_1.hasPathsEndingAlike)(item) || (0, claim_layout_1.hasOutputsFlatteningAlike)(item) ? 2 : undefined,
|
|
48
50
|
needs: item.needs.length > 0 ? getNeedsIdentities(item) : undefined,
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
exports.getWorkTaskCacheDescription = getWorkTaskCacheDescription;
|
|
54
|
+
// The secrets without `cache: true`, by name and source: `NAME<env:VAR`, `NAME<gcp:ref as
|
|
55
|
+
// account`, `NAME<file` (a path of the machine, which differs between machines). Their values
|
|
56
|
+
// stay out of the key, as before: what a provider returns may change on every read.
|
|
57
|
+
function getSecretSources(projectRoot, secrets) {
|
|
58
|
+
return secrets
|
|
59
|
+
.filter((secret) => !secret.cache)
|
|
60
|
+
.map((secret) => {
|
|
61
|
+
const source = secret.source;
|
|
62
|
+
const from = source.type === 'file' ? 'file' : (0, work_secret_1.describeSecretSource)(secret);
|
|
63
|
+
return `${(0, work_secret_1.getPortableSecretName)(projectRoot, secret)}<${from}`;
|
|
64
|
+
})
|
|
65
|
+
.sort();
|
|
66
|
+
}
|
|
67
|
+
exports.getSecretSources = getSecretSources;
|
|
52
68
|
// `visiting` holds the services on the way here: services that need each other in a loop
|
|
53
69
|
// fail to plan (checkForLoop), the identity only has to come back to say so
|
|
54
70
|
function getNeedsIdentities(item, visiting = new Set()) {
|
|
@@ -78,6 +94,10 @@ function getWorkServiceCacheIdentity(item, visiting = new Set()) {
|
|
|
78
94
|
.filter((secret) => secret.cache)
|
|
79
95
|
.map((secret) => `${(0, work_secret_1.getPortableSecretName)(service.projectRoot, secret)}=${secret.digest()}`)
|
|
80
96
|
.sort(),
|
|
97
|
+
// left out when it reads none, so the identity of such a service stays what it was
|
|
98
|
+
...(service.secrets.some((secret) => !secret.cache)
|
|
99
|
+
? { secretSources: getSecretSources(service.projectRoot, service.secrets) }
|
|
100
|
+
: {}),
|
|
81
101
|
// as declared: arguments after -- of a run of the init leave the service as it is
|
|
82
102
|
init: service.init ? (0, work_cache_id_1.getDeclaredWorkTaskId)(service.init.task) : null,
|
|
83
103
|
}
|
|
@@ -96,16 +116,25 @@ exports.getWorkServiceCacheIdentity = getWorkServiceCacheIdentity;
|
|
|
96
116
|
// The form written to disk: description.json in a cache entry (pushed to remote
|
|
97
117
|
// backends, readable by everyone who can pull) and the local explain record.
|
|
98
118
|
// Env is where tokens get passed, so each value is stored as a digest; the task
|
|
99
|
-
// id is still hashed from the values themselves.
|
|
119
|
+
// id is still hashed from the values themselves. So are where its secrets come from: who may
|
|
120
|
+
// pull an entry need not know which secrets of which provider a task reads.
|
|
100
121
|
function storedCacheDescription(description) {
|
|
101
|
-
if (!description.envs) {
|
|
122
|
+
if (!description.envs && !description.secretSources) {
|
|
102
123
|
return description;
|
|
103
124
|
}
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
const digest = (value) => `sha256:${(0, crypto_1.createHash)('sha256').update(value).digest('hex')}`;
|
|
126
|
+
const stored = { ...description };
|
|
127
|
+
if (description.envs) {
|
|
128
|
+
const envs = {};
|
|
129
|
+
for (const [key, value] of Object.entries(description.envs)) {
|
|
130
|
+
envs[key] = digest(value);
|
|
131
|
+
}
|
|
132
|
+
stored.envs = envs;
|
|
133
|
+
}
|
|
134
|
+
if (description.secretSources) {
|
|
135
|
+
stored.secretSources = description.secretSources.map(digest);
|
|
107
136
|
}
|
|
108
|
-
return
|
|
137
|
+
return stored;
|
|
109
138
|
}
|
|
110
139
|
exports.storedCacheDescription = storedCacheDescription;
|
|
111
140
|
//# sourceMappingURL=work-task-cache-description.js.map
|
|
@@ -8,6 +8,7 @@ const normalize_path_1 = require("./utils/normalize-path");
|
|
|
8
8
|
const template_value_1 = require("./utils/template-value");
|
|
9
9
|
const portable_path_1 = require("./utils/portable-path");
|
|
10
10
|
const abort_1 = require("../executer/abort");
|
|
11
|
+
const secret_catalog_1 = require("../secrets/secret-catalog");
|
|
11
12
|
const provider_values_1 = require("../secrets/provider-values");
|
|
12
13
|
// Where the value comes from, for messages and for what makes a service
|
|
13
14
|
// different: never the value.
|
|
@@ -57,7 +58,7 @@ function parseSecretSource(secret, ref, cwd, envs, catalog, taskAccount, label)
|
|
|
57
58
|
if (kind === 'file') {
|
|
58
59
|
return { type: 'file', path: (0, normalize_path_1.normalizePath)(cwd, (0, os_1.homedir)(), (0, template_value_1.templateValue)(ref, envs)) };
|
|
59
60
|
}
|
|
60
|
-
const provider = catalog.providers
|
|
61
|
+
const provider = (0, secret_catalog_1.declared)(catalog.providers, kind);
|
|
61
62
|
if (!provider) {
|
|
62
63
|
const declared = Object.keys(catalog.providers);
|
|
63
64
|
throw new Error(`${label}: unknown secret provider ${kind}, ${declared.length > 0 ? `declared: ${declared.join(', ')}` : 'none is declared'}`);
|
|
@@ -74,11 +75,11 @@ function parseSecretSource(secret, ref, cwd, envs, catalog, taskAccount, label)
|
|
|
74
75
|
? `${label}: ${kind}:${providerRef} needs account: on the secret, a server uses neither a task's account nor a default`
|
|
75
76
|
: `${label}: ${kind}:${providerRef} needs an account, and none is named or marked default: true`);
|
|
76
77
|
}
|
|
77
|
-
const account = catalog.accounts
|
|
78
|
+
const account = (0, secret_catalog_1.declared)(catalog.accounts, accountName);
|
|
78
79
|
if (!account) {
|
|
79
80
|
throw new Error(`${label}: unknown secret account ${accountName}, declared: ${Object.keys(catalog.accounts).join(', ') || 'none'}`);
|
|
80
81
|
}
|
|
81
|
-
const credentials = account.providers
|
|
82
|
+
const credentials = (0, secret_catalog_1.declared)(account.providers, kind);
|
|
82
83
|
if (!credentials) {
|
|
83
84
|
throw new Error(`${label}: account ${accountName} has no credentials for provider ${kind}`);
|
|
84
85
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectSecretCatalog = exports.emptySecretCatalog = void 0;
|
|
3
|
+
exports.collectSecretCatalog = exports.emptySecretCatalog = exports.declared = void 0;
|
|
4
4
|
const merge_environment_variables_1 = require("../environment/merge-environment-variables");
|
|
5
5
|
const replace_env_variables_1 = require("../environment/replace-env-variables");
|
|
6
6
|
const units_1 = require("../utils/units");
|
|
7
7
|
const DEFAULT_TIMEOUT = '30s';
|
|
8
|
+
// What a record of the catalog holds under a name a build file or a config gives, only when it
|
|
9
|
+
// was declared there: `constructor` or `toString` is no provider or account of any catalog.
|
|
10
|
+
function declared(record, name) {
|
|
11
|
+
return Object.prototype.hasOwnProperty.call(record, name) ? record[name] : undefined;
|
|
12
|
+
}
|
|
13
|
+
exports.declared = declared;
|
|
8
14
|
function emptySecretCatalog() {
|
|
9
15
|
return { providers: {}, accounts: {} };
|
|
10
16
|
}
|
package/dist/server/plan.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inspectBundle = exports.planBundle = exports.getCredentialReads = exports.PLAIN_SERVER_ENVS = exports.DefinitionError = void 0;
|
|
3
|
+
exports.inspectBundle = exports.planBundle = exports.getCredentialReads = exports.withSymbolicValues = exports.PLAIN_SERVER_ENVS = exports.DefinitionError = void 0;
|
|
4
4
|
const promises_1 = require("fs/promises");
|
|
5
5
|
const os_1 = require("os");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -25,6 +25,17 @@ exports.DefinitionError = DefinitionError;
|
|
|
25
25
|
// Variables of a server that hold no credential (FR-008): a task may read these and
|
|
26
26
|
// still take arguments, or reach any network. The ones of the run's source are set for each run.
|
|
27
27
|
exports.PLAIN_SERVER_ENVS = ['PATH', 'HOME', 'CI', ...run_source_envs_1.RUN_SOURCE_ENVS];
|
|
28
|
+
// The environment of runs as a build file is read before anybody runs it (a publish, a
|
|
29
|
+
// proposal, POST /v1/definitions/plan): each variable but the plain ones stands for its name,
|
|
30
|
+
// `${NAME}`. What the server answers about a build file, a description or an image that reads
|
|
31
|
+
// `$NAME` included, then never holds a value a run would see. The tasks of a run read the values.
|
|
32
|
+
function withSymbolicValues(processEnvs) {
|
|
33
|
+
return Object.fromEntries(Object.entries(processEnvs).map(([name, value]) => [
|
|
34
|
+
name,
|
|
35
|
+
value === undefined || exports.PLAIN_SERVER_ENVS.includes(name.toUpperCase()) ? value : `\${${name}}`,
|
|
36
|
+
]));
|
|
37
|
+
}
|
|
38
|
+
exports.withSymbolicValues = withSymbolicValues;
|
|
28
39
|
// What an item holds that its command must not hand out: its secrets, and the variables
|
|
29
40
|
// of the server its `envs` read, but the plain ones.
|
|
30
41
|
function getCredentialReads(item) {
|
|
@@ -256,6 +267,15 @@ function findItemPolicyProblems(item, policy, root) {
|
|
|
256
267
|
problems.push(`${item.name}: volume ${volume.name} is not a volume name, a path of the server can't be mounted`);
|
|
257
268
|
}
|
|
258
269
|
}
|
|
270
|
+
if (policy.readableEnvs) {
|
|
271
|
+
const allowed = policy.readableEnvs;
|
|
272
|
+
const refusedEnvs = ('envs' in data ? data.envs.processNames ?? [] : []).filter((name) => !exports.PLAIN_SERVER_ENVS.includes(name.toUpperCase()) && !allowed.includes(name));
|
|
273
|
+
if (refusedEnvs.length > 0) {
|
|
274
|
+
problems.push(`${item.name}: reads ${refusedEnvs
|
|
275
|
+
.map((name) => `$${name}`)
|
|
276
|
+
.join(', ')} of the server, which it does not list in ${policy.envsFrom ?? 'runs.env.allow'}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
259
279
|
for (const secret of secretsOf(item)) {
|
|
260
280
|
const source = secret.source;
|
|
261
281
|
if (policy.backend === 'kubernetes' && source.type === 'provider') {
|
|
@@ -341,6 +361,7 @@ function toPlan(root, item) {
|
|
|
341
361
|
deps: item.deps.map((dep) => dep.name).sort(),
|
|
342
362
|
// by their names in the plan, not the names the task reaches them at (`postgres` of an include)
|
|
343
363
|
needs: item.needs.map((need) => need.service.name).sort(),
|
|
364
|
+
...((0, work_service_1.isContainerWorkService)(data) && data.init ? { init: data.init.task.name } : {}),
|
|
344
365
|
accounts,
|
|
345
366
|
secrets,
|
|
346
367
|
serverEnvs: 'envs' in data ? data.envs.processNames ?? [] : [],
|
package/dist/server/policy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decideRun = exports.sandboxRepos = exports.decideSandbox = exports.sandboxPushBranches = exports.sandboxBranchType = exports.endpointLevel = exports.getGrant = exports.usedAccounts = exports.mayYank = exports.canUse = exports.maySeeDefinitions = exports.mayPublish = exports.mayPropose = exports.mayReadChecks = exports.mayRun = exports.matches = exports.subjectName = void 0;
|
|
3
|
+
exports.decideRun = exports.sandboxRepos = exports.decideSandbox = exports.sandboxPushBranches = exports.sandboxBranchType = exports.endpointLevel = exports.getGrant = exports.usedAccounts = exports.mayYank = exports.accountLevel = exports.canUse = exports.maySeeDefinitions = exports.mayPublish = exports.mayPropose = exports.mayReadChecks = exports.mayRun = exports.matches = exports.subjectName = void 0;
|
|
4
4
|
const repo_1 = require("./repo");
|
|
5
5
|
const BUILDS_ORDER = ['run', 'propose', 'publish'];
|
|
6
6
|
// The name an entitlement gives a subject, for the pages to name its runs by when its tokens
|
|
@@ -47,9 +47,15 @@ function maySeeDefinitions(grant) {
|
|
|
47
47
|
exports.maySeeDefinitions = maySeeDefinitions;
|
|
48
48
|
// `use` includes deciding about the runs others request on the account.
|
|
49
49
|
function canUse(grant, account) {
|
|
50
|
-
return grant
|
|
50
|
+
return accountLevel(grant, account) === 'use';
|
|
51
51
|
}
|
|
52
52
|
exports.canUse = canUse;
|
|
53
|
+
// The level the caller has for an account, only when an entitlement names it: an account
|
|
54
|
+
// called `constructor` or `toString` is not found on the prototype of the record.
|
|
55
|
+
function accountLevel(grant, account) {
|
|
56
|
+
return Object.prototype.hasOwnProperty.call(grant.accounts, account) ? grant.accounts[account] : undefined;
|
|
57
|
+
}
|
|
58
|
+
exports.accountLevel = accountLevel;
|
|
53
59
|
// Pulling a version back is a safe thing to do, so it is open to who publishes the build
|
|
54
60
|
// file, and to who uses an account the version works with: they are the ones who
|
|
55
61
|
// answer for what runs as it.
|
|
@@ -58,13 +64,14 @@ function mayYank(grant, version) {
|
|
|
58
64
|
}
|
|
59
65
|
exports.mayYank = mayYank;
|
|
60
66
|
function usedAccounts(grant) {
|
|
61
|
-
return Object.keys(grant.accounts).filter((account) => grant
|
|
67
|
+
return Object.keys(grant.accounts).filter((account) => canUse(grant, account));
|
|
62
68
|
}
|
|
63
69
|
exports.usedAccounts = usedAccounts;
|
|
64
70
|
// Default deny: a caller without a matching entitlement gets nothing.
|
|
65
71
|
function getGrant(entitlements, principal) {
|
|
66
72
|
const matched = [];
|
|
67
|
-
|
|
73
|
+
// no prototype: an account named like one of its properties (`__proto__`) is a key like any other
|
|
74
|
+
const accounts = Object.create(null);
|
|
68
75
|
const repos = [];
|
|
69
76
|
const sandboxes = [];
|
|
70
77
|
const endpoints = [];
|
|
@@ -79,7 +86,7 @@ function getGrant(entitlements, principal) {
|
|
|
79
86
|
checks = checks || entitlement.checks === 'read';
|
|
80
87
|
observe = observe || entitlement.observe === true;
|
|
81
88
|
for (const [account, level] of Object.entries(entitlement.accounts)) {
|
|
82
|
-
if (accounts
|
|
89
|
+
if (accountLevel({ accounts }, account) !== 'use') {
|
|
83
90
|
accounts[account] = level;
|
|
84
91
|
}
|
|
85
92
|
}
|
|
@@ -233,11 +240,11 @@ function decideRun(input) {
|
|
|
233
240
|
}
|
|
234
241
|
const request = [];
|
|
235
242
|
for (const account of accounts) {
|
|
236
|
-
const level = grant
|
|
243
|
+
const level = accountLevel(grant, account);
|
|
237
244
|
if (level === undefined) {
|
|
238
245
|
return { type: 'refuse', status: 403, error: `you may not use the account ${account}, it needs use or request` };
|
|
239
246
|
}
|
|
240
|
-
const rules = catalog[account];
|
|
247
|
+
const rules = Object.prototype.hasOwnProperty.call(catalog, account) ? catalog[account] : undefined;
|
|
241
248
|
// a sandbox holds changes nobody reviewed: an account takes its runs only when it says so
|
|
242
249
|
const sources = rules?.source ?? ['ref', 'upload'];
|
|
243
250
|
if (!sources.includes(source.type)) {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RepoAccess = void 0;
|
|
4
4
|
const redact_1 = require("../utils/redact");
|
|
5
5
|
const provider_values_1 = require("../secrets/provider-values");
|
|
6
|
+
const secret_catalog_1 = require("../secrets/secret-catalog");
|
|
6
7
|
const git_checkout_1 = require("./git-checkout");
|
|
7
8
|
const repo_1 = require("./repo");
|
|
8
9
|
// A token is read again after this long, so a short-lived one (a GitHub App
|
|
@@ -119,9 +120,9 @@ class RepoAccess {
|
|
|
119
120
|
const catalog = this.environment.hosted?.catalog;
|
|
120
121
|
const kind = secret.from.substring(0, secret.from.indexOf(':'));
|
|
121
122
|
const ref = secret.from.substring(secret.from.indexOf(':') + 1);
|
|
122
|
-
const provider = catalog.providers
|
|
123
|
-
const account = catalog.accounts
|
|
124
|
-
const credentials = account
|
|
123
|
+
const provider = (0, secret_catalog_1.declared)(catalog.providers, kind);
|
|
124
|
+
const account = (0, secret_catalog_1.declared)(catalog.accounts, secret.account);
|
|
125
|
+
const credentials = account ? (0, secret_catalog_1.declared)(account.providers, kind) : undefined;
|
|
125
126
|
if (!provider || !credentials) {
|
|
126
127
|
throw new Error(`the source credential ${secret.from} as ${secret.account} is not defined`);
|
|
127
128
|
}
|
|
@@ -594,8 +594,9 @@ exports.serverConfigSchema = zod_1.z
|
|
|
594
594
|
// the most open network a task or service of a run on a sandbox gets, written as
|
|
595
595
|
// a task's `network`: only the services it needs by default
|
|
596
596
|
network: network_schema_1.networkSchema.default('none'),
|
|
597
|
-
// the variables of `runs.env.allow` an `env:` secret
|
|
598
|
-
//
|
|
597
|
+
// the variables of runs (`runs.env.allow` and `runs.env.set`) an `env:` secret and the
|
|
598
|
+
// `envs` of a build file of a run on a sandbox may read, besides PATH, HOME and CI:
|
|
599
|
+
// none by default, a sandbox holds code nobody reviewed
|
|
599
600
|
env: zod_1.z
|
|
600
601
|
.object({ allow: zod_1.z.array(zod_1.z.string().regex(/^[A-Za-z_][A-Za-z0-9_()]*$/)).default([]) })
|
|
601
602
|
.strict()
|
|
@@ -788,11 +789,11 @@ exports.serverConfigSchema = zod_1.z
|
|
|
788
789
|
});
|
|
789
790
|
}
|
|
790
791
|
config.sandboxes.env.allow.forEach((name, index) => {
|
|
791
|
-
if (!config.runs.env.allow.includes(name)) {
|
|
792
|
+
if (!config.runs.env.allow.includes(name) && !Object.prototype.hasOwnProperty.call(config.runs.env.set, name)) {
|
|
792
793
|
ctx.addIssue({
|
|
793
794
|
code: zod_1.z.ZodIssueCode.custom,
|
|
794
795
|
path: ['sandboxes', 'env', 'allow', index],
|
|
795
|
-
message: `${name} is not in runs.env.allow, no run can read it`,
|
|
796
|
+
message: `${name} is not in runs.env.allow or runs.env.set, no run can read it`,
|
|
796
797
|
});
|
|
797
798
|
}
|
|
798
799
|
});
|
package/dist/server/server.js
CHANGED
|
@@ -38,6 +38,7 @@ const sandbox_storage_1 = require("./sandbox-storage");
|
|
|
38
38
|
const kubernetes_sandbox_storage_1 = require("./kubernetes-sandbox-storage");
|
|
39
39
|
const sandbox_docker_1 = require("./sandbox-docker");
|
|
40
40
|
const sandboxes_api_1 = require("./sandboxes-api");
|
|
41
|
+
const plan_1 = require("./plan");
|
|
41
42
|
const endpoints_1 = require("./endpoints");
|
|
42
43
|
const service_runs_1 = require("./service-runs");
|
|
43
44
|
const units_1 = require("../utils/units");
|
|
@@ -152,7 +153,7 @@ async function handleRuns(config, registry, definitions, sources, sandboxes, pla
|
|
|
152
153
|
const grant = (0, policy_1.getGrant)(config.entitlements, principal);
|
|
153
154
|
const run = registry.cancel(principal, id, accountsOf(config, principal), (up) => (0, service_runs_1.mayPublishEndpoints)(grant, up));
|
|
154
155
|
log(`cancel iss=${principal.iss} sub=${principal.sub} run=${id} found=${Boolean(run)}`);
|
|
155
|
-
run ? (0, http_2.send)(res, 200,
|
|
156
|
+
run ? (0, http_2.send)(res, 200, answerRun(config, principal, run)) : (0, http_2.send)(res, 404, { error: 'not found' });
|
|
156
157
|
}
|
|
157
158
|
else if (action === 'extend') {
|
|
158
159
|
if (method !== 'POST') {
|
|
@@ -180,7 +181,7 @@ async function handleRuns(config, registry, definitions, sources, sandboxes, pla
|
|
|
180
181
|
(0, http_2.send)(res, 409, { error: result.reason });
|
|
181
182
|
}
|
|
182
183
|
else {
|
|
183
|
-
(0, http_2.send)(res, 200,
|
|
184
|
+
(0, http_2.send)(res, 200, answerRun(config, principal, result.run));
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
else if (method !== 'GET') {
|
|
@@ -268,9 +269,18 @@ async function extendRun(config, registry, log, principal, id, req, res) {
|
|
|
268
269
|
(0, http_2.send)(res, 409, { error: `the run is ${result.state}, only a service run that is up can be extended` });
|
|
269
270
|
}
|
|
270
271
|
else {
|
|
271
|
-
(0, http_2.send)(res, 200,
|
|
272
|
+
(0, http_2.send)(res, 200, answerRun(config, principal, result.run));
|
|
272
273
|
}
|
|
273
274
|
}
|
|
275
|
+
// What a stop, an extend or a wake answers: the run whole for who may read it (its owner, who
|
|
276
|
+
// decides about it, `observe`), else what the list shows of it. Who may only open or publish
|
|
277
|
+
// endpoints of its repository is told how it stands, not its arguments, plan or log.
|
|
278
|
+
function answerRun(config, principal, run) {
|
|
279
|
+
const viewer = (0, overview_1.getViewer)(config, principal);
|
|
280
|
+
return (0, overview_1.mayRead)(viewer, run)
|
|
281
|
+
? toRunResponse(run, undefined, !(0, overview_1.owns)(viewer, run), viewer.nameOf)
|
|
282
|
+
: (0, overview_1.toListedRun)(viewer, run);
|
|
283
|
+
}
|
|
274
284
|
// Why the owner of a service run that sleeps may no longer run it, with the entitlements of
|
|
275
285
|
// the moment: a wake is started by who opens an endpoint, but runs as the owner, as a new
|
|
276
286
|
// run of theirs would.
|
|
@@ -816,9 +826,14 @@ async function startServer(config, environment, options = {}) {
|
|
|
816
826
|
},
|
|
817
827
|
};
|
|
818
828
|
const storage = config.storage.directory ?? (0, path_1.join)((0, get_cache_directory_1.getHammerkitDirectory)(), 'server');
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
829
|
+
// a build file nobody ran yet is read with the names of the variables, not their values
|
|
830
|
+
const definitions = new definitions_1.DefinitionStore((0, path_1.join)(storage, 'definitions'), {
|
|
831
|
+
...planning.environment,
|
|
832
|
+
hosted: {
|
|
833
|
+
...planning.environment.hosted,
|
|
834
|
+
buildFileEnvs: (0, plan_1.withSymbolicValues)(planning.environment.processEnvs),
|
|
835
|
+
},
|
|
836
|
+
}, { policy: planning.policy });
|
|
822
837
|
await definitions.load();
|
|
823
838
|
const repos = new repo_access_1.RepoAccess(config, planning.environment, options.repos);
|
|
824
839
|
const sandboxRuntimes = (0, server_config_1.getSandboxRuntimes)(config);
|
|
@@ -847,6 +862,8 @@ async function startServer(config, environment, options = {}) {
|
|
|
847
862
|
...planning.policy,
|
|
848
863
|
envs: config.sandboxes.env.allow,
|
|
849
864
|
envsFrom: 'sandboxes.env.allow',
|
|
865
|
+
// and what its build files read of the run's variables, `$NAME` in its `envs`
|
|
866
|
+
readableEnvs: config.sandboxes.env.allow,
|
|
850
867
|
runtimes: sandboxRuntimes,
|
|
851
868
|
capabilities: config.sandboxes.capabilities,
|
|
852
869
|
capabilitiesFrom: 'sandboxes.capabilities',
|
|
@@ -38,7 +38,9 @@ function containerPorts(plan) {
|
|
|
38
38
|
* Why the endpoints of a service run can't be published, or null. Each is a port its
|
|
39
39
|
* service declares, of a service the run starts. Under a `runs.secretNetwork` below `open`
|
|
40
40
|
* a service behind an endpoint may not read a secret or a credential of the server: a page
|
|
41
|
-
* is a way out that no mask of the log covers.
|
|
41
|
+
* is a way out that no mask of the log covers. Nor may what it is made from or talks to: a
|
|
42
|
+
* task it depends on (its init task too) can leave a value in a file the service serves,
|
|
43
|
+
* and a service it needs can hand one over the connection it answers on.
|
|
42
44
|
*/
|
|
43
45
|
function refuseEndpoints(request, plan, secretNetworkOpen) {
|
|
44
46
|
for (const endpoint of request.endpoints) {
|
|
@@ -50,14 +52,50 @@ function refuseEndpoints(request, plan, secretNetworkOpen) {
|
|
|
50
52
|
const ports = containerPorts(item);
|
|
51
53
|
return `${endpoint.service} has no port ${endpoint.port}${ports.length > 0 ? `, its ports are ${ports.join(', ')}` : ', it declares none'}`;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (secretNetworkOpen) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
for (const { name, path } of reachedFrom(endpoint.service, plan)) {
|
|
59
|
+
const reads = (0, plan_1.getCredentialReads)(plan[name]);
|
|
60
|
+
if (reads.length === 0) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const what = reads.join(', ');
|
|
64
|
+
if (path.length === 0) {
|
|
65
|
+
return `${name} reads ${what}, it can not be behind an endpoint on this server (runs.secretNetwork): a page could show it`;
|
|
66
|
+
}
|
|
67
|
+
// the way from the service to what reads it: `web needs api, which needs vault`
|
|
68
|
+
const way = path.map((step, index) => `${index === 0 ? '' : ', which '}${step.relation} ${step.name}`).join('');
|
|
69
|
+
return (`${endpoint.service} ${way}, which reads ${what}: ` +
|
|
70
|
+
'it can not be behind an endpoint on this server (runs.secretNetwork), a page could show it');
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
73
|
return null;
|
|
59
74
|
}
|
|
60
75
|
exports.refuseEndpoints = refuseEndpoints;
|
|
76
|
+
function reachedFrom(service, plan) {
|
|
77
|
+
if (!plan[service]) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
const reached = [{ name: service, path: [] }];
|
|
81
|
+
const seen = new Set([service]);
|
|
82
|
+
for (let index = 0; index < reached.length; index++) {
|
|
83
|
+
const { name, path } = reached[index];
|
|
84
|
+
const item = plan[name];
|
|
85
|
+
const next = [
|
|
86
|
+
...(item.init ? [{ relation: 'is initialized by', name: item.init }] : []),
|
|
87
|
+
...(item.deps ?? []).map((dep) => ({ relation: 'depends on', name: dep })),
|
|
88
|
+
...(item.needs ?? []).map((need) => ({ relation: 'needs', name: need })),
|
|
89
|
+
];
|
|
90
|
+
for (const step of next) {
|
|
91
|
+
if (plan[step.name] && !seen.has(step.name)) {
|
|
92
|
+
seen.add(step.name);
|
|
93
|
+
reached.push({ name: step.name, path: [...path, step] });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return reached;
|
|
98
|
+
}
|
|
61
99
|
function toRunEndpoints(endpoints, hosts, url) {
|
|
62
100
|
return endpoints.map((endpoint, index) => ({
|
|
63
101
|
service: endpoint.service,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lineSplitter = exports.MAX_LINE_CHARS = void 0;
|
|
4
|
+
const string_decoder_1 = require("string_decoder");
|
|
5
|
+
// The most of a line that is held back for its end: a longer one is passed on in parts.
|
|
6
|
+
exports.MAX_LINE_CHARS = 64 * 1024;
|
|
7
|
+
/**
|
|
8
|
+
* The lines of output that arrives in chunks, split where getLogs splits a chunk: at a line
|
|
9
|
+
* feed, with a CR before it. A line that two chunks (or two frames of docker) split is passed
|
|
10
|
+
* on whole once it ends, so the mask of the secrets of a run (SecretRegistry.redact, which
|
|
11
|
+
* works per line) covers a value that was split between them. Empty lines are left out, as
|
|
12
|
+
* getLogs does. A line of more than `maxChars` is passed on in parts of that length.
|
|
13
|
+
*/
|
|
14
|
+
function lineSplitter(onLine, maxChars = exports.MAX_LINE_CHARS) {
|
|
15
|
+
// a character split between two chunks stays whole
|
|
16
|
+
const decoder = new string_decoder_1.StringDecoder('utf8');
|
|
17
|
+
let pending = '';
|
|
18
|
+
const take = (text) => {
|
|
19
|
+
const lines = (pending + text).split(/\r?\n/);
|
|
20
|
+
pending = lines.pop() ?? '';
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
if (line) {
|
|
23
|
+
onLine(line);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
while (pending.length > maxChars) {
|
|
27
|
+
onLine(pending.slice(0, maxChars));
|
|
28
|
+
pending = pending.slice(maxChars);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
let ended = false;
|
|
32
|
+
return {
|
|
33
|
+
write(chunk) {
|
|
34
|
+
if (!ended) {
|
|
35
|
+
take(typeof chunk === 'string' ? chunk : decoder.write(chunk));
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
end() {
|
|
39
|
+
if (ended) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
ended = true;
|
|
43
|
+
take(decoder.end());
|
|
44
|
+
if (pending) {
|
|
45
|
+
onLine(pending);
|
|
46
|
+
pending = '';
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.lineSplitter = lineSplitter;
|
|
52
|
+
//# sourceMappingURL=line-splitter.js.map
|
package/package.json
CHANGED