IAM 역할 및 AWS Secret을 생성합니다
AWS 자격 증명을 명시적으로 제공하는 대신 AWS IAM 역할로 인증하여 Kubernetes Pod를 구성하여 AWS 리소스에 액세스할 수 있습니다.
|
AWS IAM 역할을 사용하여 인증하려면 EKS를 사용하여 Kubernetes 클러스터를 구축해야 합니다. |
AWS Secrets Manager 암호를 생성합니다
Trident는 사용자를 위해 스토리지 관리를 위해 FSx 가상 서버에 대해 API를 발행하므로 이를 위해 자격 증명이 필요합니다. 이러한 자격 증명을 전달하는 안전한 방법은 AWS Secrets Manager 암호를 사용하는 것입니다. 따라서 아직 계정이 없는 경우 vsadmin 계정의 자격 증명이 포함된 AWS Secrets Manager 암호를 생성해야 합니다.
이 예에서는 Trident CSI 자격 증명을 저장하기 위한 AWS Secrets Manager 암호를 생성합니다.
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 ID 또는 IAM 역할 생성
Kubernetes 서비스 계정이 EKS Pod Identity를 사용하는 AWS Identity and Access Management(IAM) 역할 또는 서비스 계정 연결(IRSA)을 위한 IAM 역할을 맡도록 구성할 수 있습니다. 서비스 계정을 사용하도록 구성된 모든 Pod는 해당 역할에 액세스 권한이 있는 모든 AWS 서비스에 액세스할 수 있습니다.
Amazon EKS Pod Identity 연결은 Amazon EC2 인스턴스 프로필이 Amazon EC2 인스턴스에 자격 증명을 제공하는 방식과 유사하게 애플리케이션의 자격 증명을 관리하는 기능을 제공합니다.
EKS 클러스터에 Pod Identity 설치:
AWS 콘솔을 통해 또는 다음 AWS CLI 명령을 사용하여 Pod ID를 생성할 수 있습니다.
aws eks create-addon --cluster-name <EKS_CLUSTER_NAME> --addon-name eks-pod-identity-agent
자세한 내용은 다음을 참조하세요. "Amazon EKS Pod Identity Agent 설정" .
trust-relationship.json을 생성합니다:
EKS 서비스 주체가 Pod Identity에 대한 이 역할을 수행할 수 있도록 trust-relationship.json 파일을 생성하세요. 그런 다음 다음 신뢰 정책을 사용하여 역할을 생성하세요.
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
포드 ID 연결 생성:
IAM 역할과 Trident 서비스 계정(trident-controller) 간에 Pod ID 연결을 생성합니다.
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
AWS CLI 사용:
aws iam create-role --role-name AmazonEKS_FSxN_CSI_DriverRole \ --assume-role-policy-document file://trust-relationship.json
-
trust-relationship.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