

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Pengaturan Peran IAM
<a name="spark-troubleshooting-agent-iam-setup"></a>

## Prasyarat
<a name="spark-troubleshooting-agent-iam-prerequisites"></a>

Sebelum Anda mulai, pastikan Anda memiliki:
+  AWS Akun dengan akses administratif IAM
+ AWS CLI diinstal dan dikonfigurasi. Untuk informasi selengkapnya, lihat [Menginstal AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html).

Atur variabel berikut untuk digunakan dalam perintah berikutnya:

```
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
REGION=$(aws configure get region)
```

## Langkah 1: Buat peran IAM
<a name="spark-troubleshooting-agent-iam-step1"></a>

Server SMUS MCP menggunakan peran IAM Anda untuk mengotorisasi operasi di tingkat layanan. AWS Tidak diperlukan MCP-specific izin terpisah.

**Untuk membuat peran IAM (AWS CLI)**

1. Buat dokumen kebijakan kepercayaan yang memungkinkan akun Anda untuk mengambil peran:

   ```
   cat > mcp-trust-policy.json << EOF
   {
     "Version": "2012-10-17",
     "Statement": [
       {
         "Sid": "AllowAccountToAssumeRole",
         "Effect": "Allow",
         "Principal": { "AWS": "arn:aws:iam::${ACCOUNT_ID}:root" },
         "Action": "sts:AssumeRole"
       }
     ]
   }
   EOF
   ```

1. Buat peran:

   ```
   aws iam create-role \
     --role-name SparkTroubleshootingMCPRole \
     --assume-role-policy-document file://mcp-trust-policy.json
   ```

## Langkah 2: Lampirkan izin untuk mode penyebaran Anda
<a name="spark-troubleshooting-agent-iam-step2"></a>

Lampirkan kebijakan izin yang cocok dengan platform penerapan Spark Anda. Anda dapat melampirkan satu atau beberapa hal berikut tergantung pada platform mana yang Anda gunakan.

### Opsi A: EMR pada EC2
<a name="spark-troubleshooting-agent-iam-emr-ec2"></a>

1. Buat dokumen kebijakan:

   ```
   cat > emr-ec2-policy.json << 'EOF'
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Sid": "EMREC2ReadAccess",
         "Effect": "Allow",
         "Action": [
           "elasticmapreduce:DescribeCluster",
           "elasticmapreduce:DescribeStep",
           "elasticmapreduce:ListSteps",
           "elasticmapreduce:ListClusters",
           "elasticmapreduce:DescribeJobFlows"
         ],
         "Resource": ["*"]
       },
       {
         "Sid": "EMRS3LogAccess",
         "Effect": "Allow",
         "Action": ["s3:GetObject", "s3:ListBucket"],
         "Resource": "*"
       },
       {
         "Sid": "EMRPersistentApp",
         "Effect": "Allow",
         "Action": [
           "elasticmapreduce:CreatePersistentAppUI",
           "elasticmapreduce:DescribePersistentAppUI",
           "elasticmapreduce:GetPersistentAppUIPresignedURL"
         ],
         "Resource": ["*"]
       }
     ]
   }
   EOF
   ```

1. Buat dan lampirkan kebijakan:

   ```
   aws iam put-role-policy \
     --role-name SparkTroubleshootingMCPRole \
     --policy-name EMREC2TroubleshootingAccess \
     --policy-document file://emr-ec2-policy.json
   ```

Atau, Anda dapat melampirkan kebijakan [AmazonElasticMapReduceFullAccess](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AmazonElasticMapReduceFullAccess.html) AWS terkelola jika peran Anda sudah menggunakannya:

```
aws iam attach-role-policy \
  --role-name SparkTroubleshootingMCPRole \
  --policy-arn arn:aws:iam::aws:policy/AmazonElasticMapReduceFullAccess
```

### Opsi B: AWS Glue
<a name="spark-troubleshooting-agent-iam-glue"></a>

