# Fluentd를 통한 GCP Audit -> S3

{% hint style="warning" %}
사용을 고려하세요 [Fluent Bit](/ko/data-onboarding/data-pipeline-tools/fluent-bit-onboarding-guide.md) Panther로 로그를 전달할 때 Fluentd 대신 사용하세요. Fluent Bit은 Fluentd보다 설정이 더 쉽고 리소스 사용량이 적습니다.
{% endhint %}

## 목표 <a href="#objectives" id="objectives"></a>

이 레시피의 목표는 Google Cloud Project Audit Logs를 Panther로 스트리밍하는 것입니다. 많은 기업이 여러 클라우드 제공업체를 사용하며, 이 단계들을 통해 GCP 계정에서 발생하는 API 호출을 Panther로 수집할 수 있습니다.

우리는 GCP와 AWS 전반의 기본 구성 요소를 조합하여 이를 구현할 것입니다.

## 솔루션 개요 <a href="#solution-brief" id="solution-brief"></a>

대략적으로, 다음 흐름을 구현할 것입니다:

1. 감사 로그는 GCP에서 생성되어 PubSub로 라우팅됩니다
2. Fluentd가 PubSub를 폴링하여 S3 버킷으로 전달합니다
3. S3 버킷은 정규화, 디택션, 장기 저장을 위해 Panther에 온보딩됩니다

## 단계 <a href="#steps" id="steps"></a>

### 1단계: 새 Pub/Sub 생성 <a href="#step-1-create-a-new-pub-sub" id="step-1-create-a-new-pub-sub"></a>

<figure><img src="/files/4ef22eeeca8d971b2e10ee92a5bdc10a211803dc" alt="The image shows the Pub/Sub console from Google Cloud Platform"><figcaption></figcaption></figure>

1. GCP에서 Pub/Sub 콘솔을 엽니다
2. 새 Topic을 생성하고 Panther-Audit라고 이름을 지정합니다
   * ‘Add a default subscription’의 선택을 해제합니다
   * CREATE TOPIC을 선택합니다
3. Subscriptions > Create subscription을 클릭합니다
   * Subscription ID로 Panther-Audit를 입력합니다
   * Panther-Audit topic을 선택합니다
   * 다른 모든 옵션은 그대로 두거나, 필요한 경우 만료/보존 설정을 조정합니다(예상 지출/예산에 따라)
   * CREATE를 클릭합니다

\
Topic 이름(projects/\<project-name>/topics/Panther-Audit)과 Topic subscription(Panther-Audit)을 적어 둡니다. 나중에 사용할 것입니다.

### 2단계: Logs Router 생성 <a href="#step-2-create-a-logs-router" id="step-2-create-a-logs-router"></a>

<figure><img src="/files/f7123fddb024199f2f3960e21a537d475a48ad27" alt="The image shows the Logs Explorer page from Google Cloud Platform"><figcaption></figcaption></figure>

