@smithy/credential-provider-imds 4.3.9 → 4.4.0
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-cjs/index.js +23 -24
- package/package.json +6 -6
package/dist-cjs/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var node_http = require('node:http');
|
|
5
|
-
var protocols = require('@smithy/core/protocols');
|
|
1
|
+
const { ProviderError, CredentialsProviderError, loadConfig } = require("@smithy/core/config");
|
|
2
|
+
const node_http = require("node:http");
|
|
3
|
+
const { parseUrl } = require("@smithy/core/protocols");
|
|
6
4
|
|
|
7
5
|
const isImdsCredentials = (arg) => Boolean(arg) &&
|
|
8
6
|
typeof arg === "object" &&
|
|
@@ -30,17 +28,17 @@ function httpRequest(options) {
|
|
|
30
28
|
hostname: options.hostname?.replace(/^\[(.+)\]$/, "$1"),
|
|
31
29
|
});
|
|
32
30
|
req.on("error", (err) => {
|
|
33
|
-
reject(Object.assign(new
|
|
31
|
+
reject(Object.assign(new ProviderError("Unable to connect to instance metadata service"), err));
|
|
34
32
|
req.destroy();
|
|
35
33
|
});
|
|
36
34
|
req.on("timeout", () => {
|
|
37
|
-
reject(new
|
|
35
|
+
reject(new ProviderError("TimeoutError from instance metadata service"));
|
|
38
36
|
req.destroy();
|
|
39
37
|
});
|
|
40
38
|
req.on("response", (res) => {
|
|
41
39
|
const { statusCode = 400 } = res;
|
|
42
40
|
if (statusCode < 200 || 300 <= statusCode) {
|
|
43
|
-
reject(Object.assign(new
|
|
41
|
+
reject(Object.assign(new ProviderError("Error response received from instance metadata service"), { statusCode }));
|
|
44
42
|
req.destroy();
|
|
45
43
|
}
|
|
46
44
|
const chunks = [];
|
|
@@ -73,7 +71,7 @@ const fromContainerMetadata = (init = {}) => {
|
|
|
73
71
|
const requestOptions = await getCmdsUri({ logger: init.logger });
|
|
74
72
|
const credsResponse = JSON.parse(await requestFromEcsImds(timeout, requestOptions));
|
|
75
73
|
if (!isImdsCredentials(credsResponse)) {
|
|
76
|
-
throw new
|
|
74
|
+
throw new CredentialsProviderError("Invalid response received from instance metadata service.", {
|
|
77
75
|
logger: init.logger,
|
|
78
76
|
});
|
|
79
77
|
}
|
|
@@ -109,16 +107,16 @@ const getCmdsUri = async ({ logger }) => {
|
|
|
109
107
|
parsed = new URL(process.env[ENV_CMDS_FULL_URI]);
|
|
110
108
|
}
|
|
111
109
|
catch {
|
|
112
|
-
throw new
|
|
110
|
+
throw new CredentialsProviderError(`${process.env[ENV_CMDS_FULL_URI]} is not a valid container metadata service URL`, { tryNextLink: false, logger });
|
|
113
111
|
}
|
|
114
112
|
if (!parsed.hostname || !GREENGRASS_HOSTS.has(parsed.hostname)) {
|
|
115
|
-
throw new
|
|
113
|
+
throw new CredentialsProviderError(`${parsed.hostname} is not a valid container metadata service hostname`, {
|
|
116
114
|
tryNextLink: false,
|
|
117
115
|
logger,
|
|
118
116
|
});
|
|
119
117
|
}
|
|
120
118
|
if (!parsed.protocol || !GREENGRASS_PROTOCOLS.has(parsed.protocol)) {
|
|
121
|
-
throw new
|
|
119
|
+
throw new CredentialsProviderError(`${parsed.protocol} is not a valid container metadata service protocol`, {
|
|
122
120
|
tryNextLink: false,
|
|
123
121
|
logger,
|
|
124
122
|
});
|
|
@@ -130,7 +128,7 @@ const getCmdsUri = async ({ logger }) => {
|
|
|
130
128
|
port: parsed.port ? parseInt(parsed.port, 10) : undefined,
|
|
131
129
|
};
|
|
132
130
|
}
|
|
133
|
-
throw new
|
|
131
|
+
throw new CredentialsProviderError("The container metadata credential provider cannot be used unless" +
|
|
134
132
|
` the ${ENV_CMDS_RELATIVE_URI} or ${ENV_CMDS_FULL_URI} environment` +
|
|
135
133
|
" variable is set", {
|
|
136
134
|
tryNextLink: false,
|
|
@@ -138,7 +136,7 @@ const getCmdsUri = async ({ logger }) => {
|
|
|
138
136
|
});
|
|
139
137
|
};
|
|
140
138
|
|
|
141
|
-
class InstanceMetadataV1FallbackError extends
|
|
139
|
+
class InstanceMetadataV1FallbackError extends CredentialsProviderError {
|
|
142
140
|
tryNextLink;
|
|
143
141
|
name = "InstanceMetadataV1FallbackError";
|
|
144
142
|
constructor(message, tryNextLink = true) {
|
|
@@ -148,11 +146,11 @@ class InstanceMetadataV1FallbackError extends config.CredentialsProviderError {
|
|
|
148
146
|
}
|
|
149
147
|
}
|
|
150
148
|
|
|
151
|
-
|
|
149
|
+
var Endpoint;
|
|
152
150
|
(function (Endpoint) {
|
|
153
151
|
Endpoint["IPv4"] = "http://169.254.169.254";
|
|
154
152
|
Endpoint["IPv6"] = "http://[fd00:ec2::254]";
|
|
155
|
-
})(
|
|
153
|
+
})(Endpoint || (Endpoint = {}));
|
|
156
154
|
|
|
157
155
|
const ENV_ENDPOINT_NAME = "AWS_EC2_METADATA_SERVICE_ENDPOINT";
|
|
158
156
|
const CONFIG_ENDPOINT_NAME = "ec2_metadata_service_endpoint";
|
|
@@ -176,15 +174,15 @@ const ENDPOINT_MODE_CONFIG_OPTIONS = {
|
|
|
176
174
|
default: EndpointMode.IPv4,
|
|
177
175
|
};
|
|
178
176
|
|
|
179
|
-
const getInstanceMetadataEndpoint = async () =>
|
|
180
|
-
const getFromEndpointConfig = async () =>
|
|
177
|
+
const getInstanceMetadataEndpoint = async () => parseUrl((await getFromEndpointConfig()) || (await getFromEndpointModeConfig()));
|
|
178
|
+
const getFromEndpointConfig = async () => loadConfig(ENDPOINT_CONFIG_OPTIONS)();
|
|
181
179
|
const getFromEndpointModeConfig = async () => {
|
|
182
|
-
const endpointMode = await
|
|
180
|
+
const endpointMode = await loadConfig(ENDPOINT_MODE_CONFIG_OPTIONS)();
|
|
183
181
|
switch (endpointMode) {
|
|
184
182
|
case EndpointMode.IPv4:
|
|
185
|
-
return
|
|
183
|
+
return Endpoint.IPv4;
|
|
186
184
|
case EndpointMode.IPv6:
|
|
187
|
-
return
|
|
185
|
+
return Endpoint.IPv6;
|
|
188
186
|
default:
|
|
189
187
|
throw new Error(`Unsupported endpoint mode: ${endpointMode}.` + ` Select from ${Object.values(EndpointMode)}`);
|
|
190
188
|
}
|
|
@@ -248,12 +246,12 @@ const getInstanceMetadataProvider = (init = {}) => {
|
|
|
248
246
|
if (isImdsV1Fallback) {
|
|
249
247
|
let fallbackBlockedFromProfile = false;
|
|
250
248
|
let fallbackBlockedFromProcessEnv = false;
|
|
251
|
-
const configValue = await
|
|
249
|
+
const configValue = await loadConfig({
|
|
252
250
|
environmentVariableSelector: (env) => {
|
|
253
251
|
const envValue = env[AWS_EC2_METADATA_V1_DISABLED];
|
|
254
252
|
fallbackBlockedFromProcessEnv = !!envValue && envValue !== "false";
|
|
255
253
|
if (envValue === undefined) {
|
|
256
|
-
throw new
|
|
254
|
+
throw new CredentialsProviderError(`${AWS_EC2_METADATA_V1_DISABLED} not set in env, checking config file next.`, { logger: init.logger });
|
|
257
255
|
}
|
|
258
256
|
return fallbackBlockedFromProcessEnv;
|
|
259
257
|
},
|
|
@@ -352,7 +350,7 @@ const getCredentialsFromProfile = async (profile, options, init) => {
|
|
|
352
350
|
path: IMDS_PATH + profile,
|
|
353
351
|
})).toString());
|
|
354
352
|
if (!isImdsCredentials(credentialsResponse)) {
|
|
355
|
-
throw new
|
|
353
|
+
throw new CredentialsProviderError("Invalid response received from instance metadata service.", {
|
|
356
354
|
logger: init.logger,
|
|
357
355
|
});
|
|
358
356
|
}
|
|
@@ -364,6 +362,7 @@ exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
|
|
364
362
|
exports.ENV_CMDS_AUTH_TOKEN = ENV_CMDS_AUTH_TOKEN;
|
|
365
363
|
exports.ENV_CMDS_FULL_URI = ENV_CMDS_FULL_URI;
|
|
366
364
|
exports.ENV_CMDS_RELATIVE_URI = ENV_CMDS_RELATIVE_URI;
|
|
365
|
+
exports.Endpoint = Endpoint;
|
|
367
366
|
exports.fromContainerMetadata = fromContainerMetadata;
|
|
368
367
|
exports.fromInstanceMetadata = fromInstanceMetadata;
|
|
369
368
|
exports.getInstanceMetadataEndpoint = getInstanceMetadataEndpoint;
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/credential-provider-imds",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "AWS credential provider that sources credentials from the EC2 instance metadata service and ECS container metadata service",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'",
|
|
9
|
-
"build:es:cjs": "yarn g:tsc -p tsconfig.es.json && node ../../scripts/inline",
|
|
10
|
-
"build:types": "yarn g:tsc -p tsconfig.types.json",
|
|
9
|
+
"build:es:cjs": "premove dist-es && yarn g:tsc -p tsconfig.es.json && node ../../scripts/inline",
|
|
10
|
+
"build:types": "premove dist-types && yarn g:tsc -p tsconfig.types.json",
|
|
11
11
|
"build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
|
|
12
|
-
"clean": "premove dist-cjs dist-es dist-types
|
|
12
|
+
"clean": "premove dist-cjs dist-es dist-types",
|
|
13
13
|
"format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
|
|
14
14
|
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
|
|
15
15
|
"stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@smithy/core": "^3.
|
|
31
|
-
"@smithy/types": "^4.
|
|
30
|
+
"@smithy/core": "^3.25.0",
|
|
31
|
+
"@smithy/types": "^4.15.0",
|
|
32
32
|
"tslib": "^2.6.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|