SageMakerで機械学習アクティビティとIAMポリシーの関係を整理してみた

2024.05.07

こんちには。

データアナリティクス事業本部 機械学習チームの中村(nokomoro3)です。

今回はSageMaker Studio使用時に登場する、機械学習アクティビティについて調べてみましたので共有します。

機械学習アクティビティは以下のシーンで登場します。

  • SageMakerコンソールのRole Managerでロールを作成する際
  • SageMaker Studio Domainを新規作成する際(高速セットアップを使用しない場合)

基本的には双方同じですので、本記事ではまずRole Managerをベースにご説明し、続いてDomain作成時やその他の注意点などを述べる形といたします。

SageMaker Role Managerについて

SageMaker Role Managerは、Amazon SageMakerでデータサイエンティストやMLOpsエンジニアなど役割(ペルソナ)毎に異なる最小権限を、 一般的な機械学習ニーズに対応する形でAmazon SageMakerコンソールから構築・管理する機能となっています。

具体的には3つの事前設定されたペルソナと、いくつかの機械学習アクティビティという事前定義された権限があり、 これらをそのまま用いるか、これらをベースとしてビジネスニーズに合わせたロールを作成することができる機能です。

詳細は以下も参照ください。

機械学習アクティビティの一覧

以下に記載があります。

表にすると以下のような感じです。

名前 説明
01. Access Required AWS Services S3、ECR、Cloudwatch、EC2へのアクセス権限。ジョブおよびエンドポイントの実行ロールに必要。
02. Run Studio Applications Studio環境内で操作するための権限。ドメインおよびユーザープロファイルの実行ロールに必要。
03. Manage ML Jobs SageMakerジョブのライフサイクル全体を管理する権限。
04. Manage Models SageMakerモデルおよびModel Registryを管理する権限。
05. Manage Endpoints SageMaker Endpointのデプロイとアップデートを管理する権限。
06. Manage Pipelines SageMaker Pipelinesおよびパイプライン実行を管理する権限。
07. Manage Experiments ExperimentsおよびTrial の管理権限
08. Search and visualize experiments 監査、リネージのクエリ、Experimentsの可視化のための権限。
09. Manage Model Monitoring SageMaker Model Monitor の監視スケジュールを管理する権限。
10. S3 Full Access すべてのS3操作を実行する権限。
11. S3 Bucket Access 指定したバケットに対する操作の実行権限。
12. Query Athena Workgroups Amazon Athena クエリの実行および管理権限。
13. Manage Glue Tables SageMaker Feature Store および Data Wrangler の Glue テーブルを作成および管理する権限。
14. Canvas Core Access Canvas での実験(基本的なデータ準備、モデル構築、検証など)を実行する権限。
15. Canvas Data Preparation (powered by Data Wrangler) Canvas でエンドツーエンドのデータ準備を実行する権限。
16. Canvas AI Services Amazon Bedrock、Amazon Textract、Amazon Rekognition、Amazon Comprehendからready-to-useなモデルにアクセスする権限。さらにAmazon BedrockやAmazon SageMaker Jumpstartのfine-tuningをする権限。
17. Canvas MLOps Canvasユーザーがモデルをエンドポイントに直接デプロイする権限。
18. Canvas Kendra Access CanvasがKendraにアクセスし、エンタープライズドキュメントを検索する権限。

番号は本記事で説明のために割り振ってたものとなりますのでご了承ください。

「01. Access Required AWS Services」はS3やECRなどのSageMaker外のリソースを必要とする際のアクティビティです。 10.および11.もSaeMaker外のリソースに関するものですが、S3に限定されているものと理解すれば良さそうです。

「02. Run Studio Applications」はSageMaker Studioを使う際のAppやSpaceなどを操作する基本的なアクティビティです。

03~09はそれぞれSageMaker Studioの機能ごとに割り振られているアクティビティです。

12.および13.はFeature StoreやData WranglerなどAthenaやGlueと関連する機能を使う際のアクティビティとなっています。

14~17はSageMaker Canvasに関する機能で、「18. Canvas Kendra Access」もCanvasに関するものではありますが、Kendraへのアクセスをするためのアクティビティとなっています。

