Skip to content

Commit 625750c

Browse files
edwardpsEdward Sun
authored andcommitted
change: fix the file uploading signature verification error (#1551)
* change: fix the file uploading signature verification error **Description** The URL contains charater(+) which is not escaped properly. Fixed by removing the conditional logic to escape for the character. **Testing** 1. Changed UT passed 2. Test in sample notebook * **Description** Changed from x-mlapp-sm-app-server-arn to x-sagemaker-partner-app-server-arn Also make some small format adjusting for the signing context information. **Testing Done** UT passed --------- Co-authored-by: Edward Sun <[email protected]>
1 parent df1c9dd commit 625750c

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/sagemaker/partner_app/auth_utils.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
HEADER_CONNECTION = "Connection"
2626
HEADER_X_AMZ_TARGET = "X-Amz-Target"
2727
HEADER_AUTHORIZATION = "Authorization"
28-
HEADER_MLAPP_SM_APP_SERVER_ARN = "X-Mlapp-Sm-App-Server-Arn"
28+
HEADER_PARTNER_APP_SERVER_ARN = "X-SageMaker-Partner-App-Server-Arn"
2929
HEADER_PARTNER_APP_AUTHORIZATION = "X-Amz-Partner-App-Authorization"
3030
HEADER_X_AMZ_CONTENT_SHA_256 = "X-Amz-Content-SHA256"
3131
CALL_PARTNER_APP_API_ACTION = "SageMaker.CallPartnerAppApi"
@@ -59,7 +59,7 @@ def get_signed_request(
5959
headers[HEADER_PARTNER_APP_AUTHORIZATION] = headers[HEADER_AUTHORIZATION]
6060

6161
# App Arn
62-
headers[HEADER_MLAPP_SM_APP_SERVER_ARN] = app_arn
62+
headers[HEADER_PARTNER_APP_SERVER_ARN] = app_arn
6363

6464
# IAM Action
6565
headers[HEADER_X_AMZ_TARGET] = CALL_PARTNER_APP_API_ACTION
@@ -74,9 +74,7 @@ def get_signed_request(
7474
del headers[HEADER_CONNECTION]
7575

7676
# Spaces are encoded as %20
77-
# TODO - confirm the motivation
78-
if method in ("GET", "DEL"):
79-
url = url.replace("+", "%20")
77+
url = url.replace("+", "%20")
8078

8179
# Calculate SigV4 header
8280
aws_request = AWSRequest(

tests/unit/sagemaker/partner_app/test_auth_utils.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TestPartnerAppAuthUtils(unittest.TestCase):
1717
def setUp(self):
1818
self.sigv4_mock = Mock(spec=SigV4Auth)
1919
self.app_arn = "arn:aws:sagemaker:us-west-2:123456789012:partner-app/abc123"
20-
self.url = "https://partner-app-abc123.us-west-2.amazonaws.com"
20+
self.url = "https://partner-app-abc123.us-west-2.amazonaws.com?fileName=Jupyter+interactive"
2121
self.method = "POST"
2222
self.headers = {"Authorization": "API_KEY", "Connection": "conn"}
2323
self.body = b'{"key": "value"}' # Byte type body for hashing
@@ -32,7 +32,7 @@ def test_get_signed_request_with_body(self, AWSRequestMock):
3232
expected_sign_headers = {
3333
"Authorization": "API_KEY",
3434
"X-Amz-Partner-App-Authorization": "API_KEY",
35-
"X-Mlapp-Sm-App-Server-Arn": self.app_arn,
35+
"X-SageMaker-Partner-App-Server-Arn": self.app_arn,
3636
"X-Amz-Target": "SageMaker.CallPartnerAppApi",
3737
"X-Amz-Content-SHA256": expected_hash,
3838
}
@@ -45,8 +45,8 @@ def test_get_signed_request_with_body(self, AWSRequestMock):
4545
self.sigv4_mock, self.app_arn, self.url, self.method, self.headers, self.body
4646
)
4747

48-
# Assert X-Mlapp-Sm-App-Server-Arn header is correct
49-
self.assertEqual(signed_headers["X-Mlapp-Sm-App-Server-Arn"], self.app_arn)
48+
# Assert X-SageMaker-Partner-App-Server-Arn header is correct
49+
self.assertEqual(signed_headers["X-SageMaker-Partner-App-Server-Arn"], self.app_arn)
5050

5151
# Assert the Authorization header was moved to X-Amz-Partner-App-Authorization
5252
self.assertIn("X-Amz-Partner-App-Authorization", signed_headers)
@@ -57,10 +57,11 @@ def test_get_signed_request_with_body(self, AWSRequestMock):
5757
# Assert the Connection header is reserved
5858
self.assertEqual(signed_headers["Connection"], "conn")
5959

60+
expected_canonical_url = self.url.replace("+", "%20")
6061
# Assert AWSRequestMock was called
6162
AWSRequestMock.assert_called_once_with(
6263
method=self.method,
63-
url=self.url,
64+
url=expected_canonical_url,
6465
headers=expected_sign_headers,
6566
data=self.body,
6667
)

0 commit comments

Comments
 (0)