hammerkit 2.0.0-next.16 → 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/item-network.js +51 -18
- 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/kubernetes/ensure-persistent-data.js +22 -7
- package/dist/kubernetes/network-gate.js +74 -11
- package/dist/kubernetes/network-policy.js +32 -10
- package/dist/kubernetes/remove-stale-items.js +15 -2
- package/dist/kubernetes/restore-kubernetes-data.js +3 -2
- package/dist/kubernetes/sandbox-runner.js +3 -4
- package/dist/kubernetes/store-kubernetes-data.js +3 -2
- package/dist/kubernetes/transfer-tools.js +66 -0
- 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-runtime-docker.js +28 -46
- package/dist/planner/work-secret.js +4 -3
- package/dist/secrets/secret-catalog.js +7 -1
- package/dist/server/kubernetes-backend.js +16 -0
- 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/run-worker.js +7 -2
- package/dist/server/server-config.js +14 -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
|
@@ -16,6 +16,7 @@ const container_resources_1 = require("./container-resources");
|
|
|
16
16
|
const job_placement_1 = require("./job-placement");
|
|
17
17
|
const network_policy_1 = require("./network-policy");
|
|
18
18
|
const resources_1 = require("./resources");
|
|
19
|
+
const transfer_tools_1 = require("./transfer-tools");
|
|
19
20
|
const volumes_1 = require("./volumes");
|
|
20
21
|
/**
|
|
21
22
|
* The runner of a sandbox: one pod that the commands of a run on the sandbox are exec'd
|
|
@@ -46,10 +47,8 @@ const TMP_VOLUME = 'hammerkit-runner-tmp';
|
|
|
46
47
|
const TOOLS_VOLUME = 'hammerkit-runner-tools';
|
|
47
48
|
const TOOLS_PATH = '/.hammerkit';
|
|
48
49
|
const BUSYBOX = `${TOOLS_PATH}/busybox`;
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
// busybox:<version>-musl`).
|
|
52
|
-
exports.RUNNER_TOOLS_IMAGE = 'busybox:1.37.0-musl@sha256:5cec3fc171c87218698e85a52af7087de727372aae264a787b8112901a5b0092';
|
|
50
|
+
// copied into the runner by an init container
|
|
51
|
+
exports.RUNNER_TOOLS_IMAGE = transfer_tools_1.HELPER_TOOLS_IMAGE;
|
|
53
52
|
const RUNNER_START_MS = 5 * 60 * 1000;
|
|
54
53
|
const RUNNER_POLL_MS = 250;
|
|
55
54
|
const PULL_FAILURES = ['ErrImagePull', 'ImagePullBackOff', 'InvalidImageName'];
|
|
@@ -6,6 +6,7 @@ const log_1 = require("../log");
|
|
|
6
6
|
const event_cache_1 = require("../executer/event-cache");
|
|
7
7
|
const volumes_1 = require("./volumes");
|
|
8
8
|
const ensure_persistent_data_1 = require("./ensure-persistent-data");
|
|
9
|
+
const transfer_tools_1 = require("./transfer-tools");
|
|
9
10
|
async function storeKubernetesData(work, kubernetes, instance, environment, path,
|
|
10
11
|
// the state the outputs are of: on a service run, they are in its folder (see
|
|
11
12
|
// getStateFilesDir)
|
|
@@ -22,9 +23,9 @@ stateKey) {
|
|
|
22
23
|
await (0, ensure_persistent_data_1.getPodForPersistence)(instance, kubernetes, work, persistence, 'read', signal, async (name) => {
|
|
23
24
|
for (const generatedArchive of (0, event_cache_1.getArchivePaths)(work.data, path)) {
|
|
24
25
|
const writerStream = environment.file.createWriteStream(generatedArchive.filename);
|
|
25
|
-
const res = await instance.exec.exec(kubernetes.namespace, name, 'volume', files.has(generatedArchive.path)
|
|
26
|
+
const res = await instance.exec.exec(kubernetes.namespace, name, 'volume', (0, transfer_tools_1.inTransferPod)(files.has(generatedArchive.path)
|
|
26
27
|
? ['tar', 'zcf', '-', '-C', path_1.posix.dirname(generatedArchive.path), path_1.posix.basename(generatedArchive.path)]
|
|
27
|
-
: ['tar', 'zcf', '-', '-C', generatedArchive.path, '.'], writerStream, process.stderr, null, false, (status) => {
|
|
28
|
+
: ['tar', 'zcf', '-', '-C', generatedArchive.path, '.']), writerStream, process.stderr, null, false, (status) => {
|
|
28
29
|
work.status.write('debug', `archive ${generatedArchive.path} of ${name}: ${status}`);
|
|
29
30
|
writerStream.close();
|
|
30
31
|
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRANSFER_TOOLS_ENV = exports.TRANSFER_TOOLS_MOUNT = exports.TRANSFER_TOOLS_VOLUMES = exports.getTransferToolsInitContainer = exports.inTransferPod = exports.isTransferToolsPath = exports.TRANSFER_BUSYBOX = exports.TRANSFER_TOOLS_PATH = exports.HELPER_TOOLS_IMAGE = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
// Pinned, static (it runs in any image) busybox: the tools of the pods hammerkit runs its own
|
|
6
|
+
// commands in, such as the runner of a sandbox and the pods that copy files into and out of
|
|
7
|
+
// a claim. To bump it, take the index digest of the tag (`docker buildx imagetools inspect
|
|
8
|
+
// busybox:<version>-musl`).
|
|
9
|
+
exports.HELPER_TOOLS_IMAGE = 'busybox:1.37.0-musl@sha256:5cec3fc171c87218698e85a52af7087de727372aae264a787b8112901a5b0092';
|
|
10
|
+
/**
|
|
11
|
+
* The pod that copies files into and out of a claim mounts the outputs of a task at the
|
|
12
|
+
* paths the task wrote them to, which may be any path, /bin included. So what it runs comes
|
|
13
|
+
* from a folder no mount of the task can be: an init container copies the pinned busybox
|
|
14
|
+
* into it and links each of its tools there, and the pod's own container finds them by its
|
|
15
|
+
* PATH, mounted read-only. Every command starts with the busybox itself, so a tool of the
|
|
16
|
+
* same name in a mounted output never runs.
|
|
17
|
+
*/
|
|
18
|
+
exports.TRANSFER_TOOLS_PATH = '/.hammerkit';
|
|
19
|
+
const TRANSFER_TOOLS_VOLUME = 'hammerkit-transfer-tools';
|
|
20
|
+
exports.TRANSFER_BUSYBOX = `${exports.TRANSFER_TOOLS_PATH}/busybox`;
|
|
21
|
+
const TRANSFER_BIN = `${exports.TRANSFER_TOOLS_PATH}/bin`;
|
|
22
|
+
// a path in or over the folder of the tools (`/`, `/.hammerkit`, `/.hammerkit/bin`), where a
|
|
23
|
+
// mount would hide them
|
|
24
|
+
function isTransferToolsPath(path) {
|
|
25
|
+
const normalized = path_1.posix.normalize(path).replace(/\/+$/, '') || '/';
|
|
26
|
+
return normalized === '/' || normalized === exports.TRANSFER_TOOLS_PATH || normalized.startsWith(`${exports.TRANSFER_TOOLS_PATH}/`);
|
|
27
|
+
}
|
|
28
|
+
exports.isTransferToolsPath = isTransferToolsPath;
|
|
29
|
+
// `command` (a tool and its arguments) run by the busybox of the transfer pod
|
|
30
|
+
function inTransferPod(command) {
|
|
31
|
+
return [exports.TRANSFER_BUSYBOX, ...command];
|
|
32
|
+
}
|
|
33
|
+
exports.inTransferPod = inTransferPod;
|
|
34
|
+
function getTransferToolsInitContainer() {
|
|
35
|
+
return {
|
|
36
|
+
name: TRANSFER_TOOLS_VOLUME,
|
|
37
|
+
image: exports.HELPER_TOOLS_IMAGE,
|
|
38
|
+
command: [
|
|
39
|
+
'/bin/busybox',
|
|
40
|
+
'sh',
|
|
41
|
+
'-c',
|
|
42
|
+
`/bin/busybox cp /bin/busybox ${exports.TRANSFER_BUSYBOX} && /bin/busybox mkdir -p ${TRANSFER_BIN} && ${exports.TRANSFER_BUSYBOX} --install -s ${TRANSFER_BIN}`,
|
|
43
|
+
],
|
|
44
|
+
volumeMounts: [{ name: TRANSFER_TOOLS_VOLUME, mountPath: exports.TRANSFER_TOOLS_PATH }],
|
|
45
|
+
securityContext: {
|
|
46
|
+
runAsNonRoot: true,
|
|
47
|
+
runAsUser: 65534,
|
|
48
|
+
allowPrivilegeEscalation: false,
|
|
49
|
+
readOnlyRootFilesystem: true,
|
|
50
|
+
capabilities: { drop: ['ALL'] },
|
|
51
|
+
},
|
|
52
|
+
// its own requests: the defaults of a namespace are sized for tasks, and a pod's
|
|
53
|
+
// request is the larger of its init containers' and the sum of its containers'
|
|
54
|
+
resources: { requests: { cpu: '10m', memory: '16Mi' }, limits: { memory: '16Mi' } },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.getTransferToolsInitContainer = getTransferToolsInitContainer;
|
|
58
|
+
exports.TRANSFER_TOOLS_VOLUMES = [{ name: TRANSFER_TOOLS_VOLUME, emptyDir: {} }];
|
|
59
|
+
exports.TRANSFER_TOOLS_MOUNT = {
|
|
60
|
+
name: TRANSFER_TOOLS_VOLUME,
|
|
61
|
+
mountPath: exports.TRANSFER_TOOLS_PATH,
|
|
62
|
+
readOnly: true,
|
|
63
|
+
};
|
|
64
|
+
// the tools a script of the transfer pod runs, and nothing else
|
|
65
|
+
exports.TRANSFER_TOOLS_ENV = [{ name: 'PATH', value: TRANSFER_BIN }];
|
|
66
|
+
//# sourceMappingURL=transfer-tools.js.map
|
|
@@ -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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dockerServiceRuntime = exports.dockerTaskRuntime = void 0;
|
|
3
|
+
exports.dockerServiceRuntime = exports.getCacheHelperOptions = exports.dockerTaskRuntime = void 0;
|
|
4
4
|
const run_labels_1 = require("../docker/run-labels");
|
|
5
5
|
const execute_docker_1 = require("../executer/execute-docker");
|
|
6
6
|
const remove_container_1 = require("../docker/remove-container");
|
|
@@ -116,20 +116,11 @@ exports.dockerTaskRuntime = dockerTaskRuntime;
|
|
|
116
116
|
function isOnHost(generate) {
|
|
117
117
|
return generate.isFile || generate.export;
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (root) {
|
|
125
|
-
const names = item.data.type === 'container-service'
|
|
126
|
-
? item.data.volumes.filter((v) => !v.inherited).map((v) => v.name)
|
|
127
|
-
: item.data.generates.filter((v) => !v.inherited && !v.isFile).map((v) => v.volumeName);
|
|
128
|
-
for (const name of names) {
|
|
129
|
-
await (0, get_docker_executor_1.ensureVolumeExists)(docker, item.status, name, (0, get_docker_executor_1.volumeLabels)(root));
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
await (0, using_container_1.usingContainer)(docker, item, {
|
|
119
|
+
// The container that copies an item's outputs into and out of its volumes for the cache:
|
|
120
|
+
// the item's image with those volumes mounted, kept running while archives go in or out.
|
|
121
|
+
// The image is the item's, so whatever its network, this step has none.
|
|
122
|
+
function getCacheHelperOptions(item, environment) {
|
|
123
|
+
return {
|
|
133
124
|
abortSignal: environment.abortCtrl.signal,
|
|
134
125
|
Image: item.data.image,
|
|
135
126
|
Tty: true,
|
|
@@ -144,18 +135,32 @@ async function restoreContainer(docker, environment, item, path) {
|
|
|
144
135
|
},
|
|
145
136
|
HostConfig: {
|
|
146
137
|
AutoRemove: true,
|
|
147
|
-
|
|
148
|
-
//
|
|
149
|
-
// throwaway container's filesystem
|
|
138
|
+
NetworkMode: 'none',
|
|
139
|
+
// the item's own output volumes, so restored archives land there rather than in
|
|
140
|
+
// this throwaway container's filesystem
|
|
150
141
|
Binds: item.data.type === 'container-service'
|
|
151
|
-
? item.data.volumes
|
|
152
|
-
.filter((v) => !v.inherited)
|
|
153
|
-
.map((v) => `${v.name}:${(0, execute_docker_1.convertToPosixPath)(v.containerPath)}`)
|
|
142
|
+
? item.data.volumes.filter((v) => !v.inherited).map((v) => `${v.name}:${(0, execute_docker_1.convertToPosixPath)(v.containerPath)}`)
|
|
154
143
|
: item.data.generates
|
|
155
144
|
.filter((v) => !v.inherited && !v.isFile)
|
|
156
145
|
.map((v) => `${v.volumeName}:${(0, execute_docker_1.convertToPosixPath)(v.path)}`),
|
|
157
146
|
},
|
|
158
|
-
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
exports.getCacheHelperOptions = getCacheHelperOptions;
|
|
150
|
+
async function restoreContainer(docker, environment, item, path) {
|
|
151
|
+
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
152
|
+
// on a server the volumes the outputs are restored into carry the run's files, so they
|
|
153
|
+
// are removed with a sandbox
|
|
154
|
+
const root = (0, execution_steps_1.hostedRoot)(environment);
|
|
155
|
+
if (root) {
|
|
156
|
+
const names = item.data.type === 'container-service'
|
|
157
|
+
? item.data.volumes.filter((v) => !v.inherited).map((v) => v.name)
|
|
158
|
+
: item.data.generates.filter((v) => !v.inherited && !v.isFile).map((v) => v.volumeName);
|
|
159
|
+
for (const name of names) {
|
|
160
|
+
await (0, get_docker_executor_1.ensureVolumeExists)(docker, item.status, name, (0, get_docker_executor_1.volumeLabels)(root));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
await (0, using_container_1.usingContainer)(docker, item, getCacheHelperOptions(item, environment), async (container) => {
|
|
159
164
|
for (const generate of (0, event_cache_1.getArchivePaths)(item.data, path)) {
|
|
160
165
|
if (await environment.file.exists(generate.filename)) {
|
|
161
166
|
// a cache hit means exactly the stored outputs: whatever a failed or
|
|
@@ -272,30 +277,7 @@ function dockerServiceRuntime(service, workEnvironment) {
|
|
|
272
277
|
exports.dockerServiceRuntime = dockerServiceRuntime;
|
|
273
278
|
async function archiveContainer(docker, environment, item, path) {
|
|
274
279
|
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
275
|
-
await (0, using_container_1.usingContainer)(docker, item, {
|
|
276
|
-
abortSignal: environment.abortCtrl.signal,
|
|
277
|
-
Image: item.data.image,
|
|
278
|
-
Tty: true,
|
|
279
|
-
Entrypoint: ['sh'],
|
|
280
|
-
Cmd: ['-c', 'sleep 3600'],
|
|
281
|
-
WorkingDir: (0, execute_docker_1.convertToPosixPath)(item.data.cwd),
|
|
282
|
-
Labels: {
|
|
283
|
-
app: 'hammerkit',
|
|
284
|
-
'hammerkit-id': (0, work_instance_id_1.getWorkInstanceId)(item),
|
|
285
|
-
...(0, run_labels_1.getRunLabels)(),
|
|
286
|
-
'hammerkit-type': 'task',
|
|
287
|
-
},
|
|
288
|
-
HostConfig: {
|
|
289
|
-
AutoRemove: true,
|
|
290
|
-
Binds: item.data.type === 'container-service'
|
|
291
|
-
? item.data.volumes
|
|
292
|
-
.filter((v) => !v.inherited)
|
|
293
|
-
.map((v) => `${v.name}:${(0, execute_docker_1.convertToPosixPath)(v.containerPath)}`)
|
|
294
|
-
: item.data.generates
|
|
295
|
-
.filter((v) => !v.inherited && !v.isFile)
|
|
296
|
-
.map((v) => `${v.volumeName}:${(0, execute_docker_1.convertToPosixPath)(v.path)}`),
|
|
297
|
-
},
|
|
298
|
-
}, async (container) => {
|
|
280
|
+
await (0, using_container_1.usingContainer)(docker, item, getCacheHelperOptions(item, environment), async (container) => {
|
|
299
281
|
const hostFiles = new Set(item.data.type === 'container-task'
|
|
300
282
|
? item.data.generates.filter((g) => !g.inherited && g.isFile).map((g) => g.path)
|
|
301
283
|
: []);
|
|
@@ -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
|
}
|
|
@@ -12,6 +12,7 @@ const capacity_1 = require("./capacity");
|
|
|
12
12
|
const kubernetes_instance_1 = require("../kubernetes/kubernetes-instance");
|
|
13
13
|
const log_1 = require("../log");
|
|
14
14
|
const network_policy_1 = require("../kubernetes/network-policy");
|
|
15
|
+
const network_gate_1 = require("../kubernetes/network-gate");
|
|
15
16
|
const sleep_1 = require("../utils/sleep");
|
|
16
17
|
const version_1 = require("../version");
|
|
17
18
|
const executor_1 = require("./executor");
|
|
@@ -98,6 +99,8 @@ function readInClusterNamespace() {
|
|
|
98
99
|
* Policies add up, so neither selects the pods of a limited item: its own policy (see
|
|
99
100
|
* buildNetworkPolicy) is all it may reach, DNS left out, and all that may reach it. An
|
|
100
101
|
* egress proxy takes connections from its item only (buildProxyPolicy).
|
|
102
|
+
* - the pods that copy files into and out of claims: no network at all (they are limited,
|
|
103
|
+
* and the policies of the items whose labels they carry leave them out)
|
|
101
104
|
*/
|
|
102
105
|
function getNamespacePolicies(namespace, deniedEgress, allowedEgress = []) {
|
|
103
106
|
const metadata = (name) => ({
|
|
@@ -157,6 +160,17 @@ function getNamespacePolicies(namespace, deniedEgress, allowedEgress = []) {
|
|
|
157
160
|
ingress: [],
|
|
158
161
|
},
|
|
159
162
|
},
|
|
163
|
+
{
|
|
164
|
+
apiVersion: 'networking.k8s.io/v1',
|
|
165
|
+
kind: 'NetworkPolicy',
|
|
166
|
+
metadata: metadata('hammerkit-transfer'),
|
|
167
|
+
spec: {
|
|
168
|
+
// the pods that copy files into and out of a claim, which are reached through the
|
|
169
|
+
// API (exec): nothing in or out
|
|
170
|
+
podSelector: { matchLabels: { [network_policy_1.TRANSFER_LABEL]: 'true' } },
|
|
171
|
+
policyTypes: ['Ingress', 'Egress'],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
160
174
|
];
|
|
161
175
|
}
|
|
162
176
|
exports.getNamespacePolicies = getNamespacePolicies;
|
|
@@ -565,6 +579,7 @@ class KubernetesExecutor {
|
|
|
565
579
|
// The cluster as the process of a run sees it: the namespace its tasks and services go in.
|
|
566
580
|
environmentOf(run, namespace, work, capabilitiesProblem) {
|
|
567
581
|
const backend = this.config.backend;
|
|
582
|
+
const openGate = (0, network_gate_1.getOpenNetworkGate)(backend);
|
|
568
583
|
return {
|
|
569
584
|
type: 'kubernetes',
|
|
570
585
|
namespace,
|
|
@@ -585,6 +600,7 @@ class KubernetesExecutor {
|
|
|
585
600
|
// the claims of a service run go with its namespace
|
|
586
601
|
...(this.keep > 0 && !run.up ? { volumeScope: getVolumeScope(run) } : {}),
|
|
587
602
|
...(run.up ? { serviceRun: true } : {}),
|
|
603
|
+
...(openGate ? { openGate } : {}),
|
|
588
604
|
...(backend.capabilities
|
|
589
605
|
? {
|
|
590
606
|
capabilities: {
|
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
|
}
|