機械学習アクティビティとペルソナの関係

ペルソナについては以下に記載のとおり3つが事前設定されています。

それぞれの概要は以下です。

  • Data Scientist
  • MLOps Engineer
  • SageMaker Compute Role

各ペルソナで有効となる機械学習アクティビティは以下となります。

Activity Name Data Scientist MLOps Engineer SageMaker Compute Role
01. Access Required AWS Services
02. Run Studio Applications
03. Manage ML Jobs
04. Manage Models
05. Manage Endpoints
06. Manage Pipelines
07. Manage Experiments
08. Search and visualize experiments
09. Manage Model Monitoring
10. S3 Full Access
11. S3 Bucket Access
12. Query Athena Workgroups
13. Manage Glue Tables
14. Canvas Core Access
15. Canvas Data Preparation (powered by Data Wrangler)
16. Canvas AI Services
17. Canvas MLOps
18. Canvas Kendra Access

なお、SageMaker Studio Domain作成時にデフォルトでチェックされている機械学習アクティビティは、Data Scientistのペルソナに沿ったものとなっているようです。

またRole Managerからペルソナを選択すると、上記のアクティビティが必ず有効になるものではなく、自動的にチェックボックスが入る程度の緩めな設定となっており、自由に不要なものは外すことができます。

Role Managerを使ってみる

それではRole Managerから実際に機械学習アクティビティを持ったロールを作成してみます。

SageMakerのコンソールからRole Managerをクリックします。

「ロールを作成」をクリックします。

ロール名のサフィックスとペルソナを選択します。

ネットワーク条件でVPCカスタマイズを有効にすることもできます。このカスタマイズを有効にすると、アクティビティによっては作成されるIAMポリシーがVPCの制限が付いたものになります。

設定後は「次へ」を押下します。

設定したペルソナに基づいて既に機械学習アクティビティにチェックが付いている状態となります。

アクティビティによっては、パラメータの設定が必要ですので入力します。 なおパラメータ設定したリソースが本当に存在するかどうかは確認されず、単にポリシーに値を埋め込むのに使用されるようです。 設定後は「次へ」を押下します。

アタッチするポリシーを追加することもできます。試しにAmazonSageMakerFullAccessを追加して「次へ」を押下します。

最後に確認画面が表示されますので、「送信」を押下します。

作成後のロールは以下のようにアクティビティに対応するポリシーと、追加したポリシーがアタッチされている状態となります。

ポリシーのアタッチには上限があり、チェックボックスのチェック時にはエラーが表示されなかったですのでご注意ください。

機械学習アクティビティの詳細

機械学習アクティビティとIAMポリシーの対応

機械学習アクティビティはそれぞれ、カスタムポリシーまたはマネージドポリシーと1対1対応しています。

Activity Name 種類 ポリシー名
01. Access Required AWS Services カスタム SM_ComputeExecutionRole_{タイムスタンプ}
02. Run Studio Applications カスタム SM_StudioAppPermissions_{タイプスタンプ}
03. Manage ML Jobs カスタム SM_CommonJobManagement_{タイムスタンプ}
04. Manage Models カスタム SM_ModelManagement_{タイムスタンプ}
05. Manage Endpoints カスタム SM_EndpointDeployment_{タイムスタンプ}
06. Manage Pipelines カスタム SM_PipelineManagement_{タイムスタンプ}
07. Manage Experiments カスタム SM_ExperimentsManagement_{タイムスタンプ}
08. Search and visualize experiments カスタム SM_ExperimentsVisualization_{タイムスタンプ}
09. Manage Model Monitoring カスタム SM_ModelMonitoring_{タイムスタンプ}
10. S3 Full Access カスタム SageMakerS3AllResourcesPolicyTemplate_{タイムスタンプ}
11. S3 Bucket Access カスタム SageMakerS3BucketPolicyTemplate_{タイムスタンプ}
12. Query Athena Workgroups カスタム SM_AthenaQueryAccess_{タイムスタンプ}
13. Manage Glue Tables カスタム SM_GlueTableManagement_{タイムスタンプ}
14. Canvas Core Access マネージド arn:aws:iam::aws:policy/AmazonSageMakerCanvasFullAccess
15. Canvas Data Preparation (powered by Data Wrangler) マネージド arn:aws:iam::aws:policy/AmazonSageMakerCanvasDataPrepFullAccess
16. Canvas AI Services マネージド arn:aws:iam::aws:policy/AmazonSageMakerCanvasAIServicesAccess
17. Canvas MLOps マネージド arn:aws:iam::aws:policy/service-role/AmazonSageMakerCanvasDirectDeployAccess
18. Canvas Kendra Access カスタム SagemakerCanvasKendraAccessPolicyTemplate_{タイムスタンプ}

