以下是使用 **Podman** 將 container image 推送到 [Quay.io](http://quay.io/) 並進行 CVE 掃描的範例指令。假設你已經有 [Quay.io](http://quay.io/) 帳戶並創建了一個 repository,且使用 Podman 作為 container 管理工具。流程與 Docker 類似,但使用 Podman 特有的命令。 ### 前提條件 1. [Quay.io](http://quay.io/) 帳戶和一個 repository(公開或私有)。 2. Podman 已安裝並配置好。 3. 確保你有權限推送 image 到目標 repository。 ### 範例指令 ### 1. 登入 [Quay.io](http://quay.io/) 使用 Podman 登入 [Quay.io](http://quay.io/): ```bash podman login quay.io ``` 輸入你的 [Quay.io](http://quay.io/) 使用者名稱和密碼。如果使用 robot account 或 OAuth token,則: ```bash podman login -u "username+robotname" -p "token" quay.io ``` ### 2. 拉取或準備一個 Container Image 假設你想掃描一個現有的 image(例如 `nginx:latest`)。從 registry 拉取: ```bash podman pull docker.io/library/nginx:latest 或是可以直接從registry拉 podman tag registry.access.redhat.com/ubi8/ubi-minimal:latest quay.io/myquayuser/mytestrepo:v1 ``` 如果使用自己的本地 image(例如 `my-app:latest`),則可跳過此步。 ### 3. 為 Image 打上 [Quay.io](http://quay.io/) 標籤 將 image 重新標記為 [Quay.io](http://quay.io/) 的 repository 格式: ```bash podman tag docker.io/library/nginx:latest quay.io/yourusername/yourrepo:nginx-latest ``` - 將 `yourusername` 替換為你的 [Quay.io](http://quay.io/) 使用者名稱或組織名稱。 - 將 `yourrepo` 替換為你的 [Quay.io](http://quay.io/) repository 名稱。 - 標籤(例如 `nginx-latest`)可自訂。 ### 4. 推送 Image 到 [Quay.io](http://quay.io/) 推送標記好的 image 到 [Quay.io](http://quay.io/): ```bash podman push quay.io/yourusername/yourrepo:nginx-latest ``` 推送完成後,[Quay.io](http://quay.io/) 的 Clair 掃描器會自動對 image 進行 CVE 掃描。 ### 5. 查看掃描結果 1. 登入 [Quay.io](http://quay.io/) 網頁介面([https://quay.io](https://quay.io/))。 2. 導航到你的 repository(`yourusername/yourrepo`)。 3. 點擊對應的 image tag(例如 `nginx-latest`)。 4. 在「Security Report」或「Vulnerabilities」部分,查看 Clair 掃描的 CVE 報告,包含: - CVE 編號 - 嚴重程度(Low, Medium, High, Critical) - 是否可修復(Fixable) - 修復建議(如果適用) ### 6. (可選)使用 API 獲取掃描結果 若需程式化獲取掃描結果,可使用 [Quay.io](http://quay.io/) API。例如: ```bash curl -H "Authorization: Bearer YOUR_TOKEN" \\ <https://quay.io/api/v1/repository/yourusername/yourrepo/manifest/MANIFEST_SHA/security?vulnerabilities=true> ``` - 將 `YOUR_TOKEN` 替換為你的 [Quay.io](http://quay.io/) OAuth token。 - 將 `MANIFEST_SHA` 替換為目標 image 的 manifest digest(在 [Quay.io](http://quay.io/) 介面可找到)。 ### 範例總結 假設你的 [Quay.io](http://quay.io/) 使用者名稱是 `johndoe`,repository 名稱是 `myapp`,完整指令如下: ```bash podman login quay.io podman pull docker.io/library/nginx:latest podman tag docker.io/library/nginx:latest quay.io/johndoe/myapp:nginx-latest podman push quay.io/johndoe/myapp:nginx-latest ``` 然後,前往 [Quay.io](http://quay.io/) 網頁介面查看 `johndoe/myapp:nginx-latest` 的 CVE 掃描結果。 ### 注意事項 - **Podman 與 Docker 的差異**:Podman 不依賴 daemon,指令格式與 Docker 幾乎相同,但使用 `podman` 取代 `docker`。 - **認證儲存**:Podman 將認證儲存在 `$HOME/.config/containers/auth.json`,確保正確配置以避免登入問題。 - **掃描自動化**:[Quay.io](http://quay.io/) 推送後自動觸發 Clair 掃描,無需額外配置。 - **私有 Repository**:若使用私有 repository,確保使用正確的 robot account 或 token。 - **修復漏洞**:檢查掃描報告中的「Fixable」漏洞,並考慮更新基底 image 或套件版本。