Skip to content

Commit e7d27a5

Browse files
Add exclusion list for environment variables (#802)
* Restrict runner ENV access * Retrieve exclusion list from environment variable * Apply suggestions from code review * Fix “the blunder of the century” https://www.youtube.com/watch?v=vcFBwt1nu2U * Add warning for GitHub runners * Update github.js * Update github.js --------- Co-authored-by: Helio Machado <[email protected]>
1 parent 2675110 commit e7d27a5

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/cml.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,14 @@ class CML {
421421
}
422422

423423
async startRunner(opts = {}) {
424-
return await this.getDriver().startRunner(opts);
424+
const env = {};
425+
const sensitive = [
426+
'_CML_RUNNER_SENSITIVE_ENV',
427+
...process.env._CML_RUNNER_SENSITIVE_ENV.split(':')
428+
];
429+
for (const variable in process.env)
430+
if (!sensitive.includes(variable)) env[variable] = process.env[variable];
431+
return await this.getDriver().startRunner({ ...opts, env });
425432
}
426433

427434
async registerRunner(opts = {}) {

src/drivers/bitbucket_cloud.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class BitbucketCloud {
166166

167167
async startRunner(opts) {
168168
const { projectPath } = this;
169-
const { workdir, name, labels } = opts;
169+
const { workdir, name, labels, env } = opts;
170170

171171
winston.warn(
172172
`Bitbucket runner is working under /tmp folder and not under ${workdir} as expected`
@@ -197,7 +197,7 @@ class BitbucketCloud {
197197
${gpu ? '--runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all' : ''} \
198198
docker-public.packages.atlassian.com/sox/atlassian/bitbucket-pipelines-runner:1`;
199199

200-
return spawn(command, { shell: true });
200+
return spawn(command, { shell: true, env });
201201
} catch (err) {
202202
throw new Error(`Failed preparing runner: ${err.message}`);
203203
}

src/drivers/github.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ class Github {
255255
}
256256

257257
async startRunner(opts) {
258-
const { workdir, single, name, labels } = opts;
258+
const { workdir, single, name, labels, env } = opts;
259+
260+
this.warn(
261+
'cloud credentials are no longer available on self-hosted runner steps; please use step.env and secrets instead'
262+
);
259263

260264
try {
261265
const runnerCfg = resolve(workdir, '.runner');
@@ -295,7 +299,8 @@ class Github {
295299
);
296300

297301
return spawn(resolve(workdir, 'run.sh'), {
298-
shell: true
302+
shell: true,
303+
env
299304
});
300305
} catch (err) {
301306
throw new Error(`Failed preparing GitHub runner: ${err.message}`);

src/drivers/gitlab.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ class Gitlab {
183183
single,
184184
labels,
185185
name,
186-
dockerVolumes = []
186+
dockerVolumes = [],
187+
env
187188
} = opts;
188189

189190
const gpu = await gpuPresent();
@@ -222,7 +223,7 @@ class Gitlab {
222223
${dockerVolumesTpl} \
223224
${single ? '--max-builds 1' : ''}`;
224225

225-
return spawn(command, { shell: true });
226+
return spawn(command, { shell: true, env });
226227
} catch (err) {
227228
if (err.message === 'Forbidden')
228229
err.message +=

0 commit comments

Comments
 (0)