Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(credential-provider-imds): support IMDS for IPv6 endpoints (#2660)
- Loading branch information
Showing
13 changed files
with
278 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum Endpoint { | ||
IPv4 = "http://169.254.169.254", | ||
IPv6 = "http://[fd00:ec2::254]", | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/credential-provider-imds/src/config/EndpointConfigOptions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CONFIG_ENDPOINT_NAME, ENDPOINT_CONFIG_OPTIONS, ENV_ENDPOINT_NAME } from "./EndpointConfigOptions"; | ||
|
||
describe("ENDPOINT_CONFIG_OPTIONS", () => { | ||
describe("environmentVariableSelector", () => { | ||
const { environmentVariableSelector } = ENDPOINT_CONFIG_OPTIONS; | ||
it.each([undefined, "mockEndpoint"])(`when env[${ENV_ENDPOINT_NAME}]: %s`, (mockEndpoint) => { | ||
expect(environmentVariableSelector({ [ENV_ENDPOINT_NAME]: mockEndpoint })).toBe(mockEndpoint); | ||
}); | ||
}); | ||
|
||
describe("configFileSelector", () => { | ||
const { configFileSelector } = ENDPOINT_CONFIG_OPTIONS; | ||
it.each([undefined, "mockEndpoint"])(`when env[${CONFIG_ENDPOINT_NAME}]: %s`, (mockEndpoint) => { | ||
expect(configFileSelector({ [CONFIG_ENDPOINT_NAME]: mockEndpoint })).toBe(mockEndpoint); | ||
}); | ||
}); | ||
|
||
it("default returns undefined", () => { | ||
const { default: defaultKey } = ENDPOINT_CONFIG_OPTIONS; | ||
expect(defaultKey).toBe(undefined); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/credential-provider-imds/src/config/EndpointConfigOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider"; | ||
|
||
export const ENV_ENDPOINT_NAME = "AWS_EC2_METADATA_SERVICE_ENDPOINT"; | ||
export const CONFIG_ENDPOINT_NAME = "ec2_metadata_service_endpoint"; | ||
|
||
export const ENDPOINT_CONFIG_OPTIONS: LoadedConfigSelectors<string | undefined> = { | ||
environmentVariableSelector: (env) => env[ENV_ENDPOINT_NAME], | ||
configFileSelector: (profile) => profile[CONFIG_ENDPOINT_NAME], | ||
default: undefined, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum EndpointMode { | ||
IPv4 = "IPv4", | ||
IPv6 = "IPv6", | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/credential-provider-imds/src/config/EndpointModeConfigOptions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { EndpointMode } from "./EndpointMode"; | ||
import { | ||
CONFIG_ENDPOINT_MODE_NAME, | ||
ENDPOINT_MODE_CONFIG_OPTIONS, | ||
ENV_ENDPOINT_MODE_NAME, | ||
} from "./EndpointModeConfigOptions"; | ||
|
||
describe("ENDPOINT_MODE_CONFIG_OPTIONS", () => { | ||
describe("environmentVariableSelector", () => { | ||
const { environmentVariableSelector } = ENDPOINT_MODE_CONFIG_OPTIONS; | ||
it.each([undefined, "mockEndpointMode"])(`when env[${ENV_ENDPOINT_MODE_NAME}]: %s`, (mockEndpoint) => { | ||
expect(environmentVariableSelector({ [ENV_ENDPOINT_MODE_NAME]: mockEndpoint })).toBe(mockEndpoint); | ||
}); | ||
}); | ||
|
||
describe("configFileSelector", () => { | ||
const { configFileSelector } = ENDPOINT_MODE_CONFIG_OPTIONS; | ||
it.each([undefined, "mockEndpointMode"])(`when env[${CONFIG_ENDPOINT_MODE_NAME}]: %s`, (mockEndpoint) => { | ||
expect(configFileSelector({ [CONFIG_ENDPOINT_MODE_NAME]: mockEndpoint })).toBe(mockEndpoint); | ||
}); | ||
}); | ||
|
||
it(`default returns ${EndpointMode.IPv4}`, () => { | ||
const { default: defaultKey } = ENDPOINT_MODE_CONFIG_OPTIONS; | ||
expect(defaultKey).toBe(EndpointMode.IPv4); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/credential-provider-imds/src/config/EndpointModeConfigOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider"; | ||
|
||
import { EndpointMode } from "./EndpointMode"; | ||
|
||
export const ENV_ENDPOINT_MODE_NAME = "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE"; | ||
export const CONFIG_ENDPOINT_MODE_NAME = "ec2_metadata_service_endpoint_mode"; | ||
|
||
export const ENDPOINT_MODE_CONFIG_OPTIONS: LoadedConfigSelectors<string | undefined> = { | ||
environmentVariableSelector: (env) => env[ENV_ENDPOINT_MODE_NAME], | ||
configFileSelector: (profile) => profile[CONFIG_ENDPOINT_MODE_NAME], | ||
default: EndpointMode.IPv4, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.