Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to disable access to cloud metadata services #26411

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/usage/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,12 @@ This is currently applicable to `npm` only, and only used in cases where bugs in
If enabled emoji shortcodes are replaced with their Unicode equivalents.
For example: `:warning:` will be replaced with `⚠️`.

## useCloudMetadataServices

Some cloud providers offer services to receive metadata about the current instance, for example [AWS Instance metadata](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html)
or [GCP VM metadata](https://cloud.google.com/compute/docs/metadata/overview).
Use this option to control whether Renovate should try to access these services.

## username

You may need to set a `username` if you:
Expand Down
8 changes: 8 additions & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const options: RenovateOptions[] = [
default: false,
globalOnly: true,
},
{
name: 'useCloudMetadataServices',
description:
'If `false`, Renovate does not try to access cloud metadata services.',
type: 'boolean',
default: true,
globalOnly: true,
},
{
name: 'allowPostUpgradeCommandTemplating',
description:
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface GlobalOnlyConfig {
repositories?: RenovateRepository[];
platform?: PlatformId;
endpoint?: string;
useCloudMetadataServices?: boolean;
}

// Config options used within the repository worker, but not user configurable
Expand Down
23 changes: 23 additions & 0 deletions lib/workers/global/initialize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,27 @@ describe('workers/global/initialize', () => {
await expect(globalInitialize(config)).toResolve();
});
});

describe('configureThirdPartyLibraries()', () => {
beforeEach(() => {
delete process.env.AWS_EC2_METADATA_DISABLED;
delete process.env.METADATA_SERVER_DETECTION;
});

it('sets env vars when cloud metadata services disabled', async () => {
const config: RenovateConfig = { useCloudMetadataServices: false };
git.validateGitVersion.mockResolvedValueOnce(true);
await expect(globalInitialize(config)).toResolve();
expect(process.env.AWS_EC2_METADATA_DISABLED).toBe('true');
expect(process.env.METADATA_SERVER_DETECTION).toBe('none');
});

it('does not set env vars when cloud metadata services enabled', async () => {
const config: RenovateConfig = { useCloudMetadataServices: true };
git.validateGitVersion.mockResolvedValueOnce(true);
await expect(globalInitialize(config)).toResolve();
expect(process.env.AWS_EC2_METADATA_DISABLED).toBeUndefined();
expect(process.env.METADATA_SERVER_DETECTION).toBeUndefined();
});
});
});
9 changes: 9 additions & 0 deletions lib/workers/global/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ function setGlobalHostRules(config: RenovateConfig): void {
}
}

function configureThirdPartyLibraries(config: AllConfig): void {
if (!config.useCloudMetadataServices) {
logger.debug('Disabling the use of cloud metadata services');
process.env.AWS_EC2_METADATA_DISABLED = 'true'; // See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-list
process.env.METADATA_SERVER_DETECTION = 'none'; // See https://cloud.google.com/nodejs/docs/reference/gcp-metadata/latest#environment-variables
}
}

export async function globalInitialize(
config_: AllConfig,
): Promise<RenovateConfig> {
Expand All @@ -76,6 +84,7 @@ export async function globalInitialize(
limitCommitsPerRun(config);
setEmojiConfig(config);
setGlobalHostRules(config);
configureThirdPartyLibraries(config);
await initMergeConfidence();
return config;
}
Expand Down