참고: 프로젝트 sink 대신 집계된 조직 로그 sink를 선택적으로 생성할 수 있습니다. 집계된 sink 생성에 대해 자세히 알아보려면 다음을 참조하세요. [Google의 문서](https://cloud.google.com/logging/docs/export/aggregated_sinks#gcloud).

1. Logging 콘솔을 엽니다
2. Logs Router를 클릭합니다
3. CREATE SINK를 클릭합니다
4. 이름을 Panther-Audit로 설정합니다
5. Sink Destination을 설정합니다
   * Cloud Pub/Sub topic
   * Panther-Audit Topic을 선택합니다
6. CREATE SINK를 클릭합니다

Pub/Sub로 이동해 Panther-Audit의 Topic ID를 클릭한 다음 ACTIVITY를 확인하여 Audit 이벤트를 볼 수 있으면 이 파이프라인이 작동 중인지 검증할 수 있습니다.

<figure><img src="/files/c5b66af1eadc39bc44fb71391818985850e153a9" alt="The image shows Google Cloud Platform&#x27;s Pub/Sub console. In the left sidebar, &#x22;Topics&#x22; is highlighted. The &#x22;Panther-audit&#x22; topic is selected."><figcaption></figcaption></figure>

### 3단계: 서비스 계정 생성 <a href="#hardbreak-step-3-create-a-service-account" id="hardbreak-step-3-create-a-service-account"></a>

1. IAM & Admin을 엽니다
2. Service Accounts를 클릭합니다
3. CREATE SERVICE ACCOUNT를 클릭합니다
   * 서비스 계정 이름을 Panther-Audit로 설정합니다. 원하시면 설명을 추가할 수 있습니다.
   * Create and Continue를 클릭합니다
   * 아래에서 **이 서비스 계정에 프로젝트 액세스 권한 부여**를 선택하고 서비스 계정 액세스 역할을 *Pub/Sub Viewer* 및 *Pub/Sub Subscriber*
   * Continue를 클릭합니다
   * Done을 클릭합니다
4. Service accounts -> Actions에서 Manage keys, ADD KEY, Create new key를 클릭하고 JSON을 선택한 다음 CREATE를 눌러 자격 증명을 다운로드합니다.
5. 이 자격 증명 파일은 안전하게 보관하세요! 곧 사용할 것입니다.

<figure><img src="/files/dc7244733971ce1cf3fa8fdeab6486c43fa0c14e" alt="The image shows the IAM &#x26; Admin console in Google Cloud Platform. In the left sidebar, &#x22;Service Accounts&#x22; is highlighted. The center of the page says &#x22;Service accounts for project &#x27;My First Project&#x27;&#x22;. In the list, the panther-audit project is selected. A 3-dots icon on the right is expanded to an open dropdown menu, and the option &#x22;Manage keys&#x22; is highlighted."><figcaption></figcaption></figure>

### 4단계: AWS 인프라 구성 <a href="#step-4-configure-aws-infrastructure" id="step-4-configure-aws-infrastructure"></a>

를 클릭할 수 있습니다.  [Fluentd 온보딩 가이드](/ko/data-onboarding/data-pipeline-tools/fluentd.md)및 배포를 검토합니다 **Firehose & S3** 스택.

### 5단계: AWS에서 인스턴스 시작 <a href="#step-5-launch-your-instance-in-aws" id="step-5-launch-your-instance-in-aws"></a>

1. AWS EC2 Console을 엽니다(위에서 스택을 시작한 것과 같은 리전) 그리고 Ubuntu 인스턴스를 시작합니다.
2. Launch Instance를 클릭합니다
   * 선택 **Ubuntu Server 20.04 LTS**
   * 선택 **t2.medium** (원하시면 더 강력한 인스턴스 유형을 사용해도 됩니다)
   * IAM Role 섹션에서 **InstanceProfileName** 의 값을 선택합니다. 4단계에서 복사한 값이며, 형식은 “\<stack-name>-FirehoseInstanceProfile-\<random-string>”입니다.
   * Add Storage를 클릭하고 64GiB 용량 드라이브를 추가합니다
   * 원하는 대로 Security Group, Key Pair 및 기타 설정을 구성합니다
3. Launch를 클릭합니다

### 6단계: Fluentd 설치 및 구성 <a href="#step-6-install-and-configure-fluentd" id="step-6-install-and-configure-fluentd"></a>

1. 키 페어를 ssh agent에 추가합니다
   * `ssh-add <path-to-keypair>`
2. 3단계에서 다운로드한 GCP 자격 증명을 인스턴스로 SCP로 복사합니다
   * `scp <path-to-gcp-cred-file> ubuntu@<public-ip>:/home/ubuntu/`
3. 새로 시작한 EC2 인스턴스에 SSH로 접속합니다
   * `ssh ubuntu@<public-ip>`
4. [Ubuntu용 Fluentd를 설치합니다](https://docs.fluentd.org/installation/install-by-deb)
   * Ubuntu Focal에 대한 지침을 따릅니다
5. 설치합니다 [공식](https://github.com/awslabs/aws-fluent-plugin-kinesis) AWS Kinesis 플러그인
   * `sudo td-agent-gem install fluent-plugin-kinesis`
6. GCP 플러그인을 설치합니다
   * `sudo td-agent-gem install fluent-plugin-gcloud-pubsub-custom`
7. 기본 fluentd 설정을 다음 위치에서 덮어씁니다 `/etc/td-agent/td-agent.conf`:

   ```
   <system>  
     log_level debug
   </system>

   <source>
     @type gcloud_pubsub
     tag gcp.audit
     project <YOUR-GCP-PROJECT-ID>
     key <PATH-TO-YOUR-KEYPAIR>
     topic <PANTHER-AUDIT-TOPIC-ID>
     subscription <PANTHER-AUDIT-SUBSCRIPTION-ID>
     max_messages 1000
     return_immediately true
     pull_interval 1
     pull_threads 2
     parse_error_action exception
     <parse>
       @type json
     </parse>
   </source>

   <match gcp.**>
     @type kinesis_firehose
     region <YOUR-FIREHOSE-REGION>
     delivery_stream_name <YOUR-FIREHOSE-NAME>

     <assume_role_credentials>
       duration_seconds 3600
       role_arn <YOUR-FIREHOSE-ROLE-ARN>
       role_session_name "#{Socket.gethostname}-panther-audit"
     </assume_role_credentials>
   </match>
   ```
8. 재시작 `td-agent`
   * `sudo systemctl restart td-agent`

### 7단계: Panther에 데이터 온보딩 <a href="#step-7-onboard-data-into-panther" id="step-7-onboard-data-into-panther"></a>

다음 이유로 [GCP audit logs](/ko/data-onboarding/supported-logs/gcp.md) 는 기본적으로 지원되므로, [S3 버킷을 데이터 전송 수단으로 구성](/ko/data-onboarding/data-transports/aws/s3.md) 하여 Panther를 통해 로그 수집을 시작할 수 있습니다.

## **문제 해결**

* 참고: CloudFormation 템플릿 내의 `IntervalInSeconds`및 `SizeInMBs` 매개변수 때문에 로그가 S3 버킷에 표시되기까지 약 5분이 걸릴 수 있습니다.
* 오류가 있는지 td-agent 로그를 모니터링합니다
  * `sudo tail -f /var/log/td-agent/td-agent.log`
* 더 자세한 로깅이 필요하면 다음을 실행합니다:
  * `td-agent -vv`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.panther.com/ko/data-onboarding/data-pipeline-tools/fluentd/gcp-audit-to-s3-via-fluentd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
