Skip to main content
本繁體中文版使用機器翻譯,譯文僅供參考,若與英文版本牴觸,應以英文版本為準。

建立 IAM 角色和 AWS 密碼

貢獻者 netapp-aruldeepa netapp-mwallis

您可以將 Kubernetes Pod 設定為以 AWS IAM 角色進行驗證、而非提供明確的 AWS 認證、以存取 AWS 資源。

註 若要使用 AWS IAM 角色進行驗證、您必須使用 EKS 部署 Kubernetes 叢集。

建立 AWS Secrets Manager 密碼

由於 Trident 將針對 FSX Vserver 發行 API ,以便為您管理儲存設備,因此需要認證才能這麼做。傳遞這些認證的安全方法是透過 AWS Secrets Manager 密碼。因此,如果您還沒有,就必須建立 AWS Secrets Manager 密碼,其中包含 vsadmin 帳戶的認證。

此範例建立 AWS Secrets Manager 密碼來儲存 Trident CSI 認證:

aws secretsmanager create-secret --name trident-secret --description "Trident CSI credentials"\
  --secret-string "{\"username\":\"vsadmin\",\"password\":\"<svmpassword>\"}"

建立 IAM 原則

Trident 也需要 AWS 權限才能正確執行。因此,您需要建立一個原則,讓 Trident 擁有所需的權限。

下列範例使用 AWS CLI 建立 IAM 原則:

aws iam create-policy --policy-name AmazonFSxNCSIDriverPolicy --policy-document file://policy.json
  --description "This policy grants access to Trident CSI to FSxN and Secrets manager"
  • 政策 JSON 範例 * :

{
  "Statement": [
    {
      "Action": [
        "fsx:DescribeFileSystems",
        "fsx:DescribeVolumes",
        "fsx:CreateVolume",
        "fsx:RestoreVolumeFromSnapshot",
        "fsx:DescribeStorageVirtualMachines",
        "fsx:UntagResource",
        "fsx:UpdateVolume",
        "fsx:TagResource",
        "fsx:DeleteVolume"
      ],
      "Effect": "Allow",
      "Resource": "*"
    },
    {
      "Action": "secretsmanager:GetSecretValue",
      "Effect": "Allow",
      "Resource": "arn:aws:secretsmanager:<aws-region>:<aws-account-id>:secret:<aws-secret-manager-name>*"
    }
  ],
  "Version": "2012-10-17"
}

為服務帳戶關聯 (IRSA) 建立 Pod Identity 或 IAM 角色

您可以使用 EKS Pod Identity 設定 Kubernetes 服務帳戶,使其代入 AWS Identity and Access Management (IAM) 角色,或使用 IAM 角色進行服務帳戶關聯 (IRSA)。任何已配置為使用該服務帳戶的 Pod 都可以存取該角色有權存取的任何 AWS 服務。

Pod 身份

Amazon EKS Pod Identity 關聯提供了管理應用程式憑證的能力,類似於 Amazon EC2 執行個體設定檔向 Amazon EC2 執行個體提供憑證的方式。

在您的 EKS 叢集上安裝 Pod Identity

您可以透過 AWS 主控台或使用下列 AWS CLI 指令建立 Pod 身分:

aws eks create-addon --cluster-name <EKS_CLUSTER_NAME> --addon-name eks-pod-identity-agent

更多資訊請參閱"設定 Amazon EKS Pod Identity Agent"

創建 trust-relationship.json

建立 trust-relationship.json 文件,使 EKS 服務主體能夠承擔 Pod Identity 的此角色。然後建立一個具有以下信任策略的角色:

aws iam create-role \
  --role-name fsxn-csi-role --assume-role-policy-document file://trust-relationship.json \
  --description "fsxn csi pod identity role"

trust-relationship.json 文件

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "pods.eks.amazonaws.com"
      },
      "Action": [
        "sts:AssumeRole",
        "sts:TagSession"
      ]
    }
  ]
}

將角色策略附加到 IAM 角色

將上一個步驟中的角色策略附加到已建立的 IAM 角色:

aws iam attach-role-policy \
  --policy-arn arn:aws:iam::aws:111122223333:policy/fsxn-csi-policy \
  --role-name fsxn-csi-role

建立 pod 身分關聯

在 IAM 角色和 Trident 服務帳戶(trident-controller)之間建立 pod 身分關聯

aws eks create-pod-identity-association \
  --cluster-name <EKS_CLUSTER_NAME> \
  --role-arn arn:aws:iam::111122223333:role/fsxn-csi-role \
  --namespace trident --service-account trident-controller
服務帳戶關聯 (IRSA) 的 IAM 角色

使用 AWS CLI

aws iam create-role --role-name AmazonEKS_FSxN_CSI_DriverRole \
  --assume-role-policy-document file://trust-relationship.json
  • 信任關係 .json 檔案: *

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::<account_id>:oidc-provider/<oidc_provider>"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "<oidc_provider>:aud": "sts.amazonaws.com",
          "<oidc_provider>:sub": "system:serviceaccount:trident:trident-controller"
        }
      }
    }
  ]
}

更新檔案中的下列值 trust-relationship.json

  • * <account_id> * - 您的 AWS 帳戶 ID

  • * <oidc_provider> * - EKS 叢集的 OIDC 。您可以執行下列項目來取得 oidc_provider :

    aws eks describe-cluster --name my-cluster --query "cluster.identity.oidc.issuer"\
      --output text | sed -e "s/^https:\/\///"
  • 使用 IAM 原則附加 IAM 角色 * :

建立角色後,請使用以下命令將原則(在上述步驟中建立)附加至角色:

aws iam attach-role-policy --role-name my-role --policy-arn <IAM policy ARN>
  • 驗證 OICD 提供者是否已關聯 * :

確認您的 OIDC 供應商與您的叢集相關聯。您可以使用下列命令來驗證:

aws iam list-open-id-connect-providers | grep $oidc_id | cut -d "/" -f4

如果輸出為空,請使用下列命令將 IAM OIDC 與叢集建立關聯:

eksctl utils associate-iam-oidc-provider --cluster $cluster_name --approve

如果您使用 eksctl,請使用下列範例為 EKS 中的服務帳戶建立 IAM 角色:

eksctl create iamserviceaccount --name trident-controller --namespace trident \
  --cluster <my-cluster> --role-name AmazonEKS_FSxN_CSI_DriverRole --role-only \
  --attach-policy-arn <IAM-Policy ARN> --approve