Merge pull request #3146 from github/mbg/start-proxy/authenticate

Provide `Authorization` header when downloading `update-job-proxy`
This commit is contained in:
Michael B. Gale
2025-09-24 19:09:40 +01:00
committed by GitHub
9 changed files with 137 additions and 44 deletions

17
lib/analyze-action.js generated
View File

@@ -90236,6 +90236,14 @@ function getApiDetails() {
function getApiClient() {
return createApiClientWithDetails(getApiDetails());
}
function getAuthorizationHeaderFor(logger, apiDetails, url2) {
if (url2.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && url2.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug(`Providing an authorization token.`);
return `token ${apiDetails.auth}`;
}
logger.debug(`Not using an authorization token.`);
return void 0;
}
var cachedGitHubVersion = void 0;
async function getGitHubVersionFromApi(apiClient, apiDetails) {
if (parseGitHubUrl(apiDetails.url) === GITHUB_DOTCOM_URL) {
@@ -92429,11 +92437,12 @@ var downloadCodeQL = async function(codeqlURL, compressionMethod, maybeBundleVer
let authorization = void 0;
if (searchParams.has("token")) {
logger.debug("CodeQL tools URL contains an authorization token.");
} else if (codeqlURL.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && codeqlURL.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug("Providing an authorization token to download CodeQL tools.");
authorization = `token ${apiDetails.auth}`;
} else {
logger.debug("Downloading CodeQL tools without an authorization token.");
authorization = getAuthorizationHeaderFor(
logger,
apiDetails,
codeqlURL
);
}
const toolcacheInfo = getToolcacheDestinationInfo(
maybeBundleVersion,

View File

@@ -128455,6 +128455,14 @@ function getApiDetails() {
function getApiClient() {
return createApiClientWithDetails(getApiDetails());
}
function getAuthorizationHeaderFor(logger, apiDetails, url2) {
if (url2.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && url2.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug(`Providing an authorization token.`);
return `token ${apiDetails.auth}`;
}
logger.debug(`Not using an authorization token.`);
return void 0;
}
var cachedGitHubVersion = void 0;
async function getGitHubVersionFromApi(apiClient, apiDetails) {
if (parseGitHubUrl(apiDetails.url) === GITHUB_DOTCOM_URL) {
@@ -130372,11 +130380,12 @@ var downloadCodeQL = async function(codeqlURL, compressionMethod, maybeBundleVer
let authorization = void 0;
if (searchParams.has("token")) {
logger.debug("CodeQL tools URL contains an authorization token.");
} else if (codeqlURL.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && codeqlURL.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug("Providing an authorization token to download CodeQL tools.");
authorization = `token ${apiDetails.auth}`;
} else {
logger.debug("Downloading CodeQL tools without an authorization token.");
authorization = getAuthorizationHeaderFor(
logger,
apiDetails,
codeqlURL
);
}
const toolcacheInfo = getToolcacheDestinationInfo(
maybeBundleVersion,

17
lib/init-action.js generated
View File

@@ -86091,6 +86091,14 @@ function getApiClient() {
function getApiClientWithExternalAuth(apiDetails) {
return createApiClientWithDetails(apiDetails, { allowExternal: true });
}
function getAuthorizationHeaderFor(logger, apiDetails, url) {
if (url.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && url.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug(`Providing an authorization token.`);
return `token ${apiDetails.auth}`;
}
logger.debug(`Not using an authorization token.`);
return void 0;
}
var cachedGitHubVersion = void 0;
async function getGitHubVersionFromApi(apiClient, apiDetails) {
if (parseGitHubUrl(apiDetails.url) === GITHUB_DOTCOM_URL) {
@@ -89201,11 +89209,12 @@ var downloadCodeQL = async function(codeqlURL, compressionMethod, maybeBundleVer
let authorization = void 0;
if (searchParams.has("token")) {
logger.debug("CodeQL tools URL contains an authorization token.");
} else if (codeqlURL.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && codeqlURL.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug("Providing an authorization token to download CodeQL tools.");
authorization = `token ${apiDetails.auth}`;
} else {
logger.debug("Downloading CodeQL tools without an authorization token.");
authorization = getAuthorizationHeaderFor(
logger,
apiDetails,
codeqlURL
);
}
const toolcacheInfo = getToolcacheDestinationInfo(
maybeBundleVersion,

View File

@@ -49356,17 +49356,8 @@ var persistInputs = function() {
core4.saveState(persistedInputsKey, JSON.stringify(inputEnvironmentVariables));
};
// src/logging.ts
var core5 = __toESM(require_core());
function getActionsLogger() {
return core5;
}
// src/start-proxy.ts
var core7 = __toESM(require_core());
// src/api-client.ts
var core6 = __toESM(require_core());
var core5 = __toESM(require_core());
var githubUtils = __toESM(require_utils4());
var retry = __toESM(require_dist_node15());
var import_console_log_level = __toESM(require_console_log_level());
@@ -49391,6 +49382,23 @@ function getApiDetails() {
function getApiClient() {
return createApiClientWithDetails(getApiDetails());
}
function getAuthorizationHeaderFor(logger, apiDetails, url) {
if (url.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && url.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug(`Providing an authorization token.`);
return `token ${apiDetails.auth}`;
}
logger.debug(`Not using an authorization token.`);
return void 0;
}
// src/logging.ts
var core6 = __toESM(require_core());
function getActionsLogger() {
return core6;
}
// src/start-proxy.ts
var core7 = __toESM(require_core());
// src/defaults.json
var bundleVersion = "codeql-bundle-v2.23.1";
@@ -49682,10 +49690,16 @@ async function getProxyBinaryPath(logger) {
const proxyInfo = await getDownloadUrl(logger);
let proxyBin = toolcache.find(proxyFileName, proxyInfo.version);
if (!proxyBin) {
const apiDetails = getApiDetails();
const authorization = getAuthorizationHeaderFor(
logger,
apiDetails,
proxyInfo.url
);
const temp = await toolcache.downloadTool(
proxyInfo.url,
void 0,
void 0,
authorization,
{
accept: "application/octet-stream"
}

17
lib/upload-lib.js generated
View File

@@ -88582,6 +88582,14 @@ function getApiDetails() {
function getApiClient() {
return createApiClientWithDetails(getApiDetails());
}
function getAuthorizationHeaderFor(logger, apiDetails, url2) {
if (url2.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && url2.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug(`Providing an authorization token.`);
return `token ${apiDetails.auth}`;
}
logger.debug(`Not using an authorization token.`);
return void 0;
}
var cachedGitHubVersion = void 0;
async function getGitHubVersionFromApi(apiClient, apiDetails) {
if (parseGitHubUrl(apiDetails.url) === GITHUB_DOTCOM_URL) {
@@ -90200,11 +90208,12 @@ var downloadCodeQL = async function(codeqlURL, compressionMethod, maybeBundleVer
let authorization = void 0;
if (searchParams.has("token")) {
logger.debug("CodeQL tools URL contains an authorization token.");
} else if (codeqlURL.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && codeqlURL.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug("Providing an authorization token to download CodeQL tools.");
authorization = `token ${apiDetails.auth}`;
} else {
logger.debug("Downloading CodeQL tools without an authorization token.");
authorization = getAuthorizationHeaderFor(
logger,
apiDetails,
codeqlURL
);
}
const toolcacheInfo = getToolcacheDestinationInfo(
maybeBundleVersion,

View File

@@ -88834,6 +88834,14 @@ function getApiDetails() {
function getApiClient() {
return createApiClientWithDetails(getApiDetails());
}
function getAuthorizationHeaderFor(logger, apiDetails, url2) {
if (url2.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && url2.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug(`Providing an authorization token.`);
return `token ${apiDetails.auth}`;
}
logger.debug(`Not using an authorization token.`);
return void 0;
}
var cachedGitHubVersion = void 0;
async function getGitHubVersionFromApi(apiClient, apiDetails) {
if (parseGitHubUrl(apiDetails.url) === GITHUB_DOTCOM_URL) {
@@ -90901,11 +90909,12 @@ var downloadCodeQL = async function(codeqlURL, compressionMethod, maybeBundleVer
let authorization = void 0;
if (searchParams.has("token")) {
logger.debug("CodeQL tools URL contains an authorization token.");
} else if (codeqlURL.startsWith(`${apiDetails.url}/`) || apiDetails.apiURL && codeqlURL.startsWith(`${apiDetails.apiURL}/`)) {
logger.debug("Providing an authorization token to download CodeQL tools.");
authorization = `token ${apiDetails.auth}`;
} else {
logger.debug("Downloading CodeQL tools without an authorization token.");
authorization = getAuthorizationHeaderFor(
logger,
apiDetails,
codeqlURL
);
}
const toolcacheInfo = getToolcacheDestinationInfo(
maybeBundleVersion,

View File

@@ -4,6 +4,7 @@ import * as retry from "@octokit/plugin-retry";
import consoleLogLevel from "console-log-level";
import { getActionVersion, getRequiredInput } from "./actions-util";
import { Logger } from "./logging";
import { getRepositoryNwo, RepositoryNwo } from "./repository";
import {
ConfigurationError,
@@ -54,7 +55,7 @@ function createApiClientWithDetails(
);
}
export function getApiDetails() {
export function getApiDetails(): GitHubApiDetails {
return {
auth: getRequiredInput("token"),
url: getRequiredEnvParam("GITHUB_SERVER_URL"),
@@ -72,6 +73,36 @@ export function getApiClientWithExternalAuth(
return createApiClientWithDetails(apiDetails, { allowExternal: true });
}
/**
* Gets a value for the `Authorization` header for a request to `url`; or `undefined` if the
* `Authorization` header should not be set for `url`.
*
* @param logger The logger to use for debugging messages.
* @param apiDetails Details of the GitHub API we are using.
* @param url The URL for which we want to add an `Authorization` header.
*
* @returns The value for the `Authorization` header or `undefined` if it shouldn't be populated.
*/
export function getAuthorizationHeaderFor(
logger: Logger,
apiDetails: GitHubApiDetails,
url: string,
): string | undefined {
// We only want to provide an authorization header if we are downloading
// from the same GitHub instance the Action is running on.
// This avoids leaking Enterprise tokens to dotcom.
if (
url.startsWith(`${apiDetails.url}/`) ||
(apiDetails.apiURL && url.startsWith(`${apiDetails.apiURL}/`))
) {
logger.debug(`Providing an authorization token.`);
return `token ${apiDetails.auth}`;
}
logger.debug(`Not using an authorization token.`);
return undefined;
}
let cachedGitHubVersion: GitHubVersion | undefined = undefined;
export async function getGitHubVersionFromApi(

View File

@@ -567,21 +567,17 @@ export const downloadCodeQL = async function (
const headers: OutgoingHttpHeaders = {
accept: "application/octet-stream",
};
// We only want to provide an authorization header if we are downloading
// from the same GitHub instance the Action is running on.
// This avoids leaking Enterprise tokens to dotcom.
// We also don't want to send an authorization header if there's already a token provided in the URL.
let authorization: string | undefined = undefined;
// We don't want to send an authorization header if there's already a token provided in the URL.
if (searchParams.has("token")) {
logger.debug("CodeQL tools URL contains an authorization token.");
} else if (
codeqlURL.startsWith(`${apiDetails.url}/`) ||
(apiDetails.apiURL && codeqlURL.startsWith(`${apiDetails.apiURL}/`))
) {
logger.debug("Providing an authorization token to download CodeQL tools.");
authorization = `token ${apiDetails.auth}`;
} else {
logger.debug("Downloading CodeQL tools without an authorization token.");
authorization = api.getAuthorizationHeaderFor(
logger,
apiDetails,
codeqlURL,
);
}
const toolcacheInfo = getToolcacheDestinationInfo(

View File

@@ -6,6 +6,7 @@ import * as toolcache from "@actions/tool-cache";
import { pki } from "node-forge";
import * as actionsUtil from "./actions-util";
import { getApiDetails, getAuthorizationHeaderFor } from "./api-client";
import { getActionsLogger, Logger } from "./logging";
import {
Credential,
@@ -192,10 +193,16 @@ async function getProxyBinaryPath(logger: Logger): Promise<string> {
let proxyBin = toolcache.find(proxyFileName, proxyInfo.version);
if (!proxyBin) {
const apiDetails = getApiDetails();
const authorization = getAuthorizationHeaderFor(
logger,
apiDetails,
proxyInfo.url,
);
const temp = await toolcache.downloadTool(
proxyInfo.url,
undefined,
undefined,
authorization,
{
accept: "application/octet-stream",
},