Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions botocore/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,13 @@ def _assume_role_with_web_identity(self):
if role_session_name is not None:
extra_args['RoleSessionName'] = role_session_name

duration_seconds = self._get_profile_config('duration_seconds')
if duration_seconds is not None:
try:
extra_args['DurationSeconds'] = int(duration_seconds)
except ValueError:
pass

fetcher = AssumeRoleWithWebIdentityCredentialFetcher(
client_creator=self._client_creator,
web_identity_token_loader=token_loader,
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,36 @@ def test_role_session_name_provided(self):
WebIdentityToken='totally.a.token',
)

def test_duration_seconds_provided(self):
self.config['duration_seconds'] = '7200'
response = {
'Credentials': {
'AccessKeyId': 'foo',
'SecretAccessKey': 'bar',
'SessionToken': 'baz',
'Expiration': self.some_future_time().isoformat(),
},
}
client_creator = self.create_client_creator(with_response=response)
mock_loader_cls = self._mock_loader_cls('totally.a.token')
provider = credentials.AssumeRoleWithWebIdentityProvider(
load_config=self._load_config,
client_creator=client_creator,
cache={},
profile_name=self.profile_name,
token_loader_cls=mock_loader_cls,
)

provider.load().get_frozen_credentials()

client = client_creator.return_value
client.assume_role_with_web_identity.assert_called_with(
RoleArn='arn:aws:iam::123:role/role-name',
DurationSeconds=7200,
RoleSessionName=mock.ANY,
WebIdentityToken='totally.a.token',
)

def test_role_arn_not_set(self):
del self.config['role_arn']
client_creator = self.create_client_creator(with_response={})
Expand Down