Post

EKS에서 IRSA를 사용해야 하는 이유

EKS 환경에서 Pod 단위 IAM 권한 부여를 가능하게 하는 IRSA에 대해 정리

개념 설명:

Applications in a Pod’s containers can use an AWS SDK or the AWS CLI to make API requests to AWS services using AWS Identity and Access Management (IAM) permissions. Applications must sign their AWS API requests with AWS credentials. IAM roles for service accounts (IRSA) provide the ability to manage credentials for your applications, similar to the way that Amazon EC2 instance profiles provide credentials to Amazon EC2 instances. Instead of creating and distributing your AWS credentials to the containers or using the Amazon EC2 instance’s role, you associate an IAM role with a Kubernetes service account and configure your Pods to use the service account.
공식문서 - IRSA 소개
IRSA(IAM Roles for Service Accounts)는 EKS에서 Kubernetes의 ServiceAccount와 AWS IAM Role을 연결시켜, Pod 단위로 IAM 권한을 부여할 수 있게 하는 기능.
IRSA는 IAM OIDC 연동을 기반으로 하며, Pod가 실행 중인 컨테이너 안에서 IAM Role을 Assume할 수 있도록 AWS STS를 활용.

  • 비슷한 개념과 비교:
    • vs EC2 instance profile: 모든 Pod가 동일한 권한을 가짐
    • vs kube2iam, kiam (서드파티 도구): 복잡하고 관리 이슈가 있음
    • IRSA는 공식 지원되며 Kubernetes 네이티브 방식과 잘 통합됨
  • 사용이 적합한 환경:
    • 민감한 AWS 리소스를 접근하는 Pod (예: S3, DynamoDB, Secrets Manager)
    • 보안 강화가 필요한 멀티테넌시 환경
    • Least Privilege 권한 정책이 중요한 금융/보안/규제 환경
  • 사용 방법:

    1. OIDC 공급자 설정

    1
    
    eksctl utils associate-iam-oidc-provider     --region ap-northeast-2     --cluster enginrect-cluster     --approve
    

    2. IAM Role 생성 (Trust Policy 포함)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": {
            "Federated": "arn:aws:iam::xxxxxxxxxxxx:oidc-provider/oidc.eks.ap-northeast-2.amazonaws.com/id/{oidc-id}"
          },
          "Action": "sts:AssumeRoleWithWebIdentity",
          "Condition": {
            "StringEquals": {
              "oidc.eks.ap-northeast-2.amazonaws.com/id/{oidc-id}:sub": "system:serviceaccount:default:enginrect-sa"
            }
          }
        }
      ]
    }
    

    3. Kubernetes ServiceAccount 생성 및 IAM Role 연결

    1
    2
    3
    4
    5
    6
    7
    
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: enginrect-sa
      namespace: default
      annotations:
        eks.amazonaws.com/role-arn: arn:aws:iam::xxxxxxxxxxxx:role/enginrect-irsa-role
    

    4. Pod에 ServiceAccount 적용

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: s3-access-app
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: s3-access
      template:
        metadata:
          labels:
            app: s3-access
        spec:
          serviceAccountName: enginrect-sa
          ...
    

    위 구성으로 enginrect-sa를 사용하는 Pod는 enginrect-irsa-role을 통해 AWS 리소스에 접근할 수 있게 됩니다.

This post is licensed under CC BY 4.0 by the author.