fix(core): prevent false-positive RoleValidationError under condition…#6029
Open
raza-khan0108 wants to merge 1 commit into
Open
fix(core): prevent false-positive RoleValidationError under condition…#6029raza-khan0108 wants to merge 1 commit into
raza-khan0108 wants to merge 1 commit into
Conversation
…-based SCPs (aws#6019) - Treat AllowedByOrganizations/AllowedByPermissionsBoundary=false with implicitDeny as unverifiable instead of definitive denial (_is_unverifiable_denial) - Warn and proceed when policies cannot be definitively evaluated (�erdict = None) - Add �alidate_role parameter to esolve_and_validate_role() and support SAGEMAKER_VALIDATE_ROLE=false env var to allow client-side check opt-out - Expose esolve_and_validate_role class method on IamRoleResolver with ole_arn keyword alias support - Add unit tests for conditional SCP handling, opt-out behavior, and class method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #6019: prevents false-positive
RoleValidationErrorexceptions during role resolution and validation (resolve_and_validate_role) when AWS accounts use condition-based Service Control Policies (SCPs) or condition-based IAM permissions boundaries.Problem
sagemaker-corev2.15.0introduced a pre-flight permission validation check (_evaluate_permissionsviaiam:SimulatePrincipalPolicy) that runs during high-level object construction (e.g.,ModelTrainer(...),TrainDefaults.get_role()) before job submission.Per AWS IAM Documentation, the IAM policy simulator does not evaluate conditional SCPs or permissions boundaries. When an AWS account uses condition-based SCPs (e.g., restricting regions, IP ranges, or required tags),
iam:SimulatePrincipalPolicyreturns:EvalDecision:implicitDenyOrganizationsDecisionDetail:{"AllowedByOrganizations": false}(orPermissionsBoundaryDecisionDetail:{"AllowedByPermissionsBoundary": "false"})Because the previous implementation treated any non-allowed
SimulatePrincipalPolicyverdict as a hard failure (RoleValidationError), valid roles in enterprise AWS Organizations environments were blocked from using high-level SDK v3 constructs (ModelTrainer,ModelBuilder,Pipeline).Solution & Architectural Changes
This PR refactors the client-side role validation flow to gracefully handle simulator limitations and provides explicit opt-out controls:
1. Unverifiable Denial Detection
_is_unverifiable_denial(result: dict) -> boolinsagemaker.core.helper.iam_role_resolverto inspectSimulatePrincipalPolicyevaluation items.EvalDecisionisimplicitDenydue toAllowedByOrganizations: falseorAllowedByPermissionsBoundary: false, the action is classified as unverifiable rather than definitively denied.2. Partitioned Simulation Results & Warn-and-Proceed Behavior
_simulate_denied_actions(...)now returns a tupleTuple[List[str], List[str]]containing(denied_actions, unverifiable_actions)._evaluate_permissions(...)encountersunverifiableactions (and zero definitivedeniedactions), it:WARNINGmessage detailing that Organizations / SCP conditions prevented faithful simulation.verdict = None, [](unverifiable status) rather thanFalse(denied).resolve_and_validate_role(...)treatsverdict = Noneas a soft check: it warns the caller and proceeds with the role without raisingRoleValidationError.verify_hyperpod_connect_permissions(...)also handlesunverifiabledecisions gracefully by logging anINFOmessage and returningNone.3. Client-Side Validation Opt-Out
validate_role: bool = Trueoptional parameter toresolve_and_validate_role(...). When set toFalse, client-side simulation and trust checks are skipped immediately.SAGEMAKER_VALIDATE_ROLE: settingSAGEMAKER_VALIDATE_ROLE=false(or0/no) skips client-side validation globally without requiring code modifications.4. Object-Oriented Interface Integration
resolve_and_validate_role(...)as a method on theIamRoleResolverclass so that call sites passing aroundIamRoleResolverinstances can invoke validation directly while supporting therole_arnkeyword alias.Changes by File
sagemaker-core/src/sagemaker/core/helper/iam_role_resolver.py_is_unverifiable_denialhelper.• Refactored
_simulate_denied_actionsto return(denied, unverifiable)tuple.• Updated
_evaluate_permissionsandverify_hyperpod_connect_permissionsto log warnings and proceed on unverifiable verdicts.• Added
validate_roleparameter andSAGEMAKER_VALIDATE_ROLEenv var check toresolve_and_validate_role.• Added
resolve_and_validate_rolemethod toIamRoleResolverclass.sagemaker-core/tests/unit/helper/test_iam_role_resolver.pyTestSimulateDeniedActionsunit tests for tuple return signature.• Added
test_partitions_unverifiable_denialscovering conditional SCP and boundary evaluation results.• Added
test_conditional_scp_unverifiable_denial_warns_and_proceedsverifyingRoleValidationErroris bypassed with correct warning log.• Added unit tests for
validate_role=False,SAGEMAKER_VALIDATE_ROLE=false,IamRoleResolver().resolve_and_validate_role(), and HyperPod connect unverifiable checks.Verification & Testing
Automated Unit Tests
Ran the full suite of unit tests for the
helpermodule viapytest:Results:
test_iam_role_resolver.py: 79 passed (100%)test_iam_role_creator.py,test_iam_role_resolver.py,test_session_helper.py): 204 passed in 2.14sBackward Compatibility
resolve_and_validate_role(...)callers and unit tests continue to function without modification.explicitDenyorimplicitDenydue to missing IAM role policy permissions) continue to raiseRoleValidationErroras expected.Related Issues
RoleValidationErrorunder condition-based SCPs (IAM simulator can't evaluate conditional SCPs) #6019