Skip to content

Commit 1f047e7

Browse files
committed
fix(github-actions): remove bundled credential from bazel remote configuration (#2856)
PR Close #2856
1 parent 51204d4 commit 1f047e7

File tree

9 files changed

+19441
-164
lines changed

9 files changed

+19441
-164
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.github/local-actions/labels-sync/main.js
44
.github/local-actions/lock-closed/main.js
5-
github-actions/bazel/configure-remote/configure-remote.cjs
5+
github-actions/bazel/configure-remote/main.js
66
github-actions/branch-manager/main.js
77
github-actions/browserstack/set-browserstack-env.cjs
88
github-actions/pull-request-labeling/main.js
Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,19 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "generated_file_test", "nodejs_binary")
2-
load("//tools:defaults.bzl", "esbuild", "ts_library")
3-
load("//tools/node-to-shell-script:index.bzl", "nodejs_script_to_sh_script")
4-
5-
copy_to_bin(
6-
name = "gcp_token",
7-
srcs = ["gcp_token.data"],
8-
)
1+
load("//tools:defaults.bzl", "esbuild_checked_in", "ts_library")
92

103
ts_library(
114
name = "setup-bazel-remote-exec",
125
srcs = glob(["*.ts"]),
13-
# TODO(devversion): Remove this when `ts_library` supports `.mts` extension.
14-
devmode_module = "commonjs",
156
deps = [
167
"@npm//@actions/core",
178
"@npm//@types/node",
189
],
1910
)
2011

21-
nodejs_binary(
22-
name = "encrypt",
23-
data = [":setup-bazel-remote-exec"],
24-
entry_point = ":encrypt.ts",
25-
)
26-
27-
esbuild(
28-
name = "bundle",
29-
srcs = [":gcp_token"],
30-
args = {
31-
"loader": {
32-
".data": "binary",
33-
},
34-
},
12+
esbuild_checked_in(
13+
name = "main",
3514
entry_point = "index.ts",
36-
format = "iife",
37-
minify = True,
38-
sourcemap = "",
39-
deps = [":setup-bazel-remote-exec"],
40-
)
41-
42-
# TODO: determine if we can use the node script directly in github actions
43-
nodejs_script_to_sh_script(
44-
name = "script",
45-
bundle_file = ":bundle.js",
46-
output_file = "script.sh",
47-
)
48-
49-
generated_file_test(
50-
name = "configure-remote",
51-
src = "configure-remote.cjs",
52-
generated = ":bundle.js",
15+
target = "node20",
16+
deps = [
17+
":setup-bazel-remote-exec",
18+
],
5319
)

github-actions/bazel/configure-remote/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ inputs:
2222
2323
runs:
2424
using: 'node20'
25-
main: 'configure-remote.cjs'
25+
main: 'main.js'

github-actions/bazel/configure-remote/configure-remote.cjs

Lines changed: 0 additions & 73 deletions
This file was deleted.

github-actions/bazel/configure-remote/constants.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

github-actions/bazel/configure-remote/encrypt.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Binary file not shown.

github-actions/bazel/configure-remote/index.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@
77
*/
88

99
// @ts-ignore-next-line
10-
import tokenRaw from './gcp_token.data';
11-
import {k, iv, alg, at} from './constants.js';
12-
import {createDecipheriv} from 'crypto';
1310
import path from 'path';
1411
import fs from 'fs';
1512
import os from 'os';
16-
import {exportVariable, getBooleanInput, getInput} from '@actions/core';
13+
import {exportVariable, getBooleanInput, getInput, notice} from '@actions/core';
1714

1815
async function main() {
1916
const isWindows = os.platform() === 'win32';
2017
const bazelRcPath = getInput('bazelrc', {required: false, trimWhitespace: true});
2118
const allowWindowsRbe = getBooleanInput('allow_windows_rbe', {required: true});
2219
const trustedBuild = getBooleanInput('trusted_build', {required: false});
23-
const credential =
24-
getInput('google_credential', {required: false, trimWhitespace: true}) ||
25-
getEmbeddedCredential();
20+
const credential = getInput('google_credential', {required: false, trimWhitespace: true});
21+
22+
// If no credential is provided, gracefully exit.
23+
if (credential === '') {
24+
notice('No credential was provided.', {title: 'Skipped setting up Bazel RBE'});
25+
return;
26+
}
2627

2728
const destPath = isWindows
2829
? path.join(process.env.APPDATA!, 'gcloud/application_default_credentials.json')
@@ -55,13 +56,6 @@ async function readFileGracefully(filePath: string): Promise<string> {
5556
}
5657
}
5758

58-
/** Extract the embeeded credential from the action. */
59-
function getEmbeddedCredential(): string {
60-
const t: Uint8Array = tokenRaw;
61-
const dcip = createDecipheriv(alg, k, iv).setAuthTag(Buffer.from(at, 'base64'));
62-
return dcip.update(t, undefined, 'utf8') + dcip.final('utf8');
63-
}
64-
6559
main().catch((e) => {
6660
console.error(e);
6761
process.exitCode = 1;

0 commit comments

Comments
 (0)