Harbor v2.5遠端複製:製品的簽名如影隨形
題圖攝於美國加州蒙特雷港
( 本文根據 Harbor 社群經理 Orlin Vasilev 的英文部落格改編,感謝 CNCF公眾號的初始翻譯和 Harbor 維護者團隊提供的測試環境。)
相關資訊:
招聘雲原生工程師(參見另一篇)
經過社群維護者們的通力合作,Harbor v2.5 於上週釋出了,新版本為使用者們帶來了如下幾個重要的新特性。
-
Cosign 簽名的引入,使得製品(映象等)複製時簽名可以同步複製。
-
提高了併發拉取請求的效能。
-
改進了垃圾回收功能的容錯性,當刪除某個製品(Artifact)發生錯誤時,可繼續刪除其他製品。
-
複製中可跳過在代理快取專案中的製品。
-
啟用 Distribtion purging 功能,可以刪除 upload 目錄中的孤立檔案。
-
使用 Golang v1.17.7 構建的。
-
使用 Distribution v2.8.0 和 Trivy v0.22.0。
本篇 著重給大 家介紹一下的是 Cosign, 它是 Harbor 2.5 重要功能。
在 Harbor 製品(Artifact)倉庫中,製品的簽名和簽名驗證是關鍵的安全功能之一,可幫助使用者檢查製品的完整性。Harbor 2.5通過與另外兩個開源專案 Notary [1] 和 Cosign [2] 的整合,支援了內容信任,其中 Cosign 是新增的功能。
Cosign 是一個 OCI 製品簽名和驗證解決方案,是 Sigstore 開源專案 [3] 的一部分。
用 Cosign 對 OCI 製品簽名後,可將生成的簽名推入(push)到 Harbor 中。這個簽名作為製品的附件(accessory)和該製品一起儲存。Harbor 管理和維護已簽名製品和 cosign 簽名之間的聯絡,在Tag保留規則(tag retention rules)和不可變規則(immutable rules)等功能中,Harbor的內建功能自動維護製品和簽名之間的對應關係。
將 Cosign 與 Harbor 結合使用解決了之前一個懸而未決的問題:映象等製品在遠端複製中,其簽名信息無法被複制到目標端。現在,當用戶通過複製規則(replication rule)把已簽名製品複製到遠端時,Harbor 把簽名信息也同步複製到了遠端,使得遠端的製品具有同樣的簽名。
你可以參閱 完整文件 [5] 瞭解更多。
功能設定示例
兩個Harbor v2.5例項預設對每個倉庫專案啟用了 Cosign 的設定。通過配置兩個Harbor例項的複製規則,我們在兩個例項harbor1 和 harbor2中的專案“cosign”之間建立基於推送的複製規則(從harbor1 到 harbor2),使用機器人帳戶(robot-account)作為認證身份。
1. 安裝兩個啟用了 cosign (和 notary ) Harbor 的實 例
我們使用Harbor的 離線安裝程式 [6] 。
# ./install.sh --with-notary --with-trivy
[Step 0]: checking if docker is installed ...
...
...
...
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating network "harbor_harbor-notary" with the default driver
Creating network "harbor_notary-sig" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating redis ... done
Creating registryctl ... done
Creating registry ... done
Creating harbor-db ... done
Creating trivy-adapter ... done
Creating notary-signer ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
Creating notary-server ... done
✔ ----Harbor has been installed and started successfully.----
2. 建立新專案“cosign”
在專案中啟用 cosign:
3. 建立新使用者“cosign-demo ”,並將其分配給專案“cosign”
4. 在第二個例項上建立專案“cosign”
5. 在第二個例項上 建立機器人帳戶 [7] “robot$cosign”
儲存機器人賬號的認證憑證,將在配置遠端複製的時候使用:
6. 在第一個 Harbor 例項上 設定複製 [8]
設定新的目標 Harbor 例項:
設定從 Harbor1->Harbor2 的複製規則:
7. 建立 cosign 金鑰對
為了能夠執行以下步驟,需要安裝“cosign”。見 安裝說明 [9] 。
$ cosign generate-key-pair
Enter password for private key:
Enter again:
Private key written to cosign.key
Public key written to cosign.pub
你可以匯出金鑰的密碼( 也稱為 pass-phrase ),以便在自動化中使用:
export COSIGN_PASSWORD=Your_Super_P1$$w0rD
8. 映象推送和簽名
使用你的 cosign-demo 使用者登入第一個 Harbor 例項。
$ docker login harbor1.orlix.org
Authenticating with existing credentials...
Login Succeeded
然後將映象推送到你已經設定好的 cosign 專案,下面的例子使用了映象 pause:1。
$ docker push harbor1.orlix.org/cosign/pause:1
The push refers to repository [harbor1.orlix.org/cosign/pause]
5f70bf18a086: Layer already exists
e16a89738269: Layer already exists
1: digest: sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105 size: 938
一旦我們在Harbor中有了可用的映象,我們就可以用 cosign 來做映象簽名。
$ cosign sign --key cosign.key harbor1.orlix.org/cosign/pause:1
Enter password for private key:
Pushing signature to: harbor1.orlix.org/cosign/pause
9. 觸發複製並驗證結果
驗證複製結果:

