Lesson 1 of 5 Securing ML and AI Workloads

Designing IAM Roles and Policies for ML and AI

This lesson explains how to design the IAM identities that every ML job, endpoint, notebook, knowledge base and agent acts with, and the permissions of the people who use them.

Learning outcomes

After completing this lesson, you will be able to:

  • Configure execution roles and service roles.
  • Grant iam:PassRole narrowly.
  • Enforce secure configurations with SageMaker condition keys.

Execution roles and service roles

SageMaker AI training jobs, processing jobs, endpoints, pipelines and Studio domains run with an execution role whose trust policy allows sagemaker.amazonaws.com to assume it. The role's permissions decide which S3 data, ECR images, KMS keys and other services the job can use. Bedrock features have their own service roles: a knowledge base role reads data sources and calls the embedding model and vector store; a model customisation role reads training data and writes output; an evaluation job role reads datasets and invokes models; a Bedrock agent role invokes its model. Lambda functions used as agent tools have execution roles too.

True or false

Execution roles

Exam skills 4.3.3

Check how SageMaker AI execution roles work.

Log in to try this activity Interactive activities are free with an account.

Permissions for people: iam:PassRole

A user or pipeline that creates a SageMaker AI job or Bedrock resource must be allowed to pass the execution role to the service with iam:PassRole. Restricting PassRole to specific role ARNs, with the condition iam:PassedToService, stops users from escalating privileges by attaching a more powerful role to a job. Missing PassRole is one of the most common causes of AccessDenied when starting training jobs.

{
  "Effect": "Allow",
  "Action": "iam:PassRole",
  "Resource": "arn:aws:iam::111122223333:role/sagemaker-training-churn",
  "Condition": {"StringEquals": {"iam:PassedToService": "sagemaker.amazonaws.com"}}
}

Condition keys and personas

SageMaker AI condition keys enforce secure configurations in IAM or SCPs: sagemaker:VpcSubnets and sagemaker:VpcSecurityGroupIds require VPC placement; sagemaker:NetworkIsolation and sagemaker:InterContainerTrafficEncryption require isolation and encryption; sagemaker:VolumeKmsKey and sagemaker:OutputKmsKey require KMS keys; sagemaker:InstanceTypes limits instance types. For Bedrock, policies can limit bedrock:InvokeModel to specific model or inference profile ARNs and require a guardrail with bedrock:GuardrailIdentifier. SageMaker Role Manager creates roles for personas such as data scientist and MLOps engineer from templates. The following table summarises the identities.

IdentityUsed byTypical permissions
SageMaker AI execution roleTraining, processing, endpoints, pipelinesS3 prefixes, ECR pull, KMS, CloudWatch Logs
Knowledge base service roleBedrock Knowledge BasesData source read, embedding model, vector store
Customization job roleBedrock fine-tuningTraining data read, output write
Agent / tool rolesBedrock Agents, AgentCore, Lambda toolsOnly the APIs each tool needs
Human roles (personas)Data scientists, MLOps engineersCreate jobs, PassRole for approved roles

The following diagram shows where each security rule for SageMaker AI training jobs is enforced when a data scientist calls the API.

How the security rules are enforced at the API. A data scientist's role may pass only sagemaker-training-* roles to SageMaker AI. When CreateTrainingJob is called, an SCP denies the request unless VPC subnets are set, network isolation is on and a volume KMS key is given; and the execution role reaches only the team's S3 prefixes and KMS key.
The scenario is illustrative.
Spot the bug

A policy that is too loose

Exam skills 4.3.3 · 4.3.2

Find the lines that let data scientists start training jobs outside the security rules.

Log in to try this activity Interactive activities are free with an account.
Worked example

Enforcing secure training jobs

A security team requires that every training job in the ML accounts runs in the VPC, with network isolation and KMS-encrypted volumes, and that data scientists can use only the approved execution role.

  • An SCP denies sagemaker:CreateTrainingJob when sagemaker:VpcSubnets is absent or sagemaker:NetworkIsolation is false, or when sagemaker:VolumeKmsKey is absent.
  • The data scientist persona role allows iam:PassRole only on sagemaker-training-* roles passed to SageMaker AI.
  • Execution roles allow S3 access only to the team's prefixes and decrypt only with the team's KMS key.

Guidance documents alone would not stop a misconfigured job; condition keys in SCPs enforce the rules at the API.

Check yourself

Which permission does a user need to create a SageMaker training job with an execution role?

Show answer

iam:PassRole on that execution role.

Exam Tips

Remember for the exam

  • SageMaker AI jobs and endpoints act with an execution role trusted by sagemaker.amazonaws.com.
  • Creating jobs requires iam:PassRole on the execution role.
  • Enforce VPC, isolation and KMS with SageMaker AI condition keys in IAM or SCPs.
  • Limit Bedrock invocation to approved model ARNs; require guardrails with a condition key.
  • Persona roles from SageMaker Role Manager simplify least privilege.