Amazon SageMaker 基於身份的政策示例 - Amazon SageMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Amazon SageMaker 基於身份的政策示例

根據預設,IAM 使用者和角色不具備建立或修改 SageMaker 資源的許可。他們也無法使用 AWS Management Console、AWS CLI 或 AWS API 執行任務。IAM 管理員必須建立 IAM 政策,授予使用者和角色在指定資源上執行特定 API 操作的所需許可。管理員接著必須將這些政策連接至需要這些許可的 IAM 使用者或群組。要了解如何將策略附加到 IAM 使用者或群組,請參閱在IAM 使用者指南中的新增和移除 IAM 身分許可

若要了解如何使用這些範例 JSON 政策文件建立 IAM 身分型政策,請參閱《IAM 使用者指南》中的在 JSON 索引標籤上建立政策

政策最佳實務

以身分識別為基礎的政策會決定某人是否可以建立、存取或刪除您帳戶中的 SageMaker 資源。這些動作可能會讓您的 AWS 帳戶 產生費用。當您建立或編輯身分型政策時,請遵循下列準則及建議事項:

  • 開始使用 AWS 受管政策並朝向最低權限許可的目標邁進:如需開始授予許可給使用者和工作負載,請使用 AWS 受管政策,這些政策會授予許可給許多常用案例。它們可在您的 AWS 帳戶 中使用。我們建議您定義特定於使用案例的 AWS 客戶管理政策,以便進一步減少許可。如需更多資訊,請參閱 IAM 使用者指南中的 AWS 受管政策任務職能的 AWS 受管政策

  • 套用最低許可許可 – 設定 IAM 政策的許可時,請僅授予執行任務所需的權限。為實現此目的,您可以定義在特定條件下可以對特定資源採取的動作,這也稱為最低權限許可。如需使用 IAM 套用許可的更多相關資訊,請參閱 IAM 使用者指南中的 IAM 中的政策和許可

  • 使用 IAM 政策中的條件進一步限制存取權 – 您可以將條件新增至政策,以限制動作和資源的存取。例如,您可以撰寫政策條件,指定必須使用 SSL 傳送所有請求。您也可以使用條件來授予對服務動作的存取權,前提是透過特定 AWS 服務 (例如 AWS CloudFormation)使用條件。如需更多資訊,請參閱《IAM 使用者指南》中的 IAM JSON 政策元素:條件

  • 使用 IAM Access Analyzer 驗證 IAM 政策,確保許可安全且可正常運作 – IAM Access Analyzer 驗證新政策和現有政策,確保這些政策遵從 IAM 政策語言 (JSON) 和 IAM 最佳實務。IAM Access Analyzer 提供 100 多項政策檢查及切實可行的建議,可協助您編寫安全且實用的政策。如需更多資訊,請參閱 IAM 使用者指南中的 IAM Access Analyzer 政策驗證

  • 需要多重要素驗證 (MFA):如果存在需要 AWS 帳戶中 IAM 使用者或根使用者的情況,請開啟 MFA 提供額外的安全性。如需在呼叫 API 操作時請求 MFA,請將 MFA 條件新增至您的政策。如需更多資訊,請參閱 IAM 使用者指南中的設定 MFA 保護的 API 存取

有關 IAM 中最佳實務的更多相關資訊,請參閱 IAM 使用者指南中的 IAM 最佳安全實務

使用控 SageMaker 制台

若要存取 Amazon SageMaker 主控台,您必須擁有最少一組許可。這些許可必須允許您列出和檢視您 AWS 帳戶中 SageMaker 資源的詳細資訊。如果您建立比最基本必要許可更嚴格的身分型政策,則對於具有該政策的實體(使用者或角色)而言,主控台就無法如預期運作。

若要確保這些實體仍可使用 SageMaker 主控台,請同時將下列AWS受管理的原則附加至實體。如需更多資訊,請參閱《IAM 使用者指南》中的新增許可到使用者

對於僅呼叫 AWS CLI 或 AWS API 的使用者,您不需要允許其最基本主控台許可。反之,只需允許存取符合您嘗試執行之 API 操作的動作就可以了。

使用 Amazon SageMaker 主控台所需的許可

許可參考表格列出 Amazon SageMaker API 操作,並顯示每個操作所需的許可。如需 Amazon SageMaker API 操作的詳細資訊,請參閱Amazon SageMaker API 許可:動作、許可和資源參考

