fix(codex): 修正 runner 沙箱並改以 OAuth id_token 的 email 驗證登入帳號
codex exec 加上 -s danger-full-access 避免 runner 容器內 bubblewrap 因 無法建立 user namespace 而失敗;action 新增 email output(解析 auth.json id_token 的 email claim),CI 改用 steps.codex.outputs.email 比對 vars.CODEX_EMAIL,不再依賴模型自行回報帳號。
This commit is contained in:
@@ -29,7 +29,7 @@ jobs:
|
|||||||
uses: https://gitea.jsc.idv.tw/composite-actions/codex@v${{ needs.release-tag-version.outputs.version }}
|
uses: https://gitea.jsc.idv.tw/composite-actions/codex@v${{ needs.release-tag-version.outputs.version }}
|
||||||
with:
|
with:
|
||||||
oauth: ${{ secrets.CODEX_OAUTH }}
|
oauth: ${{ secrets.CODEX_OAUTH }}
|
||||||
prompt: "請告訴我目前登入的帳號,只要電子郵件不要其他任何資訊"
|
prompt: "請自我介紹"
|
||||||
- name: 檢查輸出
|
- name: 檢查登入帳號
|
||||||
if: ${{ steps.codex.outputs.text != vars.CODEX_EMAIL }}
|
if: ${{ steps.codex.outputs.email != vars.CODEX_EMAIL }}
|
||||||
run: exit 1
|
run: exit 1
|
||||||
|
|||||||
+16
-1
@@ -13,6 +13,9 @@ outputs:
|
|||||||
text:
|
text:
|
||||||
description: '輸出的文字'
|
description: '輸出的文字'
|
||||||
value: ${{ steps.codex.outputs.text }}
|
value: ${{ steps.codex.outputs.text }}
|
||||||
|
email:
|
||||||
|
description: '目前登入帳號的電子郵件(取自 OAuth id_token)'
|
||||||
|
value: ${{ steps.codex.outputs.email }}
|
||||||
runs:
|
runs:
|
||||||
using: 'composite'
|
using: 'composite'
|
||||||
steps:
|
steps:
|
||||||
@@ -38,11 +41,23 @@ runs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
text="$(codex exec --skip-git-repo-check --model "$MODEL" "$PROMPT")"
|
text="$(codex exec --skip-git-repo-check -s danger-full-access --model "$MODEL" "$PROMPT")"
|
||||||
printf '%s\n' "$text"
|
printf '%s\n' "$text"
|
||||||
|
|
||||||
|
# 從 OAuth id_token(JWT)解出目前登入帳號的 email;正規表示式對冒號後空白容錯
|
||||||
|
auth_file="$HOME/.codex/auth.json"
|
||||||
|
id_token="$(grep -oE -m1 '"id_token"[[:space:]]*:[[:space:]]*"[^"]*"' "$auth_file" | sed -E 's/.*:[[:space:]]*"//; s/"$//' || true)"
|
||||||
|
payload="$(printf '%s' "$id_token" | cut -d. -f2 | tr '_-' '/+')"
|
||||||
|
case $((${#payload} % 4)) in
|
||||||
|
2) payload="${payload}==" ;;
|
||||||
|
3) payload="${payload}=" ;;
|
||||||
|
esac
|
||||||
|
email="$(printf '%s' "$payload" | base64 -d 2>/dev/null | grep -oE -m1 '"email"[[:space:]]*:[[:space:]]*"[^"]*"' | sed -E 's/.*:[[:space:]]*"//; s/"$//' || true)"
|
||||||
|
|
||||||
{
|
{
|
||||||
echo 'text<<CODEX_OUTPUT'
|
echo 'text<<CODEX_OUTPUT'
|
||||||
printf '%s\n' "$text"
|
printf '%s\n' "$text"
|
||||||
echo 'CODEX_OUTPUT'
|
echo 'CODEX_OUTPUT'
|
||||||
|
echo "email=$email"
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$GITHUB_OUTPUT"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
Reference in New Issue
Block a user