

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

# 設定 IAM 許可以存取資料來源 (適用於管理員)
<a name="sagemaker-sql-extension-datasources-connection-permissions"></a>

管理員應確保 JupyterLab 應用程式使用的執行角色具有必要的 AWS IAM 許可，以透過設定的 AWS Glue 連線存取資料。
+ **管理員使用 建立的連線 AWS CLI**：若要檢視[管理員建立的](sagemaker-sql-extension-datasources-glue-connection.md) AWS Glue 連線並存取其資料，使用者需要讓管理員將特定許可連接到 Studio 中 JupyterLab 應用程式所使用的 SageMaker AI 執行角色。這包括對 AWS Glue的存取、Secrets Manager 和資料庫特定的許可。共用執行角色的所有應用程式都可以看到管理員建立的連線，因為此執行角色獲授予檢視特定 AWS Glue 目錄或資料庫的許可。若要了解每種資料來源類型的必要許可清單，請參閱[管理員定義的連線需要 IAM 許可](#admin-defined-connections-permissions)中管理員定義的連線許可。
+ **使用者在 JupyterLab 中使用 SQL 延伸模組 UI 建立的連線**：除非連線的可見性範圍縮小至使用者建立的連線，否則也會列出共用相同執行角色的[使用者設定檔建立的](sagemaker-sql-extension-datasources-glue-connection-user-defined.md)連線。使用者建立的連線會透過建立它們的使用者設定檔加以標記。若要限制僅建立連線的使用者才能檢視、更新或刪除這些使用者建立的連線，管理員可以將其他標籤型存取控制限制新增至執行角色 IAM 許可。若要了解所需的其他標籤型存取控制，請參閱[使用者定義的連線需要 IAM 許可](#user-defined-connections-permissions)。

## 管理員定義的連線需要 IAM 許可
<a name="admin-defined-connections-permissions"></a>

若要授予 Studio 中 JupyterLab 應用程式使用的 SageMaker AI 執行角色透過 AWS Glue 連線存取資料來源，請將下列內嵌政策連接至角色。

若要檢視每個資料來源或驗證方法的特定許可和政策詳細資訊，請選擇下面的相關連線類型。

**注意**  
建議您將政策的許可限制為僅必要的資源和動作。  
若要縮小政策範圍並授予最低權限存取，請將政策中的 `"Resource": ["*"]` 萬用字元取代為需要存取的確切資源的特定 ARN。如需如何控制資源存取的詳細資訊，請參閱[使用精細 ARN 許可微調 AWS 資源存取](#resource-access-control)。

### 所有連線類型
<a name="datasources-connection-permissions-all"></a>

**注意**  
我們強烈建議將此政策範圍縮小到僅限必要的動作和資源。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GetS3AndDataSourcesMetadata",
            "Effect": "Allow",
            "Action": [
                "glue:GetDatabases",
                "glue:GetSchema",
                "glue:GetTables",
                "s3:ListBucket",
                "s3:GetObject",
                "s3:GetBucketLocation",
                "glue:GetDatabase",
                "glue:GetTable",
                "glue:ListSchemas",
                "glue:GetPartitions"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket/*",
                "arn:aws:glue:us-east-1:111122223333:catalog",
    "arn:aws:glue:us-east-1:111122223333:connection/*"
            ]
        },
        {
            "Sid": "ExecuteQueries",
            "Effect": "Allow",
            "Action": [
                "athena:ListDataCatalogs",
                "athena:ListDatabases",
                "athena:ListTableMetadata",
                "athena:StartQueryExecution",
                "athena:GetQueryExecution",
                "athena:RunQuery",
                "athena:StartSession",
                "athena:GetQueryResults",
                "athena:ListWorkGroups",
                "s3:ListMultipartUploadParts",
                "s3:ListBucket",
                "s3:GetBucketLocation",
                "athena:GetDataCatalog",
                "s3:AbortMultipartUpload",
                "s3:GetObject",
                "s3:PutObject",
                "athena:GetWorkGroup"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket/*",
                "arn:aws:athena:us-east-1:111122223333:workgroup/workgroup-name"
            ]
        },
        {
            "Sid": "GetGlueConnections",
            "Effect": "Allow",
            "Action": [
                "glue:GetConnections",
                "glue:GetConnection"
            ],
            "Resource": [
                "arn:aws:glue:us-east-1:111122223333:catalog",
                "arn:aws:glue:us-east-1:111122223333:connection/*"
            ]
        },
        {
            "Sid": "GetSecrets",
            "Effect": "Allow",
            "Action": [
                "secretsmanager:GetSecretValue"
            ],
            "Resource": [
                "arn:aws:secretsmanager:us-east-1:111122223333:secret:secret-name"
            ]
        },
        {
            "Sid": "GetClusterCredentials",
            "Effect": "Allow",
            "Action": [
                "redshift:GetClusterCredentials"
            ],
            "Resource": [
                "arn:aws:redshift:us-east-1:111122223333:cluster:cluster-name"
            ]
        }
    ]
}
```

------

### Athena
<a name="datasources-connection-permissions-athena"></a>

**注意**  
我們強烈建議將此政策的範圍縮小到僅所需的資源。

如需詳細資訊，請參閱 [Athena 文件](https://docs.aws.amazon.com/athena/latest/ug/federated-query-iam-access.html)中的*範例 IAM 許可政策*。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GetS3AndDataSourcesMetadata",
            "Effect": "Allow",
            "Action": [
                "glue:GetDatabases",
                "glue:GetSchema",
                "glue:GetTables",
                "s3:ListBucket",
                "s3:GetObject",
                "s3:GetBucketLocation",
                "glue:GetDatabase",
                "glue:GetTable",
                "glue:ListSchemas",
                "glue:GetPartitions"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket/*",                
                "arn:aws:glue:us-east-2:111122223333:catalog",
                "arn:aws:glue:us-east-2:111122223333:connection/*"
            ]
        },
        {
            "Sid": "ExecuteAthenaQueries",
            "Effect": "Allow",
            "Action": [
                "athena:ListDataCatalogs",
                "athena:ListDatabases",
                "athena:ListTableMetadata",
                "athena:StartQueryExecution",
                "athena:GetQueryExecution",
                "athena:RunQuery",
                "athena:StartSession",
                "athena:GetQueryResults",
                "athena:ListWorkGroups",
                "s3:ListMultipartUploadParts",
                "s3:ListBucket",
                "s3:GetBucketLocation",
                "athena:GetDataCatalog",
                "s3:AbortMultipartUpload",
                "s3:GetObject",
                "s3:PutObject",
                "athena:GetWorkGroup"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket/*",
                "arn:aws:athena:us-east-2:111122223333:workgroup/workgroup-name"
            ]
        },
        {
            "Sid": "GetGlueConnections",
            "Effect": "Allow",
            "Action": [
                "glue:GetConnections",
                "glue:GetConnection"
            ],
            "Resource": [
                "arn:aws:glue:us-east-2:111122223333:catalog",
                "arn:aws:glue:us-east-2:111122223333:connection/*"
            ]
        },
        {
            "Sid": "GetSecrets",
            "Effect": "Allow",
            "Action": [                
                "secretsmanager:GetSecretValue"
            ],
            "Resource": [
                "arn:aws:secretsmanager:us-east-2:111122223333:secret:secret-name"       
            ]
        }
    ]
}
```

------

### Amazon Redshift 和 Amazon Redshift Serverless (使用者名稱和密碼驗證) / Snowflake
<a name="datasources-connection-permissions-snowflake-redshift-user-password"></a>

**注意**  
我們強烈建議將此政策的範圍縮小到僅所需的資源。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GetS3Metadata",
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetObject",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket/*"
            ]
        },
        {
            "Sid": "GetGlueConnections",
            "Effect": "Allow",
            "Action": [
                "glue:GetConnections",
                "glue:GetConnection"
            ],
            "Resource": [
                "arn:aws:glue:us-east-2:111122223333:catalog",
                "arn:aws:glue:us-east-2:111122223333:connection/*"
            ]
        },
        {
            "Sid": "GetSecrets",
            "Effect": "Allow",
            "Action": [                
                "secretsmanager:GetSecretValue"
            ],
            "Resource": [
                "arn:aws:secretsmanager:us-east-2:111122223333:secret:secret-name"            
            ]
        }
    ]
}
```

------

### Amazon Redshift (IAM 驗證)
<a name="datasources-connection-permissions-redshift-iam"></a>

**注意**  
我們強烈建議將此政策的範圍縮小到僅所需的資源。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GetS3Metadata",
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetObject",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket/*",
                "arn:aws:s3:::amzn-s3-demo-bucket/*"
            ]
        },
        {
            "Sid": "GetGlueConnections",
            "Effect": "Allow",
            "Action": [
                "glue:GetConnections",
                "glue:GetConnection"
            ],
            "Resource": [
                "arn:aws:glue:us-east-1:111122223333:catalog",
                "arn:aws:glue:us-east-1:111122223333:connection/*",
                "arn:aws:glue:us-east-1:111122223333:connection/connection-name"
            ]
        },
        {
            "Sid": "GetSecrets",
            "Effect": "Allow",
            "Action": [
                "secretsmanager:GetSecretValue"
            ],
            "Resource": [
                "arn:aws:secretsmanager:us-east-1:111122223333:secret:secret-name",
                "arn:aws:secretsmanager:us-east-1:111122223333:secret:secret-name-with-suffix"
            ]
        },
        {
            "Sid": "GetClusterCredentials",
            "Effect": "Allow",
            "Action": [
                "redshift:GetClusterCredentials"
            ],
            "Resource": [
                "arn:aws:redshift:us-east-1:111122223333:cluster:cluster-name",
                "arn:aws:redshift:us-east-1:111122223333:dbuser:cluster-name/db-user-name"
            ]
        }
    ]
}
```

------

### Amazon Redshift Serverless (IAM 驗證)
<a name="datasources-connection-permissions-redshift-serverless-iam"></a>

**注意**  
我們強烈建議將此政策的範圍縮小到僅所需的資源。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GetS3Metadata",
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetObject",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket/*"
            ]
        },
        {
            "Sid": "GetGlueConnections",
            "Effect": "Allow",
            "Action": [
                "glue:GetConnections",
                "glue:GetConnection"
            ],
            "Resource": [
                "arn:aws:glue:us-east-2:111122223333:catalog",
                "arn:aws:glue:us-east-2:111122223333:connection/*"
            ]
        },
        {
            "Sid": "GetSecrets",
            "Effect": "Allow",
            "Action": [                
                "secretsmanager:GetSecretValue"
            ],
            "Resource": [
                "arn:aws:secretsmanager:us-east-2:111122223333:secret:secret-name"         
            ]
        },
        {
            "Sid": "GetRedshiftServerlessCredentials",
            "Effect": "Allow",
            "Action": [
                "redshift-serverless:GetCredentials"
            ],
            "Resource": [
                "arn:aws:redshift-serverless:us-east-2:111122223333:namespace/namespace-id"           
            ]
        }
    ]
}
```

------

## 使用者定義的連線需要 IAM 許可
<a name="user-defined-connections-permissions"></a>

使用者的 IAM 政策許可可以考慮 AWS Glue 連線資源上是否存在`UserProfile`標籤。
+ **若要檢視 AWS Glue 連線**：
  + 使用者可以檢視沒有 `UserProfile` 標籤的所有連線 (由管理員建立)。
  + 使用者可以檢視其具有的 `UserProfile` 標籤含有與其使用者設定檔相同值的連線。
  + 使用者無法檢視其具有的 `UserProfile` 標籤含有與其使用者設定檔不同值的連線。
+ **若要更新或刪除 AWS Glue 連線**：
  + 使用者可以更新或刪除其具有的 `UserProfile` 標籤含有與其使用者設定檔相同值的連線。
  + 使用者無法更新或刪除其具有的 `UserProfile` 標籤含有與其使用者設定檔不同值的連線。
  + 使用者無法更新或刪除沒有 `UserProfile` 標籤的連線。

若要達成此目的，管理員必須授予使用者設定檔的 JupyterLab 應用程式所使用的執行角色，超出其現有[管理員定義連線許可](#admin-defined-connections-permissions)的額外許可。具體而言，除了存取管理員定義 AWS Glue 連線所需的許可之外，還必須授予以下兩個額外的 IAM 許可給使用者的執行角色：
+ 建立 AWS Glue 連線並將`UserProfile`標籤與使用者設定檔名稱的值建立關聯的許可。
+ 檢視、更新和刪除標籤`UserProfile`符合使用者設定檔名稱之 AWS Glue 連線的許可。

此許可會根據特定使用者設定檔標籤值，限制對 AWS Glue 連線的存取。使用您要設為目標之使用者的設定檔名稱更新 `UserProfile` 標籤值。

```
"Action": [
    "glue:GetConnection",
    "glue:GetConnections"    
],
"Resource": [
    "arn:aws:glue:region:account_id:connection/*"
],
"Condition": {
    "StringEqualsIfExists": {
        "aws:ResourceTag/UserProfile": "user_profile_name"
    }
}
```

此許可將建立、更新和刪除使用者所建立連線的能力限制為僅限具有指定 `UserProfile` 標籤值的使用者設定檔案所建立的連線。

```
"Action": [
    "glue:DeleteConnection",
    "glue:UpdateConnection",
    "glue:CreateConnection",
    "glue:TagResource"
],
"Resource": [
    "arn:aws:glue:region:account_id:connection/*"
],
"Condition": {
    "StringEquals": {
        "aws:ResourceTag/UserProfile": "user_profile"
    }
}
```

## 使用精細 ARN 許可微調 AWS 資源存取
<a name="resource-access-control"></a>

若要更精細地控制對 AWS 資源的存取，請將政策`"Resource": ["*"]`中的萬用字元資源取代為僅需要存取之資源的特定 Amazon Resource Name (ARNs)。使用確切 ARN 而非萬用字元可限制對預期資源的存取。
+ **使用特定的 Amazon S3 儲存貯體 ARN**

  例如，儲存貯體層級或物件層級操作的 ` "arn:aws:s3:::bucket-name/*"` 或 `"arn:aws:s3:::bucket-name"`。

  如需 Amazon S3 中所有資源類型的相關資訊，請參閱 [Amazon S3 定義的資源類型](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html#amazons3-resources-for-iam-policies)。
+ **使用特定 AWS Glue 資料庫 ARNs**

  例如 ` "arn:aws:glue:region:account-id:catalog"` 或 ` "arn:aws:glue:region:account-id:database/db-name"`。如需 中所有資源類型的資訊 AWS Glue，請參閱 [定義的資源類型 AWS Glue](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsglue.html#awsglue-resources-for-iam-policies)。
+ **使用特定的 Athena 工作群組 ARN**

  例如 `"arn:aws:athena:region:account-id:workgroup/workgroup-name"`。如需 Athena 中所有資源類型的相關資訊，請參閱 [Athena 定義的資源類型](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html#amazonathena-resources-for-iam-policies)。
+ **使用特定的 AWS Secrets Manager 秘密 ARNs**

  例如 `"arn:aws:secretsmanager:region:account-id:secret:secret-name"`。如需 AWS Secrets Manager 中所有資源類型的資訊，請參閱 [AWS Secrets Manager 定義的資源類型](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssecretsmanager.html#awssecretsmanager-resources-for-iam-policies)
+ **使用特定的 Amazon Redshift 叢集 ARN**

  例如 `"arn:aws:redshift:region:account-id:cluster:cluster-name"`。如需 Amazon Redshift 中所有資源類型的相關資訊，請參閱 [Amazon Redshift 定義的資源類型](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonredshift.html#amazonredshift-resources-for-iam-policies)。如需 Redshift Serverless 中所有資源類型的相關資訊，請參閱 [Redshift Serverless 定義的資源類型](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonredshiftserverless.html#amazonredshiftserverless-resources-for-iam-policies)。