# CircleCI를 통한 Panther 콘텐츠 관리

## 개요

CircleCI를 구성하여 소스 리포지토리에서 Panther 콘솔로 디텍션 파이프라인을 자동으로 테스트하고 업로드하도록 설정할 수 있습니다.

이 가이드는 다음을 설명합니다:

* 리포지토리가 CircleCI를 지원하도록 구성하는 방법.
* 리포지토리에 커밋한 디텍션 콘텐츠를 Panther 인스턴스로 자동으로 업로드하도록 CircleCI를 구성하는 방법.

참조 [Panther 콘텐츠용 CI/CD](https://docs.panther.com/ko/panther/detections-repo/ci-cd) Panther로 CI/CD 워크플로를 시작하는 방법에 대한 정보는

## CircleCI 설정

CircleCI를 사용하여 디텍션 콘텐츠를 Panther 인스턴스에 업로드하려면 리포지토리에 CircleCI 작업을 생성한 다음 Panther API 자격 증명을 위한 환경 변수를 구성합니다.

### 필수 조건

* Panther 콘솔에서 API 토큰을 생성하세요.
  * 참조 [API 토큰 생성에 대한 이러한 지침](https://docs.panther.com/ko/api#how-to-create-a-panther-api-token).
* 이미 CircleCI 계정이 없다면, [무료 계정을 생성하세요](https://circleci.com/signup).

### 1단계: 디텍션 리포지토리 설정

* Panther 디텍션 콘텐츠용 리포지토리가 아직 없다면 하나를 생성하세요. 권장되는 방법은 다음 중 하나입니다: [비공개로 클론](https://docs.panther.com/ko/panther/detections-repo/setup/deprecated/private-cloned-repo) 또는 [공개로 포크](https://docs.panther.com/ko/panther/detections-repo/setup/deprecated/public-fork) Panther의 [panther-analysis 리포지토리](https://github.com/panther-labs/panther-analysis).

### 2단계: 리포지토리에 CircleCI 작업 추가

CircleCI가 커밋한 디텍션 콘텐츠를 테스트하고 `main` 브랜치에 `panther-analysis` 리포지토리에서 업로드하려면 CircleCI 작업을 생성해야 합니다.

1. 명령줄에서 로컬 비공개 리포지토리의 루트로 이동하세요:\
   `cd path/to/your/repository`
2. CircleCI 구성용 새 디렉터리와 새 구성 파일을 생성하세요:

   `mkdir .circleci && touch .circleci/config.yml`
3. 다음 파일을 열기: `config.yml` 그리고 다음 내용을 붙여넣으세요:

   ```yaml
   version: 2.1
   jobs:
     upload:
       docker:
         - image: 'cimg/python:3.11'
       steps:
         - checkout
         - run:
             name: 가상 환경 설정 및 종속성 설치
             command: make venv
         - run:
             name: 단위 테스트 실행
             command: pipenv run panther_analysis_tool test
         - run:
             name: 디텍션 콘텐츠 업로드
             # (선택 사항) 아래 명령에 `--filter Enabled=true`를 추가하면 Enabled 된 디텍션만 업로드합니다
             command:  |
               PANTHER_API_HOST=$INTERNAL_API_HOST \
               PANTHER_API_TOKEN=$INTERNAL_API_TOKEN \
               pipenv run -- panther_analysis_tool upload
   workflows:
     panther:
       jobs:
         - upload:
             filters:
               branches:
                 only:
                   - main
   ```
4. 변경 사항을 추가하고 커밋한 다음 리포지토리에 푸시하세요:

   `git add . && git commit -m 'adding initial circleci configuration' && git push`

### 3단계: Panther API 자격 증명을 환경 변수로 추가

다음 환경 변수들이 `PANTHER_API_TOKEN` 및 `PANTHER_API_HOST` 정확한 인증을 위해 설정되어 있는지 확인하세요.

1. 다음에 로그인하세요: [CircleCI](https://circleci.com/vcs-authorize/) 그리고 프로젝트가 속한 조직을 선택하세요.
2. 왼쪽 내비게이션 메뉴에서 **Projects**.
3. 프로젝트 목록에서 해당 `panther-analysis` 리포지토리를 찾으세요. 프로젝트 오른쪽에서 **...** 그런 다음 **Project Settings**.

   <figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-abb4d67aacc8bcedb4e45fa91db69f536c072abf%2Fcircleci-project-settings%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1).jpeg?alt=media" alt="In the CircleCI console, the Projects screen is shown. The three dots icon has been selected on the panther-analysis project."><figcaption></figcaption></figure>
4. 왼쪽 내비게이션 메뉴에서 **Environment Variables**.
5. 클릭하세요 **Add Environment Variable**를 클릭하고 다음을 추가하세요 `INTERNAL_API_TOKEN` 및 `INTERNAL_API_HOST`.

   <figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-8d99839757052e9a5cba86334ecf84617fdad8c8%2Fimage.png?alt=media" alt="In the CircleCI console, the Project Settings screen is shown. There is a button to &#x22;Add Environment Variable&#x22;"><figcaption></figcaption></figure>

   * 자세한 내용은 CircleCI 문서의 [환경 변수 사용](https://circleci.com/docs/env-vars) 을 참조하세요.

다음도 확인하세요: [Panther Analysis 도구 명령](https://docs.panther.com/panther-developer-workflows/ci-cd/deployment-workflows/pat/pat-commands) Panther Analysis 도구에 대한 자세한 정보.
