Skip to content

Commit

Permalink
Add exclusion list for environment variables (#802)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
DavidGOrtega and 0x2b3bfa0 authored May 9, 2024
1 parent 2675110 commit e7d27a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,14 @@ class CML {
}

async startRunner(opts = {}) {
return await this.getDriver().startRunner(opts);
const env = {};
const sensitive = [
'_CML_RUNNER_SENSITIVE_ENV',
...process.env._CML_RUNNER_SENSITIVE_ENV.split(':')
];
for (const variable in process.env)
if (!sensitive.includes(variable)) env[variable] = process.env[variable];
return await this.getDriver().startRunner({ ...opts, env });
}

async registerRunner(opts = {}) {
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/bitbucket_cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class BitbucketCloud {

async startRunner(opts) {
const { projectPath } = this;
const { workdir, name, labels } = opts;
const { workdir, name, labels, env } = opts;

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

return spawn(command, { shell: true });
return spawn(command, { shell: true, env });
} catch (err) {
throw new Error(`Failed preparing runner: ${err.message}`);
}
Expand Down
9 changes: 7 additions & 2 deletions src/drivers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ class Github {
}

async startRunner(opts) {
const { workdir, single, name, labels } = opts;
const { workdir, single, name, labels, env } = opts;

this.warn(
'cloud credentials are no longer available on self-hosted runner steps; please use step.env and secrets instead'
);

try {
const runnerCfg = resolve(workdir, '.runner');
Expand Down Expand Up @@ -295,7 +299,8 @@ class Github {
);

return spawn(resolve(workdir, 'run.sh'), {
shell: true
shell: true,
env
});
} catch (err) {
throw new Error(`Failed preparing GitHub runner: ${err.message}`);
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class Gitlab {
single,
labels,
name,
dockerVolumes = []
dockerVolumes = [],
env
} = opts;

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

return spawn(command, { shell: true });
return spawn(command, { shell: true, env });
} catch (err) {
if (err.message === 'Forbidden')
err.message +=
Expand Down

0 comments on commit e7d27a5

Please sign in to comment.