1. Buat dokumen kebijakan:

   ```
   cat > glue-policy.json << EOF
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Sid": "GlueReadAccess",
         "Effect": "Allow",
         "Action": [
           "glue:GetJob",
           "glue:GetJobRun",
           "glue:GetJobRuns",
           "glue:GetJobs",
           "glue:BatchGetJobs"
         ],
         "Resource": ["arn:aws:glue:*:${ACCOUNT_ID}:job/*"]
       },
       {
         "Sid": "GlueCloudWatchLogsAccess",
         "Effect": "Allow",
         "Action": ["logs:GetLogEvents", "logs:FilterLogEvents"],
         "Resource": ["arn:aws:logs:*:${ACCOUNT_ID}:log-group:/aws-glue/*"]
       },
       {
         "Sid": "GlueSparkWebUI",
         "Effect": "Allow",
         "Action": [
           "glue:RequestLogParsing",
           "glue:GetLogParsingStatus",
           "glue:GetEnvironment",
           "glue:GetStage",
           "glue:GetStages",
           "glue:GetStageFiles",
           "glue:BatchGetStageFiles",
           "glue:GetStageAttempt",
           "glue:GetStageAttemptTaskList",
           "glue:GetStageAttemptTaskSummary",
           "glue:GetExecutors",
           "glue:GetExecutorsThreads",
           "glue:GetStorage",
           "glue:GetStorageUnit",
           "glue:GetQueries",
           "glue:GetQuery",
           "glue:GetDashboardUrl"
         ],
         "Resource": ["arn:aws:glue:*:${ACCOUNT_ID}:job/*"]
       },
       {
         "Sid": "GluePassRoleAccess",
         "Effect": "Allow",
         "Action": "iam:PassRole",
         "Resource": "*",
         "Condition": {
           "StringLike": {
             "iam:PassedToService": "glue.amazonaws.com"
           }
         }
       }
     ]
   }
   EOF
   ```

1. Lampirkan kebijakan:

   ```
   aws iam put-role-policy \
     --role-name SparkTroubleshootingMCPRole \
     --policy-name GlueTroubleshootingAccess \
     --policy-document file://glue-policy.json
   ```

### Opsi C: EMR Tanpa Server
<a name="spark-troubleshooting-agent-iam-emr-serverless"></a>

1. Buat dokumen kebijakan:

   ```
   cat > emr-serverless-policy.json << EOF
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Sid": "EMRServerlessReadAccess",
         "Effect": "Allow",
         "Action": [
           "emr-serverless:GetJobRun",
           "emr-serverless:GetApplication",
           "emr-serverless:ListApplications",
           "emr-serverless:ListJobRuns",
           "emr-serverless:ListJobRunAttempts",
           "emr-serverless:GetDashboardForJobRun",
           "emr-serverless:ListTagsForResource"
         ],
         "Resource": ["*"]
       },
       {
         "Sid": "EMRServerlessCloudWatchLogsAccess",
         "Effect": "Allow",
         "Action": ["logs:GetLogEvents", "logs:FilterLogEvents"],
         "Resource": ["arn:aws:logs:*:${ACCOUNT_ID}:log-group:/aws/emr-serverless/*"]
       },
       {
         "Sid": "EMRServerlessS3LogsAccess",
         "Effect": "Allow",
         "Action": ["s3:GetObject", "s3:ListBucket"],
         "Resource": "*"
       }
     ]
   }
   EOF
   ```

1. Lampirkan kebijakan:

   ```
   aws iam put-role-policy \
     --role-name SparkTroubleshootingMCPRole \
     --policy-name EMRServerlessTroubleshootingAccess \
     --policy-document file://emr-serverless-policy.json
   ```

### Opsi D: EMR di EKS
<a name="spark-troubleshooting-agent-iam-emr-eks"></a>

