配置安全執行環境
說明 Codex Security 從授權接入到 reviewed findings、remediation pull request 的基本流程。
這一篇用 12 分鐘換什麼:把 Codex Security 從"點一下掃一下"重新理解成五步運營閉環——接入 → 掃描 → 等回填 → 完善威脅模型 → 處理 finding 與 PR。讀完後你不會再把"掃描建立成功"當作完成標準。
這頁帶你從 initial access 走到 reviewed findings,以及 Codex Security 中的 remediation pull requests。
開始前,先確認已經設定 Codex Cloud。還沒有的話,從 Codex Cloud 開始。
這不是一篇"開啟開關"的說明。Codex Security 的有效性取決於三件事:repository 是否正確接入 Codex Cloud、scan 是否覆蓋了合適的 history window、threat model 是否能表達真實架構和風險優先順序。
flowchart LR
S1["1️⃣ 接入<br/>Cloud env / 許可權 / secrets"]
S2["2️⃣ 建立掃描<br/>選 branch / history window"]
S3["3️⃣ 等待回填<br/>commit-level pass<br/>可能要數小時"]
S4["4️⃣ 完善威脅模型<br/>架構 / 邊界 / 敏感資料"]
S5["5️⃣ Triage 與修復<br/>finding → PR → review"]
S1 --> S2 --> S3 --> S4 --> S5
S5 -.->|架構變更後| S4
S5 -.->|新入口後| S2
1. Access and Environment
Codex Security 會掃描透過 Codex Cloud connected 的 GitHub repositories。
先確認:
- workspace 已有 Codex Security access。
- 你想掃描的 repository 已在 Codex Cloud 中可用。
開啟 Codex environments,檢查該 repository 是否已有 environment。
如果沒有,請先在那裡建立 environment,再繼續。
入口:
https://chatgpt.com/codex/settings/environments
environment 要檢查什麼
建立 scan 前不要只看 repository 是否出現在列表裡,還要檢查 environment 是否能支撐後續驗證:
- setup steps 是否能安裝依賴。
- 預設 branch 是否正確。
- 構建和測試命令是否能在 cloud environment 中執行。
- secrets 是否只在 setup 階段可用,且沒有進入 agent phase。
- repository 許可權是否只覆蓋需要掃描的範圍。
如果環境本身不能構建或執行關鍵路徑,Codex Security 仍可能產出 findings,但自動驗證質量會下降。安全掃描不是孤立動作,它依賴可復現的工程環境。
2. New Security Scan
environment 存在後,開啟 Create a security scan,並選擇剛剛 connected 的 repository。
入口:
https://chatgpt.com/codex/security/scans/new
Codex Security 會先從 newest commits 往回掃描 repository。它用這種方式在 new commits 進入時構建和重新整理 scan context。
配置 repository:
- 選擇 GitHub organization。
- 選擇 repository。
- 選擇要 scan 的 branch。
- 選擇 environment。
- 選擇 history window。更長的 window 會提供更多 context,但 backfill 需要更長時間。
- 點選 Create。
history window 怎麼選
history window 決定 initial backfill 回看多長的提交歷史。
| 場景 | 建議 |
|---|---|
| 新接入的小儲存庫 | 可以選擇更長視窗,換取更多上下文 |
| 大型 monorepo | 先選擇較短視窗驗證流程,再擴大範圍 |
| 安全事故覆盤 | 覆蓋事故相關時間段和關鍵改動 |
| 只關注新增風險 | 選擇較短視窗,後續依賴增量掃描 |
| 審計前準備 | 預留足夠 backfill 時間,不要臨近釋出才啟動 |
不要為了“更全面”盲目選擇最長視窗。視窗越長,初始掃描越慢,findings 也更需要分層 triage。
3. Initial Scans Can Take a While
建立 scan 後,Codex Security 會先對 selected history window 執行 commit-level security pass。
initial backfill 可能需要幾個小時,尤其是 larger repositories 或 longer windows。
如果 findings 沒有立刻出現,這是 expected behavior。請等待 initial scan 完成後,再開 ticket 或 troubleshooting。
initial scan setup 是 automatic 且 thorough 的,可能需要幾個小時。第一批 findings 延遲出現時,不需要緊張。
初始等待期間做什麼
等待 backfill 時,可以先準備這些材料:
- 當前 repository 的系統邊界說明。
- 外部入口列表,例如 HTTP API、webhook、CLI、worker、上傳入口。
- 敏感資料路徑,例如 token、支付、使用者隱私、內部管理操作。
- 已知高風險模組,例如 auth、permission、serialization、file parsing。
- 負責 review findings 的 code owner 和 security owner。
這些材料會在下一步 threat model review 中用到。
4. Review Scans and Improve the Threat Model
review scans 入口:
https://chatgpt.com/codex/security/scans
initial scan 完成後,開啟 scan,review 自動生成的 threat model。
initial findings 出現後,更新 threat model,讓它匹配你的 architecture、trust boundaries 和 business context。
這會幫助 Codex Security 為你的 team rank issues。
如果你希望 scan results 改變,可以編輯 threat model,更新 scope、priorities 和 assumptions。
initial findings 出現後,要 revisit model,讓 scan guidance 持續對齊當前 priorities。
保持 threat model current,有助於 Codex Security 產出更好的 suggestions。
關於 threat models 如何影響 criticality 和 triage,見 Improving the threat model。
threat model review 模板
開啟自動生成的 threat model 後,至少補齊下面幾類資訊:
Repository type:
主要服务形态,例如 public API、SaaS backend、CLI、desktop app、worker。
Entry points:
外部请求、webhook、文件上传、命令行参数、后台任务、第三方回调。
Trust boundaries:
用户到服务、服务到内部服务、CI 到生产、浏览器到 API、插件到主进程。
Sensitive data:
token、账号、支付、密钥、用户内容、内部配置、审计日志。
High-priority review areas:
认证、授权、输入解析、文件处理、权限提升、依赖边界。編輯後的 threat model 應該短,但不能空泛。它要讓掃描器知道“這個儲存庫真正危險的地方在哪裡”。
5. Review Findings and Patch
initial backfill 完成後,在 Findings view 中 review findings。
入口:
https://chatgpt.com/codex/security/findings
有兩個 view:
- Recommended Findings:repo 中最 critical issues 的動態 top 10 list。
- All Findings:覆蓋 repository 的 sortable、filterable findings table。
Recommended findings view:
https://developers.openai.com/codex/security/images/aardvark_recommended_findings.png
點選 finding 可以開啟 detail page,其中包括:
- issue 的 concise description。
- commit details 和 file paths 等 key metadata。
- 關於 impact 的 contextual reasoning。
- relevant code excerpts。
- 可用時包含 call-path 或 data-flow context。
- validation steps 和 validation output。
你可以 review 每個 finding,並直接從 finding detail page 建立 PR。
review findings 並建立 PR 的入口:
https://chatgpt.com/codex/security/findings
Review finding 的順序
每個 finding 建議按這個順序看:
- 看 title 和 severity,只作為初篩。
- 看 affected files 和 commit context,確認是否在真實程式碼路徑裡。
- 看 root cause,判斷是否和 threat model 裡的入口或邊界相關。
- 看 validation output,確認是否有復現證據。
- 看 suggested patch,判斷是否最小、可維護、符合團隊風格。
- 看測試覆蓋,決定是否補 security regression test。
- 決定 reject、defer、open PR 或手動改寫 patch。
不要把 validation success 當成合併許可。它只說明問題更值得審查,不說明補丁可以跳過 code review。
Remediation PR 的標準
從 finding detail page 建立 PR 前,至少確認:
- patch 沒有擴大許可權邊界。
- patch 沒有吞掉錯誤或隱藏異常。
- patch 有測試或可復現驗證。
- patch 沒有把風險轉移到呼叫方。
- 變更範圍聚焦在 finding 相關程式碼。
- code owner 能看懂修復意圖。
安全補丁比普通功能補丁更需要小範圍、可復現、可回復。
運營節奏
Codex Security 接入後建議形成固定節奏:
| 週期 | 動作 |
|---|---|
| 每週 | Review recommended findings,處理 top risk |
| 每次架構變化後 | 更新 threat model |
| 每次新增外部入口後 | 檢查 scan context 是否覆蓋 |
| 每次重大 release 前 | 複查高危 findings 和 deferred findings |
| 每次誤報後 | 記錄原因,調整 threat model 或環境 |
如果 findings 長期沒人 review,掃描價值會快速下降。工具負責發現和證據,人負責取捨和閉環。
完成標準
一輪安全 scan 不應以“scan 建立成功”為完成標準。更可靠的完成標準是:
- repository 和 environment 接入正確。
- initial backfill 已完成。
- threat model 已人工 review 並更新。
- recommended findings 已被 triage。
- 高危 findings 有 owner 和處理狀態。
- proposed patch 已經過 code review。
- 關鍵修復有迴歸測試或驗證記錄。
相關文件
- Codex Security:product overview。
- FAQ:common questions。
- Improving the threat model:如何 improve scan context 和 finding prioritization。
- Codex Security setup:access、environment、scan、findings 和 PR workflow。