VPCのカスタマイズが利用可能な機械学習アクティビティ

以下に示す一部の機械学習アクティビティは、Role Managerから「VPCのカスタマイズを利用可能」を有効にすることによって、カスタムポリシーの内容が変わります。

Activity Name 対応ポリシー
01. Access Required AWS Services カスタム | SM_ComputeExecutionRole_VPC_{タイムスタンプ}
03. Manage ML Jobs カスタム | SM_CommonJobManagement_VPC_{タイムスタンプ}
04. Manage Models カスタム | SM_ModelManagement_VPC_{タイムスタンプ}
09. Manage Model Monitoring カスタム | SM_ModelMonitoring_VPC_{タイムスタンプ}

他のアクティビティに依存する機械学習アクティビティ

また以下に示す一部の機械学習アクティビティは、他の機械学習アクティビティに依存しているため、依存しているアクティビティも同時に有効化する必要があります。(おもにCanvas関係)

Activity Name 有効にする必要のあるアクティビティ
14. Canvas Core Access Run Studio Applications
15. Canvas Data Preparation (powered by Data Wrangler) Run Studio Applications
16. Canvas AI Services Run Studio Applications
Canvas Core AccessまたはCanvas Data Preparation
17. Canvas MLOps Run Studio Applications
Canvas Core AccessまたはCanvas Data Preparation
18. Canvas Kendra Access Run Studio Applications
Canvas Core AccessまたはCanvas Data Preparation

機械学習アクティビティのポリシー定義

ここからはそれぞれのポリシー定義を確認していきます。

Access Required AWS Services

パラメータは以下の2つとなります。

  • S3Buckets
  • ECRRepoArns

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:BatchPutMetrics",
                "ecr:GetAuthorizationToken",
                "ecr:ListImages"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage"
            ],
            "Resource": [
                "{パラメータで指定したECRのレポジトリARN}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "cloudwatch:PutMetricData",
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "cloudwatch:namespace": [
                        "*SageMaker*",
                        "*Sagemaker*",
                        "*sagemaker*"
                    ]
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:CreateLogGroup",
                "logs:DescribeLogStreams"
            ],
            "Resource": "arn:aws:logs:*:*:log-group:/aws/sagemaker/*"
        }
    ]
}

VPCのカスタマイズを利用可能にした場合は以下となります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:BatchPutMetrics",
                "ecr:GetAuthorizationToken",
                "ecr:ListImages"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage"
            ],
            "Resource": [
                "{パラメータで指定したECRのレポジトリARN}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:CreateNetworkInterface",
                "ec2:CreateNetworkInterfacePermission",
                "ec2:DeleteNetworkInterface",
                "ec2:DeleteNetworkInterfacePermission",
                "ec2:DescribeNetworkInterfaces",
                "ec2:DescribeVpcs",
                "ec2:DescribeDhcpOptions",
                "ec2:DescribeSubnets",
                "ec2:DescribeSecurityGroups"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "cloudwatch:PutMetricData",
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "cloudwatch:namespace": [
                        "*SageMaker*",
                        "*Sagemaker*",
                        "*sagemaker*"
                    ]
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:CreateLogGroup",
                "logs:DescribeLogStreams"
            ],
            "Resource": "arn:aws:logs:*:*:log-group:/aws/sagemaker/*"
        }
    ]
}

