處理 AI review findings 並改寫 Node.js entrypoint #1
@@ -1,10 +1,26 @@
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
# 安裝必要的工具
|
# 安裝必要的工具
|
||||||
RUN apk add --no-cache --no-check-certificate bash
|
RUN apk add --no-cache --no-check-certificate bash ca-certificates curl git
|
||||||
|
|
||||||
|
# 設定安裝用的環境變數
|
||||||
|
ENV CODEX_NON_INTERACTIVE=1
|
||||||
|
ENV CODEX_INSTALL_DIR=/usr/local/bin
|
||||||
|
ENV CODEX_HOME=/root/.codex
|
||||||
|
|
||||||
|
Ghost marked this conversation as resolved
|
|||||||
|
# 安裝 Codex CLI 工具
|
||||||
|
RUN curl -fsSL https://chatgpt.com/codex/install.sh | sh
|
||||||
|
|
||||||
|
# 安裝 doc 技能
|
||||||
|
RUN codex plugin marketplace add https://gitea.jsc.idv.tw/plugins/doc.git \
|
||||||
|
&& codex plugin add jsc@doc
|
||||||
|
|
||||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Leo
**問題**:在 Dockerfile 中直接使用 `curl` 下載並執行安裝腳本 (`sh "$install_script"`) 存在潛在的安全風險與不確定性,且沒有檢查腳本的完整性或簽章。若腳本內容在未來變更,可能導致映像檔建置失敗或植入非預期的內容,增加維護與安全風險。
**建議**:建議將安裝腳本改為明確的版本化下載,或者如果可能,將安裝邏輯整合進 Dockerfile 自身,以確保建置過程的冪等性與安全性。
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Leo
**問題**:在 Dockerfile 中直接使用 `curl` 下載並執行安裝腳本存在潛在的安全風險與不確定性,且沒有檢查腳本的完整性或簽章。若腳本內容在未來變更,可能導致映像檔建置失敗或植入非預期的內容。
**建議**:建議將安裝腳本改為明確的版本化下載,或者將安裝邏輯整合進 Dockerfile 自身。
gitea-actions
commented
嚴重等級:🔴 嚴重 **嚴重等級**:🔴 嚴重
**審查員**:Assassin
**問題**:Dockerfile 直接從外部連結下載並執行腳本,且未驗證其雜湊值,若來源遭攔截或篡改,將導致任意程式碼執行。
**建議**:下載指令碼後,務必使用 sha256sum 或其他雜湊函數驗證其完整性,確保與預期內容一致後再執行。
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Bard
**問題**:將安裝腳本邏輯直接寫在 `RUN` 指令中顯得冗長,且使用 `$(mktemp)` 容易產生難以追蹤的臨時檔案。
**建議**:考慮將安裝邏輯封裝成一個獨立的 script 檔案,讓 `Dockerfile` 更簡潔優雅。
|
|||||||
|
# 安裝 code-review 技能
|
||||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Mage
**問題**:若 sh "$install_script" 安裝過程失敗,rm -f 由於被 && 連接,不會被執行,導致 build 過程中殘留不必要的暫存檔案,雖然 Docker Layer 會自動清除,但仍屬不佳的清理實作。
**建議**:建議改用 trap 進行清理,或確保 rm -f 指令在 failure 情境下也能執行,例如:sh "$install_script" || { rm -f "$install_script"; exit 1; }
|
|||||||
|
RUN codex plugin marketplace add https://gitea.jsc.idv.tw/plugins/code-review.git \
|
||||||
|
&& codex plugin add jsc@code-review
|
||||||
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Leo
**問題**:插件 URL 與版本參照 (REF) 硬編碼在 Dockerfile 中,未來若需更新插件或更換來源,需重新編譯整個 Docker 映像檔,維護成本較高。
**建議**:建議將這些插件清單與版本資訊移至外部設定檔 (如 plugins.json),並在 Dockerfile 中讀取該檔案進行安裝,增加彈性。
|
|||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|||||||
@@ -1,20 +1,24 @@
|
|||||||
name: 'Docker Action Template'
|
name: 'Codex CLI'
|
||||||
description: 'Docker Action 範本'
|
description: 'Codex CLI Action'
|
||||||
author: 'Jeffery'
|
author: 'Jeffery'
|
||||||
inputs:
|
inputs:
|
||||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Bard
**問題**:輸入參數 `oauth` 實質為 base64 編碼的 json,命名易生誤解。
**建議**:建議更名為 `auth_config` 或 `encoded_auth_json`。
|
|||||||
runner_token:
|
oauth:
|
||||||
description: 'Gitea Runner Token'
|
description: 'Base64 encoded Codex auth.json'
|
||||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Leo
**問題**:將 Base64 編碼的認證資訊設為 Action input,導致明文暴露在 Workflow 配置中,難以維護。
**建議**:應改為直接使用 Action 的 Secrets 機制(如 `secrets.CODEX_AUTH`),將認證資訊與設定分離。
|
|||||||
required: true
|
required: true
|
||||||
text:
|
model:
|
||||||
description: '輸入的文字'
|
description: 'Codex model name'
|
||||||
default: "Hello, World!"
|
required: true
|
||||||
|
prompt:
|
||||||
|
description: 'Prompt for codex exec'
|
||||||
|
required: false
|
||||||
|
default: '請自我介紹'
|
||||||
outputs:
|
outputs:
|
||||||
text:
|
text:
|
||||||
description: '輸出的文字'
|
description: 'Execution result status'
|
||||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Bard
**問題**:輸出欄位命名為 `text`,但賦值內容為「執行狀態(status)」,語義不符。
**建議**:將欄位名稱改為 `status`,以保持命名與意圖一致。
|
|||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'Dockerfile'
|
||||||
env:
|
env:
|
||||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
OAUTH: ${{ inputs.oauth }}
|
||||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
MODEL: ${{ inputs.model }}
|
||||||
RUNNER_TOKEN: ${{ inputs.runner_token || secrets.GITEA_TOKEN || secrets.RUNNER_TOKEN }}
|
PROMPT: ${{ inputs.prompt }}
|
||||||
|
|||||||
@@ -1,11 +1,24 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "Gitea Server Url: $GITEA_SERVER_URL"
|
set -euo pipefail
|
||||||
|
|
||||||
echo "Gitea Repository: $GITEA_REPOSITORY"
|
if [[ -z "${OAUTH:-}" ]]; then
|
||||||
|
echo "OAUTH is required: provide base64 encoded Codex auth.json." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Gitea Runner Token: $RUNNER_TOKEN"
|
if [[ -z "${MODEL:-}" ]]; then
|
||||||
|
echo "MODEL is required." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Input Text: $INPUT_TEXT"
|
CODEX_HOME="${CODEX_HOME:-/root/.codex}"
|
||||||
|
mkdir -p "$CODEX_HOME"
|
||||||
|
printf '%s' "$OAUTH" | base64 -d > "$CODEX_HOME/auth.json"
|
||||||
|
chmod 600 "$CODEX_HOME/auth.json"
|
||||||
|
|
||||||
echo "text=$INPUT_TEXT" >> "$GITHUB_OUTPUT"
|
codex exec --dangerously-bypass-approvals-and-sandbox --model "$MODEL" "$PROMPT"
|
||||||
|
|
||||||
|
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
|
||||||
|
echo "text=completed" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|||||||
嚴重等級:🟡 警告
審查員:Assassin
問題:Codex 外掛市集來源指向
gitea.jsc.idv.tw,未驗證來源的安全性。若該伺服器遭駭,將導致自動安裝惡意或篡改過的外掛,進而導致供應鏈攻擊。建議:若可能,請將外掛來源固定在受信任的內部儲存庫或使用經簽署的外掛版本。確保來源伺服器具有嚴格的存取控管與安全性掃描。
嚴重等級:🟡 警告
審查員:Leo
問題:環境變數使用以空格分隔的字串,若未來名稱中包含空格將導致 shell 展開錯誤,且難以維護。
建議:建議改用換行符號(
)分隔,並在安裝迴圈中使用
IFS=$' '處理,以提高 shell 指令的健壯性。