Skip to content

Commit 6d14e6e

Browse files
author
Roja Reddy Sareddy
committed
refactor(evaluate): Use evaluation role type via iam_role_resolver
Add 'evaluation' role type to IAM_POLICY_CONFIG with Bedrock and MLflow permissions. BaseEvaluator now calls resolve_and_validate_role with role_type='evaluation' which validates permissions and trust using the existing iam_role_resolver infrastructure. Removes the standalone role_permission_validator utility in favor of the existing centralized approach.
1 parent bfc1047 commit 6d14e6e

5 files changed

Lines changed: 238 additions & 371 deletions

File tree

‎sagemaker-core/src/sagemaker/core/helper/iam_policies.py‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,4 +812,76 @@
812812
},
813813
},
814814
},
815+
"evaluation": {
816+
"role_name": "SageMaker-AutoRole-Evaluation",
817+
"trust_policy": {
818+
"Version": "2012-10-17",
819+
"Statement": [
820+
{
821+
"Effect": "Allow",
822+
"Principal": {
823+
"Service": [
824+
"sagemaker.amazonaws.com",
825+
"bedrock.amazonaws.com",
826+
]
827+
},
828+
"Action": "sts:AssumeRole",
829+
"Condition": {
830+
"StringEquals": {"aws:SourceAccount": "ACCOUNT_PLACEHOLDER"}
831+
},
832+
}
833+
],
834+
},
835+
"policies": {
836+
"bedrock_evaluation_policy": {
837+
"Version": "2012-10-17",
838+
"Statement": [
839+
{
840+
"Effect": "Allow",
841+
"Action": [
842+
"bedrock:CreateEvaluationJob",
843+
"bedrock:GetEvaluationJob",
844+
"bedrock:InvokeModel",
845+
"bedrock:InvokeModelWithResponseStream",
846+
],
847+
"Resource": "*",
848+
}
849+
],
850+
},
851+
"mlflow_policy": {
852+
"Version": "2012-10-17",
853+
"Statement": [
854+
{
855+
"Effect": "Allow",
856+
"Action": [
857+
"sagemaker-mlflow:GetExperimentByName",
858+
"sagemaker-mlflow:CreateExperiment",
859+
"sagemaker-mlflow:CreateRun",
860+
"sagemaker-mlflow:LogBatch",
861+
"sagemaker-mlflow:LogMetric",
862+
"sagemaker-mlflow:LogParam",
863+
"sagemaker-mlflow:SetTag",
864+
"sagemaker-mlflow:UpdateRun",
865+
],
866+
"Resource": "arn:aws:sagemaker:*:*:mlflow-app/*",
867+
}
868+
],
869+
},
870+
"s3_policy": {
871+
"Version": "2012-10-17",
872+
"Statement": [
873+
{
874+
"Effect": "Allow",
875+
"Action": [
876+
"s3:GetObject",
877+
"s3:PutObject",
878+
"s3:ListBucket",
879+
"s3:GetBucketLocation",
880+
],
881+
"Resource": "S3_PLACEHOLDER",
882+
}
883+
],
884+
},
885+
},
886+
},
815887
}

‎sagemaker-core/src/sagemaker/core/helper/iam_role_resolver.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
logger = logging.getLogger(__name__)
2727

28-
ROLE_TYPES = ("training", "serving", "pipeline", "feature_store", "bedrock", "hyperpod")
28+
ROLE_TYPES = ("training", "serving", "pipeline", "feature_store", "bedrock", "hyperpod", "evaluation")
2929

3030
# Permissions the HyperPod CLI flow needs on the *caller* identity — the local
3131
# principal that runs `hyperpod connect-cluster` and `hyperpod start-job`. The CLI

‎sagemaker-train/src/sagemaker/train/common_utils/role_permission_validator.py‎

Lines changed: 0 additions & 195 deletions
This file was deleted.

‎sagemaker-train/src/sagemaker/train/evaluate/base_evaluator.py‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
_is_nova_model,
3131
)
3232
from sagemaker.train.common_utils.recipe_utils import resolve_recipe, get_resolved_recipe_from_context
33-
from sagemaker.train.common_utils.role_permission_validator import (
34-
validate_evaluation_role_permissions,
35-
)
3633
from sagemaker.train.common_utils.validator import validate_hyperpod_compute
3734
from sagemaker.train.defaults import TrainDefaults
3835
from sagemaker.train.recipe_resolver import flatten_resolved_recipe
@@ -737,10 +734,10 @@ def _get_aws_execution_context(self) -> Dict[str, str]:
737734
# This is the job execution role for the
738735
# serverless / SMTJ evaluation backends. The HyperPod backend submits via
739736
# the CLI under the caller's own credentials (see _submit_hyperpod_eval_job)
740-
# and does not resolve a role here, so "training" is always correct here.
737+
# and does not resolve a role here, so "evaluation" is correct here.
741738
role_arn = resolve_and_validate_role(
742739
provided_role=self.role,
743-
role_type="training",
740+
role_type="evaluation",
744741
sagemaker_session=self.sagemaker_session,
745742
)
746743

@@ -751,13 +748,6 @@ def _get_aws_execution_context(self) -> Dict[str, str]:
751748

752749
# Extract account ID from role ARN
753750
account_id = role_arn.split(':')[4] if ':' in role_arn else '052150106756'
754-
755-
# Validate execution role has permissions required for evaluation
756-
validate_evaluation_role_permissions(
757-
role_arn,
758-
self.sagemaker_session,
759-
mlflow_enabled=bool(getattr(self, 'mlflow_resource_arn', None)),
760-
)
761751

762752
return {
763753
'role_arn': role_arn,

0 commit comments

Comments
 (0)