ネットワーク関連の権限が追加されていることが分かります。

Run Studio Applications Permissions

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "SMStudioUserProfileAppPermissionsCreateAndDelete",
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateApp",
                "sagemaker:DeleteApp"
            ],
            "Resource": "arn:aws:sagemaker:ap-northeast-1:{アカウントID}:app/*",
            "Condition": {
                "Null": {
                    "sagemaker:OwnerUserProfileArn": "true"
                }
            }
        },
        {
            "Sid": "SMStudioCreatePresignedDomainUrlForUserProfile",
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreatePresignedDomainUrl"
            ],
            "Resource": "arn:aws:sagemaker:ap-northeast-1:{アカウントID}:user-profile/${sagemaker:DomainId}/${sagemaker:UserProfileName}"
        },
        {
            "Sid": "SMStudioAppPermissionsListAndDescribe",
            "Effect": "Allow",
            "Action": [
                "sagemaker:ListApps",
                "sagemaker:ListDomains",
                "sagemaker:ListUserProfiles",
                "sagemaker:ListSpaces",
                "sagemaker:DescribeApp",
                "sagemaker:DescribeDomain",
                "sagemaker:DescribeUserProfile",
                "sagemaker:DescribeSpace"
            ],
            "Resource": "*"
        },
        {
            "Sid": "SMStudioAppPermissionsTagOnCreate",
            "Effect": "Allow",
            "Action": [
                "sagemaker:AddTags"
            ],
            "Resource": "arn:aws:sagemaker:ap-northeast-1:{アカウントID}:*/*",
            "Condition": {
                "Null": {
                    "sagemaker:TaggingAction": "false"
                }
            }
        },
        {
            "Sid": "SMStudioRestrictSharedSpacesWithoutOwners",
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateSpace",
                "sagemaker:UpdateSpace",
                "sagemaker:DeleteSpace"
            ],
            "Resource": "arn:aws:sagemaker:ap-northeast-1:{アカウントID}:space/${sagemaker:DomainId}/*",
            "Condition": {
                "Null": {
                    "sagemaker:OwnerUserProfileArn": "true"
                }
            }
        },
        {
            "Sid": "SMStudioRestrictSpacesToOwnerUserProfile",
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateSpace",
                "sagemaker:UpdateSpace",
                "sagemaker:DeleteSpace"
            ],
            "Resource": "arn:aws:sagemaker:ap-northeast-1:{アカウントID}:space/${sagemaker:DomainId}/*",
            "Condition": {
                "ArnLike": {
                    "sagemaker:OwnerUserProfileArn": "arn:aws:sagemaker:ap-northeast-1:{アカウントID}:user-profile/${sagemaker:DomainId}/${sagemaker:UserProfileName}"
                },
                "StringEquals": {
                    "sagemaker:SpaceSharingType": [
                        "Private",
                        "Shared"
                    ]
                }
            }
        },
        {
            "Sid": "SMStudioRestrictCreatePrivateSpaceAppsToOwnerUserProfile",
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateApp",
                "sagemaker:DeleteApp"
            ],
            "Resource": "arn:aws:sagemaker:ap-northeast-1:{アカウントID}:app/${sagemaker:DomainId}/*",
            "Condition": {
                "ArnLike": {
                    "sagemaker:OwnerUserProfileArn": "arn:aws:sagemaker:ap-northeast-1:{アカウントID}:user-profile/${sagemaker:DomainId}/${sagemaker:UserProfileName}"
                },
                "StringEquals": {
                    "sagemaker:SpaceSharingType": [
                        "Private"
                    ]
                }
            }
        },
        {
            "Sid": "AllowAppActionsForSharedSpaces",
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateApp",
                "sagemaker:DeleteApp"
            ],
            "Resource": "arn:aws:sagemaker:*:*:app/${sagemaker:DomainId}/*/*/*",
            "Condition": {
                "StringEquals": {
                    "sagemaker:SpaceSharingType": [
                        "Shared"
                    ]
                }
            }
        }
    ]
}

