개요
로컬에서 개발을 하다보면 서버, GitHub
, AWS
등의 비밀 키(Secrets)
나 Credentials
을 사용하게 됩니다. 이때, 실수로 이 Secrets
나 Credentials
를 커밋(Commit)하게 되면 보안에 매우 취약해지게 됩니다.
이번 블로그 포스트에서는 GitHub Actions
또는 GitLab CI
에서 Trufflehog
을 실행하여 커밋(Commit)에 Secrets
나 Credentials
가 포함되었는지 확인하는 방법에 대해서 알아보도록 하겠습니다.
TruffleHog
TruffleHog
는 700
개 이상의 Secrets / Credentials
검사기를 통해 코드에 Secrets / Credentials
가 포함되어 있는지 확인하는 도구입니다.
TruffleHog 설치
TruffleHog
는 다음과 같이 다양한 방법으로 설치할 수 있습니다.
# 1. MacOS users
brew install trufflesecurity/trufflehog/trufflehog
# 2. Docker
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys
# 3. Docker for M1 and M2 Mac
docker run --platform linux/arm64 --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys
# 4. Binary releases
Download and unpack from https://github.com/trufflesecurity/trufflehog/releases
# 5. Compile from source
git clone https://github.com/trufflesecurity/trufflehog.git
cd trufflehog; go install
TruffleHog 실행
TruffleHog
는 다음과 같이 다양한 방법으로 실행할 수 있습니다.
# 1. Scan a repo for only verified secrets
trufflehog git https://github.com/trufflesecurity/test_keys --only-verified
# 2. Scan a GitHub Org for only verified secrets
trufflehog github --org=trufflesecurity --only-verified
# 3. Scan a GitHub Repo for only verified keys and get JSON output
trufflehog git https://github.com/trufflesecurity/test_keys --only-verified --json
# 4. Scan an S3 bucket for verified keys
trufflehog s3 --bucket=<bucket name> --only-verified
# 5. Scan a Github Repo using SSH authentication in docker
docker run --rm -v "$HOME/.ssh:/root/.ssh:ro" trufflesecurity/trufflehog:latest git ssh://github.com/trufflesecurity/test_keys
# 6. Scan individual files or directories
trufflehog filesystem path/to/file1.txt path/to/file2.txt path/to/dir
# 7. Scan GCS buckets for verified secrets.
trufflehog gcs --project-id=<project-ID> --cloud-environment --only-verified
GitHub Acionts
GitHub Actions
에서 Trufflehog
을 실행하여, 커밋(Commit)에 Secrets
나 Credentials
가 포함되었는지 확인할 수 있습니다. .github/workflows/scan_secrets.yml
파일을 생성하고 다음과 같이 수정합니다.
name: Scan secrets
on:
pull_request:
branches:
- main
jobs:
ScanSecrets:
name: Scan secrets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Scan secrets
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.repository.default_branch }}
extra_args: --only-verified
이렇게 GitHub Actions
를 생성하면, Pull Request
를 생성할 때마다 Trufflehog
을 실행하여 Secrets
나 Credentials
가 포함되었는지 확인할 수 있습니다.
GitLab CI
GitLab CI
에서 Trufflehog
을 실행하여, 커밋(Commit)에 Secrets
나 Credentials
가 포함되었는지 확인할 수 있습니다. .gitlab-ci.yml
파일을 생성하고 다음과 같이 수정합니다.
...
scan_secrets:
stage: scan
tags:
- docker
image: golang:latest
script:
- git clone https://github.com/trufflesecurity/trufflehog.git
- cd trufflehog; go install
- cd ..
- trufflehog git file://. --only-verified --fail --no-update --since-commit=main
only:
refs:
- merge_requests
...
이렇게 GitLab CI
를 생성하면, Pull Request
를 생성할 때마다 Trufflehog
을 실행하여 Secrets
나 Credentials
가 포함되었는지 확인할 수 있습니다.
완료
이것으로 Trufflehog
를 사용하여 커밋(Commit)에 Secrets
나 Credencials
이 포함되었는지 확인하는 방법에 대해서 알아보았습니다. 또한 GitHub Actions
나 GitLab CI
에서 Trufflehog
를 실행하는 방법에 대해서도 알아보았습니다.
여러분도 GitHub Actions
나 GitLab CI
에 Trufflehog
를 적용하여 커밋(Commit)에 Secrets
나 Credencials
이 포함되었는지 확인해 보시기 바랍니다.
제 블로그가 도움이 되셨나요? 하단의 댓글을 달아주시면 저에게 큰 힘이 됩니다!
앱 홍보
Deku
가 개발한 앱을 한번 사용해보세요.Deku
가 개발한 앱은 Flutter로 개발되었습니다.관심있으신 분들은 앱을 다운로드하여 사용해 주시면 정말 감사하겠습니다.