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

InvalidTokenId error when using Accesskey and SecretAccessKey returned from the response of AssumeRoleWithCertificate. #19928

Closed
haylch opened this issue Jun 13, 2024 Discussed in #19927 · 6 comments

Comments

@haylch
Copy link

haylch commented Jun 13, 2024

Discussed in #19927

Originally posted by haylch June 13, 2024
Hi, anyone can help?

Using the Accesskey and SecretAccessKey returned from the response of AssumeRoleWithCertificate and apply with the following code:

    	MinioClient minioClientConn = MinioClient.builder()
    			.endpoint(endpoint_url)
    			.credentials(accessKeyId, secretAccessKey)
    			.httpClient(okHttpClient)
    			.build();

I got the following exception:
Error occurred: error occurred
ErrorResponse(code = InvalidTokenId, message = The security token included in the request is invalid ...

How do I connect to MinIO using the response from AssumeRoleWithCertificate? Do I have to use the SessionToken? How do I use it in java?

@harshavardhana
Copy link
Member

MinioClient minioClientConn = MinioClient.builder()
.endpoint(endpoint_url)
.credentials(accessKeyId, secretAccessKey)
.httpClient(okHttpClient)
.build();

You have to pass sessionToken as well

@harshavardhana
Copy link
Member

Also, please either open a discussion or a GitHub issue—don't do both. Please do not spam everywhere.

@haylch
Copy link
Author

haylch commented Jun 13, 2024

How do I pass a sessionToken to it using minio java? The .credentials in MinioClient.builder() only accepts accessKeyId and secretAccessKey. Do you have an sample code on it for the connection?

@haylch
Copy link
Author

haylch commented Jun 13, 2024

Thanks for your help. I got it working but I wonder if it is the correct or proper way to connect?

//Get credentials from AssumeRoleWithCertificate using CertificateIdentityProvider
Provider certIdentityProvider = new CertificateIdentityProvider(endpoint_url, sslSocketFactory, x509TrustManager, null, null);
Credentials credentials = certIdentityProvider.fetch();

//Use credentials from AssumeRoleWithCertificate to connect using StaticProvider
String accessKeyId = credentials.accessKey();
String secretAccessKey = credentials.secretKey();
String sessionToken = credentials.sessionToken();
Provider staticProvider = new StaticProvider(accessKeyId, secretAccessKey, sessionToken);

MinioClient minioClientConn = MinioClient.builder()
.endpoint(endpoint_url)
.credentialsProvider(staticProvider)
.httpClient(okHttpClient)
.build();

@harshavardhana
Copy link
Member

//Get credentials from AssumeRoleWithCertificate using CertificateIdentityProvider
Provider certIdentityProvider = new CertificateIdentityProvider(endpoint_url, sslSocketFactory, x509TrustManager, null, null);

MinioClient minioClientConn = MinioClient.builder()
.endpoint(endpoint_url)
.credentialsProvider(certIdentityProvider)
.httpClient(okHttpClient)
.build();

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

No branches or pull requests

2 participants