在 Harbor1 例項上觸發複製規則 harbor1->harbor2 之後,我們可以看到該映象在兩個 Harbor 例項中都有 Cosign 簽名,可通過執行命令 cosign verify 驗證簽名。
$ cosign verify --key cosign.pub harbor1.orlix.org/cosign/pause:1 | jq .
Verification for harbor1.orlix.org/cosign/pause:1 --
The following checks were performed on each of these signatures:
- The cosign claims were validated
- The signatures were verified against the specified public key
[
{
"critical": {
"identity": {
"docker-reference": "harbor1.orlix.org/cosign/pause"
},
"image": {
"docker-manifest-digest": "sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105"
},
"type": "cosign container image signature"
},
"optional": null
}
]
$ cosign verify --key cosign.pub harbor2.orlix.org/cosign/pause:1 | jq .
Verification for harbor2.orlix.org/cosign/pause:1 --
The following checks were performed on each of these signatures:
- The cosign claims were validated
- The signatures were verified against the specified public key
[
{
"critical": {
"identity": {
"docker-reference": "harbor1.orlix.org/cosign/pause"
},
"image": {
"docker-manifest-digest": "sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105"
},
"type": "cosign container image signature"
},
"optional": null
}
驗證返回結果和退出程式碼為零,表明簽名有效!摘要(digest)值也相同!這樣,Cosign 功能配置成功了!
歡迎大家使用 cosign 功能,並通過以下方式反饋給我們建議。
歡迎與 Harbor 社群合作!
-
加入 Harbor 社群 [10] 會議和電郵列表
-
通過 @project_harbor [11] 在 Twitter 上獲取更新
-
在 CNCF Slack [12] 的#harbor 頻道與我們聊天
-
在 Github [13] 上與我們合作
-
關注 Harbor社群 [14] 公眾號,加入 Harbor 微信群
參考資料
[1] Notary: https://github.com/notaryproject/notary
[2] Cosign: https://github.com/sigstore/cosign
[3] Sigstore 專案: https://github.com/sigstore
[4] 複製功能: https://goharbor.io/docs/2.5.0/administration/configuring-replication/
[5] 完整文件: https://goharbor.io/docs/2.5.0/working-with-projects/working-with-images/sign-images/
[6] 離線安裝程式: https://goharbor.io/docs/2.5.0/install-config/download-installer/
[7] 建立機器人帳戶: https://goharbor.io/docs/2.5.0/administration/robot-accounts/
[8] 設定複製: https://goharbor.io/docs/2.5.0/administration/configuring-replication/
[9] 安裝說明: https://docs.sigstore.dev/cosign/installation/
[10] Harbor 社群: https://goharbor.io/community/
[11] @project_harbor: https://twitter.com/project_harbor
[12] CNCF Slack: https://slack.cncf.io/
[13] Github: https://github.com/goharbor/harbor
[14] Harbor社群公眾號:名稱: Harbor社群 微信ID: HarborChina
要想了解雲原生、機器學習和區塊鏈等技術原理,請立即長按以下二維碼,關注本公眾號 亨利筆記 ( henglibiji ) ,以免錯過更新。
- 2022 年 Kubernetes 使用現狀報告
- TAP 基於 Knative 的 雲原生執行時
- TAP 中的雲原生構建服務
- 基於 Backstage 的 TAP 開發者門戶
- Tanzu Application Platform 的技術概覽
- Harbor v2.5遠端複製:製品的簽名如影隨形
- 全球首個工業級聯邦學習開源平臺FATE:邀請社群開發者和使用者參與
- 楊強教授:希望2022年實現從聯邦學習到可信聯邦學習的跨越
- VMware Tanzu 參考架構
- 春節假期收官小記|搶紅包黃金時間分析
- 從帶星號的城市進入管控最嚴的北京,記住這點就夠了
- VMworld中國演講影片:應用現代化和Tanzu解決方案
- Tanzu是個啥,專家有話說
- 元宇宙再火,終究離不開這項技術
- 有了這個辦法,跑AI任務再也不用在機器上插GPU卡了
- 聯邦學習企業級解決方案(附影片和PPT)
- 楊強教授演講影片:資料要素與聯邦學習(附文字摘要)
- 聯邦學習:保護隱私安全以及克服資料孤島的機器學習
- Bitfusion 如何在 vSphere 中使用 PVRDMA 功能?
- CNCF 首箇中國開源專案Harbor是如何煉成的?