Skip to content

Commit c6295a6

Browse files
Merge pull request #530 from step-security/rc-19
Release v2.11.1
2 parents b131ca5 + 3e118b1 commit c6295a6

File tree

9 files changed

+110221
-43964
lines changed

9 files changed

+110221
-43964
lines changed

Diff for: dist/index.js

+26,140-1,364
Large diffs are not rendered by default.

Diff for: dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/post/index.js

+26,142-1,366
Large diffs are not rendered by default.

Diff for: dist/post/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/pre/index.js

+57,178-40,749
Large diffs are not rendered by default.

Diff for: dist/pre/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package-lock.json

+682-460
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/step-security/harden-runner#readme",
2525
"dependencies": {
26-
"@actions/cache": "^3.1.4",
26+
"@actions/cache": "^4.0.0",
2727
"@actions/core": "^1.5.0",
2828
"@actions/exec": "^1.1.0",
2929
"@actions/github": "^5.0.0",

Diff for: src/setup.ts

+75-21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import { Configuration, PolicyResponse } from "./interfaces";
1919
import { fetchPolicy, mergeConfigs } from "./policy-utils";
2020
import * as cache from "@actions/cache";
2121
import { getCacheEntry } from "@actions/cache/lib/internal/cacheHttpClient";
22+
import * as cacheTwirpClient from "@actions/cache/lib/internal/shared/cacheTwirpClient";
23+
import { GetCacheEntryDownloadURLRequest } from "@actions/cache/lib/generated/results/api/v1/cache";
24+
import { getCacheServiceVersion } from "@actions/cache/lib/internal/config";
25+
2226
import * as utils from "@actions/cache/lib/internal/cacheUtils";
2327
import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
2428
import { STEPSECURITY_API_URL, STEPSECURITY_WEB_URL } from "./configs";
@@ -114,28 +118,78 @@ interface MonitorResponse {
114118
} catch (exception) {
115119
console.log(exception);
116120
}
117-
try {
118-
const compressionMethod: CompressionMethod =
119-
await utils.getCompressionMethod();
120-
const cacheFilePath = path.join(__dirname, "cache.txt");
121-
core.info(`cacheFilePath ${cacheFilePath}`);
122-
const cacheEntry: ArtifactCacheEntry = await getCacheEntry(
123-
[cacheKey],
124-
[cacheFilePath],
125-
{
126-
compressionMethod: compressionMethod,
121+
122+
const cacheServiceVersion: string = getCacheServiceVersion();
123+
124+
switch (cacheServiceVersion) {
125+
case "v2":
126+
core.info(`cache version: v2`);
127+
try {
128+
const cacheFilePath = path.join(__dirname, "cache.txt");
129+
core.info(`cacheFilePath ${cacheFilePath}`);
130+
131+
const twirpClient = cacheTwirpClient.internalCacheTwirpClient();
132+
const compressionMethod = await utils.getCompressionMethod();
133+
134+
const request: GetCacheEntryDownloadURLRequest = {
135+
key: cacheKey,
136+
restoreKeys: [],
137+
version: utils.getCacheVersion(
138+
[cacheFilePath],
139+
compressionMethod,
140+
false
141+
),
142+
};
143+
144+
const response = await twirpClient.GetCacheEntryDownloadURL(
145+
request
146+
);
147+
148+
const url = new URL(response.signedDownloadUrl);
149+
core.info(
150+
`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`
151+
);
152+
153+
confg.allowed_endpoints += ` ${url.hostname}:443`;
154+
} catch (e) {
155+
core.info(`Unable to fetch cacheURL ${e}`);
156+
if (confg.egress_policy === "block") {
157+
core.info("Switching egress-policy to audit mode");
158+
confg.egress_policy = "audit";
159+
}
160+
}
161+
break;
162+
163+
case "v1":
164+
core.info(`cache version: v1`);
165+
166+
try {
167+
const compressionMethod: CompressionMethod =
168+
await utils.getCompressionMethod();
169+
const cacheFilePath = path.join(__dirname, "cache.txt");
170+
core.info(`cacheFilePath ${cacheFilePath}`);
171+
172+
const cacheEntry: ArtifactCacheEntry = await getCacheEntry(
173+
[cacheKey],
174+
[cacheFilePath],
175+
{
176+
compressionMethod: compressionMethod,
177+
}
178+
);
179+
const url = new URL(cacheEntry.archiveLocation);
180+
core.info(
181+
`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`
182+
);
183+
184+
confg.allowed_endpoints += ` ${url.hostname}:443`;
185+
} catch (exception) {
186+
// some exception has occurred.
187+
core.info(`Unable to fetch cacheURL ${exception}`);
188+
if (confg.egress_policy === "block") {
189+
core.info("Switching egress-policy to audit mode");
190+
confg.egress_policy = "audit";
191+
}
127192
}
128-
);
129-
const url = new URL(cacheEntry.archiveLocation);
130-
core.info(`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`);
131-
confg.allowed_endpoints += ` ${url.hostname}:443`;
132-
} catch (exception) {
133-
// some exception has occurred.
134-
core.info(`Unable to fetch cacheURL`);
135-
if (confg.egress_policy === "block") {
136-
core.info("Switching egress-policy to audit mode");
137-
confg.egress_policy = "audit";
138-
}
139193
}
140194
}
141195

0 commit comments

Comments
 (0)