Skip to content

Commit 591c9c5

Browse files
Copilotpelikhan
andauthored
fix: mask inferred OTLP access tokens (#50774)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 1755de8 commit 591c9c5

4 files changed

Lines changed: 34 additions & 5 deletions

File tree

.changeset/patch-mask-inferred-otlp-tokens.md

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/setup/js/exchange_otlp_workload_identity.cjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@
1313

1414
const CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
1515

16+
/**
17+
* Mask a token discovered by this inline github-script before it can be used
18+
* or exposed as an output.
19+
*
20+
* @param {unknown} value
21+
*/
22+
function maskSecret(value) {
23+
core.setSecret(String(value));
24+
}
25+
1626
async function main() {
1727
const oidcToken = process.env.GH_AW_OTLP_OIDC_TOKEN;
1828
if (!oidcToken) {
1929
throw new Error("Missing GitHub OIDC token for Google workload identity token exchange");
2030
}
21-
core.setSecret(oidcToken);
31+
maskSecret(oidcToken);
2232

2333
const response = await fetch("https://sts.googleapis.com/v1/token", {
2434
method: "POST",
@@ -44,7 +54,7 @@ async function main() {
4454
if (!accessToken) {
4555
throw new Error("Google workload identity token exchange returned no access token");
4656
}
47-
core.setSecret(accessToken);
57+
maskSecret(accessToken);
4858

4959
const serviceAccount = process.env.GH_AW_OTLP_WIF_SERVICE_ACCOUNT;
5060
if (serviceAccount) {
@@ -64,7 +74,7 @@ async function main() {
6474
if (!accessToken) {
6575
throw new Error("Google service account impersonation returned no access token");
6676
}
67-
core.setSecret(accessToken);
77+
maskSecret(accessToken);
6878
}
6979

7080
core.setOutput("token", accessToken);

actions/setup/js/exchange_otlp_workload_identity.test.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe("exchange_otlp_workload_identity", () => {
6060
expect(mockCore.setSecret).toHaveBeenCalledWith("github-oidc-token");
6161
expect(mockCore.setSecret).toHaveBeenCalledWith("federated-token");
6262
expect(mockCore.setOutput).toHaveBeenCalledWith("token", "federated-token");
63+
expect(mockCore.setSecret.mock.invocationCallOrder[1]).toBeLessThan(mockCore.setOutput.mock.invocationCallOrder[0]);
6364
});
6465

6566
it("impersonates the service account when configured", async () => {
@@ -75,6 +76,8 @@ describe("exchange_otlp_workload_identity", () => {
7576
expect(options.headers.authorization).toContain("federated-token");
7677
expect(mockCore.setSecret.mock.calls).toEqual([["github-oidc-token"], ["federated-token"], ["impersonated-token"]]);
7778
expect(mockCore.setOutput).toHaveBeenCalledWith("token", "impersonated-token");
79+
expect(mockCore.setSecret.mock.invocationCallOrder[1]).toBeLessThan(fetchMock.mock.invocationCallOrder[1]);
80+
expect(mockCore.setSecret.mock.invocationCallOrder[2]).toBeLessThan(mockCore.setOutput.mock.invocationCallOrder[0]);
7881
});
7982

8083
it("does not call the impersonation endpoint when no service account is configured", async () => {

pkg/workflow/js/exchange_otlp_workload_identity.cjs

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)