EC2 인스턴스의 IAM 역할 연결 점검

AWS API를 사용하는 EC2 워크로드에는 최소 권한 역할과 인스턴스 프로파일을 연결하세요.

설명

EC2 애플리케이션이 AWS API를 호출해야 한다면 IamInstanceProfile로 역할을 연결해 임시 자격 증명을 사용하세요. API 권한이 필요 없는 인스턴스에는 부여하지 않아도 됩니다.

잠재적 영향

필요한 자격 증명을 얻지 못하면 호출이 실패합니다. 서버에 장기 키를 저장하면 키가 유출됐을 때도 그 권한이 남습니다.

해결 방법

EC2를 신뢰하는 역할에 필요한 작업과 리소스만 허용하세요. 애플리케이션이 역할의 임시 자격 증명으로 필요한 API를 호출하는지 확인한 뒤 불필요한 장기 키를 폐기하고 삭제하세요.

예시

대상 리전의 승인된 AMI를 지정하고 AppRole을 정의하세요.

변경 전

yaml
Resources:
  AppServer:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t3.micro
      ImageId: ami-1234567890abcdef0

변경 후

yaml
Resources:
  AppServer:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t3.micro
      ImageId: ami-1234567890abcdef0
      IamInstanceProfile: !Ref AppInstanceProfile

  AppInstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Roles:
        - !Ref AppRole

두 번째 예시는 AppRole을 AppInstanceProfile에 넣고 이 프로파일을 AppServer에 연결합니다.

참조