Manage ML Jobs

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateTrainingJob",
                "sagemaker:CreateTransformJob",
                "sagemaker:CreateProcessingJob",
                "sagemaker:CreateAutoMLJob",
                "sagemaker:CreateHyperParameterTuningJob",
                "sagemaker:StopTrainingJob",
                "sagemaker:StopProcessingJob",
                "sagemaker:StopAutoMLJob",
                "sagemaker:StopHyperParameterTuningJob",
                "sagemaker:DescribeTrainingJob",
                "sagemaker:DescribeTransformJob",
                "sagemaker:DescribeProcessingJob",
                "sagemaker:DescribeAutoMLJob",
                "sagemaker:DescribeHyperParameterTuningJob",
                "sagemaker:UpdateTrainingJob",
                "sagemaker:BatchGetMetrics"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:Search",
                "sagemaker:ListTrainingJobs",
                "sagemaker:ListTransformJobs",
                "sagemaker:ListProcessingJobs",
                "sagemaker:ListAutoMLJobs",
                "sagemaker:ListCandidatesForAutoMLJob",
                "sagemaker:ListHyperParameterTuningJobs",
                "sagemaker:ListTrainingJobsForHyperParameterTuningJob"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "{作成した実行ロールのARN}"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "sagemaker.amazonaws.com"
                }
            }
        }
    ]
}

VPCのカスタマイズを利用可能にした場合は以下となります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateTrainingJob",
                "sagemaker:CreateTransformJob",
                "sagemaker:CreateProcessingJob",
                "sagemaker:CreateAutoMLJob",
                "sagemaker:CreateHyperParameterTuningJob"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*",
            "Condition": {
                "ForAllValues:StringEquals": {
                    "sagemaker:VpcSubnets": [
                        "{指定したサブネットID}"
                    ],
                    "sagemaker:VpcSecurityGroupIds": [
                        "{指定したセキュリティグループID}"
                    ]
                },
                "Null": {
                    "sagemaker:VpcSubnets": "false",
                    "sagemaker:VpcSecurityGroupIds": "false"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:StopTrainingJob",
                "sagemaker:StopTransformJob",
                "sagemaker:StopProcessingJob",
                "sagemaker:StopAutoMLJob",
                "sagemaker:StopHyperParameterTuningJob",
                "sagemaker:DescribeTrainingJob",
                "sagemaker:DescribeTransformJob",
                "sagemaker:DescribeProcessingJob",
                "sagemaker:DescribeAutoMLJob",
                "sagemaker:DescribeHyperParameterTuningJob",
                "sagemaker:UpdateTrainingJob",
                "sagemaker:BatchGetMetrics"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:Search",
                "sagemaker:ListTrainingJobs",
                "sagemaker:ListTransformJobs",
                "sagemaker:ListProcessingJobs",
                "sagemaker:ListAutoMLJobs",
                "sagemaker:ListCandidatesForAutoMLJob",
                "sagemaker:ListHyperParameterTuningJobs",
                "sagemaker:ListTrainingJobsForHyperParameterTuningJob"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "{作成した実行ロールのARN}"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "sagemaker.amazonaws.com"
                }
            }
        }
    ]
}

ConditionにVPC関連の条件が追加されています。またこちらにだけsagemaker:StopTransformJobがあり、意図通りの仕様なのか分かりませんが注意が必要です。

Manage Models

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateModel",
                "sagemaker:CreateModelPackage",
                "sagemaker:CreateModelPackageGroup",
                "sagemaker:DescribeModel",
                "sagemaker:DescribeModelPackage",
                "sagemaker:DescribeModelPackageGroup",
                "sagemaker:BatchDescribeModelPackage",
                "sagemaker:UpdateModelPackage",
                "sagemaker:DeleteModel",
                "sagemaker:DeleteModelPackage",
                "sagemaker:DeleteModelPackageGroup"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:ListModels",
                "sagemaker:ListModelPackages",
                "sagemaker:ListModelPackageGroups"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "{作成した実行ロールのARN}"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "sagemaker.amazonaws.com"
                }
            }
        }
    ]
}

