mirror of
https://github.com/github/codeql-action.git
synced 2026-08-05 04:57:19 -05:00
Install proxy cert on GitHub-hosted Ubuntu runners
This commit is contained in:
Generated
+335
-251
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ import {
|
|||||||
Credential,
|
Credential,
|
||||||
getCredentials,
|
getCredentials,
|
||||||
getDownloadUrl,
|
getDownloadUrl,
|
||||||
|
installProxyCertificate,
|
||||||
parseLanguage,
|
parseLanguage,
|
||||||
UPDATEJOB_PROXY,
|
UPDATEJOB_PROXY,
|
||||||
} from "./start-proxy";
|
} from "./start-proxy";
|
||||||
@@ -285,6 +286,8 @@ async function startProxy(
|
|||||||
url: credential.url,
|
url: credential.url,
|
||||||
}));
|
}));
|
||||||
core.setOutput("proxy_urls", JSON.stringify(registry_urls));
|
core.setOutput("proxy_urls", JSON.stringify(registry_urls));
|
||||||
|
|
||||||
|
await installProxyCertificate(logger, config.ca.cert);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getProxyBinaryPath(logger: Logger): Promise<string> {
|
async function getProxyBinaryPath(logger: Logger): Promise<string> {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
import * as fs from "fs";
|
||||||
|
import * as path from "path";
|
||||||
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
|
import { isSelfHostedRunner, runTool } from "./actions-util";
|
||||||
import { getApiClient } from "./api-client";
|
import { getApiClient } from "./api-client";
|
||||||
import * as defaults from "./defaults.json";
|
import * as defaults from "./defaults.json";
|
||||||
import { KnownLanguage } from "./languages";
|
import { KnownLanguage } from "./languages";
|
||||||
@@ -256,3 +260,49 @@ export async function getDownloadUrl(
|
|||||||
version: UPDATEJOB_PROXY_VERSION,
|
version: UPDATEJOB_PROXY_VERSION,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The standard path for certificates on Ubuntu.
|
||||||
|
const certPath = "/usr/local/share/ca-certificates/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we are running on a GitHub-hosted Ubuntu runner, this function attempts to
|
||||||
|
* install the `cert` into the system-wide certificate store.
|
||||||
|
*
|
||||||
|
* This function does nothing on other platforms.
|
||||||
|
*
|
||||||
|
* @param logger The logger to use.
|
||||||
|
* @param cert The certificate to install.
|
||||||
|
*/
|
||||||
|
export async function installProxyCertificate(logger: Logger, cert: string) {
|
||||||
|
// On GitHub-hosted linux runners, install the certificate system-wide.
|
||||||
|
if (process.platform === "linux" && !isSelfHostedRunner()) {
|
||||||
|
try {
|
||||||
|
// Don't continue if the certificate path doesn't already exist in the expected location.
|
||||||
|
if (!fs.existsSync(certPath)) {
|
||||||
|
logger.debug(
|
||||||
|
"Certificate path does not exist in the expected location.",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a sub-directory for our certificates.
|
||||||
|
const certSubPath = path.join(certPath, "codeql-action");
|
||||||
|
fs.mkdirSync(certSubPath);
|
||||||
|
|
||||||
|
// Write the certificate
|
||||||
|
const certFilePath = path.join(certSubPath, "proxy.crt");
|
||||||
|
fs.writeFileSync(certFilePath, cert);
|
||||||
|
|
||||||
|
// Update the certificates.
|
||||||
|
await runTool("sudo", ["update-ca-certificates"]);
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`Successfully installed proxy certificate to ${certFilePath}`,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
logger.info(
|
||||||
|
`Unable to install proxy certificate system-wide: ${getErrorMessage(e)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user