aws-sdk-core 3.54.2 → 3.126.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1247 -0
- data/LICENSE.txt +202 -0
- data/VERSION +1 -1
- data/lib/aws-defaults/default_configuration.rb +153 -0
- data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
- data/lib/aws-defaults.rb +3 -0
- data/lib/aws-sdk-core/arn.rb +92 -0
- data/lib/aws-sdk-core/arn_parser.rb +40 -0
- data/lib/aws-sdk-core/assume_role_credentials.rb +2 -0
- data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +104 -0
- data/lib/aws-sdk-core/async_client_stubs.rb +4 -2
- data/lib/aws-sdk-core/binary/decode_handler.rb +2 -0
- data/lib/aws-sdk-core/binary/encode_handler.rb +2 -0
- data/lib/aws-sdk-core/binary/event_builder.rb +8 -6
- data/lib/aws-sdk-core/binary/event_parser.rb +5 -3
- data/lib/aws-sdk-core/binary/event_stream_decoder.rb +2 -0
- data/lib/aws-sdk-core/binary/event_stream_encoder.rb +2 -0
- data/lib/aws-sdk-core/binary.rb +2 -0
- data/lib/aws-sdk-core/client_side_monitoring/publisher.rb +11 -1
- data/lib/aws-sdk-core/client_side_monitoring/request_metrics.rb +2 -0
- data/lib/aws-sdk-core/client_stubs.rb +15 -12
- data/lib/aws-sdk-core/credential_provider.rb +1 -30
- data/lib/aws-sdk-core/credential_provider_chain.rb +102 -40
- data/lib/aws-sdk-core/credentials.rb +2 -0
- data/lib/aws-sdk-core/deprecations.rb +17 -11
- data/lib/aws-sdk-core/eager_loader.rb +2 -0
- data/lib/aws-sdk-core/ec2_metadata.rb +237 -0
- data/lib/aws-sdk-core/ecs_credentials.rb +5 -4
- data/lib/aws-sdk-core/endpoint_cache.rb +16 -11
- data/lib/aws-sdk-core/errors.rb +102 -15
- data/lib/aws-sdk-core/event_emitter.rb +2 -0
- data/lib/aws-sdk-core/ini_parser.rb +2 -0
- data/lib/aws-sdk-core/instance_profile_credentials.rb +153 -39
- data/lib/aws-sdk-core/json/builder.rb +2 -0
- data/lib/aws-sdk-core/json/error_handler.rb +2 -0
- data/lib/aws-sdk-core/json/handler.rb +2 -0
- data/lib/aws-sdk-core/json/json_engine.rb +12 -8
- data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
- data/lib/aws-sdk-core/json/parser.rb +10 -0
- data/lib/aws-sdk-core/json.rb +11 -28
- data/lib/aws-sdk-core/log/formatter.rb +16 -4
- data/lib/aws-sdk-core/log/handler.rb +2 -0
- data/lib/aws-sdk-core/log/param_filter.rb +38 -13
- data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
- data/lib/aws-sdk-core/pageable_response.rb +48 -24
- data/lib/aws-sdk-core/pager.rb +5 -0
- data/lib/aws-sdk-core/param_converter.rb +2 -0
- data/lib/aws-sdk-core/param_validator.rb +55 -7
- data/lib/aws-sdk-core/plugins/api_key.rb +5 -1
- data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +2 -0
- data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +2 -0
- data/lib/aws-sdk-core/plugins/apig_user_agent.rb +2 -0
- data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +28 -1
- data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
- data/lib/aws-sdk-core/plugins/credentials_configuration.rb +26 -7
- data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
- data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +12 -4
- data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
- data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +2 -0
- data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
- data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
- data/lib/aws-sdk-core/plugins/http_checksum.rb +57 -0
- data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
- data/lib/aws-sdk-core/plugins/invocation_id.rb +2 -0
- data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +2 -0
- data/lib/aws-sdk-core/plugins/logging.rb +2 -0
- data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
- data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
- data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
- data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
- data/lib/aws-sdk-core/plugins/recursion_detection.rb +27 -0
- data/lib/aws-sdk-core/plugins/regional_endpoint.rb +74 -16
- data/lib/aws-sdk-core/plugins/response_paging.rb +2 -0
- data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +139 -0
- data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +100 -0
- data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +146 -0
- data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +59 -0
- data/lib/aws-sdk-core/plugins/retry_errors.rb +295 -108
- data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -0
- data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -25
- data/lib/aws-sdk-core/plugins/stub_responses.rb +5 -0
- data/lib/aws-sdk-core/plugins/transfer_encoding.rb +4 -4
- data/lib/aws-sdk-core/plugins/user_agent.rb +6 -8
- data/lib/aws-sdk-core/process_credentials.rb +8 -7
- data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
- data/lib/aws-sdk-core/query/handler.rb +2 -0
- data/lib/aws-sdk-core/query/param.rb +2 -0
- data/lib/aws-sdk-core/query/param_builder.rb +2 -0
- data/lib/aws-sdk-core/query/param_list.rb +2 -0
- data/lib/aws-sdk-core/query.rb +2 -0
- data/lib/aws-sdk-core/refreshing_credentials.rb +2 -0
- data/lib/aws-sdk-core/resources/collection.rb +2 -0
- data/lib/aws-sdk-core/rest/handler.rb +2 -0
- data/lib/aws-sdk-core/rest/request/body.rb +21 -1
- data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
- data/lib/aws-sdk-core/rest/request/endpoint.rb +10 -3
- data/lib/aws-sdk-core/rest/request/headers.rb +20 -6
- data/lib/aws-sdk-core/rest/request/querystring_builder.rb +4 -2
- data/lib/aws-sdk-core/rest/response/body.rb +2 -0
- data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
- data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
- data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
- data/lib/aws-sdk-core/rest.rb +2 -0
- data/lib/aws-sdk-core/shared_config.rb +153 -122
- data/lib/aws-sdk-core/shared_credentials.rb +9 -1
- data/lib/aws-sdk-core/sso_credentials.rb +131 -0
- data/lib/aws-sdk-core/structure.rb +13 -2
- data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
- data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
- data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
- data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
- data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
- data/lib/aws-sdk-core/stubbing/protocols/query.rb +4 -2
- data/lib/aws-sdk-core/stubbing/protocols/rest.rb +33 -7
- data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
- data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
- data/lib/aws-sdk-core/stubbing/stub_data.rb +2 -0
- data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
- data/lib/aws-sdk-core/type_builder.rb +2 -0
- data/lib/aws-sdk-core/util.rb +6 -0
- data/lib/aws-sdk-core/waiters/errors.rb +2 -0
- data/lib/aws-sdk-core/waiters/poller.rb +2 -0
- data/lib/aws-sdk-core/waiters/waiter.rb +2 -0
- data/lib/aws-sdk-core/waiters.rb +2 -0
- data/lib/aws-sdk-core/xml/builder.rb +5 -3
- data/lib/aws-sdk-core/xml/default_list.rb +2 -0
- data/lib/aws-sdk-core/xml/default_map.rb +2 -0
- data/lib/aws-sdk-core/xml/doc_builder.rb +15 -4
- data/lib/aws-sdk-core/xml/error_handler.rb +3 -1
- data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
- data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +4 -1
- data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
- data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
- data/lib/aws-sdk-core/xml/parser.rb +7 -0
- data/lib/aws-sdk-core/xml.rb +2 -0
- data/lib/aws-sdk-core.rb +22 -4
- data/lib/aws-sdk-sso/client.rb +568 -0
- data/lib/aws-sdk-sso/client_api.rb +190 -0
- data/lib/aws-sdk-sso/customizations.rb +1 -0
- data/lib/aws-sdk-sso/errors.rb +102 -0
- data/lib/aws-sdk-sso/resource.rb +26 -0
- data/lib/aws-sdk-sso/types.rb +352 -0
- data/lib/aws-sdk-sso.rb +55 -0
- data/lib/aws-sdk-sts/client.rb +970 -414
- data/lib/aws-sdk-sts/client_api.rb +41 -1
- data/lib/aws-sdk-sts/customizations.rb +4 -0
- data/lib/aws-sdk-sts/errors.rb +33 -9
- data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +38 -0
- data/lib/aws-sdk-sts/presigner.rb +75 -0
- data/lib/aws-sdk-sts/resource.rb +4 -1
- data/lib/aws-sdk-sts/types.rb +632 -236
- data/lib/aws-sdk-sts.rb +16 -6
- data/lib/seahorse/client/async_base.rb +2 -0
- data/lib/seahorse/client/async_response.rb +2 -0
- data/lib/seahorse/client/base.rb +6 -1
- data/lib/seahorse/client/block_io.rb +6 -2
- data/lib/seahorse/client/configuration.rb +6 -0
- data/lib/seahorse/client/events.rb +2 -0
- data/lib/seahorse/client/h2/connection.rb +31 -25
- data/lib/seahorse/client/h2/handler.rb +6 -5
- data/lib/seahorse/client/handler.rb +2 -0
- data/lib/seahorse/client/handler_builder.rb +2 -0
- data/lib/seahorse/client/handler_list.rb +2 -0
- data/lib/seahorse/client/handler_list_entry.rb +6 -4
- data/lib/seahorse/client/http/async_response.rb +2 -0
- data/lib/seahorse/client/http/headers.rb +2 -0
- data/lib/seahorse/client/http/request.rb +5 -3
- data/lib/seahorse/client/http/response.rb +5 -3
- data/lib/seahorse/client/logging/formatter.rb +6 -2
- data/lib/seahorse/client/logging/handler.rb +2 -0
- data/lib/seahorse/client/managed_file.rb +2 -0
- data/lib/seahorse/client/net_http/connection_pool.rb +30 -23
- data/lib/seahorse/client/net_http/handler.rb +24 -7
- data/lib/seahorse/client/net_http/patches.rb +15 -84
- data/lib/seahorse/client/networking_error.rb +2 -0
- data/lib/seahorse/client/plugin.rb +9 -6
- data/lib/seahorse/client/plugin_list.rb +2 -0
- data/lib/seahorse/client/plugins/content_length.rb +13 -7
- data/lib/seahorse/client/plugins/endpoint.rb +4 -2
- data/lib/seahorse/client/plugins/h2.rb +6 -1
- data/lib/seahorse/client/plugins/logging.rb +2 -0
- data/lib/seahorse/client/plugins/net_http.rb +39 -3
- data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
- data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
- data/lib/seahorse/client/plugins/request_callback.rb +110 -0
- data/lib/seahorse/client/plugins/response_target.rb +23 -14
- data/lib/seahorse/client/request.rb +2 -0
- data/lib/seahorse/client/request_context.rb +2 -0
- data/lib/seahorse/client/response.rb +5 -5
- data/lib/seahorse/model/api.rb +6 -0
- data/lib/seahorse/model/authorizer.rb +2 -0
- data/lib/seahorse/model/operation.rb +5 -0
- data/lib/seahorse/model/shapes.rb +27 -0
- data/lib/seahorse/util.rb +8 -1
- data/lib/seahorse/version.rb +2 -0
- data/lib/seahorse.rb +3 -0
- metadata +43 -11
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Aws
|
3
4
|
# @api private
|
4
5
|
class SharedConfig
|
6
|
+
SSO_PROFILE_KEYS = %w[sso_start_url sso_region sso_account_id sso_role_name].freeze
|
5
7
|
|
6
8
|
# @return [String]
|
7
9
|
attr_reader :credentials_path
|
@@ -48,7 +50,7 @@ module Aws
|
|
48
50
|
@profile_name = determine_profile(options)
|
49
51
|
@config_enabled = options[:config_enabled]
|
50
52
|
@credentials_path = options[:credentials_path] ||
|
51
|
-
|
53
|
+
determine_credentials_path
|
52
54
|
@parsed_credentials = {}
|
53
55
|
load_credentials_file if loadable?(@credentials_path)
|
54
56
|
if @config_enabled
|
@@ -67,7 +69,7 @@ module Aws
|
|
67
69
|
@config_enabled = options[:config_enabled] ? true : false
|
68
70
|
@profile_name = determine_profile(options)
|
69
71
|
@credentials_path = options[:credentials_path] ||
|
70
|
-
|
72
|
+
determine_credentials_path
|
71
73
|
load_credentials_file if loadable?(@credentials_path)
|
72
74
|
if @config_enabled
|
73
75
|
@config_path = options[:config_path] || determine_config_path
|
@@ -99,12 +101,10 @@ module Aws
|
|
99
101
|
def credentials(opts = {})
|
100
102
|
p = opts[:profile] || @profile_name
|
101
103
|
validate_profile_exists(p) if credentials_present?
|
102
|
-
if credentials = credentials_from_shared(p, opts)
|
104
|
+
if (credentials = credentials_from_shared(p, opts))
|
103
105
|
credentials
|
104
|
-
elsif credentials = credentials_from_config(p, opts)
|
106
|
+
elsif (credentials = credentials_from_config(p, opts))
|
105
107
|
credentials
|
106
|
-
else
|
107
|
-
nil
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -121,79 +121,80 @@ module Aws
|
|
121
121
|
credentials
|
122
122
|
end
|
123
123
|
|
124
|
-
def
|
124
|
+
def assume_role_web_identity_credentials_from_config(opts = {})
|
125
125
|
p = opts[:profile] || @profile_name
|
126
|
-
if @config_enabled
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
126
|
+
if @config_enabled && @parsed_config
|
127
|
+
entry = @parsed_config.fetch(p, {})
|
128
|
+
if entry['web_identity_token_file'] && entry['role_arn']
|
129
|
+
cfg = {
|
130
|
+
role_arn: entry['role_arn'],
|
131
|
+
web_identity_token_file: entry['web_identity_token_file'],
|
132
|
+
role_session_name: entry['role_session_name']
|
133
|
+
}
|
134
|
+
cfg[:region] = opts[:region] if opts[:region]
|
135
|
+
AssumeRoleWebIdentityCredentials.new(cfg)
|
132
136
|
end
|
133
|
-
region
|
134
|
-
else
|
135
|
-
nil
|
136
137
|
end
|
137
138
|
end
|
138
139
|
|
139
|
-
|
140
|
+
# Attempts to load from shared config or shared credentials file.
|
141
|
+
# Will always attempt first to load from the shared credentials
|
142
|
+
# file, if present.
|
143
|
+
def sso_credentials_from_config(opts = {})
|
140
144
|
p = opts[:profile] || @profile_name
|
141
|
-
|
142
|
-
|
145
|
+
credentials = sso_credentials_from_profile(@parsed_credentials, p)
|
146
|
+
if @parsed_config
|
147
|
+
credentials ||= sso_credentials_from_profile(@parsed_config, p)
|
143
148
|
end
|
149
|
+
credentials
|
144
150
|
end
|
145
151
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
p = opts[:profile] || @profile_name
|
153
|
-
if @config_enabled
|
154
|
-
if @parsed_credentials
|
155
|
-
value = @parsed_credentials.fetch(p, {})["csm_enabled"]
|
156
|
-
end
|
157
|
-
if @parsed_config
|
158
|
-
value ||= @parsed_config.fetch(p, {})["csm_enabled"]
|
159
|
-
end
|
160
|
-
value
|
161
|
-
else
|
162
|
-
nil
|
152
|
+
# Add an accessor method (similar to attr_reader) to return a configuration value
|
153
|
+
# Uses the get_config_value below to control where
|
154
|
+
# values are loaded from
|
155
|
+
def self.config_reader(*attrs)
|
156
|
+
attrs.each do |attr|
|
157
|
+
define_method(attr) { |opts = {}| get_config_value(attr.to_s, opts) }
|
163
158
|
end
|
164
159
|
end
|
165
160
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
161
|
+
config_reader(
|
162
|
+
:region,
|
163
|
+
:ca_bundle,
|
164
|
+
:credential_process,
|
165
|
+
:endpoint_discovery_enabled,
|
166
|
+
:use_dualstack_endpoint,
|
167
|
+
:use_fips_endpoint,
|
168
|
+
:ec2_metadata_service_endpoint,
|
169
|
+
:ec2_metadata_service_endpoint_mode,
|
170
|
+
:max_attempts,
|
171
|
+
:retry_mode,
|
172
|
+
:adaptive_retry_wait_to_fill,
|
173
|
+
:correct_clock_skew,
|
174
|
+
:csm_client_id,
|
175
|
+
:csm_enabled,
|
176
|
+
:csm_host,
|
177
|
+
:csm_port,
|
178
|
+
:sts_regional_endpoints,
|
179
|
+
:s3_use_arn_region,
|
180
|
+
:s3_us_east_1_regional_endpoint,
|
181
|
+
:s3_disable_multiregion_access_points,
|
182
|
+
:defaults_mode
|
183
|
+
)
|
184
|
+
|
185
|
+
private
|
180
186
|
|
181
|
-
|
187
|
+
# Get a config value from from shared credential/config files.
|
188
|
+
# Only loads a value when config_enabled is true
|
189
|
+
# Return a value from credentials preferentially over config
|
190
|
+
def get_config_value(key, opts)
|
182
191
|
p = opts[:profile] || @profile_name
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
if @parsed_config
|
188
|
-
value ||= @parsed_config.fetch(p, {})["csm_port"]
|
189
|
-
end
|
190
|
-
value
|
191
|
-
else
|
192
|
-
nil
|
193
|
-
end
|
192
|
+
|
193
|
+
value = @parsed_credentials.fetch(p, {})[key] if @parsed_credentials
|
194
|
+
value ||= @parsed_config.fetch(p, {})[key] if @config_enabled && @parsed_config
|
195
|
+
value
|
194
196
|
end
|
195
197
|
|
196
|
-
private
|
197
198
|
def credentials_present?
|
198
199
|
(@parsed_credentials && !@parsed_credentials.empty?) ||
|
199
200
|
(@parsed_config && !@parsed_config.empty?)
|
@@ -201,30 +202,31 @@ module Aws
|
|
201
202
|
|
202
203
|
def assume_role_from_profile(cfg, profile, opts, chain_config)
|
203
204
|
if cfg && prof_cfg = cfg[profile]
|
204
|
-
opts[:source_profile] ||= prof_cfg[
|
205
|
+
opts[:source_profile] ||= prof_cfg['source_profile']
|
205
206
|
credential_source = opts.delete(:credential_source)
|
206
|
-
credential_source ||= prof_cfg[
|
207
|
+
credential_source ||= prof_cfg['credential_source']
|
207
208
|
if opts[:source_profile] && credential_source
|
208
|
-
raise Errors::CredentialSourceConflictError
|
209
|
+
raise Errors::CredentialSourceConflictError,
|
209
210
|
"Profile #{profile} has a source_profile, and "\
|
210
|
-
|
211
|
-
|
212
|
-
)
|
211
|
+
'a credential_source. For assume role credentials, must '\
|
212
|
+
'provide only source_profile or credential_source, not both.'
|
213
213
|
elsif opts[:source_profile]
|
214
|
-
opts[:
|
214
|
+
opts[:visited_profiles] ||= Set.new
|
215
|
+
opts[:credentials] = resolve_source_profile(opts[:source_profile], opts)
|
215
216
|
if opts[:credentials]
|
216
|
-
opts[:role_session_name] ||= prof_cfg[
|
217
|
-
opts[:role_session_name] ||=
|
218
|
-
opts[:role_arn] ||= prof_cfg[
|
219
|
-
opts[:
|
220
|
-
opts[:
|
217
|
+
opts[:role_session_name] ||= prof_cfg['role_session_name']
|
218
|
+
opts[:role_session_name] ||= 'default_session'
|
219
|
+
opts[:role_arn] ||= prof_cfg['role_arn']
|
220
|
+
opts[:duration_seconds] ||= prof_cfg['duration_seconds']
|
221
|
+
opts[:external_id] ||= prof_cfg['external_id']
|
222
|
+
opts[:serial_number] ||= prof_cfg['mfa_serial']
|
221
223
|
opts[:profile] = opts.delete(:source_profile)
|
224
|
+
opts.delete(:visited_profiles)
|
222
225
|
AssumeRoleCredentials.new(opts)
|
223
226
|
else
|
224
|
-
raise Errors::NoSourceProfileError
|
227
|
+
raise Errors::NoSourceProfileError,
|
225
228
|
"Profile #{profile} has a role_arn, and source_profile, but the"\
|
226
|
-
|
227
|
-
)
|
229
|
+
' source_profile does not have credentials.'
|
228
230
|
end
|
229
231
|
elsif credential_source
|
230
232
|
opts[:credentials] = credentials_from_source(
|
@@ -232,61 +234,99 @@ module Aws
|
|
232
234
|
chain_config
|
233
235
|
)
|
234
236
|
if opts[:credentials]
|
235
|
-
opts[:role_session_name] ||= prof_cfg[
|
236
|
-
opts[:role_session_name] ||=
|
237
|
-
opts[:role_arn] ||= prof_cfg[
|
238
|
-
opts[:
|
239
|
-
opts[:
|
237
|
+
opts[:role_session_name] ||= prof_cfg['role_session_name']
|
238
|
+
opts[:role_session_name] ||= 'default_session'
|
239
|
+
opts[:role_arn] ||= prof_cfg['role_arn']
|
240
|
+
opts[:duration_seconds] ||= prof_cfg['duration_seconds']
|
241
|
+
opts[:external_id] ||= prof_cfg['external_id']
|
242
|
+
opts[:serial_number] ||= prof_cfg['mfa_serial']
|
240
243
|
opts.delete(:source_profile) # Cleanup
|
241
244
|
AssumeRoleCredentials.new(opts)
|
242
245
|
else
|
243
|
-
raise Errors::NoSourceCredentials
|
246
|
+
raise Errors::NoSourceCredentials,
|
244
247
|
"Profile #{profile} could not get source credentials from"\
|
245
|
-
|
246
|
-
)
|
248
|
+
" provider #{credential_source}"
|
247
249
|
end
|
248
|
-
elsif prof_cfg[
|
249
|
-
raise Errors::NoSourceProfileError.
|
250
|
-
"Profile #{profile} has a role_arn, but no source_profile."
|
251
|
-
)
|
252
|
-
else
|
253
|
-
nil
|
250
|
+
elsif prof_cfg['role_arn']
|
251
|
+
raise Errors::NoSourceProfileError, "Profile #{profile} has a role_arn, but no source_profile."
|
254
252
|
end
|
255
|
-
|
256
|
-
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def resolve_source_profile(profile, opts = {})
|
257
|
+
if opts[:visited_profiles] && opts[:visited_profiles].include?(profile)
|
258
|
+
raise Errors::SourceProfileCircularReferenceError
|
259
|
+
end
|
260
|
+
opts[:visited_profiles].add(profile) if opts[:visited_profiles]
|
261
|
+
|
262
|
+
profile_config = @parsed_credentials[profile]
|
263
|
+
if @config_enabled
|
264
|
+
profile_config ||= @parsed_config[profile]
|
265
|
+
end
|
266
|
+
|
267
|
+
if (creds = credentials(profile: profile))
|
268
|
+
creds # static credentials
|
269
|
+
elsif profile_config && profile_config['source_profile']
|
270
|
+
opts.delete(:source_profile)
|
271
|
+
assume_role_credentials_from_config(opts.merge(profile: profile))
|
272
|
+
elsif (provider = assume_role_web_identity_credentials_from_config(opts.merge(profile: profile)))
|
273
|
+
provider.credentials if provider.credentials.set?
|
274
|
+
elsif (provider = assume_role_process_credentials_from_config(profile))
|
275
|
+
provider.credentials if provider.credentials.set?
|
276
|
+
elsif (provider = sso_credentials_from_config(profile: profile))
|
277
|
+
provider.credentials if provider.credentials.set?
|
257
278
|
end
|
258
279
|
end
|
259
280
|
|
260
281
|
def credentials_from_source(credential_source, config)
|
261
282
|
case credential_source
|
262
|
-
when
|
283
|
+
when 'Ec2InstanceMetadata'
|
263
284
|
InstanceProfileCredentials.new(
|
264
285
|
retries: config ? config.instance_profile_credentials_retries : 0,
|
265
286
|
http_open_timeout: config ? config.instance_profile_credentials_timeout : 1,
|
266
287
|
http_read_timeout: config ? config.instance_profile_credentials_timeout : 1
|
267
288
|
)
|
268
|
-
when
|
289
|
+
when 'EcsContainer'
|
269
290
|
ECSCredentials.new
|
270
291
|
else
|
271
|
-
raise Errors::InvalidCredentialSourceError
|
272
|
-
|
273
|
-
|
292
|
+
raise Errors::InvalidCredentialSourceError, "Unsupported credential_source: #{credential_source}"
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def assume_role_process_credentials_from_config(profile)
|
297
|
+
validate_profile_exists(profile)
|
298
|
+
credential_process = @parsed_credentials.fetch(profile, {})['credential_process']
|
299
|
+
if @parsed_config
|
300
|
+
credential_process ||= @parsed_config.fetch(profile, {})['credential_process']
|
274
301
|
end
|
302
|
+
ProcessCredentials.new(credential_process) if credential_process
|
275
303
|
end
|
276
304
|
|
277
|
-
def credentials_from_shared(profile,
|
305
|
+
def credentials_from_shared(profile, _opts)
|
278
306
|
if @parsed_credentials && prof_config = @parsed_credentials[profile]
|
279
307
|
credentials_from_profile(prof_config)
|
280
|
-
else
|
281
|
-
nil
|
282
308
|
end
|
283
309
|
end
|
284
310
|
|
285
|
-
def credentials_from_config(profile,
|
311
|
+
def credentials_from_config(profile, _opts)
|
286
312
|
if @parsed_config && prof_config = @parsed_config[profile]
|
287
313
|
credentials_from_profile(prof_config)
|
288
|
-
|
289
|
-
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
# If any of the sso_ profile values are present, attempt to construct
|
318
|
+
# SSOCredentials
|
319
|
+
def sso_credentials_from_profile(cfg, profile)
|
320
|
+
if @parsed_config &&
|
321
|
+
(prof_config = cfg[profile]) &&
|
322
|
+
!(prof_config.keys & SSO_PROFILE_KEYS).empty?
|
323
|
+
|
324
|
+
SSOCredentials.new(
|
325
|
+
sso_start_url: prof_config['sso_start_url'],
|
326
|
+
sso_region: prof_config['sso_region'],
|
327
|
+
sso_account_id: prof_config['sso_account_id'],
|
328
|
+
sso_role_name: prof_config['sso_role_name']
|
329
|
+
)
|
290
330
|
end
|
291
331
|
end
|
292
332
|
|
@@ -296,15 +336,7 @@ module Aws
|
|
296
336
|
prof_config['aws_secret_access_key'],
|
297
337
|
prof_config['aws_session_token']
|
298
338
|
)
|
299
|
-
if
|
300
|
-
creds
|
301
|
-
else
|
302
|
-
nil
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
def credentials_complete(creds)
|
307
|
-
creds.set?
|
339
|
+
creds if creds.set?
|
308
340
|
end
|
309
341
|
|
310
342
|
def load_credentials_file
|
@@ -334,19 +366,18 @@ module Aws
|
|
334
366
|
|
335
367
|
def validate_profile_exists(profile)
|
336
368
|
unless (@parsed_credentials && @parsed_credentials[profile]) ||
|
337
|
-
|
338
|
-
msg = "Profile `#{profile}' not found in #{@credentials_path}"
|
339
|
-
|
340
|
-
raise Errors::NoSuchProfileError
|
369
|
+
(@parsed_config && @parsed_config[profile])
|
370
|
+
msg = "Profile `#{profile}' not found in #{@credentials_path}"\
|
371
|
+
"#{" or #{@config_path}" if @config_path}"
|
372
|
+
raise Errors::NoSuchProfileError, msg
|
341
373
|
end
|
342
374
|
end
|
343
375
|
|
344
376
|
def determine_profile(options)
|
345
377
|
ret = options[:profile_name]
|
346
|
-
ret ||= ENV[
|
347
|
-
ret ||=
|
378
|
+
ret ||= ENV['AWS_PROFILE']
|
379
|
+
ret ||= 'default'
|
348
380
|
ret
|
349
381
|
end
|
350
|
-
|
351
382
|
end
|
352
383
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'ini_parser'
|
2
4
|
|
3
5
|
module Aws
|
@@ -12,11 +14,17 @@ module Aws
|
|
12
14
|
'aws_session_token' => 'session_token',
|
13
15
|
}
|
14
16
|
|
15
|
-
# Constructs a new SharedCredentials object. This will load
|
17
|
+
# Constructs a new SharedCredentials object. This will load static
|
18
|
+
# (access_key_id, secret_access_key and session_token) AWS access
|
16
19
|
# credentials from an ini file, which supports profiles. The default
|
17
20
|
# profile name is 'default'. You can specify the profile name with the
|
18
21
|
# `ENV['AWS_PROFILE']` or with the `:profile_name` option.
|
19
22
|
#
|
23
|
+
# To use credentials from the default credential resolution chain
|
24
|
+
# create a client without the credential option specified.
|
25
|
+
# You may access the resolved credentials through
|
26
|
+
# `client.config.credentials`.
|
27
|
+
#
|
20
28
|
# @option [String] :path Path to the shared file. Defaults
|
21
29
|
# to "#{Dir.home}/.aws/credentials".
|
22
30
|
#
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
# An auto-refreshing credential provider that works by assuming a
|
5
|
+
# role via {Aws::SSO::Client#get_role_credentials} using a cached access
|
6
|
+
# token. This class does NOT implement the SSO login token flow - tokens
|
7
|
+
# must generated and refreshed separately by running `aws login` from the
|
8
|
+
# AWS CLI with the correct profile.
|
9
|
+
#
|
10
|
+
# For more background on AWS SSO see the official
|
11
|
+
# {https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html what is SSO Userguide}
|
12
|
+
#
|
13
|
+
# ## Refreshing Credentials from SSO
|
14
|
+
#
|
15
|
+
# The `SSOCredentials` will auto-refresh the AWS credentials from SSO. In
|
16
|
+
# addition to AWS credentials expiring after a given amount of time, the
|
17
|
+
# access token generated and cached from `aws login` will also expire.
|
18
|
+
# Once this token expires, it will not be usable to refresh AWS credentials,
|
19
|
+
# and another token will be needed. The SDK does not manage refreshing of
|
20
|
+
# the token value, but this can be done by running `aws login` with the
|
21
|
+
# correct profile.
|
22
|
+
#
|
23
|
+
#
|
24
|
+
# # You must first run aws sso login --profile your-sso-profile
|
25
|
+
# sso_credentials = Aws::SSOCredentials.new(
|
26
|
+
# sso_account_id: '123456789',
|
27
|
+
# sso_role_name: "role_name",
|
28
|
+
# sso_region: "us-east-1",
|
29
|
+
# sso_start_url: 'https://your-start-url.awsapps.com/start'
|
30
|
+
# )
|
31
|
+
#
|
32
|
+
# ec2 = Aws::EC2::Client.new(credentials: sso_credentials)
|
33
|
+
#
|
34
|
+
# If you omit `:client` option, a new {SSO::Client} object will be
|
35
|
+
# constructed.
|
36
|
+
class SSOCredentials
|
37
|
+
|
38
|
+
include CredentialProvider
|
39
|
+
include RefreshingCredentials
|
40
|
+
|
41
|
+
# @api private
|
42
|
+
SSO_REQUIRED_OPTS = [:sso_account_id, :sso_region, :sso_role_name, :sso_start_url].freeze
|
43
|
+
|
44
|
+
# @api private
|
45
|
+
SSO_LOGIN_GUIDANCE = 'The SSO session associated with this profile has '\
|
46
|
+
'expired or is otherwise invalid. To refresh this SSO session run '\
|
47
|
+
'aws sso login with the corresponding profile.'.freeze
|
48
|
+
|
49
|
+
# @option options [required, String] :sso_account_id The AWS account ID
|
50
|
+
# that temporary AWS credentials will be resolved for
|
51
|
+
#
|
52
|
+
# @option options [required, String] :sso_region The AWS region where the
|
53
|
+
# SSO directory for the given sso_start_url is hosted.
|
54
|
+
#
|
55
|
+
# @option options [required, String] :sso_role_name The corresponding
|
56
|
+
# IAM role in the AWS account that temporary AWS credentials
|
57
|
+
# will be resolved for.
|
58
|
+
#
|
59
|
+
# @option options [required, String] :sso_start_url The start URL is
|
60
|
+
# provided by the SSO service via the console and is the URL used to
|
61
|
+
# login to the SSO directory. This is also sometimes referred to as
|
62
|
+
# the "User Portal URL"
|
63
|
+
#
|
64
|
+
# @option options [SSO::Client] :client Optional `SSO::Client`. If not
|
65
|
+
# provided, a client will be constructed.
|
66
|
+
def initialize(options = {})
|
67
|
+
|
68
|
+
missing_keys = SSO_REQUIRED_OPTS.select { |k| options[k].nil? }
|
69
|
+
unless missing_keys.empty?
|
70
|
+
raise ArgumentError, "Missing required keys: #{missing_keys}"
|
71
|
+
end
|
72
|
+
|
73
|
+
@sso_start_url = options.delete(:sso_start_url)
|
74
|
+
@sso_region = options.delete(:sso_region)
|
75
|
+
@sso_role_name = options.delete(:sso_role_name)
|
76
|
+
@sso_account_id = options.delete(:sso_account_id)
|
77
|
+
|
78
|
+
# validate we can read the token file
|
79
|
+
read_cached_token
|
80
|
+
|
81
|
+
options[:region] = @sso_region
|
82
|
+
options[:credentials] = nil
|
83
|
+
@client = options[:client] || Aws::SSO::Client.new(options)
|
84
|
+
super
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [SSO::Client]
|
88
|
+
attr_reader :client
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def read_cached_token
|
93
|
+
cached_token = Json.load(File.read(sso_cache_file))
|
94
|
+
# validation
|
95
|
+
unless cached_token['accessToken'] && cached_token['expiresAt']
|
96
|
+
raise ArgumentError, 'Missing required field(s)'
|
97
|
+
end
|
98
|
+
expires_at = DateTime.parse(cached_token['expiresAt'])
|
99
|
+
if expires_at < DateTime.now
|
100
|
+
raise ArgumentError, 'Cached SSO Token is expired.'
|
101
|
+
end
|
102
|
+
cached_token
|
103
|
+
rescue Errno::ENOENT, Aws::Json::ParseError, ArgumentError
|
104
|
+
raise Errors::InvalidSSOCredentials, SSO_LOGIN_GUIDANCE
|
105
|
+
end
|
106
|
+
|
107
|
+
def refresh
|
108
|
+
cached_token = read_cached_token
|
109
|
+
c = @client.get_role_credentials(
|
110
|
+
account_id: @sso_account_id,
|
111
|
+
role_name: @sso_role_name,
|
112
|
+
access_token: cached_token['accessToken']
|
113
|
+
).role_credentials
|
114
|
+
|
115
|
+
@credentials = Credentials.new(
|
116
|
+
c.access_key_id,
|
117
|
+
c.secret_access_key,
|
118
|
+
c.session_token
|
119
|
+
)
|
120
|
+
@expiration = c.expiration
|
121
|
+
end
|
122
|
+
|
123
|
+
def sso_cache_file
|
124
|
+
start_url_sha1 = OpenSSL::Digest::SHA1.hexdigest(@sso_start_url.encode('utf-8'))
|
125
|
+
File.join(Dir.home, '.aws', 'sso', 'cache', "#{start_url_sha1}.json")
|
126
|
+
rescue ArgumentError
|
127
|
+
# Dir.home raises ArgumentError when ENV['home'] is not set
|
128
|
+
raise ArgumentError, "Unable to load sso_cache_file: ENV['HOME'] is not set."
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
# @api private
|
3
5
|
module Structure
|
@@ -46,7 +48,7 @@ module Aws
|
|
46
48
|
|
47
49
|
# Wraps the default #to_s logic with filtering of sensitive parameters.
|
48
50
|
def to_s(obj = self)
|
49
|
-
Aws::Log::ParamFilter.new.filter(obj).to_s
|
51
|
+
Aws::Log::ParamFilter.new.filter(obj, obj.class).to_s
|
50
52
|
end
|
51
53
|
|
52
54
|
class << self
|
@@ -68,11 +70,20 @@ module Aws
|
|
68
70
|
end
|
69
71
|
|
70
72
|
end
|
73
|
+
|
74
|
+
module Union
|
75
|
+
def member
|
76
|
+
self.members.select { |k| self[k] != nil }.first
|
77
|
+
end
|
78
|
+
|
79
|
+
def value
|
80
|
+
self[member] if member
|
81
|
+
end
|
82
|
+
end
|
71
83
|
end
|
72
84
|
|
73
85
|
# @api private
|
74
86
|
class EmptyStructure < Struct.new('AwsEmptyStructure')
|
75
87
|
include(Aws::Structure)
|
76
88
|
end
|
77
|
-
|
78
89
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
module Stubbing
|
3
5
|
module Protocols
|
@@ -27,7 +29,7 @@ module Aws
|
|
27
29
|
private
|
28
30
|
|
29
31
|
def content_type(api)
|
30
|
-
"application/x-amz-json-#{api.metadata['
|
32
|
+
"application/x-amz-json-#{api.metadata['jsonVersion']}"
|
31
33
|
end
|
32
34
|
|
33
35
|
def build_body(operation, data)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
module Stubbing
|
3
5
|
module Protocols
|
@@ -23,9 +25,9 @@ module Aws
|
|
23
25
|
xml = []
|
24
26
|
builder = Aws::Xml::DocBuilder.new(target: xml, indent: ' ')
|
25
27
|
builder.node(operation.name + 'Response', xmlns: xmlns(api)) do
|
26
|
-
if rules = operation.output
|
28
|
+
if (rules = operation.output)
|
27
29
|
rules.location_name = operation.name + 'Result'
|
28
|
-
Xml::Builder.new(rules, target:xml, pad:' ').to_xml(data)
|
30
|
+
Xml::Builder.new(rules, target: xml, pad:' ').to_xml(data)
|
29
31
|
end
|
30
32
|
builder.node('ResponseMetadata') do
|
31
33
|
builder.node('RequestId', 'stubbed-request-id')
|