Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@smithy/credential-provider-imds

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/credential-provider-imds - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

52

dist-cjs/index.js

@@ -118,6 +118,8 @@ var __defProp = Object.defineProperty;

return () => retry(async () => {
const requestOptions = await getCmdsUri();
const requestOptions = await getCmdsUri({ logger: init.logger });
const credsResponse = JSON.parse(await requestFromEcsImds(timeout, requestOptions));
if (!isImdsCredentials(credsResponse)) {
throw new import_property_provider.CredentialsProviderError("Invalid response received from instance metadata service.");
throw new import_property_provider.CredentialsProviderError("Invalid response received from instance metadata service.", {
logger: init.logger
});
}

@@ -149,3 +151,3 @@ return fromImdsCredentials(credsResponse);

};
var getCmdsUri = /* @__PURE__ */ __name(async () => {
var getCmdsUri = /* @__PURE__ */ __name(async ({ logger }) => {
if (process.env[ENV_CMDS_RELATIVE_URI]) {

@@ -160,12 +162,12 @@ return {

if (!parsed.hostname || !(parsed.hostname in GREENGRASS_HOSTS)) {
throw new import_property_provider.CredentialsProviderError(
`${parsed.hostname} is not a valid container metadata service hostname`,
false
);
throw new import_property_provider.CredentialsProviderError(`${parsed.hostname} is not a valid container metadata service hostname`, {
tryNextLink: false,
logger
});
}
if (!parsed.protocol || !(parsed.protocol in GREENGRASS_PROTOCOLS)) {
throw new import_property_provider.CredentialsProviderError(
`${parsed.protocol} is not a valid container metadata service protocol`,
false
);
throw new import_property_provider.CredentialsProviderError(`${parsed.protocol} is not a valid container metadata service protocol`, {
tryNextLink: false,
logger
});
}

@@ -179,3 +181,6 @@ return {

`The container metadata credential provider cannot be used unless the ${ENV_CMDS_RELATIVE_URI} or ${ENV_CMDS_FULL_URI} environment variable is set`,
false
{
tryNextLink: false,
logger
}
);

@@ -301,4 +306,4 @@ }, "getCmdsUri");

var X_AWS_EC2_METADATA_TOKEN = "x-aws-ec2-metadata-token";
var fromInstanceMetadata = /* @__PURE__ */ __name((init = {}) => staticStabilityProvider(getInstanceImdsProvider(init), { logger: init.logger }), "fromInstanceMetadata");
var getInstanceImdsProvider = /* @__PURE__ */ __name((init) => {
var fromInstanceMetadata = /* @__PURE__ */ __name((init = {}) => staticStabilityProvider(getInstanceMetadataProvider(init), { logger: init.logger }), "fromInstanceMetadata");
var getInstanceMetadataProvider = /* @__PURE__ */ __name((init = {}) => {
let disableFetchToken = false;

@@ -320,3 +325,4 @@ const { logger, profile } = init;

throw new import_property_provider.CredentialsProviderError(
`${AWS_EC2_METADATA_V1_DISABLED} not set in env, checking config file next.`
`${AWS_EC2_METADATA_V1_DISABLED} not set in env, checking config file next.`,
{ logger: init.logger }
);

@@ -367,3 +373,3 @@ }

try {
creds = await getCredentialsFromProfile(imdsProfile, options);
creds = await getCredentialsFromProfile(imdsProfile, options, init);
} catch (err) {

@@ -407,3 +413,3 @@ if (err.statusCode === 401) {

};
}, "getInstanceImdsProvider");
}, "getInstanceMetadataProvider");
var getMetadataToken = /* @__PURE__ */ __name(async (options) => httpRequest({

@@ -418,4 +424,4 @@ ...options,

var getProfile = /* @__PURE__ */ __name(async (options) => (await httpRequest({ ...options, path: IMDS_PATH })).toString(), "getProfile");
var getCredentialsFromProfile = /* @__PURE__ */ __name(async (profile, options) => {
const credsResponse = JSON.parse(
var getCredentialsFromProfile = /* @__PURE__ */ __name(async (profile, options, init) => {
const credentialsResponse = JSON.parse(
(await httpRequest({

@@ -426,6 +432,8 @@ ...options,

);
if (!isImdsCredentials(credsResponse)) {
throw new import_property_provider.CredentialsProviderError("Invalid response received from instance metadata service.");
if (!isImdsCredentials(credentialsResponse)) {
throw new import_property_provider.CredentialsProviderError("Invalid response received from instance metadata service.", {
logger: init.logger
});
}
return fromImdsCredentials(credsResponse);
return fromImdsCredentials(credentialsResponse);
}, "getCredentialsFromProfile");

@@ -432,0 +440,0 @@ // Annotate the CommonJS export names for ESM import in node:

@@ -13,6 +13,8 @@ import { CredentialsProviderError } from "@smithy/property-provider";

return () => retry(async () => {
const requestOptions = await getCmdsUri();
const requestOptions = await getCmdsUri({ logger: init.logger });
const credsResponse = JSON.parse(await requestFromEcsImds(timeout, requestOptions));
if (!isImdsCredentials(credsResponse)) {
throw new CredentialsProviderError("Invalid response received from instance metadata service.");
throw new CredentialsProviderError("Invalid response received from instance metadata service.", {
logger: init.logger,
});
}

@@ -44,3 +46,3 @@ return fromImdsCredentials(credsResponse);

};
const getCmdsUri = async () => {
const getCmdsUri = async ({ logger }) => {
if (process.env[ENV_CMDS_RELATIVE_URI]) {

@@ -55,6 +57,12 @@ return {

if (!parsed.hostname || !(parsed.hostname in GREENGRASS_HOSTS)) {
throw new CredentialsProviderError(`${parsed.hostname} is not a valid container metadata service hostname`, false);
throw new CredentialsProviderError(`${parsed.hostname} is not a valid container metadata service hostname`, {
tryNextLink: false,
logger,
});
}
if (!parsed.protocol || !(parsed.protocol in GREENGRASS_PROTOCOLS)) {
throw new CredentialsProviderError(`${parsed.protocol} is not a valid container metadata service protocol`, false);
throw new CredentialsProviderError(`${parsed.protocol} is not a valid container metadata service protocol`, {
tryNextLink: false,
logger,
});
}

@@ -68,3 +76,6 @@ return {

` the ${ENV_CMDS_RELATIVE_URI} or ${ENV_CMDS_FULL_URI} environment` +
" variable is set", false);
" variable is set", {
tryNextLink: false,
logger,
});
};

@@ -15,4 +15,4 @@ import { loadConfig } from "@smithy/node-config-provider";

const X_AWS_EC2_METADATA_TOKEN = "x-aws-ec2-metadata-token";
export const fromInstanceMetadata = (init = {}) => staticStabilityProvider(getInstanceImdsProvider(init), { logger: init.logger });
const getInstanceImdsProvider = (init) => {
export const fromInstanceMetadata = (init = {}) => staticStabilityProvider(getInstanceMetadataProvider(init), { logger: init.logger });
const getInstanceMetadataProvider = (init = {}) => {
let disableFetchToken = false;

@@ -31,3 +31,3 @@ const { logger, profile } = init;

if (envValue === undefined) {
throw new CredentialsProviderError(`${AWS_EC2_METADATA_V1_DISABLED} not set in env, checking config file next.`);
throw new CredentialsProviderError(`${AWS_EC2_METADATA_V1_DISABLED} not set in env, checking config file next.`, { logger: init.logger });
}

@@ -72,3 +72,3 @@ return fallbackBlockedFromProcessEnv;

try {
creds = await getCredentialsFromProfile(imdsProfile, options);
creds = await getCredentialsFromProfile(imdsProfile, options, init);
}

@@ -126,11 +126,13 @@ catch (err) {

const getProfile = async (options) => (await httpRequest({ ...options, path: IMDS_PATH })).toString();
const getCredentialsFromProfile = async (profile, options) => {
const credsResponse = JSON.parse((await httpRequest({
const getCredentialsFromProfile = async (profile, options, init) => {
const credentialsResponse = JSON.parse((await httpRequest({
...options,
path: IMDS_PATH + profile,
})).toString());
if (!isImdsCredentials(credsResponse)) {
throw new CredentialsProviderError("Invalid response received from instance metadata service.");
if (!isImdsCredentials(credentialsResponse)) {
throw new CredentialsProviderError("Invalid response received from instance metadata service.", {
logger: init.logger,
});
}
return fromImdsCredentials(credsResponse);
return fromImdsCredentials(credentialsResponse);
};
{
"name": "@smithy/credential-provider-imds",
"version": "3.0.0",
"version": "3.1.0",
"description": "AWS credential provider that sources credentials from the EC2 instance metadata service and ECS container metadata service",

@@ -29,4 +29,4 @@ "main": "./dist-cjs/index.js",

"dependencies": {
"@smithy/node-config-provider": "^3.0.0",
"@smithy/property-provider": "^3.0.0",
"@smithy/node-config-provider": "^3.1.0",
"@smithy/property-provider": "^3.1.0",
"@smithy/types": "^3.0.0",

@@ -33,0 +33,0 @@ "@smithy/url-parser": "^3.0.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc