Skip to content

Commit 6c73592

Browse files
author
Namrata Madan
committed
fix: create asymmetric validation key in step compiler
1 parent 1a3bda2 commit 6c73592

22 files changed

Lines changed: 1865 additions & 344 deletions

File tree

sagemaker-core/src/sagemaker/core/experiments/_utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,23 @@ def get_tc_and_exp_config_from_job_env(
118118
job_name = environment.source_arn.split("/")[-1]
119119
if environment.environment_type == _EnvironmentType.SageMakerTrainingJob:
120120
job_response = retry_with_backoff(
121-
callable_func=lambda: sagemaker_session.describe_training_job(job_name),
121+
callable_func=lambda: sagemaker_session.sagemaker_client.describe_training_job(
122+
TrainingJobName=job_name
123+
),
122124
num_attempts=4,
123125
)
124126
elif environment.environment_type == _EnvironmentType.SageMakerProcessingJob:
125127
job_response = retry_with_backoff(
126-
callable_func=lambda: sagemaker_session.describe_processing_job(job_name),
128+
callable_func=lambda: sagemaker_session.sagemaker_client.describe_processing_job(
129+
ProcessingJobName=job_name
130+
),
127131
num_attempts=4,
128132
)
129133
else: # environment.environment_type == _EnvironmentType.SageMakerTransformJob
130134
job_response = retry_with_backoff(
131-
callable_func=lambda: sagemaker_session.describe_transform_job(job_name),
135+
callable_func=lambda: sagemaker_session.sagemaker_client.describe_transform_job(
136+
TransformJobName=job_name
137+
),
132138
num_attempts=4,
133139
)
134140

sagemaker-core/src/sagemaker/core/remote_function/core/serialization.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -366,34 +366,6 @@ def serialize_exception_to_s3(
366366
)
367367

368368

369-
def _upload_payload_and_metadata_to_s3(
370-
bytes_to_upload: Union[bytes, io.BytesIO],
371-
hmac_key: str,
372-
s3_uri: str,
373-
sagemaker_session: Session,
374-
s3_kms_key,
375-
):
376-
"""Uploads serialized payload and metadata to s3.
377-
378-
Args:
379-
bytes_to_upload (bytes): Serialized bytes to upload.
380-
hmac_key (str): Key used to calculate hmac-sha256 hash of the serialized obj.
381-
s3_uri (str): S3 root uri to which resulting serialized artifacts will be uploaded.
382-
sagemaker_session (sagemaker.core.helper.session.Session):
383-
The underlying Boto3 session which AWS service calls are delegated to.
384-
s3_kms_key (str): KMS key used to encrypt artifacts uploaded to S3.
385-
"""
386-
_upload_bytes_to_s3(bytes_to_upload, f"{s3_uri}/payload.pkl", s3_kms_key, sagemaker_session)
387-
388-
sha256_hash = _compute_hash(bytes_to_upload, secret_key=hmac_key)
389-
390-
_upload_bytes_to_s3(
391-
_MetaData(sha256_hash).to_json(),
392-
f"{s3_uri}/metadata.json",
393-
s3_kms_key,
394-
sagemaker_session,
395-
)
396-
397369
def _upload_payload_and_metadata_to_s3_signed(
398370
bytes_to_upload: Union[bytes, io.BytesIO],
399371
private_key: ec.EllipticCurvePrivateKey,
@@ -561,22 +533,3 @@ def _verify_sha256_hash(expected_hash: str, buffer: bytes):
561533
"Integrity check for the serialized function or data failed. "
562534
"Please restrict access to your S3 bucket"
563535
)
564-
565-
566-
def _compute_hash(buffer: bytes, secret_key: str) -> str:
567-
"""Compute the hmac-sha256 hash"""
568-
return hmac.new(secret_key.encode(), msg=buffer, digestmod=hashlib.sha256).hexdigest()
569-
570-
571-
def _perform_integrity_check(expected_hash_value: str, secret_key: str, buffer: bytes):
572-
"""Performs integrity checks for serialized code/arguments uploaded to s3.
573-
574-
Verifies whether the hash read from s3 matches the hash calculated
575-
during remote function execution.
576-
"""
577-
actual_hash_value = _compute_hash(buffer=buffer, secret_key=secret_key)
578-
if not hmac.compare_digest(expected_hash_value, actual_hash_value):
579-
raise DeserializationError(
580-
"Integrity check for the serialized function or data failed. "
581-
"Please restrict access to your S3 bucket"
582-
)

0 commit comments

Comments
 (0)