📌 專案摘要與合規定位 📌 Executive Summary & Compliance Positioning
本儲存庫為一項企業管治示範專案,展示如何以輕量級 Streamlit 介面、動態 Secrets 隔離與確定性「治理即代碼」(Governance-as-Code)構建地盤入職安全訓練評估閉環。
This repository is an Enterprise Demo demonstrating a Zero-Data-Retention safety onboarding assessment and archiving workflow built with Streamlit, isolated Cloud Secrets, and deterministic Governance-as-Code.
傳統地盤紙本入職安全考核常面臨字跡難以辨識、缺乏標準時間戳、紙本易遺失及審計調閱耗時等風險。EnterpriseDemo-Safety-Quiz 針對香港法定職安健要求(第 59 章《工廠及工業經營條例》)及國際管理體系(ISO 45001 / ISO 9001 / ISO/IEC 27001)設計,在不架設雲端資料庫、零個人資料持久化(Zero-Data-Retention)的前提下,讓新進工友即時完成安全測驗並自動生成受控 PDF 報告(DEMO-SED-REC-001),一鍵透過後端 SMTP 直送安全及環保組(SED)郵箱,亦可無縫銜接下游 Microsoft 365 SharePoint 自動化歸檔藍圖。
Paper-based construction site safety induction tests suffer from illegible records, missing timestamps, loss of forms, and manual filing overhead. EnterpriseDemo-Safety-Quiz aligns with Hong Kong occupational safety requirements (FIUO Cap. 59) and international standards (ISO 45001 / ISO 9001 / ISO/IEC 27001). Without provisioning any external database, worker inputs exist strictly in volatile session memory to render a controlled PDF record (DEMO-SED-REC-001) and dispatch it via encrypted SMTP to the Safety & Environmental Department (SED), ready for downstream M365 SharePoint auto-archiving.
在法規邊界定性上,本系統完全採用確定性單選比對邏輯(Deterministic Rule-Based Logic),不含任何 AI / 機器學習模型或自主演算法,明確排除於《歐盟人工智能法案》(EU AI Act)及 ISO/IEC 42001 適用範圍之外,同時全面對齊香港《個人資料(私隱)條例》(第 486 章)保障資料原則(DPP 1–4)。
From a regulatory boundary perspective, this application relies strictly on deterministic exact-match grading logic (Non-AI) with zero machine learning or autonomous decision models—explicitly scoping out EU AI Act and ISO/IEC 42001 obligations while adhering to Hong Kong PDPO (Cap. 486) Data Protection Principles (DPP 1–4).
🏛️ 流程生命週期與安全歸檔閉環 🏛️ End-to-End Assessment Lifecycle & Archiving Closure
系統透過 Session State 嚴謹鎖定兩階段引導流程,配合防重複提交機制與下游自動化藍圖,達成 100% 封閉式安全合規閉環:
Enforcing a strict two-stage Session State workflow with duplicate-dispatch locks and downstream M365 blueprints to achieve a 100% closed-loop safety audit trail:
支援專屬連結參數 ?key=... 直入或通行碼核驗,防範未授權存取。Supports direct URL key parameters (?key=...) or access code verification.
輸入姓名、工人註冊證及組別,完成 5 題核心地盤職安健試題並勾選誠信聲明。Captures Name, Worker Reg No., Dept, 5 core site safety questions, and integrity consent.
即時核對動態 Secrets 題庫答案,答對 ≥3 題(60%)判定為 PASS。Evaluates answers against isolated Secrets bank; ≥3/5 (60%) required for PASS.
嵌入 UTC+8 香港時間戳、DEMO-SED-REC-001 編號、答題明細與法律聲明。Embeds HKT (UTC+8) timestamp, DEMO-SED-REC-001 ID, answer log, and notice.
後端 SMTP TLS 直送 SED 郵箱,對接 Power Automate 自動存入 SharePoint 檔案庫。Dispatches PDF via TLS SMTP to SED inbox, triggering M365 SharePoint archival flow.
📋 業務治理與權限隔離矩陣 📋 Governance & Control Isolation Matrix
| 階段Stage | 責任角色Role | 承載技術Technology Stack | 處置動作與合規控制機制Action & Governance Control |
|---|---|---|---|
| 一、身份識別1. Identification | 新入職工友New Site Worker | Streamlit Session Gate | 通過門禁核驗後填報姓名、工人註冊證號碼及所屬組別;輸入即時經 clean_text() 過濾消毒。Authenticates via gate and submits Name, Worker Reg No., and Dept; sanitized via clean_text(). |
| 二、安全考核2. Safety Quiz | 新入職工友New Site Worker | Secrets 動態題庫引擎Dynamic Secrets Quiz Bank | 完成安全帽、護眼罩、安全帶、意外通報及危害報告等 5 題考核,強制勾選個人獨立填答聲明。Completes 5 core PPE, height safety, and incident reporting items with mandatory integrity consent. |
| 三、能力評定3. Evaluation | 確定性計分核心Deterministic Engine | Python Exact-Match Logic | 依循 schemas/questions_schema.json 驗證結構,執行 ≥60%(3/5 題)合格門檻判定,滿足 ISO 45001 Clause 7.2。Validates against questions_schema.json and enforces ≥60% (3/5) pass threshold per ISO 45001 Clause 7.2. |
| 四、文件存證4. Record Rendering | 受控 PDF 引擎Controlled PDF Engine | FPDF (Noto Sans TC) | 於記憶體即時渲染含 IMS 受控標頭、HKT 時間戳與完整答題紀錄之 PDF 檔案,關閉分頁即刻銷毀暫存。Renders IMS-controlled PDF with HKT timestamp and answer log in RAM; volatile state clears on exit. |
| 五、自動歸檔5. Auto-Archiving | 安環組 (SED)SED Compliance Team | Python SMTP + M365 Flow | 一鍵加密寄送至審計郵箱並附設防重複鎖,對接 Flow_EmailToSharePointArchive.json 存入受控文件庫,另備本地下載與 WhatsApp 通道。One-click TLS email dispatch with dedup lock feeding SharePoint archival blueprint, plus local PDF backup & WhatsApp fallback. |
🧮 互動式安全考核、輸入消毒與受控 PDF 存證模擬器 🧮 Interactive Safety Quiz, Input Sanitization & Controlled Record Simulator
在此直接體驗前端考核、輸入消毒防注入(試著在姓名輸入 / * ? <>)、誠信聲明檢查門閘,以及 60% 合格門檻即時運算與 DEMO-SED-REC-001 受控存證預覽:
Test the frontline assessment logic, filename input sanitization (try typing / * ? <> in Name), integrity declaration gate, 60% pass threshold, and live DEMO-SED-REC-001 controlled record preview directly below:
| # | 地盤安全評估試題(最少答對 3 題合格)Site Safety Assessment Question (Min. 3 Correct to Pass) | 模擬作答選項Simulated Worker Selection | 判定Check |
|---|
⚙️ 技術亮點與合規工程實踐 ⚙️ Technical & Compliance Engineering Highlights
1. 零資料留存架構Zero-Data-Retention
無外置資料庫或雲端檔案桶,個人資料僅於記憶體暫存用於單次 PDF 渲染,完畢立即釋放,從根源杜絕資料庫外洩。No external DB or storage bucket; PII resides strictly in session RAM for one-time PDF rendering before automatic purge.
2. 動態 Secrets 機密隔離Dynamic Secrets Isolation
題庫答案、門禁通行碼與 SMTP 憑證均抽離至雲端環境變數保管,公開倉庫 100% 零機密暴露,支援免重部署更新試題。Quiz keys, access codes, and SMTP credentials live solely in Cloud Secrets—zero repo exposure with hot-swappable quiz banks.
3. 輸入消毒與檔名防護Input & Filename Sanitization
強制限制欄位長度並以正則過濾換行及 \/*?:"<>| 等危險字元,防範注入與路徑穿越(Path Traversal)攻擊。Enforces strict character caps and regex sanitization of control/path characters to block injection and traversal attacks.
4. 香港時區標準化存證HKT Timezone Normalization
底層統一鎖定 UTC+8 香港標準時間(HKT)蓋印 PDF 報告與審計紀錄,確保完全符合本地法定安全稽核查驗要求。Standardizes all PDF timestamps to Hong Kong Time (UTC+8 HKT) to guarantee consistent legal and IMS audit traceability.
5. 確定性非 AI 治理邊界Non-AI Regulatory Scope-Out
刻意採用透明確定性規則比對,不含任何 AI/ML 演算法,主動排除 EU AI Act 及 ISO/IEC 42001 監管合規負擔。Deliberately utilizes transparent rule-based matching with zero AI/ML models, cleanly scoping out EU AI Act and ISO 42001.
6. 下游 M365 自動歸檔藍圖Downstream M365 Blueprint
附帶 JSON Schema 校驗規範與 Power Automate 藍圖,可零額外授權將 SMTP 郵件附件自動轉存至受控 SharePoint 文件庫。Ships with JSON Schemas and a Standard-Connector Power Automate blueprint to auto-archive emailed PDFs into SharePoint.