๋ถ์์ ์ํ ์ฝ๋ ์ค๋น ์ ๋ณด
CodeQL์(๋ฅผ) ์ฌ์ฉํ์ฌ ์ฝ๋๋ฅผ ๋ถ์ํ๊ธฐ ์ ์ ์ฝ๋์์ ์ฟผ๋ฆฌ๋ฅผ ์คํํ๋ ๋ฐ ํ์ํ ๋ชจ๋ ๋ฐ์ดํฐ๊ฐ ํฌํจ๋ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค์ด์ผ ํฉ๋๋ค. CodeQL CLI๋ฅผ ์ฌ์ฉํ์ฌ CodeQL์(๋ฅผ) ์ง์ ๋ง๋ค ์ ์์ต๋๋ค.
CodeQL ๋ถ์์ ์ฝ๋์์ ๊ด๊ณํ ๋ฐ์ดํฐ๋ฅผ ์ถ์ถํ๊ณ ์ด๋ฅผ ์ฌ์ฉํ์ฌ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋น๋ํ๋ ๋ฐ ์์กดํฉ๋๋ค. CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค์๋ ์ฝ๋๋ฒ ์ด์ค์ ๋ํ ์ค์ํ ์ ๋ณด๊ฐ ๋ชจ๋ ํฌํจ๋์ด ์์ผ๋ฉฐ, ์ด ์ ๋ณด๋ CodeQL ์ฟผ๋ฆฌ๋ฅผ ์คํํ์ฌ ๋ถ์ํ ์ ์์ต๋๋ค.
CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํ๊ธฐ ์ ๋ค์ ์์ ์ ์ํํด์ผ ํฉ๋๋ค.
- CodeQL CLI(์)๋ฅผ ์ค์น ๋ฐ ์ค์ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ CodeQL CLI ์ค์ ํ๊ธฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
- ๋ถ์ํ๋ ค๋ ์ฝ๋๋ฅผ ์ฒดํฌ ์์ํฉ๋๋ค.
- ๋ถ๊ธฐ์ ๊ฒฝ์ฐ ๋ถ์ํ๋ ค๋ ๋ถ๊ธฐ์ ํค๋๋ฅผ ์ฒดํฌ ์์ํฉ๋๋ค.
- ๋์ด์ค๊ธฐ ์์ฒญ์ ๊ฒฝ์ฐ ๋์ด์ค๊ธฐ ์์ฒญ์ ํค๋ ์ปค๋ฐ์ ์ฒดํฌ ์์ํ๊ฑฐ๋, ๋์ด์ค๊ธฐ ์์ฒญ์ GitHub ์์ฑ ๋ณํฉ ์ปค๋ฐ์ ์ฒดํฌ ์์ํฉ๋๋ค.
- ๋ชจ๋ ์ข ์์ฑ์ ์ฌ์ฉํ ์ ์๋๋ก ์ฝ๋๋ฒ ์ด์ค์ ๋ํ ํ๊ฒฝ์ ์ค์ ํฉ๋๋ค.
- ์ปดํ์ผ๋ ์ธ์ด๋ฅผ ์ฌ์ฉํ์ฌ ์ต์์ ๊ฒฐ๊ณผ๋ฅผ ์ป์ผ๋ ค๋ฉด ์ฝ๋๋ฒ ์ด์ค์ ๋ํ ๋น๋ ๋ช ๋ น(์๋ ๊ฒฝ์ฐ)์ ์ฐพ์ต๋๋ค. ์ผ๋ฐ์ ์ผ๋ก ์ด ๋ช ๋ น์ CI ์์คํ ์ ๊ตฌ์ฑ ํ์ผ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ฝ๋๋ฒ ์ด์ค๊ฐ ์ค๋น๋๋ฉด codeql database create
(์)๋ฅผ ์คํํ์ฌ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ปดํ์ผ๋์ง ์์ ์ธ์ด์ ๋ํ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ ๋ฐ ์ปดํ์ผ๋ ์ธ์ด์ ๋ํ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ๋ฅผ ์ฐธ์กฐํ์ธ์.
codeql database create
์คํ ์ค
CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ ํ๋ก์ ํธ์ ์ฒดํฌ ์์ ๋ฃจํธ์์ ๋ค์ ๋ช ๋ น์ ์คํํ์ฌ ์์ฑ๋ฉ๋๋ค.
codeql database create <database> --language=<language-identifier>
๋ค์ ํญ๋ชฉ์ ์ง์ ํด์ผ ํฉ๋๋ค.
-
<database>
๋ ์์ฑํ ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๊ฒฝ๋ก์ ๋๋ค. ๋ช ๋ น์ ์คํํ๋ฉด ์ด ๋๋ ํฐ๋ฆฌ๊ฐ ๋ง๋ค์ด์ง๋๋ค. ๊ธฐ์กด ๋๋ ํฐ๋ฆฌ๋ฅผ ์ง์ ํ ์๋ ์์ต๋๋ค. -
--language
: ๋ฐ์ดํฐ๋ฒ ์ด์ค ์์ฑ์ ์ฌ์ฉ๋๋ ์ธ์ด์ ์๋ณ์์ ๋๋ค.--db-cluster
์ ํจ๊ป ์ฌ์ฉํ ๊ฒฝ์ฐ ์ต์ ์ ์ผํ๋ก ๊ตฌ๋ถ๋ ๋ชฉ๋ก์ ํ์ฉํ๊ฑฐ๋ ๋ ๋ฒ ์ด์ ์ง์ ํ ์ ์์ต๋๋ค. CodeQL(์)๋ ๋ค์ ์ธ์ด์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ๋ฅผ ์ง์ํฉ๋๋ค.์ธ์ด ์๋ณ์ ์ ํ์ ์ผํฐ๋ํฐ๋ธ ์๋ณ์(์๋ ๊ฒฝ์ฐ) C/C++ c-cpp
c
๋๋cpp
C# csharp
Go go
Java/Kotlin java-kotlin
java
๋๋kotlin
JavaScript/TypeScript javascript-typescript
javascript
๋๋typescript
Python python
Ruby ruby
Swift swift
GitHub Actions ์ํฌํ๋ก actions
์ฐธ๊ณ ํญ๋ชฉ
๋์ฒด ์๋ณ์ ์ค ํ๋๋ฅผ ์ง์ ํ๋ ๊ฒฝ์ฐ ํ์ค ์ธ์ด ์๋ณ์๋ฅผ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค. ์๋ฅผ ๋ค์ด
javascript
๋์javascript-typescript
๋ฅผ ์ง์ ํด๋ TypeScript ์ฝ๋์ ๋ถ์์ ์ ์ธ๋์ง ์์ต๋๋ค.--paths-ignore
์ต์ ์ ์ฌ์ฉํ์ฌ ๊ณ ๊ธ ์ค์ ์ํฌํ๋ก์์ ์ด ์์ ์ ์ํํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ฝ๋ ๊ฒ์์ ์ํ ๊ณ ๊ธ ์ค์ ์ฌ์ฉ์ ์ง์ ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
์ฝ๋๋ฒ ์ด์ค์ ๋น๋ ํ๋ก์ธ์ค๋ฅผ ํธ์ถํ๋ ๋น๋ ๋ช ๋ น ๋๋ ์คํฌ๋ฆฝํธ๊ฐ ์๋ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ์ง์ ํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
codeql database create <database> --command <build> \
--language=<language-identifier>
๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค๊ธฐ ์ํ ์ต์
์๋ณธ ํ์ผ์ ์์น, ์ฝ๋๋ฅผ ์ปดํ์ผํด์ผ ํ๋ ๊ฒฝ์ฐ, ๋ ๊ฐ ์ด์์ ์ธ์ด์ ๋ํ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํ๋ ค๋ ๊ฒฝ์ฐ ์ถ๊ฐ ์ต์ ์ ์ง์ ํ ์ ์์ต๋๋ค.
์ต์ | ํ์ | ์ฌ์ฉ |
---|---|---|
<database> | CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ํด ๋ง๋ค ๋๋ ํฐ๋ฆฌ์ ์ด๋ฆ๊ณผ ์์น๋ฅผ ์ง์ ํฉ๋๋ค. ๊ธฐ์กด ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ฎ์ด์ฐ๋ ค๊ณ ํ๋ฉด ๋ช
๋ น์ด ์คํจํฉ๋๋ค. ๋ํ --db-cluster ๋ฅผ ์ง์ ํ๋ ๊ฒฝ์ฐ ์ด๋ ๋ถ๋ชจ ๋๋ ํฐ๋ฆฌ์ด๋ฉฐ ํ์ ๋๋ ํฐ๋ฆฌ๋ ๋ถ์๋ ๊ฐ ์ธ์ด์ ๋ํด ๋ง๋ค์ด์ง๋๋ค. | |
--language | ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ์ธ์ด์ ์๋ณ์๋ฅผ c-cpp , csharp , go , java-kotlin , javascript-typescript , python , ruby , swift ์ค ํ๋๋ก ์ง์ ํฉ๋๋ค. --db-cluster ์ ํจ๊ป ์ฌ์ฉํ ๊ฒฝ์ฐ ์ต์
์ ์ผํ๋ก ๊ตฌ๋ถ๋ ๋ชฉ๋ก์ ํ์ฉํ๊ฑฐ๋ ๋ ๋ฒ ์ด์ ์ง์ ํ ์ ์์ต๋๋ค. | |
--command | ๊ถ์ฅ. ์ฝ๋๋ฒ ์ด์ค์ ๋ํ ๋น๋ ํ๋ก์ธ์ค๋ฅผ ํธ์ถํ๋ ๋น๋ ๋ช
๋ น ๋๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ง์ ํ๋ ๋ฐ ์ฌ์ฉํฉ๋๋ค. ๋ช
๋ น์ ํ์ฌ ํด๋์์ ์คํ๋๊ฑฐ๋ ์ ์๋ ๊ฒฝ์ฐ --source-root ์์ ์คํ๋ฉ๋๋ค. Python ๋ฐ JavaScript/TypeScript ๋ถ์์๋ ํ์ํ์ง ์์ต๋๋ค. | |
--build-mode | ๊ถ์ฅ. --command ์ ์ ๊ณตํ์ง ์์ ๋ C/C++, C# ๋ฐ Java๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋ ์์ด CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํ ์ง(none ) ์๋๋ฉด ๋น๋ ๋ช
๋ น์ ์๋์ผ๋ก ๊ฐ์งํ๋ ค๊ณ ์๋ํ ์ง(autobuild ) ์ฌ๋ถ๋ฅผ ์ง์ ํฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์๋ ๋น๋ ๊ฒ์์ด ์ฌ์ฉ๋ฉ๋๋ค. ๋น๋ ๋ชจ๋ ๋น๊ต๋ CodeQL ๋น๋ ๋ชจ๋๋ฅผ ์ฐธ์กฐํ์ธ์. | |
--db-cluster | ๋ค๊ตญ์ด ์ฝ๋๋ฒ ์ด์ค์์ --language ์ ์ํด ์ง์ ๋ ๊ฐ ์ธ์ด์ ๋ํด ํ๋์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉํฉ๋๋ค. | |
--no-run-unnecessary-builds | ๊ถ์ฅ. CodeQL CLI๊ฐ ๋น๋๋ฅผ ๋ชจ๋ํฐ๋งํ ํ์๊ฐ ์๋ ์ธ์ด(์: Python ๋ฐ JavaScript/TypeScript)์ ๋น๋ ๋ช ๋ น์ ํ์ํ์ง ์๋ ๋ฐ ์ฌ์ฉํฉ๋๋ค. | |
--source-root | ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ฒดํฌ ์์ ๋ฃจํธ ์ธ๋ถ์์ CLI๋ฅผ ์คํํ๋ ๊ฒฝ์ฐ ์ฌ์ฉํฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก database create ๋ช
๋ น์ ํ์ฌ ๋๋ ํฐ๋ฆฌ๊ฐ ์๋ณธ ํ์ผ์ ๋ฃจํธ ๋๋ ํฐ๋ฆฌ๋ผ๊ณ ๊ฐ์ ํฉ๋๋ค. ์ด ์ต์
์ ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ์์น๋ฅผ ์ง์ ํฉ๋๋ค. | |
--codescanning-config | ๊ณ ๊ธ. CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ๊ณผ ์ดํ ๋จ๊ณ์์ ์คํํ ์ฟผ๋ฆฌ๋ฅผ ์ง์ ํ๋ ๊ตฌ์ฑ ํ์ผ์ด ์๋ ๊ฒฝ์ฐ ์ฌ์ฉํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ์ฝ๋ ๊ฒ์์ ์ํ ๊ณ ๊ธ ์ค์ ์ฌ์ฉ์ ์ง์ ๋ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์. |
์ถ์ถ๊ธฐ ์ต์ ์ ์ง์ ํ์ฌ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋๋ ์ถ์ถ๊ธฐ์ ๋์์ ์ฌ์ฉ์ ์ง์ ํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ถ์ถ๊ธฐ ์ต์ ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ๋ ์ฌ์ฉํ ์ ์๋ ๋ชจ๋ ์ต์ ์ ๋ํ ์ ์ฒด ๋ด์ฉ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
๋จ์ผ ์ธ์ด ์์
๋ค์์ /checkouts/example-repo
์์ ์ฒดํฌ ์์๋ ๋ฆฌํฌ์งํ ๋ฆฌ์ ๋ํ ๋จ์ผ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋๋ ์์์
๋๋ค. JavaScript ์ถ์ถ๊ธฐ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฆฌํฌ์งํ ๋ฆฌ์ JavaScript ๋ฐ TypeScript ์ฝ๋์ ๊ณ์ธต์ ํํ์ ๋ง๋ญ๋๋ค. ๊ฒฐ๊ณผ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ /codeql-dbs/example-repo
์ ์ ์ฅ๋ฉ๋๋ค.
$ codeql database create /codeql-dbs/example-repo --language=javascript-typescript \
--source-root /checkouts/example-repo
> Initializing database at /codeql-dbs/example-repo.
> Running command [/codeql-home/codeql/javascript/tools/autobuild.cmd]
in /checkouts/example-repo.
> [build-stdout] Single-threaded extraction.
> [build-stdout] Extracting
...
> Finalizing database at /codeql-dbs/example-repo.
> Successfully created database at /codeql-dbs/example-repo.
๋ค์ค ์ธ์ด ์์
๋ค์์ /checkouts/example-repo-multi
์์ ์ฒดํฌ ์์๋ ๋ฆฌํฌ์งํ ๋ฆฌ์ ๋ํ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค 2๊ฐ๋ฅผ ๋ง๋๋ ์์์
๋๋ค. ์ด๋ ๋ค์์ ์ฌ์ฉํฉ๋๋ค.
--db-cluster
- ๋ ๊ฐ ์ด์ ์ธ์ด์ ๋ถ์์ ์์ฒญํฉ๋๋ค.--language
- ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ์ธ์ด๋ฅผ ์ง์ ํฉ๋๋ค.--command
- ์ฝ๋๋ฒ ์ด์ค์ ๋ํ ๋น๋ ๋ช ๋ น์ ๋๊ตฌ์ ์๋ฆฝ๋๋ค(์ฌ๊ธฐ์๋make
).--no-run-unnecessary-builds
- ํ์ํ์ง ์์ ๊ฒฝ์ฐ ์ธ์ด(์: Python)์ ๋น๋ ๋ช ๋ น์ ๊ฑด๋๋ฐ๋๋ก ๋๊ตฌ์ ์๋ฆฝ๋๋ค.
๊ฒฐ๊ณผ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ /codeql-dbs/example-repo-multi
์ python
๋ฐ cpp
ํ์ ๋๋ ํฐ๋ฆฌ์ ์ ์ฅ๋ฉ๋๋ค.
$ codeql database create /codeql-dbs/example-repo-multi \
--db-cluster --language python,c-cpp \
--command make --no-run-unnecessary-builds \
--source-root /checkouts/example-repo-multi
Initializing databases at /codeql-dbs/example-repo-multi.
Running build command: [make]
[build-stdout] Calling python3 /codeql-bundle/codeql/python/tools/get_venv_lib.py
[build-stdout] Calling python3 -S /codeql-bundle/codeql/python/tools/python_tracer.py -v -z all -c /codeql-dbs/example-repo-multi/python/working/trap_cache -p ERROR: 'pip' not installed.
[build-stdout] /usr/local/lib/python3.6/dist-packages -R /checkouts/example-repo-multi
[build-stdout] [INFO] Python version 3.6.9
[build-stdout] [INFO] Python extractor version 5.16
[build-stdout] [INFO] [2] Extracted file /checkouts/example-repo-multi/hello.py in 5ms
[build-stdout] [INFO] Processed 1 modules in 0.15s
[build-stdout] <output from calling 'make' to build the C/C++ code>
Finalizing databases at /codeql-dbs/example-repo-multi.
Successfully created databases at /codeql-dbs/example-repo-multi.
$
์งํ๋ฅ ๋ฐ ๊ฒฐ๊ณผ
์ง์ ํ ์ต์
์ ๋ฌธ์ ๊ฐ ์์ผ๋ฉด ์ค๋ฅ๊ฐ ๋ณด๊ณ ๋ฉ๋๋ค. ํด์๋ ์ธ์ด์ ๊ฒฝ์ฐ C/C++, C# ๋ฐ Java์ --build-mode none
์ ์ง์ ํ๋ฉด ์ถ์ถ ์งํ๋ฅ ์ด ์ฝ์์ ํ์๋ฉ๋๋ค. ๊ฐ ์๋ณธ ํ์ผ์ ๋ํด ์ฝ์์ ์ถ์ถ์ ์ฑ๊ณตํ๋์ง ๋๋ ์คํจํ๋์ง๋ฅผ ํ์ํฉ๋๋ค. ์ปดํ์ผ๋ ์ธ์ด๊ฐ ๋น๋๋๋ฉด ์ฝ์์ ๋น๋ ์์คํ
์ ์ถ๋ ฅ์ด ํ์๋ฉ๋๋ค.
๋ฐ์ดํฐ๋ฒ ์ด์ค๊ฐ ์ฑ๊ณต์ ์ผ๋ก ๋ง๋ค์ด์ง๋ฉด ๋ช
๋ น์ ์ง์ ๋ ๊ฒฝ๋ก์์ ์ ๋๋ ํฐ๋ฆฌ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. --db-cluster
์ต์
์ ์ฌ์ฉํ์ฌ ๋ ์ด์์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ ๊ฒฝ์ฐ ๊ฐ ์ธ์ด์ ๋ํด ํ์ ๋๋ ํฐ๋ฆฌ๊ฐ ๋ง๋ค์ด์ง๋๋ค. ๊ฐ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋๋ ํฐ๋ฆฌ์๋ ๊ด๊ณํ ๋ฐ์ดํฐ(๋ถ์์ ํ์) ๋ฐ ์๋ณธ ์์นด์ด๋ธ(๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ๋ ์์ฑํ ์๋ณธ ํ์ผ์ ๋ณต์ฌ๋ณธ)๋ฅผ ํฌํจํ์ฌ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ํ๋ ๋ฐ ์ฌ์ฉ๋๋ ์ฌ๋ฌ ํ์ ๋๋ ํฐ๋ฆฌ๊ฐ ํฌํจ๋ฉ๋๋ค.
์ปดํ์ผ๋์ง ์์ ์ธ์ด์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ
CodeQL CLI์๋ ์ปดํ์ผ๋์ง ์์ ์ธ์ด, ํนํ JavaScript(๋ฐ TypeScript), Python ๋ฐ Ruby์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋๋ ์ถ์ถ๊ธฐ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. ์ด๋ฌํ ์ถ์ถ๊ธฐ๋ JavaScript, Python ๋๋ Ruby๋ฅผ --language
์ต์
์ผ๋ก ์ง์ ํ๊ณ database create
(์)๋ฅผ ์คํํ๋ฉด ์๋์ผ๋ก ํธ์ถ๋ฉ๋๋ค. ์ด๋ค ์ธ์ด์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ๋๋ ์ถ๊ฐ์ ์ธ ์ข
์์ฑ์ ๋ชจ๋ ์ฌ์ฉํ ์ ์๋์ง ํ์ธํด์ผ ํฉ๋๋ค.
์ฐธ๊ณ ํญ๋ชฉ
JavaScript, TypeScript, Python ๋ฐ Ruby์ฉ์ผ๋ก database create
๋ฅผ ์คํํ๋ ๊ฒฝ์ฐ --command
์ต์
์ ์ง์ ํด์ ์ ๋ฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์ผ๋ฐ ์ถ์ถ๊ธฐ ํธ์ถ์ ์ฌ์ ์ํ์ฌ ๋น ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค๊ฒ ๋ฉ๋๋ค. ์ฌ๋ฌ ์ธ์ด์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค๊ณ ๊ทธ ์ค ํ๋๊ฐ ์ปดํ์ผ๋ ์ธ์ด์ธ ๊ฒฝ์ฐ, --no-run-unnecessary-builds
์ต์
์ ์ฌ์ฉํ์ฌ ์ปดํ์ผํ ํ์๊ฐ ์๋ ์ธ์ด์ ๋ํ ๋ช
๋ น์ ๊ฑด๋๋๋๋ค.
JavaScript ๋ฐ TypeScript
JavaScript์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ๋๋ ์ถ๊ฐ ์ข
์์ฑ์ด ํ์ํ์ง ์์ง๋ง ํ๋ก์ ํธ์ TypeScript ํ์ผ์ด ํฌํจ๋ ๊ฒฝ์ฐ Node.js 14 ์ด์์ด ์ค์น๋์ด ์์ด์ผ ํ๋ฉฐ PATH
์์ node
๋ก ์ฌ์ฉํ ์ ์์ด์ผ ํฉ๋๋ค. ๋ช
๋ น์ค์์ JavaScript ๋ฐ TypeScript ํ์ผ์ ๋ชจ๋ ์ถ์ถํ๋๋ก --language=javascript-typescript
(์)๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค.
codeql database create --language=javascript-typescript --source-root <folder-to-extract> <output-folder>/javascript-database
์ฌ๊ธฐ์๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ๊ฐ ์คํ๋๋ ์์น์ธ --source-root
๊ฒฝ๋ก๋ฅผ ์ง์ ํ์ง๋ง ์ฝ๋๋ฒ ์ด์ค์ ์ฒดํฌ ์์ ๋ฃจํธ์ผ ํ์๋ ์์ต๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก node_modules
๋ฐ bower_components
๋๋ ํฐ๋ฆฌ์์์ ํ์ผ์ ์ถ์ถ๋์ง ์์ต๋๋ค.
Python
Python์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ๋๋ ๋ค์์ ํ์ธํด์ผ ํฉ๋๋ค.
- Python 3์ด ์ค์น๋์ด ์์ผ๋ฉฐ CodeQL ์ถ์ถ๊ธฐ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- ์ฝ๋์ ์ฌ์ฉํ๋ Python ๋ฒ์ ์ด ์ค์น๋์ด ์์ต๋๋ค.
๋ช
๋ น์ค์์ --language=python
(์)๋ฅผ ์ง์ ํด์ผ ํฉ๋๋ค. ์์:
codeql database create --language=python <output-folder>/python-database
๊ทธ๋ฌ๋ฉด ์ฝ๋์ ์ฒดํฌ ์์ ๋ฃจํธ์์ database create
ํ์ ๋ช
๋ น์ ์คํํ์ฌ <output-folder>/python-database
์์ ์ Python ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํฉ๋๋ค.
Ruby
Ruby์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค๋ ค๋ฉด ์ถ๊ฐ ์ข
์์ฑ์ด ํ์ํ์ง ์์ต๋๋ค. ๋ช
๋ น์ค์์ --language=ruby
(์)๋ฅผ ์ง์ ํด์ผ ํฉ๋๋ค. ์์:
codeql database create --language=ruby --source-root <folder-to-extract> <output-folder>/ruby-database
์ฌ๊ธฐ์๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ๊ฐ ์คํ๋๋ ์์น์ธ --source-root
๊ฒฝ๋ก๋ฅผ ์ง์ ํ์ง๋ง ์ฝ๋๋ฒ ์ด์ค์ ์ฒดํฌ ์์ ๋ฃจํธ์ผ ํ์๋ ์์ต๋๋ค.
์ปดํ์ผ๋ ์ธ์ด์ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง๋ค๊ธฐ
์ปดํ์ผ๋ ์ธ์ด์ ๊ฒฝ์ฐ CodeQL์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํ๋ ๋ฐ ํ์ํ ๋น๋ ์์คํ ์ ํธ์ถํด์ผ ํ๋ฏ๋ก CLI์์ ๋น๋ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ ์์ด์ผ ํฉ๋๋ค. ์ด ๋ฐฉ๋ฒ์ ์์ฑ๋ ์ฝ๋๋ฅผ ํฌํจํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ญ๋๋ค. CodeQL์๋ ์ฝ๋๋ฒ ์ด์ค๋ฅผ ๋น๋ํ๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
๋ํ C/C++, C# ๋ฐ Java์ ๊ฒฝ์ฐ ์ฝ๋๋ฅผ ๋น๋ํ์ง ์๊ณ , ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํ๋ ์ต์ ์ด ์์ต๋๋ค. ์ด ๊ธฐ๋ฅ์ ๋ง์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ๋ํด code scanning์(๋ฅผ) ์ฌ์ฉํ๋๋ก ์ค์ ํ๋ ค๋ ๊ฒฝ์ฐ์ ํนํ ์ ์ฉํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ CodeQL ๋น๋ ๋ชจ๋๋ฅผ ์ฐธ์กฐํ์ธ์.
๋น๋ ์์คํ ์๋ ๊ฒ์
CodeQL CLI์๋ C/C++, C#, Go, Java, Kotlin, Rust(๊ณต๊ฐ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ), ๋ฐ Swift ์ฝ๋์ฉ ์๋ ๋น๋๊ธฐ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. CodeQL ์๋ ๋น๋๊ธฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋น๋ ๋ช ๋ น์ ์ง์ ํ์ง ์๊ณ ๋ ์ปดํ์ผ๋ ์ธ์ด์ฉ ํ๋ก์ ํธ๋ฅผ ๋น๋ํ ์ ์์ต๋๋ค. ์๋ ๋น๋๊ธฐ๊ฐ ํธ์ถ๋ ๋ CodeQL์์๋ ์๋ณธ์ ๊ฒ์ฌํ์ฌ ๋น๋ ์์คํ ์ ๊ทผ๊ฑฐ๋ฅผ ํ์ธํ๊ณ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ถ์ถ์ ํ์ํ ์ต์ ์ ๋ช ๋ น ์งํฉ์ ์คํํ๋ ค๊ณ ์๋ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ์ปดํ์ผ๋ ์ธ์ด์ ๋ํ CodeQL ์ฝ๋ ๊ฒ์ฌํ๊ธฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
--command
์ต์
์ ํฌํจํ์ง ์๊ฑฐ๋ --build-mode none
์ ์ค์ ํ์ง ์์ผ๋ฉด ์ปดํ์ผ๋ ์ธ์ด์ ๋ํด codeql database create
๋ฅผ ์คํํ ๋ ์๋ ๋น๋๊ธฐ๊ฐ ์๋์ผ๋ก ํธ์ถ๋ฉ๋๋ค. ์๋ฅผ ๋ค์ด Swift ์ฝ๋๋ฒ ์ด์ค์ ๊ฒฝ์ฐ ๋ค์์ ์คํํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.
codeql database create --language=swift <output-folder>/swift-database
์ฝ๋๋ฒ ์ด์ค์์ ํ์ค ๋น๋ ์์คํ ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์๋ ๋น๋๊ธฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋๋ ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ๋๋ค. ๋นํ์ค ๋น๋ ๋จ๊ณ๊ฐ ํ์ํ ์๋ณธ์ ๊ฒฝ์ฐ ๋ช ๋ น์ค์์ ๊ฐ ๋จ๊ณ๋ฅผ ๋ช ์์ ์ผ๋ก ์ ์ํด์ผ ํ ์ ์์ต๋๋ค.
์ฐธ๊ณ ํญ๋ชฉ
- Go ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋น๋ํ๋ ๊ฒฝ์ฐ Go ๋๊ตฌ ์ฒด์ธ(๋ฒ์ 1.11 ์ด์)์ ์ค์นํ๊ณ ์ข ์์ฑ์ด ์๋ ๊ฒฝ์ฐ ์ ์ ํ ์ข ์์ฑ ๊ด๋ฆฌ์(์: dep)๋ฅผ ์ค์นํฉ๋๋ค.
- Go ์๋ ๋น๋๊ธฐ๋ ๋ฆฌํฌ์งํ ๋ฆฌ์์ Go๋ก ์์ฑ๋ ์ฝ๋๋ฅผ ์๋์ผ๋ก ๊ฒ์ํ๋ ค๊ณ ์๋ํ๊ณ ์ข
์์ฑ์ ๊ฐ์ ธ์ค๊ธฐ ์ํด ๋น๋ ์คํฌ๋ฆฝํธ๋ง ์คํํฉ๋๋ค. CodeQL์์ ๋น๋ ์คํฌ๋ฆฝํธ์ ์ํด ์ปดํ์ผ๋ ํ์ผ๋ก ์ถ์ถ์ ์ ํํ๋ ค๋ฉด ํ๊ฒฝ ๋ณ์
CODEQL_EXTRACTOR_GO_BUILD_TRACING=on
(์)๋ฅผ ์ค์ ํ๊ฑฐ๋--command
์ต์ ์ ์ฌ์ฉํ์ฌ ๋น๋ ๋ช ๋ น์ ์ง์ ํฉ๋๋ค.
๋น๋ ๋ช ๋ น ์ง์
๋ค์ ์์๋ ์ปดํ์ผ๋ ์ธ์ด์ฉ์ผ๋ก ์ง์ ํ ์ ์๋ ๋น๋ ๋ช ๋ น ์ค ์ผ๋ถ์ ๋ํ ์์ด๋์ด๋ฅผ ์ ๊ณตํ๋๋ก ์ค๊ณ๋์์ต๋๋ค.
์ฐธ๊ณ ํญ๋ชฉ
์ด --command
์ต์
์ ๋จ์ผ ์ธ์๋ฅผ ํ์ฉํฉ๋๋ค. ๋ ์ด์์ ๋ช
๋ น์ ์ฌ์ฉํด์ผ ํ๋ ๊ฒฝ์ฐ --command
๋ฅผ ์ฌ๋ฌ ๋ฒ ์ง์ ํฉ๋๋ค. ํ์ ๋ช
๋ น ๋ฐ ์ต์
์ ์ ๋ฌํด์ผ ํ๋ ๊ฒฝ์ฐ, ์ ์ฒด ์ธ์๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ํด์ํ๋ ค๋ฉด ๋ฐ์ดํ๋ก ๋ฌถ์ด์ผ ํฉ๋๋ค.
-
make
๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ C/C++ ํ๋ก์ ํธ:# Disable parallel execution via `-j1` or other techniques: https://www.gnu.org/software/make/manual/make.html#Parallel-Execution codeql database create cpp-database --language=c-cpp --command=make
-
dotnet build
๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ C# ํ๋ก์ ํธ:๋ชจ๋ ์ฝ๋๊ฐ ๋น๋๋๋๋ก
/t:rebuild
๋ฅผ ์ถ๊ฐํ๊ฑฐ๋ ์ด์ dotnet clean
์ ์ํํ๋ ๊ฒ์ด ์ข์ต๋๋ค(๋น๋๋์ง ์์ ์ฝ๋๋ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ํฌํจ๋์ง ์์).codeql database create csharp-database --language=csharp --command='dotnet build /t:rebuild'
-
CODEQL_EXTRACTOR_GO_BUILD_TRACING=on
ํ๊ฒฝ ๋ณ์๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ Go ํ๋ก์ ํธ:CODEQL_EXTRACTOR_GO_BUILD_TRACING=on codeql database create go-database --language=go
-
์ฌ์ฉ์ ์ง์ ๋น๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ Go ํ๋ก์ ํธ:
codeql database create go-database --language=go --command='./scripts/build.sh'
-
Gradle์ ์ฌ์ฉํ์ฌ ๋น๋๋ Java ํ๋ก์ ํธ:
# Use `--no-daemon` because a build delegated to an existing daemon cannot be detected by CodeQL. # To ensure isolated builds without caching, add `--no-build-cache` on persistent machines. codeql database create java-database --language=java-kotlin --command='gradle --no-daemon clean test'
-
Maven์ ์ฌ์ฉํ์ฌ ๋น๋๋ Java ํ๋ก์ ํธ:
codeql database create java-database --language=java-kotlin --command='mvn clean install'
-
Ant๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ Java ํ๋ก์ ํธ:
codeql database create java-database --language=java-kotlin --command='ant -f build.xml'
-
Xcode ํ๋ก์ ํธ ๋๋ ์์ ์์ญ์์ ๋น๋๋ Swift ํ๋ก์ ํธ์ ๋๋ค. ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๊ฐ์ฅ ํฐ Swift ๋์์ ๋ค์๊ณผ ๊ฐ์ด ๋น๋๋ฉ๋๋ค.
ํ๋ก์ ํธ๊ฐ ํด๋ฆฐ ์ํ์ด๊ณ ์ฌ์ฉ ๊ฐ๋ฅํ ๋น๋ ์ํฐํฉํธ๊ฐ ์๋์ง ํ์ธํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
xcodebuild clean -all codeql database create -l swift swift-database
-
swift build
๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ Swift ํ๋ก์ ํธ:codeql database create -l swift -c "swift build" swift-database
-
xcodebuild
๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ Swift ํ๋ก์ ํธ:codeql database create -l swift -c "xcodebuild build -target your-target" swift-database
archive
๋ฐtest
์ต์ ์xcodebuild
์ ์ ๋ฌํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ํ์คxcodebuild
๋ช ๋ น์ ๊ฐ์ฅ ๋น ๋ฅด๋ฉฐ ์ฑ๊ณต์ ์ธ ๊ฒ์ฌ๋ฅผ ์ํด CodeQL์ ํ์ํ ๋ชจ๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ๊ถ์ฅ๋ฉ๋๋ค. -
์ฌ์ฉ์ ์ง์ ๋น๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ Swift ํ๋ก์ ํธ:
codeql database create -l swift -c "./scripts/build.sh" swift-database
-
Bazel์ ์ฌ์ฉํ์ฌ ๋น๋๋ ํ๋ก์ ํธ:
# Navigate to the Bazel workspace. # Before building, remove cached objects # and stop all running Bazel server processes. bazel clean --expunge # Build using the following Bazel flags, to help CodeQL detect the build: # `--spawn_strategy=local`: build locally, instead of using a distributed build # `--nouse_action_cache`: turn off build caching, which might prevent recompilation of source code # `--noremote_accept_cached`, `--noremote_upload_local_results`: avoid using a remote cache # `--disk_cache=`: avoid using a disk cache. Note that a disk cache is no longer considered a remote cache as of Bazel 6. codeql database create new-database --language=<language> \ --command='bazel build --spawn_strategy=local --nouse_action_cache --noremote_accept_cached --noremote_upload_local_results --disk_cache= //path/to/package:target' # After building, stop all running Bazel server processes. # This ensures future build commands start in a clean Bazel server process # without CodeQL attached. bazel shutdown
-
์ฌ์ฉ์ ์ง์ ๋น๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๋ ํ๋ก์ ํธ:
codeql database create new-database --language=<language> --command='./scripts/build.sh'
์ด ๋ช ๋ น์ ํ๋ก์ ํธ๋ฅผ ๋น๋ํ๋ ๋ฐ ํ์ํ ๋ชจ๋ ๋ช ๋ น์ ํฌํจํ๋ ์ฌ์ฉ์ ์ง์ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํฉ๋๋ค.
๊ฐ์ ๋น๋ ์ถ์ ์ฌ์ฉ
์ปดํ์ผ๋ ์ธ์ด์ฉ CodeQL CLI ์๋ ๋น๋๊ธฐ๊ฐ CI ์ํฌํ๋ก์์ ์๋ํ์ง ์๊ณ codeql database trace-command
๋ก ๋น๋ ๋ช
๋ น ํธ์ถ์ ๋ํํ ์ ์๋ ๊ฒฝ์ฐ, ๊ฐ์ ๋น๋ ์ถ์ ์ ์ฌ์ฉํ์ฌ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. ๊ฐ์ ๋น๋ ์ถ์ ์ ์ฌ์ฉํ๋ ค๋ฉด CI ์์คํ
์์ ๊ฐ ๋น๋ ์์
์ ๋ํ ์ฌ์ฉ์ ์ง์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ ์ ์์ด์ผ ํฉ๋๋ค.
๊ฐ์ ๋น๋ ์ถ์ ์ ์ฌ์ฉํ์ฌ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํ๋ ค๋ฉด ํ๋ก์ ํธ์ ์ฒดํฌ ์์ ๋ฃจํธ์์ ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค.
codeql database init ... --begin-tracing <database>
๋ค์ ํญ๋ชฉ์ ์ง์ ํด์ผ ํฉ๋๋ค.
<database>
๋ ์์ฑํ ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๊ฒฝ๋ก์ ๋๋ค. ๋ช ๋ น์ ์คํํ๋ฉด ์ด ๋๋ ํฐ๋ฆฌ๊ฐ ๋ง๋ค์ด์ง๋๋ค. ๊ธฐ์กด ๋๋ ํฐ๋ฆฌ๋ฅผ ์ง์ ํ ์๋ ์์ต๋๋ค.--begin-tracing
์ ๋น๋ ๋ช ๋ น์ ์ถ์ ํ ํ๊ฒฝ์ ์ค์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋ ์คํฌ๋ฆฝํธ๋ฅผ ๋ง๋ญ๋๋ค.
codeql database init
๋ช
๋ น์ ๋ํ ๋ค๋ฅธ ์ต์
์ ์ ์์ ์ผ๋ก ์ง์ ํ ์ ์์ต๋๋ค.
์ฐธ๊ณ ํญ๋ชฉ
๋น๋๊ฐ Windows์์ ์คํ๋๋ ๊ฒฝ์ฐ --trace-process-level <number>
๋๋ --trace-process-name <parent process name>
๋ฅผ ์ค์ ํ์ฌ ํด๋น ์ต์
์ด ๋ถ์ ์ค์ธ ์ฝ๋์ ๋ํ ๋ชจ๋ ๋น๋ ๋จ๊ณ๋ฅผ ๊ด์ฐฐํ๋ ๋ถ๋ชจ CI ํ๋ก์ธ์ค๋ฅผ ๊ฐ๋ฆฌํค๋๋ก ํด์ผ ํฉ๋๋ค.
์ด codeql database init
๋ช
๋ น์ ๋ค์ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
Created skeleton <database>. This in-progress database is ready to be populated by an extractor. In order to initialise tracing, some environment variables need to be set in the shell your build will run in. A number of scripts to do this have been created in <database>/temp/tracingEnvironment. Please run one of these scripts before invoking your build command.
Based on your operating system, we recommend you run: ...
์ด codeql database init
๋ช
๋ น์ CodeQL์ด ๋น๋ ๋จ๊ณ ์ํ์ค๋ฅผ ์ถ์ ํ ์ ์๋๋ก ํ๋ ํ๊ฒฝ ๋ณ์ ๋ฐ ๊ฐ์ด ํฌํจ๋ ํ์ผ๋ก <database>/temp/tracingEnvironment
๋ฅผ ๋ง๋ญ๋๋ค. ์ด๋ฌํ ํ์ผ์ ์ด๋ฆ์ start-tracing.{json,sh,bat,ps1}
์
๋๋ค. ๋ค์ ๋จ๊ณ์์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ๊ธฐ ์ํด CI ์์คํ
์ ๋ฉ์ปค๋์ฆ๊ณผ ํจ๊ป ์ด๋ฌํ ํ์ผ ์ค ํ๋๋ฅผ ์ฌ์ฉํฉ๋๋ค. ๋ง์ผํ
๋ชฉ๋ก์ ๊ตฌ์ฑ์์ ๊ด๋ฆฌํ ์ ์์ต๋๋ค.
- JSON ํ์ผ์ ์ฝ๊ณ , ์ฒ๋ฆฌํ๊ณ , CI ์์คํ
์์ ์์ํ๋ ํ์์ผ๋ก ํ๊ฒฝ ๋ณ์๋ฅผ ์ถ๋ ฅํฉ๋๋ค. ์๋ฅผ ๋ค์ด Azure DevOps์๋
echo "##vso[task.setvariable variable=NAME]VALUE"
๋ฅผ ์์ํฉ๋๋ค. - ๋๋ CI ์์คํ
์ ํ๊ฒฝ์ ์ ์งํ๋ ๊ฒฝ์ฐ ์ ์ ํ
start-tracing
์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ์ฌ CI ์์คํ ์ ์ ธ ํ๊ฒฝ์์ CodeQL ๋ณ์๋ฅผ ์ค์ ํฉ๋๋ค.
์ฝ๋๋ฅผ ๋น๋ํฉ๋๋ค. ์ ํ์ ์ผ๋ก ๋๋ ํฐ๋ฆฌ์ end-tracing.{json,sh,bat,ps1}
์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ์ฌ start-tracing
์คํฌ๋ฆฝํธ๊ฐ ์ ์ฅ๋ ๋๋ ํฐ๋ฆฌ์์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํด์ ํ ๋ค์ codeql database finalize <database>
๋ช
๋ น์ ์คํํฉ๋๋ค.
๊ฐ์ ๋น๋ ์ถ์ ์ ์ฌ์ฉํ์ฌ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ ํ์๋ ๋ค๋ฅธ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ง์ฐฌ๊ฐ์ง๋ก ์์ ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ์ฝ๋ ๊ฒ์์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ถ์ํ๊ณ GitHub์ ๊ฒฐ๊ณผ๋ฅผ ์ ๋ก๋ํฉ๋๋ค.
๊ฐ์ ๋น๋ ์ถ์ ์ ์ฌ์ฉํ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค ์์ฑ ์์
์ฐธ๊ณ ํญ๋ชฉ
Azure DevOps ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋๋ ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ GitHub Advanced Security for Azure DevOps๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค. ์ค๋ช ์๋ Microsoft Learn์์ GitHub Advanced Security for Azure DevOps ๊ตฌ์ฑ์ ์ฐธ์กฐํ์ธ์.
๋ค์ ์์์์๋ Azure DevOps ํ์ดํ๋ผ์ธ์์ ๊ฐ์ ๋น๋ ์ถ์ ์ ์ฌ์ฉํ์ฌ CodeQL ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
steps:
# Download the CodeQL CLI and query packs...
# Check out the repository ...
# Run any pre-build tasks, for example, restore NuGet dependencies...
# Initialize the CodeQL database.
# In this example, the CodeQL CLI has been downloaded and placed on the PATH.
- task: CmdLine@1
displayName: Initialize CodeQL database
inputs:
# Assumes the source code is checked out to the current working directory.
# Creates a database at `<current working directory>/db`.
# Running on Windows, so specifies a trace process level.
script: "codeql database init --language csharp --trace-process-name Agent.Worker.exe --source-root . --begin-tracing db"
# Read the generated environment variables and values,
# and set them so they are available for subsequent commands
# in the build pipeline. This is done in PowerShell in this example.
- task: PowerShell@1
displayName: Set CodeQL environment variables
inputs:
targetType: inline
script: >
$json = Get-Content $(System.DefaultWorkingDirectory)/db/temp/tracingEnvironment/start-tracing.json | ConvertFrom-Json
$json.PSObject.Properties | ForEach-Object {
$template = "##vso[task.setvariable variable="
$template += $_.Name
$template += "]"
$template += $_.Value
echo "$template"
}
# Execute the pre-defined build step. Note the `msbuildArgs` variable.
- task: VSBuild@1
inputs:
solution: '**/*.sln'
msbuildArgs: /p:OutDir=$(Build.ArtifactStagingDirectory)
platform: Any CPU
configuration: Release
# Execute a clean build, in order to remove any existing build artifacts prior to the build.
clean: True
displayName: Visual Studio Build
# Read and set the generated environment variables to end build tracing. This is done in PowerShell in this example.
- task: PowerShell@1
displayName: Clear CodeQL environment variables
inputs:
targetType: inline
script: >
$json = Get-Content $(System.DefaultWorkingDirectory)/db/temp/tracingEnvironment/end-tracing.json | ConvertFrom-Json
$json.PSObject.Properties | ForEach-Object {
$template = "##vso[task.setvariable variable="
$template += $_.Name
$template += "]"
$template += $_.Value
echo "$template"
}
- task: CmdLine@2
displayName: Finalize CodeQL database
inputs:
script: 'codeql database finalize db'
# Other tasks go here, for example:
# `codeql database analyze`
# then `codeql github upload-results` ...
๋ค์ ๋จ๊ณ
- CodeQL CLI๋ฅผ ์ฌ์ฉํ์ฌ ์ฝ๋์์ ๋ง๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ถ์ํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด๋ ค๋ฉด CodeQL ์ฟผ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ์ฝ๋ ๋ถ์์(๋ฅผ) ์ฐธ์กฐํ์ธ์.