pull_request_target ๐ค๋ก ์ธ๋ถ ํฌํฌ๋ฅผ ๊ตฌ์ถํ ๋ ํ๊ฒฝ ๋ณดํธ ๊ท์น์ ์ฌ์ฉํ์ฌ ๋น๋ฐ ๋ณดํธ
GITHUB_TOKEN๋ฅผ ์ ์ธํ๊ณ  ์ํฌํ๋ก๊ฐ ํฌํฌ๋ ์ ์ฅ์์์ ํธ๋ฆฌ๊ฑฐ๋  ๋ ๋น๋ฐ์ด ๋ฌ๋์๊ฒ ์ ๋ฌ๋์ง ์์ต๋๋ค. ์ด๋ ํฌํฌ๋ ์ ์ฅ์ ๋ด์ ํฌํจ๋  ์ ์๋ ์ ๋ขฐํ  ์ ์๋ ์ฝ๋์ ์๋ ์คํ์ ๋ฐฉ์งํ๊ธฐ ์ํ ๊ฒ์
๋๋ค.์ฆ, ์ํฌํ๋ก์ ํฌํจ๋์ด์ผ ํ๋ ์ํธ๊ฐ ์๋ ๊ฒฝ์ฐ
pull_request ํธ๋ฆฌ๊ฑฐ๋ฅผ ์ฌ์ฉํ  ์ ์์ต๋๋ค.๋คํํ
pull_request_target comes to rescue ....the
pull_request_targetevent behaves in an almost identical way to the pull_request event with the same set of filters and payload. However, instead of running against the workflow and code from the merge commit, the event runs against the workflow and code from the base of the pull request. This means the workflow is running from a trusted source...
์ด์  ๋น๋ฐ์ ์ก์ธ์คํ ์ ์์ง๋ง ์๋ชป๋ ์ฝ๋๋ฅผ ์์ฑํ๊ณ ์์ต๋๋ค.
๋ถ๋ช ํ ๋ค์ ์ฝ๋๋ก ์ด ๋ฌธ์ ๋ฅผ ๊ทน๋ณตํ๋ ค๋ ์ฌ๋๋ค์ด ์์ต๋๋ค.
#INSECURE
steps:
- uses: actions/checkout@v2
  with:
    ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR
๋ค๋ฅธ ๋ณด์ ์กฐ์น๋ฅผ ์ทจํ์ง ์์ผ๋ฉด ์์ ํ์ง ์๊ธฐ ๋๋ฌธ์ ๊ถ์ฅํ์ง ์์ผ๋ฉฐ ์ ๋นํฉ๋๋ค.
GitHub์ ์์ฒด ๊ธฐ์ฌPreventing pwn requests์์ ์ ์Jaroslav Lobaฤevski๋ PR์
pull_request_target ๋ ์ด๋ธ์ด ์ง์ ๋์๋์ง ์ฌ๋ถ๋ฅผ ํ์ธํ๋ ์กฐ๊ฑด๊ณผ ํจ๊ป safe to test๋ฅผ ์ฌ์ฉํ  ๊ฒ์ ์ ์ํฉ๋๋ค. ์ด์ ๊ฐ์ด:    jobs:
      build:
        name: Build and test
        runs-on: ubuntu-latest
        if: contains(github.event.pull_request.labels.*.name, 'safe to test')
