aws-sdk-js icon indicating copy to clipboard operation
aws-sdk-js copied to clipboard

Node 18 Credentials Container Not Working

Open skulljoi opened this issue 4 years ago • 4 comments

Describe the bug


Important

Another news, with node 16 it try to use 127.0.0.1 but with node 18 it goes to ::1. But it is not listening in ::1 only 127.0.0.1 perhaps an issue with the GG Container that it is not listening for ipv6 only ipv4


When using node 18 with greengrass the credentials container does not work. you just set the enviroment variables:

export AWS_CONTAINER_AUTHORIZATION_TOKEN=XXXXXXXXXXXXXXXX export AWS_CONTAINER_CREDENTIALS_FULL_URI='http://localhost:45501/2016-11-01/credentialprovider/'

const AWS = require('aws-sdk'); AWS.config.region = 'eu-west-1'; const s3 = new AWS.S3(); const paramsConfig = { Bucket: BUCKET_NAME, Key: OBJECT_KEY, IfNoneMatch: OBJECT_TAG, }; const response = await s3.getObject(paramsConfig).promise();

and then you have not credentials provided. But rolling back to node16 everything works fine

Expected Behavior

With the environment defined this code should return the S3 Object.

Current Behavior

It just throw an exception telling that there is no credentials defined.

Reproduction Steps

install greengrass, add a component that access S3, make it dependable of the TokenExchange. Or make the credential container work from some other way. create the code example, and make it run.

export AWS_CONTAINER_AUTHORIZATION_TOKEN=XXXXXXXXXXXXXXXX export AWS_CONTAINER_CREDENTIALS_FULL_URI='http://localhost:45501/2016-11-01/credentialprovider/'

const AWS = require('aws-sdk'); AWS.config.region = 'eu-west-1'; const s3 = new AWS.S3(); const paramsConfig = { Bucket: BUCKET_NAME, Key: OBJECT_KEY, IfNoneMatch: OBJECT_TAG, }; const response = await s3.getObject(paramsConfig).promise();

Possible Solution

// FIX FOR GG problem with ipv6
if (process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI) {
	let localhostIpv4 = process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI;
	localhostIpv4 = localhostIpv4.replace('localhost', '127.0.0.1');
	process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI = localhostIpv4;
}

Additional Information/Context

No response

SDK version used

"aws-sdk": "^2.1071.0",

Environment details (OS name and version, etc.)

Raspberry armv7l GNU/Linux

skulljoi avatar Oct 17 '22 06:10 skulljoi

Another news, with node 16 it try to use 127.0.0.1 but with node 18 it goes to ::1. But it is not listening in ::1 only 127.0.0.1

skulljoi avatar Oct 24 '22 09:10 skulljoi

With a simple change it works

// FIX FOR GG problem with ipv6
if (process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI) {
	let localhostIpv4 = process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI;
	localhostIpv4 = localhostIpv4.replace('localhost', '127.0.0.1');
	process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI = localhostIpv4;
}

skulljoi avatar Oct 26 '22 10:10 skulljoi

Hey @skulljoi thanks for opening this issue, I was not able to follow up with the reproduction steps, perhaps is it possible to mention more steps there on how to set it up, maybe a repo ? Also can you mention where are you trying to add the code that you have mentioned?

ajredniwja avatar Oct 31 '22 02:10 ajredniwja

I was not sure where to open the issue, but guess it is a problem with TokenExchange in the Greengrass service: https://github.com/aws-greengrass/aws-greengrass-nucleus/issues/1348

But to reproduce, you need an ethernet driver with ipv4 and ipv6. Install the greengrass 2.8.1 and create a component that will use the TokenExchangeService from greengrass. The AWS-SDK will look for the environment variable for the container that is started on ipv4 localhost address (127.0.0.1). But the SDK will look for the ipv6 address on localhost (::1)

skulljoi avatar Nov 02 '22 07:11 skulljoi