brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jul 09. 2019

131.CloudTrail 이용하기

<1> 목적

시스템 로그를 저장한다.

저장한 로그를 모니터링한다.

저장한 로그를 문제의 원인을 찾는다.



<2>  CloudTrail 로 확인 가능한것

1. 모든 API 작업  로그로 기록 확인

2. 시스템 사용 이력을  확인

3. 로그를 S3에  저장하여 추후 감사



<3> 실습

CloudTrail 만들면서,  로그저장용 S3를 만들어 저장한다.

참고 : CloudTrail은 디폴트로  enable된다.


순서

1.  CloudTrail 생성

2.  S3 생성  : test6-bucket-kr

3. CloudTrail  Event history  확인

4. S3에서 CloudTrail log 확인



1. CloudTrail  생성 : test7-trail-kr



1) Create trail   

Storage location  :  Create New S3 bucket    >  Yes  >  test7-s3-kr   > create



CloudTral에서  New s3 Bucket을 생성하면  기본적으로  다음과 같은 Bucket Policy가 들어간다.



S3 > test7-s3-kr > Permissions > Bucket Policy


{

    "Version": "2012-10-17",

    "Statement": [

        {

            "Sid": "AWSCloudTrailAclCheck20150319",

            "Effect": "Allow",

            "Principal": {

                "Service": "cloudtrail.amazonaws.com"

            },

            "Action": "s3:GetBucketAcl",

            "Resource": "arn:aws:s3:::test7-s3-kr"

        },

        {

            "Sid": "AWSCloudTrailWrite20150319",

            "Effect": "Allow",

            "Principal": {

                "Service": "cloudtrail.amazonaws.com"

            },

            "Action": "s3:PutObject",

            "Resource": "arn:aws:s3:::test7-s3-kr/AWSLogs/605701001576/*",

            "Condition": {

                "StringEquals": {

                    "s3:x-amz-acl": "bucket-owner-full-control"

                }

            }

        }

    ]

}




3. CloudTrail  Event history  확인


각종 이벤트 확인이  가능하다.




4. S3에서 Cloud Trail log 확인


S3에서 필터링을 하지 않은 경우  모든 지역의 로그가 남는다.  

필터링이 필요하다.






5.  S3에  모든 지역의 로그가 남는다.   필터링이 필요하다.


- aws:RequestedRegion 로 제한이 가능하다.

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/ExamplePolicies_EC2.html


https://docs.aws.amazon.com/ko_kr/IAM/latest/UserGuide/reference_policies_condition-keys.html#AvailableKeys


{

    "Version": "2012-10-17",

    "Statement": [

        {

            "Sid": "AWSCloudTrailAclCheck20150319",

            "Effect": "Allow",

            "Principal": {

                "Service": "cloudtrail.amazonaws.com"

            },

            "Action": "s3:GetBucketAcl",

            "Resource": "arn:aws:s3:::test7-s3-kr",

"Condition": {

"StringEquals": {

"aws:RequestedRegion": "ap-northeast-1"

}

}

        },

        {

            "Sid": "AWSCloudTrailWrite20150319",

            "Effect": "Allow",

            "Principal": {

                "Service": "cloudtrail.amazonaws.com"

            },

            "Action": "s3:PutObject",

            "Resource": "arn:aws:s3:::test7-s3-kr/AWSLogs/605701001576/*",

            "Condition": {

                "StringEquals": {

                    "s3:x-amz-acl": "bucket-owner-full-control"

                }

            }

        }

    ]

}




6.  테스트 완료후  CloudTrail  삭제

CloudTrail  > Trails >  해당 CloudTrail 선택

오른쪽 위  휴지통이 삭제이다.



감사합니다.

매거진의 이전글 130.무료 Trusted Advisor,무료서비스5개
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari