AWS CloudFormation 템플릿을 사용하여 GuardDuty 조건부로 Amazon 활성화 - AWS 권장 가이드

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS CloudFormation 템플릿을 사용하여 GuardDuty 조건부로 Amazon 활성화

작성자: Ram Kandaswamy(AWS)

환경: 프로덕션

기술: 보안, 자격 증명, 규정 준수 DevOps, 운영

AWS 서비스: AWS CloudFormation, Amazon GuardDuty, AWS Lambda, AWS Identity and Access Management

요약

AWS CloudFormation 템플릿을 사용하여 Amazon Web Services(AWS) 계정 GuardDuty 에서 Amazon을 활성화할 수 있습니다. 기본적으로 GuardDuty 를 사용하여 CloudFormation 를 켜려고 할 때 가 이미 활성화된 경우 스택 배포가 실패합니다. 그러나 CloudFormation 템플릿의 조건을 사용하여 GuardDuty 가 이미 활성화되어 있는지 확인할 수 있습니다. 는 정적 값을 비교하는 조건의 사용을 CloudFormation 지원합니다. 동일한 템플릿 내에서 다른 리소스 속성의 출력을 사용하는 것은 지원하지 않습니다. 자세한 내용은 CloudFormation 사용 설명서의 조건을 참조하세요.

이 패턴에서는 AWS Lambda 함수가 지원하는 CloudFormation 사용자 지정 리소스를 사용하여 아직 활성화되지 않은 GuardDuty 경우 조건부로 활성화합니다. GuardDuty 이 활성화된 경우 스택은 상태를 캡처하여 스택의 출력 섹션에 기록합니다. GuardDuty 가 활성화되지 않은 경우 스택에서 활성화합니다.

사전 조건 및 제한 사항

사전 조건 

  • 활성 AWS 계정

  • CloudFormation 스택을 생성, 업데이트 및 삭제할 수 있는 권한이 있는 AWS Identity and Access Management(IAM) 역할

제한 사항

  • GuardDuty 가 AWS 계정 또는 리전에 대해 수동으로 비활성화된 경우 이 패턴은 해당 대상 계정 또는 리전 GuardDuty 에 대해 활성화되지 않습니다.

아키텍처

대상 기술 스택

패턴은 IaC(Infrastructure as Code) CloudFormation 를 사용합니다. Lambda 함수가 지원하는 CloudFormation 사용자 지정 리소스를 사용하여 동적 서비스 활성화 기능을 달성할 수 있습니다.

대상 아키텍처 

다음 상위 수준 아키텍처 다이어그램은 CloudFormation 템플릿을 배포 GuardDuty 하여 를 활성화하는 프로세스를 보여줍니다.

  1. CloudFormation 템플릿을 배포하여 CloudFormation 스택을 생성합니다.

  2. 스택은 IAM 역할과 Lambda 함수를 생성합니다.

  3. Lambda 함수가 IAM 역할을 수임합니다.

  4. 대상 AWS 계정에서 GuardDuty 가 아직 활성화되지 않은 경우 Lambda 함수가 이를 활성화합니다.

CloudFormation 템플릿을 배포 GuardDuty 하여 활성화하는 프로세스

자동화 및 규모 조정

이 AWS CloudFormation StackSet 기능을 사용하여 이 솔루션을 여러 AWS 계정 및 AWS 리전으로 확장할 수 있습니다. 자세한 내용은 CloudFormation 사용 설명서의 작업 AWS CloudFormation StackSets 단원을 참조하세요.

도구

  • AWS 명령줄 인터페이스(AWS CLI)는 명령줄 쉘의 명령을 통해 AWS 서비스와 상호 작용하는 데 도움이 되는 오픈 소스 도구입니다.

  • AWS CloudFormation 는 AWS 리소스를 설정하고, 리소스를 빠르고 일관되게 프로비저닝하고, AWS 계정 및 리전의 수명 주기 전반에 걸쳐 리소스를 관리할 수 있도록 지원합니다.

  • Amazon GuardDuty은 로그를 분석하고 처리하여 AWS 사용자 환경에서 예기치 않고 잠재적으로 승인되지 않은 활동을 식별하는 지속적인 보안 모니터링 서비스입니다.

  • AWS Identity and Access Management(IAM)는 AWS 리소스에 대한 액세스를 인증하고 사용할 수 있는 권한을 부여받은 사용자를 제어하여 리소스에 대한 액세스를 안전하게 관리하는 데 도움이 됩니다.

  • AWS Lambda는 서버를 프로비저닝하거나 관리할 필요 없이 코드를 실행하는 데 도움이 되는 컴퓨팅 서비스입니다. 필요할 때만 코드를 실행하며 자동으로 확장이 가능하므로 사용한 컴퓨팅 시간만큼만 비용을 지불합니다.

에픽

작업설명필요한 기술

CloudFormation 템플릿을 생성합니다.

  1. 추가 정보 섹션의 CloudFormation 템플릿에 코드를 복사합니다.

  2. 텍스트 편집기에 코드를 붙여넣습니다.

  3. 워크스테이션에서 파일을 sample.yaml로 저장합니다.

AWS DevOps