์ด๊ฒ์ ์๋ฒฝํ๊ฒ ์ ํจํ ์ ๊ทผ ๋ฐฉ์์ด์ง๋ง ํฌํฌ๋ฅผ ๋น๋ํ๋ ๋์ ์น์ธ๋์ง ์์ ์ฝ๋ ์คํ์ ๋ฐฉ์งํ๋ ๋ ์ข๊ณ ํธ๋ฆฌํ ๋ฐฉ๋ฒ์ ์ฐพ์ ๊ฒ ๊ฐ์ต๋๋ค.
ํ๊ฒฝ ๋ณดํธ ๊ท์น
๋ถ๊ณผ ๋ช ๋ฌ ์ ์ GitHub๋ Environment protection rules ์ ์๊ฐํ์ต๋๋ค. ์ด ๊ธฐ๋ฅ์ ์ฃผ์ ๋ชฉ์ ์ ์ฃผ์ด์ง ์กฐ๊ฑด์ด ์ถฉ์กฑ๋ ๋๊น์ง ์ํฌํ๋ก ์คํ์ ์ผ์ ์ค์งํ๋ ๊ท์น์ ์ ์ฉํ์ฌ ๋ฐฐํฌ ์ค์ ํ๊ฒฝ์ ๋ณดํธํ๋ ๊ฒ์ ๋๋ค. ์ฌ๋์ ์น์ธ, ํน์  ์๊ฐ ๊ฒฝ๊ณผ ๋ฑ์ด ์์ต๋๋ค. ๊ทธ๋ฌ๋ ์ผ๋ฐ์ ์ธ ์ฉ๋๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ฐ๋ฆฌ์ ๊ฒฝ์ฐ ์ ์ฅ์ ๋น๋ฐ์ ๋ณดํธํ๊ณ ์ ๋ขฐํ ์ ์๋ ์ฝ๋์ ์คํ์ ๋ฐฉ์งํ๋ ๋ฐ ์ฌ์ฉํ ๊ฒ์ ๋๋ค.
๋น๋ ๋ณดํธ
์ฌ๋์ ์น์ธ์ด ํ์ํ "๋์ด์ค๊ธฐ ์์ฒญ ํตํฉ"์ด๋ผ๋ ๋๋ฏธ ํ๊ฒฝ์ ์ถ๊ฐํ๋ ๊ฒ๋ถํฐ ์์ํ๊ฒ ์ต๋๋ค.

์ฐ๋ฆฌ์ ๊ธฐ๋ณธ ๋น๋ ์ ์ฐจ๋ ์ด ํ๊ฒฝ๊ณผ ์ฐ๊ฒฐ๋๋ฉฐ ๋๋ฏธ ์ํฌํ๋ก ๋จ๊ณ
approve๊ฐ ์ ํ๋์ด ์ํฌํ๋ก๋ฅผ ์์ํ๊ณ  ํ ์์ฒญ ์์ฑ์์๊ฒ ๋ ์งํํ๊ธฐ ์ ์ ๊ฒํ ๊ฐ ํ์ํจ์ ์๋ฆฝ๋๋ค.on:
  pull_request_target:
    branches: [ master ]
jobs:
  approve: # First step
    runs-on: ubuntu-latest
    steps:
    - name: Approve
      run: echo For security reasons, all pull requests need to be approved first before running any automated CI.
  build: # Second step
    runs-on: ubuntu-latest
    needs: [approve] # Require the first step to finish
    environment:
      name: Integrate Pull Request # Our dummy environment
    steps:
    - ...
์ด๋ ๊ฒ ํ๋ฉด ๋๊ตฐ๊ฐ๊ฐ ์ ์ถ๋ ์ฝ๋๋ฅผ ๊ฒํ ํ ๋๊น์ง ์ํฌํ๋ก๊ฐ ์งํ๋์ง ์์ผ๋ฏ๋ก ๋ค์ ๋จ๊ณ์์ ์์ ํ๊ฒ
${{ github.event.pull_request.head.sha }}๋ฅผ ํ์ธํ๊ณ  ๋น๋ํ  ์ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋น๋๋ PR์ ๊ธฐ๋ฐ๊ณผ PR์ ์ค์  ์ฝ๋์์ ์ ๋ขฐํ  ์ ์๋ ์ํฌํ๋ก๋ฅผ ์ฌ์ฉํ์ฌ ์คํ๋ฉ๋๋ค.์ค์ ๋ก ์๋ํ๋ ๋ฐฉ์
 
  
  
  
  
 Codecov์ ๋ํ ๋ช ๋ง๋