VPCのカスタマイズを利用可能にした場合は以下となります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateModel"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*",
            "Condition": {
                "ForAllValues:StringEquals": {
                    "sagemaker:VpcSubnets": [
                        "{指定したサブネットID}"
                    ],
                    "sagemaker:VpcSecurityGroupIds": [
                        "{指定したセキュリティグループID}"
                    ]
                },
                "Null": {
                    "sagemaker:VpcSubnets": "false",
                    "sagemaker:VpcSecurityGroupIds": "false"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateModelPackage",
                "sagemaker:CreateModelPackageGroup",
                "sagemaker:DescribeModel",
                "sagemaker:DescribeModelPackage",
                "sagemaker:DescribeModelPackageGroup",
                "sagemaker:BatchDescribeModelPackage",
                "sagemaker:UpdateModelPackage",
                "sagemaker:DeleteModel",
                "sagemaker:DeleteModelPackage",
                "sagemaker:DeleteModelPackageGroup"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:ListModels",
                "sagemaker:ListModelPackages",
                "sagemaker:ListModelPackageGroups"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "{作成した実行ロールのARN}"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "sagemaker.amazonaws.com"
                }
            }
        }
    ]
}

ConditionにVPC関連の条件が追加されています。

Manage Endpoints

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateEndpointConfig",
                "sagemaker:CreateEndpoint",
                "sagemaker:DeleteEndpointConfig",
                "sagemaker:DeleteEndpoint",
                "sagemaker:UpdateEndpoint",
                "sagemaker:UpdateEndpointWeightsAndCapacities",
                "sagemaker:DescribeEndpoint",
                "sagemaker:DescribeEndpointConfig"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:ListEndpoints",
                "sagemaker:ListEndpointConfigs"
            ],
            "Resource": "*"
        }
    ]
}

Manage Pipelines

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreatePipeline",
                "sagemaker:StartPipelineExecution",
                "sagemaker:StopPipelineExecution",
                "sagemaker:RetryPipelineExecution",
                "sagemaker:UpdatePipelineExecution",
                "sagemaker:SendPipelineExecutionStepSuccess",
                "sagemaker:SendPipelineExecutionStepFailure",
                "sagemaker:DescribePipeline",
                "sagemaker:DescribePipelineExecution",
                "sagemaker:DescribePipelineDefinitionForExecution",
                "sagemaker:DeletePipeline"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:ListPipelines",
                "sagemaker:ListPipelineExecutions",
                "sagemaker:ListPipelineExecutionSteps",
                "sagemaker:ListPipelineParametersForExecution"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "{作成した実行ロールのARN}"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "sagemaker.amazonaws.com"
                }
            }
        }
    ]
}

Manage Experiments

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:AddAssociation",
                "sagemaker:CreateAction",
                "sagemaker:CreateArtifact",
                "sagemaker:CreateContext",
                "sagemaker:CreateExperiment",
                "sagemaker:CreateTrial",
                "sagemaker:CreateTrialComponent",
                "sagemaker:UpdateAction",
                "sagemaker:UpdateArtifact",
                "sagemaker:UpdateContext",
                "sagemaker:UpdateExperiment",
                "sagemaker:UpdateTrial",
                "sagemaker:UpdateTrialComponent",
                "sagemaker:AssociateTrialComponent",
                "sagemaker:DisassociateTrialComponent",
                "sagemaker:DeleteAssociation",
                "sagemaker:DeleteAction",
                "sagemaker:DeleteArtifact",
                "sagemaker:DeleteContext",
                "sagemaker:DeleteExperiment",
                "sagemaker:DeleteTrial",
                "sagemaker:DeleteTrialComponent"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        }
    ]
}