若要使用 Amazon SageMaker 主控台,您需要授予其他動作的許可。特別是主控台需要允許 ec2 動作的許可才可顯示子網路、VPC 和安全群組。或者,主控台需要許可來建立任務的執行角色,例如 CreateNotebookCreateTrainingJobCreateModel。使用以下許可政策來授予這些許可:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "SageMakerApis", "Effect": "Allow", "Action": [ "sagemaker:*" ], "Resource": "*" }, { "Sid": "VpcConfigurationForCreateForms", "Effect": "Allow", "Action": [ "ec2:DescribeVpcs", "ec2:DescribeSubnets", "ec2:DescribeSecurityGroups" ], "Resource": "*" }, { "Sid":"KmsKeysForCreateForms", "Effect":"Allow", "Action":[ "kms:DescribeKey", "kms:ListAliases" ], "Resource":"*" }, { "Sid": "AccessAwsMarketplaceSubscriptions", "Effect": "Allow", "Action": [ "aws-marketplace:ViewSubscriptions" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "codecommit:BatchGetRepositories", "codecommit:CreateRepository", "codecommit:GetRepository", "codecommit:ListRepositories", "codecommit:ListBranches", "secretsmanager:CreateSecret", "secretsmanager:DescribeSecret", "secretsmanager:ListSecrets" ], "Resource": "*" }, { "Sid":"ListAndCreateExecutionRoles", "Effect":"Allow", "Action":[ "iam:ListRoles", "iam:CreateRole", "iam:CreatePolicy", "iam:AttachRolePolicy" ], "Resource":"*" }, { "Sid": "DescribeECRMetaData", "Effect": "Allow", "Action": [ "ecr:Describe*" ], "Resource": "*" }, { "Sid": "PassRoleForExecutionRoles", "Effect": "Allow", "Action": [ "iam:PassRole" ], "Resource": "*", "Condition": { "StringEquals": { "iam:PassedToService": "sagemaker.amazonaws.com" } } } ] }

使用 Amazon SageMaker Ground Truth 主控台所需的許可

若要使用 Amazon G SageMaker round Truth 主控台,您需要授予其他資源的許可。特別是主控台需要檢視訂閱的 AWS Marketplace 許可、管理您私有人力的 Amazon Cognito操作許可、存取您輸入和輸出檔案的 Amazon S3 動作許可,以及列出和呼叫函數的 AWS Lambda 動作許可。使用以下許可政策來授予這些許可:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GroundTruthConsole", "Effect": "Allow", "Action": [ "aws-marketplace:DescribeListings", "aws-marketplace:ViewSubscriptions", "cognito-idp:AdminAddUserToGroup", "cognito-idp:AdminCreateUser", "cognito-idp:AdminDeleteUser", "cognito-idp:AdminDisableUser", "cognito-idp:AdminEnableUser", "cognito-idp:AdminRemoveUserFromGroup", "cognito-idp:CreateGroup", "cognito-idp:CreateUserPool", "cognito-idp:CreateUserPoolClient", "cognito-idp:CreateUserPoolDomain", "cognito-idp:DescribeUserPool", "cognito-idp:DescribeUserPoolClient", "cognito-idp:ListGroups", "cognito-idp:ListIdentityProviders", "cognito-idp:ListUsers", "cognito-idp:ListUsersInGroup", "cognito-idp:ListUserPoolClients", "cognito-idp:ListUserPools", "cognito-idp:UpdateUserPool", "cognito-idp:UpdateUserPoolClient", "groundtruthlabeling:DescribeConsoleJob", "groundtruthlabeling:ListDatasetObjects", "groundtruthlabeling:RunFilterOrSampleManifestJob", "groundtruthlabeling:RunGenerateManifestByCrawlingJob", "lambda:InvokeFunction", "lambda:ListFunctions", "s3:GetObject", "s3:PutObject", "s3:SelectObjectContent" ], "Resource": "*" } ] }

使用 Amazon 擴增 AI(預覽版)主控台所需的權限