์ด ์ํฌํ๋ก๋ฅผ ๊ตฌํํ๋ ๋์ GitHub Checkout Action๊ณผ ์ ์ฌํ๊ฒ Codecov ์์ ์ด ๊ธฐ๋ณธ์ ์ผ๋ก pointed to the PR's Base์ด๊ณ ์ฌ์ ์ํด์ผ ํ๋ ๋ฌธ์ ์ ์ง๋ฉดํ์ต๋๋ค. ์ด๋ ๋ค์์ ํตํด ๋ฌ์ฑํ ์ ์์ต๋๋ค.
- name: Codecov
  uses: codecov/codecov-action@v1
  with:
    token: ${{ secrets.CODECOV_TOKEN }}
    override_pr: ${{ github.event.number }}
    override_commit: ${{ github.event.pull_request.head.sha }}
๋ค์ ๊ฒฝ๊ณ ๋ฉ์์ง๋ฅผ ์ ๊ฑฐํ๋ ค๋ฉด:
Issue detecting commit SHA. Please run actions/checkout with fetch-depth > 1 or set to 0
๊ฒฐ์  ์์ ์
fetch-depth๋ 2๋ก ์ค์ ํด์ผ ํฉ๋๋ค.steps:
- uses: actions/checkout@v2      
  with:
    fetch-depth: 2
์ฐธ๊ณ : ์กฐ๊ฑด๋ถ workflow step ๋ฐ shell script์ ์ฌ์ฉํ๋ ๋์ฒด ์ ๊ทผ ๋ฐฉ์์ ์ฐพ์์ต๋๋ค. ๊ทธ๋ฌ๋ ์ปค๋ฐ SHA๋ฅผ ์ฌ์ ์ํ๋ ๊ฒ์ด ํจ์ฌ ์ฝ์ต๋๋ค.
์์ฝ
์ด ์ ๊ทผ ๋ฐฉ์์ ์ฅ์ ์ ๋ณด๋ฅ ์ค์ธ ์ํฌํ๋ก์ ๋ํ ์ ์ ๋ฉ์ผ ์๋ฆผ์ ๋ฐ๊ณ ํด๋ฆญ ํ ๋ฒ์ผ๋ก ๊ฒํ ๋ฐ ์น์ธํ ์ ์๋ ๊ฒํ ์ ๊ทธ๋ฃน์ ํ ๋นํ ์ ์๋ค๋ ๊ฒ์ ๋๋ค.
์  ์๊ฐ์๋ ๋ชจ๋ ์ด๋ฒคํธ๊ฐ ๊ธฐ๋ก๋๊ณ ๋ ์ด๋ธ์ ์ฌ์ฉํ๋ ๊ฒ๋ณด๋ค ์๋ฏธ๋ก ์ ์ผ๋ก ๋ ์ ํํ๊ธฐ ๋๋ฌธ์ ํ๋ก์ธ์ค๊ฐ ๋ ํฌ๋ช ํฉ๋๋ค.
์ ์ฒด ์ํฌํ๋ก๋ฅผ ํ์ํ๋ ค๋ฉด ๋ด ํ๋ก์ ํธWopiHost๋ฅผ ํ์ธํ์ญ์์ค.
pull_request_target์ ์ธ๋ถ ์ฌํญ์ ๋ํด ์์ธํ ์์๋ณด๋ ค๋ฉด documentation๋ก ์ด๋ํ์ญ์์ค.
                Reference
์ด ๋ฌธ์ ์ ๊ดํ์ฌ(pull_request_target ๐ค๋ก ์ธ๋ถ ํฌํฌ๋ฅผ ๊ตฌ์ถํ ๋ ํ๊ฒฝ ๋ณดํธ ๊ท์น์ ์ฌ์ฉํ์ฌ ๋น๋ฐ ๋ณดํธ), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://dev.to/petrsvihlik/using-environment-protection-rules-to-secure-secrets-when-building-external-forks-with-pullrequesttarget-hciํ ์คํธ๋ฅผ ์์ ๋กญ๊ฒ ๊ณต์ ํ๊ฑฐ๋ ๋ณต์ฌํ ์ ์์ต๋๋ค.ํ์ง๋ง ์ด ๋ฌธ์์ URL์ ์ฐธ์กฐ URL๋ก ๋จ๊ฒจ ๋์ญ์์ค.
                                
                                
                                
                                
                                
                                ์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ
์ธ  ๋ฐ๊ฒฌ์ ์ ๋
                                (Collection and Share based on the CC Protocol.)
                            
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค