페이지 트리

이 문서는  오픈소스인 Snyk를 연동하여 Bitbucket에서 빌드시 소스코드 보안 취약점을 파악하는 가이드를 공유하기 위해 작성되었다.




시작하기전에

Bitbucket Pipeline과 연동되는 Snyk에서 지원하는 언어는 아래와 같습니다. (Bitbucket Pipelines integration - Snyk User Docs)

  • JavaScript (npm)

  • .NET (NuGet)

  • PHP Composer

  • Ruby

  • Docker

개요

Snyk란 SW 개발 tool chain 에 연동하여 commit 이나 build, CI/CD 시 프로젝트의 의존성을 검사해서 보안 취약점이 있는 외부 open source 를 사용하는지 알려주는 보안 도구입니다.

Snyk는 설치형이 아닌 Cloud 기반의 SaaS 서비스를 제공한다는 특징이 있습니다.

연동하기

Step1) Bitbucket Cloud에서 Snyk 활성화

Repository 사이드 메뉴 > snyk 메뉴에서 Import this repository 선택

Step2) Personal App passwords 생성

  • Account : Read
  • Workspace membership : Read
  • Projects : Read
  • Repositories : Write
  • Pull requests : Write
  • Webhooks : Read and Write

Step3) API 토큰 발급

아래 url에서 click to show로 자신의 토큰 키 확인

Account general settings | Snyk

Step4) Bitbucket cloud repository에 토큰 설정

Repository 설정 > Repository variables에 전단계에서 확인한 Token값 설정

Step5) Snyk에서 Bitbucket Cloud 설정

Add Project > Bitbucket Cloud > 가져오려는 저장소 선택 후 Add selected repositories 선택

Step6) Bitbucket-pipelines.yml 파일 설정

Bitbucket yaml파일에 빌드마다 취약점 분석하게 설정(아래 Security scan 영역 참조)

필수옵션

  • SNYK_TOKEN: $SNYK_TOKEN
  • LANGUAGE: 'maven-3.6.3'

DONT_BREAK_BUILD true옵션은 취약점 발견후에도 빌드 성공으로 bypass. 기본옵션은 false.

# This is an example Starter pipeline configuration
# Use a skeleton to build, test and deploy using manual and parallel steps
# -----
# You can specify a custom docker image from Docker Hub as your build environment.

image: maven:3.8.3-jdk-11

clone:
  depth: full     # SonarCloud scanner needs the full history to assign issues properly
  
pipelines:
  default:
    - parallel:
      - step:
          name: 'Build'          
          script:
          - mvn -B install test org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
      - step:
          name: 'Security scan'
          script:
            - echo "Your security scan goes here..."
            - pipe: snyk/snyk-scan:0.4.6
              variables:
                SNYK_TOKEN: $SNYK_TOKEN
                LANGUAGE: 'maven-3.6.3'
                DONT_BREAK_BUILD: 'true'
    # The following deployment steps will be executed for each pipeline run. To configure your steps and conditionally deploy see https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/
    - step:
        name: 'Deployment to Staging'
        deployment: staging
        script:
          - echo "Your deployment to staging script goes here..."
    - step:
        name: 'Deployment to Production'
        deployment: production
        trigger: 'manual'
        script:
          - echo "Your deployment to production script goes here..."

실행결과

9개의 보안 취약점이 도출되어 빌드실패 시킴(DONT_BREAK_BUILD: 'false'일 경우)





참조

내용


  • 레이블 없음