chore(security): untrack .env - #231
Conversation
.env was tracked despite .gitignore already listing it (lines 12, 48). Inspected the tracked file (without echoing values): it contains no assignments at all — a stray '*.secret' line and pasted gemini-cli cheat-sheet text. Full-history audit across all commits touching .env found no real-looking value, so no rotation is required. - git rm --cached .env (file stays on disk, now ignored) - .env.example already provides the placeholder template - See SECRETS-SETUP.md for moving values to GitHub Secrets
|
เห็นว่าคุณเปิดไฟล์
และคุณพูดถึง error "Command 'gemini-cli' cannot run while the agent is active" ที่เกิดขึ้นใน VS Code/CLI. 🔐 การจัดการ Secrets ใน GitHub Actionsแทนที่จะเก็บค่าเหล่านี้ใน
🛠 การแก้ Error "Agent Active"
⚙️ การตั้งค่า Provider อื่น ๆ
✅ แนวทางที่ปลอดภัย
คุณอยากให้ผมช่วยเขียน ตัวอย่าง workflow YAML ที่รวมการใช้ secrets เหล่านี้กับ FastAPI pipeline ของคุณเลยไหมครับ? จะได้เป็น production‑ready CI/CD spec ที่ปลอดภัยและตรงกับสไตล์ที่คุณใช้ (DAG, caching, security scans). |
|
ผมดูไฟล์ 🔐 สิ่งที่ควรทำกับ
|
|
ผมเห็นว่าคุณเปิดไฟล์ 🔐 สิ่งที่ควรทำกับไฟล์
|
zyntromedia
left a comment
There was a problem hiding this comment.
@fig find better quality .env >>>check project structure and write)
zyntromedia
left a comment
There was a problem hiding this comment.
@fig suggest .env files for best depending project structure.
main rewrote .env after this PR was opened, producing a modify/delete conflict. Resolution keeps this PR's intent: .env stays untracked and ignored (verified with git check-ignore). Refs #231
…emplates
Review feedback asked for higher-quality .env files that match the project
structure. The repo is a multi-component monorepo — the code reads 148
distinct env vars while the single root .env.example declared 16 — so one
root file cannot document it.
- Add .env.example beside each component that reads env: graphql_api/,
frontend/, scripts/, deliverables/{pm-backend,fastapi-obsidian-backend,
agent-security-suite,manus-client}, deliverables/product-crud/{server,web}
- Rewrite the root .env.example: grouped by concern, every var annotated with
the file that reads it, plus the docker-compose substitutions
- Fix .gitignore: `.env.*` was swallowing every per-component .env.example.
New templates were invisible to git and would never have been committed.
Adds !.env.example / !**/.env.example negations; .env stays ignored
- Add docs/ENVIRONMENT.md: layout, precedence, core-app variable reference,
the service-name-vs-localhost rule, secrets policy, CI secret list, and the
deliberate tracked-.env fixture
Two undocumented gaps found and closed while writing this:
- app/ reads JWT_SECRET (app/core/config.py) and JWT_SECRET_KEY (app/config.py)
from the same .env. Setting only one makes every token fail verification
while login still succeeds. Both now documented with that warning.
- SENTRY_DSN, CACHE_ENABLED, CACHE_TTL had no template entry.
Verified: 11 templates parse; every declared key resolves to a real code read
(scripts/validate_env_templates.py — 0 failures, 0 warnings); all 23 vars read
by app/ are documented; .env still ignored at every level; the fig-best-practices
broken-project .env remains tracked as its test fixture requires.
Refs #231
…alidator Records PR #231 per the repo's Definition of Done, and moves the env-template verification out of an author's workspace and into the repository so it can be re-run: - scripts/validate_env_templates.py — parses every .env.example, asserts keys are well-formed and unique, rejects values that look like real secrets, and requires each declared key to resolve to an actual read in the component it documents. Also asserts every variable the core app reads is documented. Exits non-zero on failure so it can gate CI. - new.inprogress.done/inprogress/TASK-20260915-001 — task record with scope, out-of-scope decisions, acceptance criteria and actual validation output. - CHANGELOG.md — 2026-09-15 section. Validation: `python3 scripts/validate_env_templates.py` -> 0 failures, 0 warnings, exit 0. `python3 -m pytest tests/` in new.inprogress.done/ -> 20 passed. Refs #231
ทำตาม review แล้วครับ —
|
| Component | Template | ตัวแปร |
|---|---|---|
| Core FastAPI app | .env.example (เขียนใหม่) |
43 |
| GraphQL API | graphql_api/.env.example |
11 |
| Frontend (Vite) | frontend/.env.example |
1 |
| Ops scripts | scripts/.env.example |
8 |
| PM backend | deliverables/pm-backend/.env.example |
10 |
| Obsidian backend | deliverables/fastapi-obsidian-backend/.env.example |
7 |
| Agent security | deliverables/agent-security-suite/.env.example |
3 |
| Manus client | deliverables/manus-client/.env.example |
2 |
| product-crud server | deliverables/product-crud/server/.env.example |
4 |
| product-crud web | deliverables/product-crud/web/.env.example |
2 |
ทุกไฟล์มี comment ว่าตัวแปรถูกอ่านจาก source ไฟล์ไหน + ค่า default จริงจากโค้ด
เจอ 2 บั๊กที่ต้องแก้ก่อน ไม่งั้นงานไม่เข้า commit
1. .gitignore บรรทัด 49 (.env.*) match .env.example ทุกชั้น
ตอนแรกเขียน template ลงดิสก์ครบ แต่ git status สะอาด — เพราะ .env.* กิน .env.example ด้วย ไฟล์จะอยู่บนเครื่องแต่ไม่เคยเข้า commit เพิ่ม negation แล้ว โดย .env ยัง ignore เหมือนเดิม:
.env.*
!.env.example
!**/.env.example2. JWT อ่านคนละชื่อจาก .env ไฟล์เดียวกัน
app/core/config.py→JWT_SECRETapp/config.py→JWT_SECRET_KEY
ตั้งตัวเดียว → login ผ่าน แต่ token ทุกอัน verify ไม่ผ่าน (401) เพราะคนละ key ในไฟล์เดียวกัน ทั้งคู่ documented พร้อมคำเตือนแล้ว
เพิ่มให้ครบด้วย: SENTRY_DSN, CACHE_ENABLED, CACHE_TTL ซึ่งไม่มีใน template เลย
เอกสาร
docs/ENVIRONMENT.md — layout, precedence, ตารางตัวแปร core app, กฎ service-name vs localhost, secrets policy, รายการ CI secrets
ตรวจซ้ำได้เอง
scripts/validate_env_templates.py อยู่ใน repo:
PASS .env.example (43 vars)
PASS graphql_api/.env.example (11 vars)
...
RESULT: 0 failures, 0 warnings
เช็คว่า (1) ทุก template parse ได้ (2) ทุก key resolve กลับไปหาการอ่านจริงใน source ของ component นั้น (3) ทุกตัวแปรที่ app/ อ่าน ถูก document แล้ว
ที่ยังไม่แตะ
deliverables/fig-best-practices/examples/broken-project/.env— เป็น test fixture ที่ quality gate assert อยู่ ลบแล้วเทสต์จะกลายเป็น vacuousVAULT_ADDR,VAULT_ROLE,ALERT_SLACK_WEBHOOK— ไม่มีโค้ดอ่านเลย จึง label เป็น Reserved ไม่ลบ เพื่อรอ broker/Vault rollout
`deliverables/docs-verify/` compares the README's declared `docs/` count against the tree. Adding docs/ENVIRONMENT.md moved the real count to 38 while the README still declared 37, so the gate flagged it — caught on a fresh run against the branch. Corrected, and `environment configuration` added to the description of what the directory holds. docs-verify now reports 16/17; the single remaining failure is P-001 (the five unparseable workflow files), which fails identically on main's own head. Refs #231
|
@zyntromedia ขอ review อีกครั้งครับ — มี commit ใหม่ 3 ตัวหลัง review ของคุณ และ PR เป็น ready for review แล้ว สำคัญ: review ทั้ง 4 อันของคุณ (รวม 2 อันที่ ตอบโจทย์ review: ".env files for best depending project structure"สแกนทั้ง repo ก่อนเขียน — โค้ดอ่าน env 148 ตัวแปร แต่ root
ทุกไฟล์มี comment ว่าตัวแปรถูกอ่านจาก source ไฟล์ไหน พร้อมค่า default จริงจากโค้ด 2 บั๊กที่เจอระหว่างทาง (แก้แล้ว)1. 2. JWT อ่านคนละชื่อจาก ตรวจซ้ำได้เอง
CI แดงไม่ได้มาจาก PR นี้head ของ |
|
@zyntromedia ขอถามเรื่องไทม์ไลน์ครับ — PR นี้พร้อม review แล้ว (commit ที่ต้องมีคือ approve ใหม่บน commit ล่าสุด เพราะ review ทั้ง 4 อันของคุณส่งบน ถามตรง ๆ สองข้อครับ:
ไม่มีอะไรต้องแก้เพิ่มรออยู่ — เหลือแค่ approve ครับ |
Do it yourself! |
Summary
.envถูก track อยู่ที่ root ทั้งที่ทั้ง repo อ่าน env 148 ตัวแปร คนละชุดกันตาม component — ไฟล์เดียวจึงทั้ง document ไม่ครบ และเก็บ secret ไม่ได้ PR นี้ทำให้.envไม่ถูก track ทุกจุด และย้าย env template ไปอยู่ข้างโค้ดของแต่ละ componentWhat changed
Untrack
git rm --cached .env— ไฟล์ยังอยู่บนเครื่อง แต่ git ไม่ track และ ignore แล้วmain→ ตอนนี้mergeable: truePer-component templates (ตอบ review: ".env files for best depending project structure")
graphql_api/,frontend/,scripts/deliverables/{pm-backend, fastapi-obsidian-backend, agent-security-suite, manus-client}deliverables/product-crud/{server,web}Rewritten root
.env.exampledocker-composesubstitutions (DB_PASSWORD,MINIO_PASSWORD,GRAFANA_PASSWORD)docs/ENVIRONMENT.md— layout, precedence, ตารางตัวแปรของ core app, กฎ service-name vs localhost, secrets policy, รายการ CI secrets, และ.envที่ track อยู่โดยเจตนาTwo defects found and fixed
1.
.gitignoreline 49 (.env.*) match.env.exampleทุกชั้นตัว template ที่ PR นี้เพิ่มจะถูกเขียนลงดิสก์ แต่ git ignore เงียบ ๆ —
git statusสะอาด แต่งานไม่เข้า commit เลย เพิ่ม negation!.env.example/!**/.env.exampleแล้ว โดย.envยัง ignore เหมือนเดิม2. JWT อ่านคนละชื่อจาก
.envไฟล์เดียวกันapp/core/config.pyJWT_SECRETapp/config.pyJWT_SECRET_KEYตั้งอันเดียว → login ผ่าน แต่ token ทุกอัน verify ไม่ผ่าน (401) งงมากเพราะ login สำเร็จ ทั้งคู่ documented พร้อมคำเตือนแล้ว รวมถึง
SENTRY_DSN,CACHE_ENABLED,CACHE_TTLที่ไม่มีใน template เลยVerification
python3 scripts/validate_env_templates.py0 failures, 0 warnings, exit 0git check-ignore -v --no-index <each>.env.examplegit check-ignore -v --no-index .env.gitignore:48:.env— ยัง ignoregit merge-base --is-ancestor origin/main HEADpython3 -m pytest tests/(new.inprogress.done/)scripts/validate_env_templates.pyอยู่ใน repo เพื่อให้เช็คซ้ำได้เองNote — CI แดงไม่ใช่จาก PR นี้
lint/Python 3.11/Python 3.12fail ที่ขั้น "Set up job":เป็น pin ที่ resolve ไม่ได้ และ head ของ
mainเองก็ fail เหมือนกัน (5fca616) — CI แดงทั้ง repo มาก่อนแล้ว ตรงกับ P-001 ซึ่งยังถูก block เพราะ App ไม่มีworkflowspermission PR นี้ไม่แตะ.github/เลยแม้แต่ไฟล์เดียว