aws-sdk-core 3.226.3 → 3.241.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +138 -0
- data/VERSION +1 -1
- data/lib/aws-defaults/default_configuration.rb +2 -1
- data/lib/aws-sdk-core/assume_role_credentials.rb +8 -8
- data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +2 -2
- data/lib/aws-sdk-core/client_stubs.rb +6 -0
- data/lib/aws-sdk-core/credential_provider_chain.rb +71 -22
- data/lib/aws-sdk-core/ecs_credentials.rb +13 -13
- data/lib/aws-sdk-core/endpoints.rb +37 -13
- data/lib/aws-sdk-core/errors.rb +3 -0
- data/lib/aws-sdk-core/instance_profile_credentials.rb +7 -7
- data/lib/aws-sdk-core/login_credentials.rb +229 -0
- data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +145 -75
- data/lib/aws-sdk-core/plugins/credentials_configuration.rb +75 -59
- data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +28 -16
- data/lib/aws-sdk-core/plugins/sign.rb +23 -28
- data/lib/aws-sdk-core/plugins/stub_responses.rb +6 -0
- data/lib/aws-sdk-core/plugins/user_agent.rb +4 -1
- data/lib/aws-sdk-core/refreshing_credentials.rb +8 -11
- data/lib/aws-sdk-core/shared_config.rb +30 -0
- data/lib/aws-sdk-core/sso_credentials.rb +1 -1
- data/lib/aws-sdk-core/static_token_provider.rb +1 -2
- data/lib/aws-sdk-core/token.rb +3 -3
- data/lib/aws-sdk-core/token_provider.rb +4 -0
- data/lib/aws-sdk-core/token_provider_chain.rb +2 -6
- data/lib/aws-sdk-core.rb +4 -0
- data/lib/aws-sdk-signin/client.rb +604 -0
- data/lib/aws-sdk-signin/client_api.rb +119 -0
- data/lib/aws-sdk-signin/customizations.rb +1 -0
- data/lib/aws-sdk-signin/endpoint_parameters.rb +69 -0
- data/lib/aws-sdk-signin/endpoint_provider.rb +59 -0
- data/lib/aws-sdk-signin/endpoints.rb +20 -0
- data/lib/aws-sdk-signin/errors.rb +122 -0
- data/lib/aws-sdk-signin/plugins/endpoints.rb +77 -0
- data/lib/aws-sdk-signin/resource.rb +26 -0
- data/lib/aws-sdk-signin/types.rb +299 -0
- data/lib/aws-sdk-signin.rb +63 -0
- data/lib/aws-sdk-sso/client.rb +24 -17
- data/lib/aws-sdk-sso/endpoint_parameters.rb +4 -4
- data/lib/aws-sdk-sso/endpoint_provider.rb +2 -2
- data/lib/aws-sdk-sso.rb +1 -1
- data/lib/aws-sdk-ssooidc/client.rb +43 -23
- data/lib/aws-sdk-ssooidc/client_api.rb +5 -0
- data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +4 -4
- data/lib/aws-sdk-ssooidc/errors.rb +10 -0
- data/lib/aws-sdk-ssooidc/types.rb +27 -15
- data/lib/aws-sdk-ssooidc.rb +1 -1
- data/lib/aws-sdk-sts/client.rb +159 -28
- data/lib/aws-sdk-sts/client_api.rb +72 -0
- data/lib/aws-sdk-sts/customizations.rb +0 -1
- data/lib/aws-sdk-sts/endpoint_parameters.rb +5 -5
- data/lib/aws-sdk-sts/errors.rb +64 -0
- data/lib/aws-sdk-sts/presigner.rb +2 -6
- data/lib/aws-sdk-sts/types.rb +175 -6
- data/lib/aws-sdk-sts.rb +1 -1
- data/lib/seahorse/client/h2/handler.rb +6 -1
- data/lib/seahorse/client/net_http/patches.rb +44 -11
- metadata +27 -1
|
@@ -14,64 +14,68 @@ module Aws
|
|
|
14
14
|
|
|
15
15
|
option(:account_id, doc_type: String, docstring: '')
|
|
16
16
|
|
|
17
|
-
option(
|
|
17
|
+
option(
|
|
18
|
+
:profile,
|
|
18
19
|
doc_default: 'default',
|
|
19
20
|
doc_type: String,
|
|
20
|
-
docstring:
|
|
21
|
-
Used when loading credentials from the shared credentials file
|
|
22
|
-
|
|
21
|
+
docstring: <<~DOCS)
|
|
22
|
+
Used when loading credentials from the shared credentials file at `HOME/.aws/credentials`.
|
|
23
|
+
When not specified, 'default' is used.
|
|
23
24
|
DOCS
|
|
24
25
|
|
|
25
|
-
option(
|
|
26
|
+
option(
|
|
27
|
+
:credentials,
|
|
26
28
|
required: true,
|
|
27
29
|
doc_type: 'Aws::CredentialProvider',
|
|
28
30
|
rbs_type: 'untyped',
|
|
29
|
-
docstring:
|
|
30
|
-
Your AWS credentials. This can be
|
|
31
|
-
following classes:
|
|
31
|
+
docstring: <<~DOCS
|
|
32
|
+
Your AWS credentials used for authentication. This can be any class that includes and implements
|
|
33
|
+
`Aws::CredentialProvider`, or instance of any one of the following classes:
|
|
32
34
|
|
|
33
|
-
* `Aws::Credentials` - Used for configuring static, non-refreshing
|
|
34
|
-
|
|
35
|
+
* `Aws::Credentials` - Used for configuring static, non-refreshing
|
|
36
|
+
credentials.
|
|
35
37
|
|
|
36
|
-
* `Aws::SharedCredentials` - Used for loading static credentials from a
|
|
37
|
-
|
|
38
|
+
* `Aws::SharedCredentials` - Used for loading static credentials from a
|
|
39
|
+
shared file, such as `~/.aws/config`.
|
|
38
40
|
|
|
39
|
-
* `Aws::AssumeRoleCredentials` - Used when you need to assume a role.
|
|
41
|
+
* `Aws::AssumeRoleCredentials` - Used when you need to assume a role.
|
|
40
42
|
|
|
41
|
-
* `Aws::AssumeRoleWebIdentityCredentials` - Used when you need to
|
|
42
|
-
|
|
43
|
+
* `Aws::AssumeRoleWebIdentityCredentials` - Used when you need to
|
|
44
|
+
assume a role after providing credentials via the web.
|
|
43
45
|
|
|
44
|
-
* `Aws::SSOCredentials` - Used for loading credentials from AWS SSO using an
|
|
45
|
-
|
|
46
|
+
* `Aws::SSOCredentials` - Used for loading credentials from AWS SSO using an
|
|
47
|
+
access token generated from `aws login`.
|
|
46
48
|
|
|
47
|
-
* `Aws::ProcessCredentials` - Used for loading credentials from a
|
|
48
|
-
|
|
49
|
+
* `Aws::ProcessCredentials` - Used for loading credentials from a
|
|
50
|
+
process that outputs to stdout.
|
|
49
51
|
|
|
50
|
-
* `Aws::InstanceProfileCredentials` - Used for loading credentials
|
|
51
|
-
|
|
52
|
+
* `Aws::InstanceProfileCredentials` - Used for loading credentials
|
|
53
|
+
from an EC2 IMDS on an EC2 instance.
|
|
52
54
|
|
|
53
|
-
* `Aws::ECSCredentials` - Used for loading credentials from
|
|
54
|
-
|
|
55
|
+
* `Aws::ECSCredentials` - Used for loading credentials from
|
|
56
|
+
instances running in ECS.
|
|
55
57
|
|
|
56
|
-
* `Aws::CognitoIdentityCredentials` - Used for loading credentials
|
|
57
|
-
|
|
58
|
+
* `Aws::CognitoIdentityCredentials` - Used for loading credentials
|
|
59
|
+
from the Cognito Identity service.
|
|
58
60
|
|
|
59
|
-
When `:credentials` are not configured directly, the following
|
|
60
|
-
locations will be searched for credentials:
|
|
61
|
+
When `:credentials` are not configured directly, the following locations will be searched for credentials:
|
|
61
62
|
|
|
62
|
-
* `Aws.config[:credentials]`
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
* `Aws.config[:credentials]`
|
|
64
|
+
|
|
65
|
+
* The `:access_key_id`, `:secret_access_key`, `:session_token`, and
|
|
66
|
+
`:account_id` options.
|
|
67
|
+
|
|
68
|
+
* `ENV['AWS_ACCESS_KEY_ID']`, `ENV['AWS_SECRET_ACCESS_KEY']`,
|
|
69
|
+
`ENV['AWS_SESSION_TOKEN']`, and `ENV['AWS_ACCOUNT_ID']`.
|
|
70
|
+
|
|
71
|
+
* `~/.aws/credentials`
|
|
72
|
+
|
|
73
|
+
* `~/.aws/config`
|
|
74
|
+
|
|
75
|
+
* EC2/ECS IMDS instance profile - When used by default, the timeouts are very aggressive.
|
|
76
|
+
Construct and pass an instance of `Aws::InstanceProfileCredentials` or `Aws::ECSCredentials` to
|
|
77
|
+
enable retries and extended timeouts. Instance profile credential fetching can be disabled by
|
|
78
|
+
setting `ENV['AWS_EC2_METADATA_DISABLED']` to `true`.
|
|
75
79
|
DOCS
|
|
76
80
|
) do |config|
|
|
77
81
|
CredentialProviderChain.new(config).resolve
|
|
@@ -81,31 +85,43 @@ locations will be searched for credentials:
|
|
|
81
85
|
|
|
82
86
|
option(:instance_profile_credentials_timeout, 1)
|
|
83
87
|
|
|
84
|
-
option(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
following classes:
|
|
88
|
+
option(
|
|
89
|
+
:token_provider,
|
|
90
|
+
doc_type: 'Aws::TokenProvider',
|
|
91
|
+
rbs_type: 'untyped',
|
|
92
|
+
docstring: <<~DOCS
|
|
93
|
+
Your Bearer token used for authentication. This can be any class that includes and implements
|
|
94
|
+
`Aws::TokenProvider`, or instance of any one of the following classes:
|
|
91
95
|
|
|
92
|
-
* `Aws::StaticTokenProvider` - Used for configuring static, non-refreshing
|
|
93
|
-
|
|
96
|
+
* `Aws::StaticTokenProvider` - Used for configuring static, non-refreshing
|
|
97
|
+
tokens.
|
|
94
98
|
|
|
95
|
-
* `Aws::SSOTokenProvider` - Used for loading tokens from AWS SSO using an
|
|
96
|
-
|
|
99
|
+
* `Aws::SSOTokenProvider` - Used for loading tokens from AWS SSO using an
|
|
100
|
+
access token generated from `aws login`.
|
|
97
101
|
|
|
98
|
-
When `:token_provider` is not configured directly, the `Aws::TokenProviderChain`
|
|
99
|
-
will be used to search for tokens configured for your profile in shared configuration files.
|
|
100
|
-
|
|
102
|
+
When `:token_provider` is not configured directly, the `Aws::TokenProviderChain`
|
|
103
|
+
will be used to search for tokens configured for your profile in shared configuration files.
|
|
104
|
+
DOCS
|
|
101
105
|
) do |config|
|
|
102
|
-
|
|
103
|
-
StaticTokenProvider.new('token')
|
|
104
|
-
else
|
|
105
|
-
TokenProviderChain.new(config).resolve
|
|
106
|
-
end
|
|
106
|
+
TokenProviderChain.new(config).resolve
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
+
option(
|
|
110
|
+
:auth_scheme_preference,
|
|
111
|
+
doc_type: 'Array<String>',
|
|
112
|
+
rbs_type: 'Array[String]',
|
|
113
|
+
docstring: <<~DOCS
|
|
114
|
+
A list of preferred authentication schemes to use when making a request. Supported values are:
|
|
115
|
+
`sigv4`, `sigv4a`, `httpBearerAuth`, and `noAuth`. When set using `ENV['AWS_AUTH_SCHEME_PREFERENCE']` or in
|
|
116
|
+
shared config as `auth_scheme_preference`, the value should be a comma-separated list.
|
|
117
|
+
DOCS
|
|
118
|
+
) do |config|
|
|
119
|
+
value =
|
|
120
|
+
ENV['AWS_AUTH_SCHEME_PREFERENCE'] ||
|
|
121
|
+
Aws.shared_config.auth_scheme_preference(profile: config.profile) ||
|
|
122
|
+
''
|
|
123
|
+
value.gsub(' ', '').gsub("\t", '').split(',')
|
|
124
|
+
end
|
|
109
125
|
end
|
|
110
126
|
end
|
|
111
127
|
end
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
module Aws
|
|
4
4
|
module Plugins
|
|
5
5
|
module Retries
|
|
6
|
-
|
|
7
6
|
# @api private
|
|
8
7
|
class ClockSkew
|
|
9
|
-
|
|
10
8
|
CLOCK_SKEW_THRESHOLD = 5 * 60 # five minutes
|
|
11
9
|
|
|
12
10
|
def initialize
|
|
@@ -22,9 +20,9 @@ module Aws
|
|
|
22
20
|
end
|
|
23
21
|
|
|
24
22
|
# Gets the clock_correction in seconds to apply to a given endpoint
|
|
25
|
-
# @param endpoint [URI
|
|
23
|
+
# @param endpoint [URI, String]
|
|
26
24
|
def clock_correction(endpoint)
|
|
27
|
-
@mutex.synchronize { @endpoint_clock_corrections[endpoint
|
|
25
|
+
@mutex.synchronize { @endpoint_clock_corrections[normalized_endpoint(endpoint)] }
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
# The estimated skew factors in any clock skew from
|
|
@@ -35,7 +33,7 @@ module Aws
|
|
|
35
33
|
# Estimated Skew should not be used to correct clock skew errors
|
|
36
34
|
# it should only be used to estimate TTL for a request
|
|
37
35
|
def estimated_skew(endpoint)
|
|
38
|
-
@mutex.synchronize { @endpoint_estimated_skews[endpoint
|
|
36
|
+
@mutex.synchronize { @endpoint_estimated_skews[normalized_endpoint(endpoint)] }
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
# Determines whether a request has clock skew by comparing
|
|
@@ -55,9 +53,9 @@ module Aws
|
|
|
55
53
|
endpoint = context.http_request.endpoint
|
|
56
54
|
now_utc = Time.now.utc
|
|
57
55
|
server_time = server_time(context.http_response)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
return unless server_time && (now_utc - server_time).abs > CLOCK_SKEW_THRESHOLD
|
|
57
|
+
|
|
58
|
+
set_clock_correction(normalized_endpoint(endpoint), server_time - now_utc)
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
# Called for every request
|
|
@@ -69,20 +67,35 @@ module Aws
|
|
|
69
67
|
now_utc = Time.now.utc
|
|
70
68
|
server_time = server_time(context.http_response)
|
|
71
69
|
return unless server_time
|
|
70
|
+
|
|
72
71
|
@mutex.synchronize do
|
|
73
|
-
@endpoint_estimated_skews[endpoint
|
|
72
|
+
@endpoint_estimated_skews[normalized_endpoint(endpoint)] = server_time - now_utc
|
|
74
73
|
end
|
|
75
74
|
end
|
|
76
75
|
|
|
77
76
|
private
|
|
78
77
|
|
|
78
|
+
##
|
|
79
|
+
# @param endpoint [URI, String]
|
|
80
|
+
# the endpoint to normalize
|
|
81
|
+
#
|
|
82
|
+
# @return [String]
|
|
83
|
+
# the endpoint's schema, host, and port - without any path or query arguments
|
|
84
|
+
def normalized_endpoint(endpoint)
|
|
85
|
+
uri = endpoint.is_a?(URI::Generic) ? endpoint : URI(endpoint.to_s)
|
|
86
|
+
|
|
87
|
+
return endpoint.to_s unless uri.scheme && uri.host
|
|
88
|
+
|
|
89
|
+
"#{uri.scheme}://#{uri.host}:#{uri.port}"
|
|
90
|
+
rescue URI::InvalidURIError
|
|
91
|
+
endpoint.to_s
|
|
92
|
+
end
|
|
93
|
+
|
|
79
94
|
# @param response [Seahorse::Client::Http::Response:]
|
|
80
95
|
def server_time(response)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
nil
|
|
85
|
-
end
|
|
96
|
+
Time.parse(response.headers['date']).utc
|
|
97
|
+
rescue StandardError
|
|
98
|
+
nil
|
|
86
99
|
end
|
|
87
100
|
|
|
88
101
|
# Sets the clock correction for an endpoint
|
|
@@ -90,11 +103,10 @@ module Aws
|
|
|
90
103
|
# @param correction [Number]
|
|
91
104
|
def set_clock_correction(endpoint, correction)
|
|
92
105
|
@mutex.synchronize do
|
|
93
|
-
@endpoint_clock_corrections[endpoint
|
|
106
|
+
@endpoint_clock_corrections[normalized_endpoint(endpoint)] = correction
|
|
94
107
|
end
|
|
95
108
|
end
|
|
96
109
|
end
|
|
97
110
|
end
|
|
98
111
|
end
|
|
99
112
|
end
|
|
100
|
-
|
|
@@ -13,9 +13,6 @@ module Aws
|
|
|
13
13
|
option(:sigv4_region)
|
|
14
14
|
option(:unsigned_operations, default: [])
|
|
15
15
|
|
|
16
|
-
supported_auth_types = %w[sigv4 bearer sigv4-s3express sigv4a none]
|
|
17
|
-
SUPPORTED_AUTH_TYPES = supported_auth_types.freeze
|
|
18
|
-
|
|
19
16
|
def add_handlers(handlers, cfg)
|
|
20
17
|
operations = cfg.api.operation_names - cfg.unsigned_operations
|
|
21
18
|
handlers.add(Handler, step: :sign, operations: operations)
|
|
@@ -32,7 +29,7 @@ module Aws
|
|
|
32
29
|
}
|
|
33
30
|
SignatureV4.new(auth_scheme, config, sigv4_overrides)
|
|
34
31
|
when 'bearer'
|
|
35
|
-
Bearer.new
|
|
32
|
+
Bearer.new(config)
|
|
36
33
|
else
|
|
37
34
|
NullSigner.new
|
|
38
35
|
end
|
|
@@ -41,7 +38,6 @@ module Aws
|
|
|
41
38
|
class Handler < Seahorse::Client::Handler
|
|
42
39
|
def call(context)
|
|
43
40
|
# Skip signing if using sigv2 signing from s3_signer in S3
|
|
44
|
-
credentials = nil
|
|
45
41
|
unless v2_signing?(context.config)
|
|
46
42
|
signer = Sign.signer_for(
|
|
47
43
|
context[:auth_scheme],
|
|
@@ -49,18 +45,22 @@ module Aws
|
|
|
49
45
|
context[:sigv4_region],
|
|
50
46
|
context[:sigv4_credentials]
|
|
51
47
|
)
|
|
52
|
-
credentials = signer.credentials if signer.is_a?(SignatureV4)
|
|
53
48
|
signer.sign(context)
|
|
54
49
|
end
|
|
55
|
-
with_metrics(
|
|
50
|
+
with_metrics(signer) { @handler.call(context) }
|
|
56
51
|
end
|
|
57
52
|
|
|
58
53
|
private
|
|
59
54
|
|
|
60
|
-
def with_metrics(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
def with_metrics(signer, &block)
|
|
56
|
+
case signer
|
|
57
|
+
when SignatureV4
|
|
58
|
+
Aws::Plugins::UserAgent.metric(*signer.credentials.metrics, &block)
|
|
59
|
+
when Bearer
|
|
60
|
+
Aws::Plugins::UserAgent.metric(*signer.token_provider.metrics, &block)
|
|
61
|
+
else
|
|
62
|
+
block.call
|
|
63
|
+
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def v2_signing?(config)
|
|
@@ -72,21 +72,19 @@ module Aws
|
|
|
72
72
|
|
|
73
73
|
# @api private
|
|
74
74
|
class Bearer
|
|
75
|
-
def initialize
|
|
75
|
+
def initialize(config)
|
|
76
|
+
@token_provider = config.token_provider
|
|
76
77
|
end
|
|
77
78
|
|
|
79
|
+
attr_reader :token_provider
|
|
80
|
+
|
|
78
81
|
def sign(context)
|
|
79
82
|
if context.http_request.endpoint.scheme != 'https'
|
|
80
|
-
raise ArgumentError,
|
|
81
|
-
'Unable to use bearer authorization on non https endpoint.'
|
|
83
|
+
raise ArgumentError, 'Unable to use bearer authorization on non https endpoint.'
|
|
82
84
|
end
|
|
85
|
+
raise Errors::MissingBearerTokenError unless @token_provider && @token_provider.set?
|
|
83
86
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
raise Errors::MissingBearerTokenError unless token_provider&.set?
|
|
87
|
-
|
|
88
|
-
context.http_request.headers['Authorization'] =
|
|
89
|
-
"Bearer #{token_provider.token.token}"
|
|
87
|
+
context.http_request.headers['Authorization'] = "Bearer #{@token_provider.token.token}"
|
|
90
88
|
end
|
|
91
89
|
|
|
92
90
|
def presign_url(*args)
|
|
@@ -100,16 +98,11 @@ module Aws
|
|
|
100
98
|
|
|
101
99
|
# @api private
|
|
102
100
|
class SignatureV4
|
|
103
|
-
attr_reader :signer
|
|
104
|
-
|
|
105
101
|
def initialize(auth_scheme, config, sigv4_overrides = {})
|
|
106
102
|
scheme_name = auth_scheme['name']
|
|
107
|
-
|
|
108
103
|
unless %w[sigv4 sigv4a sigv4-s3express].include?(scheme_name)
|
|
109
|
-
raise ArgumentError,
|
|
110
|
-
"Expected sigv4, sigv4a, or sigv4-s3express auth scheme, got #{scheme_name}"
|
|
104
|
+
raise ArgumentError, "Expected sigv4, sigv4a, or sigv4-s3express auth scheme, got #{scheme_name}"
|
|
111
105
|
end
|
|
112
|
-
|
|
113
106
|
region = if scheme_name == 'sigv4a'
|
|
114
107
|
auth_scheme['signingRegionSet'].join(',')
|
|
115
108
|
else
|
|
@@ -121,8 +114,8 @@ module Aws
|
|
|
121
114
|
region: sigv4_overrides[:region] || config.sigv4_region || region,
|
|
122
115
|
credentials_provider: sigv4_overrides[:credentials] || config.credentials,
|
|
123
116
|
signing_algorithm: scheme_name.to_sym,
|
|
124
|
-
uri_escape_path:
|
|
125
|
-
normalize_path:
|
|
117
|
+
uri_escape_path: !auth_scheme['disableDoubleEncoding'],
|
|
118
|
+
normalize_path: !auth_scheme['disableNormalizePath'],
|
|
126
119
|
unsigned_headers: %w[content-length user-agent x-amzn-trace-id expect transfer-encoding connection]
|
|
127
120
|
)
|
|
128
121
|
rescue Aws::Sigv4::Errors::MissingCredentialsError
|
|
@@ -130,6 +123,8 @@ module Aws
|
|
|
130
123
|
end
|
|
131
124
|
end
|
|
132
125
|
|
|
126
|
+
attr_reader :signer
|
|
127
|
+
|
|
133
128
|
def sign(context)
|
|
134
129
|
req = context.http_request
|
|
135
130
|
|
|
@@ -29,6 +29,12 @@ requests are made, and retries are disabled.
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
option(:token_provider) do |config|
|
|
33
|
+
if config.stub_responses
|
|
34
|
+
StaticTokenProvider.new('stubbed-token')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
option(:stubs) { {} }
|
|
33
39
|
option(:stubs_mutex) { Mutex.new }
|
|
34
40
|
option(:api_requests) { [] }
|
|
@@ -54,7 +54,10 @@ module Aws
|
|
|
54
54
|
"CREDENTIALS_HTTP" : "z",
|
|
55
55
|
"CREDENTIALS_IMDS" : "0",
|
|
56
56
|
"SSO_LOGIN_DEVICE" : "1",
|
|
57
|
-
"SSO_LOGIN_AUTH" : "2"
|
|
57
|
+
"SSO_LOGIN_AUTH" : "2",
|
|
58
|
+
"BEARER_SERVICE_ENV_VARS": "3",
|
|
59
|
+
"CREDENTIALS_PROFILE_LOGIN": "AC",
|
|
60
|
+
"CREDENTIALS_LOGIN": "AD"
|
|
58
61
|
}
|
|
59
62
|
METRICS
|
|
60
63
|
|
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Aws
|
|
4
|
-
|
|
5
4
|
# Base class used credential classes that can be refreshed. This
|
|
6
5
|
# provides basic refresh logic in a thread-safe manner. Classes mixing in
|
|
7
|
-
# this module are expected to implement a
|
|
6
|
+
# this module are expected to implement a `#refresh` method that populates
|
|
8
7
|
# the following instance variables:
|
|
9
8
|
#
|
|
10
|
-
# * `@
|
|
11
|
-
# * `@
|
|
12
|
-
# * `@session_token`
|
|
13
|
-
# * `@expiration`
|
|
9
|
+
# * `@credentials` ({Credentials})
|
|
10
|
+
# * `@expiration` (Time)
|
|
14
11
|
#
|
|
15
|
-
# @api private
|
|
16
12
|
module RefreshingCredentials
|
|
17
|
-
|
|
18
13
|
SYNC_EXPIRATION_LENGTH = 300 # 5 minutes
|
|
19
14
|
ASYNC_EXPIRATION_LENGTH = 600 # 10 minutes
|
|
20
15
|
|
|
21
16
|
CLIENT_EXCLUDE_OPTIONS = Set.new([:before_refresh]).freeze
|
|
22
17
|
|
|
18
|
+
# @param [Hash] options
|
|
19
|
+
# @option options [Proc] :before_refresh A Proc called before credentials are refreshed.
|
|
20
|
+
# It accepts `self` as the only argument.
|
|
23
21
|
def initialize(options = {})
|
|
24
22
|
@mutex = Mutex.new
|
|
25
|
-
@before_refresh = options.delete(:before_refresh) if Hash
|
|
23
|
+
@before_refresh = options.delete(:before_refresh) if options.is_a?(Hash)
|
|
26
24
|
|
|
27
25
|
@before_refresh.call(self) if @before_refresh
|
|
28
26
|
refresh
|
|
@@ -59,7 +57,7 @@ module Aws
|
|
|
59
57
|
# Otherwise, if we're approaching expiration, use the existing credentials
|
|
60
58
|
# but attempt a refresh in the background.
|
|
61
59
|
def refresh_if_near_expiration!
|
|
62
|
-
#
|
|
60
|
+
# NOTE: This check is an optimization. Rather than acquire the mutex on every #refresh_if_near_expiration
|
|
63
61
|
# call, we check before doing so, and then we check within the mutex to avoid a race condition.
|
|
64
62
|
# See issue: https://github.com/aws/aws-sdk-ruby/issues/2641 for more info.
|
|
65
63
|
if near_expiration?(sync_expiration_length)
|
|
@@ -91,6 +89,5 @@ module Aws
|
|
|
91
89
|
true
|
|
92
90
|
end
|
|
93
91
|
end
|
|
94
|
-
|
|
95
92
|
end
|
|
96
93
|
end
|
|
@@ -171,6 +171,16 @@ module Aws
|
|
|
171
171
|
token
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
+
# Attempts to load from shared config or shared credentials file.
|
|
175
|
+
# Will always attempt first to load from the shared credentials
|
|
176
|
+
# file, if present.
|
|
177
|
+
def login_credentials_from_config(opts = {})
|
|
178
|
+
p = opts[:profile] || @profile_name
|
|
179
|
+
credentials = login_credentials_from_profile(@parsed_credentials, p, opts[:region])
|
|
180
|
+
credentials ||= login_credentials_from_profile(@parsed_config, p, opts[:region]) if @parsed_config
|
|
181
|
+
credentials
|
|
182
|
+
end
|
|
183
|
+
|
|
174
184
|
# Source a custom configured endpoint from the shared configuration file
|
|
175
185
|
#
|
|
176
186
|
# @param [Hash] opts
|
|
@@ -203,6 +213,7 @@ module Aws
|
|
|
203
213
|
config_reader(
|
|
204
214
|
:region,
|
|
205
215
|
:account_id_endpoint_mode,
|
|
216
|
+
:auth_scheme_preference,
|
|
206
217
|
:sigv4a_signing_region_set,
|
|
207
218
|
:ca_bundle,
|
|
208
219
|
:credential_process,
|
|
@@ -368,6 +379,15 @@ module Aws
|
|
|
368
379
|
)
|
|
369
380
|
when 'EcsContainer'
|
|
370
381
|
ECSCredentials.new
|
|
382
|
+
when 'Environment'
|
|
383
|
+
creds = Credentials.new(
|
|
384
|
+
ENV['AWS_ACCESS_KEY_ID'],
|
|
385
|
+
ENV['AWS_SECRET_ACCESS_KEY'],
|
|
386
|
+
ENV['AWS_SESSION_TOKEN'],
|
|
387
|
+
account_id: ENV['AWS_ACCOUNT_ID']
|
|
388
|
+
)
|
|
389
|
+
creds.metrics = ['CREDENTIALS_ENV_VARS']
|
|
390
|
+
creds
|
|
371
391
|
else
|
|
372
392
|
raise Errors::InvalidCredentialSourceError, "Unsupported credential_source: #{credential_source}"
|
|
373
393
|
end
|
|
@@ -459,6 +479,16 @@ module Aws
|
|
|
459
479
|
end
|
|
460
480
|
end
|
|
461
481
|
|
|
482
|
+
def login_credentials_from_profile(cfg, profile, region)
|
|
483
|
+
return unless @parsed_config && (prof_config = cfg[profile]) && prof_config['login_session']
|
|
484
|
+
|
|
485
|
+
cfg = { login_session: prof_config['login_session'] }
|
|
486
|
+
cfg[:region] = region if region
|
|
487
|
+
creds = LoginCredentials.new(cfg)
|
|
488
|
+
creds.metrics << 'CREDENTIALS_PROFILE_LOGIN'
|
|
489
|
+
creds
|
|
490
|
+
end
|
|
491
|
+
|
|
462
492
|
def credentials_from_profile(prof_config)
|
|
463
493
|
creds = Credentials.new(
|
|
464
494
|
prof_config['aws_access_key_id'],
|
|
@@ -7,7 +7,7 @@ module Aws
|
|
|
7
7
|
# {Aws::SSOTokenProvider} will be used to refresh the token if possible.
|
|
8
8
|
# This class does NOT implement the SSO login token flow - tokens
|
|
9
9
|
# must generated separately by running `aws login` from the
|
|
10
|
-
# AWS CLI with the correct profile. The
|
|
10
|
+
# AWS CLI with the correct profile. The {SSOCredentials} will
|
|
11
11
|
# auto-refresh the AWS credentials from SSO.
|
|
12
12
|
#
|
|
13
13
|
# # You must first run aws sso login --profile your-sso-profile
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Aws
|
|
4
4
|
class StaticTokenProvider
|
|
5
|
-
|
|
6
5
|
include TokenProvider
|
|
7
6
|
|
|
8
7
|
# @param [String] token
|
|
9
8
|
# @param [Time] expiration
|
|
10
|
-
def initialize(token, expiration=nil)
|
|
9
|
+
def initialize(token, expiration = nil)
|
|
11
10
|
@token = Token.new(token, expiration)
|
|
12
11
|
end
|
|
13
12
|
end
|
data/lib/aws-sdk-core/token.rb
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
module Aws
|
|
4
4
|
class Token
|
|
5
5
|
|
|
6
|
-
# @param [String] token
|
|
7
|
-
# @param [Time] expiration
|
|
8
|
-
def initialize(token, expiration=nil)
|
|
6
|
+
# @param [String, nil] token
|
|
7
|
+
# @param [Time, nil] expiration
|
|
8
|
+
def initialize(token, expiration = nil)
|
|
9
9
|
@token = token
|
|
10
10
|
@expiration = expiration
|
|
11
11
|
end
|
|
@@ -27,17 +27,13 @@ module Aws
|
|
|
27
27
|
|
|
28
28
|
def static_profile_sso_token(options)
|
|
29
29
|
if Aws.shared_config.config_enabled? && options[:config] && options[:config].profile
|
|
30
|
-
Aws.shared_config.sso_token_from_config(
|
|
31
|
-
profile: options[:config].profile
|
|
32
|
-
)
|
|
30
|
+
Aws.shared_config.sso_token_from_config(profile: options[:config].profile)
|
|
33
31
|
end
|
|
34
32
|
end
|
|
35
33
|
|
|
36
|
-
|
|
37
34
|
def sso_token(options)
|
|
38
|
-
profile_name = determine_profile_name(options)
|
|
39
35
|
if Aws.shared_config.config_enabled?
|
|
40
|
-
Aws.shared_config.sso_token_from_config(profile:
|
|
36
|
+
Aws.shared_config.sso_token_from_config(profile: determine_profile_name(options))
|
|
41
37
|
end
|
|
42
38
|
rescue Errors::NoSuchProfileError
|
|
43
39
|
nil
|
data/lib/aws-sdk-core.rb
CHANGED
|
@@ -25,6 +25,7 @@ module Aws
|
|
|
25
25
|
autoload :SharedCredentials, 'aws-sdk-core/shared_credentials'
|
|
26
26
|
autoload :ProcessCredentials, 'aws-sdk-core/process_credentials'
|
|
27
27
|
autoload :SSOCredentials, 'aws-sdk-core/sso_credentials'
|
|
28
|
+
autoload :LoginCredentials, 'aws-sdk-core/login_credentials'
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
# tokens and token providers
|
|
@@ -175,3 +176,6 @@ require_relative 'aws-sdk-sts'
|
|
|
175
176
|
# aws-sdk-sso is included to support Aws::SSOCredentials
|
|
176
177
|
require_relative 'aws-sdk-sso'
|
|
177
178
|
require_relative 'aws-sdk-ssooidc'
|
|
179
|
+
|
|
180
|
+
# aws-sdk-signin is included to support Aws::SignInCredentials
|
|
181
|
+
require_relative 'aws-sdk-signin'
|