Search and visualize experiments

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:DescribeAction",
                "sagemaker:DescribeArtifact",
                "sagemaker:DescribeContext",
                "sagemaker:DescribeExperiment",
                "sagemaker:DescribeTrial",
                "sagemaker:DescribeTrialComponent",
                "sagemaker:DescribeLineageGroup"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:ListAssociations",
                "sagemaker:ListActions",
                "sagemaker:ListArtifacts",
                "sagemaker:ListContexts",
                "sagemaker:ListExperiments",
                "sagemaker:ListTrials",
                "sagemaker:ListTrialComponents",
                "sagemaker:ListLineageGroups",
                "sagemaker:GetLineageGroupPolicy",
                "sagemaker:QueryLineage",
                "sagemaker:Search",
                "sagemaker:GetSearchSuggestions"
            ],
            "Resource": "*"
        }
    ]
}

Manage Model Monitoring

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateMonitoringSchedule",
                "sagemaker:UpdateMonitoringSchedule",
                "sagemaker:DescribeMonitoringSchedule",
                "sagemaker:DeleteMonitoringSchedule",
                "sagemaker:StartMonitoringSchedule",
                "sagemaker:StopMonitoringSchedule",
                "sagemaker:CreateProcessingJob",
                "sagemaker:DescribeProcessingJob",
                "sagemaker:StopProcessingJob"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:ListMonitoringSchedules",
                "sagemaker:ListProcessingJobs"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "{作成した実行ロールのARN}"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "sagemaker.amazonaws.com"
                }
            }
        }
    ]
}

VPCのカスタマイズを利用可能にした場合は以下となります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateMonitoringSchedule",
                "sagemaker:UpdateMonitoringSchedule",
                "sagemaker:CreateProcessingJob"
            ],
            "Resource": "arn:aws:sagemaker:*:*:*/*",
            "Condition": {
                "ForAllValues:StringEquals": {
                    "sagemaker:VpcSubnets": [
                        "{指定したサブネットID}"
                    ],
                    "sagemaker:VpcSecurityGroupIds": [
                        "{指定したセキュリティグループID}"
                    ]
                },
                "Null": {
                    "sagemaker:VpcSubnets": "false",
                    "sagemaker:VpcSecurityGroupIds": "false"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:ListMonitoringSchedules",
                "sagemaker:ListProcessingJobs"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "{作成した実行ロールのARN}"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "sagemaker.amazonaws.com"
                }
            }
        }
    ]
}

ConditionにVPC関連の条件が追加されています。また今度はVPCカスタマイズを有効にした場合に、権限が少なくなっているようです。これが意図通りの仕様なのか分かりませんが注意が必要です。

S3 Full Access

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::*"
            ]
        }
    ]
}

S3 Bucket Access