CloudFormation 스택을 생성합니다.

  1. 에 다음 명령을 AWS CLI입력합니다. 이렇게 하면 sample.yaml 파일을 사용하여 새 CloudFormation 스택이 생성됩니다. 자세한 내용은 CloudFormation 사용 설명서의 스택 생성을 참조하세요.

    aws cloudformation create-stack \ --stack-name guardduty-cf-stack \ --template-body file://sample.yaml
  2. 스택이 성공적으로 생성되었음을 CLI나타내는 다음 값이 AWS 에 나타나는지 확인합니다. 스택을 생성하는 데 필요한 시간은 다를 수 있습니다.

    "StackStatus": "CREATE_COMPLETE",
AWS DevOps

AWS 계정에 대해 활성화된 GuardDuty 를 확인합니다.

  1. AWS 관리 콘솔에 로그인하고 에서 GuardDuty 콘솔을 엽니다https://console.aws.amazon.com/guardduty/.

  2. GuardDuty 서비스가 활성화되어 있는지 확인합니다.

클라우드 관리자, AWS 관리자

추가 계정 또는 AWS 리전을 구성합니다.

사용 사례에 필요한 경우 AWS CloudFormation StackSet 기능을 사용하여 이 솔루션을 여러 AWS 계정 및 AWS 리전으로 확장합니다. 자세한 내용은 CloudFormation 사용 설명서의 작업 AWS CloudFormation StackSets 단원을 참조하세요.

클라우드 관리자, AWS 관리자

관련 리소스

참조

자습서 및 동영상

추가 정보

CloudFormation 템플릿

AWSTemplateFormatVersion: 2010-09-09 Resources: rLambdaLogGroup: Type: 'AWS::Logs::LogGroup' DeletionPolicy: Delete Properties: RetentionInDays: 7 LogGroupName: /aws/lambda/resource-checker rLambdaCheckerLambdaRole: Type: 'AWS::IAM::Role' Properties: RoleName: !Sub 'resource-checker-lambda-role-${AWS::Region}' AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: lambda.amazonaws.com Action: 'sts:AssumeRole' Path: / Policies: - PolicyName: !Sub 'resource-checker-lambda-policy-${AWS::Region}' PolicyDocument: Version: 2012-10-17 Statement: - Sid: CreateLogGroup Effect: Allow Action: - 'logs:CreateLogGroup' - 'logs:CreateLogStream' - 'logs:PutLogEvents' - 'iam:CreateServiceLinkedRole' - 'cloudformation:CreateStack' - 'cloudformation:DeleteStack' - 'cloudformation:Desc*' - 'guardduty:CreateDetector' - 'guardduty:ListDetectors' - 'guardduty:DeleteDetector' Resource: '*' resourceCheckerLambda: Type: 'AWS::Lambda::Function' Properties: Description: Checks for resource type enabled and possibly name to exist FunctionName: resource-checker Handler: index.lambda_handler Role: !GetAtt - rLambdaCheckerLambdaRole - Arn Runtime: python3.8 MemorySize: 128 Timeout: 180 Code: ZipFile: | import boto3 import os import json from botocore.exceptions import ClientError import cfnresponse guardduty=boto3.client('guardduty') cfn=boto3.client('cloudformation') def lambda_handler(event, context): print('Event: ', event) if 'RequestType' in event: if event['RequestType'] in ["Create","Update"]: enabled=False try: response=guardduty.list_detectors() if "DetectorIds" in response and len(response["DetectorIds"])>0: enabled="AlreadyEnabled" elif "DetectorIds" in response and len(response["DetectorIds"])==0: cfn_response=cfn.create_stack( StackName='guardduty-cfn-stack', TemplateBody='{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "A sample template", "Resources": { "IRWorkshopGuardDutyDetector": { "Type": "AWS::GuardDuty::Detector", "Properties": { "Enable": true } } } }' ) enabled="True" except Exception as e: print("Exception: ",e) responseData = {} responseData['status'] = enabled cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData, "CustomResourcePhysicalID" ) elif event['RequestType'] == "Delete": cfn_response=cfn.delete_stack( StackName='guardduty-cfn-stack') cfnresponse.send(event, context, cfnresponse.SUCCESS, {}) CheckResourceExist: Type: 'Custom::LambdaCustomResource' Properties: ServiceToken: !GetAtt - resourceCheckerLambda - Arn Outputs: status: Value: !GetAtt - CheckResourceExist - status

Lambda 리소스의 대체 코드 옵션

제공된 CloudFormation 템플릿은 인라인 코드를 사용하여 Lambda 리소스를 참조하므로 더 쉽게 참조하고 안내할 수 있습니다. 또는 Lambda 코드를 Amazon Simple Storage Service(Amazon S3) 버킷에 넣고 CloudFormation 템플릿에서 참조할 수 있습니다. 인라인 코드는 패키지 종속성 또는 라이브러리를 지원하지 않습니다. S3 버킷에 Lambda 코드를 배치하고 CloudFormation 템플릿에서 참조하면 이를 지원할 수 있습니다.

아래의 코드 행을 바꿉니다.

Code: ZipFile: |

다음 코드 행 사용:

Code: S3Bucket: <bucket name> S3Key: <python file name> S3ObjectVersion: <version>

S3 버킷에서 버전 관리를 사용하지 않는 경우 S3ObjectVersion 속성을 생략할 수 있습니다. 자세한 내용은 Amazon S3 사용 설명서의 S3 버킷에서 버전 관리 사용을 참조하세요.