C.W.K.
Stream
Lesson 03 of 04 · published

Hook, signing, local gate

~20 min · hooks, signing

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

Hook 과 signing 이 의도를 강제로

Git hook 은 .git/hooks/ 의 스크립트로 lifecycle 이벤트에 발화: before-commit, after-commit, before-push, before-receive 등. 팀에 중요한 건 두 카테고리. Client-side hook (pre-commit, commit-msg, pre-push) 은 개발자 머신에서 실행, 노트북 떠나기 전 문제 잡음 — 포맷팅, 린팅, 금지 문자열 탐지, 기본 test 실행. Server-side hook (pre-receive, update) 은 서버에서 실행, 정책 위반 push 거부 — 마지막 방어선이고 부주의한 contributor 가 우회할 수 없는 유일한 거.

오늘날 실용적 client-side 스택: pre-commit (Python 도구, hook 이름 아님) 또는 Husky (Node 생태계) 가 YAML 이나 package.json 에서 hook 을 선언적 구성. Hook config 가 formatter (Prettier, Black), linter (ESLint, Ruff), 커스텀 체크 (no console.log, production 코드에 no TODO, secret 스캔) 실행. 각 push 가 위반을 일찍 — 고치기 싼 시점 — 표면화, CI 가 분 단위 후 돌리는 게 아니라.

Commit signing 이 두 번째 보강 layer. git commit -S (또는 commit.gpgsign = true) 로 Git 이 GPG 또는 SSH key 로 commit 서명. GitHub 의 'Verified' 배지가 서명이 author 에 등록된 key 와 일치 확인. 사칭 차단: 개발자 계정 비밀번호 훔친 attacker 가 signing key 는 못 가져갔으면 signed commit 요구하는 branch 보호 통과 못 함. SSH commit signing (Git 2.34+) 이 GPG 보다 쉽고 SSH push 에 이미 쓰는 같은 key 로 작동.

한 번 설정. git config --global commit.gpgsign true 로 모든 commit 서명. git config --global gpg.format ssh 로 GPG 대신 SSH key 사용. 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

실제 프로젝트에 pre-commit 을 최소 체크 셋 (whitespace, secret 탐지, 언어에 맞는 linter) 으로 설치. pre-commit run --all-files 돌리고 잡힌 거 다 고침. 별도로 레슨의 단계대로 SSH commit signing 머신에 세팅, signed commit push, GitHub UI 의 'Verified' 배지 확인. 팀 hook config 에 추가할 체크 하나 적어.

Progress

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

댓글 0

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

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