본문 바로가기
C.W.K.
Stream
Lesson 03 of 04 · published

Hook, signing, local gate

~20 min · hooks, signing

Level 0추적 전 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Hook과 signing은 의도를 실제 규칙으로 만들어

Git hook은 .git/hooks/의 script로 commit 전후, push 전, server receive 전 같은 lifecycle event에 실행돼. 팀에는 두 부류가 중요해. Client-side hook(pre-commit, commit-msg, pre-push)은 개발자 머신에서 formatting, lint, 금지 문자열, 기본 test 문제를 일찍 잡아. Server-side hook(pre-receive, update)은 서버에서 정책을 어긴 push를 거부해. 마지막 방어선이며 부주의한 contributor가 우회할 수 없는 쪽이야.

실용적인 client-side 도구로는 Python 도구인 pre-commit과 Node 생태계의 Husky가 있어. YAML이나 package.json에 hook을 선언하고 Prettier, Black 같은 formatter, ESLint, Ruff 같은 linter, console.log나 운영 코드의 TODO, secret scan 같은 맞춤 검사를 실행해. CI가 몇 분 뒤 알려주기 전에 고치기 가장 싼 시점에 문제를 드러내.

Commit signing은 두 번째 보강층이야. git commit -Scommit.gpgsign = true를 쓰면 Git이 GPG 또는 SSH key로 commit에 서명해. GitHub의 'Verified' badge는 서명이 author 계정에 등록된 key와 맞는지 확인해. 계정 password를 훔친 공격자도 signing key가 없다면 signed commit을 요구하는 branch 보호를 통과하지 못해. Git 2.34+의 SSH signing은 GPG보다 설정이 쉽고 push에 쓰는 SSH key를 활용할 수 있어.

git config --global commit.gpgsign true로 모든 commit을 서명하고, git config --global gpg.format ssh로 SSH 형식을 고른 뒤 git config --global user.signingkey ~/.ssh/id_ed25519.pub로 key를 지정해. Branch 보호의 'Require signed commits'는 서명 없는 push를 막아. Hook의 형식 및 내용 검사와 결합하면 팀 표준이 사람의 주의력 대신 도구에 새겨져.

Code

pre-commit framework — 선언적 hook·text
# .pre-commit-config.yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-merge-conflict
      - id: detect-private-key
      - id: check-added-large-files
        args: ['--maxkb=500']
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.6.9
    hooks:
      - id: ruff
        args: [--fix]
      - id: ruff-format
  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.41.0
    hooks:
      - id: markdownlint

# 설치:
# pip install pre-commit
# pre-commit install
SSH commit signing 세팅·bash
# git push 에 이미 쓰는 SSH key 사용:
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub

# Default 로 모든 commit 서명:
git config --global commit.gpgsign true
git config --global tag.gpgsign true

# 검증용으로 key 신뢰 (1회):
echo "$(git config user.email) $(cat ~/.ssh/id_ed25519.pub)" \
  > ~/.config/git/allowed_signers
git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers

# GitHub 에 signing key 알리기 (Settings → SSH and GPG keys → Signing key)

# 로컬에서 commit 서명 확인:
git log --show-signature -1

External links

Exercise

실제 프로젝트에 whitespace, secret 탐지, 언어에 맞는 linter로 구성한 최소 pre-commit을 설치해. pre-commit run --all-files를 실행하고 발견된 문제를 고쳐. 별도로 lesson의 순서대로 SSH commit signing을 머신에 설정하고 signed commit을 push해 GitHub UI의 'Verified' badge를 확인해. 팀 hook에 더할 검사 하나도 적어봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.