@@ -219,6 +219,10 @@ def _prepare_credentials(self, **config):
219219 # Enable bucket region caching
220220 login_info ["cache_regions" ] = config .get ("cache_regions" , True )
221221
222+ role_arn = config .get ("role_arn" )
223+ if role_arn :
224+ self ._assume_role (login_info , role_arn )
225+
222226 config_path = config .get ("configpath" )
223227 if config_path :
224228 os .environ .setdefault ("AWS_CONFIG_FILE" , config_path )
@@ -229,6 +233,29 @@ def _prepare_credentials(self, **config):
229233 splitter = "dot" ,
230234 )
231235
236+ @staticmethod
237+ def _assume_role (login_info , role_arn ):
238+ import botocore .session
239+
240+ session = botocore .session .Session (
241+ profile = login_info .get ("profile" ),
242+ )
243+ sts = session .create_client (
244+ "sts" ,
245+ aws_access_key_id = login_info .get ("key" ),
246+ aws_secret_access_key = login_info .get ("secret" ),
247+ aws_session_token = login_info .get ("token" ),
248+ )
249+ resp = sts .assume_role (
250+ RoleArn = role_arn ,
251+ RoleSessionName = "dvc" ,
252+ )
253+ creds = resp ["Credentials" ]
254+ login_info ["key" ] = creds ["AccessKeyId" ]
255+ login_info ["secret" ] = creds ["SecretAccessKey" ]
256+ login_info ["token" ] = creds ["SessionToken" ]
257+ login_info ["profile" ] = None
258+
232259 @wrap_prop (threading .Lock ())
233260 @cached_property
234261 def fs (self ):
0 commit comments