若要使用擴增 AI 主控台,您需要授予其他資源的許可。使用以下許可政策來授予這些許可:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "sagemaker:*Algorithm", "sagemaker:*Algorithms", "sagemaker:*App", "sagemaker:*Apps", "sagemaker:*AutoMLJob", "sagemaker:*AutoMLJobs", "sagemaker:*CodeRepositories", "sagemaker:*CodeRepository", "sagemaker:*CompilationJob", "sagemaker:*CompilationJobs", "sagemaker:*Endpoint", "sagemaker:*EndpointConfig", "sagemaker:*EndpointConfigs", "sagemaker:*EndpointWeightsAndCapacities", "sagemaker:*Endpoints", "sagemaker:*Environment", "sagemaker:*EnvironmentVersion", "sagemaker:*EnvironmentVersions", "sagemaker:*Environments", "sagemaker:*Experiment", "sagemaker:*Experiments", "sagemaker:*FlowDefinitions", "sagemaker:*HumanLoop", "sagemaker:*HumanLoops", "sagemaker:*HumanTaskUi", "sagemaker:*HumanTaskUis", "sagemaker:*HyperParameterTuningJob", "sagemaker:*HyperParameterTuningJobs", "sagemaker:*LabelingJob", "sagemaker:*LabelingJobs", "sagemaker:*Metrics", "sagemaker:*Model", "sagemaker:*ModelPackage", "sagemaker:*ModelPackages", "sagemaker:*Models", "sagemaker:*MonitoringExecutions", "sagemaker:*MonitoringSchedule", "sagemaker:*MonitoringSchedules", "sagemaker:*NotebookInstance", "sagemaker:*NotebookInstanceLifecycleConfig", "sagemaker:*NotebookInstanceLifecycleConfigs", "sagemaker:*NotebookInstanceUrl", "sagemaker:*NotebookInstances", "sagemaker:*ProcessingJob", "sagemaker:*ProcessingJobs", "sagemaker:*RenderUiTemplate", "sagemaker:*Search", "sagemaker:*SearchSuggestions", "sagemaker:*Tags", "sagemaker:*TrainingJob", "sagemaker:*TrainingJobs", "sagemaker:*TransformJob", "sagemaker:*TransformJobs", "sagemaker:*Trial", "sagemaker:*TrialComponent", "sagemaker:*TrialComponents", "sagemaker:*Trials", "sagemaker:*Workteam", "sagemaker:*Workteams" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "sagemaker:*FlowDefinition" ], "Resource": "*", "Condition": { "StringEqualsIfExists": { "sagemaker:WorkteamType": [ "private-crowd", "vendor-crowd" ] } } }, { "Effect": "Allow", "Action": [ "application-autoscaling:DeleteScalingPolicy", "application-autoscaling:DeleteScheduledAction", "application-autoscaling:DeregisterScalableTarget", "application-autoscaling:DescribeScalableTargets", "application-autoscaling:DescribeScalingActivities", "application-autoscaling:DescribeScalingPolicies", "application-autoscaling:DescribeScheduledActions", "application-autoscaling:PutScalingPolicy", "application-autoscaling:PutScheduledAction", "application-autoscaling:RegisterScalableTarget", "aws-marketplace:ViewSubscriptions", "cloudwatch:DeleteAlarms", "cloudwatch:DescribeAlarms", "cloudwatch:GetMetricData", "cloudwatch:GetMetricStatistics", "cloudwatch:ListMetrics", "cloudwatch:PutMetricAlarm", "cloudwatch:PutMetricData", "codecommit:BatchGetRepositories", "codecommit:CreateRepository", "codecommit:GetRepository", "codecommit:ListBranches", "codecommit:ListRepositories", "cognito-idp:AdminAddUserToGroup", "cognito-idp:AdminCreateUser", "cognito-idp:AdminDeleteUser", "cognito-idp:AdminDisableUser", "cognito-idp:AdminEnableUser", "cognito-idp:AdminRemoveUserFromGroup", "cognito-idp:CreateGroup", "cognito-idp:CreateUserPool", "cognito-idp:CreateUserPoolClient", "cognito-idp:CreateUserPoolDomain", "cognito-idp:DescribeUserPool", "cognito-idp:DescribeUserPoolClient", "cognito-idp:ListGroups", "cognito-idp:ListIdentityProviders", "cognito-idp:ListUserPoolClients", "cognito-idp:ListUserPools", "cognito-idp:ListUsers", "cognito-idp:ListUsersInGroup", "cognito-idp:UpdateUserPool", "cognito-idp:UpdateUserPoolClient", "ec2:CreateNetworkInterface", "ec2:CreateNetworkInterfacePermission", "ec2:CreateVpcEndpoint", "ec2:DeleteNetworkInterface", "ec2:DeleteNetworkInterfacePermission", "ec2:DescribeDhcpOptions", "ec2:DescribeNetworkInterfaces", "ec2:DescribeRouteTables", "ec2:DescribeSecurityGroups", "ec2:DescribeSubnets", "ec2:DescribeVpcEndpoints", "ec2:DescribeVpcs", "ecr:BatchCheckLayerAvailability", "ecr:BatchGetImage", "ecr:CreateRepository", "ecr:Describe*", "ecr:GetAuthorizationToken", "ecr:GetDownloadUrlForLayer", "elastic-inference:Connect", "elasticfilesystem:DescribeFileSystems", "elasticfilesystem:DescribeMountTargets", "fsx:DescribeFileSystems", "glue:CreateJob", "glue:DeleteJob", "glue:GetJob", "glue:GetJobRun", "glue:GetJobRuns", "glue:GetJobs", "glue:ResetJobBookmark", "glue:StartJobRun", "glue:UpdateJob", "groundtruthlabeling:*", "iam:ListRoles", "kms:DescribeKey", "kms:ListAliases", "lambda:ListFunctions", "logs:CreateLogGroup", "logs:CreateLogStream", "logs:DescribeLogGroups", "logs:DescribeLogStreams", "logs:GetLogEvents", "logs:PutLogEvents", "sns:ListTopics" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "logs:CreateLogDelivery", "logs:DeleteLogDelivery", "logs:DescribeResourcePolicies", "logs:GetLogDelivery", "logs:ListLogDeliveries", "logs:PutResourcePolicy", "logs:UpdateLogDelivery" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "ecr:SetRepositoryPolicy", "ecr:CompleteLayerUpload", "ecr:BatchDeleteImage", "ecr:UploadLayerPart", "ecr:DeleteRepositoryPolicy", "ecr:InitiateLayerUpload", "ecr:DeleteRepository", "ecr:PutImage" ], "Resource": "arn:aws:ecr:*:*:repository/*sagemaker*" }, { "Effect": "Allow", "Action": [ "codecommit:GitPull", "codecommit:GitPush" ], "Resource": [ "arn:aws:codecommit:*:*:*sagemaker*", "arn:aws:codecommit:*:*:*SageMaker*", "arn:aws:codecommit:*:*:*Sagemaker*" ] }, { "Effect": "Allow", "Action": [ "secretsmanager:ListSecrets" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "secretsmanager:DescribeSecret", "secretsmanager:GetSecretValue", "secretsmanager:CreateSecret" ], "Resource": [ "arn:aws:secretsmanager:*:*:secret:AmazonSageMaker-*" ] }, { "Effect": "Allow", "Action": [ "secretsmanager:DescribeSecret", "secretsmanager:GetSecretValue" ], "Resource": "*", "Condition": { "StringEquals": { "secretsmanager:ResourceTag/SageMaker": "true" } } }, { "Effect": "Allow", "Action": [ "robomaker:CreateSimulationApplication", "robomaker:DescribeSimulationApplication", "robomaker:DeleteSimulationApplication" ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "robomaker:CreateSimulationJob", "robomaker:DescribeSimulationJob", "robomaker:CancelSimulationJob" ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:AbortMultipartUpload", "s3:GetBucketCors", "s3:PutBucketCors" ], "Resource": [ "arn:aws:s3:::*SageMaker*", "arn:aws:s3:::*Sagemaker*", "arn:aws:s3:::*sagemaker*", "arn:aws:s3:::*aws-glue*" ] }, { "Effect": "Allow", "Action": [ "s3:CreateBucket", "s3:GetBucketLocation", "s3:ListBucket", "s3:ListAllMyBuckets" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": "*", "Condition": { "StringEqualsIgnoreCase": { "s3:ExistingObjectTag/SageMaker": "true" } } }, { "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], "Resource": [ "arn:aws:lambda:*:*:function:*SageMaker*", "arn:aws:lambda:*:*:function:*sagemaker*", "arn:aws:lambda:*:*:function:*Sagemaker*", "arn:aws:lambda:*:*:function:*LabelingFunction*" ] }, { "Action": "iam:CreateServiceLinkedRole", "Effect": "Allow", "Resource": "arn:aws:iam::*:role/aws-service-role/sagemaker.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_SageMakerEndpoint", "Condition": { "StringLike": { "iam:AWSServiceName": "sagemaker.application-autoscaling.amazonaws.com" } } }, { "Effect": "Allow", "Action": "iam:CreateServiceLinkedRole", "Resource": "*", "Condition": { "StringEquals": { "iam:AWSServiceName": "robomaker.amazonaws.com" } } }, { "Effect": "Allow", "Action": [ "sns:Subscribe", "sns:CreateTopic" ], "Resource": [ "arn:aws:sns:*:*:*SageMaker*", "arn:aws:sns:*:*:*Sagemaker*", "arn:aws:sns:*:*:*sagemaker*" ] }, { "Effect": "Allow", "Action": [ "iam:PassRole" ], "Resource": "arn:aws:iam::*:role/*", "Condition": { "StringEquals": { "iam:PassedToService": [ "sagemaker.amazonaws.com", "glue.amazonaws.com", "robomaker.amazonaws.com", "states.amazonaws.com" ] } } } ] }

允許使用者檢視自己的許可

此範例會示範如何建立政策,允許 IAM 使用者檢視附加到他們使用者身分的內嵌及受管政策。此政策包含在主控台上,或是使用 AWS CLI 或 AWS API 透過編寫程式的方式完成此動作的許可。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": ["arn:aws:iam::*:user/${aws:username}"] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] }

使用條件鍵控制 SageMaker 資源的建立

控制精細的存取權限,以允許使用 SageMaker特定條件金鑰建立 SageMaker 資源。如需有關在 IAM 政策中使用條件金鑰的相關資訊,請參閱 IAM 使用者指南中的 IAM JSON 政策元素:條件

IAM 使用者指南」的「條件金鑰」中列出了條件金鑰、相關 API 動作以及相關文件的連結。 SageMaker

下列範例顯示如何使用 SageMaker 條件鍵來控制存取。

使用檔案系統條件金鑰來控制 SageMaker 資源的存取

SageMaker 訓練為訓練演算法提供安全的基礎架構,但在某些情況下,您可能需要更深入的防禦能力。例如,您可以將在演算法中執行不受信任程式碼的風險降到最低,或者在組織中具有特定的安全性規定。對於這些案例,您可以在 IAM 政策的條件元素中使用服務特定的條件金鑰,將使用者範圍縮小到特定檔案系統、目錄、存取模式(讀寫、唯讀)和安全群組。

限制 IAM 使用者只能使用特定目錄和存取模式

下列原則將使用者限制為 EFS 檔案系統的/sagemaker/xgboost-dm/train/sagemaker/xgboost-dm/validation目錄 ro (唯讀) AccessMode:

注意

允許目錄時,訓練演算法也可以存取其所有子目錄。POSIX 權限會遭到忽略。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AccessToElasticFileSystem", "Effect": "Allow", "Action": [ "sagemaker:CreateTrainingJob", "sagemaker:CreateHyperParameterTuningJob" ], "Resource": "*", "Condition": { "StringEquals": { "sagemaker:FileSystemId": "fs-12345678", "sagemaker:FileSystemAccessMode": "ro", "sagemaker:FileSystemType": "EFS", "sagemaker:FileSystemDirectoryPath": "/sagemaker/xgboost-dm/train" } } }, { "Sid": "AccessToElasticFileSystemValidation", "Effect": "Allow", "Action": [ "sagemaker:CreateTrainingJob", "sagemaker:CreateHyperParameterTuningJob" ], "Resource": "*", "Condition": { "StringEquals": { "sagemaker:FileSystemId": "fs-12345678", "sagemaker:FileSystemAccessMode": "ro", "sagemaker:FileSystemType": "EFS", "sagemaker:FileSystemDirectoryPath": "/sagemaker/xgboost-dm/validation" } } } ] }

限制使用者只能使用特定的檔案系統

若要防止惡意演算法利用使用者空間用戶端,直接以您的帳戶存取任何檔案系統,您可以透過允許來自特定安全群組的輸入來限制網路流量。在下列範例中, 使用者只能使用指定的安全群組來存取檔案系統:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AccessToLustreFileSystem", "Effect": "Allow", "Action": [ "sagemaker:CreateTrainingJob", "sagemaker:CreateHyperParameterTuningJob" ], "Resource": "*", "Condition": { "StringEquals": { "sagemaker:FileSystemId": "fs-12345678", "sagemaker:FileSystemAccessMode": "ro", "sagemaker:FileSystemType": "FSxLustre", "sagemaker:FileSystemDirectoryPath": "/fsx/sagemaker/xgboost/train" }, "ForAllValues:StringEquals": { "sagemaker:VpcSecurityGroupIds": [ "sg-12345678" ] } } } ] }

雖然上述範例可以限制演算法只能存取特定檔案系統,但是並不會阻止演算法利用使用者空間用戶端存取該檔案系統內的任何目錄。若要緩解此情況,您可以:

  • 確定檔案系統只包含您信任 使用者可以存取的資料

  • 建立 IAM 角色,限制您的使用者只能利用已核准的 ECR 儲存庫中的演算法啟動訓練任務

如需如何搭配使用角色的詳細資訊 SageMaker,請參閱SageMaker 角色

將訓練限制為特定 VPC

限制AWS使用者只能從 Amazon VPC 內建立訓練任務。在 VPC 內建立訓練任務時,您可以使用 VPC 流程日誌,來監控進出訓練叢集的所有流量。有關使用 VPC 流日誌的資訊,請參閱VPC 流日誌在《Amazon Virtual Private Cloud 使用者指南》

以下政策強制使用者從 VPC 內呼叫 CreateTrainingJob 來建立訓練任務:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowFromVpc", "Effect": "Allow", "Action": [ "sagemaker:CreateTrainingJob", "sagemaker:CreateHyperParameterTuningJob" ], "Resource": "*", "Condition": { "ForAllValues:StringEquals": { "sagemaker:VpcSubnets": ["subnet-a1234"], "sagemaker:VpcSecurityGroupIds": ["sg12345", "sg-67890"] }, "Null": { "sagemaker:VpcSubnets": "false", "sagemaker:VpcSecurityGroupIds": "false" } } } ] }

限制存取 Ground Truth 標籤任務和 Amazon A2I 人力審核工作流程的人力類型

Amazon SageMaker Ground Truth 和 Amazon Augmented AI 工作團隊屬於三種員工類型之一:公共(使用 Amazon Mechanical Turk),私人和廠商。若要使用其中一種類型或工作團隊 ARN 來將使用者存取權限制為某個特定的工作團隊,請使用 sagemaker:WorkteamType 和/或 sagemaker:WorkteamArn 條件索引鍵。若是 sagemaker:WorkteamType 條件金鑰,請使用字串條件運算子。若是 sagemaker:WorkteamArn 條件金鑰,請使用 Amazon Resource Name (ARN) 條件運算子。如果使用者嘗試建立具有受限工作團隊的標籤工作,則會 SageMaker 傳回拒絕存取錯誤。

下列政策示範如何透過不同方式將 sagemaker:WorkteamTypesagemaker:WorkteamArn 條件金鑰與適當的條件運算子及有效條件值搭配使用。

下列範例將 sagemaker:WorkteamType 條件金鑰與 StringEquals 條件運算子搭配使用,以限制對公有工作團隊的存取權。它可接受以下格式的條件值:workforcetype-crowd,其中 workforcetype 可以等於 publicprivatevendor

{ "Version": "2012-10-17", "Statement": [ { "Sid": "RestrictWorkteamType", "Effect": "Deny", "Action": "sagemaker:CreateLabelingJob", "Resource": "*", "Condition": { "StringEquals": { "sagemaker:WorkteamType": "public-crowd" } } } ] }

下列政策示範如何使用 sagemaker:WorkteamArn 條件金鑰來限制對公有工作團隊的存取權。第一個政策示範如何將其與工作團隊 ARN 的有效 IAM Regex 變體及ArnLike條件運算子搭配使用。第二個政策示範如何將其與 ArnEquals 條件運算子及工作團隊 ARN 搭配使用。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "RestrictWorkteamType", "Effect": "Deny", "Action": "sagemaker:CreateLabelingJob", "Resource": "*", "Condition": { "ArnLike": { "sagemaker:WorkteamArn": "arn:aws:sagemaker:*:*:workteam/public-crowd/*" } } } ] }
{ "Version": "2012-10-17", "Statement": [ { "Sid": "RestrictWorkteamType", "Effect": "Deny", "Action": "sagemaker:CreateLabelingJob", "Resource": "*", "Condition": { "ArnEquals": { "sagemaker:WorkteamArn": "arn:aws:sagemaker:us-west-2:394669845002:workteam/public-crowd/default" } } } ] }

強制加密輸入資料

下列政策限制使用者只能指定 AWS KMS 金鑰,以在建立訓練、超參數調校及標記任務時,使用 sagemaker:VolumeKmsKey 條件金鑰來加密輸入資料:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "EnforceEncryption", "Effect": "Allow", "Action": [ "sagemaker:CreateTrainingJob", "sagemaker:CreateHyperParameterTuningJob", "sagemaker:CreateLabelingJob", "sagemaker:CreateFlowDefiniton" ], "Resource": "*", "Condition": { "ArnEquals": { "sagemaker:VolumeKmsKey": "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" } } } ] }

強制加密筆記本執行個體儲存體磁碟區

下列政策限制使用者只能指定 AWS KMS 金鑰,以在建立或更新筆記本執行個體時,使用 sagemaker:VolumeKmsKey 條件金鑰來加密連接的儲存磁碟區:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "EnforceEncryption", "Effect": "Allow", "Action": [ "sagemaker:CreateNotebookInstance" ], "Resource": "*", "Condition": { "ArnLike": { "sagemaker:VolumeKmsKey": "*key/volume-kms-key-12345" } } } ] }

強制為訓練任務執行網路隔離

下列政策限制使用者在建立訓練任務時,只能使用 sagemaker:NetworkIsolation 條件金鑰來啟用網路隔離:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "EnforceIsolation", "Effect": "Allow", "Action": [ "sagemaker:CreateTrainingJob", "sagemaker:CreateHyperParameterTuningJob" ], "Resource": "*", "Condition": { "Bool": { "sagemaker:NetworkIsolation": "true" } } } ] }

強制為訓練任務執行特定執行個體類型

下列政策限制使用者在建立訓練任務時,只能使用 sagemaker:InstanceTypes 條件金鑰來使用特定的執行個體類型:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "EnforceInstanceType", "Effect": "Allow", "Action": [ "sagemaker:CreateTrainingJob", "sagemaker:CreateHyperParameterTuningJob" ], "Resource": "*", "Condition": { "ForAllValues:StringLike": { "sagemaker:InstanceTypes": ["ml.c5.*"] } } } ] }

強制為訓練任務執行特定 EI 加速器

下列政策會在建立或更新筆記本執行個體時,以及使用 sagemaker:AcceleratorTypes 條件金鑰建立端點組態時,限制使用者使用特定的 Elastic Inference (EI) 加速器:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "EnforceAcceleratorType", "Effect": "Allow", "Action": [ "sagemaker:CreateNotebookInstance", "sagemaker:UpdateNotebookInstance", "sagemaker:CreateEndpointConfig" ], "Resource": "*", "Condition": { "ForAllValues:StringEquals": { "sagemaker:AcceleratorTypes": ["ml.eia1.medium"] } } } ] }

強制停用網際網路存取和根存取以建立筆記本執行個體

您可以同時對筆記本執行個體停用網際網路存取和根存取,以協助讓它們更加安全。如需控制對筆記本執行個體的根存取的相關資訊,請參閱控制對 SageMaker 筆記本執行個體的根存取。如需對筆記本執行個體停用網際網路存取的相關資訊,請參閱將 VPC 中的筆記本執行個體連接外部資源

下列政策要求 使用者在建立執行個體時停用網路存取,以及在建立或更新筆記本執行個體時停用根存取。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "LockDownCreateNotebookInstance", "Effect": "Allow", "Action": [ "sagemaker:CreateNotebookInstance" ], "Resource": "*", "Condition": { "StringEquals": { "sagemaker:DirectInternetAccess": "Disabled", "sagemaker:RootAccess": "Disabled" }, "Null": { "sagemaker:VpcSubnets": "false", "sagemaker:VpcSecurityGroupIds": "false" } } }, { "Sid": "LockDownUpdateNotebookInstance", "Effect": "Allow", "Action": [ "sagemaker:UpdateNotebookInstance" ], "Resource": "*", "Condition": { "StringEquals": { "sagemaker:RootAccess": "Disabled" } } } ] }

使用以身分識別為基礎的原則控制 SageMaker API 的存取

若要控制對 SageMaker 託管端點的 SageMaker API 呼叫和呼叫的存取,請使用以身分識別為基礎的 IAM 政策。

限制對來自 VPC 內呼叫的 SageMaker API 和執行階段的存取

如果您在 VPC 中設定介面端點,則 VPC 以外的個人仍然可以透過網際網路連線到 SageMaker API 和執行階段,除非您附加 IAM 政策限制來自 VPC 內的所有使用者和群組可存取您的資源的呼叫。 SageMaker 如需針對 SageMaker API 和執行階段建立 VPC 介面端點的詳細資訊,請參閱Connect 到您的 VPC SageMaker 內部

重要

如果您套用類似下列其中一項的 IAM 政策,使用者將無法透過主控台存取指定的 SageMaker API。

若只要限制在您的 VPC 內建立的連線存取,請建立 AWS Identity and Access Management 政策,只限制來自您的 VPC 內呼叫的存取。然後將該原則新增至用於存取 SageMaker API 或執行階段的每個使用AWS Identity and Access Management者、群組或角色。

注意

此政策僅允許向建立介面端點之子網路中的呼叫者建立連線。

{ "Id": "api-example-1", "Version": "2012-10-17", "Statement": [ { "Sid": "EnableAPIAccess", "Effect": "Allow", "Action": [ "sagemaker:*" ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceVpc": "vpc-111bbaaa" } } } ] }

如果希望僅限使用介面端點建立的呼叫存取 API,請使用 aws:SourceVpce 條件金鑰,不要使用 aws:SourceVpc

{ "Id": "api-example-1", "Version": "2012-10-17", "Statement": [ { "Sid": "EnableAPIAccess", "Effect": "Allow", "Action": [ "sagemaker:CreatePresignedNotebookInstanceUrl" ], "Resource": "*", "Condition": { "StringEquals": { "aws:sourceVpce": [ "vpce-111bbccc", "vpce-111bbddd" ] } } } ] }

依 IP 位址限制 SageMaker API 和執行階段呼叫的存取

若要僅允許從您指定的清單中的 IP 位址存取 SageMaker API 呼叫和執行階段叫用,請附加拒絕存取 API 的 IAM 政策,除非呼叫來自清單中的 IP 位址,傳送給用於存取 API 或執行階段的每個使用AWS Identity and Access Management者、群組或角色。如需有關建立和編輯 IAM 政策的資訊,請參閱《使用者指南》AWS Identity and Access Management中的建立 IAM 政策。若要指定您想要其可以存取 API 呼叫的 IP 地址清單,請使用 IpAddress 條件運算子和 aws:SourceIP 條件內容金鑰。如需有關條件運算子的相關資訊,請參閱《使用者指南》AWS Identity and Access Management中的 IAM JSON 政策元素:條件運算子。如需 IAM 條件內容金鑰的資訊,請參閱 AWS 全域條件金鑰

例如,以下政策只允許從範圍 192.0.2.0-192.0.2.255203.0.113.0-203.0.113.255 的 IP 地址存取 CreateTrainingJob

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sagemaker:CreateTrainingJob", "Resource": "*", "Condition": { "IpAddress": { "aws:SourceIp": [ "192.0.2.0/24", "203.0.113.0/24" ] } } } ] }

依 IP 地址限制存取筆記本執行個體

若只允許從您指定清單中的 IP 地址存取筆記本執行個體,請將拒絕存取的 IAM 政策連接到 CreatePresignedNotebookInstanceUrl,除非呼叫來自用於存取筆記本執行個體之每個 AWS Identity and Access Management 使用者、群組或角色清單中的 IP 地址。如需有關建立和編輯 IAM 政策的資訊,請參閱《使用者指南》AWS Identity and Access Management中的建立 IAM 政策。若要指定您想要存取之筆記本執行個體的 IP 地址清單,請使用 IpAddress 條件運算子和 aws:SourceIP 條件內容金鑰。如需有關條件運算子的相關資訊,請參閱《使用者指南》AWS Identity and Access Management中的 IAM JSON 政策元素:條件運算子。如需 IAM 條件內容金鑰的資訊,請參閱 AWS 全域條件金鑰

例如,以下政策只允許從範圍在 192.0.2.0-192.0.2.255203.0.113.0-203.0.113.255 的 IP 地址存取筆記本執行個體:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sagemaker:CreatePresignedNotebookInstanceUrl", "Resource": "*", "Condition": { "IpAddress": { "aws:SourceIp": [ "192.0.2.0/24", "203.0.113.0/24" ] } } } ] }

此政策限制存取對 CreatePresignedNotebookInstanceUrl 的呼叫和該呼叫傳回的 URL。此原則也會限制在主控台中開啟筆記本執行個體的存取權,並針對每個嘗試連線至筆記本執行個體的 HTTP 要求和 WebSocket 框架強制執行。

注意

SageMaker 透過 VPC 介面端點連線時,使用此方法依 IP 位址篩選不相容。 。如需透過 VPC 介面端點連線時限制存取筆記本執行個體的資訊,請參閱透過 VPC 界面端點連線至筆記本執行個體

使用標籤控制對 SageMaker 資源的存取

在 IAM 政策中指定標籤,以控制對資 SageMaker 源群組的存取。使用標籤以進行屬性型存取控制 (ABAC) 使用標籤可協助您將資源的存取分割給特定使用者群組。您可以讓一個團隊存取一個資源群組,而另一個團隊可以存取另一組資源。您可以在 IAM 政策中提供ResourceTag條件,以便為每個群組提供存取權。

注意

以標籤為基礎的政策不會限制以下 API 呼叫:

  • DeleteImageVersion

  • DescribeImageVersion

  • ListAlgorithms

  • ListCodeRepositories

  • ListCompilationJobs

  • ListEndpointConfigs

  • ListEndpoints

  • ListFlowDefinitions

  • ListHumanTaskUis

  • ListHyperparameterTuningJobs

  • ListLabelingJobs

  • ListLabelingJobsForWorkteam

  • ListModelPackages

  • ListModels

  • ListNotebookInstanceLifecycleConfigs

  • ListNotebookInstances

  • ListSubscribedWorkteams

  • ListTags

  • ListProcessingJobs

  • ListTrainingJobs

  • ListTrainingJobsForHyperParameterTuningJob

  • ListTransformJobs

  • ListWorkteams

  • 搜尋

一個簡單的範例可以幫助您了解如何使用標籤來分區資源。假設您的 AWS 帳戶中已定義兩種不同的 IAM 群組,名為 DevTeam1DevTeam2。您也建立了 10 個筆記本執行個體。您正在為一個專案使用 5 個筆記本執行個體。您正在為第二個專案使用另外 5 個筆記本執行個體。您可以提供DevTeam1在第一個專案使用的筆記本執行個體上進行 API 呼叫的許可。您可以提供DevTeam2用於第二個專案的筆記本執行個體上進行 API 呼叫。

下列程序提供一個簡單的範例,可協助您了解新增標籤的概念。您可以使用它來實現前段中說明的解決方案。

控制對 API 呼叫的存取權(範例)
  1. 使用鍵 Project 和值 A 在用於第一個專案的筆記本執行個體新增標籤。如需將標籤新增至 SageMaker 資源的資訊,請參閱AddTags

  2. 使用鍵 Project 和值 B 在用於第二個專案的筆記本執行個體新增標籤。

  3. 建立具有 ResourceTag 條件的 IAM 政策,拒絕存取用於第二個專案的筆記本執行個體,並將該政策連接到 DevTeam1。以下是拒絕標籤為鍵 Project 和值 B 之任何筆記本執行個體中所有 API 呼叫的政策範例:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sagemaker:*", "Resource": "*" }, { "Effect": "Deny", "Action": "sagemaker:*", "Resource": "*", "Condition": { "StringEquals": { "sagemaker:ResourceTag/Project": "B" } } }, { "Effect": "Deny", "Action": [ "sagemaker:AddTags", "sagemaker:DeleteTags" ], "Resource": "*" } ] }

    有關建立 IAM 政策並將其附加到身分的資訊,請參閱《使用者指南》AWS Identity and Access Management中的 控制對使用政策的存取

  4. 建立具有 ResourceTag 條件的 IAM 政策,拒絕存取用於第一個專案的筆記本執行個體,並將該政策連接到 DevTeam2。以下是拒絕標籤為鍵 Project 和值 A 之任何筆記本執行個體中所有 API 呼叫的政策範例:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sagemaker:*", "Resource": "*" }, { "Effect": "Deny", "Action": "sagemaker:*", "Resource": "*", "Condition": { "StringEquals": { "sagemaker:ResourceTag/Project": "A" } } }, { "Effect": "Deny", "Action": [ "sagemaker:AddTags", "sagemaker:DeleteTags" ], "Resource": "*" } ] }

提供在建立資源時標記 SageMaker資源的權限

有許多 Amazon SageMaker 操作可讓您的使用者在建立資源時指定標籤。使用資源標籤來實作屬性型存取控制 (ABAC)。使用標籤可協助您將資源的存取分割給特定使用者群組。您可以讓一個團隊存取一個資源群組,而另一個團隊可以存取另一組資源。您可以在 IAM 政策中提供ResourceTag條件,以便為每個群組提供存取權。

您必須授予使用者存取他們用來建立資源的許可。對於需要建立處理程序的使用者,您必須在政策sagemaker:CreateProcessingJob中授予他們存取權。如果您的使用者正在標記他們建立的資源,您還必須授予標記許可。

重要

您只能授予使用者將標籤新增至他們建立的資源的許可。他們無法將標籤新增至已建立的資源。

以下是您無法為其提供資源以新增標籤的操作:

  • DeleteImageVersion

  • DescribeImageVersion

  • ListAlgorithms

  • ListCodeRepositories

  • ListCompilationJobs

  • ListEndpointConfigs

  • ListEndpoints

  • ListFlowDefinitions

  • ListHumanTaskUis

  • ListHyperparameterTuningJobs

  • ListLabelingJobs

  • ListLabelingJobsForWorkteam

  • ListModelPackages

  • ListModels

  • ListNotebookInstanceLifecycleConfigs

  • ListNotebookInstances

  • ListSubscribedWorkteams

  • ListTags

  • ListProcessingJobs

  • ListTrainingJobs

  • ListTrainingJobsForHyperParameterTuningJob

  • ListTransformJobs

  • ListWorkteams

  • 搜尋

您可以控制使用者可以標記的作業,或他們可以使用的標籤的存取權。您可以指定下列使用案例的許可:

  • 新增許可來標記使用任何操作建立的資源以及使用任何標籤的許可

  • 新增許可來標記使用特定操作和許可建立的資源以使用任何標籤

  • 將使用任何操作和許可建立的資源新增許可標記為特定標籤

  • 新增許可,將使用特定作業和許可建立的資源標記至特定標籤

Permissions for any operation and any tag

將下列陳述式新增至 IAM 政策,以授予使用者針對任何作業新增任何標籤的許可。

{ "Statement": [ { "Effect": "Allow", "Action": [ "sagemaker:Create*" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "sagemaker:AddTags" ], "Resource": "arn:aws:sagemaker:region:account:*/*", "Condition": { "Null": { "sagemaker:TaggingAction" : "false" } } } ] }
Permissions for a specific operation with specific tags

下列陳述式提供使用者許可,可將cc123標籤新增至使用CreateModel作業建立的資源。您可以修改陳述式以符合自己的需求,並將其新增至附加在使用者角色的 IAM 政策。

{ "Statement": [ { "Effect": "Allow", "Action": [ "sagemaker:CreateModel" ], "Resource": "*", "Condition": { "StringEquals": { "aws:RequestTag/cost-center": [ "cc123" ] }, "ForAnyValue:StringEquals": { "aws:TagKeys": [ "purpose" ] } } }, { "Effect": "Allow", "Action": [ "sagemaker:AddTags" ], "Resource": "arn:aws:sagemaker:region:account:*/*", "Condition": { "Null": { "sagemaker:TaggingAction" : "false" } } } ] }
Permissions for a specific operation and any tag

下列陳述式提供使用者許可,可將任何標籤新增至使用CreateModel作業建立的資源。

{ "Statement": [ { "Effect": "Allow", "Action": [ "sagemaker:CreateModel" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "sagemaker:AddTags" ], "Resource": "arn:aws:sagemaker:region:account:model/*", "Condition": { "String": { "sagemaker:TaggingAction" : [ "CreateModel" ] } } } ] }