1. Buat dokumen kebijakan:

   ```
   cat > emr-eks-policy.json << EOF
   {
       "Version": "2012-10-17",
       "Statement": [
           {
               "Action": [
                   "emr-containers:DescribeVirtualCluster",
                   "emr-containers:DescribeJobRun",
                   "emr-containers:ListJobRuns",
                   "emr-containers:ListVirtualClusters"
               ],
               "Resource": "*",
               "Effect": "Allow",
               "Sid": "EMREKSReadAccess"
           },
           {
               "Action": [
                   "logs:GetLogEvents",
                   "logs:DescribeLogGroups",
                   "logs:DescribeLogStreams"
               ],
               "Resource": "*",
               "Effect": "Allow",
               "Sid": "EMRCloudWatchLogAccess"
           },
           {
               "Action": [
                   "elasticmapreduce:CreatePersistentAppUI",
                   "elasticmapreduce:DescribePersistentAppUI",
                   "elasticmapreduce:GetPersistentAppUIPresignedURL"
               ],
               "Resource": "*",
               "Effect": "Allow",
               "Sid": "EMRPersistentApp"
           },
           {
               "Action": [
                   "s3:GetObject",
                   "s3:ListBucket"
               ],
               "Resource": "*",
               "Effect": "Allow",
               "Sid": "EMREKSS3LogAccess"
           }
       ]
   }
   EOF
   ```

1. Lampirkan kebijakan:

   ```
   aws iam put-role-policy \
     --role-name SparkTroubleshootingMCPRole \
     --policy-name EMREKSTroubleshootingAccess \
     --policy-document file://emr-eks-policy.json
   ```

### Opsional: Izin KMS untuk Log terenkripsi CloudWatch
<a name="spark-troubleshooting-agent-iam-kms"></a>

Jika CloudWatch Log Anda dienkripsi dengan kunci KMS yang dikelola pelanggan, tambahkan yang berikut ini (ganti `<KEY_ID>` dengan ID kunci KMS Anda):

```
aws iam put-role-policy \
  --role-name SparkTroubleshootingMCPRole \
  --policy-name KMSCloudWatchLogsDecrypt \
  --policy-document "{
    \"Version\": \"2012-10-17\",
    \"Statement\": [{
      \"Effect\": \"Allow\",
      \"Action\": [\"kms:Decrypt\", \"kms:DescribeKey\"],
      \"Resource\": \"arn:aws:kms:${REGION}:${ACCOUNT_ID}:key/<KEY_ID>\"
    }]
  }"
```

## Langkah 3: Konfigurasikan klien MCP Anda
<a name="spark-troubleshooting-agent-iam-step3"></a>

Konfigurasikan klien MCP Anda (misalnya, Claude Desktop atau Amazon Q Developer) untuk menggunakan peran ARN yang Anda buat:

```
echo "arn:aws:iam::${ACCOUNT_ID}:role/SparkTroubleshootingMCPRole"
```

Lihat dokumentasi klien MCP Anda untuk mengetahui cara mengonfigurasi AWS kredensil (biasanya melalui AWS profil yang mengasumsikan peran ini).

## Kunci kondisi untuk permintaan server MCP
<a name="spark-troubleshooting-agent-mcp-permissions-change"></a>

Dua tombol kondisi secara otomatis ditambahkan ke semua permintaan yang dibuat melalui server SMUS MCP:
+ `aws:ViaAWSMCPService`— Setel ke `true` untuk setiap permintaan yang dibuat melalui server MCP AWS terkelola.
+ `aws:CalledViaAWSMCP`— Setel ke prinsipal layanan server MCP (misalnya,`sagemaker-unified-studio-mcp.amazonaws.com`).

Anda dapat menggunakan tombol kondisi ini untuk mengontrol akses ke sumber daya Anda saat permintaan berasal dari server MCP AWS terkelola.

**Contoh: Izinkan operasi baca Glue hanya ketika diakses melalui server SMUS MCP:**

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowGlueReadViaSMUSMCP",
      "Effect": "Allow",
      "Action": ["glue:GetJob", "glue:GetJobRun", "glue:GetJobRuns"],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "aws:CalledViaAWSMCP": "sagemaker-unified-studio-mcp.amazonaws.com"
        }
      }
    }
  ]
}
```

**Contoh: Tolak operasi penghapusan saat diakses melalui server MCP AWS terkelola:**

```
{
  "Effect": "Deny",
  "Action": ["s3:DeleteObject", "s3:DeleteBucket"],
  "Resource": "*",
  "Condition": {
    "Bool": {
      "aws:ViaAWSMCPService": "true"
    }
  }
}
```

Untuk informasi selengkapnya tentang kunci kondisi, lihat [kunci konteks kondisi AWS global](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html) di *Panduan Pengguna IAM*.