Skip to content

Commit 2831ccc

Browse files
committed
Merge pull request ManageIQ#630 from alauddinulaganathan/assume_role_support_for_aws_eks_credentials
Assume role support for aws eks credentials (cherry picked from commit 9f95df3)
1 parent 7ffc2dd commit 2831ccc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,14 @@ require 'aws-sdk-core'
313313
credentials = Aws::Credentials.new(access_key, secret_key)
314314
# Or a profile
315315
credentials = Aws::SharedCredentials.new(profile_name: 'default').credentials
316+
# Or for an STS Assumed Role Credentials or any other credential Provider other than Static Credentials
317+
credentials = Aws::AssumeRoleCredentials.new({ client: sts_client, role_arn: role_arn, role_session_name: session_name })
316318

319+
# Kubeclient Auth Options
317320
auth_options = {
318321
bearer_token: Kubeclient::AmazonEksCredentials.token(credentials, eks_cluster_name)
319322
}
323+
320324
client = Kubeclient::Client.new(
321325
eks_cluster_https_endpoint, 'v1', auth_options: auth_options
322326
)

Diff for: lib/kubeclient/aws_eks_credentials.rb

+15-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@ def token(credentials, eks_cluster, region: 'us-east-1')
2020
end
2121
# https://github.com/aws/aws-sdk-ruby/pull/1848
2222
# Get a signer
23-
signer = Aws::Sigv4::Signer.new(
24-
service: 'sts',
25-
region: region,
26-
credentials: credentials
27-
)
23+
signer = if credentials.respond_to?(:credentials)
24+
Aws::Sigv4::Signer.new(
25+
service: 'sts',
26+
region: region,
27+
credentials_provider: credentials
28+
)
29+
else
30+
Aws::Sigv4::Signer.new(
31+
service: 'sts',
32+
region: region,
33+
credentials: credentials
34+
)
35+
end
36+
37+
credentials = credentials.credentials if credentials.respond_to?(:credentials)
2838

2939
# https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Sigv4/Signer.html#presign_url-instance_method
3040
presigned_url_string = signer.presign_url(

0 commit comments

Comments
 (0)