renovate 44.60.0 → 44.60.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/options/index.js +5 -3
- package/dist/config/options/index.js.map +1 -1
- package/dist/config/types.d.ts +10 -0
- package/dist/config/types.js.map +1 -1
- package/dist/config/validation.js +7 -3
- package/dist/config/validation.js.map +1 -1
- package/dist/config-validator.js +4 -1
- package/dist/config-validator.js.map +1 -1
- package/dist/util/host-rules.d.ts +25 -2
- package/dist/util/host-rules.js +62 -5
- package/dist/util/host-rules.js.map +1 -1
- package/dist/workers/global/index.js +7 -2
- package/dist/workers/global/index.js.map +1 -1
- package/dist/workers/global/initialize.js +8 -4
- package/dist/workers/global/initialize.js.map +1 -1
- package/dist/workers/repository/init/filter-allowed-env.js +30 -0
- package/dist/workers/repository/init/filter-allowed-env.js.map +1 -0
- package/dist/workers/repository/init/merge.js +171 -15
- package/dist/workers/repository/init/merge.js.map +1 -1
- package/package.json +1 -1
- package/renovate-schema.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-validator.js","names":["getFileConfig"],"sources":["../lib/config-validator.ts"],"sourcesContent":["#!/usr/bin/env node\nimport 'source-map-support/register.js';\nimport './punycode.cjs';\n\nimport { styleText } from 'node:util';\nimport { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';\nimport { Command, CommanderError } from 'commander';\nimport { dequal } from 'dequal';\nimport { diffLines } from 'diff';\nimport fs from 'fs-extra';\nimport { getConfigFileNames } from './config/app-strings.ts';\nimport { GlobalConfig } from './config/global.ts';\nimport { massageConfig } from './config/massage.ts';\nimport { migrateConfig } from './config/migration.ts';\nimport type { RenovateConfig } from './config/types.ts';\nimport { validateConfig } from './config/validation.ts';\nimport { pkg } from './expose.ts';\nimport { init, logger } from './logger/index.ts';\nimport { getEnv } from './util/env.ts';\nimport { add as addHostRule } from './util/host-rules.ts';\nimport { regEx, regexEngineStatus } from './util/regex.ts';\nimport { getConfig as getFileConfig } from './workers/global/config/parse/file.ts';\nimport { parseConfigs } from './workers/global/config/parse/index.ts';\nimport { getParsedContent } from './workers/global/config/parse/util.ts';\n\nawait init();\n\nconst { pathExists, readFile } = fs;\n\nlet returnVal = 0;\n\n/**\n * Make sure that we've resolved configuration from the different places that Renovate users would expect them to be specified\n *\n * This then allows a `configType=repo` config to i.e. be validated alongside a `config.js` or `env RENOVATE_ALLOWED_COMMANDS=...`\n *\n * Note that we intentionally don't fully initialize Renovate and its modules, as we're not fully running, and it would require a Platform to be configured\n * */\nasync function partiallyGlobalInitialize(): Promise<void> {\n // NOTE that this doesn't allow command-line arguments\n const globalConfig = await parseConfigs(getEnv(), []);\n GlobalConfig.set(globalConfig);\n\n if (globalConfig.hostRules) {\n for (const hostRule of globalConfig.hostRules) {\n addHostRule(hostRule);\n }\n }\n}\n\nasync function validate(\n configType: 'global' | 'repo',\n desc: string,\n config: RenovateConfig,\n strict: boolean,\n isPreset = false,\n): Promise<void> {\n if (config.hostRules) {\n for (const hostRule of config.hostRules) {\n addHostRule(hostRule);\n }\n }\n const { isMigrated, migratedConfig } = migrateConfig(config);\n if (isMigrated) {\n logger.warn(\n {\n oldConfig: config,\n newConfig: migratedConfig,\n },\n 'Config migration necessary',\n );\n const changedObjects = diffLines(\n JSON.stringify(config, null, 2),\n JSON.stringify(migratedConfig, null, 2),\n { ignoreWhitespace: false, newlineIsToken: false },\n );\n const added = styleText('green', '+ ');\n const removed = styleText('red', '- ');\n const msg = changedObjects\n .flatMap((part) => {\n let linePrefix: string;\n if (part.added) {\n linePrefix = added;\n } else if (part.removed) {\n linePrefix = removed;\n } else {\n linePrefix = ' ';\n }\n return part.value\n .split('\\n')\n .filter(isNonEmptyStringAndNotWhitespace)\n .map((line) =>\n line.replace(regEx(/^(?<ws> *)/), `${linePrefix}$<ws>`),\n );\n })\n .join('\\n');\n // oxlint-disable-next-line renovate/logger-static-message -- the multi-line, colorized diff must be interpolated to stay readable; as a metadata field it is JSON-escaped onto one line\n logger.warn(`Config migration diff:\\n${msg}`);\n if (strict) {\n returnVal = 1;\n }\n }\n const massagedConfig = massageConfig(migratedConfig);\n const res = await validateConfig(configType, massagedConfig, isPreset);\n if (res.errors.length) {\n logger.error(\n { file: desc, errors: res.errors },\n 'Found errors in configuration',\n );\n returnVal = 1;\n }\n if (res.warnings.length) {\n logger.warn(\n { file: desc, warnings: res.warnings },\n 'Found errors in configuration',\n );\n returnVal = 1;\n }\n}\n\ninterface PackageJson {\n renovate?: RenovateConfig;\n 'renovate-config'?: Record<string, RenovateConfig>;\n}\n\n(async () => {\n await partiallyGlobalInitialize();\n\n const program = new Command('renovate-config-validator')\n .summary('Validate Renovate configuration files')\n .description(\n `Validate your Renovate configuration (repo config, shared presets or global configuration) files\\n` +\n // oxlint-disable-next-line renovate/no-hardcoded-docs-url -- CLI help text, no config available\n 'If no [config-files...] are given, renovate-config-validator will look at the default config file locations (https://docs.renovatebot.com/configuration-options/)',\n )\n .addHelpText(\n 'after',\n // oxlint-disable-next-line renovate/no-hardcoded-docs-url -- CLI help text, no config available\n `\nWhen specifying [config-files...], Renovate will treat them as global self-hosted configuration files. You can disable this behaviour with --no-global\n\nExamples:\n\n $ renovate-config-validator\n $ renovate-config-validator --strict\n $ renovate-config-validator first_config.json\n $ renovate-config-validator --strict config.js\n $ renovate-config-validator --no-global renovate.json5\n $ env RENOVATE_CONFIG_FILE=obscure-name.json renovate-config-validator\n\nGlobal configuration:\n\nIf you have specified global self-hosted configuration (https://docs.renovatebot.com/self-hosted-configuration/) in environment variables or in a \\`config.js\\`, this will be detected:\n\n $ env RENOVATE_ALLOWED_ENV='[\"GO*\"]' renovate-config-validator\n # if passing the filename, make sure it's not validating as a global config\n $ env RENOVATE_ALLOWED_ENV='[\"GO*\"]' renovate-config-validator --no-global renovate.json`,\n )\n .argument('[config-files...]')\n .version(pkg.version, '-v, --version')\n .option(\n '--strict',\n 'Fail command if any configuration warnings, errors, or a migration is needed',\n )\n .option(\n '--no-global',\n 'When specifying [config-files], do not treat them as global self-hosted configuration file(s)',\n true,\n )\n // allow us to manage the exit code\n .exitOverride();\n\n program.action(async (files, opts) => {\n const strict = opts.strict ?? false;\n let filesValidated = 0;\n\n // without RE2, patterns are checked by RegExp, which accepts syntax RE2 rejects (e.g. lookahead)\n if (regexEngineStatus.type === 'unavailable') {\n logger.warn(\n { err: regexEngineStatus.err },\n 'RE2 not usable, falling back to RegExp: regex validation may be inaccurate',\n );\n } else if (regexEngineStatus.type === 'ignored') {\n logger.debug(\n 'RE2 ignored via RENOVATE_X_IGNORE_RE2: regex validation may be inaccurate',\n );\n }\n\n if (files.length) {\n let isGlobalConfig = true;\n if (opts.global === false) {\n isGlobalConfig = false;\n }\n const configType = isGlobalConfig ? 'global' : 'repo';\n for (const file of files) {\n try {\n if (!(await pathExists(file))) {\n returnVal = 1;\n logger.error({ file }, 'File does not exist');\n break;\n }\n const parsedContent = await getParsedContent(file);\n try {\n logger.info(`Validating ${file} as ${configType} config`);\n await validate(configType, file, parsedContent, strict);\n } catch (err) {\n logger.warn({ file, err }, 'File is not valid Renovate config');\n returnVal = 1;\n }\n } catch (err) {\n logger.warn({ file, err }, 'File could not be parsed');\n returnVal = 1;\n }\n\n filesValidated++;\n }\n } else {\n for (const file of getConfigFileNames().filter(\n (name) => name !== 'package.json',\n )) {\n try {\n if (!(await pathExists(file))) {\n continue;\n }\n const parsedContent = await getParsedContent(file);\n try {\n logger.info(`Validating ${file}`);\n await validate('repo', file, parsedContent, strict);\n } catch (err) {\n logger.warn({ file, err }, 'File is not valid Renovate config');\n returnVal = 1;\n }\n } catch (err) {\n logger.warn({ file, err }, 'File could not be parsed');\n returnVal = 1;\n }\n\n filesValidated++;\n }\n try {\n const pkgJson = JSON.parse(\n await readFile('package.json', 'utf8'),\n ) as PackageJson;\n if (pkgJson.renovate) {\n logger.info(`Validating package.json > renovate`);\n await validate(\n 'repo',\n 'package.json > renovate',\n pkgJson.renovate,\n strict,\n );\n\n filesValidated++;\n }\n if (pkgJson['renovate-config']) {\n logger.info(`Validating package.json > renovate-config`);\n for (const presetConfig of Object.values(\n pkgJson['renovate-config'],\n )) {\n await validate(\n 'repo',\n 'package.json > renovate-config',\n presetConfig,\n strict,\n true,\n );\n\n filesValidated++;\n }\n }\n } catch {\n // ignore\n }\n try {\n const env = getEnv();\n const fileConfig = await getFileConfig(env);\n if (!dequal(fileConfig, {})) {\n const file = env.RENOVATE_CONFIG_FILE ?? 'config.js';\n logger.info(`Validating ${file}`);\n try {\n await validate('global', file, fileConfig, strict);\n } catch (err) {\n logger.error({ file, err }, 'File is not valid Renovate config');\n returnVal = 1;\n }\n filesValidated++;\n }\n } catch {\n // ignore\n }\n }\n if (returnVal === 0 && filesValidated) {\n logger.info(\n `Config validated successfully against ${filesValidated} file(s)`,\n );\n } else if (!filesValidated) {\n logger.warn(`No files to perform configuration validation against`);\n }\n // Use exitCode (not process.exit) so async log streams can flush\n process.exitCode = returnVal;\n });\n\n await program.parseAsync();\n})().catch((e) => {\n // Commander throws an error at the end of Action execution i.e. as part of the `help` and `version` commands, and so we don't want to return an error code in this case\n if (\n e instanceof CommanderError &&\n (e.code === 'commander.helpDisplayed' || e.code === 'commander.version')\n ) {\n return;\n }\n\n // oxlint-disable-next-line no-console -- intentional: display critical error on CLI\n console.error(e);\n process.exit(99);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,KAAK;AAEX,MAAM,EAAE,YAAY,aAAa;AAEjC,IAAI,YAAY;;;;;;;;AAShB,eAAe,4BAA2C;CAExD,MAAM,eAAe,MAAM,aAAa,OAAO,GAAG,CAAC,CAAC;CACpD,aAAa,IAAI,YAAY;CAE7B,IAAI,aAAa,WACf,KAAK,MAAM,YAAY,aAAa,WAClC,IAAY,QAAQ;AAG1B;AAEA,eAAe,SACb,YACA,MACA,QACA,QACA,WAAW,OACI;CACf,IAAI,OAAO,WACT,KAAK,MAAM,YAAY,OAAO,WAC5B,IAAY,QAAQ;CAGxB,MAAM,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Y;KACd;IACF,SAAS,KAAK;KACZ,OAAO,KAAK;MAAE;MAAM;KAAI,GAAG,0BAA0B;KACrD,YAAY;IACd;IAEA;GACF;GACA,IAAI;IACF,MAAM,UAAU,KAAK,MACnB,MAAM,SAAS,gBAAgB,MAAM,CACvC;IACA,IAAI,QAAQ,UAAU;KACpB,OAAO,KAAK,oCAAoC;KAChD,MAAM,SACJ,QACA,2BACA,QAAQ,UACR,MACF;KAEA;IACF;IACA,IAAI,QAAQ,oBAAoB;KAC9B,OAAO,KAAK,2CAA2C;KACvD,KAAK,MAAM,gBAAgB,OAAO,OAChC,QAAQ,kBACV,GAAG;MACD,MAAM,SACJ,QACA,kCACA,cACA,QACA,IACF;MAEA;KACF;IACF;GACF,QAAQ,CAER;GACA,IAAI;IACF,MAAM,MAAM,OAAO;IACnB,MAAM,aAAa,MAAMA,UAAc,GAAG;IAC1C,IAAI,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG;KAC3B,MAAM,OAAO,IAAI,wBAAwB;KACzC,OAAO,KAAK,cAAc,MAAM;KAChC,IAAI;MACF,MAAM,SAAS,UAAU,MAAM,YAAY,MAAM;KACnD,SAAS,KAAK;MACZ,OAAO,MAAM;OAAE;OAAM;MAAI,GAAG,mCAAmC;MAC/D,YAAY;KACd;KACA;IACF;GACF,QAAQ,CAER;EACF;EACA,IAAI,cAAc,KAAK,gBACrB,OAAO,KACL,yCAAyC,eAAe,SAC1D;OACK,IAAI,CAAC,gBACV,OAAO,KAAK,sDAAsD;EAGpE,QAAQ,WAAW;CACrB,CAAC;CAED,MAAM,QAAQ,WAAW;AAC3B,EAAA,CAAG,CAAC,CAAC,OAAO,MAAM;CAEhB,IACE,aAAa,mBACZ,EAAE,SAAS,6BAA6B,EAAE,SAAS,sBAEpD;CAIF,QAAQ,MAAM,CAAC;CACf,QAAQ,KAAK,EAAE;AACjB,CAAC"}
|
|
1
|
+
{"version":3,"file":"config-validator.js","names":["getFileConfig"],"sources":["../lib/config-validator.ts"],"sourcesContent":["#!/usr/bin/env node\nimport 'source-map-support/register.js';\nimport './punycode.cjs';\n\nimport { styleText } from 'node:util';\nimport { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';\nimport { Command, CommanderError } from 'commander';\nimport { dequal } from 'dequal';\nimport { diffLines } from 'diff';\nimport fs from 'fs-extra';\nimport { getConfigFileNames } from './config/app-strings.ts';\nimport { GlobalConfig } from './config/global.ts';\nimport { massageConfig } from './config/massage.ts';\nimport { migrateConfig } from './config/migration.ts';\nimport type { AllConfig, RenovateConfig } from './config/types.ts';\nimport { validateConfig } from './config/validation.ts';\nimport { pkg } from './expose.ts';\nimport { init, logger } from './logger/index.ts';\nimport { getEnv } from './util/env.ts';\nimport { add as addHostRule } from './util/host-rules.ts';\nimport { regEx, regexEngineStatus } from './util/regex.ts';\nimport { getConfig as getFileConfig } from './workers/global/config/parse/file.ts';\nimport { parseConfigs } from './workers/global/config/parse/index.ts';\nimport { getParsedContent } from './workers/global/config/parse/util.ts';\n\nawait init();\n\nconst { pathExists, readFile } = fs;\n\nlet returnVal = 0;\n\n/**\n * Make sure that we've resolved configuration from the different places that Renovate users would expect them to be specified\n *\n * This then allows a `configType=repo` config to i.e. be validated alongside a `config.js` or `env RENOVATE_ALLOWED_COMMANDS=...`\n *\n * Note that we intentionally don't fully initialize Renovate and its modules, as we're not fully running, and it would require a Platform to be configured\n * */\nasync function partiallyGlobalInitialize(): Promise<void> {\n // NOTE that this doesn't allow command-line arguments\n const globalConfig = await parseConfigs(getEnv(), []);\n GlobalConfig.set(globalConfig);\n\n if (globalConfig.hostRules) {\n // the self-hosted admin's own headers get no exemption from `allowedHeaders` either, as `applyHostRule` filters the rule it matches by header name alone whoever set it - so `addHostRule` drops them here too, with a WARN, rather than leave them to be silently discarded at request time\n for (const hostRule of globalConfig.hostRules) {\n addHostRule(hostRule);\n }\n }\n}\n\nasync function validate(\n configType: 'global' | 'repo',\n desc: string,\n config: RenovateConfig,\n strict: boolean,\n isPreset = false,\n): Promise<void> {\n if (config.hostRules) {\n // `allowedHeaders` enforces the checks regardless of whether it's global self-hosted administrator config, or repo config\n // a global config file being validated brings its own `allowedHeaders`, and should be validated against it, like a real run would after parsing it\n const allowedHeaders =\n configType === 'global'\n ? ((config as AllConfig).allowedHeaders ??\n GlobalConfig.get('allowedHeaders'))\n : GlobalConfig.get('allowedHeaders');\n for (const hostRule of config.hostRules) {\n addHostRule(hostRule, { allowedHeaders });\n }\n }\n const { isMigrated, migratedConfig } = migrateConfig(config);\n if (isMigrated) {\n logger.warn(\n {\n oldConfig: config,\n newConfig: migratedConfig,\n },\n 'Config migration necessary',\n );\n const changedObjects = diffLines(\n JSON.stringify(config, null, 2),\n JSON.stringify(migratedConfig, null, 2),\n { ignoreWhitespace: false, newlineIsToken: false },\n );\n const added = styleText('green', '+ ');\n const removed = styleText('red', '- ');\n const msg = changedObjects\n .flatMap((part) => {\n let linePrefix: string;\n if (part.added) {\n linePrefix = added;\n } else if (part.removed) {\n linePrefix = removed;\n } else {\n linePrefix = ' ';\n }\n return part.value\n .split('\\n')\n .filter(isNonEmptyStringAndNotWhitespace)\n .map((line) =>\n line.replace(regEx(/^(?<ws> *)/), `${linePrefix}$<ws>`),\n );\n })\n .join('\\n');\n // oxlint-disable-next-line renovate/logger-static-message -- the multi-line, colorized diff must be interpolated to stay readable; as a metadata field it is JSON-escaped onto one line\n logger.warn(`Config migration diff:\\n${msg}`);\n if (strict) {\n returnVal = 1;\n }\n }\n const massagedConfig = massageConfig(migratedConfig);\n const res = await validateConfig(configType, massagedConfig, isPreset);\n if (res.errors.length) {\n logger.error(\n { file: desc, errors: res.errors },\n 'Found errors in configuration',\n );\n returnVal = 1;\n }\n if (res.warnings.length) {\n logger.warn(\n { file: desc, warnings: res.warnings },\n 'Found errors in configuration',\n );\n returnVal = 1;\n }\n}\n\ninterface PackageJson {\n renovate?: RenovateConfig;\n 'renovate-config'?: Record<string, RenovateConfig>;\n}\n\n(async () => {\n await partiallyGlobalInitialize();\n\n const program = new Command('renovate-config-validator')\n .summary('Validate Renovate configuration files')\n .description(\n `Validate your Renovate configuration (repo config, shared presets or global configuration) files\\n` +\n // oxlint-disable-next-line renovate/no-hardcoded-docs-url -- CLI help text, no config available\n 'If no [config-files...] are given, renovate-config-validator will look at the default config file locations (https://docs.renovatebot.com/configuration-options/)',\n )\n .addHelpText(\n 'after',\n // oxlint-disable-next-line renovate/no-hardcoded-docs-url -- CLI help text, no config available\n `\nWhen specifying [config-files...], Renovate will treat them as global self-hosted configuration files. You can disable this behaviour with --no-global\n\nExamples:\n\n $ renovate-config-validator\n $ renovate-config-validator --strict\n $ renovate-config-validator first_config.json\n $ renovate-config-validator --strict config.js\n $ renovate-config-validator --no-global renovate.json5\n $ env RENOVATE_CONFIG_FILE=obscure-name.json renovate-config-validator\n\nGlobal configuration:\n\nIf you have specified global self-hosted configuration (https://docs.renovatebot.com/self-hosted-configuration/) in environment variables or in a \\`config.js\\`, this will be detected:\n\n $ env RENOVATE_ALLOWED_ENV='[\"GO*\"]' renovate-config-validator\n # if passing the filename, make sure it's not validating as a global config\n $ env RENOVATE_ALLOWED_ENV='[\"GO*\"]' renovate-config-validator --no-global renovate.json`,\n )\n .argument('[config-files...]')\n .version(pkg.version, '-v, --version')\n .option(\n '--strict',\n 'Fail command if any configuration warnings, errors, or a migration is needed',\n )\n .option(\n '--no-global',\n 'When specifying [config-files], do not treat them as global self-hosted configuration file(s)',\n true,\n )\n // allow us to manage the exit code\n .exitOverride();\n\n program.action(async (files, opts) => {\n const strict = opts.strict ?? false;\n let filesValidated = 0;\n\n // without RE2, patterns are checked by RegExp, which accepts syntax RE2 rejects (e.g. lookahead)\n if (regexEngineStatus.type === 'unavailable') {\n logger.warn(\n { err: regexEngineStatus.err },\n 'RE2 not usable, falling back to RegExp: regex validation may be inaccurate',\n );\n } else if (regexEngineStatus.type === 'ignored') {\n logger.debug(\n 'RE2 ignored via RENOVATE_X_IGNORE_RE2: regex validation may be inaccurate',\n );\n }\n\n if (files.length) {\n let isGlobalConfig = true;\n if (opts.global === false) {\n isGlobalConfig = false;\n }\n const configType = isGlobalConfig ? 'global' : 'repo';\n for (const file of files) {\n try {\n if (!(await pathExists(file))) {\n returnVal = 1;\n logger.error({ file }, 'File does not exist');\n break;\n }\n const parsedContent = await getParsedContent(file);\n try {\n logger.info(`Validating ${file} as ${configType} config`);\n await validate(configType, file, parsedContent, strict);\n } catch (err) {\n logger.warn({ file, err }, 'File is not valid Renovate config');\n returnVal = 1;\n }\n } catch (err) {\n logger.warn({ file, err }, 'File could not be parsed');\n returnVal = 1;\n }\n\n filesValidated++;\n }\n } else {\n for (const file of getConfigFileNames().filter(\n (name) => name !== 'package.json',\n )) {\n try {\n if (!(await pathExists(file))) {\n continue;\n }\n const parsedContent = await getParsedContent(file);\n try {\n logger.info(`Validating ${file}`);\n await validate('repo', file, parsedContent, strict);\n } catch (err) {\n logger.warn({ file, err }, 'File is not valid Renovate config');\n returnVal = 1;\n }\n } catch (err) {\n logger.warn({ file, err }, 'File could not be parsed');\n returnVal = 1;\n }\n\n filesValidated++;\n }\n try {\n const pkgJson = JSON.parse(\n await readFile('package.json', 'utf8'),\n ) as PackageJson;\n if (pkgJson.renovate) {\n logger.info(`Validating package.json > renovate`);\n await validate(\n 'repo',\n 'package.json > renovate',\n pkgJson.renovate,\n strict,\n );\n\n filesValidated++;\n }\n if (pkgJson['renovate-config']) {\n logger.info(`Validating package.json > renovate-config`);\n for (const presetConfig of Object.values(\n pkgJson['renovate-config'],\n )) {\n await validate(\n 'repo',\n 'package.json > renovate-config',\n presetConfig,\n strict,\n true,\n );\n\n filesValidated++;\n }\n }\n } catch {\n // ignore\n }\n try {\n const env = getEnv();\n const fileConfig = await getFileConfig(env);\n if (!dequal(fileConfig, {})) {\n const file = env.RENOVATE_CONFIG_FILE ?? 'config.js';\n logger.info(`Validating ${file}`);\n try {\n await validate('global', file, fileConfig, strict);\n } catch (err) {\n logger.error({ file, err }, 'File is not valid Renovate config');\n returnVal = 1;\n }\n filesValidated++;\n }\n } catch {\n // ignore\n }\n }\n if (returnVal === 0 && filesValidated) {\n logger.info(\n `Config validated successfully against ${filesValidated} file(s)`,\n );\n } else if (!filesValidated) {\n logger.warn(`No files to perform configuration validation against`);\n }\n // Use exitCode (not process.exit) so async log streams can flush\n process.exitCode = returnVal;\n });\n\n await program.parseAsync();\n})().catch((e) => {\n // Commander throws an error at the end of Action execution i.e. as part of the `help` and `version` commands, and so we don't want to return an error code in this case\n if (\n e instanceof CommanderError &&\n (e.code === 'commander.helpDisplayed' || e.code === 'commander.version')\n ) {\n return;\n }\n\n // oxlint-disable-next-line no-console -- intentional: display critical error on CLI\n console.error(e);\n process.exit(99);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,KAAK;AAEX,MAAM,EAAE,YAAY,aAAa;AAEjC,IAAI,YAAY;;;;;;;;AAShB,eAAe,4BAA2C;CAExD,MAAM,eAAe,MAAM,aAAa,OAAO,GAAG,CAAC,CAAC;CACpD,aAAa,IAAI,YAAY;CAE7B,IAAI,aAAa,WAEf,KAAK,MAAM,YAAY,aAAa,WAClC,IAAY,QAAQ;AAG1B;AAEA,eAAe,SACb,YACA,MACA,QACA,QACA,WAAW,OACI;CACf,IAAI,OAAO,WAAW;EAGpB,MAAM,iBACJ,eAAe,WACT,OAAqB,kBACvB,aAAa,IAAI,gBAAgB,IACjC,aAAa,IAAI,gBAAgB;EACvC,KAAK,MAAM,YAAY,OAAO,WAC5B,IAAY,UAAU,EAAE,eAAe,CAAC;CAE5C;CACA,MAAM,EAAE,YAAY,mBAAmB,cAAc,MAAM;CAC3D,IAAI,YAAY;EACd,OAAO,KACL;GACE,WAAW;GACX,WAAW;EACb,GACA,4BACF;EACA,MAAM,iBAAiB,UACrB,KAAK,UAAU,QAAQ,MAAM,CAAC,GAC9B,KAAK,UAAU,gBAAgB,MAAM,CAAC,GACtC;GAAE,kBAAkB;GAAO,gBAAgB;EAAM,CACnD;EACA,MAAM,QAAQ,UAAU,SAAS,I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F;IACA,IAAI,QAAQ,oBAAoB;KAC9B,OAAO,KAAK,2CAA2C;KACvD,KAAK,MAAM,gBAAgB,OAAO,OAChC,QAAQ,kBACV,GAAG;MACD,MAAM,SACJ,QACA,kCACA,cACA,QACA,IACF;MAEA;KACF;IACF;GACF,QAAQ,CAER;GACA,IAAI;IACF,MAAM,MAAM,OAAO;IACnB,MAAM,aAAa,MAAMA,UAAc,GAAG;IAC1C,IAAI,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG;KAC3B,MAAM,OAAO,IAAI,wBAAwB;KACzC,OAAO,KAAK,cAAc,MAAM;KAChC,IAAI;MACF,MAAM,SAAS,UAAU,MAAM,YAAY,MAAM;KACnD,SAAS,KAAK;MACZ,OAAO,MAAM;OAAE;OAAM;MAAI,GAAG,mCAAmC;MAC/D,YAAY;KACd;KACA;IACF;GACF,QAAQ,CAER;EACF;EACA,IAAI,cAAc,KAAK,gBACrB,OAAO,KACL,yCAAyC,eAAe,SAC1D;OACK,IAAI,CAAC,gBACV,OAAO,KAAK,sDAAsD;EAGpE,QAAQ,WAAW;CACrB,CAAC;CAED,MAAM,QAAQ,WAAW;AAC3B,EAAA,CAAG,CAAC,CAAC,OAAO,MAAM;CAEhB,IACE,aAAa,mBACZ,EAAE,SAAS,6BAA6B,EAAE,SAAS,sBAEpD;CAIF,QAAQ,MAAM,CAAC;CACf,QAAQ,KAAK,EAAE;AACjB,CAAC"}
|
|
@@ -15,7 +15,30 @@ interface LegacyHostRule {
|
|
|
15
15
|
endpoint?: string;
|
|
16
16
|
}
|
|
17
17
|
declare function migrateRule(rule: LegacyHostRule & HostRule): HostRule;
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Enforce the `allowedHeaders` allowlist on a set of host rules.
|
|
20
|
+
*
|
|
21
|
+
* Loudly remove anything that's not permitted, logging a WARN.
|
|
22
|
+
*
|
|
23
|
+
* `add()` applies this to every rule it registers, so callers only need it themselves to pre-filter - e.g. to avoid repeating the WARN when the same rules are registered again and again.
|
|
24
|
+
*
|
|
25
|
+
* @param [allowedHeaders] the effective allowlist. Defaults to `GlobalConfig`, but must be passed explicitly when filtering before `GlobalConfig` reflects the repository being processed, i.e. for a `repositories[]` entry's own `allowedHeaders` override
|
|
26
|
+
* @param [warnOnDenied=true] whether to log the WARN. Pass `false` where the very same rules are filtered again, so that it is logged once rather than repeated
|
|
27
|
+
*
|
|
28
|
+
* Headers that survive this allowlist are still subject to how {@link find} combines them: an admin's headers for a host are applied over those of any repository or preset rule matching the same request, so a repository can neither drop nor substitute them.
|
|
29
|
+
*/
|
|
30
|
+
declare function filterAllowedHeaders(rules: HostRule[], allowedHeaders?: string[], warnOnDenied?: boolean): HostRule[];
|
|
31
|
+
interface AddHostRuleOptions {
|
|
32
|
+
/** the effective allowlist. Defaults to `GlobalConfig`; pass it explicitly when `GlobalConfig` does not yet reflect the repository the rule is registered for */
|
|
33
|
+
allowedHeaders?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Whether this rule comes from the self-hosted administrator's own global config, rather than from repository or preset config.
|
|
36
|
+
*
|
|
37
|
+
* Only affects how `headers` are combined (see {@link find}), and is deliberately opt-in: a caller that says nothing registers into the untrusted tier, so a new call site cannot grant itself the administrator's precedence by omission.
|
|
38
|
+
*/
|
|
39
|
+
trusted?: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare function add(params: HostRule, options?: AddHostRuleOptions): void;
|
|
19
42
|
interface HostRuleSearch {
|
|
20
43
|
hostType?: string;
|
|
21
44
|
url?: string;
|
|
@@ -38,5 +61,5 @@ declare function findAll({ hostType }: {
|
|
|
38
61
|
declare function getAll(): HostRule[];
|
|
39
62
|
declare function clear(): void;
|
|
40
63
|
//#endregion
|
|
41
|
-
export { HostRuleSearch, LegacyHostRule, add, clear, confidentialFields, find, findAll, getAll, hostType, hosts, matchesHost, migrateRule };
|
|
64
|
+
export { AddHostRuleOptions, HostRuleSearch, LegacyHostRule, add, clear, confidentialFields, filterAllowedHeaders, find, findAll, getAll, hostType, hosts, matchesHost, migrateRule };
|
|
42
65
|
//# sourceMappingURL=host-rules.d.ts.map
|
package/dist/util/host-rules.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GlobalConfig } from "../config/global.js";
|
|
2
|
+
import { matchRegexOrGlobList } from "./string-match.js";
|
|
1
3
|
import { toBase64 } from "./string.js";
|
|
2
4
|
import { addSecretForSanitizing, clearRepoSanitizedSecretsList } from "./sanitize.js";
|
|
3
5
|
import { logger } from "../logger/index.js";
|
|
@@ -38,11 +40,48 @@ function migrateRule(rule) {
|
|
|
38
40
|
} else if (hostValues.length > 1) throw new Error(`hostRules cannot contain more than one host-matching field - use "matchHost" only.`);
|
|
39
41
|
return result;
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Enforce the `allowedHeaders` allowlist on a set of host rules.
|
|
45
|
+
*
|
|
46
|
+
* Loudly remove anything that's not permitted, logging a WARN.
|
|
47
|
+
*
|
|
48
|
+
* `add()` applies this to every rule it registers, so callers only need it themselves to pre-filter - e.g. to avoid repeating the WARN when the same rules are registered again and again.
|
|
49
|
+
*
|
|
50
|
+
* @param [allowedHeaders] the effective allowlist. Defaults to `GlobalConfig`, but must be passed explicitly when filtering before `GlobalConfig` reflects the repository being processed, i.e. for a `repositories[]` entry's own `allowedHeaders` override
|
|
51
|
+
* @param [warnOnDenied=true] whether to log the WARN. Pass `false` where the very same rules are filtered again, so that it is logged once rather than repeated
|
|
52
|
+
*
|
|
53
|
+
* Headers that survive this allowlist are still subject to how {@link find} combines them: an admin's headers for a host are applied over those of any repository or preset rule matching the same request, so a repository can neither drop nor substitute them.
|
|
54
|
+
*/
|
|
55
|
+
function filterAllowedHeaders(rules, allowedHeaders, warnOnDenied = true) {
|
|
56
|
+
const allowlist = allowedHeaders ?? GlobalConfig.get("allowedHeaders");
|
|
57
|
+
const denied = [];
|
|
58
|
+
const result = rules.map((rule) => {
|
|
59
|
+
if (!rule.headers) return rule;
|
|
60
|
+
const allowed = {};
|
|
61
|
+
const ruleDenied = [];
|
|
62
|
+
for (const [name, value] of Object.entries(rule.headers)) if (matchRegexOrGlobList(name, allowlist)) allowed[name] = value;
|
|
63
|
+
else ruleDenied.push(name);
|
|
64
|
+
if (!ruleDenied.length) return rule;
|
|
65
|
+
denied.push(...ruleDenied);
|
|
66
|
+
const filtered = {
|
|
67
|
+
...rule,
|
|
68
|
+
headers: allowed
|
|
69
|
+
};
|
|
70
|
+
if (!Object.keys(allowed).length) delete filtered.headers;
|
|
71
|
+
return filtered;
|
|
72
|
+
});
|
|
73
|
+
if (denied.length && warnOnDenied) logger.warn({ denied }, "Ignoring hostRules headers not permitted by this Renovate instance's `allowedHeaders`");
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function add(params, options) {
|
|
77
|
+
let rule = migrateRule(params);
|
|
78
|
+
delete rule.trusted;
|
|
79
|
+
if (options?.trusted) rule.trusted = true;
|
|
80
|
+
if (rule.headers) [rule] = filterAllowedHeaders([rule], options?.allowedHeaders);
|
|
43
81
|
if (rule.matchHost) {
|
|
44
82
|
rule.matchHost = massageHostUrl(rule.matchHost);
|
|
45
|
-
|
|
83
|
+
const parsedUrl = parseUrl(rule.matchHost);
|
|
84
|
+
rule.resolvedHost = parsedUrl?.hostname ?? rule.matchHost;
|
|
46
85
|
confidentialFields.forEach((field) => {
|
|
47
86
|
if (rule[field]) logger.debug(`Adding ${field} authentication for ${rule.matchHost} (hostType=${rule.hostType}) to hostRules`);
|
|
48
87
|
});
|
|
@@ -78,12 +117,23 @@ function hostRuleRank({ hostType, matchHost, readOnly }) {
|
|
|
78
117
|
function fromLowerToHigherRank(a, b) {
|
|
79
118
|
return hostRuleRank(a) - hostRuleRank(b);
|
|
80
119
|
}
|
|
120
|
+
function fromLowerRankAndShorterMatchHost(a, b) {
|
|
121
|
+
return fromLowerToHigherRank(a, b) || fromShorterToLongerMatchHost(a, b);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The `headers` that apply from a set of matching rules of the same trust tier.
|
|
125
|
+
*
|
|
126
|
+
* The last rule to set any wins outright, as `find()`'s callers receive them sorted from least to most specific. That is the behaviour every matching rule had before `headers` were combined across tiers, and it is what lets a broad rule's headers be masked by a narrower rule from the same source.
|
|
127
|
+
*/
|
|
128
|
+
function headersOfLastRuleToSetThem(rules) {
|
|
129
|
+
return rules.map((rule) => rule.headers).filter(isTruthy).pop();
|
|
130
|
+
}
|
|
81
131
|
function find(search) {
|
|
82
132
|
if ([search.hostType, search.url].every(isFalsy)) {
|
|
83
133
|
logger.warn({ search }, "Invalid hostRules search");
|
|
84
134
|
return {};
|
|
85
135
|
}
|
|
86
|
-
const sortedRules = hostRules.sort(
|
|
136
|
+
const sortedRules = hostRules.sort(fromLowerRankAndShorterMatchHost);
|
|
87
137
|
const matchedRules = [];
|
|
88
138
|
for (const rule of sortedRules) {
|
|
89
139
|
let hostTypeMatch = true;
|
|
@@ -109,10 +159,17 @@ function find(search) {
|
|
|
109
159
|
if (hostTypeMatch && readOnlyMatch && hostMatch) matchedRules.push(clone(rule));
|
|
110
160
|
}
|
|
111
161
|
const res = Object.assign({}, ...matchedRules);
|
|
162
|
+
const untrustedHeaders = headersOfLastRuleToSetThem(matchedRules.filter((rule) => !rule.trusted));
|
|
163
|
+
const trustedHeaders = headersOfLastRuleToSetThem(matchedRules.filter((rule) => rule.trusted));
|
|
164
|
+
if (untrustedHeaders ?? trustedHeaders) res.headers = {
|
|
165
|
+
...untrustedHeaders,
|
|
166
|
+
...trustedHeaders
|
|
167
|
+
};
|
|
112
168
|
delete res.hostType;
|
|
113
169
|
delete res.resolvedHost;
|
|
114
170
|
delete res.matchHost;
|
|
115
171
|
delete res.readOnly;
|
|
172
|
+
delete res.trusted;
|
|
116
173
|
return res;
|
|
117
174
|
}
|
|
118
175
|
function hosts({ hostType }) {
|
|
@@ -136,6 +193,6 @@ function clear() {
|
|
|
136
193
|
clearRepoSanitizedSecretsList();
|
|
137
194
|
}
|
|
138
195
|
//#endregion
|
|
139
|
-
export { add, clear, confidentialFields, find, findAll, getAll, hostType, hosts, matchesHost, migrateRule };
|
|
196
|
+
export { add, clear, confidentialFields, filterAllowedHeaders, find, findAll, getAll, hostType, hosts, matchesHost, migrateRule };
|
|
140
197
|
|
|
141
198
|
//# sourceMappingURL=host-rules.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-rules.js","names":[],"sources":["../../lib/util/host-rules.ts"],"sourcesContent":["import { isFalsy, isString, isTruthy, isUndefined } from '@sindresorhus/is';\nimport { logger } from '../logger/index.ts';\nimport type { CombinedHostRule, HostRule } from '../types/index.ts';\nimport { clone } from './clone.ts';\nimport * as sanitize from './sanitize.ts';\nimport { toBase64 } from './string.ts';\nimport { isHttpUrl, massageHostUrl, parseUrl } from './url.ts';\n\nlet hostRules: HostRule[] = [];\n\n/**\n * Fields within `HostRule`s that must have their value registered for sanitising through `sanitize.addSecretForSanitizing()`.\n *\n * Kept in sync with `redactedFields` through tests.\n */\nexport const confidentialFields: (keyof HostRule)[] = [\n 'password',\n 'token',\n 'httpsPrivateKey',\n /* not actually sensitive, but redacted nonetheless */\n 'httpsCertificate',\n /* not actually sensitive, but redacted nonetheless */\n 'httpsCertificateAuthority',\n];\n\nexport interface LegacyHostRule {\n hostName?: string;\n domainName?: string;\n baseUrl?: string;\n host?: string;\n endpoint?: string;\n}\n\nexport function migrateRule(rule: LegacyHostRule & HostRule): HostRule {\n const cloned: LegacyHostRule & HostRule = clone(rule);\n delete cloned.hostName;\n delete cloned.domainName;\n delete cloned.baseUrl;\n const result: HostRule = cloned;\n\n const { matchHost } = result;\n const { hostName, domainName, baseUrl } = rule;\n const hostValues = [matchHost, hostName, domainName, baseUrl].filter(\n isTruthy,\n );\n if (hostValues.length === 1) {\n const [matchHost] = hostValues;\n result.matchHost = matchHost;\n } else if (hostValues.length > 1) {\n throw new Error(\n `hostRules cannot contain more than one host-matching field - use \"matchHost\" only.`,\n );\n }\n\n return result;\n}\n\nexport function add(params: HostRule): void {\n const rule = migrateRule(params);\n\n if (rule.matchHost) {\n rule.matchHost = massageHostUrl(rule.matchHost);\n const parsedUrl = parseUrl(rule.matchHost);\n rule.resolvedHost = parsedUrl?.hostname ?? rule.matchHost;\n confidentialFields.forEach((field) => {\n if (rule[field]) {\n logger.debug(\n // TODO: types (#22198)\n `Adding ${field} authentication for ${rule.matchHost!} (hostType=${\n rule.hostType\n }) to hostRules`,\n );\n }\n });\n }\n confidentialFields.forEach((field) => {\n const secret = rule[field];\n if (isString(secret) && secret.length > 3) {\n sanitize.addSecretForSanitizing(secret);\n }\n });\n if (rule.username && rule.password) {\n sanitize.addSecretForSanitizing(\n toBase64(`${rule.username}:${rule.password}`),\n );\n }\n hostRules.push(rule);\n}\n\nexport interface HostRuleSearch {\n hostType?: string;\n url?: string;\n readOnly?: boolean;\n}\n\nexport function matchesHost(url: string, matchHost: string): boolean {\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n return false;\n }\n\n const parsedMatchHost = parseUrl(matchHost);\n if (isHttpUrl(parsedUrl) && isHttpUrl(parsedMatchHost)) {\n return parsedUrl.href.startsWith(parsedMatchHost!.href);\n }\n\n const { hostname } = parsedUrl;\n if (!hostname) {\n return false;\n }\n\n if (hostname === matchHost) {\n return true;\n }\n\n const topLevelSuffix = matchHost.startsWith('.')\n ? matchHost\n : `.${matchHost}`;\n return hostname.endsWith(topLevelSuffix);\n}\n\nfunction fromShorterToLongerMatchHost(a: HostRule, b: HostRule): number {\n if (!a.matchHost || !b.matchHost) {\n return 0;\n }\n return a.matchHost.length - b.matchHost.length;\n}\n\nfunction hostRuleRank({ hostType, matchHost, readOnly }: HostRule): number {\n if ((hostType || readOnly) && matchHost) {\n return 3;\n }\n\n if (matchHost) {\n return 2;\n }\n\n if (hostType) {\n return 1;\n }\n\n return 0;\n}\n\nfunction fromLowerToHigherRank(a: HostRule, b: HostRule): number {\n return hostRuleRank(a) - hostRuleRank(b);\n}\n\nexport function find(search: HostRuleSearch): CombinedHostRule {\n if ([search.hostType, search.url].every(isFalsy)) {\n logger.warn({ search }, 'Invalid hostRules search');\n return {};\n }\n\n // Sort primarily by rank, and secondarily by matchHost length\n const sortedRules = hostRules\n .sort(fromShorterToLongerMatchHost)\n .sort(fromLowerToHigherRank);\n\n const matchedRules: HostRule[] = [];\n for (const rule of sortedRules) {\n let hostTypeMatch = true;\n let hostMatch = true;\n let readOnlyMatch = true;\n\n if (rule.hostType) {\n hostTypeMatch = false;\n // v8 ignore else -- TODO: add test #40625\n if (search.hostType === rule.hostType) {\n hostTypeMatch = true;\n }\n }\n\n if (rule.matchHost && rule.resolvedHost) {\n hostMatch = false;\n if (search.url) {\n hostMatch = matchesHost(search.url, rule.matchHost);\n }\n }\n\n if (!isUndefined(rule.readOnly)) {\n readOnlyMatch = false;\n // v8 ignore else -- TODO: add test #40625\n if (search.readOnly === rule.readOnly) {\n readOnlyMatch = true;\n hostTypeMatch = true; // When we match `readOnly`, we don't care about `hostType`\n }\n }\n\n if (hostTypeMatch && readOnlyMatch && hostMatch) {\n matchedRules.push(clone(rule));\n }\n }\n\n const res: HostRule = Object.assign({}, ...matchedRules);\n delete res.hostType;\n delete res.resolvedHost;\n delete res.matchHost;\n delete res.readOnly;\n return res;\n}\n\nexport function hosts({ hostType }: { hostType: string }): string[] {\n return hostRules\n .filter((rule) => rule.hostType === hostType)\n .map((rule) => rule.resolvedHost)\n .filter(isTruthy);\n}\n\nexport function hostType({ url }: { url: string }): string | null {\n return (\n hostRules\n .filter((rule) => rule.matchHost && matchesHost(url, rule.matchHost))\n .sort(fromShorterToLongerMatchHost)\n .map((rule) => rule.hostType)\n .filter(isTruthy)\n .pop() ?? null\n );\n}\n\nexport function findAll({ hostType }: { hostType: string }): HostRule[] {\n return hostRules.filter((rule) => rule.hostType === hostType);\n}\n\n/**\n * @returns a deep copy of all known host rules without any filtering\n */\nexport function getAll(): HostRule[] {\n return clone(hostRules);\n}\n\nexport function clear(): void {\n logger.debug('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K,QAAQ,GAAG;GAC/B,gBAAgB;;GAEhB,IAAI,OAAO,aAAa,KAAK,UAAU;IACrC,gBAAgB;IAChB,gBAAgB;GAClB;EACF;EAEA,IAAI,iBAAiB,iBAAiB,WACpC,aAAa,KAAK,MAAM,IAAI,CAAC;CAEjC;CAEA,MAAM,MAAgB,OAAO,OAAO,CAAC,GAAG,GAAG,YAAY;CACvD,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO;AACT;AAEA,SAAgB,MAAM,EAAE,YAA4C;CAClE,OAAO,UACJ,QAAQ,SAAS,KAAK,aAAa,QAAQ,CAAC,CAC5C,KAAK,SAAS,KAAK,YAAY,CAAC,CAChC,OAAO,QAAQ;AACpB;AAEA,SAAgB,SAAS,EAAE,OAAuC;CAChE,OACE,UACG,QAAQ,SAAS,KAAK,aAAa,YAAY,KAAK,KAAK,SAAS,CAAC,CAAC,CACpE,KAAK,4BAA4B,CAAC,CAClC,KAAK,SAAS,KAAK,QAAQ,CAAC,CAC5B,OAAO,QAAQ,CAAC,CAChB,IAAI,KAAK;AAEhB;AAEA,SAAgB,QAAQ,EAAE,YAA8C;CACtE,OAAO,UAAU,QAAQ,SAAS,KAAK,aAAa,QAAQ;AAC9D;;;;AAKA,SAAgB,SAAqB;CACnC,OAAO,MAAM,SAAS;AACxB;AAEA,SAAgB,QAAc;CAC5B,OAAO,MAAM,oBAAoB;CACjC,YAAY,CAAC;CACb,8BAAuC;AACzC"}
|
|
1
|
+
{"version":3,"file":"host-rules.js","names":[],"sources":["../../lib/util/host-rules.ts"],"sourcesContent":["import { isFalsy, isString, isTruthy, isUndefined } from '@sindresorhus/is';\nimport { GlobalConfig } from '../config/global.ts';\nimport { logger } from '../logger/index.ts';\nimport type { CombinedHostRule, HostRule } from '../types/index.ts';\nimport { clone } from './clone.ts';\nimport * as sanitize from './sanitize.ts';\nimport { toBase64 } from './string.ts';\nimport { matchRegexOrGlobList } from './string-match.ts';\nimport { isHttpUrl, massageHostUrl, parseUrl } from './url.ts';\n\n/**\n * A host rule as registered through {@link add}.\n *\n * `trusted` is deliberately not a field of `HostRule`: it is set from {@link AddHostRuleOptions} at registration time and must never be settable through configuration.\n */\ninterface RegisteredHostRule extends HostRule {\n /** whether the rule came from the self-hosted administrator's own global config, rather than from repository or preset config */\n trusted?: boolean;\n}\n\nlet hostRules: RegisteredHostRule[] = [];\n\n/**\n * Fields within `HostRule`s that must have their value registered for sanitising through `sanitize.addSecretForSanitizing()`.\n *\n * Kept in sync with `redactedFields` through tests.\n */\nexport const confidentialFields: (keyof HostRule)[] = [\n 'password',\n 'token',\n 'httpsPrivateKey',\n /* not actually sensitive, but redacted nonetheless */\n 'httpsCertificate',\n /* not actually sensitive, but redacted nonetheless */\n 'httpsCertificateAuthority',\n];\n\nexport interface LegacyHostRule {\n hostName?: string;\n domainName?: string;\n baseUrl?: string;\n host?: string;\n endpoint?: string;\n}\n\nexport function migrateRule(rule: LegacyHostRule & HostRule): HostRule {\n const cloned: LegacyHostRule & HostRule = clone(rule);\n delete cloned.hostName;\n delete cloned.domainName;\n delete cloned.baseUrl;\n const result: HostRule = cloned;\n\n const { matchHost } = result;\n const { hostName, domainName, baseUrl } = rule;\n const hostValues = [matchHost, hostName, domainName, baseUrl].filter(\n isTruthy,\n );\n if (hostValues.length === 1) {\n const [matchHost] = hostValues;\n result.matchHost = matchHost;\n } else if (hostValues.length > 1) {\n throw new Error(\n `hostRules cannot contain more than one host-matching field - use \"matchHost\" only.`,\n );\n }\n\n return result;\n}\n\n/**\n * Enforce the `allowedHeaders` allowlist on a set of host rules.\n *\n * Loudly remove anything that's not permitted, logging a WARN.\n *\n * `add()` applies this to every rule it registers, so callers only need it themselves to pre-filter - e.g. to avoid repeating the WARN when the same rules are registered again and again.\n *\n * @param [allowedHeaders] the effective allowlist. Defaults to `GlobalConfig`, but must be passed explicitly when filtering before `GlobalConfig` reflects the repository being processed, i.e. for a `repositories[]` entry's own `allowedHeaders` override\n * @param [warnOnDenied=true] whether to log the WARN. Pass `false` where the very same rules are filtered again, so that it is logged once rather than repeated\n *\n * Headers that survive this allowlist are still subject to how {@link find} combines them: an admin's headers for a host are applied over those of any repository or preset rule matching the same request, so a repository can neither drop nor substitute them.\n */\nexport function filterAllowedHeaders(\n rules: HostRule[],\n allowedHeaders?: string[],\n warnOnDenied = true,\n): HostRule[] {\n // `??`, rather than a parameter default: a default only applies to `undefined`, and a `null` can reach us from user config\n const allowlist = allowedHeaders ?? GlobalConfig.get('allowedHeaders');\n const denied: string[] = [];\n\n const result = rules.map((rule) => {\n if (!rule.headers) {\n return rule;\n }\n\n const allowed: Record<string, string> = {};\n const ruleDenied: string[] = [];\n for (const [name, value] of Object.entries(rule.headers)) {\n if (matchRegexOrGlobList(name, allowlist)) {\n allowed[name] = value;\n } else {\n ruleDenied.push(name);\n }\n }\n\n if (!ruleDenied.length) {\n return rule;\n }\n denied.push(...ruleDenied);\n\n const filtered: HostRule = { ...rule, headers: allowed };\n if (!Object.keys(allowed).length) {\n // drop the key rather than leave an empty object behind: `find()` treats any rule that sets `headers` as replacing the headers of the broader rules of its own tier, so a rule left with none would suppress them\n delete filtered.headers;\n }\n return filtered;\n });\n\n if (denied.length && warnOnDenied) {\n logger.warn(\n { denied },\n \"Ignoring hostRules headers not permitted by this Renovate instance's `allowedHeaders`\",\n );\n }\n return result;\n}\n\nexport interface AddHostRuleOptions {\n /** the effective allowlist. Defaults to `GlobalConfig`; pass it explicitly when `GlobalConfig` does not yet reflect the repository the rule is registered for */\n allowedHeaders?: string[];\n\n /**\n * Whether this rule comes from the self-hosted administrator's own global config, rather than from repository or preset config.\n *\n * Only affects how `headers` are combined (see {@link find}), and is deliberately opt-in: a caller that says nothing registers into the untrusted tier, so a new call site cannot grant itself the administrator's precedence by omission.\n */\n trusted?: boolean;\n}\n\nexport function add(params: HostRule, options?: AddHostRuleOptions): void {\n let rule: RegisteredHostRule = migrateRule(params);\n\n // set only from `options`, and dropped first so that it cannot be carried over from `params`: `HostRule` has no `trusted` field, but configuration is parsed from JSON, so a repository could otherwise smuggle one in and have its headers treated as the administrator's\n delete rule.trusted;\n if (options?.trusted) {\n rule.trusted = true;\n }\n\n if (rule.headers) {\n // enforced here, at the single registration chokepoint, so that no current or future caller can register a rule whose headers bypass `allowedHeaders`; `applyHostRule` filters by header name again at request time as defence in depth\n [rule] = filterAllowedHeaders([rule], options?.allowedHeaders);\n }\n\n if (rule.matchHost) {\n rule.matchHost = massageHostUrl(rule.matchHost);\n const parsedUrl = parseUrl(rule.matchHost);\n rule.resolvedHost = parsedUrl?.hostname ?? rule.matchHost;\n confidentialFields.forEach((field) => {\n if (rule[field]) {\n logger.debug(\n // TODO: types (#22198)\n `Adding ${field} authentication for ${rule.matchHost!} (hostType=${\n rule.hostType\n }) to hostRules`,\n );\n }\n });\n }\n confidentialFields.forEach((field) => {\n const secret = rule[field];\n if (isString(secret) && secret.length > 3) {\n sanitize.addSecretForSanitizing(secret);\n }\n });\n if (rule.username && rule.password) {\n sanitize.addSecretForSanitizing(\n toBase64(`${rule.username}:${rule.password}`),\n );\n }\n hostRules.push(rule);\n}\n\nexport interface HostRuleSearch {\n hostType?: string;\n url?: string;\n readOnly?: boolean;\n}\n\nexport function matchesHost(url: string, matchHost: string): boolean {\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n return false;\n }\n\n const parsedMatchHost = parseUrl(matchHost);\n if (isHttpUrl(parsedUrl) && isHttpUrl(parsedMatchHost)) {\n return parsedUrl.href.startsWith(parsedMatchHost!.href);\n }\n\n const { hostname } = parsedUrl;\n if (!hostname) {\n return false;\n }\n\n if (hostname === matchHost) {\n return true;\n }\n\n const topLevelSuffix = matchHost.startsWith('.')\n ? matchHost\n : `.${matchHost}`;\n return hostname.endsWith(topLevelSuffix);\n}\n\nfunction fromShorterToLongerMatchHost(a: HostRule, b: HostRule): number {\n if (!a.matchHost || !b.matchHost) {\n return 0;\n }\n return a.matchHost.length - b.matchHost.length;\n}\n\nfunction hostRuleRank({ hostType, matchHost, readOnly }: HostRule): number {\n if ((hostType || readOnly) && matchHost) {\n return 3;\n }\n\n if (matchHost) {\n return 2;\n }\n\n if (hostType) {\n return 1;\n }\n\n return 0;\n}\n\nfunction fromLowerToHigherRank(a: HostRule, b: HostRule): number {\n return hostRuleRank(a) - hostRuleRank(b);\n}\n\n// A single comparator, rather than two consecutive sorts: `fromShorterToLongerMatchHost` returns 0 for rules without a `matchHost`, which makes it non-transitive on its own, so a standalone length sort could leave two `matchHost` rules unordered when a host-less rule sits between them\nfunction fromLowerRankAndShorterMatchHost(a: HostRule, b: HostRule): number {\n return fromLowerToHigherRank(a, b) || fromShorterToLongerMatchHost(a, b);\n}\n\n/**\n * The `headers` that apply from a set of matching rules of the same trust tier.\n *\n * The last rule to set any wins outright, as `find()`'s callers receive them sorted from least to most specific. That is the behaviour every matching rule had before `headers` were combined across tiers, and it is what lets a broad rule's headers be masked by a narrower rule from the same source.\n */\nfunction headersOfLastRuleToSetThem(\n rules: RegisteredHostRule[],\n): Record<string, string> | undefined {\n return rules\n .map((rule) => rule.headers)\n .filter(isTruthy)\n .pop();\n}\n\nexport function find(search: HostRuleSearch): CombinedHostRule {\n if ([search.hostType, search.url].every(isFalsy)) {\n logger.warn({ search }, 'Invalid hostRules search');\n return {};\n }\n\n // Sort primarily by rank, and secondarily by matchHost length\n const sortedRules = hostRules.sort(fromLowerRankAndShorterMatchHost);\n\n const matchedRules: RegisteredHostRule[] = [];\n for (const rule of sortedRules) {\n let hostTypeMatch = true;\n let hostMatch = true;\n let readOnlyMatch = true;\n\n if (rule.hostType) {\n hostTypeMatch = false;\n // v8 ignore else -- TODO: add test #40625\n if (search.hostType === rule.hostType) {\n hostTypeMatch = true;\n }\n }\n\n if (rule.matchHost && rule.resolvedHost) {\n hostMatch = false;\n if (search.url) {\n hostMatch = matchesHost(search.url, rule.matchHost);\n }\n }\n\n if (!isUndefined(rule.readOnly)) {\n readOnlyMatch = false;\n // v8 ignore else -- TODO: add test #40625\n if (search.readOnly === rule.readOnly) {\n readOnlyMatch = true;\n hostTypeMatch = true; // When we match `readOnly`, we don't care about `hostType`\n }\n }\n\n if (hostTypeMatch && readOnlyMatch && hostMatch) {\n matchedRules.push(clone(rule));\n }\n }\n\n const res: RegisteredHostRule = Object.assign({}, ...matchedRules);\n\n // `headers` are resolved per trust tier and then combined key by key, so that repository or preset config can no longer discard - or substitute - the headers a self-hosted admin configured for the same host\n // Within a tier nothing changes: the most specific rule's `headers` still replace those of the broader rules it is combined with, so an admin masking their own broad rule with a narrower one keeps working, as does a repository doing the same among its own rules\n // This is deliberately scoped to `headers` alone, as combining any more of the fields than we already do has caused authentication regressions before: an inherited `token` and a specific rule's `username`/`password` are not meant to be used together\n const untrustedHeaders = headersOfLastRuleToSetThem(\n matchedRules.filter((rule) => !rule.trusted),\n );\n const trustedHeaders = headersOfLastRuleToSetThem(\n matchedRules.filter((rule) => rule.trusted),\n );\n if (untrustedHeaders ?? trustedHeaders) {\n // the admin's own headers are applied last, so a repository cannot override one they set for this host either\n res.headers = { ...untrustedHeaders, ...trustedHeaders };\n }\n\n delete res.hostType;\n delete res.resolvedHost;\n delete res.matchHost;\n delete res.readOnly;\n delete res.trusted;\n return res;\n}\n\nexport function hosts({ hostType }: { hostType: string }): string[] {\n return hostRules\n .filter((rule) => rule.hostType === hostType)\n .map((rule) => rule.resolvedHost)\n .filter(isTruthy);\n}\n\nexport function hostType({ url }: { url: string }): string | null {\n return (\n hostRules\n .filter((rule) => rule.matchHost && matchesHost(url, rule.matchHost))\n .sort(fromShorterToLongerMatchHost)\n .map((rule) => rule.hostType)\n .filter(isTruthy)\n .pop() ?? null\n );\n}\n\nexport function findAll({ hostType }: { hostType: string }): HostRule[] {\n return hostRules.filter((rule) => rule.hostType === hostType);\n}\n\n/**\n * @returns a deep copy of all known host rules without any filtering\n */\nexport function getAll(): HostRule[] {\n return clone(hostRules);\n}\n\nexport function clear(): void {\n logger.debug('Clearing hostRules');\n hostRules = [];\n sanitize.clearR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CAKjE,MAAM,mBAAmB,2BACvB,aAAa,QAAQ,SAAS,CAAC,KAAK,OAAO,CAC7C;CACA,MAAM,iBAAiB,2BACrB,aAAa,QAAQ,SAAS,KAAK,OAAO,CAC5C;CACA,IAAI,oBAAoB,gBAEtB,IAAI,UAAU;EAAE,GAAG;EAAkB,GAAG;CAAe;CAGzD,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO;AACT;AAEA,SAAgB,MAAM,EAAE,YAA4C;CAClE,OAAO,UACJ,QAAQ,SAAS,KAAK,aAAa,QAAQ,CAAC,CAC5C,KAAK,SAAS,KAAK,YAAY,CAAC,CAChC,OAAO,QAAQ;AACpB;AAEA,SAAgB,SAAS,EAAE,OAAuC;CAChE,OACE,UACG,QAAQ,SAAS,KAAK,aAAa,YAAY,KAAK,KAAK,SAAS,CAAC,CAAC,CACpE,KAAK,4BAA4B,CAAC,CAClC,KAAK,SAAS,KAAK,QAAQ,CAAC,CAC5B,OAAO,QAAQ,CAAC,CAChB,IAAI,KAAK;AAEhB;AAEA,SAAgB,QAAQ,EAAE,YAA8C;CACtE,OAAO,UAAU,QAAQ,SAAS,KAAK,aAAa,QAAQ;AAC9D;;;;AAKA,SAAgB,SAAqB;CACnC,OAAO,MAAM,SAAS;AACxB;AAEA,SAAgB,QAAc;CAC5B,OAAO,MAAM,oBAAoB;CACjC,YAAY,CAAC;CACb,8BAAuC;AACzC"}
|
|
@@ -8,7 +8,7 @@ import { coerceString } from "../../util/string.js";
|
|
|
8
8
|
import { addSecretForSanitizing } from "../../util/sanitize.js";
|
|
9
9
|
import { getProblems, logLevel, logger, setMeta } from "../../logger/index.js";
|
|
10
10
|
import { instrument } from "../../instrumentation/index.js";
|
|
11
|
-
import { add, clear } from "../../util/host-rules.js";
|
|
11
|
+
import { add, clear, filterAllowedHeaders } from "../../util/host-rules.js";
|
|
12
12
|
import { resolveConfigPresets } from "../../config/presets/index.js";
|
|
13
13
|
import { validateConfigSecretsAndVariables } from "../../config/secrets.js";
|
|
14
14
|
import { parseConfigs } from "./config/parse/index.js";
|
|
@@ -122,6 +122,7 @@ async function start() {
|
|
|
122
122
|
logger.info(`Written discovered repositories to ${config.writeDiscoveredRepos}`);
|
|
123
123
|
return 0;
|
|
124
124
|
}
|
|
125
|
+
let filteredGlobalHostRules;
|
|
125
126
|
for (const repository of config.repositories) {
|
|
126
127
|
if (haveReachedLimits()) break;
|
|
127
128
|
const { owner, repo } = repositoryToOwnerAndRepo(isString(repository) ? repository : repository.repository);
|
|
@@ -130,7 +131,11 @@ async function start() {
|
|
|
130
131
|
if (repoConfig.hostRules) {
|
|
131
132
|
logger.debug("Reinitializing hostRules for repo");
|
|
132
133
|
clear();
|
|
133
|
-
repoConfig.hostRules.
|
|
134
|
+
const rules = repoConfig.hostRules === config.hostRules && repoConfig.allowedHeaders === config.allowedHeaders ? filteredGlobalHostRules ??= filterAllowedHeaders(repoConfig.hostRules, config.allowedHeaders, false) : filterAllowedHeaders(repoConfig.hostRules, repoConfig.allowedHeaders);
|
|
135
|
+
for (const rule of rules) add(rule, {
|
|
136
|
+
allowedHeaders: repoConfig.allowedHeaders,
|
|
137
|
+
trusted: true
|
|
138
|
+
});
|
|
134
139
|
repoConfig.hostRules = [];
|
|
135
140
|
}
|
|
136
141
|
clear$1();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["configParser.filterConfig","hostRules.add","repositoryWorker.renovateRepository"],"sources":["../../../lib/workers/global/index.ts"],"sourcesContent":["import {\n ATTR_VCS_OWNER_NAME,\n ATTR_VCS_PROVIDER_NAME,\n ATTR_VCS_REPOSITORY_NAME,\n} from '@opentelemetry/semantic-conventions/incubating';\nimport {\n isNonEmptyObject,\n isNonEmptyString,\n isNonEmptyStringAndNotWhitespace,\n isString,\n} from '@sindresorhus/is';\nimport { ERROR } from 'bunyan';\nimport fs from 'fs-extra';\nimport semver from 'semver';\nimport upath from 'upath';\nimport { GlobalConfig } from '../../config/global.ts';\nimport * as configParser from '../../config/index.ts';\nimport { resolveConfigPresets } from '../../config/presets/index.ts';\nimport { validateConfigSecretsAndVariables } from '../../config/secrets.ts';\nimport type {\n AllConfig,\n InternalGlobalConfigOptions,\n RenovateConfig,\n RenovateRepository,\n RepoGlobalConfig,\n} from '../../config/types.ts';\nimport { CONFIG_PRESETS_INVALID } from '../../constants/error-messages.ts';\nimport { pkg } from '../../expose.ts';\nimport { instrument } from '../../instrumentation/index.ts';\nimport {\n exportStats,\n finalizeReport,\n} from '../../instrumentation/reporting.ts';\nimport { getProblems, logLevel, logger, setMeta } from '../../logger/index.ts';\nimport { setGlobalLogLevelRemaps } from '../../logger/remap.ts';\nimport { getEnv } from '../../util/env.ts';\nimport * as hostRules from '../../util/host-rules.ts';\nimport * as queue from '../../util/http/queue.ts';\nimport * as throttle from '../../util/http/throttle.ts';\nimport { regexEngineStatus } from '../../util/regex.ts';\nimport { addSecretForSanitizing } from '../../util/sanitize.ts';\nimport { coerceString } from '../../util/string.ts';\nimport * as repositoryWorker from '../repository/index.ts';\nimport type { RepositoryWorkerConfig } from '../repository/init/types.ts';\nimport { autodiscoverRepositories } from './autodiscover.ts';\nimport { parseConfigs } from './config/parse/index.ts';\nimport { globalFinalize, globalInitialize } from './initialize.ts';\nimport { isLimitReached } from './limits.ts';\n\nfunction applyGlobalOption<\n K extends keyof RepoGlobalConfig | keyof InternalGlobalConfigOptions,\n>(\n target: RepoGlobalConfig & InternalGlobalConfigOptions,\n source: RepoGlobalConfig & InternalGlobalConfigOptions,\n key: K,\n): void {\n target[key] = source[key];\n delete source[key];\n}\n\nexport async function getRepositoryConfig(\n globalConfig: RenovateConfig,\n repository: RenovateRepository,\n): Promise<RepositoryWorkerConfig> {\n const repoIsString = isString(repository);\n const repoName = repoIsString ? repository : repository.repository;\n\n const repoConfig: RepositoryWorkerConfig = {\n ...globalConfig,\n repository: repoName,\n };\n\n if (!repoIsString) {\n const { repository: _repository, ...repositoryEntryConfig } = repository;\n\n // Promote GlobalConfig.OPTIONS keys into repoConfig directly so that\n // GlobalConfig.set(repoConfig) in the repository worker picks them up\n // with per-repo overrides before onboarding checks run.\n for (const option of GlobalConfig.OPTIONS) {\n if (option in repositoryEntryConfig) {\n applyGlobalOption(repoConfig, repositoryEntryConfig, option);\n }\n }\n\n if (isNonEmptyObject(repositoryEntryConfig)) {\n // mergeRenovateConfig later resolves this repositories[] object-entry\n // config in the correct order\n repoConfig.repositoryEntryConfig = repositoryEntryConfig;\n }\n }\n\n const repoParts = repoName.split('/');\n repoParts.pop();\n repoConfig.parentOrg = repoParts.join('/');\n repoConfig.topLevelOrg = repoParts.shift();\n const platform = GlobalConfig.get('platform');\n repoConfig.localDir =\n platform === 'local'\n ? process.cwd()\n : // TODO: types (#22198)\n upath.join(repoConfig.baseDir!, `./repos/${platform}/${repoName}`);\n await fs.ensureDir(repoConfig.localDir);\n delete repoConfig.baseDir;\n return configParser.filterConfig(repoConfig, 'repository');\n}\n\nfunction getGlobalConfig(): Promise<RenovateConfig> {\n return parseConfigs(getEnv(), process.argv);\n}\n\nfunction haveReachedLimits(): boolean {\n if (isLimitReached('Commits')) {\n logger.info('Max commits created for this run.');\n return true;\n }\n return false;\n}\n\n/* istanbul ignore next */\nfunction checkEnv(): void {\n const range = pkg.engines.node;\n if (process.release?.name !== 'node' || !process.versions?.node) {\n logger.warn(\n { release: process.release, versions: process.versions },\n 'Unknown node environment detected.',\n );\n } else if (!semver.satisfies(process.versions?.node, range)) {\n logger.error(\n { versions: process.versions, range },\n 'Unsupported node environment detected. Please update your node version.',\n );\n }\n}\n\nexport async function validatePresets(config: AllConfig): Promise<void> {\n logger.debug('validatePresets()');\n try {\n await resolveConfigPresets(config);\n } catch (err) /* istanbul ignore next */ {\n logger.error({ err }, CONFIG_PRESETS_INVALID);\n throw new Error(CONFIG_PRESETS_INVALID);\n }\n}\n\nexport async function start(): Promise<number> {\n logger.info({ renovateVersion: pkg.version }, 'Renovate started');\n // istanbul ignore next\n if (regexEngineStatus.type === 'available') {\n logger.debug('Using RE2 regex engine');\n } else if (regexEngineStatus.type === 'unavailable') {\n logger.warn(\n { err: regexEngineStatus.err },\n 'RE2 not usable, falling back to RegExp',\n );\n } else if (regexEngineStatus.type === 'ignored') {\n logger.debug('RE2 regex engine is ignored via RENOVATE_X_IGNORE_RE2');\n }\n\n let config: AllConfig;\n const env = getEnv();\n try {\n if (isNonEmptyStringAndNotWhitespace(env.AWS_SECRET_ACCESS_KEY)) {\n addSecretForSanitizing(env.AWS_SECRET_ACCESS_KEY, 'global');\n }\n if (isNonEmptyStringAndNotWhitespace(env.AWS_SESSION_TOKEN)) {\n addSecretForSanitizing(env.AWS_SESSION_TOKEN, 'global');\n }\n if (isNonEmptyStringAndNotWhitespace(env.COREPACK_NPM_TOKEN)) {\n addSecretForSanitizing(env.COREPACK_NPM_TOKEN, 'global');\n }\n if (isNonEmptyStringAndNotWhitespace(env.COREPACK_NPM_PASSWORD)) {\n addSecretForSanitizing(env.COREPACK_NPM_PASSWORD, 'global');\n }\n\n await instrument('config', async () => {\n // read global config from file, env and cli args\n config = await getGlobalConfig();\n\n // Set allowedHeaders and userAgent in case hostRules headers are configured in file config\n GlobalConfig.set({\n allowedHeaders: config.allowedHeaders,\n userAgent: config.userAgent,\n });\n // initialize all submodules\n config = await globalInitialize(config);\n\n // Set platform, endpoint, allowedHeaders and userAgent in case local presets are used\n GlobalConfig.set({\n allowedHeaders: config.allowedHeaders,\n platform: config.platform,\n endpoint: config.endpoint,\n userAgent: config.userAgent,\n });\n\n await validatePresets(config);\n\n setGlobalLogLevelRemaps(config.logLevelRemap);\n\n checkEnv();\n\n // validate secrets and variables. Will throw and abort if invalid\n validateConfigSecretsAndVariables(config);\n });\n\n // autodiscover repositories (needs to come after platform initialization)\n config = await instrument('discover', () =>\n autodiscoverRepositories(config),\n );\n\n if (isNonEmptyString(config.writeDiscoveredRepos)) {\n const content = JSON.stringify(config.repositories);\n await fs.writeFile(config.writeDiscoveredRepos, content);\n logger.info(\n `Written discovered repositories to ${config.writeDiscoveredRepos}`,\n );\n return 0;\n }\n\n // Iterate through repositories sequentially\n for (const repository of config.repositories!) {\n if (haveReachedLimits()) {\n break;\n }\n\n const { owner, repo } = repositoryToOwnerAndRepo(\n isString(repository) ? repository : repository.repository,\n );\n\n await instrument(\n 'repository',\n async () => {\n const repoConfig = await getRepositoryConfig(config, repository);\n if (repoConfig.hostRules) {\n logger.debug('Reinitializing hostRules for repo');\n hostRules.clear();\n repoConfig.hostRules.forEach((rule) => hostRules.add(rule));\n repoConfig.hostRules = [];\n }\n\n // host rules can change concurrency\n queue.clear();\n throttle.clear();\n\n await repositoryWorker.renovateRepository(repoConfig);\n setMeta({});\n },\n {\n attributes: {\n [ATTR_VCS_PROVIDER_NAME]: config.platform,\n [ATTR_VCS_OWNER_NAME]: owner,\n [ATTR_VCS_REPOSITORY_NAME]: repo,\n /** @deprecated TODO remove */\n repository: isString(repository)\n ? repository\n : repository.repository,\n },\n },\n );\n }\n\n finalizeReport();\n await exportStats(config);\n } catch (err) /* istanbul ignore next */ {\n if (err.message.startsWith('Init: ')) {\n logger.fatal(\n { errorMessage: err.message.substring(6) },\n 'Initialization error',\n );\n } else {\n logger.fatal({ err }, 'Unknown error');\n }\n if (!config!) {\n // return early if we can't parse config options\n logger.debug(`Missing config`);\n return 2;\n }\n } finally {\n await globalFinalize(config!);\n if (logLevel() === 'info') {\n logger.info(\n `Renovate was run at log level \"${logLevel()}\". Set LOG_LEVEL=debug in environment variables to see extended debug logs.`,\n );\n }\n }\n const loggerErrors = getProblems().filter((p) => p.level >= ERROR);\n if (loggerErrors.length) {\n logger.info(\n { loggerErrors },\n 'Renovate is exiting with a non-zero code due to the following logged errors',\n );\n return 1;\n }\n return 0;\n}\n\nfunction repositoryToOwnerAndRepo(fullName: string): {\n owner: string;\n repo: string;\n} {\n const parts = fullName.split('/');\n const repo = coerceString(parts.pop());\n const owner = parts.join('/');\n return { owner, repo };\n}\n"],"m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Ae,YAAY,CAAC,CAAC,QAAQ,MAAM,EAAE,SAAS,KAAK;CACjE,IAAI,aAAa,QAAQ;EACvB,OAAO,KACL,EAAE,aAAa,GACf,6EACF;EACA,OAAO;CACT;CACA,OAAO;AACT;AAEA,SAAS,yBAAyB,UAGhC;CACA,MAAM,QAAQ,SAAS,MAAM,GAAG;CAChC,MAAM,OAAO,aAAa,MAAM,IAAI,CAAC;CAErC,OAAO;EAAE,OADK,MAAM,KAAK,GACZ;EAAG;CAAK;AACvB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["configParser.filterConfig","hostRules.filterAllowedHeaders","repositoryWorker.renovateRepository"],"sources":["../../../lib/workers/global/index.ts"],"sourcesContent":["import {\n ATTR_VCS_OWNER_NAME,\n ATTR_VCS_PROVIDER_NAME,\n ATTR_VCS_REPOSITORY_NAME,\n} from '@opentelemetry/semantic-conventions/incubating';\nimport {\n isNonEmptyObject,\n isNonEmptyString,\n isNonEmptyStringAndNotWhitespace,\n isString,\n} from '@sindresorhus/is';\nimport { ERROR } from 'bunyan';\nimport fs from 'fs-extra';\nimport semver from 'semver';\nimport upath from 'upath';\nimport { GlobalConfig } from '../../config/global.ts';\nimport * as configParser from '../../config/index.ts';\nimport { resolveConfigPresets } from '../../config/presets/index.ts';\nimport { validateConfigSecretsAndVariables } from '../../config/secrets.ts';\nimport type {\n AllConfig,\n InternalGlobalConfigOptions,\n RenovateConfig,\n RenovateRepository,\n RepoGlobalConfig,\n} from '../../config/types.ts';\nimport { CONFIG_PRESETS_INVALID } from '../../constants/error-messages.ts';\nimport { pkg } from '../../expose.ts';\nimport { instrument } from '../../instrumentation/index.ts';\nimport {\n exportStats,\n finalizeReport,\n} from '../../instrumentation/reporting.ts';\nimport { getProblems, logLevel, logger, setMeta } from '../../logger/index.ts';\nimport { setGlobalLogLevelRemaps } from '../../logger/remap.ts';\nimport type { HostRule } from '../../types/index.ts';\nimport { getEnv } from '../../util/env.ts';\nimport * as hostRules from '../../util/host-rules.ts';\nimport * as queue from '../../util/http/queue.ts';\nimport * as throttle from '../../util/http/throttle.ts';\nimport { regexEngineStatus } from '../../util/regex.ts';\nimport { addSecretForSanitizing } from '../../util/sanitize.ts';\nimport { coerceString } from '../../util/string.ts';\nimport * as repositoryWorker from '../repository/index.ts';\nimport type { RepositoryWorkerConfig } from '../repository/init/types.ts';\nimport { autodiscoverRepositories } from './autodiscover.ts';\nimport { parseConfigs } from './config/parse/index.ts';\nimport { globalFinalize, globalInitialize } from './initialize.ts';\nimport { isLimitReached } from './limits.ts';\n\nfunction applyGlobalOption<\n K extends keyof RepoGlobalConfig | keyof InternalGlobalConfigOptions,\n>(\n target: RepoGlobalConfig & InternalGlobalConfigOptions,\n source: RepoGlobalConfig & InternalGlobalConfigOptions,\n key: K,\n): void {\n target[key] = source[key];\n delete source[key];\n}\n\nexport async function getRepositoryConfig(\n globalConfig: RenovateConfig,\n repository: RenovateRepository,\n): Promise<RepositoryWorkerConfig> {\n const repoIsString = isString(repository);\n const repoName = repoIsString ? repository : repository.repository;\n\n const repoConfig: RepositoryWorkerConfig = {\n ...globalConfig,\n repository: repoName,\n };\n\n if (!repoIsString) {\n const { repository: _repository, ...repositoryEntryConfig } = repository;\n\n // Promote GlobalConfig.OPTIONS keys into repoConfig directly so that\n // GlobalConfig.set(repoConfig) in the repository worker picks them up\n // with per-repo overrides before onboarding checks run.\n for (const option of GlobalConfig.OPTIONS) {\n if (option in repositoryEntryConfig) {\n applyGlobalOption(repoConfig, repositoryEntryConfig, option);\n }\n }\n\n if (isNonEmptyObject(repositoryEntryConfig)) {\n // mergeRenovateConfig later resolves this repositories[] object-entry\n // config in the correct order\n repoConfig.repositoryEntryConfig = repositoryEntryConfig;\n }\n }\n\n const repoParts = repoName.split('/');\n repoParts.pop();\n repoConfig.parentOrg = repoParts.join('/');\n repoConfig.topLevelOrg = repoParts.shift();\n const platform = GlobalConfig.get('platform');\n repoConfig.localDir =\n platform === 'local'\n ? process.cwd()\n : // TODO: types (#22198)\n upath.join(repoConfig.baseDir!, `./repos/${platform}/${repoName}`);\n await fs.ensureDir(repoConfig.localDir);\n delete repoConfig.baseDir;\n return configParser.filterConfig(repoConfig, 'repository');\n}\n\nfunction getGlobalConfig(): Promise<RenovateConfig> {\n return parseConfigs(getEnv(), process.argv);\n}\n\nfunction haveReachedLimits(): boolean {\n if (isLimitReached('Commits')) {\n logger.info('Max commits created for this run.');\n return true;\n }\n return false;\n}\n\n/* istanbul ignore next */\nfunction checkEnv(): void {\n const range = pkg.engines.node;\n if (process.release?.name !== 'node' || !process.versions?.node) {\n logger.warn(\n { release: process.release, versions: process.versions },\n 'Unknown node environment detected.',\n );\n } else if (!semver.satisfies(process.versions?.node, range)) {\n logger.error(\n { versions: process.versions, range },\n 'Unsupported node environment detected. Please update your node version.',\n );\n }\n}\n\nexport async function validatePresets(config: AllConfig): Promise<void> {\n logger.debug('validatePresets()');\n try {\n await resolveConfigPresets(config);\n } catch (err) /* istanbul ignore next */ {\n logger.error({ err }, CONFIG_PRESETS_INVALID);\n throw new Error(CONFIG_PRESETS_INVALID);\n }\n}\n\nexport async function start(): Promise<number> {\n logger.info({ renovateVersion: pkg.version }, 'Renovate started');\n // istanbul ignore next\n if (regexEngineStatus.type === 'available') {\n logger.debug('Using RE2 regex engine');\n } else if (regexEngineStatus.type === 'unavailable') {\n logger.warn(\n { err: regexEngineStatus.err },\n 'RE2 not usable, falling back to RegExp',\n );\n } else if (regexEngineStatus.type === 'ignored') {\n logger.debug('RE2 regex engine is ignored via RENOVATE_X_IGNORE_RE2');\n }\n\n let config: AllConfig;\n const env = getEnv();\n try {\n if (isNonEmptyStringAndNotWhitespace(env.AWS_SECRET_ACCESS_KEY)) {\n addSecretForSanitizing(env.AWS_SECRET_ACCESS_KEY, 'global');\n }\n if (isNonEmptyStringAndNotWhitespace(env.AWS_SESSION_TOKEN)) {\n addSecretForSanitizing(env.AWS_SESSION_TOKEN, 'global');\n }\n if (isNonEmptyStringAndNotWhitespace(env.COREPACK_NPM_TOKEN)) {\n addSecretForSanitizing(env.COREPACK_NPM_TOKEN, 'global');\n }\n if (isNonEmptyStringAndNotWhitespace(env.COREPACK_NPM_PASSWORD)) {\n addSecretForSanitizing(env.COREPACK_NPM_PASSWORD, 'global');\n }\n\n await instrument('config', async () => {\n // read global config from file, env and cli args\n config = await getGlobalConfig();\n\n // Set allowedHeaders and userAgent in case hostRules headers are configured in file config\n GlobalConfig.set({\n allowedHeaders: config.allowedHeaders,\n userAgent: config.userAgent,\n });\n // initialize all submodules\n config = await globalInitialize(config);\n\n // Set platform, endpoint, allowedHeaders and userAgent in case local presets are used\n GlobalConfig.set({\n allowedHeaders: config.allowedHeaders,\n platform: config.platform,\n endpoint: config.endpoint,\n userAgent: config.userAgent,\n });\n\n await validatePresets(config);\n\n setGlobalLogLevelRemaps(config.logLevelRemap);\n\n checkEnv();\n\n // validate secrets and variables. Will throw and abort if invalid\n validateConfigSecretsAndVariables(config);\n });\n\n // autodiscover repositories (needs to come after platform initialization)\n config = await instrument('discover', () =>\n autodiscoverRepositories(config),\n );\n\n if (isNonEmptyString(config.writeDiscoveredRepos)) {\n const content = JSON.stringify(config.repositories);\n await fs.writeFile(config.writeDiscoveredRepos, content);\n logger.info(\n `Written discovered repositories to ${config.writeDiscoveredRepos}`,\n );\n return 0;\n }\n\n // the self-hosted admin's own headers get no exemption from `allowedHeaders` either, as `applyHostRule` filters the rule it matches by header name alone whoever set it - so we drop them here too, with a WARN, rather than leave them to be silently discarded at request time\n // filtered once, outside the loop, rather than for every repository it processes\n let filteredGlobalHostRules: HostRule[] | undefined;\n\n // Iterate through repositories sequentially\n for (const repository of config.repositories!) {\n if (haveReachedLimits()) {\n break;\n }\n\n const { owner, repo } = repositoryToOwnerAndRepo(\n isString(repository) ? repository : repository.repository,\n );\n\n await instrument(\n 'repository',\n async () => {\n const repoConfig = await getRepositoryConfig(config, repository);\n if (repoConfig.hostRules) {\n logger.debug('Reinitializing hostRules for repo');\n hostRules.clear();\n // `GlobalConfig` still reflects the previous repository at this point, so filter with this repository's own `allowedHeaders`: usually the global allowlist (filtered once, above), re-filtered only for a `repositories[]` entry carrying an override of its own\n const rules =\n // reuse the memo only for the exact global inputs it was computed from - today `repoConfig.hostRules` is always the global array, but nothing should break if that ever changes\n repoConfig.hostRules === config.hostRules &&\n repoConfig.allowedHeaders === config.allowedHeaders\n ? (filteredGlobalHostRules ??= hostRules.filterAllowedHeaders(\n repoConfig.hostRules,\n config.allowedHeaders,\n // `globalInitialize` already registered these very rules against this very allowlist, and warned about whatever it dropped\n false,\n ))\n : hostRules.filterAllowedHeaders(\n repoConfig.hostRules,\n repoConfig.allowedHeaders,\n );\n for (const rule of rules) {\n // already filtered: pass the same allowlist through so `add()` does not re-filter against a stale `GlobalConfig`\n // the self-hosted admin's own rules: `trusted`, so that their `headers` are applied over any a repository or preset sets for the same host\n hostRules.add(rule, {\n // we haven't yet set `GlobalConfig`, so we need to explicitly pass these in\n allowedHeaders: repoConfig.allowedHeaders,\n trusted: true,\n });\n }\n repoConfig.hostRules = [];\n }\n\n // host rules can change concurrency\n queue.clear();\n throttle.clear();\n\n await repositoryWorker.renovateRepository(repoConfig);\n setMeta({});\n },\n {\n attributes: {\n [ATTR_VCS_PROVIDER_NAME]: config.platform,\n [ATTR_VCS_OWNER_NAME]: owner,\n [ATTR_VCS_REPOSITORY_NAME]: repo,\n /** @deprecated TODO remove */\n repository: isString(repository)\n ? repository\n : repository.repository,\n },\n },\n );\n }\n\n finalizeReport();\n await exportStats(config);\n } catch (err) /* istanbul ignore next */ {\n if (err.message.startsWith('Init: ')) {\n logger.fatal(\n { errorMessage: err.message.substring(6) },\n 'Initialization error',\n );\n } else {\n logger.fatal({ err }, 'Unknown error');\n }\n if (!config!) {\n // return early if we can't parse config options\n logger.debug(`Missing config`);\n return 2;\n }\n } finally {\n await globalFinalize(config!);\n if (logLevel() === 'info') {\n logger.info(\n `Renovate was run at log level \"${logLevel()}\". Set LOG_LEVEL=debug in environment variables to see extended debug logs.`,\n );\n }\n }\n const loggerErrors = getProblems().filter((p) => p.level >= ERROR);\n if (loggerErrors.length) {\n logger.info(\n { loggerErrors },\n 'Renovate is exiting with a non-zero code due to the following logged errors',\n );\n return 1;\n }\n return 0;\n}\n\nfunction repositoryToOwnerAndRepo(fullName: string): {\n owner: string;\n repo: string;\n} {\n const parts = fullName.split('/');\n const repo = coerceString(parts.pop());\n const owner = parts.join('/');\n return { owner, repo };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAS,kBAGP,QACA,QACA,KACM;CACN,OAAO,OAAO,OAAO;CACrB,OAAO,OAAO;AAChB;AAEA,eAAsB,oBACpB,cACA,YACiC;CACjC,MAAM,eAAe,SAAS,UAAU;CACxC,MAAM,WAAW,eAAe,aAAa,WAAW;CAExD,MAAM,aAAqC;EACzC,GAAG;EACH,YAAY;CACd;CAEA,IAAI,CAAC,cAAc;EACjB,MAAM,EAAE,YAAY,aAAa,GAAG,0BAA0B;EAK9D,KAAK,MAAM,UAAU,aAAa,SAChC,IAAI,UAAU,uBACZ,kBAAkB,YAAY,uBAAuB,MAAM;EAI/D,IAAI,iBAAiB,qBAAqB,GAGxC,WAAW,wBAAwB;CAEvC;CAEA,MAAM,YAAY,SAAS,MAAM,GAAG;CACpC,UAAU,IAAI;CACd,WAAW,YAAY,UAAU,KAAK,GAAG;CACzC,WAAW,cAAc,UAAU,MAAM;CACzC,MAAM,WAAW,aAAa,IAAI,UAAU;CAC5C,WAAW,WACT,aAAa,UACT,QAAQ,IAAI,IAEZ,MAAM,KAAK,WAAW,SAAU,WAAW,SAAS,GAAG,UAAU;CACvE,MAAM,GAAG,UAAU,WAAW,QAAQ;CACtC,OAAO,WAAW;CAClB,OAAOA,aAA0B,YAAY,YAAY;AAC3D;AAEA,SAAS,kBAA2C;CAClD,OAAO,aAAa,OAAO,GAAG,QAAQ,IAAI;AAC5C;AAEA,SAAS,oBAA6B;CACpC,IAAI,eAAe,SAAS,GAAG;EAC7B,OAAO,KAAK,mC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AE5B,YAAY,SAAS,UAAU,IAC3B,aACA,WAAW;GACjB,EACF,CACF;EACF;EAEA,eAAe;EACf,MAAM,YAAY,MAAM;CAC1B,SAAS,gCAAgC;EACvC,IAAI,IAAI,QAAQ,WAAW,QAAQ,GACjC,OAAO,MACL,EAAE,cAAc,IAAI,QAAQ,UAAU,CAAC,EAAE,GACzC,sBACF;OAEA,OAAO,MAAM,EAAE,IAAI,GAAG,eAAe;EAEvC,IAAI,CAAC,QAAS;GAEZ,OAAO,MAAM,gBAAgB;GAC7B,OAAO;EACT;CACF,UAAU;EACR,MAAM,eAAe,MAAO;EAC5B,IAAI,SAAS,MAAM,QACjB,OAAO,KACL,kCAAkC,SAAS,EAAE,4EAC/C;CAEJ;CACA,MAAM,eAAe,YAAY,CAAC,CAAC,QAAQ,MAAM,EAAE,SAAS,KAAK;CACjE,IAAI,aAAa,QAAQ;EACvB,OAAO,KACL,EAAE,aAAa,GACf,6EACF;EACA,OAAO;CACT;CACA,OAAO;AACT;AAEA,SAAS,yBAAyB,UAGhC;CACA,MAAM,QAAQ,SAAS,MAAM,GAAG;CAChC,MAAM,OAAO,aAAa,MAAM,IAAI,CAAC;CAErC,OAAO;EAAE,OADK,MAAM,KAAK,GACZ;EAAG;CAAK;AACvB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resetGlobalLogLevelRemaps } from "../../logger/remap.js";
|
|
2
2
|
import { logger } from "../../logger/index.js";
|
|
3
|
-
import { add } from "../../util/host-rules.js";
|
|
3
|
+
import { add, filterAllowedHeaders } from "../../util/host-rules.js";
|
|
4
4
|
import { applySecretsAndVariablesToConfig } from "../../config/secrets.js";
|
|
5
5
|
import { cleanup, init } from "../../util/cache/package/index.js";
|
|
6
6
|
import { setHttpRateLimits } from "../../util/http/rate-limits.js";
|
|
@@ -45,7 +45,7 @@ function limitCommitsPerRun(config) {
|
|
|
45
45
|
async function checkVersions() {
|
|
46
46
|
if (!await validateGitVersion()) throw new Error("Init: git version needs upgrading");
|
|
47
47
|
}
|
|
48
|
-
function setGlobalHostRules(config) {
|
|
48
|
+
function setGlobalHostRules(config, warnOnDenied = true) {
|
|
49
49
|
if (config.hostRules) {
|
|
50
50
|
logger.debug("Setting global hostRules");
|
|
51
51
|
applySecretsAndVariablesToConfig({
|
|
@@ -53,7 +53,11 @@ function setGlobalHostRules(config) {
|
|
|
53
53
|
deleteVariables: false,
|
|
54
54
|
deleteSecrets: false
|
|
55
55
|
});
|
|
56
|
-
config.hostRules.
|
|
56
|
+
const rules = filterAllowedHeaders(config.hostRules, config.allowedHeaders, warnOnDenied);
|
|
57
|
+
for (const rule of rules) add(rule, {
|
|
58
|
+
allowedHeaders: config.allowedHeaders,
|
|
59
|
+
trusted: true
|
|
60
|
+
});
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
function configureThirdPartyLibraries(config) {
|
|
@@ -73,7 +77,7 @@ async function globalInitialize(config_) {
|
|
|
73
77
|
await init(config);
|
|
74
78
|
limitCommitsPerRun(config);
|
|
75
79
|
setEmojiConfig(config);
|
|
76
|
-
setGlobalHostRules(config);
|
|
80
|
+
setGlobalHostRules(config, false);
|
|
77
81
|
configureThirdPartyLibraries(config);
|
|
78
82
|
await initMergeConfidence(config);
|
|
79
83
|
return config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","names":["hostRules.
|
|
1
|
+
{"version":3,"file":"initialize.js","names":["hostRules.filterAllowedHeaders","packageCache.init","packageCache.cleanup"],"sources":["../../../lib/workers/global/initialize.ts"],"sourcesContent":["import os from 'node:os';\nimport fs from 'fs-extra';\nimport upath from 'upath';\nimport { applySecretsAndVariablesToConfig } from '../../config/secrets.ts';\nimport type { AllConfig, RenovateConfig } from '../../config/types.ts';\nimport { logger } from '../../logger/index.ts';\nimport { resetGlobalLogLevelRemaps } from '../../logger/remap.ts';\nimport { initPlatform } from '../../modules/platform/index.ts';\nimport * as packageCache from '../../util/cache/package/index.ts';\nimport { setEmojiConfig } from '../../util/emoji.ts';\nimport { validateGitVersion } from '../../util/git/index.ts';\nimport * as hostRules from '../../util/host-rules.ts';\nimport { setHttpRateLimits } from '../../util/http/rate-limits.ts';\nimport { initMergeConfidence } from '../../util/merge-confidence/index.ts';\nimport { setMaxLimit } from './limits.ts';\n\nasync function setDirectories(input: AllConfig): Promise<AllConfig> {\n const config: AllConfig = { ...input };\n process.env.TMPDIR = process.env.RENOVATE_TMPDIR ?? os.tmpdir();\n if (config.baseDir) {\n logger.debug(`Using configured baseDir: ${config.baseDir}`);\n } else {\n config.baseDir = upath.join(process.env.TMPDIR, 'renovate');\n logger.debug(`Using baseDir: ${config.baseDir}`);\n }\n await fs.ensureDir(config.baseDir);\n if (config.cacheDir) {\n logger.debug(`Using configured cacheDir: ${config.cacheDir}`);\n } else {\n config.cacheDir = upath.join(config.baseDir, 'cache');\n logger.debug(`Using cacheDir: ${config.cacheDir}`);\n }\n await fs.ensureDir(config.cacheDir);\n if (config.binarySource === 'docker' || config.binarySource === 'install') {\n if (config.containerbaseDir) {\n logger.debug(\n `Using configured containerbaseDir: ${config.containerbaseDir}`,\n );\n } else {\n config.containerbaseDir = upath.join(config.cacheDir, 'containerbase');\n logger.debug(`Using containerbaseDir: ${config.containerbaseDir}`);\n }\n await fs.ensureDir(config.containerbaseDir);\n }\n return config;\n}\n\nfunction limitCommitsPerRun(config: RenovateConfig): void {\n const limit = config.prCommitsPerRunLimit;\n setMaxLimit('Commits', typeof limit === 'number' && limit > 0 ? limit : null);\n}\n\nasync function checkVersions(): Promise<void> {\n const validGitVersion = await validateGitVersion();\n if (!validGitVersion) {\n throw new Error('Init: git version needs upgrading');\n }\n}\n\nfunction setGlobalHostRules(config: AllConfig, warnOnDenied = true): void {\n if (config.hostRules) {\n logger.debug('Setting global hostRules');\n applySecretsAndVariablesToConfig({\n config,\n deleteVariables: false,\n deleteSecrets: false,\n });\n // filtered here, rather than left to `add()`, so that the WARN about any dropped header can be suppressed when the same rules are registered again\n // `config.hostRules` is deliberately left as it is: a `repositories[]` entry can widen `allowedHeaders` for its own repository, and `start()` re-filters these rules with the entry's allowlist to honour that\n const rules = hostRules.filterAllowedHeaders(\n config.hostRules,\n config.allowedHeaders,\n warnOnDenied,\n );\n for (const rule of rules) {\n // already filtered above, so `add()`'s own enforcement has nothing left to drop\n // the self-hosted admin's own rules: `trusted`, so that their `headers` are applied over any a repository or preset sets for the same host\n hostRules.add(rule, {\n allowedHeaders: config.allowedHeaders,\n trusted: true,\n });\n }\n }\n}\n\nfunction configureThirdPartyLibraries(config: AllConfig): void {\n // Not using early return style to make clear what's the criterion to set the variables,\n // especially when there is more stuff added here in the future.\n if (!config.useCloudMetadataServices) {\n logger.debug('Disabling the use of cloud metadata services');\n process.env.AWS_EC2_METADATA_DISABLED = 'true'; // See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-list\n process.env.METADATA_SERVER_DETECTION = 'none'; // See https://cloud.google.com/nodejs/docs/reference/gcp-metadata/latest#environment-variables\n }\n}\n\nexport async function globalInitialize(\n config_: AllConfig,\n): Promise<RenovateConfig> {\n let config = config_;\n setHttpRateLimits();\n await checkVersions();\n setGlobalHostRules(config);\n config = await initPlatform(config);\n config = await setDirectories(config);\n await packageCache.init(config);\n limitCommitsPerRun(config);\n setEmojiConfig(config);\n // registered a second time in case initialization changed them; anything `allowedHeaders` drops was already warned about by the call above\n setGlobalHostRules(config, false);\n configureThirdPartyLibraries(config);\n await initMergeConfidence(config);\n return config;\n}\n\nexport async function globalFinalize(config: RenovateConfig): Promise<void> {\n await packageCache.cleanup(config);\n resetGlobalLogLevelRemaps();\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,eAAe,eAAe,OAAsC;CAClE,MAAM,SAAoB,EAAE,GAAG,MAAM;CACrC,QAAQ,IAAI,SAAS,QAAQ,IAAI,mBAAmB,GAAG,OAAO;CAC9D,IAAI,OAAO,SACT,OAAO,MAAM,6BAA6B,OAAO,SAAS;MACrD;EACL,OAAO,UAAU,MAAM,KAA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;CAC1C;AACF;AAEA,eAAsB,iBACpB,SACyB;CACzB,IAAI,SAAS;CACb,kBAAkB;CAClB,MAAM,cAAc;CACpB,mBAAmB,MAAM;CACzB,SAAS,MAAM,aAAa,MAAM;CAClC,SAAS,MAAM,eAAe,MAAM;CACpC,MAAMC,KAAkB,MAAM;CAC9B,mBAAmB,MAAM;CACzB,eAAe,MAAM;CAErB,mBAAmB,QAAQ,KAAK;CAChC,6BAA6B,MAAM;CACnC,MAAM,oBAAoB,MAAM;CAChC,OAAO;AACT;AAEA,eAAsB,eAAe,QAAuC;CAC1E,MAAMC,QAAqB,MAAM;CACjC,0BAA0B;AAC5B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { GlobalConfig } from "../../../config/global.js";
|
|
2
|
+
import { matchRegexOrGlobList } from "../../../util/string-match.js";
|
|
3
|
+
import { logger } from "../../../logger/index.js";
|
|
4
|
+
//#region lib/workers/repository/init/filter-allowed-env.ts
|
|
5
|
+
/**
|
|
6
|
+
* Enforce the `allowedEnv` allowlist before applying the environment variables to subcommands.
|
|
7
|
+
*
|
|
8
|
+
* If anything has reached this point from the user (repo config, presets) that isn't allowed according to `allowedEnv`, loudly remove anything with a WARN message.
|
|
9
|
+
*
|
|
10
|
+
* @param env any `env` configuration from the user (repo config, presets)
|
|
11
|
+
* @param [adminSuppliedEnv={}] any `env` that the self-hosted administrator has set. If set, these will always be allowed, regardless of `allowedEnv`
|
|
12
|
+
*
|
|
13
|
+
* NOTE that we re-apply the admin-supplied `env`, as `env` is not `mergeable: true`, so we need to make sure that we don't accidentally overwrite admin-set `env` from repo config.
|
|
14
|
+
*
|
|
15
|
+
* A user setting `env` for a value in the `allowedEnv` allowlist will take precedence over a admin-set `env`.
|
|
16
|
+
*/
|
|
17
|
+
function filterAllowedEnv(env, adminSuppliedEnv = {}) {
|
|
18
|
+
if (!env) return env;
|
|
19
|
+
const allowedEnv = GlobalConfig.get("allowedEnv");
|
|
20
|
+
const allowed = { ...adminSuppliedEnv };
|
|
21
|
+
const denied = [];
|
|
22
|
+
for (const [name, value] of Object.entries(env)) if (adminSuppliedEnv[name] === value || matchRegexOrGlobList(name, allowedEnv)) allowed[name] = value;
|
|
23
|
+
else denied.push(name);
|
|
24
|
+
if (denied.length) logger.warn({ denied }, "Ignoring env variables not permitted by this Renovate instance's `allowedEnv`");
|
|
25
|
+
return allowed;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { filterAllowedEnv };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=filter-allowed-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-allowed-env.js","names":[],"sources":["../../../../lib/workers/repository/init/filter-allowed-env.ts"],"sourcesContent":["import { GlobalConfig } from '../../../config/global.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { matchRegexOrGlobList } from '../../../util/string-match.ts';\n\n/**\n * Enforce the `allowedEnv` allowlist before applying the environment variables to subcommands.\n *\n * If anything has reached this point from the user (repo config, presets) that isn't allowed according to `allowedEnv`, loudly remove anything with a WARN message.\n *\n * @param env any `env` configuration from the user (repo config, presets)\n * @param [adminSuppliedEnv={}] any `env` that the self-hosted administrator has set. If set, these will always be allowed, regardless of `allowedEnv`\n *\n * NOTE that we re-apply the admin-supplied `env`, as `env` is not `mergeable: true`, so we need to make sure that we don't accidentally overwrite admin-set `env` from repo config.\n *\n * A user setting `env` for a value in the `allowedEnv` allowlist will take precedence over a admin-set `env`.\n */\nexport function filterAllowedEnv(\n env: Record<string, string> | undefined,\n adminSuppliedEnv: Record<string, string> = {},\n): Record<string, string> | undefined {\n if (!env) {\n return env;\n }\n const allowedEnv = GlobalConfig.get('allowedEnv');\n const allowed: Record<string, string> = { ...adminSuppliedEnv };\n const denied: string[] = [];\n for (const [name, value] of Object.entries(env)) {\n if (\n adminSuppliedEnv[name] === value ||\n matchRegexOrGlobList(name, allowedEnv)\n ) {\n allowed[name] = value;\n } else {\n denied.push(name);\n }\n }\n\n if (denied.length) {\n logger.warn(\n { denied },\n \"Ignoring env variables not permitted by this Renovate instance's `allowedEnv`\",\n );\n }\n return allowed;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,iBACd,KACA,mBAA2C,CAAC,GACR;CACpC,IAAI,CAAC,KACH,OAAO;CAET,MAAM,aAAa,aAAa,IAAI,YAAY;CAChD,MAAM,UAAkC,EAAE,GAAG,iBAAiB;CAC9D,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,GAAG,GAC5C,IACE,iBAAiB,UAAU,SAC3B,qBAAqB,MAAM,UAAU,GAErC,QAAQ,QAAQ;MAEhB,OAAO,KAAK,IAAI;CAIpB,IAAI,OAAO,QACT,OAAO,KACL,EAAE,OAAO,GACT,+EACF;CAEF,OAAO;AACT"}
|