パラメータは以下となります。

  • bucket

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:ListBucket"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}"
            ]
        },
        {
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}/*"
            ]
        }
    ]
}

Query Athena Workgroups

パラメータは以下となります。

  • WorkGroupNames

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "athena:GetQueryExecution",
                "athena:GetQueryResults",
                "athena:StartQueryExecution",
                "athena:StopQueryExecution"
            ],
            "Resource": [
                "arn:aws:athena:*:*:workgroup/{パラメータで指定したワークグループ名}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "athena:ListDataCatalogs",
                "athena:ListDatabases",
                "athena:ListTableMetadata"
            ],
            "Resource": "*"
        }
    ]
}

Manage Glue Tables

パラメータは以下の2つとなります。

  • S3Buckets
  • GlueDbNames

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "glue:SearchTables"
            ],
            "Resource": [
                "arn:aws:glue:ap-northeast-1:{アカウントID}:table/*/*",
                "arn:aws:glue:ap-northeast-1:{アカウントID}:database/{パラメータで指定したGlueデータベース名}",
                "arn:aws:glue:ap-northeast-1:{アカウントID}:catalog"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:GetBucketAcl"
            ],
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutBucketAcl"
            ],
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}/*"
            ],
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "bucket-owner-full-control"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "glue:GetTable",
                "glue:UpdateTable"
            ],
            "Resource": [
                "arn:aws:glue:ap-northeast-1:{アカウントID}:catalog",
                "arn:aws:glue:ap-northeast-1:{アカウントID}:database/sagemaker_featurestore",
                "arn:aws:glue:ap-northeast-1:{アカウントID}:table/sagemaker_featurestore/*"
            ]
        }
    ]
}

Canvas Core Access

ポリシーはマネージドポリシーとなっていますので、以下のリンクを参照ください。

Canvas Data Preparation

ポリシーはマネージドポリシーとなっていますので、以下のリンクを参照ください。

Canvas AI Services

ポリシーはマネージドポリシーとなっていますので、以下のリンクを参照ください。

Canvas MLOps

ポリシーはマネージドポリシーとなっていますので、以下のリンクを参照ください。

Canvas Kendra Access

パラメータは以下となります。

  • index_ids

ポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ListStatement",
            "Effect": "Allow",
            "Action": [
                "kendra:ListIndices"
            ],
            "Resource": "*"
        },
        {
            "Sid": "RetrieveStatement",
            "Effect": "Allow",
            "Action": [
                "kendra:Retrieve"
            ],
            "Resource": [
                "arn:aws:kendra:ap-northeast-1:{アカウントID}:index/{パラメータで指定されてKendraのインデックスID}"
            ]
        }
    ]
}

ドメイン作成時の違い

Role Managerを使用してロールを作成した場合と、SageMakerドメイン作成時にロールを作成した場合とで作成されるポリシーが異なるケースがあるため、ここではそちらについて紹介します。

なおここで紹介するドメイン作成時は、基本的にはクイックセットアップではなく、組織向けの設定を選択した場合のお話となります。

VPCカスタマイズを有効としてもポリシーは変わらない

Role Managerから作成する場合は、VPCのカスタマイズを有効とすると作成されるポリシーに変化がありましたが、ドメイン作成時にVPCカスタマイズを選択しても、ポリシーはVPCカスタマイズを行わない場合と同じポリシーとなります。

Access Required AWS Servicesの権限が変わる

アクセス可能なS3バケットが増えたようなポリシー内容となります。

その場合のポリシーは以下のようになります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}",
                "arn:aws:s3:::sagemaker-studio-{何かしらのID}/sharing",
                "arn:aws:s3:::sagemaker-ap-northeast-1-{アカウントID}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::{パラメータで指定したバケット名}/*",
                "arn:aws:s3:::sagemaker-studio-何かしらのID/sharing/*",
                "arn:aws:s3:::sagemaker-ap-northeast-1-{アカウントID}/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:BatchPutMetrics",
                "ecr:GetAuthorizationToken",
                "ecr:ListImages"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage"
            ],
            "Resource": [
                "{パラメータで指定したECRのレポジトリARN}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "cloudwatch:PutMetricData",
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "cloudwatch:namespace": [
                        "*SageMaker*",
                        "*Sagemaker*",
                        "*sagemaker*"
                    ]
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:CreateLogGroup",
                "logs:DescribeLogStreams"
            ],
            "Resource": "arn:aws:logs:*:*:log-group:/aws/sagemaker/*"
        }
    ]
}

SageMakerのデフォルトバケットと、ノートブックの共有で使用されるS3のパスがアクセス権限として追加されています。

クイックセットアップ時に自動作成される実行ロール

なお、SageMakerドメイン作成時にクイックセットアップを選択した場合、以下のAmazonSageMakerFullAccessがアタッチされた実行ロールが作成されます。

カスタムポリシーはS3に関する権限のものとなります。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::*"
            ]
        }
    ]
}

SageMakerFullAccessを使いたい場合

SageMakerFullAccessをアタッチしておけば、ほぼすべての機能を動作させることができたため検証には有用だったのですが、今回取り上げた機械学習アクティビティと紐づけられていません。

そのため、SageMakerFullAccessの付与された実行ロールが必要な場合は、以下の3ついずれかを実施する必要があります。

  • 先ほど紹介したようにRole Managerの追加のポリシーとしてアタッチする
  • ドメイン作成時にクイックセットアップを使用して、実行ロールを自動作成する
  • IAMのコンソールから手動で作成する

最も簡単なのは2番目で、Canvas関連の権限も同時に付与されますので、ご参考にされてください。

SageMakerFullAccessの権限については、以下のリンクを参照ください。

まとめ

いかがでしたでしょうか。本記事がAmazon SageMakerを使う際の参考になれば幸いです。