question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

S3Client requestHandler proxy settings ignored when credentials supplied

See original GitHub issue

Describe the bug

When supplying requestHandler and credentials to the S3Client constructor, the proxy settings in requestHandler appear to be ignored.

If just supplying requestHandler with no credentials to the S3Client constructor, then the proxy settings work and take effect.

So the issue appears to be the combination of using credentials (loaded from the AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE environment variables) with the requestHandler.

We have a requirement to be able to use both web identity tokens and use a proxy, so are looking to find a resolution or workaround.

Your environment

SDK version number

"@aws-sdk/client-s3": "^3.14.0",
"@aws-sdk/client-sts": "^3.14.0",
"@aws-sdk/credential-provider-web-identity": "^3.13.1",
"@aws-sdk/node-http-handler": "^3.13.1",
"@aws-sdk/types": "^3.13.1",
"typescript": "^4.2.4",

Is the issue in the browser/Node.js/ReactNative?

Node.js / Typescript

Details of the browser/Node.js/ReactNative version

$ node -v
v14.16.1

Steps to reproduce

Assuming that we have the following environment variables correctly setup and configured: AWS_ROLE_ARN, AWS_WEB_IDENTITY_TOKEN_FILE and http_proxy

The code which demonstrates the issue is as follows:

import { S3Client } from "@aws-sdk/client-s3";
import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
import ProxyAgent from "proxy-agent";
import { getDefaultRoleAssumerWithWebIdentity } from "@aws-sdk/client-sts";
import { fromTokenFile } from "@aws-sdk/credential-provider-web-identity";

const proxy = new ProxyAgent();
const requestHandler = new NodeHttpHandler({ 
  httpAgent: proxy, 
  httpsAgent: proxy 
});
const storageClient = new S3Client({ 
  credentials: fromTokenFile({
    roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity()
  }), 
  requestHandler: requestHandler 
});

Which correctly reads the secret information from the web identity token file, however then does not use the proxy and attempts to connect direct.

The following code which only sends the requestHandler in the constructor does not suffer from this problem. The following code works with the proxy:

import { S3Client } from "@aws-sdk/client-s3";
import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
import ProxyAgent from "proxy-agent";

const proxy = new ProxyAgent();
const requestHandler = new NodeHttpHandler({ 
  httpAgent: proxy, 
  httpsAgent: proxy 
});
const storageClient = new S3Client({ 
  requestHandler: requestHandler 
});

For our use however we need both to be able to use the AWS_WEB_IDENTITY_TOKEN_FILE and have a proxy configured.

I cannot find any relevant documentation regarding this behaviour, so it appears to be a bug. If a fix or workaround could be provided that would be much appreciated.

Note: Creating a new ProxyAgent without a URL will search for default proxy settings and does pick up from “http_proxy” and/or “https_proxy” environment variables

Observed behavior

When the credentials are passed into the S3Client constructor, then the requestHandler which applies the proxy settings (defined by ENV variables “http_proxy” and/or “https_proxy”) are not used for the subsequent calls to S3.

Connections appear to go direct (not via proxy)

Expected behavior

The proxy settings setup in the requestHandler should still be applied even when credentials are loaded when setting up the S3Client.

The proxy works fine if credentials are not specified in the S3Client constructor. So this appears to be just an issue when BOTH “credentials” and “requestHandler” are passed in.

Screenshots

N/A

Additional context

N/A

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MrBlueMoocommented, May 25, 2021

@AllanZhengYP @ajredniwja Many thanks for providing both a workaround and a fix in next release (allowing us to specify the requestHandler on the sts client used by default role assumer). I have just implemented the workaround with setting up a role assumer based on the example you provided, and I will verify this all functions as expected with proxy tomorrow.

0reactions
github-actions[bot]commented, Jun 16, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amazon S3 client connect through proxy - putObject getting ...
I stepped through everything in a debugger and found that the cause of the problem is the Amazon S3 client code expecting a...
Read more >
aws-sdk-java/AmazonS3Client.java at master - GitHub
<li>Instance Profile Credentials - delivered through the Amazon EC2 ... connects to Amazon S3 (e.g. proxy settings, retry counts, etc).
Read more >
Amazon S3 Client :: Quarkiverse Documentation - GitHub Pages
Configuration property Type Default boolean false string localstack AWS SDK client configurations Type Default
Read more >
Spring Cloud
In order to make calls to the Amazon Web Service the credentials must be configured for the the Amazon SDK. Spring Cloud AWS...
Read more >
AmazonS3Client (AWS SDK for Java - 1.12.372)
secretKey; Instance Profile Credentials - delivered through the Amazon EC2 ... this client connects to Amazon S3 (e.g. proxy settings, retry counts, etc)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found