안녕하세요 서후아빠입니다. ^_^
이번 세션은 Inspector를 구성하고, 검출 결과를 S3에 저장하는 실습을 해보겠습니다. EventBridge를 통한 SNS 및 CloudWatch 연동은 Amazon macie 구성과 동일한 부분으로 생략하였습니다.
구성도

| Inspector를 사용하기 위해서는 Inspector(or ssm) agent를 Instance에 설치해야 하며, Inspector(or ssm) agent는 기본적으로 Public으로 통신하기 때문에 Public 통신이 불가능한 Instance를 위해서 VPC endpoint를 생성해야 합니다. 만약 위 구성도처럼 VPC endpoint가 생성된 경우에는 pubA-ec2 or ecs-ec2-cluster도 VPC endpoint(ssm-ep-1~3)를 통해서 통신하게 됩니다. ECR 생성은 생략하였으나, 테스트를 원할 경우 ECR을 구성해 보시기 바랍니다. |
| ① IAM Role or SSM Run command를 이용하여 Inspector(or ssm) agent를 Instance에 설치합니다. ② Inspector v2를 활성화하면 자동으로 EC2 or ECR에 대해서 취약점 스캔을 진행합니다. ③ 탐지된 취약점(Findings)은 S3에 저장할 수 있으며, EventBridge or Security Hub로 연결하여 추가 작업할 수 있습니다. ※ Amazon macie 실습을 참조하시기 바랍니다. (https://sh-t.tistory.com/) |
사전 작업
인프라 생성 : vpc, subnet, igw, routing table, ec2 등은 설명 생략합니다.
2022.07.02 - [Networking] - [실습] Amazon VPC 구성요소 생성하기
[실습] Amazon VPC 구성요소 생성하기
안녕하세요 서후아빠입니다. ^_^ 이번 세션은 VPC 관련 구성요소에 대해서 실습을 해보겠습니다. 구성도 1단계 : VPC 생성 VPC > Your VPCs > Create VPC 구분 VPC settings (VPC Only 방식) VPC settings (VPC a..
sh-t.tistory.com
1단계 : IAM Role 수정
IAM > Roles > ecsInstanceRole or EC2에 적용된 Role > Permissions (tab) > Permissions policies의 Add permissions > Attach policies > AmazonSSMManagedInstanceCore > Attach policies
| EC2가 생성 시 자동으로 SSM agent를 설치하는 Role입니다. ECS-Optimized AMI or Amazon AMI는 기본적으로 SSM Agent가 설치되어 있습니다. |
2단계 : ECS, EC2 생성
EC2 생성에 대한 상세한 설명은 생략합니다. (단, 생성 시 1단계의 EC2 Role을 적용)
ECS 생성에 대한 상세한 설명은 아래 링크를 참조하시기 바랍니다.
[실습] ECS로 Container(EC2, Fargate) 생성하기(With ECR, EFS, SSM, CloudWacth, CodePipeline)
안녕하세요 서후아빠입니다. ^_^ 이번 세션은 AWS Container Platform의 대표 ECS에 대해서 연동 가능한 여러 서비스와 함께 실습을 해보겠습니다. Container에서 Parameter Store 사용하는 부분, Container간 연..
sh-t.tistory.com
| 위 링크에서 아래 사항을 적용하시기 바랍니다. - 5단계 : EC2 경우로 진행, 파라미터 스토어 및 EFS 연계는 생략할 것이므로 관련 설정은 생략합니다. - 7단계 : EC2 경우로 진행, Load balancer type은 None으로 진행하고, AutoScaling은 설정을 생략합니다. |
3단계 : VPC endpoint 생성
VPC > Endpoints > Create endpoint
| Endpoint settings | Services | VPC, Subnets, IP address type, Security groups | Policy |
| Name tag : ssm-ep-1 Service category : AWS services |
Service name : com.amazonaws.ap-northeast-2.ssm | VPC : vpcA Subnets : priA-sn-2 IP address type : IPv4 Security groups : Inbound 443 허용된 그룹 선택 |
Full access (or Custom) |
| Name tag : ssm-ep-2 Service category : AWS services |
Service name : com.amazonaws.ap-northeast-2.ssmmessages | VPC : vpcA Subnets : priA-sn-2 IP address type : IPv4 Security groups : Inbound 443 허용된 그룹 선택 |
Full access (or Custom) |
| Name tag : ssm-ep-3 Service category : AWS services |
Service name : com.amazonaws.ap-northeast-2.ec2messages | VPC : vpcA Subnets : priA-sn-2 IP address type : IPv4 Security groups : Inbound 443 허용된 그룹 선택 |
Full access (or Custom) |
| Region 주의하시고, 가용성 고려 시 Subnet을 2개 이상 선택하시기 바랍니다. VPC endpoint가 없는 경우 Inspector(or ssm) agent는 무조건 Public으로 통신하기 때문에 Private subnet의 Instance는 스캔 정보를 받을 수 없습니다. 또한 다음 단계에 설정된 Run Command를 통한 agent 설치도 불가능합니다. 덧붙여서 Inspector endpoint(com.amazonaws.ap-northeast-2.inspector2)만 생성하는 경우 Private subnet에 있는 EC2를 스캔할 수 없습니다. Inspector Classic은 Private에 설치한 EC2의 Scan을 실시하는 경우, 개별적으로 Inspector의 Service endpoint에 부착된 글로벌 IP 주소로의 통신/라우팅이 필요했습니다. |
4단계 : Inspector Agent 설치 (1~3단계 순서대로 진행한 경우는 SKIP)
AWS Systems Manager > Get Started with Systems Manager > Run Command > Run a Command
| Command document | Targets | Output options(옵션) | ||
| AmazonInspector-ManageAWSAgent | Targets : Choose instances manually Instances : pubA-ec2, priA-ec2 |
Write command output to an Amazon S3 bucket : Enable an S3 bucket S3 bucket name : mybucket S3 key prefix(옵션) : runcommand |
||
Targets and outputs의 Status “Success” 확인
| Output options은 기본적으로 활성화 되어 있습니다. 명령어 수행 결과를 S3 bucket에 저장하며, 폴더 구분을 위해서 prefix를 설정하는 것을 권고합니다. |
5단계 : Inspector 활성화 (Region별) 및 자동 Scan 결과 (Findings) 확인
Inspector > Get Started > View role permissions > Enable Inspector
Inspector > Account management > Instances (tab) > 3개의 인스턴스 Status “Scanning” 확인
| Inspector v2는 첫 활성화 시 15일 무료입니다. 1~4단계를 진행하지 않을 경우 Status “Unmanaged Ec2 instance” 상태로 나타날 수 있으며, 계속 "Scanning" 상태로 전환되지 않을 경우 https://docs.aws.amazon.com/ko_kr/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-troubleshoot-managed-instance.html 참조하시기 바랍니다. |
Inspector > Findings : 취약점별, 인스턴스별, 컨테이너 이미지별, 저장소별로 검출 결과 확인
별첨 : 탐지 결과 S3로 내보내기
탐지된 취약점에 대해서 S3로 저장할 수 있습니다.
Inspector > All findings > Export findings
| Add filter(옵션) | Export setting | ||
| Add filter : - (Active or suppressed or Closed or Show all) | Export file type : CSV (or JSON) S3 URL : s3://inspectorbucket/ KSM key : mykey |
||
별첨 : 불필요한 Findings를 Scan에서 제외
Inspector > Suppression rules > Create rule
| Suppression rule details |
| Name : 이름 Suppression rule filters : 항목 및 조건 입력 |
| Suppression rule filters 항목 - Common fields : Account ID, Created at, Finding ARN, Inspector score, Resource ID, Resource type, Severity, Title, Type, Updated at - EC2 : AM ID, Resource tag, Subnet ID, VPC ID - ECR : Architecture, Image ID, Image tag, Registry, Repository name - Network reachability : Network path component ID/type, Network path ingress destination address, Network path ingress source address, Open port, Protocol - Package vulnerability : Package, Related vulnerabilities, vulnerability ID Suppression rule filters 조건 : Equals, Not Equals, Starts with Suppression rules이 적용된 Findings는 Status가 “Suppressed”로 검출되며, Security Hub와 Findings 연계는 되지만, Event Bridge 통지되지 않습니다. |
별첨 : Etc
Inspector > Summary : 대상 수량(Instances, Repositories), 중요한 발견 수 (ECR container, EC2 instance, Network reachability), 상위 위험 패키지 등
Inspector > Account management : 내 계정과 AWS Organizations에 연동된 계정 관리 (Scanning Enable or Disable, Scan 상태 or 결과 확인)
Inspector > General : ECR re-scan 기간 설정(Lifetime, 180일, 30일), Permissions 확인, Inspector 중지
Inspector > Usage : 비용(계정 or 스캔) 확인
'Security' 카테고리의 다른 글
| [실습] EKS - Cluster에 대해서 kubectl 접근 허용 (0) | 2023.06.02 |
|---|---|
| [실습] AWS Security Hub 구성하기 (GuardDuty, Inspector, Macie, Config, Detective, EventBridge 등) (0) | 2022.09.01 |
| [실습] Amazon Macie 구성하기 (Security Hub, EventBridge, SNS, CloudWatch 구성) (0) | 2022.08.25 |
| [이론] Amazon Macie 기본 개념 (0) | 2022.08.24 |
| [실습] Amazon Detective 사용해보기 (0) | 2022.08.23 |