Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAM Token retrieval in DefaultTokenProvider does not honor provided client settings #37

Closed
everlylfc opened this issue Mar 11, 2021 · 3 comments

Comments

@everlylfc
Copy link

everlylfc commented Mar 11, 2021

I was having trouble applying connection timeouts to the overall flow of the code despite providing explicit values for client configuration which includes a connection timeout setting on the token provider, token manager, and the amazons3 client builder.

	private static final int S3_REQUEST_TIMEOUT_MS = 2000;
	private static final int S3_CONNECTION_TIMEOUT_MS = 1000;
	private static final int S3_CLIENT_EXECUTION_TIMEOUT_MS = 15000;
	private static final int S3_MAX_ERROR_RETRY = 5;

	public static AmazonS3 getAmazonS3(final String apiKey, final String endpoint, final String location, final String serviceInstanceId) {
		String iamEndpoint;
		if (endpoint.contains("cloud-object-storage.test.appdomain.cloud") || endpoint.contains("objectstorage.uat")) {
			iamEndpoint = "https://iam.test.cloud.ibm.com/identity/token";
		} else {
			iamEndpoint = "https://iam.cloud.ibm.com/identity/token";
		}

		ClientConfiguration clientConfig = new ClientConfiguration().withRequestTimeout(S3_REQUEST_TIMEOUT_MS).withConnectionTimeout(S3_CONNECTION_TIMEOUT_MS)
				.withClientExecutionTimeout(S3_CLIENT_EXECUTION_TIMEOUT_MS)
				.withRetryPolicy(PredefinedRetryPolicies.getDefaultRetryPolicyWithCustomMaxRetries(S3_MAX_ERROR_RETRY));
		clientConfig.setUseTcpKeepAlive(true);

		final DefaultTokenProvider tokenProvider = new DefaultTokenProvider(apiKey);
		tokenProvider.setHttpClientSettings(HttpClientSettings.adapt(clientConfig));
		tokenProvider.setIamEndpoint(iamEndpoint);
		final DefaultTokenManager tokenManager = new DefaultTokenManager(tokenProvider);
		tokenManager.setIamEndpoint(iamEndpoint);
		tokenManager.setIamMaxRetry(S3_MAX_ERROR_RETRY);
		tokenManager.setClientConfiguration(clientConfig);
		final BasicIBMOAuthCredentials credentials = new BasicIBMOAuthCredentials(tokenManager, serviceInstanceId);

		return AmazonS3ClientBuilder.standard().withIAMEndpoint(iamEndpoint).withCredentials(new AWSStaticCredentialsProvider(credentials))
				.withEndpointConfiguration(new EndpointConfiguration(endpoint, location)).withPathStyleAccessEnabled(true).withClientConfiguration(clientConfig)
				.build();
	}

I pulled the source code and changed this section to explicitly set a request config to test if this was the issue:

RequestConfig config = RequestConfig.custom().setConnectTimeout(1000).build();
HttpClient client = builder.setSSLSocketFactory(sslsf).setDefaultRequestConfig(config).build();

With this explicit setting, the behavior was what I was expecting. It seems the token provider is not configured with the client configuration that is provided.

@IBMeric
Copy link
Member

IBMeric commented Mar 16, 2021

Thank you for your report and investigation. We have an internal ticket tracking this item.

@IBMeric
Copy link
Member

IBMeric commented Jan 18, 2022

@everlylfc This issue has been resolved in 2.11.1. Please verify and close this ticket.

@IBMeric
Copy link
Member

IBMeric commented Jan 25, 2022

Closing ticket as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants