Skip to content

Commit 2ef27a1

Browse files
laurenyuyangaws
authored andcommitted
Make sure that an arn including 'role' won't pass (aws#65) (aws#570)
1 parent 4ffdeda commit 2ef27a1

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
CHANGELOG
33
=========
44

5+
1.16.4.dev
6+
==========
7+
8+
* bug-fix: Session: don't allow get_execution_role() to return an ARN that's not a role but has "role" in the name
9+
510
1.16.3
611
======
712

8-
* bug-fix: Local Mode: Allow support for SSH in local mode
13+
* bug-fix: Local Mode: Allow support for SSH in local mode
914
* bug-fix: Append retry id to default Airflow job name to avoid name collisions in retry
1015
* bug-fix: Local Mode: No longer requires s3 permissions to run local entry point file
1116
* feature: Estimators: add support for PyTorch 1.0.0

src/sagemaker/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ def get_execution_role(sagemaker_session=None):
12121212
sagemaker_session = Session()
12131213
arn = sagemaker_session.get_caller_identity_arn()
12141214

1215-
if 'role' in arn:
1215+
if ':role/' in arn:
12161216
return arn
12171217
message = 'The current AWS identity is not a role: {}, therefore it cannot be used as a SageMaker execution role'
12181218
raise ValueError(message.format(arn))

tests/unit/test_session.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def test_get_execution_role_throws_exception_if_arn_is_not_role():
6565
assert 'ValueError: The current AWS identity is not a role' in str(error)
6666

6767

68+
def test_get_execution_role_throws_exception_if_arn_is_not_role_with_role_in_name():
69+
session = Mock()
70+
session.get_caller_identity_arn.return_value = 'arn:aws:iam::369233609183:user/marcos-role'
71+
72+
with pytest.raises(ValueError) as error:
73+
get_execution_role(session)
74+
assert 'ValueError: The current AWS identity is not a role' in str(error)
75+
76+
6877
def test_get_caller_identity_arn_from_an_user(boto_session):
6978
sess = Session(boto_session)
7079
arn = 'arn:aws:iam::369233609183:user/mia'

0 commit comments

Comments
 (0)